diff options
author | Albert Herranz <albert_herranz@yahoo.es> | 2009-12-12 01:31:53 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2009-12-13 00:24:31 -0500 |
commit | de32400dd26e743c5d500aa42d8d6818b79edb73 (patch) | |
tree | 5fee868e4fac044dca4fb3a18532b67b62c90c96 /arch | |
parent | 02d748a9ee56735641bade9b734dc2fa9be4df4c (diff) |
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 <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/mm/init_32.c | 4 | ||||
-rw-r--r-- | arch/powerpc/mm/mmu_decl.h | 10 | ||||
-rw-r--r-- | arch/powerpc/mm/pgtable_32.c | 32 | ||||
-rw-r--r-- | arch/powerpc/mm/ppc_mmu_32.c | 4 | ||||
-rw-r--r-- | arch/powerpc/platforms/embedded6xx/wii.c | 63 |
5 files changed, 106 insertions, 7 deletions
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c index 9ddcfb4dc139..703c7c2e0d9f 100644 --- a/arch/powerpc/mm/init_32.c +++ b/arch/powerpc/mm/init_32.c | |||
@@ -131,9 +131,13 @@ void __init MMU_init(void) | |||
131 | MMU_setup(); | 131 | MMU_setup(); |
132 | 132 | ||
133 | if (lmb.memory.cnt > 1) { | 133 | if (lmb.memory.cnt > 1) { |
134 | #ifndef CONFIG_WII | ||
134 | lmb.memory.cnt = 1; | 135 | lmb.memory.cnt = 1; |
135 | lmb_analyze(); | 136 | lmb_analyze(); |
136 | printk(KERN_WARNING "Only using first contiguous memory region"); | 137 | printk(KERN_WARNING "Only using first contiguous memory region"); |
138 | #else | ||
139 | wii_memory_fixups(); | ||
140 | #endif | ||
137 | } | 141 | } |
138 | 142 | ||
139 | total_lowmem = total_memory = lmb_end_of_DRAM() - memstart_addr; | 143 | total_lowmem = total_memory = lmb_end_of_DRAM() - memstart_addr; |
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h index d2e5321d5ea6..9aa39fe74f8a 100644 --- a/arch/powerpc/mm/mmu_decl.h +++ b/arch/powerpc/mm/mmu_decl.h | |||
@@ -136,6 +136,14 @@ extern phys_addr_t total_lowmem; | |||
136 | extern phys_addr_t memstart_addr; | 136 | extern phys_addr_t memstart_addr; |
137 | extern phys_addr_t lowmem_end_addr; | 137 | extern phys_addr_t lowmem_end_addr; |
138 | 138 | ||
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 | |||
139 | /* ...and now those things that may be slightly different between processor | 147 | /* ...and now those things that may be slightly different between processor |
140 | * architectures. -- Dan | 148 | * architectures. -- Dan |
141 | */ | 149 | */ |
@@ -155,5 +163,5 @@ extern void adjust_total_lowmem(void); | |||
155 | #elif defined(CONFIG_PPC32) | 163 | #elif defined(CONFIG_PPC32) |
156 | /* anything 32-bit except 4xx or 8xx */ | 164 | /* anything 32-bit except 4xx or 8xx */ |
157 | extern void MMU_init_hw(void); | 165 | extern void MMU_init_hw(void); |
158 | extern unsigned long mmu_mapin_ram(void); | 166 | extern unsigned long mmu_mapin_ram(unsigned long top); |
159 | #endif | 167 | #endif |
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c index cb96cb2e17cc..b55bbe87acb8 100644 --- a/arch/powerpc/mm/pgtable_32.c +++ b/arch/powerpc/mm/pgtable_32.c | |||
@@ -283,18 +283,18 @@ int map_page(unsigned long va, phys_addr_t pa, int flags) | |||
283 | } | 283 | } |
284 | 284 | ||
285 | /* | 285 | /* |
286 | * Map in a big chunk of physical memory starting at PAGE_OFFSET. | 286 | * Map in a chunk of physical memory starting at start. |
287 | */ | 287 | */ |
288 | void __init mapin_ram(void) | 288 | void __init __mapin_ram_chunk(unsigned long offset, unsigned long top) |
289 | { | 289 | { |
290 | unsigned long v, s, f; | 290 | unsigned long v, s, f; |
291 | phys_addr_t p; | 291 | phys_addr_t p; |
292 | int ktext; | 292 | int ktext; |
293 | 293 | ||
294 | s = mmu_mapin_ram(); | 294 | s = offset; |
295 | v = PAGE_OFFSET + s; | 295 | v = PAGE_OFFSET + s; |
296 | p = memstart_addr + s; | 296 | p = memstart_addr + s; |
297 | for (; s < total_lowmem; s += PAGE_SIZE) { | 297 | for (; s < top; s += PAGE_SIZE) { |
298 | ktext = ((char *) v >= _stext && (char *) v < etext); | 298 | ktext = ((char *) v >= _stext && (char *) v < etext); |
299 | f = ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL; | 299 | f = ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL; |
300 | map_page(v, p, f); | 300 | map_page(v, p, f); |
@@ -307,6 +307,30 @@ void __init mapin_ram(void) | |||
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
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 | |||
310 | /* Scan the real Linux page tables and return a PTE pointer for | 334 | /* Scan the real Linux page tables and return a PTE pointer for |
311 | * a virtual address in a context. | 335 | * a virtual address in a context. |
312 | * Returns true (1) if PTE was found, zero otherwise. The pointer to | 336 | * Returns true (1) if PTE was found, zero otherwise. The pointer to |
diff --git a/arch/powerpc/mm/ppc_mmu_32.c b/arch/powerpc/mm/ppc_mmu_32.c index 2d2a87e10154..f11c2cdcb0fe 100644 --- a/arch/powerpc/mm/ppc_mmu_32.c +++ b/arch/powerpc/mm/ppc_mmu_32.c | |||
@@ -72,7 +72,7 @@ unsigned long p_mapped_by_bats(phys_addr_t pa) | |||
72 | return 0; | 72 | return 0; |
73 | } | 73 | } |
74 | 74 | ||
75 | unsigned long __init mmu_mapin_ram(void) | 75 | unsigned long __init mmu_mapin_ram(unsigned long top) |
76 | { | 76 | { |
77 | unsigned long tot, bl, done; | 77 | unsigned long tot, bl, done; |
78 | unsigned long max_size = (256<<20); | 78 | unsigned long max_size = (256<<20); |
@@ -86,7 +86,7 @@ unsigned long __init mmu_mapin_ram(void) | |||
86 | 86 | ||
87 | /* Make sure we don't map a block larger than the | 87 | /* Make sure we don't map a block larger than the |
88 | smallest alignment of the physical address. */ | 88 | smallest alignment of the physical address. */ |
89 | tot = total_lowmem; | 89 | tot = top; |
90 | for (bl = 128<<10; bl < max_size; bl <<= 1) { | 90 | for (bl = 128<<10; bl < max_size; bl <<= 1) { |
91 | if (bl * 2 > tot) | 91 | if (bl * 2 > tot) |
92 | break; | 92 | break; |
diff --git a/arch/powerpc/platforms/embedded6xx/wii.c b/arch/powerpc/platforms/embedded6xx/wii.c index 1bd41cc8039d..de0c1e397c99 100644 --- a/arch/powerpc/platforms/embedded6xx/wii.c +++ b/arch/powerpc/platforms/embedded6xx/wii.c | |||
@@ -20,6 +20,8 @@ | |||
20 | #include <linux/seq_file.h> | 20 | #include <linux/seq_file.h> |
21 | #include <linux/kexec.h> | 21 | #include <linux/kexec.h> |
22 | #include <linux/of_platform.h> | 22 | #include <linux/of_platform.h> |
23 | #include <linux/lmb.h> | ||
24 | #include <mm/mmu_decl.h> | ||
23 | 25 | ||
24 | #include <asm/io.h> | 26 | #include <asm/io.h> |
25 | #include <asm/machdep.h> | 27 | #include <asm/machdep.h> |
@@ -52,6 +54,67 @@ | |||
52 | static void __iomem *hw_ctrl; | 54 | static void __iomem *hw_ctrl; |
53 | static void __iomem *hw_gpio; | 55 | static void __iomem *hw_gpio; |
54 | 56 | ||
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 | |||
55 | static void wii_spin(void) | 118 | static void wii_spin(void) |
56 | { | 119 | { |
57 | local_irq_disable(); | 120 | local_irq_disable(); |