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
16 void lv2_cleanup(void)
20 printf("Cleaning up after Lv-2...\n");
22 if (lv1_gpu_close() == 0)
23 printf("GPU closed\n");
26 result
= lv1_get_logical_ppe_id(&ppe_id
);
28 fatal("could not get PPE id");
30 printf("PPE id: %ld\n", ppe_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);
37 printf("Selected VAS 0\n");
43 if (lv1_disconnect_irq_plug_ext(ppe_id
, j
, i
) == 0)
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)
51 printf("Destructed %d IRQ outlets\n", count
);
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;
71 printf("Allocating all possible lv1 memory...\n");
75 while (size
>= 4096) {
79 result
= lv1_allocate_memory(size
, 12, 0, 0, &newaddr
, &muid
);
84 cur_ctr
= (newaddr
& 0x03fffffff000)>>12;
85 if (cur_ctr
> ctr_max
)
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");
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))
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
);
119 } else if (flags
!= 0) {
120 if ((flags
>>60) == 0xc) {
121 if (lv1_unmap_htab(start_address
) == 0)
130 prev
= start_address
;
135 printf("Cleaned up %ld bytes in %d blocks\n", total
, blocks
);
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);
147 printf("Cleared IRQ mask for VUART %d\n", i
);