Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the routines for handling the MMU on those |
| 3 | * PowerPC implementations where the MMU substantially follows the |
| 4 | * architecture specification. This includes the 6xx, 7xx, 7xxx, |
Michael Ellerman | 0f36910 | 2014-07-10 12:29:24 +1000 | [diff] [blame] | 5 | * and 8260 implementations but excludes the 8xx and 4xx. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 6 | * -- paulus |
| 7 | * |
| 8 | * Derived from arch/ppc/mm/init.c: |
| 9 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 10 | * |
| 11 | * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) |
| 12 | * and Cort Dougan (PReP) (cort@cs.nmt.edu) |
| 13 | * Copyright (C) 1996 Paul Mackerras |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 14 | * |
| 15 | * Derived from "arch/i386/mm/init.c" |
| 16 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License |
| 20 | * as published by the Free Software Foundation; either version |
| 21 | * 2 of the License, or (at your option) any later version. |
| 22 | * |
| 23 | */ |
| 24 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/highmem.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 29 | #include <linux/memblock.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 30 | |
| 31 | #include <asm/prom.h> |
| 32 | #include <asm/mmu.h> |
| 33 | #include <asm/machdep.h> |
Christophe Leroy | 9efc74f | 2018-11-09 17:33:24 +0000 | [diff] [blame] | 34 | #include <asm/code-patching.h> |
Christophe Leroy | 63b2bc6 | 2019-02-21 19:08:49 +0000 | [diff] [blame] | 35 | #include <asm/sections.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 36 | |
| 37 | #include "mmu_decl.h" |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 38 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 39 | struct hash_pte *Hash, *Hash_end; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 40 | unsigned long Hash_size, Hash_mask; |
| 41 | unsigned long _SDR1; |
| 42 | |
Becky Bruce | 316a405 | 2008-06-14 09:41:43 +1000 | [diff] [blame] | 43 | struct ppc_bat BATS[8][2]; /* 8 pairs of IBAT, DBAT */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 44 | |
| 45 | struct batrange { /* stores address ranges mapped by BATs */ |
| 46 | unsigned long start; |
| 47 | unsigned long limit; |
Becky Bruce | 7c5c432 | 2008-06-14 09:41:42 +1000 | [diff] [blame] | 48 | phys_addr_t phys; |
Jon Loeliger | ee0339f | 2006-06-17 17:52:44 -0500 | [diff] [blame] | 49 | } bat_addrs[8]; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Return PA for this VA if it is mapped by a BAT, or 0 |
| 53 | */ |
Christophe Leroy | 3084cdb | 2016-02-09 17:07:58 +0100 | [diff] [blame] | 54 | phys_addr_t v_block_mapped(unsigned long va) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 55 | { |
| 56 | int b; |
Christophe Leroy | e93ba1b | 2018-11-16 17:27:42 +0000 | [diff] [blame] | 57 | for (b = 0; b < ARRAY_SIZE(bat_addrs); ++b) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 58 | if (va >= bat_addrs[b].start && va < bat_addrs[b].limit) |
| 59 | return bat_addrs[b].phys + (va - bat_addrs[b].start); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Return VA for a given PA or 0 if not mapped |
| 65 | */ |
Christophe Leroy | 3084cdb | 2016-02-09 17:07:58 +0100 | [diff] [blame] | 66 | unsigned long p_block_mapped(phys_addr_t pa) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 67 | { |
| 68 | int b; |
Christophe Leroy | e93ba1b | 2018-11-16 17:27:42 +0000 | [diff] [blame] | 69 | for (b = 0; b < ARRAY_SIZE(bat_addrs); ++b) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 70 | if (pa >= bat_addrs[b].phys |
| 71 | && pa < (bat_addrs[b].limit-bat_addrs[b].start) |
| 72 | +bat_addrs[b].phys) |
| 73 | return bat_addrs[b].start+(pa-bat_addrs[b].phys); |
| 74 | return 0; |
| 75 | } |
| 76 | |
Christophe Leroy | e4d6654 | 2019-02-21 19:08:39 +0000 | [diff] [blame] | 77 | static int find_free_bat(void) |
| 78 | { |
| 79 | int b; |
| 80 | |
| 81 | if (cpu_has_feature(CPU_FTR_601)) { |
| 82 | for (b = 0; b < 4; b++) { |
| 83 | struct ppc_bat *bat = BATS[b]; |
| 84 | |
| 85 | if (!(bat[0].batl & 0x40)) |
| 86 | return b; |
| 87 | } |
| 88 | } else { |
| 89 | int n = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4; |
| 90 | |
| 91 | for (b = 0; b < n; b++) { |
| 92 | struct ppc_bat *bat = BATS[b]; |
| 93 | |
| 94 | if (!(bat[1].batu & 3)) |
| 95 | return b; |
| 96 | } |
| 97 | } |
| 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | static unsigned int block_size(unsigned long base, unsigned long top) |
| 102 | { |
| 103 | unsigned int max_size = (cpu_has_feature(CPU_FTR_601) ? 8 : 256) << 20; |
| 104 | unsigned int base_shift = (fls(base) - 1) & 31; |
| 105 | unsigned int block_shift = (fls(top - base) - 1) & 31; |
| 106 | |
| 107 | return min3(max_size, 1U << base_shift, 1U << block_shift); |
| 108 | } |
| 109 | |
Christophe Leroy | 5e04ae8 | 2019-02-21 19:08:48 +0000 | [diff] [blame] | 110 | /* |
| 111 | * Set up one of the IBAT (block address translation) register pairs. |
| 112 | * The parameters are not checked; in particular size must be a power |
| 113 | * of 2 between 128k and 256M. |
| 114 | * Only for 603+ ... |
| 115 | */ |
| 116 | static void setibat(int index, unsigned long virt, phys_addr_t phys, |
| 117 | unsigned int size, pgprot_t prot) |
| 118 | { |
| 119 | unsigned int bl = (size >> 17) - 1; |
| 120 | int wimgxpp; |
| 121 | struct ppc_bat *bat = BATS[index]; |
| 122 | unsigned long flags = pgprot_val(prot); |
| 123 | |
| 124 | if (!cpu_has_feature(CPU_FTR_NEED_COHERENT)) |
| 125 | flags &= ~_PAGE_COHERENT; |
| 126 | |
| 127 | wimgxpp = (flags & _PAGE_COHERENT) | (_PAGE_EXEC ? BPP_RX : BPP_XX); |
| 128 | bat[0].batu = virt | (bl << 2) | 2; /* Vs=1, Vp=0 */ |
| 129 | bat[0].batl = BAT_PHYS_ADDR(phys) | wimgxpp; |
| 130 | if (flags & _PAGE_USER) |
| 131 | bat[0].batu |= 1; /* Vp = 1 */ |
| 132 | } |
| 133 | |
| 134 | static void clearibat(int index) |
| 135 | { |
| 136 | struct ppc_bat *bat = BATS[index]; |
| 137 | |
| 138 | bat[0].batu = 0; |
| 139 | bat[0].batl = 0; |
| 140 | } |
| 141 | |
Christophe Leroy | 63b2bc6 | 2019-02-21 19:08:49 +0000 | [diff] [blame] | 142 | static unsigned long __init __mmu_mapin_ram(unsigned long base, unsigned long top) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 143 | { |
Christophe Leroy | e4d6654 | 2019-02-21 19:08:39 +0000 | [diff] [blame] | 144 | int idx; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 145 | |
Christophe Leroy | e4d6654 | 2019-02-21 19:08:39 +0000 | [diff] [blame] | 146 | while ((idx = find_free_bat()) != -1 && base != top) { |
| 147 | unsigned int size = block_size(base, top); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 148 | |
Christophe Leroy | e4d6654 | 2019-02-21 19:08:39 +0000 | [diff] [blame] | 149 | if (size < 128 << 10) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 150 | break; |
Christophe Leroy | e4d6654 | 2019-02-21 19:08:39 +0000 | [diff] [blame] | 151 | setbat(idx, PAGE_OFFSET + base, base, size, PAGE_KERNEL_X); |
| 152 | base += size; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 153 | } |
| 154 | |
Christophe Leroy | e4d6654 | 2019-02-21 19:08:39 +0000 | [diff] [blame] | 155 | return base; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 156 | } |
| 157 | |
Christophe Leroy | 63b2bc6 | 2019-02-21 19:08:49 +0000 | [diff] [blame] | 158 | unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top) |
| 159 | { |
| 160 | int done; |
| 161 | unsigned long border = (unsigned long)__init_begin - PAGE_OFFSET; |
| 162 | |
| 163 | if (__map_without_bats) { |
| 164 | pr_debug("RAM mapped without BATs\n"); |
| 165 | return base; |
| 166 | } |
| 167 | |
| 168 | if (!strict_kernel_rwx_enabled() || base >= border || top <= border) |
| 169 | return __mmu_mapin_ram(base, top); |
| 170 | |
| 171 | done = __mmu_mapin_ram(base, border); |
| 172 | if (done != border - base) |
| 173 | return done; |
| 174 | |
| 175 | return done + __mmu_mapin_ram(border, top); |
| 176 | } |
| 177 | |
| 178 | void mmu_mark_initmem_nx(void) |
| 179 | { |
| 180 | int nb = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4; |
| 181 | int i; |
| 182 | unsigned long base = (unsigned long)_stext - PAGE_OFFSET; |
| 183 | unsigned long top = (unsigned long)_etext - PAGE_OFFSET; |
| 184 | unsigned long size; |
| 185 | |
| 186 | if (cpu_has_feature(CPU_FTR_601)) |
| 187 | return; |
| 188 | |
| 189 | for (i = 0; i < nb - 1 && base < top && top - base > (128 << 10);) { |
| 190 | size = block_size(base, top); |
| 191 | setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_TEXT); |
| 192 | base += size; |
| 193 | } |
| 194 | if (base < top) { |
| 195 | size = block_size(base, top); |
| 196 | size = max(size, 128UL << 10); |
| 197 | if ((top - base) > size) { |
| 198 | if (strict_kernel_rwx_enabled()) |
| 199 | pr_warn("Kernel _etext not properly aligned\n"); |
| 200 | size <<= 1; |
| 201 | } |
| 202 | setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_TEXT); |
| 203 | base += size; |
| 204 | } |
| 205 | for (; i < nb; i++) |
| 206 | clearibat(i); |
| 207 | |
| 208 | update_bats(); |
| 209 | |
| 210 | for (i = TASK_SIZE >> 28; i < 16; i++) { |
| 211 | /* Do not set NX on VM space for modules */ |
| 212 | if (IS_ENABLED(CONFIG_MODULES) && |
| 213 | (VMALLOC_START & 0xf0000000) == i << 28) |
| 214 | break; |
| 215 | mtsrin(mfsrin(i << 28) | 0x10000000, i << 28); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | void mmu_mark_rodata_ro(void) |
| 220 | { |
| 221 | int nb = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4; |
| 222 | int i; |
| 223 | |
| 224 | if (cpu_has_feature(CPU_FTR_601)) |
| 225 | return; |
| 226 | |
| 227 | for (i = 0; i < nb; i++) { |
| 228 | struct ppc_bat *bat = BATS[i]; |
| 229 | |
| 230 | if (bat_addrs[i].start < (unsigned long)__init_begin) |
| 231 | bat[1].batl = (bat[1].batl & ~BPP_RW) | BPP_RX; |
| 232 | } |
| 233 | |
| 234 | update_bats(); |
| 235 | } |
| 236 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 237 | /* |
| 238 | * Set up one of the I/D BAT (block address translation) register pairs. |
| 239 | * The parameters are not checked; in particular size must be a power |
| 240 | * of 2 between 128k and 256M. |
Christophe Leroy | df25f86 | 2019-02-21 19:08:43 +0000 | [diff] [blame] | 241 | * On 603+, only set IBAT when _PAGE_EXEC is set |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 242 | */ |
Becky Bruce | 7c5c432 | 2008-06-14 09:41:42 +1000 | [diff] [blame] | 243 | void __init setbat(int index, unsigned long virt, phys_addr_t phys, |
Michael Ellerman | 5dd4e4f | 2015-03-25 20:11:55 +1100 | [diff] [blame] | 244 | unsigned int size, pgprot_t prot) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 245 | { |
| 246 | unsigned int bl; |
| 247 | int wimgxpp; |
Becky Bruce | 316a405 | 2008-06-14 09:41:43 +1000 | [diff] [blame] | 248 | struct ppc_bat *bat = BATS[index]; |
Michael Ellerman | 5dd4e4f | 2015-03-25 20:11:55 +1100 | [diff] [blame] | 249 | unsigned long flags = pgprot_val(prot); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 250 | |
Gerhard Pircher | 4c456a6 | 2009-01-23 06:51:28 +0000 | [diff] [blame] | 251 | if ((flags & _PAGE_NO_CACHE) || |
| 252 | (cpu_has_feature(CPU_FTR_NEED_COHERENT) == 0)) |
| 253 | flags &= ~_PAGE_COHERENT; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 254 | |
| 255 | bl = (size >> 17) - 1; |
| 256 | if (PVR_VER(mfspr(SPRN_PVR)) != 1) { |
| 257 | /* 603, 604, etc. */ |
| 258 | /* Do DBAT first */ |
| 259 | wimgxpp = flags & (_PAGE_WRITETHRU | _PAGE_NO_CACHE |
| 260 | | _PAGE_COHERENT | _PAGE_GUARDED); |
| 261 | wimgxpp |= (flags & _PAGE_RW)? BPP_RW: BPP_RX; |
Becky Bruce | 316a405 | 2008-06-14 09:41:43 +1000 | [diff] [blame] | 262 | bat[1].batu = virt | (bl << 2) | 2; /* Vs=1, Vp=0 */ |
| 263 | bat[1].batl = BAT_PHYS_ADDR(phys) | wimgxpp; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 264 | if (flags & _PAGE_USER) |
Becky Bruce | 316a405 | 2008-06-14 09:41:43 +1000 | [diff] [blame] | 265 | bat[1].batu |= 1; /* Vp = 1 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 266 | if (flags & _PAGE_GUARDED) { |
| 267 | /* G bit must be zero in IBATs */ |
Christophe Leroy | df25f86 | 2019-02-21 19:08:43 +0000 | [diff] [blame] | 268 | flags &= ~_PAGE_EXEC; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 269 | } |
Christophe Leroy | df25f86 | 2019-02-21 19:08:43 +0000 | [diff] [blame] | 270 | if (flags & _PAGE_EXEC) |
| 271 | bat[0] = bat[1]; |
| 272 | else |
| 273 | bat[0].batu = bat[0].batl = 0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 274 | } else { |
| 275 | /* 601 cpu */ |
| 276 | if (bl > BL_8M) |
| 277 | bl = BL_8M; |
| 278 | wimgxpp = flags & (_PAGE_WRITETHRU | _PAGE_NO_CACHE |
| 279 | | _PAGE_COHERENT); |
| 280 | wimgxpp |= (flags & _PAGE_RW)? |
| 281 | ((flags & _PAGE_USER)? PP_RWRW: PP_RWXX): PP_RXRX; |
Becky Bruce | 316a405 | 2008-06-14 09:41:43 +1000 | [diff] [blame] | 282 | bat->batu = virt | wimgxpp | 4; /* Ks=0, Ku=1 */ |
| 283 | bat->batl = phys | bl | 0x40; /* V=1 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | bat_addrs[index].start = virt; |
| 287 | bat_addrs[index].limit = virt + ((bl + 1) << 17) - 1; |
| 288 | bat_addrs[index].phys = phys; |
| 289 | } |
| 290 | |
| 291 | /* |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 292 | * Preload a translation in the hash table |
| 293 | */ |
| 294 | void hash_preload(struct mm_struct *mm, unsigned long ea, |
Christophe Leroy | 34eb138 | 2018-10-09 13:51:54 +0000 | [diff] [blame] | 295 | bool is_exec, unsigned long trap) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 296 | { |
| 297 | pmd_t *pmd; |
| 298 | |
Mathieu Malaterre | d873152 | 2018-04-13 20:41:43 +0200 | [diff] [blame] | 299 | if (!Hash) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 300 | return; |
David Gibson | f1a1eb2 | 2007-05-09 15:20:37 +1000 | [diff] [blame] | 301 | pmd = pmd_offset(pud_offset(pgd_offset(mm, ea), ea), ea); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 302 | if (!pmd_none(*pmd)) |
Paul Mackerras | 6218a76 | 2006-06-11 14:15:17 +1000 | [diff] [blame] | 303 | add_hash_page(mm->context.id, ea, pmd_val(*pmd)); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 307 | * Initialize the hash table and patch the instructions in hashtable.S. |
| 308 | */ |
| 309 | void __init MMU_init_hw(void) |
| 310 | { |
| 311 | unsigned int hmask, mb, mb2; |
| 312 | unsigned int n_hpteg, lg_n_hpteg; |
| 313 | |
Christophe Leroy | 4a3a224 | 2018-11-09 17:33:22 +0000 | [diff] [blame] | 314 | if (!mmu_has_feature(MMU_FTR_HPTE_TABLE)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 315 | return; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 316 | |
| 317 | if ( ppc_md.progress ) ppc_md.progress("hash:enter", 0x105); |
| 318 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 319 | #define LG_HPTEG_SIZE 6 /* 64 bytes per HPTEG */ |
| 320 | #define SDR1_LOW_BITS ((n_hpteg - 1) >> 10) |
| 321 | #define MIN_N_HPTEG 1024 /* min 64kB hash table */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 322 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 323 | /* |
| 324 | * Allow 1 HPTE (1/8 HPTEG) for each page of memory. |
| 325 | * This is less than the recommended amount, but then |
| 326 | * Linux ain't AIX. |
| 327 | */ |
| 328 | n_hpteg = total_memory / (PAGE_SIZE * 8); |
| 329 | if (n_hpteg < MIN_N_HPTEG) |
| 330 | n_hpteg = MIN_N_HPTEG; |
| 331 | lg_n_hpteg = __ilog2(n_hpteg); |
| 332 | if (n_hpteg & (n_hpteg - 1)) { |
| 333 | ++lg_n_hpteg; /* round up if not power of 2 */ |
| 334 | n_hpteg = 1 << lg_n_hpteg; |
| 335 | } |
| 336 | Hash_size = n_hpteg << LG_HPTEG_SIZE; |
| 337 | |
| 338 | /* |
| 339 | * Find some memory for the hash table. |
| 340 | */ |
| 341 | if ( ppc_md.progress ) ppc_md.progress("hash:find piece", 0x322); |
Mike Rapoport | b63a07d | 2019-03-07 16:31:06 -0800 | [diff] [blame] | 342 | Hash = memblock_alloc(Hash_size, Hash_size); |
Mike Rapoport | 8a7f97b | 2019-03-11 23:30:31 -0700 | [diff] [blame^] | 343 | if (!Hash) |
| 344 | panic("%s: Failed to allocate %lu bytes align=0x%lx\n", |
| 345 | __func__, Hash_size, Hash_size); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 346 | _SDR1 = __pa(Hash) | SDR1_LOW_BITS; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 347 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 348 | Hash_end = (struct hash_pte *) ((unsigned long)Hash + Hash_size); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 349 | |
Tony Breeds | c7c8eed | 2008-08-01 11:38:39 +1000 | [diff] [blame] | 350 | printk("Total memory = %lldMB; using %ldkB for hash table (at %p)\n", |
| 351 | (unsigned long long)(total_memory >> 20), Hash_size >> 10, Hash); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 352 | |
| 353 | |
| 354 | /* |
| 355 | * Patch up the instructions in hashtable.S:create_hpte |
| 356 | */ |
| 357 | if ( ppc_md.progress ) ppc_md.progress("hash:patch", 0x345); |
| 358 | Hash_mask = n_hpteg - 1; |
| 359 | hmask = Hash_mask >> (16 - LG_HPTEG_SIZE); |
| 360 | mb2 = mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg; |
| 361 | if (lg_n_hpteg > 16) |
| 362 | mb2 = 16 - LG_HPTEG_SIZE; |
| 363 | |
Christophe Leroy | 6790dae | 2019-02-21 10:37:57 +0000 | [diff] [blame] | 364 | modify_instruction_site(&patch__hash_page_A0, 0xffff, |
| 365 | ((unsigned int)Hash - PAGE_OFFSET) >> 16); |
Christophe Leroy | 9efc74f | 2018-11-09 17:33:24 +0000 | [diff] [blame] | 366 | modify_instruction_site(&patch__hash_page_A1, 0x7c0, mb << 6); |
| 367 | modify_instruction_site(&patch__hash_page_A2, 0x7c0, mb2 << 6); |
| 368 | modify_instruction_site(&patch__hash_page_B, 0xffff, hmask); |
| 369 | modify_instruction_site(&patch__hash_page_C, 0xffff, hmask); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 370 | |
| 371 | /* |
| 372 | * Patch up the instructions in hashtable.S:flush_hash_page |
| 373 | */ |
Christophe Leroy | 6790dae | 2019-02-21 10:37:57 +0000 | [diff] [blame] | 374 | modify_instruction_site(&patch__flush_hash_A0, 0xffff, |
| 375 | ((unsigned int)Hash - PAGE_OFFSET) >> 16); |
Christophe Leroy | 9efc74f | 2018-11-09 17:33:24 +0000 | [diff] [blame] | 376 | modify_instruction_site(&patch__flush_hash_A1, 0x7c0, mb << 6); |
| 377 | modify_instruction_site(&patch__flush_hash_A2, 0x7c0, mb2 << 6); |
| 378 | modify_instruction_site(&patch__flush_hash_B, 0xffff, hmask); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 379 | |
| 380 | if ( ppc_md.progress ) ppc_md.progress("hash:done", 0x205); |
| 381 | } |
Benjamin Herrenschmidt | cd3db0c | 2010-07-06 15:39:02 -0700 | [diff] [blame] | 382 | |
| 383 | void setup_initial_memory_limit(phys_addr_t first_memblock_base, |
| 384 | phys_addr_t first_memblock_size) |
| 385 | { |
| 386 | /* We don't currently support the first MEMBLOCK not mapping 0 |
| 387 | * physical on those processors |
| 388 | */ |
| 389 | BUG_ON(first_memblock_base != 0); |
| 390 | |
| 391 | /* 601 can only access 16MB at the moment */ |
| 392 | if (PVR_VER(mfspr(SPRN_PVR)) == 1) |
| 393 | memblock_set_current_limit(min_t(u64, first_memblock_size, 0x01000000)); |
| 394 | else /* Anything else has 256M mapped */ |
| 395 | memblock_set_current_limit(min_t(u64, first_memblock_size, 0x10000000)); |
| 396 | } |