Skip to content

Commit de32400

Browse files
herraa1glikely
authored andcommitted
wii: use both mem1 and mem2 as ram
The Nintendo Wii video game console has two discontiguous RAM regions: - MEM1: 24MB @ 0x00000000 - MEM2: 64MB @ 0x10000000 Unfortunately, the kernel currently does not support discontiguous RAM memory regions on 32-bit PowerPC platforms. This patch adds a series of workarounds to allow the use of the second memory region (MEM2) as RAM by the kernel. Basically, a single range of memory from the beginning of MEM1 to the end of MEM2 is reported to the kernel, and a memory reservation is created for the hole between MEM1 and MEM2. With this patch the system is able to use all the available RAM and not just ~27% of it. This will no longer be needed when proper discontig memory support for 32-bit PowerPC is added to the kernel. Signed-off-by: Albert Herranz <[email protected]> Acked-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Grant Likely <[email protected]>
1 parent 02d748a commit de32400

File tree

5 files changed

+106
-7
lines changed

5 files changed

+106
-7
lines changed

arch/powerpc/mm/init_32.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ void __init MMU_init(void)
131131
MMU_setup();
132132

133133
if (lmb.memory.cnt > 1) {
134+
#ifndef CONFIG_WII
134135
lmb.memory.cnt = 1;
135136
lmb_analyze();
136137
printk(KERN_WARNING "Only using first contiguous memory region");
138+
#else
139+
wii_memory_fixups();
140+
#endif
137141
}
138142

139143
total_lowmem = total_memory = lmb_end_of_DRAM() - memstart_addr;

arch/powerpc/mm/mmu_decl.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ extern phys_addr_t total_lowmem;
136136
extern phys_addr_t memstart_addr;
137137
extern phys_addr_t lowmem_end_addr;
138138

139+
#ifdef CONFIG_WII
140+
extern unsigned long wii_hole_start;
141+
extern unsigned long wii_hole_size;
142+
143+
extern unsigned long wii_mmu_mapin_mem2(unsigned long top);
144+
extern void wii_memory_fixups(void);
145+
#endif
146+
139147
/* ...and now those things that may be slightly different between processor
140148
* architectures. -- Dan
141149
*/
@@ -155,5 +163,5 @@ extern void adjust_total_lowmem(void);
155163
#elif defined(CONFIG_PPC32)
156164
/* anything 32-bit except 4xx or 8xx */
157165
extern void MMU_init_hw(void);
158-
extern unsigned long mmu_mapin_ram(void);
166+
extern unsigned long mmu_mapin_ram(unsigned long top);
159167
#endif

arch/powerpc/mm/pgtable_32.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,18 @@ int map_page(unsigned long va, phys_addr_t pa, int flags)
283283
}
284284

