diff options
author | Albert Herranz <albert_herranz@yahoo.es> | 2009-12-12 01:31:52 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2009-12-13 00:24:31 -0500 |
commit | 02d748a9ee56735641bade9b734dc2fa9be4df4c (patch) | |
tree | 94e869d9ee34dd0b0075883aa202956749d76ae1 /arch | |
parent | d1d56f8c1d5a622228177eca47e9dcff0498bddb (diff) |
wii: bootwrapper: add fixup to calc useable mem2
The top portion of MEM2 (the second 64MB memory block) in the Nintendo
Wii video game console is used by the firmware running on the Starlet
processor.
Add code to calculate the portion of MEM2 safely useable by the
Broadway processor. When running under the 'mini' firmware this is
easily determined from an in-memory header. Otherwise, a safe default
is used.
Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/powerpc/boot/wii.c | 118 |
1 files changed, 115 insertions, 3 deletions
diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c index d0e2625a9539..2ebaec0344dd 100644 --- a/arch/powerpc/boot/wii.c +++ b/arch/powerpc/boot/wii.c | |||
@@ -22,10 +22,120 @@ | |||
22 | 22 | ||
23 | BSS_STACK(8192); | 23 | BSS_STACK(8192); |
24 | 24 | ||
25 | #define HW_REG(x) ((void *)(x)) | 25 | #define HW_REG(x) ((void *)(x)) |
26 | 26 | ||
27 | #define EXI_CTRL HW_REG(0x0d800070) | 27 | #define EXI_CTRL HW_REG(0x0d800070) |
28 | #define EXI_CTRL_ENABLE (1<<0) | 28 | #define EXI_CTRL_ENABLE (1<<0) |
29 | |||
30 | #define MEM2_TOP (0x10000000 + 64*1024*1024) | ||
31 | #define FIRMWARE_DEFAULT_SIZE (12*1024*1024) | ||
32 | |||
33 | |||
34 | struct mipc_infohdr { | ||
35 | char magic[3]; | ||
36 | u8 version; | ||
37 | u32 mem2_boundary; | ||
38 | u32 ipc_in; | ||
39 | size_t ipc_in_size; | ||
40 | u32 ipc_out; | ||
41 | size_t ipc_out_size; | ||
42 | }; | ||
43 | |||
44 | static int mipc_check_address(u32 pa) | ||
45 | { | ||
46 | /* only MEM2 addresses */ | ||
47 | if (pa < 0x10000000 || pa > 0x14000000) | ||
48 | return -EINVAL; | ||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static struct mipc_infohdr *mipc_get_infohdr(void) | ||
53 | { | ||
54 | struct mipc_infohdr **hdrp, *hdr; | ||
55 | |||
56 | /* 'mini' header pointer is the last word of MEM2 memory */ | ||
57 | hdrp = (struct mipc_infohdr **)0x13fffffc; | ||
58 | if (mipc_check_address((u32)hdrp)) { | ||
59 | printf("mini: invalid hdrp %08X\n", (u32)hdrp); | ||
60 | hdr = NULL; | ||
61 | goto out; | ||
62 | } | ||
63 | |||
64 | hdr = *hdrp; | ||
65 | if (mipc_check_address((u32)hdr)) { | ||
66 | printf("mini: invalid hdr %08X\n", (u32)hdr); | ||
67 | hdr = NULL; | ||
68 | goto out; | ||
69 | } | ||
70 | if (memcmp(hdr->magic, "IPC", 3)) { | ||
71 | printf("mini: invalid magic\n"); | ||
72 | hdr = NULL; | ||
73 | goto out; | ||
74 | } | ||
75 | |||
76 | out: | ||
77 | return hdr; | ||
78 | } | ||
79 | |||
80 | static int mipc_get_mem2_boundary(u32 *mem2_boundary) | ||
81 | { | ||
82 | struct mipc_infohdr *hdr; | ||
83 | int error; | ||
84 | |||
85 | hdr = mipc_get_infohdr(); | ||
86 | if (!hdr) { | ||
87 | error = -1; | ||
88 | goto out; | ||
89 | } | ||
90 | |||
91 | if (mipc_check_address(hdr->mem2_boundary)) { | ||
92 | printf("mini: invalid mem2_boundary %08X\n", | ||
93 | hdr->mem2_boundary); | ||
94 | error = -EINVAL; | ||
95 | goto out; | ||
96 | } | ||
97 | *mem2_boundary = hdr->mem2_boundary; | ||
98 | error = 0; | ||
99 | out: | ||
100 | return error; | ||
101 | |||
102 | } | ||
103 | |||
104 | static void platform_fixups(void) | ||
105 | { | ||
106 | void *mem; | ||
107 | u32 reg[4]; | ||
108 | u32 mem2_boundary; | ||
109 | int len; | ||
110 | int error; | ||
111 | |||
112 | mem = finddevice("/memory"); | ||
113 | if (!mem) | ||
114 | fatal("Can't find memory node\n"); | ||
115 | |||
116 | /* two ranges of (address, size) words */ | ||
117 | len = getprop(mem, "reg", reg, sizeof(reg)); | ||
118 | if (len != sizeof(reg)) { | ||
119 | /* nothing to do */ | ||
120 | goto out; | ||
121 | } | ||
122 | |||
123 | /* retrieve MEM2 boundary from 'mini' */ | ||
124 | error = mipc_get_mem2_boundary(&mem2_boundary); | ||
125 | if (error) { | ||
126 | /* if that fails use a sane value */ | ||
127 | mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE; | ||
128 | } | ||
129 | |||
130 | if (mem2_boundary > reg[2] && mem2_boundary < reg[2] + reg[3]) { | ||
131 | reg[3] = mem2_boundary - reg[2]; | ||
132 | printf("top of MEM2 @ %08X\n", reg[2] + reg[3]); | ||
133 | setprop(mem, "reg", reg, sizeof(reg)); | ||
134 | } | ||
135 | |||
136 | out: | ||
137 | return; | ||
138 | } | ||
29 | 139 | ||
30 | void platform_init(unsigned long r3, unsigned long r4, unsigned long r5) | 140 | void platform_init(unsigned long r3, unsigned long r4, unsigned long r5) |
31 | { | 141 | { |
@@ -42,5 +152,7 @@ void platform_init(unsigned long r3, unsigned long r4, unsigned long r5) | |||
42 | 152 | ||
43 | if (ug_probe()) | 153 | if (ug_probe()) |
44 | console_ops.write = ug_console_write; | 154 | console_ops.write = ug_console_write; |
155 | |||
156 | platform_ops.fixups = platform_fixups; | ||
45 | } | 157 | } |
46 | 158 | ||