~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/mm/nohash/book3e_pgtable.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright 2005, Paul Mackerras, IBM Corporation.
  4  * Copyright 2009, Benjamin Herrenschmidt, IBM Corporation.
  5  * Copyright 2015-2016, Aneesh Kumar K.V, IBM Corporation.
  6  */
  7 
  8 #include <linux/sched.h>
  9 #include <linux/memblock.h>
 10 #include <asm/pgalloc.h>
 11 #include <asm/tlb.h>
 12 #include <asm/dma.h>
 13 #include <asm/code-patching.h>
 14 
 15 #include <mm/mmu_decl.h>
 16 
 17 #ifdef CONFIG_SPARSEMEM_VMEMMAP
 18 /*
 19  * On Book3E CPUs, the vmemmap is currently mapped in the top half of
 20  * the vmalloc space using normal page tables, though the size of
 21  * pages encoded in the PTEs can be different
 22  */
 23 int __meminit vmemmap_create_mapping(unsigned long start,
 24                                      unsigned long page_size,
 25                                      unsigned long phys)
 26 {
 27         /* Create a PTE encoding without page size */
 28         unsigned long i, flags = _PAGE_PRESENT | _PAGE_ACCESSED |
 29                 _PAGE_KERNEL_RW;
 30 
 31         /* PTEs only contain page size encodings up to 32M */
 32         BUG_ON(mmu_psize_defs[mmu_vmemmap_psize].shift - 10 > 0xf);
 33 
 34         /* Encode the size in the PTE */
 35         flags |= (mmu_psize_defs[mmu_vmemmap_psize].shift - 10) << 8;
 36 
 37         /* For each PTE for that area, map things. Note that we don't
 38          * increment phys because all PTEs are of the large size and
 39          * thus must have the low bits clear
 40          */
 41         for (i = 0; i < page_size; i += PAGE_SIZE)
 42                 BUG_ON(map_kernel_page(start + i, phys, __pgprot(flags)));
 43 
 44         return 0;
 45 }
 46 
 47 #ifdef CONFIG_MEMORY_HOTPLUG
 48 void vmemmap_remove_mapping(unsigned long start,
 49                             unsigned long page_size)
 50 {
 51 }
 52 #endif
 53 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
 54 
 55 static void __init *early_alloc_pgtable(unsigned long size)
 56 {
 57         void *ptr;
 58 
 59         ptr = memblock_alloc_try_nid(size, size, MEMBLOCK_LOW_LIMIT,
 60                                      __pa(MAX_DMA_ADDRESS), NUMA_NO_NODE);
 61 
 62         if (!ptr)
 63                 panic("%s: Failed to allocate %lu bytes align=0x%lx max_addr=%lx\n",
 64                       __func__, size, size, __pa(MAX_DMA_ADDRESS));
 65 
 66         return ptr;
 67 }
 68 
 69 /*
 70  * map_kernel_page currently only called by __ioremap
 71  * map_kernel_page adds an entry to the ioremap page table
 72  * and adds an entry to the HPT, possibly bolting it
 73  */
 74 int __ref map_kernel_page(unsigned long ea, phys_addr_t pa, pgprot_t prot)
 75 {
 76         pgd_t *pgdp;
 77         p4d_t *p4dp;
 78         pud_t *pudp;
 79         pmd_t *pmdp;
 80         pte_t *ptep;
 81 
 82         BUILD_BUG_ON(TASK_SIZE_USER64 > PGTABLE_RANGE);
 83         if (slab_is_available()) {
 84                 pgdp = pgd_offset_k(ea);
 85                 p4dp = p4d_offset(pgdp, ea);
 86                 pudp = pud_alloc(&init_mm, p4dp, ea);
 87                 if (!pudp)
 88                         return -ENOMEM;
 89                 pmdp = pmd_alloc(&init_mm, pudp, ea);
 90                 if (!pmdp)
 91                         return -ENOMEM;
 92                 ptep = pte_alloc_kernel(pmdp, ea);
 93                 if (!ptep)
 94                         return -ENOMEM;
 95         } else {
 96                 pgdp = pgd_offset_k(ea);
 97                 p4dp = p4d_offset(pgdp, ea);
 98                 if (p4d_none(*p4dp)) {
 99                         pudp = early_alloc_pgtable(PUD_TABLE_SIZE);
100                         p4d_populate(&init_mm, p4dp, pudp);
101                 }
102                 pudp = pud_offset(p4dp, ea);
103                 if (pud_none(*pudp)) {
104                         pmdp = early_alloc_pgtable(PMD_TABLE_SIZE);
105                         pud_populate(&init_mm, pudp, pmdp);
106                 }
107                 pmdp = pmd_offset(pudp, ea);
108                 if (!pmd_present(*pmdp)) {
109                         ptep = early_alloc_pgtable(PTE_TABLE_SIZE);
110                         pmd_populate_kernel(&init_mm, pmdp, ptep);
111                 }
112                 ptep = pte_offset_kernel(pmdp, ea);
113         }
114         set_pte_at(&init_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT, prot));
115 
116         smp_wmb();
117         return 0;
118 }
119 
120 void __patch_exception(int exc, unsigned long addr)
121 {
122         unsigned int *ibase = &interrupt_base_book3e;
123 
124         /*
125          * Our exceptions vectors start with a NOP and -then- a branch
126          * to deal with single stepping from userspace which stops on
127          * the second instruction. Thus we need to patch the second
128          * instruction of the exception, not the first one.
129          */
130 
131         patch_branch(ibase + (exc / 4) + 1, addr, 0);
132 }
133 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php