Added boot process information to help someone find out what really happens.
[bootos.git] / stage2 / cleanup.c
blob600aaeae519f2d485f0ca85f2acdb87aa39e91c2
1 /* cleanup.c - clean up after lv2
3 Copyright (C) 2010-2011 Hector Martin "marcan" <hector@marcansoft.com>
5 This code is licensed to you under the terms of the GNU GPL, version 2;
6 see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
7 */
9 #include "config.h"
10 #include "types.h"
11 #include "lv1call.h"
12 #include "debug.h"
13 #include "cleanup.h"
14 #include "device.h"
16 void lv2_cleanup(void)
18 s64 result;
19 int i,j;
20 printf("Cleaning up after Lv-2...\n");
22 if (lv1_gpu_close() == 0)
23 printf("GPU closed\n");
25 u64 ppe_id;
26 result = lv1_get_logical_ppe_id(&ppe_id);
27 if (result)
28 fatal("could not get PPE id");
30 printf("PPE id: %ld\n", ppe_id);
32 u64 vas_id;
33 result = lv1_get_virtual_address_space_id_of_ppe(&vas_id);
34 printf("VAS id: %ld\n", vas_id);
35 result = lv1_select_virtual_address_space(0);
36 if (result == 0)
37 printf("Selected VAS 0\n");
39 int count = 0;
41 for (i=0; i<512; i++)
42 for (j=0; j<2; j++)
43 if (lv1_disconnect_irq_plug_ext(ppe_id, j, i) == 0)
44 count++;
46 printf("Disconnected %d IRQ plugs\n", count);
48 for (i=0, count=0; i<256; i++)
49 if (lv1_destruct_io_irq_outlet(i) == 0)
50 count++;
51 printf("Destructed %d IRQ outlets\n", count);
53 count = 0;
54 if (lv1_configure_irq_state_bitmap(ppe_id, 0, 0) == 0) count++;
55 if (lv1_configure_irq_state_bitmap(ppe_id, 1, 0) == 0) count++;
56 printf("Removed %d state bitmaps\n", count);
58 printf("Closed %d devices\n", close_all_devs());
60 for (i=0; i<256; i++) {
61 if (lv1_disable_logical_spe(i, 0) == 0)
62 printf("Disabled logical spe %d\n", i);
63 if (lv1_destruct_logical_spe(i) == 0)
64 printf("Destroyed logical spe %d\n", i);
67 u64 size = 256*1024*1024;
68 int blocks = 0;
69 u64 total = 0;
71 printf("Allocating all possible lv1 memory...\n");
73 u64 ctr_max = 0;
75 while (size >= 4096) {
76 u64 newaddr;
77 u64 muid;
78 u64 cur_ctr;
79 result = lv1_allocate_memory(size, 12, 0, 0, &newaddr, &muid);
80 if (result) {
81 size >>= 1;
82 continue;
84 cur_ctr = (newaddr & 0x03fffffff000)>>12;
85 if (cur_ctr > ctr_max)
86 ctr_max = cur_ctr;
87 blocks++;
88 total += size;
91 printf("Allocated %ld bytes in %d blocks\n", total, blocks);
92 printf("Current allocation address counter is 0x%lx\n", ctr_max);
94 printf("Brute forcing Lv1 allocation regions...\n");
96 u64 counter;
97 u64 sbits;
98 total = 0;
99 blocks = 0;
100 u64 prev = -1;
102 u64 ctr_limit = 0x40000;
104 for (counter = 0; counter <= ctr_limit; counter++) {
105 for (sbits = 12; sbits <= 30; sbits++) {
106 u64 addr = (counter<<12) | (sbits<<42);
107 if (counter > ctr_max && (addr & 0xfffff))
108 continue;
109 u64 start_address, size, access_rights, page_size, flags;
110 result = lv1_query_logical_partition_address_region_info(addr,
111 &start_address, &size, &access_rights, &page_size, &flags);
112 if (result == 0 && start_address != prev) {
113 printf("%012lx: size %7lx rights %lx pagesize %ld (%6x) flags 0x%016lx ", start_address, size, access_rights, page_size, 1<<page_size, flags);
114 result = lv1_release_memory(start_address);
115 if (result == 0) {
116 blocks++;
117 total += size;
118 printf("CLEANED\n");
119 } else if (flags != 0) {
120 if ((flags>>60) == 0xc) {
121 if (lv1_unmap_htab(start_address) == 0)
122 printf("CLEANED ");
123 printf("HTAB\n");
124 } else {
125 printf("IOMEM\n");
127 } else {
128 printf("ERROR\n");
130 prev = start_address;
135 printf("Cleaned up %ld bytes in %d blocks\n", total, blocks);
137 for (i=0; i<16; i++)
138 if (lv1_destruct_virtual_address_space(i) == 0)
139 printf("Destroyed VAS %d\n", i);
141 if (lv1_deconfigure_virtual_uart_irq() == 0)
142 printf("Deconfigured VUART IRQ\n");
144 for (i=0; i<64; i++) {
145 result = lv1_set_virtual_uart_param(i, 2, 0);
146 if (result == 0)
147 printf("Cleared IRQ mask for VUART %d\n", i);