1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/powerpc/boot/wii.c
5 * Nintendo Wii bootwrapper support
6 * Copyright (C) 2008-2009 The GameCube Linux Team
7 * Copyright (C) 2008,2009 Albert Herranz
20 #define HW_REG(x) ((void *)(x))
22 #define EXI_CTRL HW_REG(0x0d800070)
23 #define EXI_CTRL_ENABLE (1<<0)
25 #define MEM2_TOP (0x10000000 + 64*1024*1024)
26 #define FIRMWARE_DEFAULT_SIZE (12*1024*1024)
39 static int mipc_check_address(u32 pa
)
41 /* only MEM2 addresses */
42 if (pa
< 0x10000000 || pa
> 0x14000000)
47 static struct mipc_infohdr
*mipc_get_infohdr(void)
49 struct mipc_infohdr
**hdrp
, *hdr
;
51 /* 'mini' header pointer is the last word of MEM2 memory */
52 hdrp
= (struct mipc_infohdr
**)0x13fffffc;
53 if (mipc_check_address((u32
)hdrp
)) {
54 printf("mini: invalid hdrp %08X\n", (u32
)hdrp
);
60 if (mipc_check_address((u32
)hdr
)) {
61 printf("mini: invalid hdr %08X\n", (u32
)hdr
);
65 if (memcmp(hdr
->magic
, "IPC", 3)) {
66 printf("mini: invalid magic\n");
75 static int mipc_get_mem2_boundary(u32
*mem2_boundary
)
77 struct mipc_infohdr
*hdr
;
80 hdr
= mipc_get_infohdr();
86 if (mipc_check_address(hdr
->mem2_boundary
)) {
87 printf("mini: invalid mem2_boundary %08X\n",
92 *mem2_boundary
= hdr
->mem2_boundary
;
99 static void platform_fixups(void)
107 mem
= finddevice("/memory");
109 fatal("Can't find memory node\n");
111 /* two ranges of (address, size) words */
112 len
= getprop(mem
, "reg", reg
, sizeof(reg
));
113 if (len
!= sizeof(reg
)) {
118 /* retrieve MEM2 boundary from 'mini' */
119 error
= mipc_get_mem2_boundary(&mem2_boundary
);
121 /* if that fails use a sane value */
122 mem2_boundary
= MEM2_TOP
- FIRMWARE_DEFAULT_SIZE
;
125 if (mem2_boundary
> reg
[2] && mem2_boundary
< reg
[2] + reg
[3]) {
126 reg
[3] = mem2_boundary
- reg
[2];
127 printf("top of MEM2 @ %08X\n", reg
[2] + reg
[3]);
128 setprop(mem
, "reg", reg
, sizeof(reg
));
135 void platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
)
137 u32 heapsize
= 24*1024*1024 - (u32
)_end
;
139 simple_alloc_init(_end
, heapsize
, 32, 64);
140 fdt_init(_dtb_start
);
143 * 'mini' boots the Broadway processor with EXI disabled.
144 * We need it enabled before probing for the USB Gecko.
146 out_be32(EXI_CTRL
, in_be32(EXI_CTRL
) | EXI_CTRL_ENABLE
);
149 console_ops
.write
= ug_console_write
;
151 platform_ops
.fixups
= platform_fixups
;