forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/arch/powerpc/include/asm/book3s/64/hash.h
....@@ -18,12 +18,21 @@
1818 #include <asm/book3s/64/hash-4k.h>
1919 #endif
2020
21
+/* Bits to set in a PMD/PUD/PGD entry valid bit*/
22
+#define HASH_PMD_VAL_BITS (0x8000000000000000UL)
23
+#define HASH_PUD_VAL_BITS (0x8000000000000000UL)
24
+#define HASH_PGD_VAL_BITS (0x8000000000000000UL)
25
+
2126 /*
2227 * Size of EA range mapped by our pagetables.
2328 */
2429 #define H_PGTABLE_EADDR_SIZE (H_PTE_INDEX_SIZE + H_PMD_INDEX_SIZE + \
2530 H_PUD_INDEX_SIZE + H_PGD_INDEX_SIZE + PAGE_SHIFT)
2631 #define H_PGTABLE_RANGE (ASM_CONST(1) << H_PGTABLE_EADDR_SIZE)
32
+/*
33
+ * Top 2 bits are ignored in page table walk.
34
+ */
35
+#define EA_MASK (~(0xcUL << 60))
2736
2837 /*
2938 * We store the slot details in the second half of page table.
....@@ -35,46 +44,65 @@
3544 #else
3645 #define H_PUD_CACHE_INDEX (H_PUD_INDEX_SIZE)
3746 #endif
38
-/*
39
- * Define the address range of the kernel non-linear virtual area
40
- */
41
-#define H_KERN_VIRT_START ASM_CONST(0xD000000000000000)
42
-#define H_KERN_VIRT_SIZE ASM_CONST(0x0000400000000000) /* 64T */
4347
4448 /*
45
- * The vmalloc space starts at the beginning of that region, and
46
- * occupies half of it on hash CPUs and a quarter of it on Book3E
47
- * (we keep a quarter for the virtual memmap)
49
+ * +------------------------------+
50
+ * | |
51
+ * | |
52
+ * | |
53
+ * +------------------------------+ Kernel virtual map end (0xc00e000000000000)
54
+ * | |
55
+ * | |
56
+ * | 512TB/16TB of vmemmap |
57
+ * | |
58
+ * | |
59
+ * +------------------------------+ Kernel vmemmap start
60
+ * | |
61
+ * | 512TB/16TB of IO map |
62
+ * | |
63
+ * +------------------------------+ Kernel IO map start
64
+ * | |
65
+ * | 512TB/16TB of vmap |
66
+ * | |
67
+ * +------------------------------+ Kernel virt start (0xc008000000000000)
68
+ * | |
69
+ * | |
70
+ * | |
71
+ * +------------------------------+ Kernel linear (0xc.....)
4872 */
49
-#define H_VMALLOC_START H_KERN_VIRT_START
50
-#define H_VMALLOC_SIZE ASM_CONST(0x380000000000) /* 56T */
51
-#define H_VMALLOC_END (H_VMALLOC_START + H_VMALLOC_SIZE)
5273
53
-#define H_KERN_IO_START H_VMALLOC_END
74
+#define H_VMALLOC_START H_KERN_VIRT_START
75
+#define H_VMALLOC_SIZE H_KERN_MAP_SIZE
76
+#define H_VMALLOC_END (H_VMALLOC_START + H_VMALLOC_SIZE)
77
+
78
+#define H_KERN_IO_START H_VMALLOC_END
79
+#define H_KERN_IO_SIZE H_KERN_MAP_SIZE
80
+#define H_KERN_IO_END (H_KERN_IO_START + H_KERN_IO_SIZE)
81
+
82
+#define H_VMEMMAP_START H_KERN_IO_END
83
+#define H_VMEMMAP_SIZE H_KERN_MAP_SIZE
84
+#define H_VMEMMAP_END (H_VMEMMAP_START + H_VMEMMAP_SIZE)
85
+
86
+#define NON_LINEAR_REGION_ID(ea) ((((unsigned long)ea - H_KERN_VIRT_START) >> REGION_SHIFT) + 2)
5487
5588 /*
5689 * Region IDs
5790 */
58
-#define REGION_SHIFT 60UL
59
-#define REGION_MASK (0xfUL << REGION_SHIFT)
60
-#define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
61
-
62
-#define VMALLOC_REGION_ID (REGION_ID(H_VMALLOC_START))
63
-#define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET))
64
-#define VMEMMAP_REGION_ID (0xfUL) /* Server only */
65
-#define USER_REGION_ID (0UL)
91
+#define USER_REGION_ID 0
92
+#define LINEAR_MAP_REGION_ID 1
93
+#define VMALLOC_REGION_ID NON_LINEAR_REGION_ID(H_VMALLOC_START)
94
+#define IO_REGION_ID NON_LINEAR_REGION_ID(H_KERN_IO_START)
95
+#define VMEMMAP_REGION_ID NON_LINEAR_REGION_ID(H_VMEMMAP_START)
96
+#define INVALID_REGION_ID (VMEMMAP_REGION_ID + 1)
6697
6798 /*
6899 * Defines the address of the vmemap area, in its own region on
69100 * hash table CPUs.
70101 */
71
-#define H_VMEMMAP_BASE (VMEMMAP_REGION_ID << REGION_SHIFT)
72
-
73102 #ifdef CONFIG_PPC_MM_SLICES
74103 #define HAVE_ARCH_UNMAPPED_AREA
75104 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
76105 #endif /* CONFIG_PPC_MM_SLICES */
77
-
78106
79107 /* PTEIDX nibble */
80108 #define _PTEIDX_SECONDARY 0x8
....@@ -84,11 +112,31 @@
84112 #define H_PUD_BAD_BITS (PMD_TABLE_SIZE-1)
85113
86114 #ifndef __ASSEMBLY__
115
+static inline int get_region_id(unsigned long ea)
116
+{
117
+ int region_id;
118
+ int id = (ea >> 60UL);
119
+
120
+ if (id == 0)
121
+ return USER_REGION_ID;
122
+
123
+ if (id != (PAGE_OFFSET >> 60))
124
+ return INVALID_REGION_ID;
125
+
126
+ if (ea < H_KERN_VIRT_START)
127
+ return LINEAR_MAP_REGION_ID;
128
+
129
+ BUILD_BUG_ON(NON_LINEAR_REGION_ID(H_VMALLOC_START) != 2);
130
+
131
+ region_id = NON_LINEAR_REGION_ID(ea);
132
+ return region_id;
133
+}
134
+
87135 #define hash__pmd_bad(pmd) (pmd_val(pmd) & H_PMD_BAD_BITS)
88136 #define hash__pud_bad(pud) (pud_val(pud) & H_PUD_BAD_BITS)
89
-static inline int hash__pgd_bad(pgd_t pgd)
137
+static inline int hash__p4d_bad(p4d_t p4d)
90138 {
91
- return (pgd_val(pgd) == 0);
139
+ return (p4d_val(p4d) == 0);
92140 }
93141 #ifdef CONFIG_STRICT_KERNEL_RWX
94142 extern void hash__mark_rodata_ro(void);
....@@ -196,15 +244,15 @@
196244 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
197245
198246
199
-extern int hash__map_kernel_page(unsigned long ea, unsigned long pa,
200
- unsigned long flags);
247
+int hash__map_kernel_page(unsigned long ea, unsigned long pa, pgprot_t prot);
201248 extern int __meminit hash__vmemmap_create_mapping(unsigned long start,
202249 unsigned long page_size,
203250 unsigned long phys);
204251 extern void hash__vmemmap_remove_mapping(unsigned long start,
205252 unsigned long page_size);
206253
207
-int hash__create_section_mapping(unsigned long start, unsigned long end, int nid);
254
+int hash__create_section_mapping(unsigned long start, unsigned long end,
255
+ int nid, pgprot_t prot);
208256 int hash__remove_section_mapping(unsigned long start, unsigned long end);
209257
210258 #endif /* !__ASSEMBLY__ */