285285
/*
286-
* Map in a big chunk of physical memory starting at PAGE_OFFSET.
286+
* Map in a chunk of physical memory starting at start.
287287
*/
288-
void __init mapin_ram(void)
288+
void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
289289
{
290290
unsigned long v, s, f;
291291
phys_addr_t p;
292292
int ktext;
293293

294-
s = mmu_mapin_ram();
294+
s = offset;
295295
v = PAGE_OFFSET + s;
296296
p = memstart_addr + s;
297-
for (; s < total_lowmem; s += PAGE_SIZE) {
297+
for (; s < top; s += PAGE_SIZE) {
298298
ktext = ((char *) v >= _stext && (char *) v < etext);
299299
f = ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL;
300300
map_page(v, p, f);
@@ -307,6 +307,30 @@ void __init mapin_ram(void)
307307
}
308308
}
309309

310+
void __init mapin_ram(void)
311+
{
312+
unsigned long s, top;
313+
314+
#ifndef CONFIG_WII
315+
top = total_lowmem;
316+
s = mmu_mapin_ram(top);
317+
__mapin_ram_chunk(s, top);
318+
#else
319+
if (!wii_hole_size) {
320+
s = mmu_mapin_ram(total_lowmem);
321+
__mapin_ram_chunk(s, total_lowmem);
322+
} else {
323+
top = wii_hole_start;
324+
s = mmu_mapin_ram(top);
325+
__mapin_ram_chunk(s, top);
326+
327+
top = lmb_end_of_DRAM();
328+
s = wii_mmu_mapin_mem2(top);
329+
__mapin_ram_chunk(s, top);
330+
}
331+
#endif
332+
}
333+
310334
/* Scan the real Linux page tables and return a PTE pointer for
311335
* a virtual address in a context.
312336
* Returns true (1) if PTE was found, zero otherwise. The pointer to

arch/powerpc/mm/ppc_mmu_32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ unsigned long p_mapped_by_bats(phys_addr_t pa)
7272
return 0;
7373
}
7474

75-
unsigned long __init mmu_mapin_ram(void)
75+
unsigned long __init mmu_mapin_ram(unsigned long top)
7676
{
7777
unsigned long tot, bl, done;
7878
unsigned long max_size = (256<<20);
@@ -86,7 +86,7 @@ unsigned long __init mmu_mapin_ram(void)
8686

8787
/* Make sure we don't map a block larger than the
8888
smallest alignment of the physical address. */
89-
tot = total_lowmem;
89+
tot = top;
9090
for (bl = 128<<10; bl < max_size; bl <<= 1) {
9191
if (bl * 2 > tot)
9292
break;

arch/powerpc/platforms/embedded6xx/wii.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <linux/seq_file.h>
2121
#include <linux/kexec.h>
2222
#include <linux/of_platform.h>
23+
#include <linux/lmb.h>
24+
#include <mm/mmu_decl.h>
2325

2426
#include <asm/io.h>
2527
#include <asm/machdep.h>
@@ -52,6 +54,67 @@
5254
static void __iomem *hw_ctrl;
5355
static void __iomem *hw_gpio;
5456

57+
unsigned long wii_hole_start;
58+
unsigned long wii_hole_size;
59+
60+
61+
static int __init page_aligned(unsigned long x)
62+
{
63+
return !(x & (PAGE_SIZE-1));
64+
}
65+
66+
void __init wii_memory_fixups(void)
67+
{
68+
struct lmb_property *p = lmb.memory.region;
69+
70+
/*
71+
* This is part of a workaround to allow the use of two
72+
* discontiguous RAM ranges on the Wii, even if this is
73+
* currently unsupported on 32-bit PowerPC Linux.
74+
*
75+
* We coealesce the two memory ranges of the Wii into a
76+
* single range, then create a reservation for the "hole"
77+
* between both ranges.
78+
*/
79+
80+
BUG_ON(lmb.memory.cnt != 2);
81+
BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
82+
83+
p[0].size = _ALIGN_DOWN(p[0].size, PAGE_SIZE);
84+
p[1].size = _ALIGN_DOWN(p[1].size, PAGE_SIZE);
85+
86+
wii_hole_start = p[0].base + p[0].size;
87+
wii_hole_size = p[1].base - wii_hole_start;
88+
89+
pr_info("MEM1: <%08llx %08llx>\n", p[0].base, p[0].size);
90+
pr_info("HOLE: <%08lx %08lx>\n", wii_hole_start, wii_hole_size);
91+
pr_info("MEM2: <%08llx %08llx>\n", p[1].base, p[1].size);
92+
93+
p[0].size += wii_hole_size + p[1].size;
94+
95+
lmb.memory.cnt = 1;
96+
lmb_analyze();
97+
98+
/* reserve the hole */
99+
lmb_reserve(wii_hole_start, wii_hole_size);
100+
}
101+
102+
unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
103+
{
104+
unsigned long delta, size, bl;
105+
unsigned long max_size = (256<<20);
106+
107+
/* MEM2 64MB@0x10000000 */
108+
delta = wii_hole_start + wii_hole_size;
109+
size = top - delta;
110+
for (bl = 128<<10; bl < max_size; bl <<= 1) {
111+
if (bl * 2 > size)
112+
break;
113+
}
114+
setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X);
115+
return delta + bl;
116+
}
117+
55118
static void wii_spin(void)
56119
{
57120
local_irq_disable();

0 commit comments

Comments
 (0)