forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/arch/powerpc/mm/mem.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * PowerPC version
34 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
....@@ -9,12 +10,6 @@
910 *
1011 * Derived from "arch/i386/mm/init.c"
1112 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
12
- *
13
- * This program is free software; you can redistribute it and/or
14
- * modify it under the terms of the GNU General Public License
15
- * as published by the Free Software Foundation; either version
16
- * 2 of the License, or (at your option) any later version.
17
- *
1813 */
1914
2015 #include <linux/export.h>
....@@ -27,22 +22,21 @@
2722 #include <linux/mm.h>
2823 #include <linux/stddef.h>
2924 #include <linux/init.h>
30
-#include <linux/bootmem.h>
25
+#include <linux/memblock.h>
3126 #include <linux/highmem.h>
3227 #include <linux/initrd.h>
3328 #include <linux/pagemap.h>
3429 #include <linux/suspend.h>
35
-#include <linux/memblock.h>
3630 #include <linux/hugetlb.h>
3731 #include <linux/slab.h>
3832 #include <linux/vmalloc.h>
3933 #include <linux/memremap.h>
34
+#include <linux/dma-direct.h>
35
+#include <linux/kprobes.h>
4036
41
-#include <asm/pgalloc.h>
4237 #include <asm/prom.h>
4338 #include <asm/io.h>
4439 #include <asm/mmu_context.h>
45
-#include <asm/pgtable.h>
4640 #include <asm/mmu.h>
4741 #include <asm/smp.h>
4842 #include <asm/machdep.h>
....@@ -54,8 +48,12 @@
5448 #include <asm/fixmap.h>
5549 #include <asm/swiotlb.h>
5650 #include <asm/rtas.h>
51
+#include <asm/kasan.h>
52
+#include <asm/svm.h>
53
+#include <asm/mmzone.h>
54
+#include <asm/ftrace.h>
5755
58
-#include "mmu_decl.h"
56
+#include <mm/mmu_decl.h>
5957
6058 #ifndef CPU_FTR_COHERENT_ICACHE
6159 #define CPU_FTR_COHERENT_ICACHE 0 /* XXX for now */
....@@ -64,27 +62,6 @@
6462
6563 unsigned long long memory_limit;
6664 bool init_mem_is_free;
67
-
68
-#ifdef CONFIG_HIGHMEM
69
-pte_t *kmap_pte;
70
-EXPORT_SYMBOL(kmap_pte);
71
-pgprot_t kmap_prot;
72
-EXPORT_SYMBOL(kmap_prot);
73
-#define TOP_ZONE ZONE_HIGHMEM
74
-
75
-static inline pte_t *virt_to_kpte(unsigned long vaddr)
76
-{
77
- return pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr),
78
- vaddr), vaddr), vaddr);
79
-}
80
-#else
81
-#define TOP_ZONE ZONE_NORMAL
82
-#endif
83
-
84
-int page_is_ram(unsigned long pfn)
85
-{
86
- return memblock_is_memory(__pfn_to_phys(pfn));
87
-}
8865
8966 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
9067 unsigned long size, pgprot_t vma_prot)
....@@ -108,7 +85,8 @@
10885 }
10986 #endif
11087
111
-int __weak create_section_mapping(unsigned long start, unsigned long end, int nid)
88
+int __weak create_section_mapping(unsigned long start, unsigned long end,
89
+ int nid, pgprot_t prot)
11290 {
11391 return -ENODEV;
11492 }
....@@ -118,25 +96,44 @@
11896 return -ENODEV;
11997 }
12098
121
-int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
122
- bool want_memblock)
99
+#define FLUSH_CHUNK_SIZE SZ_1G
100
+/**
101
+ * flush_dcache_range_chunked(): Write any modified data cache blocks out to
102
+ * memory and invalidate them, in chunks of up to FLUSH_CHUNK_SIZE
103
+ * Does not invalidate the corresponding instruction cache blocks.
104
+ *
105
+ * @start: the start address
106
+ * @stop: the stop address (exclusive)
107
+ * @chunk: the max size of the chunks
108
+ */
109
+static void flush_dcache_range_chunked(unsigned long start, unsigned long stop,
110
+ unsigned long chunk)
111
+{
112
+ unsigned long i;
113
+
114
+ for (i = start; i < stop; i += chunk) {
115
+ flush_dcache_range(i, min(stop, i + chunk));
116
+ cond_resched();
117
+ }
118
+}
119
+
120
+int __ref arch_add_memory(int nid, u64 start, u64 size,
121
+ struct mhp_params *params)
123122 {
124123 unsigned long start_pfn = start >> PAGE_SHIFT;
125124 unsigned long nr_pages = size >> PAGE_SHIFT;
126125 int rc;
127126
128
- resize_hpt_for_hotplug(memblock_phys_mem_size());
129
-
130127 start = (unsigned long)__va(start);
131
- rc = create_section_mapping(start, start + size, nid);
128
+ rc = create_section_mapping(start, start + size, nid,
129
+ params->pgprot);
132130 if (rc) {
133131 pr_warn("Unable to create mapping for hot added memory 0x%llx..0x%llx: %d\n",
134132 start, start + size, rc);
135133 return -EFAULT;
136134 }
137
- flush_inval_dcache_range(start, start + size);
138135
139
- return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
136
+ return __add_pages(nid, start_pfn, nr_pages, params);
140137 }
141138
142139 void __ref arch_remove_memory(int nid, u64 start, u64 size,
....@@ -150,7 +147,8 @@
150147
151148 /* Remove htab bolted mappings for this section of memory */
152149 start = (unsigned long)__va(start);
153
- flush_inval_dcache_range(start, start + size);
150
+ flush_dcache_range_chunked(start, start + size, FLUSH_CHUNK_SIZE);
151
+
154152 ret = remove_section_mapping(start, start + size);
155153 WARN_ON_ONCE(ret);
156154
....@@ -158,38 +156,8 @@
158156 * hit that section of memory
159157 */
160158 vm_unmap_aliases();
161
-
162
- resize_hpt_for_hotplug(memblock_phys_mem_size());
163159 }
164160 #endif
165
-
166
-/*
167
- * walk_memory_resource() needs to make sure there is no holes in a given
168
- * memory range. PPC64 does not maintain the memory layout in /proc/iomem.
169
- * Instead it maintains it in memblock.memory structures. Walk through the
170
- * memory regions, find holes and callback for contiguous regions.
171
- */
172
-int
173
-walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
174
- void *arg, int (*func)(unsigned long, unsigned long, void *))
175
-{
176
- struct memblock_region *reg;
177
- unsigned long end_pfn = start_pfn + nr_pages;
178
- unsigned long tstart, tend;
179
- int ret = -1;
180
-
181
- for_each_memblock(memory, reg) {
182
- tstart = max(start_pfn, memblock_region_memory_base_pfn(reg));
183
- tend = min(end_pfn, memblock_region_memory_end_pfn(reg));
184
- if (tstart >= tend)
185
- continue;
186
- ret = (*func)(tstart, tend - tstart, arg);
187
- if (ret)
188
- break;
189
- }
190
- return ret;
191
-}
192
-EXPORT_SYMBOL_GPL(walk_system_ram_range);
193161
194162 #ifndef CONFIG_NEED_MULTIPLE_NODES
195163 void __init mem_topology_setup(void)
....@@ -208,23 +176,22 @@
208176
209177 void __init initmem_init(void)
210178 {
211
- /* XXX need to clip this if using highmem? */
212
- sparse_memory_present_with_active_regions(0);
213179 sparse_init();
214180 }
215181
216182 /* mark pages that don't exist as nosave */
217183 static int __init mark_nonram_nosave(void)
218184 {
219
- struct memblock_region *reg, *prev = NULL;
185
+ unsigned long spfn, epfn, prev = 0;
186
+ int i;
220187
221
- for_each_memblock(memory, reg) {
222
- if (prev &&
223
- memblock_region_memory_end_pfn(prev) < memblock_region_memory_base_pfn(reg))
224
- register_nosave_region(memblock_region_memory_end_pfn(prev),
225
- memblock_region_memory_base_pfn(reg));
226
- prev = reg;
188
+ for_each_mem_pfn_range(i, MAX_NUMNODES, &spfn, &epfn, NULL) {
189
+ if (prev && prev < spfn)
190
+ register_nosave_region(prev, spfn);
191
+
192
+ prev = epfn;
227193 }
194
+
228195 return 0;
229196 }
230197 #else /* CONFIG_NEED_MULTIPLE_NODES */
....@@ -234,54 +201,19 @@
234201 }
235202 #endif
236203
237
-static bool zone_limits_final;
238
-
239204 /*
240
- * The memory zones past TOP_ZONE are managed by generic mm code.
241
- * These should be set to zero since that's what every other
242
- * architecture does.
243
- */
244
-static unsigned long max_zone_pfns[MAX_NR_ZONES] = {
245
- [0 ... TOP_ZONE ] = ~0UL,
246
- [TOP_ZONE + 1 ... MAX_NR_ZONES - 1] = 0
247
-};
248
-
249
-/*
250
- * Restrict the specified zone and all more restrictive zones
251
- * to be below the specified pfn. May not be called after
252
- * paging_init().
253
- */
254
-void __init limit_zone_pfn(enum zone_type zone, unsigned long pfn_limit)
255
-{
256
- int i;
257
-
258
- if (WARN_ON(zone_limits_final))
259
- return;
260
-
261
- for (i = zone; i >= 0; i--) {
262
- if (max_zone_pfns[i] > pfn_limit)
263
- max_zone_pfns[i] = pfn_limit;
264
- }
265
-}
266
-
267
-/*
268
- * Find the least restrictive zone that is entirely below the
269
- * specified pfn limit. Returns < 0 if no suitable zone is found.
205
+ * Zones usage:
270206 *
271
- * pfn_limit must be u64 because it can exceed 32 bits even on 32-bit
272
- * systems -- the DMA limit can be higher than any possible real pfn.
207
+ * We setup ZONE_DMA to be 31-bits on all platforms and ZONE_NORMAL to be
208
+ * everything else. GFP_DMA32 page allocations automatically fall back to
209
+ * ZONE_DMA.
210
+ *
211
+ * By using 31-bit unconditionally, we can exploit zone_dma_bits to inform the
212
+ * generic DMA mapping code. 32-bit only devices (if not handled by an IOMMU
213
+ * anyway) will take a first dip into ZONE_NORMAL and get otherwise served by
214
+ * ZONE_DMA.
273215 */
274
-int dma_pfn_limit_to_zone(u64 pfn_limit)
275
-{
276
- int i;
277
-
278
- for (i = TOP_ZONE; i >= 0; i--) {
279
- if (max_zone_pfns[i] <= pfn_limit)
280
- return i;
281
- }
282
-
283
- return -EPERM;
284
-}
216
+static unsigned long max_zone_pfns[MAX_NR_ZONES];
285217
286218 /*
287219 * paging_init() sets up the page tables - in fact we've already done this.
....@@ -291,20 +223,15 @@
291223 unsigned long long total_ram = memblock_phys_mem_size();
292224 phys_addr_t top_of_ram = memblock_end_of_DRAM();
293225
294
-#ifdef CONFIG_PPC32
295
- unsigned long v = __fix_to_virt(__end_of_fixed_addresses - 1);
296
- unsigned long end = __fix_to_virt(FIX_HOLE);
226
+#ifdef CONFIG_HIGHMEM
227
+ unsigned long v = __fix_to_virt(FIX_KMAP_END);
228
+ unsigned long end = __fix_to_virt(FIX_KMAP_BEGIN);
297229
298230 for (; v < end; v += PAGE_SIZE)
299
- map_kernel_page(v, 0, 0); /* XXX gross */
300
-#endif
231
+ map_kernel_page(v, 0, __pgprot(0)); /* XXX gross */
301232
302
-#ifdef CONFIG_HIGHMEM
303
- map_kernel_page(PKMAP_BASE, 0, 0); /* XXX gross */
233
+ map_kernel_page(PKMAP_BASE, 0, __pgprot(0)); /* XXX gross */
304234 pkmap_page_table = virt_to_kpte(PKMAP_BASE);
305
-
306
- kmap_pte = virt_to_kpte(__fix_to_virt(FIX_KMAP_BEGIN));
307
- kmap_prot = PAGE_KERNEL;
308235 #endif /* CONFIG_HIGHMEM */
309236
310237 printk(KERN_DEBUG "Top of RAM: 0x%llx, Total RAM: 0x%llx\n",
....@@ -312,12 +239,25 @@
312239 printk(KERN_DEBUG "Memory hole size: %ldMB\n",
313240 (long int)((top_of_ram - total_ram) >> 20));
314241
315
-#ifdef CONFIG_HIGHMEM
316
- limit_zone_pfn(ZONE_NORMAL, lowmem_end_addr >> PAGE_SHIFT);
242
+ /*
243
+ * Allow 30-bit DMA for very limited Broadcom wifi chips on many
244
+ * powerbooks.
245
+ */
246
+ if (IS_ENABLED(CONFIG_PPC32))
247
+ zone_dma_bits = 30;
248
+ else
249
+ zone_dma_bits = 31;
250
+
251
+#ifdef CONFIG_ZONE_DMA
252
+ max_zone_pfns[ZONE_DMA] = min(max_low_pfn,
253
+ 1UL << (zone_dma_bits - PAGE_SHIFT));
317254 #endif
318
- limit_zone_pfn(TOP_ZONE, top_of_ram >> PAGE_SHIFT);
319
- zone_limits_final = true;
320
- free_area_init_nodes(max_zone_pfns);
255
+ max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
256
+#ifdef CONFIG_HIGHMEM
257
+ max_zone_pfns[ZONE_HIGHMEM] = max_pfn;
258
+#endif
259
+
260
+ free_area_init(max_zone_pfns);
321261
322262 mark_nonram_nosave();
323263 }
....@@ -339,12 +279,18 @@
339279 * back to to-down.
340280 */
341281 memblock_set_bottom_up(true);
342
- swiotlb_init(0);
282
+ if (is_secure_guest())
283
+ svm_swiotlb_init();
284
+ else
285
+ swiotlb_init(0);
343286 #endif
344287
345288 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
346289 set_max_mapnr(max_pfn);
347
- free_all_bootmem();
290
+
291
+ kasan_late_init();
292
+
293
+ memblock_free_all();
348294
349295 #ifdef CONFIG_HIGHMEM
350296 {
....@@ -372,17 +318,18 @@
372318 mem_init_print_info(NULL);
373319 #ifdef CONFIG_PPC32
374320 pr_info("Kernel virtual memory layout:\n");
321
+#ifdef CONFIG_KASAN
322
+ pr_info(" * 0x%08lx..0x%08lx : kasan shadow mem\n",
323
+ KASAN_SHADOW_START, KASAN_SHADOW_END);
324
+#endif
375325 pr_info(" * 0x%08lx..0x%08lx : fixmap\n", FIXADDR_START, FIXADDR_TOP);
376326 #ifdef CONFIG_HIGHMEM
377327 pr_info(" * 0x%08lx..0x%08lx : highmem PTEs\n",
378328 PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP));
379329 #endif /* CONFIG_HIGHMEM */
380
-#ifdef CONFIG_NOT_COHERENT_CACHE
381
- pr_info(" * 0x%08lx..0x%08lx : consistent mem\n",
382
- IOREMAP_TOP, IOREMAP_TOP + CONFIG_CONSISTENT_SIZE);
383
-#endif /* CONFIG_NOT_COHERENT_CACHE */
384
- pr_info(" * 0x%08lx..0x%08lx : early ioremap\n",
385
- ioremap_bot, IOREMAP_TOP);
330
+ if (ioremap_bot != IOREMAP_TOP)
331
+ pr_info(" * 0x%08lx..0x%08lx : early ioremap\n",
332
+ ioremap_bot, IOREMAP_TOP);
386333 pr_info(" * 0x%08lx..0x%08lx : vmalloc & ioremap\n",
387334 VMALLOC_START, VMALLOC_END);
388335 #endif /* CONFIG_PPC32 */
....@@ -394,14 +341,125 @@
394341 mark_initmem_nx();
395342 init_mem_is_free = true;
396343 free_initmem_default(POISON_FREE_INITMEM);
344
+ ftrace_free_init_tramp();
397345 }
398346
399
-#ifdef CONFIG_BLK_DEV_INITRD
400
-void __init free_initrd_mem(unsigned long start, unsigned long end)
347
+/**
348
+ * flush_coherent_icache() - if a CPU has a coherent icache, flush it
349
+ * @addr: The base address to use (can be any valid address, the whole cache will be flushed)
350
+ * Return true if the cache was flushed, false otherwise
351
+ */
352
+static inline bool flush_coherent_icache(unsigned long addr)
401353 {
402
- free_reserved_area((void *)start, (void *)end, -1, "initrd");
354
+ /*
355
+ * For a snooping icache, we still need a dummy icbi to purge all the
356
+ * prefetched instructions from the ifetch buffers. We also need a sync
357
+ * before the icbi to order the the actual stores to memory that might
358
+ * have modified instructions with the icbi.
359
+ */
360
+ if (cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
361
+ mb(); /* sync */
362
+ allow_read_from_user((const void __user *)addr, L1_CACHE_BYTES);
363
+ icbi((void *)addr);
364
+ prevent_read_from_user((const void __user *)addr, L1_CACHE_BYTES);
365
+ mb(); /* sync */
366
+ isync();
367
+ return true;
368
+ }
369
+
370
+ return false;
403371 }
404
-#endif
372
+
373
+/**
374
+ * invalidate_icache_range() - Flush the icache by issuing icbi across an address range
375
+ * @start: the start address
376
+ * @stop: the stop address (exclusive)
377
+ */
378
+static void invalidate_icache_range(unsigned long start, unsigned long stop)
379
+{
380
+ unsigned long shift = l1_icache_shift();
381
+ unsigned long bytes = l1_icache_bytes();
382
+ char *addr = (char *)(start & ~(bytes - 1));
383
+ unsigned long size = stop - (unsigned long)addr + (bytes - 1);
384
+ unsigned long i;
385
+
386
+ for (i = 0; i < size >> shift; i++, addr += bytes)
387
+ icbi(addr);
388
+
389
+ mb(); /* sync */
390
+ isync();
391
+}
392
+
393
+/**
394
+ * flush_icache_range: Write any modified data cache blocks out to memory
395
+ * and invalidate the corresponding blocks in the instruction cache
396
+ *
397
+ * Generic code will call this after writing memory, before executing from it.
398
+ *
399
+ * @start: the start address
400
+ * @stop: the stop address (exclusive)
401
+ */
402
+void flush_icache_range(unsigned long start, unsigned long stop)
403
+{
404
+ if (flush_coherent_icache(start))
405
+ return;
406
+
407
+ clean_dcache_range(start, stop);
408
+
409
+ if (IS_ENABLED(CONFIG_44x)) {
410
+ /*
411
+ * Flash invalidate on 44x because we are passed kmapped
412
+ * addresses and this doesn't work for userspace pages due to
413
+ * the virtually tagged icache.
414
+ */
415
+ iccci((void *)start);
416
+ mb(); /* sync */
417
+ isync();
418
+ } else
419
+ invalidate_icache_range(start, stop);
420
+}
421
+EXPORT_SYMBOL(flush_icache_range);
422
+
423
+#if !defined(CONFIG_PPC_8xx) && !defined(CONFIG_PPC64)
424
+/**
425
+ * flush_dcache_icache_phys() - Flush a page by it's physical address
426
+ * @physaddr: the physical address of the page
427
+ */
428
+static void flush_dcache_icache_phys(unsigned long physaddr)
429
+{
430
+ unsigned long bytes = l1_dcache_bytes();
431
+ unsigned long nb = PAGE_SIZE / bytes;
432
+ unsigned long addr = physaddr & PAGE_MASK;
433
+ unsigned long msr, msr0;
434
+ unsigned long loop1 = addr, loop2 = addr;
435
+
436
+ msr0 = mfmsr();
437
+ msr = msr0 & ~MSR_DR;
438
+ /*
439
+ * This must remain as ASM to prevent potential memory accesses
440
+ * while the data MMU is disabled
441
+ */
442
+ asm volatile(
443
+ " mtctr %2;\n"
444
+ " mtmsr %3;\n"
445
+ " isync;\n"
446
+ "0: dcbst 0, %0;\n"
447
+ " addi %0, %0, %4;\n"
448
+ " bdnz 0b;\n"
449
+ " sync;\n"
450
+ " mtctr %2;\n"
451
+ "1: icbi 0, %1;\n"
452
+ " addi %1, %1, %4;\n"
453
+ " bdnz 1b;\n"
454
+ " sync;\n"
455
+ " mtmsr %5;\n"
456
+ " isync;\n"
457
+ : "+&r" (loop1), "+&r" (loop2)
458
+ : "r" (nb), "r" (msr), "i" (bytes), "r" (msr0)
459
+ : "ctr", "memory");
460
+}
461
+NOKPROBE_SYMBOL(flush_dcache_icache_phys)
462
+#endif // !defined(CONFIG_PPC_8xx) && !defined(CONFIG_PPC64)
405463
406464 /*
407465 * This is called when a page has been modified by the kernel.
....@@ -435,11 +493,45 @@
435493 __flush_dcache_icache(start);
436494 kunmap_atomic(start);
437495 } else {
438
- __flush_dcache_icache_phys(page_to_pfn(page) << PAGE_SHIFT);
496
+ unsigned long addr = page_to_pfn(page) << PAGE_SHIFT;
497
+
498
+ if (flush_coherent_icache(addr))
499
+ return;
500
+ flush_dcache_icache_phys(addr);
439501 }
440502 #endif
441503 }
442504 EXPORT_SYMBOL(flush_dcache_icache_page);
505
+
506
+/**
507
+ * __flush_dcache_icache(): Flush a particular page from the data cache to RAM.
508
+ * Note: this is necessary because the instruction cache does *not*
509
+ * snoop from the data cache.
510
+ *
511
+ * @page: the address of the page to flush
512
+ */
513
+void __flush_dcache_icache(void *p)
514
+{
515
+ unsigned long addr = (unsigned long)p;
516
+
517
+ if (flush_coherent_icache(addr))
518
+ return;
519
+
520
+ clean_dcache_range(addr, addr + PAGE_SIZE);
521
+
522
+ /*
523
+ * We don't flush the icache on 44x. Those have a virtual icache and we
524
+ * don't have access to the virtual address here (it's not the page
525
+ * vaddr but where it's mapped in user space). The flushing of the
526
+ * icache on these is handled elsewhere, when a change in the address
527
+ * space occurs, before returning to user space.
528
+ */
529
+
530
+ if (mmu_has_feature(MMU_FTR_TYPE_44x))
531
+ return;
532
+
533
+ invalidate_icache_range(addr, addr + PAGE_SIZE);
534
+}
443535
444536 void clear_user_page(void *page, unsigned long vaddr, struct page *pg)
445537 {
....@@ -477,7 +569,7 @@
477569 flush_dcache_page(pg);
478570 }
479571
480
-void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
572
+void flush_icache_user_page(struct vm_area_struct *vma, struct page *page,
481573 unsigned long addr, int len)
482574 {
483575 unsigned long maddr;
....@@ -486,63 +578,6 @@
486578 flush_icache_range(maddr, maddr + len);
487579 kunmap(page);
488580 }
489
-EXPORT_SYMBOL(flush_icache_user_range);
490
-
491
-/*
492
- * This is called at the end of handling a user page fault, when the
493
- * fault has been handled by updating a PTE in the linux page tables.
494
- * We use it to preload an HPTE into the hash table corresponding to
495
- * the updated linux PTE.
496
- *
497
- * This must always be called with the pte lock held.
498
- */
499
-void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
500
- pte_t *ptep)
501
-{
502
-#ifdef CONFIG_PPC_STD_MMU
503
- /*
504
- * We don't need to worry about _PAGE_PRESENT here because we are
505
- * called with either mm->page_table_lock held or ptl lock held
506
- */
507
- unsigned long access, trap;
508
-
509
- if (radix_enabled()) {
510
- prefetch((void *)address);
511
- return;
512
- }
513
-
514
- /* We only want HPTEs for linux PTEs that have _PAGE_ACCESSED set */
515
- if (!pte_young(*ptep) || address >= TASK_SIZE)
516
- return;
517
-
518
- /* We try to figure out if we are coming from an instruction
519
- * access fault and pass that down to __hash_page so we avoid
520
- * double-faulting on execution of fresh text. We have to test
521
- * for regs NULL since init will get here first thing at boot
522
- *
523
- * We also avoid filling the hash if not coming from a fault
524
- */
525
-
526
- trap = current->thread.regs ? TRAP(current->thread.regs) : 0UL;
527
- switch (trap) {
528
- case 0x300:
529
- access = 0UL;
530
- break;
531
- case 0x400:
532
- access = _PAGE_EXEC;
533
- break;
534
- default:
535
- return;
536
- }
537
-
538
- hash_preload(vma->vm_mm, address, access, trap);
539
-#endif /* CONFIG_PPC_STD_MMU */
540
-#if (defined(CONFIG_PPC_BOOK3E_64) || defined(CONFIG_PPC_FSL_BOOK3E)) \
541
- && defined(CONFIG_HUGETLB_PAGE)
542
- if (is_vm_hugetlb_page(vma))
543
- book3e_hugetlb_preload(vma, address, *ptep);
544
-#endif
545
-}
546581
547582 /*
548583 * System memory should not be in /proc/iomem but various tools expect it
....@@ -550,20 +585,24 @@
550585 */
551586 static int __init add_system_ram_resources(void)
552587 {
553
- struct memblock_region *reg;
588
+ phys_addr_t start, end;
589
+ u64 i;
554590
555
- for_each_memblock(memory, reg) {
591
+ for_each_mem_range(i, &start, &end) {
556592 struct resource *res;
557
- unsigned long base = reg->base;
558
- unsigned long size = reg->size;
559593
560594 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
561595 WARN_ON(!res);
562596
563597 if (res) {
564598 res->name = "System RAM";
565
- res->start = base;
566
- res->end = base + size - 1;
599
+ res->start = start;
600
+ /*
601
+ * In memblock, end points to the first byte after
602
+ * the range while in resourses, end points to the
603
+ * last byte in the range.
604
+ */
605
+ res->end = end - 1;
567606 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
568607 WARN_ON(request_resource(&iomem_resource, res) < 0);
569608 }
....@@ -592,3 +631,9 @@
592631 return 0;
593632 }
594633 #endif /* CONFIG_STRICT_DEVMEM */
634
+
635
+/*
636
+ * This is defined in kernel/resource.c but only powerpc needs to export it, for
637
+ * the EHEA driver. Drop this when drivers/net/ethernet/ibm/ehea is removed.
638
+ */
639
+EXPORT_SYMBOL_GPL(walk_system_ram_range);