Adrian Bunk | b00dc83 | 2008-05-19 16:52:27 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * arch/sparc64/mm/init.c |
| 3 | * |
| 4 | * Copyright (C) 1996-1999 David S. Miller (davem@caip.rutgers.edu) |
| 5 | * Copyright (C) 1997-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 6 | */ |
| 7 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 8 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/string.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/bootmem.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/hugetlb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/initrd.h> |
| 17 | #include <linux/swap.h> |
| 18 | #include <linux/pagemap.h> |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 19 | #include <linux/poison.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/fs.h> |
| 21 | #include <linux/seq_file.h> |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 22 | #include <linux/kprobes.h> |
David S. Miller | 1ac4f5e | 2005-09-21 21:49:32 -0700 | [diff] [blame] | 23 | #include <linux/cache.h> |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 24 | #include <linux/sort.h> |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 25 | #include <linux/percpu.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 26 | #include <linux/memblock.h> |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 27 | #include <linux/mmzone.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <asm/head.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/page.h> |
| 32 | #include <asm/pgalloc.h> |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/oplib.h> |
| 35 | #include <asm/iommu.h> |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/uaccess.h> |
| 38 | #include <asm/mmu_context.h> |
| 39 | #include <asm/tlbflush.h> |
| 40 | #include <asm/dma.h> |
| 41 | #include <asm/starfire.h> |
| 42 | #include <asm/tlb.h> |
| 43 | #include <asm/spitfire.h> |
| 44 | #include <asm/sections.h> |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 45 | #include <asm/tsb.h> |
David S. Miller | 481295f | 2006-02-07 21:51:08 -0800 | [diff] [blame] | 46 | #include <asm/hypervisor.h> |
David S. Miller | 372b07b | 2006-06-21 15:35:28 -0700 | [diff] [blame] | 47 | #include <asm/prom.h> |
David S. Miller | 5cbc307 | 2007-05-25 15:49:59 -0700 | [diff] [blame] | 48 | #include <asm/mdesc.h> |
David S. Miller | 3d5ae6b | 2008-03-25 21:51:40 -0700 | [diff] [blame] | 49 | #include <asm/cpudata.h> |
Sam Ravnborg | 59dec13 | 2014-05-16 23:26:07 +0200 | [diff] [blame^] | 50 | #include <asm/setup.h> |
David S. Miller | 4f70f7a | 2008-08-12 18:33:56 -0700 | [diff] [blame] | 51 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Sam Ravnborg | 27137e5 | 2008-11-16 20:08:45 -0800 | [diff] [blame] | 53 | #include "init_64.h" |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 54 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 55 | unsigned long kern_linear_pte_xor[4] __read_mostly; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 56 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 57 | /* A bitmap, two bits for every 256MB of physical memory. These two |
| 58 | * bits determine what page size we use for kernel linear |
| 59 | * translations. They form an index into kern_linear_pte_xor[]. The |
| 60 | * value in the indexed slot is XOR'd with the TLB miss virtual |
| 61 | * address to form the resulting TTE. The mapping is: |
| 62 | * |
| 63 | * 0 ==> 4MB |
| 64 | * 1 ==> 256MB |
| 65 | * 2 ==> 2GB |
| 66 | * 3 ==> 16GB |
| 67 | * |
| 68 | * All sun4v chips support 256MB pages. Only SPARC-T4 and later |
| 69 | * support 2GB pages, and hopefully future cpus will support the 16GB |
| 70 | * pages as well. For slots 2 and 3, we encode a 256MB TTE xor there |
| 71 | * if these larger page sizes are not supported by the cpu. |
| 72 | * |
| 73 | * It would be nice to determine this from the machine description |
| 74 | * 'cpu' properties, but we need to have this table setup before the |
| 75 | * MDESC is initialized. |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 76 | */ |
| 77 | unsigned long kpte_linear_bitmap[KPTE_BITMAP_BYTES / sizeof(unsigned long)]; |
| 78 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 79 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 80 | /* A special kernel TSB for 4MB, 256MB, 2GB and 16GB linear mappings. |
| 81 | * Space is allocated for this right after the trap table in |
| 82 | * arch/sparc64/kernel/head.S |
David S. Miller | 2d9e276 | 2007-05-29 01:58:31 -0700 | [diff] [blame] | 83 | */ |
| 84 | extern struct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES]; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 85 | #endif |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 86 | |
David S. Miller | ce33fdc | 2012-09-06 19:01:25 -0700 | [diff] [blame] | 87 | static unsigned long cpu_pgsz_mask; |
| 88 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 89 | #define MAX_BANKS 32 |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 90 | |
Greg Kroah-Hartman | 7c9503b | 2012-12-21 14:03:26 -0800 | [diff] [blame] | 91 | static struct linux_prom64_registers pavail[MAX_BANKS]; |
| 92 | static int pavail_ents; |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 93 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 94 | static int cmp_p64(const void *a, const void *b) |
| 95 | { |
| 96 | const struct linux_prom64_registers *x = a, *y = b; |
| 97 | |
| 98 | if (x->phys_addr > y->phys_addr) |
| 99 | return 1; |
| 100 | if (x->phys_addr < y->phys_addr) |
| 101 | return -1; |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static void __init read_obp_memory(const char *property, |
| 106 | struct linux_prom64_registers *regs, |
| 107 | int *num_ents) |
| 108 | { |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 109 | phandle node = prom_finddevice("/memory"); |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 110 | int prop_size = prom_getproplen(node, property); |
| 111 | int ents, ret, i; |
| 112 | |
| 113 | ents = prop_size / sizeof(struct linux_prom64_registers); |
| 114 | if (ents > MAX_BANKS) { |
| 115 | prom_printf("The machine has more %s property entries than " |
| 116 | "this kernel can support (%d).\n", |
| 117 | property, MAX_BANKS); |
| 118 | prom_halt(); |
| 119 | } |
| 120 | |
| 121 | ret = prom_getproperty(node, property, (char *) regs, prop_size); |
| 122 | if (ret == -1) { |
Akinobu Mita | 5da444a | 2012-09-29 03:14:49 +0000 | [diff] [blame] | 123 | prom_printf("Couldn't get %s property from /memory.\n", |
| 124 | property); |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 125 | prom_halt(); |
| 126 | } |
| 127 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 128 | /* Sanitize what we got from the firmware, by page aligning |
| 129 | * everything. |
| 130 | */ |
| 131 | for (i = 0; i < ents; i++) { |
| 132 | unsigned long base, size; |
| 133 | |
| 134 | base = regs[i].phys_addr; |
| 135 | size = regs[i].reg_size; |
| 136 | |
| 137 | size &= PAGE_MASK; |
| 138 | if (base & ~PAGE_MASK) { |
| 139 | unsigned long new_base = PAGE_ALIGN(base); |
| 140 | |
| 141 | size -= new_base - base; |
| 142 | if ((long) size < 0L) |
| 143 | size = 0UL; |
| 144 | base = new_base; |
| 145 | } |
David S. Miller | 0015d3d | 2007-03-15 00:06:34 -0700 | [diff] [blame] | 146 | if (size == 0UL) { |
| 147 | /* If it is empty, simply get rid of it. |
| 148 | * This simplifies the logic of the other |
| 149 | * functions that process these arrays. |
| 150 | */ |
| 151 | memmove(®s[i], ®s[i + 1], |
| 152 | (ents - i - 1) * sizeof(regs[0])); |
| 153 | i--; |
| 154 | ents--; |
| 155 | continue; |
| 156 | } |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 157 | regs[i].phys_addr = base; |
| 158 | regs[i].reg_size = size; |
| 159 | } |
David S. Miller | 486ad10 | 2006-06-22 00:00:00 -0700 | [diff] [blame] | 160 | |
David S. Miller | 486ad10 | 2006-06-22 00:00:00 -0700 | [diff] [blame] | 161 | *num_ents = ents; |
| 162 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 163 | sort(regs, ents, sizeof(struct linux_prom64_registers), |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 164 | cmp_p64, NULL); |
| 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
David S. Miller | d8ed1d4 | 2009-08-25 16:47:46 -0700 | [diff] [blame] | 167 | unsigned long sparc64_valid_addr_bitmap[VALID_ADDR_BITMAP_BYTES / |
| 168 | sizeof(unsigned long)]; |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 169 | EXPORT_SYMBOL(sparc64_valid_addr_bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 171 | /* Kernel physical address base and size in bytes. */ |
David S. Miller | 1ac4f5e | 2005-09-21 21:49:32 -0700 | [diff] [blame] | 172 | unsigned long kern_base __read_mostly; |
| 173 | unsigned long kern_size __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /* Initial ramdisk setup */ |
| 176 | extern unsigned long sparc_ramdisk_image64; |
| 177 | extern unsigned int sparc_ramdisk_image; |
| 178 | extern unsigned int sparc_ramdisk_size; |
| 179 | |
David S. Miller | 1ac4f5e | 2005-09-21 21:49:32 -0700 | [diff] [blame] | 180 | struct page *mem_map_zero __read_mostly; |
Aneesh Kumar K.V | 35802c0 | 2008-04-29 08:11:12 -0400 | [diff] [blame] | 181 | EXPORT_SYMBOL(mem_map_zero); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
David S. Miller | 0835ae0 | 2005-10-04 15:23:20 -0700 | [diff] [blame] | 183 | unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly; |
| 184 | |
| 185 | unsigned long sparc64_kern_pri_context __read_mostly; |
| 186 | unsigned long sparc64_kern_pri_nuc_bits __read_mostly; |
| 187 | unsigned long sparc64_kern_sec_context __read_mostly; |
| 188 | |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 189 | int num_kernel_image_mappings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | #ifdef CONFIG_DEBUG_DCFLUSH |
| 192 | atomic_t dcpage_flushes = ATOMIC_INIT(0); |
| 193 | #ifdef CONFIG_SMP |
| 194 | atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0); |
| 195 | #endif |
| 196 | #endif |
| 197 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 198 | inline void flush_dcache_page_impl(struct page *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 200 | BUG_ON(tlb_type == hypervisor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | #ifdef CONFIG_DEBUG_DCFLUSH |
| 202 | atomic_inc(&dcpage_flushes); |
| 203 | #endif |
| 204 | |
| 205 | #ifdef DCACHE_ALIASING_POSSIBLE |
| 206 | __flush_dcache_page(page_address(page), |
| 207 | ((tlb_type == spitfire) && |
| 208 | page_mapping(page) != NULL)); |
| 209 | #else |
| 210 | if (page_mapping(page) != NULL && |
| 211 | tlb_type == spitfire) |
| 212 | __flush_icache_page(__pa(page_address(page))); |
| 213 | #endif |
| 214 | } |
| 215 | |
| 216 | #define PG_dcache_dirty PG_arch_1 |
David S. Miller | 22adb35 | 2007-05-26 01:14:43 -0700 | [diff] [blame] | 217 | #define PG_dcache_cpu_shift 32UL |
| 218 | #define PG_dcache_cpu_mask \ |
| 219 | ((1UL<<ilog2(roundup_pow_of_two(NR_CPUS)))-1UL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | #define dcache_dirty_cpu(page) \ |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 222 | (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 224 | static inline void set_dcache_dirty(struct page *page, int this_cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | unsigned long mask = this_cpu; |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 227 | unsigned long non_cpu_bits; |
| 228 | |
| 229 | non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift); |
| 230 | mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty); |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | __asm__ __volatile__("1:\n\t" |
| 233 | "ldx [%2], %%g7\n\t" |
| 234 | "and %%g7, %1, %%g1\n\t" |
| 235 | "or %%g1, %0, %%g1\n\t" |
| 236 | "casx [%2], %%g7, %%g1\n\t" |
| 237 | "cmp %%g7, %%g1\n\t" |
| 238 | "bne,pn %%xcc, 1b\n\t" |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 239 | " nop" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | : /* no outputs */ |
| 241 | : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags) |
| 242 | : "g1", "g7"); |
| 243 | } |
| 244 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 245 | static inline void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | unsigned long mask = (1UL << PG_dcache_dirty); |
| 248 | |
| 249 | __asm__ __volatile__("! test_and_clear_dcache_dirty\n" |
| 250 | "1:\n\t" |
| 251 | "ldx [%2], %%g7\n\t" |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 252 | "srlx %%g7, %4, %%g1\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | "and %%g1, %3, %%g1\n\t" |
| 254 | "cmp %%g1, %0\n\t" |
| 255 | "bne,pn %%icc, 2f\n\t" |
| 256 | " andn %%g7, %1, %%g1\n\t" |
| 257 | "casx [%2], %%g7, %%g1\n\t" |
| 258 | "cmp %%g7, %%g1\n\t" |
| 259 | "bne,pn %%xcc, 1b\n\t" |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 260 | " nop\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | "2:" |
| 262 | : /* no outputs */ |
| 263 | : "r" (cpu), "r" (mask), "r" (&page->flags), |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 264 | "i" (PG_dcache_cpu_mask), |
| 265 | "i" (PG_dcache_cpu_shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | : "g1", "g7"); |
| 267 | } |
| 268 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 269 | static inline void tsb_insert(struct tsb *ent, unsigned long tag, unsigned long pte) |
| 270 | { |
| 271 | unsigned long tsb_addr = (unsigned long) ent; |
| 272 | |
David S. Miller | 3b3ab2e | 2006-02-17 09:54:42 -0800 | [diff] [blame] | 273 | if (tlb_type == cheetah_plus || tlb_type == hypervisor) |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 274 | tsb_addr = __pa(tsb_addr); |
| 275 | |
| 276 | __tsb_insert(tsb_addr, tag, pte); |
| 277 | } |
| 278 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 279 | unsigned long _PAGE_ALL_SZ_BITS __read_mostly; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 280 | |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 281 | static void flush_dcache(unsigned long pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 283 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 285 | page = pfn_to_page(pfn); |
David S. Miller | 1a78ced | 2009-10-12 03:20:57 -0700 | [diff] [blame] | 286 | if (page) { |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 287 | unsigned long pg_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 289 | pg_flags = page->flags; |
| 290 | if (pg_flags & (1UL << PG_dcache_dirty)) { |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 291 | int cpu = ((pg_flags >> PG_dcache_cpu_shift) & |
| 292 | PG_dcache_cpu_mask); |
| 293 | int this_cpu = get_cpu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 295 | /* This is just to optimize away some function calls |
| 296 | * in the SMP case. |
| 297 | */ |
| 298 | if (cpu == this_cpu) |
| 299 | flush_dcache_page_impl(page); |
| 300 | else |
| 301 | smp_flush_dcache_page_impl(page, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 303 | clear_dcache_dirty_cpu(page, cpu); |
| 304 | |
| 305 | put_cpu(); |
| 306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 308 | } |
| 309 | |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 310 | /* mm->context.lock must be held */ |
| 311 | static void __update_mmu_tsb_insert(struct mm_struct *mm, unsigned long tsb_index, |
| 312 | unsigned long tsb_hash_shift, unsigned long address, |
| 313 | unsigned long tte) |
| 314 | { |
| 315 | struct tsb *tsb = mm->context.tsb_block[tsb_index].tsb; |
| 316 | unsigned long tag; |
| 317 | |
David S. Miller | bcd896b | 2013-02-19 13:20:08 -0800 | [diff] [blame] | 318 | if (unlikely(!tsb)) |
| 319 | return; |
| 320 | |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 321 | tsb += ((address >> tsb_hash_shift) & |
| 322 | (mm->context.tsb_block[tsb_index].tsb_nentries - 1UL)); |
| 323 | tag = (address >> 22UL); |
| 324 | tsb_insert(tsb, tag, tte); |
| 325 | } |
| 326 | |
David S. Miller | bcd896b | 2013-02-19 13:20:08 -0800 | [diff] [blame] | 327 | #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) |
| 328 | static inline bool is_hugetlb_pte(pte_t pte) |
| 329 | { |
| 330 | if ((tlb_type == hypervisor && |
| 331 | (pte_val(pte) & _PAGE_SZALL_4V) == _PAGE_SZHUGE_4V) || |
| 332 | (tlb_type != hypervisor && |
| 333 | (pte_val(pte) & _PAGE_SZALL_4U) == _PAGE_SZHUGE_4U)) |
| 334 | return true; |
| 335 | return false; |
| 336 | } |
| 337 | #endif |
| 338 | |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 339 | void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 340 | { |
| 341 | struct mm_struct *mm; |
David S. Miller | bcd896b | 2013-02-19 13:20:08 -0800 | [diff] [blame] | 342 | unsigned long flags; |
Russell King | 4b3073e | 2009-12-18 16:40:18 +0000 | [diff] [blame] | 343 | pte_t pte = *ptep; |
Sam Ravnborg | ff9aefb | 2009-01-06 12:51:26 -0800 | [diff] [blame] | 344 | |
| 345 | if (tlb_type != hypervisor) { |
| 346 | unsigned long pfn = pte_pfn(pte); |
| 347 | |
| 348 | if (pfn_valid(pfn)) |
| 349 | flush_dcache(pfn); |
| 350 | } |
David S. Miller | bd40791 | 2006-01-31 18:31:38 -0800 | [diff] [blame] | 351 | |
| 352 | mm = vma->vm_mm; |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 353 | |
| 354 | spin_lock_irqsave(&mm->context.lock, flags); |
| 355 | |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 356 | #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) |
David S. Miller | bcd896b | 2013-02-19 13:20:08 -0800 | [diff] [blame] | 357 | if (mm->context.huge_pte_count && is_hugetlb_pte(pte)) |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 358 | __update_mmu_tsb_insert(mm, MM_TSB_HUGE, REAL_HPAGE_SHIFT, |
David S. Miller | bcd896b | 2013-02-19 13:20:08 -0800 | [diff] [blame] | 359 | address, pte_val(pte)); |
| 360 | else |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 361 | #endif |
David S. Miller | bcd896b | 2013-02-19 13:20:08 -0800 | [diff] [blame] | 362 | __update_mmu_tsb_insert(mm, MM_TSB_BASE, PAGE_SHIFT, |
| 363 | address, pte_val(pte)); |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 364 | |
| 365 | spin_unlock_irqrestore(&mm->context.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | void flush_dcache_page(struct page *page) |
| 369 | { |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 370 | struct address_space *mapping; |
| 371 | int this_cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 373 | if (tlb_type == hypervisor) |
| 374 | return; |
| 375 | |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 376 | /* Do not bother with the expensive D-cache flush if it |
| 377 | * is merely the zero page. The 'bigcore' testcase in GDB |
| 378 | * causes this case to run millions of times. |
| 379 | */ |
| 380 | if (page == ZERO_PAGE(0)) |
| 381 | return; |
| 382 | |
| 383 | this_cpu = get_cpu(); |
| 384 | |
| 385 | mapping = page_mapping(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | if (mapping && !mapping_mapped(mapping)) { |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 387 | int dirty = test_bit(PG_dcache_dirty, &page->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | if (dirty) { |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 389 | int dirty_cpu = dcache_dirty_cpu(page); |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if (dirty_cpu == this_cpu) |
| 392 | goto out; |
| 393 | smp_flush_dcache_page_impl(page, dirty_cpu); |
| 394 | } |
| 395 | set_dcache_dirty(page, this_cpu); |
| 396 | } else { |
| 397 | /* We could delay the flush for the !page_mapping |
| 398 | * case too. But that case is for exec env/arg |
| 399 | * pages and those are %99 certainly going to get |
| 400 | * faulted into the tlb (and thus flushed) anyways. |
| 401 | */ |
| 402 | flush_dcache_page_impl(page); |
| 403 | } |
| 404 | |
| 405 | out: |
| 406 | put_cpu(); |
| 407 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 408 | EXPORT_SYMBOL(flush_dcache_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 410 | void __kprobes flush_icache_range(unsigned long start, unsigned long end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
David S. Miller | a43fe0e | 2006-02-04 03:10:53 -0800 | [diff] [blame] | 412 | /* Cheetah and Hypervisor platform cpus have coherent I-cache. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | if (tlb_type == spitfire) { |
| 414 | unsigned long kaddr; |
| 415 | |
David S. Miller | a94aa25 | 2007-03-15 15:50:11 -0700 | [diff] [blame] | 416 | /* This code only runs on Spitfire cpus so this is |
| 417 | * why we can assume _PAGE_PADDR_4U. |
| 418 | */ |
| 419 | for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE) { |
| 420 | unsigned long paddr, mask = _PAGE_PADDR_4U; |
| 421 | |
| 422 | if (kaddr >= PAGE_OFFSET) |
| 423 | paddr = kaddr & mask; |
| 424 | else { |
| 425 | pgd_t *pgdp = pgd_offset_k(kaddr); |
| 426 | pud_t *pudp = pud_offset(pgdp, kaddr); |
| 427 | pmd_t *pmdp = pmd_offset(pudp, kaddr); |
| 428 | pte_t *ptep = pte_offset_kernel(pmdp, kaddr); |
| 429 | |
| 430 | paddr = pte_val(*ptep) & mask; |
| 431 | } |
| 432 | __flush_icache_page(paddr); |
| 433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 436 | EXPORT_SYMBOL(flush_icache_range); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | void mmu_info(struct seq_file *m) |
| 439 | { |
David S. Miller | ce33fdc | 2012-09-06 19:01:25 -0700 | [diff] [blame] | 440 | static const char *pgsz_strings[] = { |
| 441 | "8K", "64K", "512K", "4MB", "32MB", |
| 442 | "256MB", "2GB", "16GB", |
| 443 | }; |
| 444 | int i, printed; |
| 445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (tlb_type == cheetah) |
| 447 | seq_printf(m, "MMU Type\t: Cheetah\n"); |
| 448 | else if (tlb_type == cheetah_plus) |
| 449 | seq_printf(m, "MMU Type\t: Cheetah+\n"); |
| 450 | else if (tlb_type == spitfire) |
| 451 | seq_printf(m, "MMU Type\t: Spitfire\n"); |
David S. Miller | a43fe0e | 2006-02-04 03:10:53 -0800 | [diff] [blame] | 452 | else if (tlb_type == hypervisor) |
| 453 | seq_printf(m, "MMU Type\t: Hypervisor (sun4v)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | else |
| 455 | seq_printf(m, "MMU Type\t: ???\n"); |
| 456 | |
David S. Miller | ce33fdc | 2012-09-06 19:01:25 -0700 | [diff] [blame] | 457 | seq_printf(m, "MMU PGSZs\t: "); |
| 458 | printed = 0; |
| 459 | for (i = 0; i < ARRAY_SIZE(pgsz_strings); i++) { |
| 460 | if (cpu_pgsz_mask & (1UL << i)) { |
| 461 | seq_printf(m, "%s%s", |
| 462 | printed ? "," : "", pgsz_strings[i]); |
| 463 | printed++; |
| 464 | } |
| 465 | } |
| 466 | seq_putc(m, '\n'); |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | #ifdef CONFIG_DEBUG_DCFLUSH |
| 469 | seq_printf(m, "DCPageFlushes\t: %d\n", |
| 470 | atomic_read(&dcpage_flushes)); |
| 471 | #ifdef CONFIG_SMP |
| 472 | seq_printf(m, "DCPageFlushesXC\t: %d\n", |
| 473 | atomic_read(&dcpage_flushes_xcall)); |
| 474 | #endif /* CONFIG_SMP */ |
| 475 | #endif /* CONFIG_DEBUG_DCFLUSH */ |
| 476 | } |
| 477 | |
David S. Miller | a94aa25 | 2007-03-15 15:50:11 -0700 | [diff] [blame] | 478 | struct linux_prom_translation prom_trans[512] __read_mostly; |
| 479 | unsigned int prom_trans_ents __read_mostly; |
| 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | unsigned long kern_locked_tte_data; |
| 482 | |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 483 | /* The obp translations are saved based on 8k pagesize, since obp can |
| 484 | * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS -> |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 485 | * HI_OBP_ADDRESS range are handled in ktlb.S. |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 486 | */ |
David S. Miller | 5085b4a | 2005-09-22 00:45:41 -0700 | [diff] [blame] | 487 | static inline int in_obp_range(unsigned long vaddr) |
| 488 | { |
| 489 | return (vaddr >= LOW_OBP_ADDRESS && |
| 490 | vaddr < HI_OBP_ADDRESS); |
| 491 | } |
| 492 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 493 | static int cmp_ptrans(const void *a, const void *b) |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 494 | { |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 495 | const struct linux_prom_translation *x = a, *y = b; |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 496 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 497 | if (x->virt > y->virt) |
| 498 | return 1; |
| 499 | if (x->virt < y->virt) |
| 500 | return -1; |
| 501 | return 0; |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 502 | } |
| 503 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 504 | /* Read OBP translations property into 'prom_trans[]'. */ |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 505 | static void __init read_obp_translations(void) |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 506 | { |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 507 | int n, node, ents, first, last, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | node = prom_finddevice("/virtual-memory"); |
| 510 | n = prom_getproplen(node, "translations"); |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 511 | if (unlikely(n == 0 || n == -1)) { |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 512 | prom_printf("prom_mappings: Couldn't get size.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | prom_halt(); |
| 514 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 515 | if (unlikely(n > sizeof(prom_trans))) { |
Akinobu Mita | 5da444a | 2012-09-29 03:14:49 +0000 | [diff] [blame] | 516 | prom_printf("prom_mappings: Size %d is too big.\n", n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | prom_halt(); |
| 518 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 519 | |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 520 | if ((n = prom_getproperty(node, "translations", |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 521 | (char *)&prom_trans[0], |
| 522 | sizeof(prom_trans))) == -1) { |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 523 | prom_printf("prom_mappings: Couldn't get property.\n"); |
| 524 | prom_halt(); |
| 525 | } |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 526 | |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 527 | n = n / sizeof(struct linux_prom_translation); |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 528 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 529 | ents = n; |
| 530 | |
| 531 | sort(prom_trans, ents, sizeof(struct linux_prom_translation), |
| 532 | cmp_ptrans, NULL); |
| 533 | |
| 534 | /* Now kick out all the non-OBP entries. */ |
| 535 | for (i = 0; i < ents; i++) { |
| 536 | if (in_obp_range(prom_trans[i].virt)) |
| 537 | break; |
| 538 | } |
| 539 | first = i; |
| 540 | for (; i < ents; i++) { |
| 541 | if (!in_obp_range(prom_trans[i].virt)) |
| 542 | break; |
| 543 | } |
| 544 | last = i; |
| 545 | |
| 546 | for (i = 0; i < (last - first); i++) { |
| 547 | struct linux_prom_translation *src = &prom_trans[i + first]; |
| 548 | struct linux_prom_translation *dest = &prom_trans[i]; |
| 549 | |
| 550 | *dest = *src; |
| 551 | } |
| 552 | for (; i < ents; i++) { |
| 553 | struct linux_prom_translation *dest = &prom_trans[i]; |
| 554 | dest->virt = dest->size = dest->data = 0x0UL; |
| 555 | } |
| 556 | |
| 557 | prom_trans_ents = last - first; |
| 558 | |
| 559 | if (tlb_type == spitfire) { |
| 560 | /* Clear diag TTE bits. */ |
| 561 | for (i = 0; i < prom_trans_ents; i++) |
| 562 | prom_trans[i].data &= ~0x0003fe0000000000UL; |
| 563 | } |
David S. Miller | f4142cb | 2011-09-29 12:18:59 -0700 | [diff] [blame] | 564 | |
| 565 | /* Force execute bit on. */ |
| 566 | for (i = 0; i < prom_trans_ents; i++) |
| 567 | prom_trans[i].data |= (tlb_type == hypervisor ? |
| 568 | _PAGE_EXEC_4V : _PAGE_EXEC_4U); |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 571 | static void __init hypervisor_tlb_lock(unsigned long vaddr, |
| 572 | unsigned long pte, |
| 573 | unsigned long mmu) |
| 574 | { |
David S. Miller | 7db35f3 | 2007-05-29 02:22:14 -0700 | [diff] [blame] | 575 | unsigned long ret = sun4v_mmu_map_perm_addr(vaddr, 0, pte, mmu); |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 576 | |
David S. Miller | 7db35f3 | 2007-05-29 02:22:14 -0700 | [diff] [blame] | 577 | if (ret != 0) { |
Akinobu Mita | 5da444a | 2012-09-29 03:14:49 +0000 | [diff] [blame] | 578 | prom_printf("hypervisor_tlb_lock[%lx:%x:%lx:%lx]: " |
David S. Miller | 7db35f3 | 2007-05-29 02:22:14 -0700 | [diff] [blame] | 579 | "errors with %lx\n", vaddr, 0, pte, mmu, ret); |
David S. Miller | 12e126a | 2006-02-17 14:40:30 -0800 | [diff] [blame] | 580 | prom_halt(); |
| 581 | } |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 582 | } |
| 583 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 584 | static unsigned long kern_large_tte(unsigned long paddr); |
| 585 | |
David S. Miller | 898cf0e | 2005-09-23 11:59:44 -0700 | [diff] [blame] | 586 | static void __init remap_kernel(void) |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 587 | { |
| 588 | unsigned long phys_page, tte_vaddr, tte_data; |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 589 | int i, tlb_ent = sparc64_highest_locked_tlbent(); |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | tte_vaddr = (unsigned long) KERNBASE; |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 592 | phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 593 | tte_data = kern_large_tte(phys_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | kern_locked_tte_data = tte_data; |
| 596 | |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 597 | /* Now lock us into the TLBs via Hypervisor or OBP. */ |
| 598 | if (tlb_type == hypervisor) { |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 599 | for (i = 0; i < num_kernel_image_mappings; i++) { |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 600 | hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU); |
| 601 | hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU); |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 602 | tte_vaddr += 0x400000; |
| 603 | tte_data += 0x400000; |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 604 | } |
| 605 | } else { |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 606 | for (i = 0; i < num_kernel_image_mappings; i++) { |
| 607 | prom_dtlb_load(tlb_ent - i, tte_data, tte_vaddr); |
| 608 | prom_itlb_load(tlb_ent - i, tte_data, tte_vaddr); |
| 609 | tte_vaddr += 0x400000; |
| 610 | tte_data += 0x400000; |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 611 | } |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 612 | sparc64_highest_unlocked_tlb_ent = tlb_ent - i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
David S. Miller | 0835ae0 | 2005-10-04 15:23:20 -0700 | [diff] [blame] | 614 | if (tlb_type == cheetah_plus) { |
| 615 | sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 | |
| 616 | CTX_CHEETAH_PLUS_NUC); |
| 617 | sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC; |
| 618 | sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0; |
| 619 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 622 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 623 | static void __init inherit_prom_mappings(void) |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 624 | { |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 625 | /* Now fixup OBP's idea about where we really are mapped. */ |
David S. Miller | 3c62a2d | 2008-02-17 23:22:50 -0800 | [diff] [blame] | 626 | printk("Remapping the kernel... "); |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 627 | remap_kernel(); |
David S. Miller | 3c62a2d | 2008-02-17 23:22:50 -0800 | [diff] [blame] | 628 | printk("done.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | void prom_world(int enter) |
| 632 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | if (!enter) |
Al Viro | dff933d | 2012-09-26 01:21:14 -0400 | [diff] [blame] | 634 | set_fs(get_fs()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
David S. Miller | 3487d1d | 2006-01-31 18:33:25 -0800 | [diff] [blame] | 636 | __asm__ __volatile__("flushw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | void __flush_dcache_range(unsigned long start, unsigned long end) |
| 640 | { |
| 641 | unsigned long va; |
| 642 | |
| 643 | if (tlb_type == spitfire) { |
| 644 | int n = 0; |
| 645 | |
| 646 | for (va = start; va < end; va += 32) { |
| 647 | spitfire_put_dcache_tag(va & 0x3fe0, 0x0); |
| 648 | if (++n >= 512) |
| 649 | break; |
| 650 | } |
David S. Miller | a43fe0e | 2006-02-04 03:10:53 -0800 | [diff] [blame] | 651 | } else if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | start = __pa(start); |
| 653 | end = __pa(end); |
| 654 | for (va = start; va < end; va += 32) |
| 655 | __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" |
| 656 | "membar #Sync" |
| 657 | : /* no outputs */ |
| 658 | : "r" (va), |
| 659 | "i" (ASI_DCACHE_INVALIDATE)); |
| 660 | } |
| 661 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 662 | EXPORT_SYMBOL(__flush_dcache_range); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
David S. Miller | 85f1e1f | 2007-03-15 17:51:26 -0700 | [diff] [blame] | 664 | /* get_new_mmu_context() uses "cache + 1". */ |
| 665 | DEFINE_SPINLOCK(ctx_alloc_lock); |
| 666 | unsigned long tlb_context_cache = CTX_FIRST_VERSION - 1; |
| 667 | #define MAX_CTX_NR (1UL << CTX_NR_BITS) |
| 668 | #define CTX_BMAP_SLOTS BITS_TO_LONGS(MAX_CTX_NR) |
| 669 | DECLARE_BITMAP(mmu_context_bmap, MAX_CTX_NR); |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* Caller does TLB context flushing on local CPU if necessary. |
| 672 | * The caller also ensures that CTX_VALID(mm->context) is false. |
| 673 | * |
| 674 | * We must be careful about boundary cases so that we never |
| 675 | * let the user have CTX 0 (nucleus) or we ever use a CTX |
| 676 | * version of zero (and thus NO_CONTEXT would not be caught |
| 677 | * by version mis-match tests in mmu_context.h). |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 678 | * |
| 679 | * Always invoked with interrupts disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | */ |
| 681 | void get_new_mmu_context(struct mm_struct *mm) |
| 682 | { |
| 683 | unsigned long ctx, new_ctx; |
| 684 | unsigned long orig_pgsz_bits; |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 685 | int new_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Kirill Tkhai | 07df841 | 2013-04-09 00:29:46 +0400 | [diff] [blame] | 687 | spin_lock(&ctx_alloc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK); |
| 689 | ctx = (tlb_context_cache + 1) & CTX_NR_MASK; |
| 690 | new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx); |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 691 | new_version = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | if (new_ctx >= (1 << CTX_NR_BITS)) { |
| 693 | new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1); |
| 694 | if (new_ctx >= ctx) { |
| 695 | int i; |
| 696 | new_ctx = (tlb_context_cache & CTX_VERSION_MASK) + |
| 697 | CTX_FIRST_VERSION; |
| 698 | if (new_ctx == 1) |
| 699 | new_ctx = CTX_FIRST_VERSION; |
| 700 | |
| 701 | /* Don't call memset, for 16 entries that's just |
| 702 | * plain silly... |
| 703 | */ |
| 704 | mmu_context_bmap[0] = 3; |
| 705 | mmu_context_bmap[1] = 0; |
| 706 | mmu_context_bmap[2] = 0; |
| 707 | mmu_context_bmap[3] = 0; |
| 708 | for (i = 4; i < CTX_BMAP_SLOTS; i += 4) { |
| 709 | mmu_context_bmap[i + 0] = 0; |
| 710 | mmu_context_bmap[i + 1] = 0; |
| 711 | mmu_context_bmap[i + 2] = 0; |
| 712 | mmu_context_bmap[i + 3] = 0; |
| 713 | } |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 714 | new_version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | goto out; |
| 716 | } |
| 717 | } |
| 718 | mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63)); |
| 719 | new_ctx |= (tlb_context_cache & CTX_VERSION_MASK); |
| 720 | out: |
| 721 | tlb_context_cache = new_ctx; |
| 722 | mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits; |
Kirill Tkhai | 07df841 | 2013-04-09 00:29:46 +0400 | [diff] [blame] | 723 | spin_unlock(&ctx_alloc_lock); |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 724 | |
| 725 | if (unlikely(new_version)) |
| 726 | smp_new_mmu_context_version(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 729 | static int numa_enabled = 1; |
| 730 | static int numa_debug; |
| 731 | |
| 732 | static int __init early_numa(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | { |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 734 | if (!p) |
| 735 | return 0; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 736 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 737 | if (strstr(p, "off")) |
| 738 | numa_enabled = 0; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 739 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 740 | if (strstr(p, "debug")) |
| 741 | numa_debug = 1; |
| 742 | |
| 743 | return 0; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 744 | } |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 745 | early_param("numa", early_numa); |
| 746 | |
| 747 | #define numadbg(f, a...) \ |
| 748 | do { if (numa_debug) \ |
| 749 | printk(KERN_INFO f, ## a); \ |
| 750 | } while (0) |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 751 | |
David S. Miller | 4e82c9a | 2008-02-13 18:00:03 -0800 | [diff] [blame] | 752 | static void __init find_ramdisk(unsigned long phys_base) |
| 753 | { |
| 754 | #ifdef CONFIG_BLK_DEV_INITRD |
| 755 | if (sparc_ramdisk_image || sparc_ramdisk_image64) { |
| 756 | unsigned long ramdisk_image; |
| 757 | |
| 758 | /* Older versions of the bootloader only supported a |
| 759 | * 32-bit physical address for the ramdisk image |
| 760 | * location, stored at sparc_ramdisk_image. Newer |
| 761 | * SILO versions set sparc_ramdisk_image to zero and |
| 762 | * provide a full 64-bit physical address at |
| 763 | * sparc_ramdisk_image64. |
| 764 | */ |
| 765 | ramdisk_image = sparc_ramdisk_image; |
| 766 | if (!ramdisk_image) |
| 767 | ramdisk_image = sparc_ramdisk_image64; |
| 768 | |
| 769 | /* Another bootloader quirk. The bootloader normalizes |
| 770 | * the physical address to KERNBASE, so we have to |
| 771 | * factor that back out and add in the lowest valid |
| 772 | * physical page address to get the true physical address. |
| 773 | */ |
| 774 | ramdisk_image -= KERNBASE; |
| 775 | ramdisk_image += phys_base; |
| 776 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 777 | numadbg("Found ramdisk at physical address 0x%lx, size %u\n", |
| 778 | ramdisk_image, sparc_ramdisk_size); |
| 779 | |
David S. Miller | 4e82c9a | 2008-02-13 18:00:03 -0800 | [diff] [blame] | 780 | initrd_start = ramdisk_image; |
| 781 | initrd_end = ramdisk_image + sparc_ramdisk_size; |
David S. Miller | 3b2a7e2 | 2008-02-13 18:13:20 -0800 | [diff] [blame] | 782 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 783 | memblock_reserve(initrd_start, sparc_ramdisk_size); |
David S. Miller | d45100f | 2008-05-06 15:19:54 -0700 | [diff] [blame] | 784 | |
| 785 | initrd_start += PAGE_OFFSET; |
| 786 | initrd_end += PAGE_OFFSET; |
David S. Miller | 4e82c9a | 2008-02-13 18:00:03 -0800 | [diff] [blame] | 787 | } |
| 788 | #endif |
| 789 | } |
| 790 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 791 | struct node_mem_mask { |
| 792 | unsigned long mask; |
| 793 | unsigned long val; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 794 | }; |
| 795 | static struct node_mem_mask node_masks[MAX_NUMNODES]; |
| 796 | static int num_node_masks; |
| 797 | |
| 798 | int numa_cpu_lookup_table[NR_CPUS]; |
| 799 | cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES]; |
| 800 | |
| 801 | #ifdef CONFIG_NEED_MULTIPLE_NODES |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 802 | |
| 803 | struct mdesc_mblock { |
| 804 | u64 base; |
| 805 | u64 size; |
| 806 | u64 offset; /* RA-to-PA */ |
| 807 | }; |
| 808 | static struct mdesc_mblock *mblocks; |
| 809 | static int num_mblocks; |
| 810 | |
| 811 | static unsigned long ra_to_pa(unsigned long addr) |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 812 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | int i; |
| 814 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 815 | for (i = 0; i < num_mblocks; i++) { |
| 816 | struct mdesc_mblock *m = &mblocks[i]; |
David S. Miller | 6fc5bae | 2006-12-28 21:00:23 -0800 | [diff] [blame] | 817 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 818 | if (addr >= m->base && |
| 819 | addr < (m->base + m->size)) { |
| 820 | addr += m->offset; |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | return addr; |
| 825 | } |
| 826 | |
| 827 | static int find_node(unsigned long addr) |
| 828 | { |
| 829 | int i; |
| 830 | |
| 831 | addr = ra_to_pa(addr); |
| 832 | for (i = 0; i < num_node_masks; i++) { |
| 833 | struct node_mem_mask *p = &node_masks[i]; |
| 834 | |
| 835 | if ((addr & p->mask) == p->val) |
| 836 | return i; |
| 837 | } |
| 838 | return -1; |
| 839 | } |
| 840 | |
Tejun Heo | f9b18db | 2011-07-12 10:46:32 +0200 | [diff] [blame] | 841 | static u64 memblock_nid_range(u64 start, u64 end, int *nid) |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 842 | { |
| 843 | *nid = find_node(start); |
| 844 | start += PAGE_SIZE; |
| 845 | while (start < end) { |
| 846 | int n = find_node(start); |
| 847 | |
| 848 | if (n != *nid) |
| 849 | break; |
| 850 | start += PAGE_SIZE; |
| 851 | } |
| 852 | |
David S. Miller | c918dcc | 2008-08-14 01:41:39 -0700 | [diff] [blame] | 853 | if (start > end) |
| 854 | start = end; |
| 855 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 856 | return start; |
| 857 | } |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 858 | #endif |
| 859 | |
| 860 | /* This must be invoked after performing all of the necessary |
Tejun Heo | 2a4814d | 2011-12-08 10:22:08 -0800 | [diff] [blame] | 861 | * memblock_set_node() calls for 'nid'. We need to be able to get |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 862 | * correct data from get_pfn_range_for_nid(). |
| 863 | */ |
| 864 | static void __init allocate_node_data(int nid) |
| 865 | { |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 866 | struct pglist_data *p; |
Paul Gortmaker | aa6f079 | 2012-05-09 20:44:29 -0400 | [diff] [blame] | 867 | unsigned long start_pfn, end_pfn; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 868 | #ifdef CONFIG_NEED_MULTIPLE_NODES |
Paul Gortmaker | aa6f079 | 2012-05-09 20:44:29 -0400 | [diff] [blame] | 869 | unsigned long paddr; |
| 870 | |
Benjamin Herrenschmidt | 9d1e249 | 2010-07-06 15:39:17 -0700 | [diff] [blame] | 871 | paddr = memblock_alloc_try_nid(sizeof(struct pglist_data), SMP_CACHE_BYTES, nid); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 872 | if (!paddr) { |
| 873 | prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid); |
| 874 | prom_halt(); |
| 875 | } |
| 876 | NODE_DATA(nid) = __va(paddr); |
| 877 | memset(NODE_DATA(nid), 0, sizeof(struct pglist_data)); |
| 878 | |
David S. Miller | 625d693 | 2012-04-25 13:13:43 -0700 | [diff] [blame] | 879 | NODE_DATA(nid)->node_id = nid; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 880 | #endif |
| 881 | |
| 882 | p = NODE_DATA(nid); |
| 883 | |
| 884 | get_pfn_range_for_nid(nid, &start_pfn, &end_pfn); |
| 885 | p->node_start_pfn = start_pfn; |
| 886 | p->node_spanned_pages = end_pfn - start_pfn; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | static void init_node_masks_nonnuma(void) |
| 890 | { |
| 891 | int i; |
| 892 | |
| 893 | numadbg("Initializing tables for non-numa.\n"); |
| 894 | |
| 895 | node_masks[0].mask = node_masks[0].val = 0; |
| 896 | num_node_masks = 1; |
| 897 | |
| 898 | for (i = 0; i < NR_CPUS; i++) |
| 899 | numa_cpu_lookup_table[i] = 0; |
| 900 | |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 901 | cpumask_setall(&numa_cpumask_lookup_table[0]); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | #ifdef CONFIG_NEED_MULTIPLE_NODES |
| 905 | struct pglist_data *node_data[MAX_NUMNODES]; |
| 906 | |
| 907 | EXPORT_SYMBOL(numa_cpu_lookup_table); |
| 908 | EXPORT_SYMBOL(numa_cpumask_lookup_table); |
| 909 | EXPORT_SYMBOL(node_data); |
| 910 | |
| 911 | struct mdesc_mlgroup { |
| 912 | u64 node; |
| 913 | u64 latency; |
| 914 | u64 match; |
| 915 | u64 mask; |
| 916 | }; |
| 917 | static struct mdesc_mlgroup *mlgroups; |
| 918 | static int num_mlgroups; |
| 919 | |
| 920 | static int scan_pio_for_cfg_handle(struct mdesc_handle *md, u64 pio, |
| 921 | u32 cfg_handle) |
| 922 | { |
| 923 | u64 arc; |
| 924 | |
| 925 | mdesc_for_each_arc(arc, md, pio, MDESC_ARC_TYPE_FWD) { |
| 926 | u64 target = mdesc_arc_target(md, arc); |
| 927 | const u64 *val; |
| 928 | |
| 929 | val = mdesc_get_property(md, target, |
| 930 | "cfg-handle", NULL); |
| 931 | if (val && *val == cfg_handle) |
| 932 | return 0; |
| 933 | } |
| 934 | return -ENODEV; |
| 935 | } |
| 936 | |
| 937 | static int scan_arcs_for_cfg_handle(struct mdesc_handle *md, u64 grp, |
| 938 | u32 cfg_handle) |
| 939 | { |
| 940 | u64 arc, candidate, best_latency = ~(u64)0; |
| 941 | |
| 942 | candidate = MDESC_NODE_NULL; |
| 943 | mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) { |
| 944 | u64 target = mdesc_arc_target(md, arc); |
| 945 | const char *name = mdesc_node_name(md, target); |
| 946 | const u64 *val; |
| 947 | |
| 948 | if (strcmp(name, "pio-latency-group")) |
| 949 | continue; |
| 950 | |
| 951 | val = mdesc_get_property(md, target, "latency", NULL); |
| 952 | if (!val) |
| 953 | continue; |
| 954 | |
| 955 | if (*val < best_latency) { |
| 956 | candidate = target; |
| 957 | best_latency = *val; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | if (candidate == MDESC_NODE_NULL) |
| 962 | return -ENODEV; |
| 963 | |
| 964 | return scan_pio_for_cfg_handle(md, candidate, cfg_handle); |
| 965 | } |
| 966 | |
| 967 | int of_node_to_nid(struct device_node *dp) |
| 968 | { |
| 969 | const struct linux_prom64_registers *regs; |
| 970 | struct mdesc_handle *md; |
| 971 | u32 cfg_handle; |
| 972 | int count, nid; |
| 973 | u64 grp; |
| 974 | |
David S. Miller | 072bd41 | 2008-08-18 20:36:17 -0700 | [diff] [blame] | 975 | /* This is the right thing to do on currently supported |
| 976 | * SUN4U NUMA platforms as well, as the PCI controller does |
| 977 | * not sit behind any particular memory controller. |
| 978 | */ |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 979 | if (!mlgroups) |
| 980 | return -1; |
| 981 | |
| 982 | regs = of_get_property(dp, "reg", NULL); |
| 983 | if (!regs) |
| 984 | return -1; |
| 985 | |
| 986 | cfg_handle = (regs->phys_addr >> 32UL) & 0x0fffffff; |
| 987 | |
| 988 | md = mdesc_grab(); |
| 989 | |
| 990 | count = 0; |
| 991 | nid = -1; |
| 992 | mdesc_for_each_node_by_name(md, grp, "group") { |
| 993 | if (!scan_arcs_for_cfg_handle(md, grp, cfg_handle)) { |
| 994 | nid = count; |
| 995 | break; |
| 996 | } |
| 997 | count++; |
| 998 | } |
| 999 | |
| 1000 | mdesc_release(md); |
| 1001 | |
| 1002 | return nid; |
| 1003 | } |
| 1004 | |
David S. Miller | 01c45381 | 2009-04-07 01:05:22 -0700 | [diff] [blame] | 1005 | static void __init add_node_ranges(void) |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1006 | { |
Benjamin Herrenschmidt | 08b8479 | 2010-08-04 13:43:31 +1000 | [diff] [blame] | 1007 | struct memblock_region *reg; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1008 | |
Benjamin Herrenschmidt | 08b8479 | 2010-08-04 13:43:31 +1000 | [diff] [blame] | 1009 | for_each_memblock(memory, reg) { |
| 1010 | unsigned long size = reg->size; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1011 | unsigned long start, end; |
| 1012 | |
Benjamin Herrenschmidt | 08b8479 | 2010-08-04 13:43:31 +1000 | [diff] [blame] | 1013 | start = reg->base; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1014 | end = start + size; |
| 1015 | while (start < end) { |
| 1016 | unsigned long this_end; |
| 1017 | int nid; |
| 1018 | |
Benjamin Herrenschmidt | 35a1f0b | 2010-07-06 15:38:58 -0700 | [diff] [blame] | 1019 | this_end = memblock_nid_range(start, end, &nid); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1020 | |
Tejun Heo | 2a4814d | 2011-12-08 10:22:08 -0800 | [diff] [blame] | 1021 | numadbg("Setting memblock NUMA node nid[%d] " |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1022 | "start[%lx] end[%lx]\n", |
| 1023 | nid, start, this_end); |
| 1024 | |
Tang Chen | e7e8de5 | 2014-01-21 15:49:26 -0800 | [diff] [blame] | 1025 | memblock_set_node(start, this_end - start, |
| 1026 | &memblock.memory, nid); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1027 | start = this_end; |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | static int __init grab_mlgroups(struct mdesc_handle *md) |
| 1033 | { |
| 1034 | unsigned long paddr; |
| 1035 | int count = 0; |
| 1036 | u64 node; |
| 1037 | |
| 1038 | mdesc_for_each_node_by_name(md, node, "memory-latency-group") |
| 1039 | count++; |
| 1040 | if (!count) |
| 1041 | return -ENOENT; |
| 1042 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1043 | paddr = memblock_alloc(count * sizeof(struct mdesc_mlgroup), |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1044 | SMP_CACHE_BYTES); |
| 1045 | if (!paddr) |
| 1046 | return -ENOMEM; |
| 1047 | |
| 1048 | mlgroups = __va(paddr); |
| 1049 | num_mlgroups = count; |
| 1050 | |
| 1051 | count = 0; |
| 1052 | mdesc_for_each_node_by_name(md, node, "memory-latency-group") { |
| 1053 | struct mdesc_mlgroup *m = &mlgroups[count++]; |
| 1054 | const u64 *val; |
| 1055 | |
| 1056 | m->node = node; |
| 1057 | |
| 1058 | val = mdesc_get_property(md, node, "latency", NULL); |
| 1059 | m->latency = *val; |
| 1060 | val = mdesc_get_property(md, node, "address-match", NULL); |
| 1061 | m->match = *val; |
| 1062 | val = mdesc_get_property(md, node, "address-mask", NULL); |
| 1063 | m->mask = *val; |
| 1064 | |
Sam Ravnborg | 9018113 | 2009-01-06 13:19:28 -0800 | [diff] [blame] | 1065 | numadbg("MLGROUP[%d]: node[%llx] latency[%llx] " |
| 1066 | "match[%llx] mask[%llx]\n", |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1067 | count - 1, m->node, m->latency, m->match, m->mask); |
| 1068 | } |
| 1069 | |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
| 1073 | static int __init grab_mblocks(struct mdesc_handle *md) |
| 1074 | { |
| 1075 | unsigned long paddr; |
| 1076 | int count = 0; |
| 1077 | u64 node; |
| 1078 | |
| 1079 | mdesc_for_each_node_by_name(md, node, "mblock") |
| 1080 | count++; |
| 1081 | if (!count) |
| 1082 | return -ENOENT; |
| 1083 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1084 | paddr = memblock_alloc(count * sizeof(struct mdesc_mblock), |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1085 | SMP_CACHE_BYTES); |
| 1086 | if (!paddr) |
| 1087 | return -ENOMEM; |
| 1088 | |
| 1089 | mblocks = __va(paddr); |
| 1090 | num_mblocks = count; |
| 1091 | |
| 1092 | count = 0; |
| 1093 | mdesc_for_each_node_by_name(md, node, "mblock") { |
| 1094 | struct mdesc_mblock *m = &mblocks[count++]; |
| 1095 | const u64 *val; |
| 1096 | |
| 1097 | val = mdesc_get_property(md, node, "base", NULL); |
| 1098 | m->base = *val; |
| 1099 | val = mdesc_get_property(md, node, "size", NULL); |
| 1100 | m->size = *val; |
| 1101 | val = mdesc_get_property(md, node, |
| 1102 | "address-congruence-offset", NULL); |
bob picco | 771a37f | 2013-06-11 14:54:51 -0400 | [diff] [blame] | 1103 | |
| 1104 | /* The address-congruence-offset property is optional. |
| 1105 | * Explicity zero it be identifty this. |
| 1106 | */ |
| 1107 | if (val) |
| 1108 | m->offset = *val; |
| 1109 | else |
| 1110 | m->offset = 0UL; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1111 | |
Sam Ravnborg | 9018113 | 2009-01-06 13:19:28 -0800 | [diff] [blame] | 1112 | numadbg("MBLOCK[%d]: base[%llx] size[%llx] offset[%llx]\n", |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1113 | count - 1, m->base, m->size, m->offset); |
| 1114 | } |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | static void __init numa_parse_mdesc_group_cpus(struct mdesc_handle *md, |
| 1120 | u64 grp, cpumask_t *mask) |
| 1121 | { |
| 1122 | u64 arc; |
| 1123 | |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 1124 | cpumask_clear(mask); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1125 | |
| 1126 | mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_BACK) { |
| 1127 | u64 target = mdesc_arc_target(md, arc); |
| 1128 | const char *name = mdesc_node_name(md, target); |
| 1129 | const u64 *id; |
| 1130 | |
| 1131 | if (strcmp(name, "cpu")) |
| 1132 | continue; |
| 1133 | id = mdesc_get_property(md, target, "id", NULL); |
Rusty Russell | e305cb8f | 2009-03-16 14:40:23 +1030 | [diff] [blame] | 1134 | if (*id < nr_cpu_ids) |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 1135 | cpumask_set_cpu(*id, mask); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | static struct mdesc_mlgroup * __init find_mlgroup(u64 node) |
| 1140 | { |
| 1141 | int i; |
| 1142 | |
| 1143 | for (i = 0; i < num_mlgroups; i++) { |
| 1144 | struct mdesc_mlgroup *m = &mlgroups[i]; |
| 1145 | if (m->node == node) |
| 1146 | return m; |
| 1147 | } |
| 1148 | return NULL; |
| 1149 | } |
| 1150 | |
| 1151 | static int __init numa_attach_mlgroup(struct mdesc_handle *md, u64 grp, |
| 1152 | int index) |
| 1153 | { |
| 1154 | struct mdesc_mlgroup *candidate = NULL; |
| 1155 | u64 arc, best_latency = ~(u64)0; |
| 1156 | struct node_mem_mask *n; |
| 1157 | |
| 1158 | mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) { |
| 1159 | u64 target = mdesc_arc_target(md, arc); |
| 1160 | struct mdesc_mlgroup *m = find_mlgroup(target); |
| 1161 | if (!m) |
| 1162 | continue; |
| 1163 | if (m->latency < best_latency) { |
| 1164 | candidate = m; |
| 1165 | best_latency = m->latency; |
| 1166 | } |
| 1167 | } |
| 1168 | if (!candidate) |
| 1169 | return -ENOENT; |
| 1170 | |
| 1171 | if (num_node_masks != index) { |
| 1172 | printk(KERN_ERR "Inconsistent NUMA state, " |
| 1173 | "index[%d] != num_node_masks[%d]\n", |
| 1174 | index, num_node_masks); |
| 1175 | return -EINVAL; |
| 1176 | } |
| 1177 | |
| 1178 | n = &node_masks[num_node_masks++]; |
| 1179 | |
| 1180 | n->mask = candidate->mask; |
| 1181 | n->val = candidate->match; |
| 1182 | |
Sam Ravnborg | 9018113 | 2009-01-06 13:19:28 -0800 | [diff] [blame] | 1183 | numadbg("NUMA NODE[%d]: mask[%lx] val[%lx] (latency[%llx])\n", |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1184 | index, n->mask, n->val, candidate->latency); |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | static int __init numa_parse_mdesc_group(struct mdesc_handle *md, u64 grp, |
| 1190 | int index) |
| 1191 | { |
| 1192 | cpumask_t mask; |
| 1193 | int cpu; |
| 1194 | |
| 1195 | numa_parse_mdesc_group_cpus(md, grp, &mask); |
| 1196 | |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 1197 | for_each_cpu(cpu, &mask) |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1198 | numa_cpu_lookup_table[cpu] = index; |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 1199 | cpumask_copy(&numa_cpumask_lookup_table[index], &mask); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1200 | |
| 1201 | if (numa_debug) { |
| 1202 | printk(KERN_INFO "NUMA GROUP[%d]: cpus [ ", index); |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 1203 | for_each_cpu(cpu, &mask) |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1204 | printk("%d ", cpu); |
| 1205 | printk("]\n"); |
| 1206 | } |
| 1207 | |
| 1208 | return numa_attach_mlgroup(md, grp, index); |
| 1209 | } |
| 1210 | |
| 1211 | static int __init numa_parse_mdesc(void) |
| 1212 | { |
| 1213 | struct mdesc_handle *md = mdesc_grab(); |
| 1214 | int i, err, count; |
| 1215 | u64 node; |
| 1216 | |
| 1217 | node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups"); |
| 1218 | if (node == MDESC_NODE_NULL) { |
| 1219 | mdesc_release(md); |
| 1220 | return -ENOENT; |
| 1221 | } |
| 1222 | |
| 1223 | err = grab_mblocks(md); |
| 1224 | if (err < 0) |
| 1225 | goto out; |
| 1226 | |
| 1227 | err = grab_mlgroups(md); |
| 1228 | if (err < 0) |
| 1229 | goto out; |
| 1230 | |
| 1231 | count = 0; |
| 1232 | mdesc_for_each_node_by_name(md, node, "group") { |
| 1233 | err = numa_parse_mdesc_group(md, node, count); |
| 1234 | if (err < 0) |
| 1235 | break; |
| 1236 | count++; |
| 1237 | } |
| 1238 | |
| 1239 | add_node_ranges(); |
| 1240 | |
| 1241 | for (i = 0; i < num_node_masks; i++) { |
| 1242 | allocate_node_data(i); |
| 1243 | node_set_online(i); |
| 1244 | } |
| 1245 | |
| 1246 | err = 0; |
| 1247 | out: |
| 1248 | mdesc_release(md); |
| 1249 | return err; |
| 1250 | } |
| 1251 | |
David S. Miller | 072bd41 | 2008-08-18 20:36:17 -0700 | [diff] [blame] | 1252 | static int __init numa_parse_jbus(void) |
| 1253 | { |
| 1254 | unsigned long cpu, index; |
| 1255 | |
| 1256 | /* NUMA node id is encoded in bits 36 and higher, and there is |
| 1257 | * a 1-to-1 mapping from CPU ID to NUMA node ID. |
| 1258 | */ |
| 1259 | index = 0; |
| 1260 | for_each_present_cpu(cpu) { |
| 1261 | numa_cpu_lookup_table[cpu] = index; |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 1262 | cpumask_copy(&numa_cpumask_lookup_table[index], cpumask_of(cpu)); |
David S. Miller | 072bd41 | 2008-08-18 20:36:17 -0700 | [diff] [blame] | 1263 | node_masks[index].mask = ~((1UL << 36UL) - 1UL); |
| 1264 | node_masks[index].val = cpu << 36UL; |
| 1265 | |
| 1266 | index++; |
| 1267 | } |
| 1268 | num_node_masks = index; |
| 1269 | |
| 1270 | add_node_ranges(); |
| 1271 | |
| 1272 | for (index = 0; index < num_node_masks; index++) { |
| 1273 | allocate_node_data(index); |
| 1274 | node_set_online(index); |
| 1275 | } |
| 1276 | |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1280 | static int __init numa_parse_sun4u(void) |
| 1281 | { |
David S. Miller | 072bd41 | 2008-08-18 20:36:17 -0700 | [diff] [blame] | 1282 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 1283 | unsigned long ver; |
| 1284 | |
| 1285 | __asm__ ("rdpr %%ver, %0" : "=r" (ver)); |
| 1286 | if ((ver >> 32UL) == __JALAPENO_ID || |
| 1287 | (ver >> 32UL) == __SERRANO_ID) |
| 1288 | return numa_parse_jbus(); |
| 1289 | } |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1290 | return -1; |
| 1291 | } |
| 1292 | |
| 1293 | static int __init bootmem_init_numa(void) |
| 1294 | { |
| 1295 | int err = -1; |
| 1296 | |
| 1297 | numadbg("bootmem_init_numa()\n"); |
| 1298 | |
| 1299 | if (numa_enabled) { |
| 1300 | if (tlb_type == hypervisor) |
| 1301 | err = numa_parse_mdesc(); |
| 1302 | else |
| 1303 | err = numa_parse_sun4u(); |
| 1304 | } |
| 1305 | return err; |
| 1306 | } |
| 1307 | |
| 1308 | #else |
| 1309 | |
| 1310 | static int bootmem_init_numa(void) |
| 1311 | { |
| 1312 | return -1; |
| 1313 | } |
| 1314 | |
| 1315 | #endif |
| 1316 | |
| 1317 | static void __init bootmem_init_nonnuma(void) |
| 1318 | { |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1319 | unsigned long top_of_ram = memblock_end_of_DRAM(); |
| 1320 | unsigned long total_ram = memblock_phys_mem_size(); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1321 | |
| 1322 | numadbg("bootmem_init_nonnuma()\n"); |
| 1323 | |
| 1324 | printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n", |
| 1325 | top_of_ram, total_ram); |
| 1326 | printk(KERN_INFO "Memory hole size: %ldMB\n", |
| 1327 | (top_of_ram - total_ram) >> 20); |
| 1328 | |
| 1329 | init_node_masks_nonnuma(); |
Tang Chen | e7e8de5 | 2014-01-21 15:49:26 -0800 | [diff] [blame] | 1330 | memblock_set_node(0, (phys_addr_t)ULLONG_MAX, &memblock.memory, 0); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1331 | allocate_node_data(0); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1332 | node_set_online(0); |
| 1333 | } |
| 1334 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1335 | static unsigned long __init bootmem_init(unsigned long phys_base) |
| 1336 | { |
| 1337 | unsigned long end_pfn; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1338 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1339 | end_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | max_pfn = max_low_pfn = end_pfn; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1341 | min_low_pfn = (phys_base >> PAGE_SHIFT); |
| 1342 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1343 | if (bootmem_init_numa() < 0) |
| 1344 | bootmem_init_nonnuma(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
David S. Miller | 625d693 | 2012-04-25 13:13:43 -0700 | [diff] [blame] | 1346 | /* Dump memblock with node info. */ |
| 1347 | memblock_dump_all(); |
| 1348 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1349 | /* XXX cpu notifier XXX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
David S. Miller | 625d693 | 2012-04-25 13:13:43 -0700 | [diff] [blame] | 1351 | sparse_memory_present_with_active_regions(MAX_NUMNODES); |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1352 | sparse_init(); |
| 1353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | return end_pfn; |
| 1355 | } |
| 1356 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1357 | static struct linux_prom64_registers pall[MAX_BANKS] __initdata; |
| 1358 | static int pall_ents __initdata; |
| 1359 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1360 | #ifdef CONFIG_DEBUG_PAGEALLOC |
Sam Ravnborg | 896aef4 | 2008-02-24 19:49:52 -0800 | [diff] [blame] | 1361 | static unsigned long __ref kernel_map_range(unsigned long pstart, |
| 1362 | unsigned long pend, pgprot_t prot) |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1363 | { |
| 1364 | unsigned long vstart = PAGE_OFFSET + pstart; |
| 1365 | unsigned long vend = PAGE_OFFSET + pend; |
| 1366 | unsigned long alloc_bytes = 0UL; |
| 1367 | |
| 1368 | if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) { |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1369 | prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n", |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1370 | vstart, vend); |
| 1371 | prom_halt(); |
| 1372 | } |
| 1373 | |
| 1374 | while (vstart < vend) { |
| 1375 | unsigned long this_end, paddr = __pa(vstart); |
| 1376 | pgd_t *pgd = pgd_offset_k(vstart); |
| 1377 | pud_t *pud; |
| 1378 | pmd_t *pmd; |
| 1379 | pte_t *pte; |
| 1380 | |
| 1381 | pud = pud_offset(pgd, vstart); |
| 1382 | if (pud_none(*pud)) { |
| 1383 | pmd_t *new; |
| 1384 | |
| 1385 | new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); |
| 1386 | alloc_bytes += PAGE_SIZE; |
| 1387 | pud_populate(&init_mm, pud, new); |
| 1388 | } |
| 1389 | |
| 1390 | pmd = pmd_offset(pud, vstart); |
| 1391 | if (!pmd_present(*pmd)) { |
| 1392 | pte_t *new; |
| 1393 | |
| 1394 | new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); |
| 1395 | alloc_bytes += PAGE_SIZE; |
| 1396 | pmd_populate_kernel(&init_mm, pmd, new); |
| 1397 | } |
| 1398 | |
| 1399 | pte = pte_offset_kernel(pmd, vstart); |
| 1400 | this_end = (vstart + PMD_SIZE) & PMD_MASK; |
| 1401 | if (this_end > vend) |
| 1402 | this_end = vend; |
| 1403 | |
| 1404 | while (vstart < this_end) { |
| 1405 | pte_val(*pte) = (paddr | pgprot_val(prot)); |
| 1406 | |
| 1407 | vstart += PAGE_SIZE; |
| 1408 | paddr += PAGE_SIZE; |
| 1409 | pte++; |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | return alloc_bytes; |
| 1414 | } |
| 1415 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1416 | extern unsigned int kvmap_linear_patch[1]; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1417 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |
| 1418 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1419 | static void __init kpte_set_val(unsigned long index, unsigned long val) |
| 1420 | { |
| 1421 | unsigned long *ptr = kpte_linear_bitmap; |
| 1422 | |
| 1423 | val <<= ((index % (BITS_PER_LONG / 2)) * 2); |
| 1424 | ptr += (index / (BITS_PER_LONG / 2)); |
| 1425 | |
| 1426 | *ptr |= val; |
| 1427 | } |
| 1428 | |
| 1429 | static const unsigned long kpte_shift_min = 28; /* 256MB */ |
| 1430 | static const unsigned long kpte_shift_max = 34; /* 16GB */ |
| 1431 | static const unsigned long kpte_shift_incr = 3; |
| 1432 | |
| 1433 | static unsigned long kpte_mark_using_shift(unsigned long start, unsigned long end, |
| 1434 | unsigned long shift) |
| 1435 | { |
| 1436 | unsigned long size = (1UL << shift); |
| 1437 | unsigned long mask = (size - 1UL); |
| 1438 | unsigned long remains = end - start; |
| 1439 | unsigned long val; |
| 1440 | |
| 1441 | if (remains < size || (start & mask)) |
| 1442 | return start; |
| 1443 | |
| 1444 | /* VAL maps: |
| 1445 | * |
| 1446 | * shift 28 --> kern_linear_pte_xor index 1 |
| 1447 | * shift 31 --> kern_linear_pte_xor index 2 |
| 1448 | * shift 34 --> kern_linear_pte_xor index 3 |
| 1449 | */ |
| 1450 | val = ((shift - kpte_shift_min) / kpte_shift_incr) + 1; |
| 1451 | |
| 1452 | remains &= ~mask; |
| 1453 | if (shift != kpte_shift_max) |
| 1454 | remains = size; |
| 1455 | |
| 1456 | while (remains) { |
| 1457 | unsigned long index = start >> kpte_shift_min; |
| 1458 | |
| 1459 | kpte_set_val(index, val); |
| 1460 | |
| 1461 | start += 1UL << kpte_shift_min; |
| 1462 | remains -= 1UL << kpte_shift_min; |
| 1463 | } |
| 1464 | |
| 1465 | return start; |
| 1466 | } |
| 1467 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1468 | static void __init mark_kpte_bitmap(unsigned long start, unsigned long end) |
| 1469 | { |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1470 | unsigned long smallest_size, smallest_mask; |
| 1471 | unsigned long s; |
| 1472 | |
| 1473 | smallest_size = (1UL << kpte_shift_min); |
| 1474 | smallest_mask = (smallest_size - 1UL); |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1475 | |
| 1476 | while (start < end) { |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1477 | unsigned long orig_start = start; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1478 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1479 | for (s = kpte_shift_max; s >= kpte_shift_min; s -= kpte_shift_incr) { |
| 1480 | start = kpte_mark_using_shift(start, end, s); |
David S. Miller | f7c0033 | 2006-03-05 22:18:50 -0800 | [diff] [blame] | 1481 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1482 | if (start != orig_start) |
| 1483 | break; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1486 | if (start == orig_start) |
| 1487 | start = (start + smallest_size) & ~smallest_mask; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1488 | } |
| 1489 | } |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1490 | |
David S. Miller | 8f361453 | 2007-12-13 06:13:38 -0800 | [diff] [blame] | 1491 | static void __init init_kpte_bitmap(void) |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1492 | { |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1493 | unsigned long i; |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1494 | |
| 1495 | for (i = 0; i < pall_ents; i++) { |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1496 | unsigned long phys_start, phys_end; |
| 1497 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1498 | phys_start = pall[i].phys_addr; |
| 1499 | phys_end = phys_start + pall[i].reg_size; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1500 | |
| 1501 | mark_kpte_bitmap(phys_start, phys_end); |
David S. Miller | 8f361453 | 2007-12-13 06:13:38 -0800 | [diff] [blame] | 1502 | } |
| 1503 | } |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1504 | |
David S. Miller | 8f361453 | 2007-12-13 06:13:38 -0800 | [diff] [blame] | 1505 | static void __init kernel_physical_mapping_init(void) |
| 1506 | { |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1507 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 8f361453 | 2007-12-13 06:13:38 -0800 | [diff] [blame] | 1508 | unsigned long i, mem_alloced = 0UL; |
| 1509 | |
| 1510 | for (i = 0; i < pall_ents; i++) { |
| 1511 | unsigned long phys_start, phys_end; |
| 1512 | |
| 1513 | phys_start = pall[i].phys_addr; |
| 1514 | phys_end = phys_start + pall[i].reg_size; |
| 1515 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1516 | mem_alloced += kernel_map_range(phys_start, phys_end, |
| 1517 | PAGE_KERNEL); |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | printk("Allocated %ld bytes for kernel page tables.\n", |
| 1521 | mem_alloced); |
| 1522 | |
| 1523 | kvmap_linear_patch[0] = 0x01000000; /* nop */ |
| 1524 | flushi(&kvmap_linear_patch[0]); |
| 1525 | |
| 1526 | __flush_tlb_all(); |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1527 | #endif |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1530 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1531 | void kernel_map_pages(struct page *page, int numpages, int enable) |
| 1532 | { |
| 1533 | unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT; |
| 1534 | unsigned long phys_end = phys_start + (numpages * PAGE_SIZE); |
| 1535 | |
| 1536 | kernel_map_range(phys_start, phys_end, |
| 1537 | (enable ? PAGE_KERNEL : __pgprot(0))); |
| 1538 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 1539 | flush_tsb_kernel_range(PAGE_OFFSET + phys_start, |
| 1540 | PAGE_OFFSET + phys_end); |
| 1541 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1542 | /* we should perform an IPI and flush all tlbs, |
| 1543 | * but that can deadlock->flush only current cpu. |
| 1544 | */ |
| 1545 | __flush_tlb_kernel_range(PAGE_OFFSET + phys_start, |
| 1546 | PAGE_OFFSET + phys_end); |
| 1547 | } |
| 1548 | #endif |
| 1549 | |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 1550 | unsigned long __init find_ecache_flush_span(unsigned long size) |
| 1551 | { |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1552 | int i; |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 1553 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1554 | for (i = 0; i < pavail_ents; i++) { |
| 1555 | if (pavail[i].reg_size >= size) |
| 1556 | return pavail[i].phys_addr; |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | return ~0UL; |
| 1560 | } |
| 1561 | |
David S. Miller | b2d4383 | 2013-09-20 21:50:41 -0700 | [diff] [blame] | 1562 | unsigned long PAGE_OFFSET; |
| 1563 | EXPORT_SYMBOL(PAGE_OFFSET); |
| 1564 | |
| 1565 | static void __init page_offset_shift_patch_one(unsigned int *insn, unsigned long phys_bits) |
| 1566 | { |
| 1567 | unsigned long final_shift; |
| 1568 | unsigned int val = *insn; |
| 1569 | unsigned int cnt; |
| 1570 | |
| 1571 | /* We are patching in ilog2(max_supported_phys_address), and |
| 1572 | * we are doing so in a manner similar to a relocation addend. |
| 1573 | * That is, we are adding the shift value to whatever value |
| 1574 | * is in the shift instruction count field already. |
| 1575 | */ |
| 1576 | cnt = (val & 0x3f); |
| 1577 | val &= ~0x3f; |
| 1578 | |
| 1579 | /* If we are trying to shift >= 64 bits, clear the destination |
| 1580 | * register. This can happen when phys_bits ends up being equal |
| 1581 | * to MAX_PHYS_ADDRESS_BITS. |
| 1582 | */ |
| 1583 | final_shift = (cnt + (64 - phys_bits)); |
| 1584 | if (final_shift >= 64) { |
| 1585 | unsigned int rd = (val >> 25) & 0x1f; |
| 1586 | |
| 1587 | val = 0x80100000 | (rd << 25); |
| 1588 | } else { |
| 1589 | val |= final_shift; |
| 1590 | } |
| 1591 | *insn = val; |
| 1592 | |
| 1593 | __asm__ __volatile__("flush %0" |
| 1594 | : /* no outputs */ |
| 1595 | : "r" (insn)); |
| 1596 | } |
| 1597 | |
| 1598 | static void __init page_offset_shift_patch(unsigned long phys_bits) |
| 1599 | { |
| 1600 | extern unsigned int __page_offset_shift_patch; |
| 1601 | extern unsigned int __page_offset_shift_patch_end; |
| 1602 | unsigned int *p; |
| 1603 | |
| 1604 | p = &__page_offset_shift_patch; |
| 1605 | while (p < &__page_offset_shift_patch_end) { |
| 1606 | unsigned int *insn = (unsigned int *)(unsigned long)*p; |
| 1607 | |
| 1608 | page_offset_shift_patch_one(insn, phys_bits); |
| 1609 | |
| 1610 | p++; |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | static void __init setup_page_offset(void) |
| 1615 | { |
| 1616 | unsigned long max_phys_bits = 40; |
| 1617 | |
| 1618 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 1619 | max_phys_bits = 42; |
| 1620 | } else if (tlb_type == hypervisor) { |
| 1621 | switch (sun4v_chip_type) { |
| 1622 | case SUN4V_CHIP_NIAGARA1: |
| 1623 | case SUN4V_CHIP_NIAGARA2: |
| 1624 | max_phys_bits = 39; |
| 1625 | break; |
| 1626 | case SUN4V_CHIP_NIAGARA3: |
| 1627 | max_phys_bits = 43; |
| 1628 | break; |
| 1629 | case SUN4V_CHIP_NIAGARA4: |
| 1630 | case SUN4V_CHIP_NIAGARA5: |
| 1631 | case SUN4V_CHIP_SPARC64X: |
| 1632 | default: |
| 1633 | max_phys_bits = 47; |
| 1634 | break; |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | if (max_phys_bits > MAX_PHYS_ADDRESS_BITS) { |
| 1639 | prom_printf("MAX_PHYS_ADDRESS_BITS is too small, need %lu\n", |
| 1640 | max_phys_bits); |
| 1641 | prom_halt(); |
| 1642 | } |
| 1643 | |
| 1644 | PAGE_OFFSET = PAGE_OFFSET_BY_BITS(max_phys_bits); |
| 1645 | |
| 1646 | pr_info("PAGE_OFFSET is 0x%016lx (max_phys_bits == %lu)\n", |
| 1647 | PAGE_OFFSET, max_phys_bits); |
| 1648 | |
| 1649 | page_offset_shift_patch(max_phys_bits); |
| 1650 | } |
| 1651 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1652 | static void __init tsb_phys_patch(void) |
| 1653 | { |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1654 | struct tsb_ldquad_phys_patch_entry *pquad; |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1655 | struct tsb_phys_patch_entry *p; |
| 1656 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1657 | pquad = &__tsb_ldquad_phys_patch; |
| 1658 | while (pquad < &__tsb_ldquad_phys_patch_end) { |
| 1659 | unsigned long addr = pquad->addr; |
| 1660 | |
| 1661 | if (tlb_type == hypervisor) |
| 1662 | *(unsigned int *) addr = pquad->sun4v_insn; |
| 1663 | else |
| 1664 | *(unsigned int *) addr = pquad->sun4u_insn; |
| 1665 | wmb(); |
| 1666 | __asm__ __volatile__("flush %0" |
| 1667 | : /* no outputs */ |
| 1668 | : "r" (addr)); |
| 1669 | |
| 1670 | pquad++; |
| 1671 | } |
| 1672 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1673 | p = &__tsb_phys_patch; |
| 1674 | while (p < &__tsb_phys_patch_end) { |
| 1675 | unsigned long addr = p->addr; |
| 1676 | |
| 1677 | *(unsigned int *) addr = p->insn; |
| 1678 | wmb(); |
| 1679 | __asm__ __volatile__("flush %0" |
| 1680 | : /* no outputs */ |
| 1681 | : "r" (addr)); |
| 1682 | |
| 1683 | p++; |
| 1684 | } |
| 1685 | } |
| 1686 | |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1687 | /* Don't mark as init, we give this to the Hypervisor. */ |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1688 | #ifndef CONFIG_DEBUG_PAGEALLOC |
| 1689 | #define NUM_KTSB_DESCR 2 |
| 1690 | #else |
| 1691 | #define NUM_KTSB_DESCR 1 |
| 1692 | #endif |
| 1693 | static struct hv_tsb_descr ktsb_descr[NUM_KTSB_DESCR]; |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1694 | extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES]; |
| 1695 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 1696 | static void patch_one_ktsb_phys(unsigned int *start, unsigned int *end, unsigned long pa) |
| 1697 | { |
| 1698 | pa >>= KTSB_PHYS_SHIFT; |
| 1699 | |
| 1700 | while (start < end) { |
| 1701 | unsigned int *ia = (unsigned int *)(unsigned long)*start; |
| 1702 | |
| 1703 | ia[0] = (ia[0] & ~0x3fffff) | (pa >> 10); |
| 1704 | __asm__ __volatile__("flush %0" : : "r" (ia)); |
| 1705 | |
| 1706 | ia[1] = (ia[1] & ~0x3ff) | (pa & 0x3ff); |
| 1707 | __asm__ __volatile__("flush %0" : : "r" (ia + 1)); |
| 1708 | |
| 1709 | start++; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | static void ktsb_phys_patch(void) |
| 1714 | { |
| 1715 | extern unsigned int __swapper_tsb_phys_patch; |
| 1716 | extern unsigned int __swapper_tsb_phys_patch_end; |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 1717 | unsigned long ktsb_pa; |
| 1718 | |
| 1719 | ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE); |
| 1720 | patch_one_ktsb_phys(&__swapper_tsb_phys_patch, |
| 1721 | &__swapper_tsb_phys_patch_end, ktsb_pa); |
| 1722 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 0785a8e | 2011-08-06 05:26:35 -0700 | [diff] [blame] | 1723 | { |
| 1724 | extern unsigned int __swapper_4m_tsb_phys_patch; |
| 1725 | extern unsigned int __swapper_4m_tsb_phys_patch_end; |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 1726 | ktsb_pa = (kern_base + |
| 1727 | ((unsigned long)&swapper_4m_tsb[0] - KERNBASE)); |
| 1728 | patch_one_ktsb_phys(&__swapper_4m_tsb_phys_patch, |
| 1729 | &__swapper_4m_tsb_phys_patch_end, ktsb_pa); |
David S. Miller | 0785a8e | 2011-08-06 05:26:35 -0700 | [diff] [blame] | 1730 | } |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 1731 | #endif |
| 1732 | } |
| 1733 | |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1734 | static void __init sun4v_ktsb_init(void) |
| 1735 | { |
| 1736 | unsigned long ktsb_pa; |
| 1737 | |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1738 | /* First KTSB for PAGE_SIZE mappings. */ |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1739 | ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE); |
| 1740 | |
| 1741 | switch (PAGE_SIZE) { |
| 1742 | case 8 * 1024: |
| 1743 | default: |
| 1744 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_8K; |
| 1745 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_8K; |
| 1746 | break; |
| 1747 | |
| 1748 | case 64 * 1024: |
| 1749 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_64K; |
| 1750 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_64K; |
| 1751 | break; |
| 1752 | |
| 1753 | case 512 * 1024: |
| 1754 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_512K; |
| 1755 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_512K; |
| 1756 | break; |
| 1757 | |
| 1758 | case 4 * 1024 * 1024: |
| 1759 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_4MB; |
| 1760 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_4MB; |
| 1761 | break; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame] | 1762 | } |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1763 | |
David S. Miller | 3f19a84 | 2006-02-17 12:03:20 -0800 | [diff] [blame] | 1764 | ktsb_descr[0].assoc = 1; |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1765 | ktsb_descr[0].num_ttes = KERNEL_TSB_NENTRIES; |
| 1766 | ktsb_descr[0].ctx_idx = 0; |
| 1767 | ktsb_descr[0].tsb_base = ktsb_pa; |
| 1768 | ktsb_descr[0].resv = 0; |
| 1769 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1770 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 1771 | /* Second KTSB for 4MB/256MB/2GB/16GB mappings. */ |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1772 | ktsb_pa = (kern_base + |
| 1773 | ((unsigned long)&swapper_4m_tsb[0] - KERNBASE)); |
| 1774 | |
| 1775 | ktsb_descr[1].pgsz_idx = HV_PGSZ_IDX_4MB; |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1776 | ktsb_descr[1].pgsz_mask = ((HV_PGSZ_MASK_4MB | |
| 1777 | HV_PGSZ_MASK_256MB | |
| 1778 | HV_PGSZ_MASK_2GB | |
| 1779 | HV_PGSZ_MASK_16GB) & |
| 1780 | cpu_pgsz_mask); |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1781 | ktsb_descr[1].assoc = 1; |
| 1782 | ktsb_descr[1].num_ttes = KERNEL_TSB4M_NENTRIES; |
| 1783 | ktsb_descr[1].ctx_idx = 0; |
| 1784 | ktsb_descr[1].tsb_base = ktsb_pa; |
| 1785 | ktsb_descr[1].resv = 0; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1786 | #endif |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1787 | } |
| 1788 | |
Paul Gortmaker | 2066aad | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 1789 | void sun4v_ktsb_register(void) |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1790 | { |
David S. Miller | 7db35f3 | 2007-05-29 02:22:14 -0700 | [diff] [blame] | 1791 | unsigned long pa, ret; |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1792 | |
| 1793 | pa = kern_base + ((unsigned long)&ktsb_descr[0] - KERNBASE); |
| 1794 | |
David S. Miller | 7db35f3 | 2007-05-29 02:22:14 -0700 | [diff] [blame] | 1795 | ret = sun4v_mmu_tsb_ctx0(NUM_KTSB_DESCR, pa); |
| 1796 | if (ret != 0) { |
| 1797 | prom_printf("hypervisor_mmu_tsb_ctx0[%lx]: " |
| 1798 | "errors with %lx\n", pa, ret); |
| 1799 | prom_halt(); |
| 1800 | } |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1803 | static void __init sun4u_linear_pte_xor_finalize(void) |
| 1804 | { |
| 1805 | #ifndef CONFIG_DEBUG_PAGEALLOC |
| 1806 | /* This is where we would add Panther support for |
| 1807 | * 32MB and 256MB pages. |
| 1808 | */ |
| 1809 | #endif |
| 1810 | } |
| 1811 | |
| 1812 | static void __init sun4v_linear_pte_xor_finalize(void) |
| 1813 | { |
| 1814 | #ifndef CONFIG_DEBUG_PAGEALLOC |
| 1815 | if (cpu_pgsz_mask & HV_PGSZ_MASK_256MB) { |
| 1816 | kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZ256MB_4V) ^ |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 1817 | PAGE_OFFSET; |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1818 | kern_linear_pte_xor[1] |= (_PAGE_CP_4V | _PAGE_CV_4V | |
| 1819 | _PAGE_P_4V | _PAGE_W_4V); |
| 1820 | } else { |
| 1821 | kern_linear_pte_xor[1] = kern_linear_pte_xor[0]; |
| 1822 | } |
| 1823 | |
| 1824 | if (cpu_pgsz_mask & HV_PGSZ_MASK_2GB) { |
| 1825 | kern_linear_pte_xor[2] = (_PAGE_VALID | _PAGE_SZ2GB_4V) ^ |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 1826 | PAGE_OFFSET; |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1827 | kern_linear_pte_xor[2] |= (_PAGE_CP_4V | _PAGE_CV_4V | |
| 1828 | _PAGE_P_4V | _PAGE_W_4V); |
| 1829 | } else { |
| 1830 | kern_linear_pte_xor[2] = kern_linear_pte_xor[1]; |
| 1831 | } |
| 1832 | |
| 1833 | if (cpu_pgsz_mask & HV_PGSZ_MASK_16GB) { |
| 1834 | kern_linear_pte_xor[3] = (_PAGE_VALID | _PAGE_SZ16GB_4V) ^ |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 1835 | PAGE_OFFSET; |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1836 | kern_linear_pte_xor[3] |= (_PAGE_CP_4V | _PAGE_CV_4V | |
| 1837 | _PAGE_P_4V | _PAGE_W_4V); |
| 1838 | } else { |
| 1839 | kern_linear_pte_xor[3] = kern_linear_pte_xor[2]; |
| 1840 | } |
| 1841 | #endif |
| 1842 | } |
| 1843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | /* paging_init() sets up the page tables */ |
| 1845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | static unsigned long last_valid_pfn; |
David S. Miller | 2b77933 | 2013-09-25 14:33:16 -0700 | [diff] [blame] | 1847 | pgd_t swapper_pg_dir[PTRS_PER_PGD]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1849 | static void sun4u_pgprot_init(void); |
| 1850 | static void sun4v_pgprot_init(void); |
| 1851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | void __init paging_init(void) |
| 1853 | { |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 1854 | unsigned long end_pfn, shift, phys_base; |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1855 | unsigned long real_end, i; |
Paul Gortmaker | aa6f079 | 2012-05-09 20:44:29 -0400 | [diff] [blame] | 1856 | int node; |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1857 | |
David S. Miller | b2d4383 | 2013-09-20 21:50:41 -0700 | [diff] [blame] | 1858 | setup_page_offset(); |
| 1859 | |
David S. Miller | 22adb35 | 2007-05-26 01:14:43 -0700 | [diff] [blame] | 1860 | /* These build time checkes make sure that the dcache_dirty_cpu() |
| 1861 | * page->flags usage will work. |
| 1862 | * |
| 1863 | * When a page gets marked as dcache-dirty, we store the |
| 1864 | * cpu number starting at bit 32 in the page->flags. Also, |
| 1865 | * functions like clear_dcache_dirty_cpu use the cpu mask |
| 1866 | * in 13-bit signed-immediate instruction fields. |
| 1867 | */ |
Christoph Lameter | 9223b41 | 2008-04-28 02:12:48 -0700 | [diff] [blame] | 1868 | |
| 1869 | /* |
| 1870 | * Page flags must not reach into upper 32 bits that are used |
| 1871 | * for the cpu number |
| 1872 | */ |
| 1873 | BUILD_BUG_ON(NR_PAGEFLAGS > 32); |
| 1874 | |
| 1875 | /* |
| 1876 | * The bit fields placed in the high range must not reach below |
| 1877 | * the 32 bit boundary. Otherwise we cannot place the cpu field |
| 1878 | * at the 32 bit boundary. |
| 1879 | */ |
David S. Miller | 22adb35 | 2007-05-26 01:14:43 -0700 | [diff] [blame] | 1880 | BUILD_BUG_ON(SECTIONS_WIDTH + NODES_WIDTH + ZONES_WIDTH + |
Christoph Lameter | 9223b41 | 2008-04-28 02:12:48 -0700 | [diff] [blame] | 1881 | ilog2(roundup_pow_of_two(NR_CPUS)) > 32); |
| 1882 | |
David S. Miller | 22adb35 | 2007-05-26 01:14:43 -0700 | [diff] [blame] | 1883 | BUILD_BUG_ON(NR_CPUS > 4096); |
| 1884 | |
David S. Miller | 481295f | 2006-02-07 21:51:08 -0800 | [diff] [blame] | 1885 | kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL; |
| 1886 | kern_size = (unsigned long)&_end - (unsigned long)KERNBASE; |
| 1887 | |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1888 | /* Invalidate both kernel TSBs. */ |
David S. Miller | 8b23427 | 2006-02-17 18:01:02 -0800 | [diff] [blame] | 1889 | memset(swapper_tsb, 0x40, sizeof(swapper_tsb)); |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1890 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1891 | memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb)); |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1892 | #endif |
David S. Miller | 8b23427 | 2006-02-17 18:01:02 -0800 | [diff] [blame] | 1893 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1894 | if (tlb_type == hypervisor) |
| 1895 | sun4v_pgprot_init(); |
| 1896 | else |
| 1897 | sun4u_pgprot_init(); |
| 1898 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1899 | if (tlb_type == cheetah_plus || |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 1900 | tlb_type == hypervisor) { |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1901 | tsb_phys_patch(); |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 1902 | ktsb_phys_patch(); |
| 1903 | } |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1904 | |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1905 | if (tlb_type == hypervisor) |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1906 | sun4v_patch_tlb_handlers(); |
| 1907 | |
David S. Miller | a94a172 | 2008-05-11 21:04:48 -0700 | [diff] [blame] | 1908 | /* Find available physical memory... |
| 1909 | * |
| 1910 | * Read it twice in order to work around a bug in openfirmware. |
| 1911 | * The call to grab this table itself can cause openfirmware to |
| 1912 | * allocate memory, which in turn can take away some space from |
| 1913 | * the list of available memory. Reading it twice makes sure |
| 1914 | * we really do get the final value. |
| 1915 | */ |
| 1916 | read_obp_translations(); |
| 1917 | read_obp_memory("reg", &pall[0], &pall_ents); |
| 1918 | read_obp_memory("available", &pavail[0], &pavail_ents); |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1919 | read_obp_memory("available", &pavail[0], &pavail_ents); |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1920 | |
| 1921 | phys_base = 0xffffffffffffffffUL; |
David S. Miller | 3b2a7e2 | 2008-02-13 18:13:20 -0800 | [diff] [blame] | 1922 | for (i = 0; i < pavail_ents; i++) { |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1923 | phys_base = min(phys_base, pavail[i].phys_addr); |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1924 | memblock_add(pavail[i].phys_addr, pavail[i].reg_size); |
David S. Miller | 3b2a7e2 | 2008-02-13 18:13:20 -0800 | [diff] [blame] | 1925 | } |
| 1926 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1927 | memblock_reserve(kern_base, kern_size); |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1928 | |
David S. Miller | 4e82c9a | 2008-02-13 18:00:03 -0800 | [diff] [blame] | 1929 | find_ramdisk(phys_base); |
| 1930 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1931 | memblock_enforce_memory_limit(cmdline_memory_size); |
David S. Miller | 25b0c65 | 2008-02-13 18:20:14 -0800 | [diff] [blame] | 1932 | |
Tejun Heo | 1aadc05 | 2011-12-08 10:22:08 -0800 | [diff] [blame] | 1933 | memblock_allow_resize(); |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 1934 | memblock_dump_all(); |
David S. Miller | 3b2a7e2 | 2008-02-13 18:13:20 -0800 | [diff] [blame] | 1935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | set_bit(0, mmu_context_bmap); |
| 1937 | |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1938 | shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE); |
| 1939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | real_end = (unsigned long)_end; |
David S. Miller | 6465874 | 2008-03-21 17:01:38 -0700 | [diff] [blame] | 1941 | num_kernel_image_mappings = DIV_ROUND_UP(real_end - KERNBASE, 1 << 22); |
| 1942 | printk("Kernel: Using %d locked TLB entries for main kernel image.\n", |
| 1943 | num_kernel_image_mappings); |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1944 | |
| 1945 | /* Set kernel pgd to upper alias so physical page computations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | * work. |
| 1947 | */ |
| 1948 | init_mm.pgd += ((shift) / (sizeof(pgd_t))); |
| 1949 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1950 | memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | /* Now can init the kernel/bad page tables. */ |
| 1953 | pud_set(pud_offset(&swapper_pg_dir[0], 0), |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1954 | swapper_low_pmd_dir + (shift / sizeof(pgd_t))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 1956 | inherit_prom_mappings(); |
David S. Miller | 5085b4a | 2005-09-22 00:45:41 -0700 | [diff] [blame] | 1957 | |
David S. Miller | 8f361453 | 2007-12-13 06:13:38 -0800 | [diff] [blame] | 1958 | init_kpte_bitmap(); |
| 1959 | |
David S. Miller | a8b900d | 2006-01-31 18:33:37 -0800 | [diff] [blame] | 1960 | /* Ok, we can use our TLB miss and window trap handlers safely. */ |
| 1961 | setup_tba(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 1963 | __flush_tlb_all(); |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 1964 | |
David S. Miller | ad07200 | 2008-02-13 19:21:51 -0800 | [diff] [blame] | 1965 | prom_build_devicetree(); |
David S. Miller | b696fdc | 2009-05-26 22:37:25 -0700 | [diff] [blame] | 1966 | of_populate_present_mask(); |
David S. Miller | b99c6eb | 2009-06-18 01:44:19 -0700 | [diff] [blame] | 1967 | #ifndef CONFIG_SMP |
| 1968 | of_fill_in_cpu_data(); |
| 1969 | #endif |
David S. Miller | ad07200 | 2008-02-13 19:21:51 -0800 | [diff] [blame] | 1970 | |
David S. Miller | 890db40 | 2009-04-01 03:13:15 -0700 | [diff] [blame] | 1971 | if (tlb_type == hypervisor) { |
David S. Miller | 4a28333 | 2008-02-13 19:22:23 -0800 | [diff] [blame] | 1972 | sun4v_mdesc_init(); |
Stephen Rothwell | 6ac5c61 | 2009-06-15 03:06:18 -0700 | [diff] [blame] | 1973 | mdesc_populate_present_mask(cpu_all_mask); |
David S. Miller | b99c6eb | 2009-06-18 01:44:19 -0700 | [diff] [blame] | 1974 | #ifndef CONFIG_SMP |
| 1975 | mdesc_fill_in_cpu_data(cpu_all_mask); |
| 1976 | #endif |
David S. Miller | ce33fdc | 2012-09-06 19:01:25 -0700 | [diff] [blame] | 1977 | mdesc_get_page_sizes(cpu_all_mask, &cpu_pgsz_mask); |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1978 | |
| 1979 | sun4v_linear_pte_xor_finalize(); |
| 1980 | |
| 1981 | sun4v_ktsb_init(); |
| 1982 | sun4v_ktsb_register(); |
David S. Miller | ce33fdc | 2012-09-06 19:01:25 -0700 | [diff] [blame] | 1983 | } else { |
| 1984 | unsigned long impl, ver; |
| 1985 | |
| 1986 | cpu_pgsz_mask = (HV_PGSZ_MASK_8K | HV_PGSZ_MASK_64K | |
| 1987 | HV_PGSZ_MASK_512K | HV_PGSZ_MASK_4MB); |
| 1988 | |
| 1989 | __asm__ __volatile__("rdpr %%ver, %0" : "=r" (ver)); |
| 1990 | impl = ((ver >> 32) & 0xffff); |
| 1991 | if (impl == PANTHER_IMPL) |
| 1992 | cpu_pgsz_mask |= (HV_PGSZ_MASK_32MB | |
| 1993 | HV_PGSZ_MASK_256MB); |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1994 | |
| 1995 | sun4u_linear_pte_xor_finalize(); |
David S. Miller | 890db40 | 2009-04-01 03:13:15 -0700 | [diff] [blame] | 1996 | } |
David S. Miller | 4a28333 | 2008-02-13 19:22:23 -0800 | [diff] [blame] | 1997 | |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 1998 | /* Flush the TLBs and the 4M TSB so that the updated linear |
| 1999 | * pte XOR settings are realized for all mappings. |
| 2000 | */ |
| 2001 | __flush_tlb_all(); |
| 2002 | #ifndef CONFIG_DEBUG_PAGEALLOC |
| 2003 | memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb)); |
| 2004 | #endif |
| 2005 | __flush_tlb_all(); |
| 2006 | |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 2007 | /* Setup bootmem... */ |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2008 | last_valid_pfn = end_pfn = bootmem_init(phys_base); |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 2009 | |
David S. Miller | 5ed56f1 | 2012-04-26 20:50:34 -0700 | [diff] [blame] | 2010 | /* Once the OF device tree and MDESC have been setup, we know |
| 2011 | * the list of possible cpus. Therefore we can allocate the |
| 2012 | * IRQ stacks. |
| 2013 | */ |
| 2014 | for_each_possible_cpu(i) { |
Paul Gortmaker | aa6f079 | 2012-05-09 20:44:29 -0400 | [diff] [blame] | 2015 | node = cpu_to_node(i); |
David S. Miller | 5ed56f1 | 2012-04-26 20:50:34 -0700 | [diff] [blame] | 2016 | |
| 2017 | softirq_stack[i] = __alloc_bootmem_node(NODE_DATA(node), |
| 2018 | THREAD_SIZE, |
| 2019 | THREAD_SIZE, 0); |
| 2020 | hardirq_stack[i] = __alloc_bootmem_node(NODE_DATA(node), |
| 2021 | THREAD_SIZE, |
| 2022 | THREAD_SIZE, 0); |
| 2023 | } |
| 2024 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 2025 | kernel_physical_mapping_init(); |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 2026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | { |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2028 | unsigned long max_zone_pfns[MAX_NR_ZONES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2030 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2032 | max_zone_pfns[ZONE_NORMAL] = end_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2034 | free_area_init_nodes(max_zone_pfns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
David S. Miller | 3c62a2d | 2008-02-17 23:22:50 -0800 | [diff] [blame] | 2037 | printk("Booting Linux...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Greg Kroah-Hartman | 7c9503b | 2012-12-21 14:03:26 -0800 | [diff] [blame] | 2040 | int page_in_phys_avail(unsigned long paddr) |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2041 | { |
| 2042 | int i; |
| 2043 | |
| 2044 | paddr &= PAGE_MASK; |
| 2045 | |
| 2046 | for (i = 0; i < pavail_ents; i++) { |
| 2047 | unsigned long start, end; |
| 2048 | |
| 2049 | start = pavail[i].phys_addr; |
| 2050 | end = start + pavail[i].reg_size; |
| 2051 | |
| 2052 | if (paddr >= start && paddr < end) |
| 2053 | return 1; |
| 2054 | } |
| 2055 | if (paddr >= kern_base && paddr < (kern_base + kern_size)) |
| 2056 | return 1; |
| 2057 | #ifdef CONFIG_BLK_DEV_INITRD |
| 2058 | if (paddr >= __pa(initrd_start) && |
| 2059 | paddr < __pa(PAGE_ALIGN(initrd_end))) |
| 2060 | return 1; |
| 2061 | #endif |
| 2062 | |
| 2063 | return 0; |
| 2064 | } |
| 2065 | |
| 2066 | static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata; |
| 2067 | static int pavail_rescan_ents __initdata; |
| 2068 | |
| 2069 | /* Certain OBP calls, such as fetching "available" properties, can |
| 2070 | * claim physical memory. So, along with initializing the valid |
| 2071 | * address bitmap, what we do here is refetch the physical available |
| 2072 | * memory list again, and make sure it provides at least as much |
| 2073 | * memory as 'pavail' does. |
| 2074 | */ |
David S. Miller | d8ed1d4 | 2009-08-25 16:47:46 -0700 | [diff] [blame] | 2075 | static void __init setup_valid_addr_bitmap_from_pavail(unsigned long *bitmap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | int i; |
| 2078 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 2079 | read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 2081 | for (i = 0; i < pavail_ents; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | unsigned long old_start, old_end; |
| 2083 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 2084 | old_start = pavail[i].phys_addr; |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2085 | old_end = old_start + pavail[i].reg_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | while (old_start < old_end) { |
| 2087 | int n; |
| 2088 | |
David S. Miller | c2a5a46 | 2006-06-22 00:01:56 -0700 | [diff] [blame] | 2089 | for (n = 0; n < pavail_rescan_ents; n++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | unsigned long new_start, new_end; |
| 2091 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 2092 | new_start = pavail_rescan[n].phys_addr; |
| 2093 | new_end = new_start + |
| 2094 | pavail_rescan[n].reg_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | |
| 2096 | if (new_start <= old_start && |
| 2097 | new_end >= (old_start + PAGE_SIZE)) { |
David S. Miller | d8ed1d4 | 2009-08-25 16:47:46 -0700 | [diff] [blame] | 2098 | set_bit(old_start >> 22, bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | goto do_next_page; |
| 2100 | } |
| 2101 | } |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2102 | |
| 2103 | prom_printf("mem_init: Lost memory in pavail\n"); |
| 2104 | prom_printf("mem_init: OLD start[%lx] size[%lx]\n", |
| 2105 | pavail[i].phys_addr, |
| 2106 | pavail[i].reg_size); |
| 2107 | prom_printf("mem_init: NEW start[%lx] size[%lx]\n", |
| 2108 | pavail_rescan[i].phys_addr, |
| 2109 | pavail_rescan[i].reg_size); |
| 2110 | prom_printf("mem_init: Cannot continue, aborting.\n"); |
| 2111 | prom_halt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
| 2113 | do_next_page: |
| 2114 | old_start += PAGE_SIZE; |
| 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | |
David S. Miller | d8ed1d4 | 2009-08-25 16:47:46 -0700 | [diff] [blame] | 2119 | static void __init patch_tlb_miss_handler_bitmap(void) |
| 2120 | { |
| 2121 | extern unsigned int valid_addr_bitmap_insn[]; |
| 2122 | extern unsigned int valid_addr_bitmap_patch[]; |
| 2123 | |
| 2124 | valid_addr_bitmap_insn[1] = valid_addr_bitmap_patch[1]; |
| 2125 | mb(); |
| 2126 | valid_addr_bitmap_insn[0] = valid_addr_bitmap_patch[0]; |
| 2127 | flushi(&valid_addr_bitmap_insn[0]); |
| 2128 | } |
| 2129 | |
Yinghai Lu | 961f8fa | 2012-11-16 19:39:21 -0800 | [diff] [blame] | 2130 | static void __init register_page_bootmem_info(void) |
| 2131 | { |
| 2132 | #ifdef CONFIG_NEED_MULTIPLE_NODES |
| 2133 | int i; |
| 2134 | |
| 2135 | for_each_online_node(i) |
| 2136 | if (NODE_DATA(i)->node_spanned_pages) |
| 2137 | register_page_bootmem_info_node(NODE_DATA(i)); |
| 2138 | #endif |
| 2139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | void __init mem_init(void) |
| 2141 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | unsigned long addr, last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | |
| 2144 | addr = PAGE_OFFSET + kern_base; |
| 2145 | last = PAGE_ALIGN(kern_size) + addr; |
| 2146 | while (addr < last) { |
| 2147 | set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap); |
| 2148 | addr += PAGE_SIZE; |
| 2149 | } |
| 2150 | |
David S. Miller | d8ed1d4 | 2009-08-25 16:47:46 -0700 | [diff] [blame] | 2151 | setup_valid_addr_bitmap_from_pavail(sparc64_valid_addr_bitmap); |
| 2152 | patch_tlb_miss_handler_bitmap(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | high_memory = __va(last_valid_pfn << PAGE_SHIFT); |
| 2155 | |
Yinghai Lu | 961f8fa | 2012-11-16 19:39:21 -0800 | [diff] [blame] | 2156 | register_page_bootmem_info(); |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 2157 | free_all_bootmem(); |
David S. Miller | 919ee67 | 2008-04-23 05:40:25 -0700 | [diff] [blame] | 2158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | /* |
| 2160 | * Set up the zero page, mark it reserved, so that page count |
| 2161 | * is not manipulated when freeing the page from user ptes. |
| 2162 | */ |
| 2163 | mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0); |
| 2164 | if (mem_map_zero == NULL) { |
| 2165 | prom_printf("paging_init: Cannot alloc zero page.\n"); |
| 2166 | prom_halt(); |
| 2167 | } |
Jiang Liu | 70affe4 | 2013-05-07 16:18:08 -0700 | [diff] [blame] | 2168 | mark_page_reserved(mem_map_zero); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
Jiang Liu | dceccbe | 2013-07-03 15:04:14 -0700 | [diff] [blame] | 2170 | mem_init_print_info(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | |
| 2172 | if (tlb_type == cheetah || tlb_type == cheetah_plus) |
| 2173 | cheetah_ecache_flush_init(); |
| 2174 | } |
| 2175 | |
David S. Miller | 898cf0e | 2005-09-23 11:59:44 -0700 | [diff] [blame] | 2176 | void free_initmem(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | { |
| 2178 | unsigned long addr, initend; |
David S. Miller | f2b6079 | 2008-08-14 01:45:41 -0700 | [diff] [blame] | 2179 | int do_free = 1; |
| 2180 | |
| 2181 | /* If the physical memory maps were trimmed by kernel command |
| 2182 | * line options, don't even try freeing this initmem stuff up. |
| 2183 | * The kernel image could have been in the trimmed out region |
| 2184 | * and if so the freeing below will free invalid page structs. |
| 2185 | */ |
| 2186 | if (cmdline_memory_size) |
| 2187 | do_free = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | |
| 2189 | /* |
| 2190 | * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes. |
| 2191 | */ |
| 2192 | addr = PAGE_ALIGN((unsigned long)(__init_begin)); |
| 2193 | initend = (unsigned long)(__init_end) & PAGE_MASK; |
| 2194 | for (; addr < initend; addr += PAGE_SIZE) { |
| 2195 | unsigned long page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | |
| 2197 | page = (addr + |
| 2198 | ((unsigned long) __va(kern_base)) - |
| 2199 | ((unsigned long) KERNBASE)); |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 2200 | memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
Jiang Liu | 70affe4 | 2013-05-07 16:18:08 -0700 | [diff] [blame] | 2202 | if (do_free) |
| 2203 | free_reserved_page(virt_to_page(page)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | #ifdef CONFIG_BLK_DEV_INITRD |
| 2208 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 2209 | { |
Jiang Liu | dceccbe | 2013-07-03 15:04:14 -0700 | [diff] [blame] | 2210 | free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM, |
| 2211 | "initrd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | } |
| 2213 | #endif |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2214 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2215 | #define _PAGE_CACHE_4U (_PAGE_CP_4U | _PAGE_CV_4U) |
| 2216 | #define _PAGE_CACHE_4V (_PAGE_CP_4V | _PAGE_CV_4V) |
| 2217 | #define __DIRTY_BITS_4U (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U) |
| 2218 | #define __DIRTY_BITS_4V (_PAGE_MODIFIED_4V | _PAGE_WRITE_4V | _PAGE_W_4V) |
| 2219 | #define __ACCESS_BITS_4U (_PAGE_ACCESSED_4U | _PAGE_READ_4U | _PAGE_R) |
| 2220 | #define __ACCESS_BITS_4V (_PAGE_ACCESSED_4V | _PAGE_READ_4V | _PAGE_R) |
| 2221 | |
| 2222 | pgprot_t PAGE_KERNEL __read_mostly; |
| 2223 | EXPORT_SYMBOL(PAGE_KERNEL); |
| 2224 | |
| 2225 | pgprot_t PAGE_KERNEL_LOCKED __read_mostly; |
| 2226 | pgprot_t PAGE_COPY __read_mostly; |
David S. Miller | 0f15952 | 2006-02-18 12:43:16 -0800 | [diff] [blame] | 2227 | |
| 2228 | pgprot_t PAGE_SHARED __read_mostly; |
| 2229 | EXPORT_SYMBOL(PAGE_SHARED); |
| 2230 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2231 | unsigned long pg_iobits __read_mostly; |
| 2232 | |
| 2233 | unsigned long _PAGE_IE __read_mostly; |
David S. Miller | 987c74f | 2006-06-25 01:34:43 -0700 | [diff] [blame] | 2234 | EXPORT_SYMBOL(_PAGE_IE); |
David S. Miller | b2bef44 | 2006-02-23 01:55:55 -0800 | [diff] [blame] | 2235 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2236 | unsigned long _PAGE_E __read_mostly; |
David S. Miller | b2bef44 | 2006-02-23 01:55:55 -0800 | [diff] [blame] | 2237 | EXPORT_SYMBOL(_PAGE_E); |
| 2238 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2239 | unsigned long _PAGE_CACHE __read_mostly; |
David S. Miller | b2bef44 | 2006-02-23 01:55:55 -0800 | [diff] [blame] | 2240 | EXPORT_SYMBOL(_PAGE_CACHE); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2241 | |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 2242 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 2243 | unsigned long vmemmap_table[VMEMMAP_SIZE]; |
| 2244 | |
David S. Miller | 2856cc2 | 2012-08-15 00:37:29 -0700 | [diff] [blame] | 2245 | static long __meminitdata addr_start, addr_end; |
| 2246 | static int __meminitdata node_start; |
| 2247 | |
Johannes Weiner | 0aad818 | 2013-04-29 15:07:50 -0700 | [diff] [blame] | 2248 | int __meminit vmemmap_populate(unsigned long vstart, unsigned long vend, |
| 2249 | int node) |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 2250 | { |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 2251 | unsigned long phys_start = (vstart - VMEMMAP_BASE); |
| 2252 | unsigned long phys_end = (vend - VMEMMAP_BASE); |
| 2253 | unsigned long addr = phys_start & VMEMMAP_CHUNK_MASK; |
| 2254 | unsigned long end = VMEMMAP_ALIGN(phys_end); |
| 2255 | unsigned long pte_base; |
| 2256 | |
| 2257 | pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4U | |
| 2258 | _PAGE_CP_4U | _PAGE_CV_4U | |
| 2259 | _PAGE_P_4U | _PAGE_W_4U); |
| 2260 | if (tlb_type == hypervisor) |
| 2261 | pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4V | |
| 2262 | _PAGE_CP_4V | _PAGE_CV_4V | |
| 2263 | _PAGE_P_4V | _PAGE_W_4V); |
| 2264 | |
| 2265 | for (; addr < end; addr += VMEMMAP_CHUNK) { |
| 2266 | unsigned long *vmem_pp = |
| 2267 | vmemmap_table + (addr >> VMEMMAP_CHUNK_SHIFT); |
| 2268 | void *block; |
| 2269 | |
| 2270 | if (!(*vmem_pp & _PAGE_VALID)) { |
| 2271 | block = vmemmap_alloc_block(1UL << 22, node); |
| 2272 | if (!block) |
| 2273 | return -ENOMEM; |
| 2274 | |
| 2275 | *vmem_pp = pte_base | __pa(block); |
| 2276 | |
David S. Miller | 2856cc2 | 2012-08-15 00:37:29 -0700 | [diff] [blame] | 2277 | /* check to see if we have contiguous blocks */ |
| 2278 | if (addr_end != addr || node_start != node) { |
| 2279 | if (addr_start) |
| 2280 | printk(KERN_DEBUG " [%lx-%lx] on node %d\n", |
| 2281 | addr_start, addr_end-1, node_start); |
| 2282 | addr_start = addr; |
| 2283 | node_start = node; |
| 2284 | } |
| 2285 | addr_end = addr + VMEMMAP_CHUNK; |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 2286 | } |
| 2287 | } |
| 2288 | return 0; |
| 2289 | } |
David S. Miller | 2856cc2 | 2012-08-15 00:37:29 -0700 | [diff] [blame] | 2290 | |
| 2291 | void __meminit vmemmap_populate_print_last(void) |
| 2292 | { |
| 2293 | if (addr_start) { |
| 2294 | printk(KERN_DEBUG " [%lx-%lx] on node %d\n", |
| 2295 | addr_start, addr_end-1, node_start); |
| 2296 | addr_start = 0; |
| 2297 | addr_end = 0; |
| 2298 | node_start = 0; |
| 2299 | } |
| 2300 | } |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 2301 | |
Johannes Weiner | 0aad818 | 2013-04-29 15:07:50 -0700 | [diff] [blame] | 2302 | void vmemmap_free(unsigned long start, unsigned long end) |
Tang Chen | 0197518 | 2013-02-22 16:33:08 -0800 | [diff] [blame] | 2303 | { |
| 2304 | } |
| 2305 | |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 2306 | #endif /* CONFIG_SPARSEMEM_VMEMMAP */ |
| 2307 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2308 | static void prot_init_common(unsigned long page_none, |
| 2309 | unsigned long page_shared, |
| 2310 | unsigned long page_copy, |
| 2311 | unsigned long page_readonly, |
| 2312 | unsigned long page_exec_bit) |
| 2313 | { |
| 2314 | PAGE_COPY = __pgprot(page_copy); |
David S. Miller | 0f15952 | 2006-02-18 12:43:16 -0800 | [diff] [blame] | 2315 | PAGE_SHARED = __pgprot(page_shared); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2316 | |
| 2317 | protection_map[0x0] = __pgprot(page_none); |
| 2318 | protection_map[0x1] = __pgprot(page_readonly & ~page_exec_bit); |
| 2319 | protection_map[0x2] = __pgprot(page_copy & ~page_exec_bit); |
| 2320 | protection_map[0x3] = __pgprot(page_copy & ~page_exec_bit); |
| 2321 | protection_map[0x4] = __pgprot(page_readonly); |
| 2322 | protection_map[0x5] = __pgprot(page_readonly); |
| 2323 | protection_map[0x6] = __pgprot(page_copy); |
| 2324 | protection_map[0x7] = __pgprot(page_copy); |
| 2325 | protection_map[0x8] = __pgprot(page_none); |
| 2326 | protection_map[0x9] = __pgprot(page_readonly & ~page_exec_bit); |
| 2327 | protection_map[0xa] = __pgprot(page_shared & ~page_exec_bit); |
| 2328 | protection_map[0xb] = __pgprot(page_shared & ~page_exec_bit); |
| 2329 | protection_map[0xc] = __pgprot(page_readonly); |
| 2330 | protection_map[0xd] = __pgprot(page_readonly); |
| 2331 | protection_map[0xe] = __pgprot(page_shared); |
| 2332 | protection_map[0xf] = __pgprot(page_shared); |
| 2333 | } |
| 2334 | |
| 2335 | static void __init sun4u_pgprot_init(void) |
| 2336 | { |
| 2337 | unsigned long page_none, page_shared, page_copy, page_readonly; |
| 2338 | unsigned long page_exec_bit; |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 2339 | int i; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2340 | |
| 2341 | PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID | |
| 2342 | _PAGE_CACHE_4U | _PAGE_P_4U | |
| 2343 | __ACCESS_BITS_4U | __DIRTY_BITS_4U | |
| 2344 | _PAGE_EXEC_4U); |
| 2345 | PAGE_KERNEL_LOCKED = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID | |
| 2346 | _PAGE_CACHE_4U | _PAGE_P_4U | |
| 2347 | __ACCESS_BITS_4U | __DIRTY_BITS_4U | |
| 2348 | _PAGE_EXEC_4U | _PAGE_L_4U); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2349 | |
| 2350 | _PAGE_IE = _PAGE_IE_4U; |
| 2351 | _PAGE_E = _PAGE_E_4U; |
| 2352 | _PAGE_CACHE = _PAGE_CACHE_4U; |
| 2353 | |
| 2354 | pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4U | __DIRTY_BITS_4U | |
| 2355 | __ACCESS_BITS_4U | _PAGE_E_4U); |
| 2356 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 2357 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 2358 | kern_linear_pte_xor[0] = _PAGE_VALID ^ PAGE_OFFSET; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 2359 | #else |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 2360 | kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4U) ^ |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 2361 | PAGE_OFFSET; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 2362 | #endif |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 2363 | kern_linear_pte_xor[0] |= (_PAGE_CP_4U | _PAGE_CV_4U | |
| 2364 | _PAGE_P_4U | _PAGE_W_4U); |
| 2365 | |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 2366 | for (i = 1; i < 4; i++) |
| 2367 | kern_linear_pte_xor[i] = kern_linear_pte_xor[0]; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2368 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2369 | _PAGE_ALL_SZ_BITS = (_PAGE_SZ4MB_4U | _PAGE_SZ512K_4U | |
| 2370 | _PAGE_SZ64K_4U | _PAGE_SZ8K_4U | |
| 2371 | _PAGE_SZ32MB_4U | _PAGE_SZ256MB_4U); |
| 2372 | |
| 2373 | |
| 2374 | page_none = _PAGE_PRESENT_4U | _PAGE_ACCESSED_4U | _PAGE_CACHE_4U; |
| 2375 | page_shared = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U | |
| 2376 | __ACCESS_BITS_4U | _PAGE_WRITE_4U | _PAGE_EXEC_4U); |
| 2377 | page_copy = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U | |
| 2378 | __ACCESS_BITS_4U | _PAGE_EXEC_4U); |
| 2379 | page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U | |
| 2380 | __ACCESS_BITS_4U | _PAGE_EXEC_4U); |
| 2381 | |
| 2382 | page_exec_bit = _PAGE_EXEC_4U; |
| 2383 | |
| 2384 | prot_init_common(page_none, page_shared, page_copy, page_readonly, |
| 2385 | page_exec_bit); |
| 2386 | } |
| 2387 | |
| 2388 | static void __init sun4v_pgprot_init(void) |
| 2389 | { |
| 2390 | unsigned long page_none, page_shared, page_copy, page_readonly; |
| 2391 | unsigned long page_exec_bit; |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 2392 | int i; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2393 | |
| 2394 | PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4V | _PAGE_VALID | |
| 2395 | _PAGE_CACHE_4V | _PAGE_P_4V | |
| 2396 | __ACCESS_BITS_4V | __DIRTY_BITS_4V | |
| 2397 | _PAGE_EXEC_4V); |
| 2398 | PAGE_KERNEL_LOCKED = PAGE_KERNEL; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2399 | |
| 2400 | _PAGE_IE = _PAGE_IE_4V; |
| 2401 | _PAGE_E = _PAGE_E_4V; |
| 2402 | _PAGE_CACHE = _PAGE_CACHE_4V; |
| 2403 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 2404 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 2405 | kern_linear_pte_xor[0] = _PAGE_VALID ^ PAGE_OFFSET; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 2406 | #else |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 2407 | kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4V) ^ |
David S. Miller | 922631b | 2013-09-18 12:00:00 -0700 | [diff] [blame] | 2408 | PAGE_OFFSET; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 2409 | #endif |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 2410 | kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_CV_4V | |
| 2411 | _PAGE_P_4V | _PAGE_W_4V); |
| 2412 | |
David S. Miller | c69ad0a | 2012-09-06 20:35:36 -0700 | [diff] [blame] | 2413 | for (i = 1; i < 4; i++) |
| 2414 | kern_linear_pte_xor[i] = kern_linear_pte_xor[0]; |
David S. Miller | 4f93d21 | 2012-09-06 18:13:58 -0700 | [diff] [blame] | 2415 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2416 | pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4V | __DIRTY_BITS_4V | |
| 2417 | __ACCESS_BITS_4V | _PAGE_E_4V); |
| 2418 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2419 | _PAGE_ALL_SZ_BITS = (_PAGE_SZ16GB_4V | _PAGE_SZ2GB_4V | |
| 2420 | _PAGE_SZ256MB_4V | _PAGE_SZ32MB_4V | |
| 2421 | _PAGE_SZ4MB_4V | _PAGE_SZ512K_4V | |
| 2422 | _PAGE_SZ64K_4V | _PAGE_SZ8K_4V); |
| 2423 | |
| 2424 | page_none = _PAGE_PRESENT_4V | _PAGE_ACCESSED_4V | _PAGE_CACHE_4V; |
| 2425 | page_shared = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V | |
| 2426 | __ACCESS_BITS_4V | _PAGE_WRITE_4V | _PAGE_EXEC_4V); |
| 2427 | page_copy = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V | |
| 2428 | __ACCESS_BITS_4V | _PAGE_EXEC_4V); |
| 2429 | page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V | |
| 2430 | __ACCESS_BITS_4V | _PAGE_EXEC_4V); |
| 2431 | |
| 2432 | page_exec_bit = _PAGE_EXEC_4V; |
| 2433 | |
| 2434 | prot_init_common(page_none, page_shared, page_copy, page_readonly, |
| 2435 | page_exec_bit); |
| 2436 | } |
| 2437 | |
| 2438 | unsigned long pte_sz_bits(unsigned long sz) |
| 2439 | { |
| 2440 | if (tlb_type == hypervisor) { |
| 2441 | switch (sz) { |
| 2442 | case 8 * 1024: |
| 2443 | default: |
| 2444 | return _PAGE_SZ8K_4V; |
| 2445 | case 64 * 1024: |
| 2446 | return _PAGE_SZ64K_4V; |
| 2447 | case 512 * 1024: |
| 2448 | return _PAGE_SZ512K_4V; |
| 2449 | case 4 * 1024 * 1024: |
| 2450 | return _PAGE_SZ4MB_4V; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame] | 2451 | } |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2452 | } else { |
| 2453 | switch (sz) { |
| 2454 | case 8 * 1024: |
| 2455 | default: |
| 2456 | return _PAGE_SZ8K_4U; |
| 2457 | case 64 * 1024: |
| 2458 | return _PAGE_SZ64K_4U; |
| 2459 | case 512 * 1024: |
| 2460 | return _PAGE_SZ512K_4U; |
| 2461 | case 4 * 1024 * 1024: |
| 2462 | return _PAGE_SZ4MB_4U; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame] | 2463 | } |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | pte_t mk_pte_io(unsigned long page, pgprot_t prot, int space, unsigned long page_size) |
| 2468 | { |
| 2469 | pte_t pte; |
David S. Miller | cf62715 | 2006-02-12 21:10:07 -0800 | [diff] [blame] | 2470 | |
| 2471 | pte_val(pte) = page | pgprot_val(pgprot_noncached(prot)); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2472 | pte_val(pte) |= (((unsigned long)space) << 32); |
| 2473 | pte_val(pte) |= pte_sz_bits(page_size); |
David S. Miller | cf62715 | 2006-02-12 21:10:07 -0800 | [diff] [blame] | 2474 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2475 | return pte; |
| 2476 | } |
| 2477 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2478 | static unsigned long kern_large_tte(unsigned long paddr) |
| 2479 | { |
| 2480 | unsigned long val; |
| 2481 | |
| 2482 | val = (_PAGE_VALID | _PAGE_SZ4MB_4U | |
| 2483 | _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_P_4U | |
| 2484 | _PAGE_EXEC_4U | _PAGE_L_4U | _PAGE_W_4U); |
| 2485 | if (tlb_type == hypervisor) |
| 2486 | val = (_PAGE_VALID | _PAGE_SZ4MB_4V | |
| 2487 | _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_P_4V | |
| 2488 | _PAGE_EXEC_4V | _PAGE_W_4V); |
| 2489 | |
| 2490 | return val | paddr; |
| 2491 | } |
| 2492 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2493 | /* If not locked, zap it. */ |
| 2494 | void __flush_tlb_all(void) |
| 2495 | { |
| 2496 | unsigned long pstate; |
| 2497 | int i; |
| 2498 | |
| 2499 | __asm__ __volatile__("flushw\n\t" |
| 2500 | "rdpr %%pstate, %0\n\t" |
| 2501 | "wrpr %0, %1, %%pstate" |
| 2502 | : "=r" (pstate) |
| 2503 | : "i" (PSTATE_IE)); |
David S. Miller | 8f361453 | 2007-12-13 06:13:38 -0800 | [diff] [blame] | 2504 | if (tlb_type == hypervisor) { |
| 2505 | sun4v_mmu_demap_all(); |
| 2506 | } else if (tlb_type == spitfire) { |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 2507 | for (i = 0; i < 64; i++) { |
| 2508 | /* Spitfire Errata #32 workaround */ |
| 2509 | /* NOTE: Always runs on spitfire, so no |
| 2510 | * cheetah+ page size encodings. |
| 2511 | */ |
| 2512 | __asm__ __volatile__("stxa %0, [%1] %2\n\t" |
| 2513 | "flush %%g6" |
| 2514 | : /* No outputs */ |
| 2515 | : "r" (0), |
| 2516 | "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU)); |
| 2517 | |
| 2518 | if (!(spitfire_get_dtlb_data(i) & _PAGE_L_4U)) { |
| 2519 | __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" |
| 2520 | "membar #Sync" |
| 2521 | : /* no outputs */ |
| 2522 | : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU)); |
| 2523 | spitfire_put_dtlb_data(i, 0x0UL); |
| 2524 | } |
| 2525 | |
| 2526 | /* Spitfire Errata #32 workaround */ |
| 2527 | /* NOTE: Always runs on spitfire, so no |
| 2528 | * cheetah+ page size encodings. |
| 2529 | */ |
| 2530 | __asm__ __volatile__("stxa %0, [%1] %2\n\t" |
| 2531 | "flush %%g6" |
| 2532 | : /* No outputs */ |
| 2533 | : "r" (0), |
| 2534 | "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU)); |
| 2535 | |
| 2536 | if (!(spitfire_get_itlb_data(i) & _PAGE_L_4U)) { |
| 2537 | __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" |
| 2538 | "membar #Sync" |
| 2539 | : /* no outputs */ |
| 2540 | : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU)); |
| 2541 | spitfire_put_itlb_data(i, 0x0UL); |
| 2542 | } |
| 2543 | } |
| 2544 | } else if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 2545 | cheetah_flush_dtlb_all(); |
| 2546 | cheetah_flush_itlb_all(); |
| 2547 | } |
| 2548 | __asm__ __volatile__("wrpr %0, 0, %%pstate" |
| 2549 | : : "r" (pstate)); |
| 2550 | } |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2551 | |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2552 | pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 2553 | unsigned long address) |
| 2554 | { |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 2555 | struct page *page = alloc_page(GFP_KERNEL | __GFP_NOTRACK | |
| 2556 | __GFP_REPEAT | __GFP_ZERO); |
| 2557 | pte_t *pte = NULL; |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2558 | |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2559 | if (page) |
| 2560 | pte = (pte_t *) page_address(page); |
| 2561 | |
| 2562 | return pte; |
| 2563 | } |
| 2564 | |
| 2565 | pgtable_t pte_alloc_one(struct mm_struct *mm, |
| 2566 | unsigned long address) |
| 2567 | { |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 2568 | struct page *page = alloc_page(GFP_KERNEL | __GFP_NOTRACK | |
| 2569 | __GFP_REPEAT | __GFP_ZERO); |
Kirill A. Shutemov | 1ae9ae5 | 2013-11-14 14:31:42 -0800 | [diff] [blame] | 2570 | if (!page) |
| 2571 | return NULL; |
| 2572 | if (!pgtable_page_ctor(page)) { |
| 2573 | free_hot_cold_page(page, 0); |
| 2574 | return NULL; |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2575 | } |
Kirill A. Shutemov | 1ae9ae5 | 2013-11-14 14:31:42 -0800 | [diff] [blame] | 2576 | return (pte_t *) page_address(page); |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | void pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
| 2580 | { |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 2581 | free_page((unsigned long)pte); |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | static void __pte_free(pgtable_t pte) |
| 2585 | { |
| 2586 | struct page *page = virt_to_page(pte); |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 2587 | |
| 2588 | pgtable_page_dtor(page); |
| 2589 | __free_page(page); |
David Miller | c460bec | 2012-10-08 16:34:22 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | void pte_free(struct mm_struct *mm, pgtable_t pte) |
| 2593 | { |
| 2594 | __pte_free(pte); |
| 2595 | } |
| 2596 | |
| 2597 | void pgtable_free(void *table, bool is_page) |
| 2598 | { |
| 2599 | if (is_page) |
| 2600 | __pte_free(table); |
| 2601 | else |
| 2602 | kmem_cache_free(pgtable_cache, table); |
| 2603 | } |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2604 | |
| 2605 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2606 | void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, |
| 2607 | pmd_t *pmd) |
| 2608 | { |
| 2609 | unsigned long pte, flags; |
| 2610 | struct mm_struct *mm; |
| 2611 | pmd_t entry = *pmd; |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2612 | |
| 2613 | if (!pmd_large(entry) || !pmd_young(entry)) |
| 2614 | return; |
| 2615 | |
David S. Miller | a7b9403 | 2013-09-26 13:45:15 -0700 | [diff] [blame] | 2616 | pte = pmd_val(entry); |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2617 | |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 2618 | /* We are fabricating 8MB pages using 4MB real hw pages. */ |
| 2619 | pte |= (addr & (1UL << REAL_HPAGE_SHIFT)); |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2620 | |
| 2621 | mm = vma->vm_mm; |
| 2622 | |
| 2623 | spin_lock_irqsave(&mm->context.lock, flags); |
| 2624 | |
| 2625 | if (mm->context.tsb_block[MM_TSB_HUGE].tsb != NULL) |
David S. Miller | 37b3a8f | 2013-09-25 13:48:49 -0700 | [diff] [blame] | 2626 | __update_mmu_tsb_insert(mm, MM_TSB_HUGE, REAL_HPAGE_SHIFT, |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2627 | addr, pte); |
| 2628 | |
| 2629 | spin_unlock_irqrestore(&mm->context.lock, flags); |
| 2630 | } |
| 2631 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 2632 | |
| 2633 | #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE) |
| 2634 | static void context_reload(void *__data) |
| 2635 | { |
| 2636 | struct mm_struct *mm = __data; |
| 2637 | |
| 2638 | if (mm == current->mm) |
| 2639 | load_secondary_context(mm); |
| 2640 | } |
| 2641 | |
David S. Miller | 0fbebed | 2013-02-19 22:34:10 -0800 | [diff] [blame] | 2642 | void hugetlb_setup(struct pt_regs *regs) |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2643 | { |
David S. Miller | 0fbebed | 2013-02-19 22:34:10 -0800 | [diff] [blame] | 2644 | struct mm_struct *mm = current->mm; |
| 2645 | struct tsb_config *tp; |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2646 | |
David S. Miller | 0fbebed | 2013-02-19 22:34:10 -0800 | [diff] [blame] | 2647 | if (in_atomic() || !mm) { |
| 2648 | const struct exception_table_entry *entry; |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2649 | |
David S. Miller | 0fbebed | 2013-02-19 22:34:10 -0800 | [diff] [blame] | 2650 | entry = search_exception_tables(regs->tpc); |
| 2651 | if (entry) { |
| 2652 | regs->tpc = entry->fixup; |
| 2653 | regs->tnpc = regs->tpc + 4; |
| 2654 | return; |
| 2655 | } |
| 2656 | pr_alert("Unexpected HugeTLB setup in atomic context.\n"); |
| 2657 | die_if_kernel("HugeTSB in atomic", regs); |
| 2658 | } |
| 2659 | |
| 2660 | tp = &mm->context.tsb_block[MM_TSB_HUGE]; |
| 2661 | if (likely(tp->tsb == NULL)) |
| 2662 | tsb_grow(mm, MM_TSB_HUGE, 0); |
| 2663 | |
David Miller | 9e695d2 | 2012-10-08 16:34:29 -0700 | [diff] [blame] | 2664 | tsb_context_switch(mm); |
| 2665 | smp_tsb_sync(mm); |
| 2666 | |
| 2667 | /* On UltraSPARC-III+ and later, configure the second half of |
| 2668 | * the Data-TLB for huge pages. |
| 2669 | */ |
| 2670 | if (tlb_type == cheetah_plus) { |
| 2671 | unsigned long ctx; |
| 2672 | |
| 2673 | spin_lock(&ctx_alloc_lock); |
| 2674 | ctx = mm->context.sparc64_ctx_val; |
| 2675 | ctx &= ~CTX_PGSZ_MASK; |
| 2676 | ctx |= CTX_PGSZ_BASE << CTX_PGSZ0_SHIFT; |
| 2677 | ctx |= CTX_PGSZ_HUGE << CTX_PGSZ1_SHIFT; |
| 2678 | |
| 2679 | if (ctx != mm->context.sparc64_ctx_val) { |
| 2680 | /* When changing the page size fields, we |
| 2681 | * must perform a context flush so that no |
| 2682 | * stale entries match. This flush must |
| 2683 | * occur with the original context register |
| 2684 | * settings. |
| 2685 | */ |
| 2686 | do_flush_tlb_mm(mm); |
| 2687 | |
| 2688 | /* Reload the context register of all processors |
| 2689 | * also executing in this address space. |
| 2690 | */ |
| 2691 | mm->context.sparc64_ctx_val = ctx; |
| 2692 | on_each_cpu(context_reload, mm, 0); |
| 2693 | } |
| 2694 | spin_unlock(&ctx_alloc_lock); |
| 2695 | } |
| 2696 | } |
| 2697 | #endif |