blob: 203735caf6915ad6b5f49161f6a82e7e48d836cd [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002/*
3 * This file contains the routines for handling the MMU on those
4 * PowerPC implementations where the MMU substantially follows the
5 * architecture specification. This includes the 6xx, 7xx, 7xxx,
Michael Ellerman0f369102014-07-10 12:29:24 +10006 * and 8260 implementations but excludes the 8xx and 4xx.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10007 * -- paulus
8 *
9 * Derived from arch/ppc/mm/init.c:
10 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
11 *
12 * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
13 * and Cort Dougan (PReP) (cort@cs.nmt.edu)
14 * Copyright (C) 1996 Paul Mackerras
Paul Mackerras14cf11a2005-09-26 16:04:21 +100015 *
16 * Derived from "arch/i386/mm/init.c"
17 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
Paul Mackerras14cf11a2005-09-26 16:04:21 +100018 */
19
Paul Mackerras14cf11a2005-09-26 16:04:21 +100020#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/init.h>
23#include <linux/highmem.h>
Yinghai Lu95f72d12010-07-12 14:36:09 +100024#include <linux/memblock.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100025
26#include <asm/prom.h>
27#include <asm/mmu.h>
28#include <asm/machdep.h>
Christophe Leroy9efc74f2018-11-09 17:33:24 +000029#include <asm/code-patching.h>
Christophe Leroy63b2bc62019-02-21 19:08:49 +000030#include <asm/sections.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100031
Christophe Leroy9d9f2cc2019-03-29 09:59:59 +000032#include <mm/mmu_decl.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100033
Christophe Leroy69a15932020-10-01 15:35:38 +000034u8 __initdata early_hash[SZ_256K] __aligned(SZ_256K) = {0};
35
Christophe Leroy6e980b52020-10-22 06:29:32 +000036static struct hash_pte __initdata *Hash = (struct hash_pte *)early_hash;
37static unsigned long __initdata Hash_size, Hash_mask;
38static unsigned int __initdata hash_mb, hash_mb2;
39unsigned long __initdata _SDR1;
Paul Mackerras14cf11a2005-09-26 16:04:21 +100040
Becky Bruce316a4052008-06-14 09:41:43 +100041struct ppc_bat BATS[8][2]; /* 8 pairs of IBAT, DBAT */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100042
Christophe Leroy03d5b192020-10-22 06:29:29 +000043static struct batrange { /* stores address ranges mapped by BATs */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100044 unsigned long start;
45 unsigned long limit;
Becky Bruce7c5c4322008-06-14 09:41:42 +100046 phys_addr_t phys;
Jon Loeligeree0339f2006-06-17 17:52:44 -050047} bat_addrs[8];
Paul Mackerras14cf11a2005-09-26 16:04:21 +100048
Christophe Leroyf2655122020-10-22 06:29:35 +000049#ifdef CONFIG_SMP
50unsigned long mmu_hash_lock;
51#endif
52
Paul Mackerras14cf11a2005-09-26 16:04:21 +100053/*
54 * Return PA for this VA if it is mapped by a BAT, or 0
55 */
Christophe Leroy3084cdb2016-02-09 17:07:58 +010056phys_addr_t v_block_mapped(unsigned long va)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100057{
58 int b;
Christophe Leroye93ba1b2018-11-16 17:27:42 +000059 for (b = 0; b < ARRAY_SIZE(bat_addrs); ++b)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100060 if (va >= bat_addrs[b].start && va < bat_addrs[b].limit)
61 return bat_addrs[b].phys + (va - bat_addrs[b].start);
62 return 0;
63}
64
65/*
66 * Return VA for a given PA or 0 if not mapped
67 */
Christophe Leroy3084cdb2016-02-09 17:07:58 +010068unsigned long p_block_mapped(phys_addr_t pa)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100069{
70 int b;
Christophe Leroye93ba1b2018-11-16 17:27:42 +000071 for (b = 0; b < ARRAY_SIZE(bat_addrs); ++b)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100072 if (pa >= bat_addrs[b].phys
73 && pa < (bat_addrs[b].limit-bat_addrs[b].start)
74 +bat_addrs[b].phys)
75 return bat_addrs[b].start+(pa-bat_addrs[b].phys);
76 return 0;
77}
78
Christophe Leroyd37823c2022-01-10 15:29:25 +000079int __init find_free_bat(void)
Christophe Leroye4d66542019-02-21 19:08:39 +000080{
81 int b;
Christophe Leroy2e38ea42020-09-29 06:48:37 +000082 int n = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4;
Christophe Leroye4d66542019-02-21 19:08:39 +000083
Christophe Leroy2e38ea42020-09-29 06:48:37 +000084 for (b = 0; b < n; b++) {
85 struct ppc_bat *bat = BATS[b];
Christophe Leroye4d66542019-02-21 19:08:39 +000086
Christophe Leroy2e38ea42020-09-29 06:48:37 +000087 if (!(bat[1].batu & 3))
88 return b;
Christophe Leroye4d66542019-02-21 19:08:39 +000089 }
90 return -1;
91}
92
Christophe Leroy12f36352019-04-30 16:11:59 +000093/*
94 * This function calculates the size of the larger block usable to map the
95 * beginning of an area based on the start address and size of that area:
Christophe Leroy8b14e1d2020-09-29 06:48:36 +000096 * - max block size is 256 on 6xx.
Christophe Leroy12f36352019-04-30 16:11:59 +000097 * - base address must be aligned to the block size. So the maximum block size
98 * is identified by the lowest bit set to 1 in the base address (for instance
99 * if base is 0x16000000, max size is 0x02000000).
100 * - block size has to be a power of two. This is calculated by finding the
101 * highest bit set to 1.
102 */
Christophe Leroyd37823c2022-01-10 15:29:25 +0000103unsigned int bat_block_size(unsigned long base, unsigned long top)
Christophe Leroye4d66542019-02-21 19:08:39 +0000104{
Christophe Leroy8b14e1d2020-09-29 06:48:36 +0000105 unsigned int max_size = SZ_256M;
Christophe Leroy12f36352019-04-30 16:11:59 +0000106 unsigned int base_shift = (ffs(base) - 1) & 31;
Christophe Leroye4d66542019-02-21 19:08:39 +0000107 unsigned int block_shift = (fls(top - base) - 1) & 31;
108
109 return min3(max_size, 1U << base_shift, 1U << block_shift);
110}
111
Christophe Leroy5e04ae82019-02-21 19:08:48 +0000112/*
113 * Set up one of the IBAT (block address translation) register pairs.
114 * The parameters are not checked; in particular size must be a power
115 * of 2 between 128k and 256M.
Christophe Leroy5e04ae82019-02-21 19:08:48 +0000116 */
117static void setibat(int index, unsigned long virt, phys_addr_t phys,
118 unsigned int size, pgprot_t prot)
119{
120 unsigned int bl = (size >> 17) - 1;
121 int wimgxpp;
122 struct ppc_bat *bat = BATS[index];
123 unsigned long flags = pgprot_val(prot);
124
125 if (!cpu_has_feature(CPU_FTR_NEED_COHERENT))
126 flags &= ~_PAGE_COHERENT;
127
128 wimgxpp = (flags & _PAGE_COHERENT) | (_PAGE_EXEC ? BPP_RX : BPP_XX);
129 bat[0].batu = virt | (bl << 2) | 2; /* Vs=1, Vp=0 */
130 bat[0].batl = BAT_PHYS_ADDR(phys) | wimgxpp;
131 if (flags & _PAGE_USER)
132 bat[0].batu |= 1; /* Vp = 1 */
133}
134
135static void clearibat(int index)
136{
137 struct ppc_bat *bat = BATS[index];
138
139 bat[0].batu = 0;
140 bat[0].batl = 0;
141}
142
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000143static unsigned long __init __mmu_mapin_ram(unsigned long base, unsigned long top)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000144{
Christophe Leroye4d66542019-02-21 19:08:39 +0000145 int idx;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000146
Christophe Leroye4d66542019-02-21 19:08:39 +0000147 while ((idx = find_free_bat()) != -1 && base != top) {
Christophe Leroyd37823c2022-01-10 15:29:25 +0000148 unsigned int size = bat_block_size(base, top);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000149
Christophe Leroye4d66542019-02-21 19:08:39 +0000150 if (size < 128 << 10)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000151 break;
Christophe Leroye4d66542019-02-21 19:08:39 +0000152 setbat(idx, PAGE_OFFSET + base, base, size, PAGE_KERNEL_X);
153 base += size;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000154 }
155
Christophe Leroye4d66542019-02-21 19:08:39 +0000156 return base;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000157}
158
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000159unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
160{
Christophe Leroy12f36352019-04-30 16:11:59 +0000161 unsigned long done;
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000162 unsigned long border = (unsigned long)__init_begin - PAGE_OFFSET;
163
Christophe Leroy035b19a2020-11-25 07:10:46 +0000164
Christophe Leroy90cbac02021-03-04 14:35:09 +0000165 if (debug_pagealloc_enabled_or_kfence() || __map_without_bats) {
Christophe Leroy035b19a2020-11-25 07:10:46 +0000166 pr_debug_once("Read-Write memory mapped without BATs\n");
Christophe Leroy2b279c02020-05-19 05:49:28 +0000167 if (base >= border)
168 return base;
169 if (top >= border)
170 top = border;
171 }
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000172
173 if (!strict_kernel_rwx_enabled() || base >= border || top <= border)
174 return __mmu_mapin_ram(base, top);
175
176 done = __mmu_mapin_ram(base, border);
Christophe Leroy12f36352019-04-30 16:11:59 +0000177 if (done != border)
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000178 return done;
179
Christophe Leroy12f36352019-04-30 16:11:59 +0000180 return __mmu_mapin_ram(border, top);
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000181}
182
Christophe Leroyc4964332020-06-29 11:15:22 +0000183static bool is_module_segment(unsigned long addr)
184{
185 if (!IS_ENABLED(CONFIG_MODULES))
186 return false;
Christophe Leroy7bee31a2020-08-05 15:27:28 +0000187 if (addr < ALIGN_DOWN(MODULES_VADDR, SZ_256M))
188 return false;
Christophe Leroy541cebb2020-08-21 07:15:25 +0000189 if (addr > ALIGN(MODULES_END, SZ_256M) - 1)
Christophe Leroy7bee31a2020-08-05 15:27:28 +0000190 return false;
Christophe Leroyc4964332020-06-29 11:15:22 +0000191 return true;
192}
193
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000194void mmu_mark_initmem_nx(void)
195{
196 int nb = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4;
197 int i;
198 unsigned long base = (unsigned long)_stext - PAGE_OFFSET;
Christophe Leroy37eb7ca2021-11-26 13:40:35 +0100199 unsigned long top = ALIGN((unsigned long)_etext - PAGE_OFFSET, SZ_128K);
Christophe Leroy4b19f962020-05-19 05:48:56 +0000200 unsigned long border = (unsigned long)__init_begin - PAGE_OFFSET;
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000201 unsigned long size;
202
Christophe Leroy37eb7ca2021-11-26 13:40:35 +0100203 for (i = 0; i < nb - 1 && base < top;) {
Christophe Leroyd37823c2022-01-10 15:29:25 +0000204 size = bat_block_size(base, top);
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000205 setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_TEXT);
206 base += size;
207 }
208 if (base < top) {
Christophe Leroyd37823c2022-01-10 15:29:25 +0000209 size = bat_block_size(base, top);
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000210 if ((top - base) > size) {
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000211 size <<= 1;
Christophe Leroy4b19f962020-05-19 05:48:56 +0000212 if (strict_kernel_rwx_enabled() && base + size > border)
213 pr_warn("Some RW data is getting mapped X. "
214 "Adjust CONFIG_DATA_SHIFT to avoid that.\n");
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000215 }
216 setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_TEXT);
217 base += size;
218 }
219 for (; i < nb; i++)
220 clearibat(i);
221
222 update_bats();
223
224 for (i = TASK_SIZE >> 28; i < 16; i++) {
225 /* Do not set NX on VM space for modules */
Christophe Leroyc4964332020-06-29 11:15:22 +0000226 if (is_module_segment(i << 28))
227 continue;
228
Christophe Leroy179ae572021-02-06 11:47:27 +0000229 mtsr(mfsr(i << 28) | 0x10000000, i << 28);
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000230 }
231}
232
233void mmu_mark_rodata_ro(void)
234{
235 int nb = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4;
236 int i;
237
Christophe Leroy63b2bc62019-02-21 19:08:49 +0000238 for (i = 0; i < nb; i++) {
239 struct ppc_bat *bat = BATS[i];
240
241 if (bat_addrs[i].start < (unsigned long)__init_begin)
242 bat[1].batl = (bat[1].batl & ~BPP_RW) | BPP_RX;
243 }
244
245 update_bats();
246}
247
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000248/*
249 * Set up one of the I/D BAT (block address translation) register pairs.
250 * The parameters are not checked; in particular size must be a power
251 * of 2 between 128k and 256M.
Christophe Leroydf25f862019-02-21 19:08:43 +0000252 * On 603+, only set IBAT when _PAGE_EXEC is set
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000253 */
Becky Bruce7c5c4322008-06-14 09:41:42 +1000254void __init setbat(int index, unsigned long virt, phys_addr_t phys,
Michael Ellerman5dd4e4f2015-03-25 20:11:55 +1100255 unsigned int size, pgprot_t prot)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000256{
257 unsigned int bl;
258 int wimgxpp;
Christophe Leroycbcaff72019-09-16 20:25:39 +0000259 struct ppc_bat *bat;
Michael Ellerman5dd4e4f2015-03-25 20:11:55 +1100260 unsigned long flags = pgprot_val(prot);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000261
Christophe Leroycbcaff72019-09-16 20:25:39 +0000262 if (index == -1)
263 index = find_free_bat();
264 if (index == -1) {
265 pr_err("%s: no BAT available for mapping 0x%llx\n", __func__,
266 (unsigned long long)phys);
267 return;
268 }
269 bat = BATS[index];
270
Gerhard Pircher4c456a62009-01-23 06:51:28 +0000271 if ((flags & _PAGE_NO_CACHE) ||
272 (cpu_has_feature(CPU_FTR_NEED_COHERENT) == 0))
273 flags &= ~_PAGE_COHERENT;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000274
275 bl = (size >> 17) - 1;
Christophe Leroy2e38ea42020-09-29 06:48:37 +0000276 /* Do DBAT first */
277 wimgxpp = flags & (_PAGE_WRITETHRU | _PAGE_NO_CACHE
278 | _PAGE_COHERENT | _PAGE_GUARDED);
279 wimgxpp |= (flags & _PAGE_RW)? BPP_RW: BPP_RX;
280 bat[1].batu = virt | (bl << 2) | 2; /* Vs=1, Vp=0 */
281 bat[1].batl = BAT_PHYS_ADDR(phys) | wimgxpp;
282 if (flags & _PAGE_USER)
283 bat[1].batu |= 1; /* Vp = 1 */
284 if (flags & _PAGE_GUARDED) {
285 /* G bit must be zero in IBATs */
286 flags &= ~_PAGE_EXEC;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000287 }
Christophe Leroy2e38ea42020-09-29 06:48:37 +0000288 if (flags & _PAGE_EXEC)
289 bat[0] = bat[1];
290 else
291 bat[0].batu = bat[0].batl = 0;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000292
293 bat_addrs[index].start = virt;
294 bat_addrs[index].limit = virt + ((bl + 1) << 17) - 1;
295 bat_addrs[index].phys = phys;
296}
297
298/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100299 * Preload a translation in the hash table
300 */
Christophe Leroy79d1bef2020-11-25 07:10:47 +0000301static void hash_preload(struct mm_struct *mm, unsigned long ea)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100302{
303 pmd_t *pmd;
304
Christophe Leroy4cc445b2020-10-22 06:29:30 +0000305 if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100306 return;
Mike Rapoporte05c7b12020-06-08 21:33:05 -0700307 pmd = pmd_off(mm, ea);
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100308 if (!pmd_none(*pmd))
Paul Mackerras6218a762006-06-11 14:15:17 +1000309 add_hash_page(mm->context.id, ea, pmd_val(*pmd));
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100310}
311
312/*
Christophe Leroye5a1edb2019-08-16 05:41:42 +0000313 * This is called at the end of handling a user page fault, when the
314 * fault has been handled by updating a PTE in the linux page tables.
315 * We use it to preload an HPTE into the hash table corresponding to
316 * the updated linux PTE.
317 *
318 * This must always be called with the pte lock held.
319 */
320void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
321 pte_t *ptep)
322{
Christophe Leroyf2043382019-08-16 05:41:44 +0000323 if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
324 return;
Christophe Leroye5a1edb2019-08-16 05:41:42 +0000325 /*
326 * We don't need to worry about _PAGE_PRESENT here because we are
327 * called with either mm->page_table_lock held or ptl lock held
328 */
Christophe Leroye5a1edb2019-08-16 05:41:42 +0000329
330 /* We only want HPTEs for linux PTEs that have _PAGE_ACCESSED set */
331 if (!pte_young(*ptep) || address >= TASK_SIZE)
332 return;
333
Christophe Leroyf49f4e22019-08-16 05:41:43 +0000334 /* We have to test for regs NULL since init will get here first thing at boot */
335 if (!current->thread.regs)
Christophe Leroye5a1edb2019-08-16 05:41:42 +0000336 return;
Christophe Leroye5a1edb2019-08-16 05:41:42 +0000337
Christophe Leroyf49f4e22019-08-16 05:41:43 +0000338 /* We also avoid filling the hash if not coming from a fault */
339 if (TRAP(current->thread.regs) != 0x300 && TRAP(current->thread.regs) != 0x400)
340 return;
341
342 hash_preload(vma->vm_mm, address);
Christophe Leroye5a1edb2019-08-16 05:41:42 +0000343}
344
345/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000346 * Initialize the hash table and patch the instructions in hashtable.S.
347 */
348void __init MMU_init_hw(void)
349{
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000350 unsigned int n_hpteg, lg_n_hpteg;
351
Christophe Leroy4a3a2242018-11-09 17:33:22 +0000352 if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000353 return;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000354
355 if ( ppc_md.progress ) ppc_md.progress("hash:enter", 0x105);
356
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000357#define LG_HPTEG_SIZE 6 /* 64 bytes per HPTEG */
358#define SDR1_LOW_BITS ((n_hpteg - 1) >> 10)
359#define MIN_N_HPTEG 1024 /* min 64kB hash table */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000360
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000361 /*
362 * Allow 1 HPTE (1/8 HPTEG) for each page of memory.
363 * This is less than the recommended amount, but then
364 * Linux ain't AIX.
365 */
366 n_hpteg = total_memory / (PAGE_SIZE * 8);
367 if (n_hpteg < MIN_N_HPTEG)
368 n_hpteg = MIN_N_HPTEG;
369 lg_n_hpteg = __ilog2(n_hpteg);
370 if (n_hpteg & (n_hpteg - 1)) {
371 ++lg_n_hpteg; /* round up if not power of 2 */
372 n_hpteg = 1 << lg_n_hpteg;
373 }
374 Hash_size = n_hpteg << LG_HPTEG_SIZE;
375
376 /*
377 * Find some memory for the hash table.
378 */
379 if ( ppc_md.progress ) ppc_md.progress("hash:find piece", 0x322);
Mike Rapoportb63a07d2019-03-07 16:31:06 -0800380 Hash = memblock_alloc(Hash_size, Hash_size);
Mike Rapoport8a7f97b2019-03-11 23:30:31 -0700381 if (!Hash)
382 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
383 __func__, Hash_size, Hash_size);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000384 _SDR1 = __pa(Hash) | SDR1_LOW_BITS;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000385
Christophe Leroy8f156c22019-04-26 16:36:37 +0000386 pr_info("Total memory = %lldMB; using %ldkB for hash table\n",
387 (unsigned long long)(total_memory >> 20), Hash_size >> 10);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000388
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000389
Christophe Leroy72f208c2019-04-26 16:23:35 +0000390 Hash_mask = n_hpteg - 1;
391 hash_mb2 = hash_mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg;
392 if (lg_n_hpteg > 16)
393 hash_mb2 = 16 - LG_HPTEG_SIZE;
394}
395
396void __init MMU_init_hw_patch(void)
397{
398 unsigned int hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
Christophe Leroy232ca1e2020-02-15 10:14:25 +0000399 unsigned int hash = (unsigned int)Hash - PAGE_OFFSET;
Christophe Leroy72f208c2019-04-26 16:23:35 +0000400
Christophe Leroy69a15932020-10-01 15:35:38 +0000401 if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
402 return;
403
Christophe Leroy72f208c2019-04-26 16:23:35 +0000404 if (ppc_md.progress)
405 ppc_md.progress("hash:patch", 0x345);
406 if (ppc_md.progress)
407 ppc_md.progress("hash:done", 0x205);
408
409 /* WARNING: Make sure nothing can trigger a KASAN check past this point */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000410
411 /*
412 * Patch up the instructions in hashtable.S:create_hpte
413 */
Christophe Leroycd08f102019-12-21 08:32:38 +0000414 modify_instruction_site(&patch__hash_page_A0, 0xffff, hash >> 16);
Christophe Leroy72f208c2019-04-26 16:23:35 +0000415 modify_instruction_site(&patch__hash_page_A1, 0x7c0, hash_mb << 6);
416 modify_instruction_site(&patch__hash_page_A2, 0x7c0, hash_mb2 << 6);
Christophe Leroy9efc74f2018-11-09 17:33:24 +0000417 modify_instruction_site(&patch__hash_page_B, 0xffff, hmask);
418 modify_instruction_site(&patch__hash_page_C, 0xffff, hmask);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000419
420 /*
421 * Patch up the instructions in hashtable.S:flush_hash_page
422 */
Christophe Leroy232ca1e2020-02-15 10:14:25 +0000423 modify_instruction_site(&patch__flush_hash_A0, 0xffff, hash >> 16);
Christophe Leroy72f208c2019-04-26 16:23:35 +0000424 modify_instruction_site(&patch__flush_hash_A1, 0x7c0, hash_mb << 6);
425 modify_instruction_site(&patch__flush_hash_A2, 0x7c0, hash_mb2 << 6);
Christophe Leroy9efc74f2018-11-09 17:33:24 +0000426 modify_instruction_site(&patch__flush_hash_B, 0xffff, hmask);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000427}
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700428
429void setup_initial_memory_limit(phys_addr_t first_memblock_base,
430 phys_addr_t first_memblock_size)
431{
432 /* We don't currently support the first MEMBLOCK not mapping 0
433 * physical on those processors
434 */
435 BUG_ON(first_memblock_base != 0);
436
Christophe Leroy8b14e1d2020-09-29 06:48:36 +0000437 memblock_set_current_limit(min_t(u64, first_memblock_size, SZ_256M));
Benjamin Herrenschmidtcd3db0c2010-07-06 15:39:02 -0700438}
Christophe Leroy31ed2b12019-03-11 08:30:35 +0000439
Christophe Leroye4dccf92019-04-26 16:36:39 +0000440void __init print_system_hash_info(void)
441{
442 pr_info("Hash_size = 0x%lx\n", Hash_size);
443 if (Hash_mask)
444 pr_info("Hash_mask = 0x%lx\n", Hash_mask);
445}
446
Christophe Leroy068fdba2020-10-22 06:29:41 +0000447void __init early_init_mmu(void)
448{
449}