Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: init.c,v 1.209 2002/02/09 19:49:31 davem Exp $ |
| 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> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/initrd.h> |
| 18 | #include <linux/swap.h> |
| 19 | #include <linux/pagemap.h> |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 20 | #include <linux/poison.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/fs.h> |
| 22 | #include <linux/seq_file.h> |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 23 | #include <linux/kprobes.h> |
David S. Miller | 1ac4f5e | 2005-09-21 21:49:32 -0700 | [diff] [blame] | 24 | #include <linux/cache.h> |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 25 | #include <linux/sort.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/head.h> |
| 28 | #include <asm/system.h> |
| 29 | #include <asm/page.h> |
| 30 | #include <asm/pgalloc.h> |
| 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/oplib.h> |
| 33 | #include <asm/iommu.h> |
| 34 | #include <asm/io.h> |
| 35 | #include <asm/uaccess.h> |
| 36 | #include <asm/mmu_context.h> |
| 37 | #include <asm/tlbflush.h> |
| 38 | #include <asm/dma.h> |
| 39 | #include <asm/starfire.h> |
| 40 | #include <asm/tlb.h> |
| 41 | #include <asm/spitfire.h> |
| 42 | #include <asm/sections.h> |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 43 | #include <asm/tsb.h> |
David S. Miller | 481295f | 2006-02-07 21:51:08 -0800 | [diff] [blame] | 44 | #include <asm/hypervisor.h> |
David S. Miller | 372b07b | 2006-06-21 15:35:28 -0700 | [diff] [blame] | 45 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | extern void device_scan(void); |
| 48 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 49 | #define MAX_PHYS_ADDRESS (1UL << 42UL) |
| 50 | #define KPTE_BITMAP_CHUNK_SZ (256UL * 1024UL * 1024UL) |
| 51 | #define KPTE_BITMAP_BYTES \ |
| 52 | ((MAX_PHYS_ADDRESS / KPTE_BITMAP_CHUNK_SZ) / 8) |
| 53 | |
| 54 | unsigned long kern_linear_pte_xor[2] __read_mostly; |
| 55 | |
| 56 | /* A bitmap, one bit for every 256MB of physical memory. If the bit |
| 57 | * is clear, we should use a 4MB page (via kern_linear_pte_xor[0]) else |
| 58 | * if set we should use a 256MB page (via kern_linear_pte_xor[1]). |
| 59 | */ |
| 60 | unsigned long kpte_linear_bitmap[KPTE_BITMAP_BYTES / sizeof(unsigned long)]; |
| 61 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 62 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 63 | /* A special kernel TSB for 4MB and 256MB linear mappings. */ |
| 64 | struct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES]; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 65 | #endif |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 66 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 67 | #define MAX_BANKS 32 |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 68 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 69 | static struct linux_prom64_registers pavail[MAX_BANKS] __initdata; |
| 70 | static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata; |
| 71 | static int pavail_ents __initdata; |
| 72 | static int pavail_rescan_ents __initdata; |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 73 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 74 | static int cmp_p64(const void *a, const void *b) |
| 75 | { |
| 76 | const struct linux_prom64_registers *x = a, *y = b; |
| 77 | |
| 78 | if (x->phys_addr > y->phys_addr) |
| 79 | return 1; |
| 80 | if (x->phys_addr < y->phys_addr) |
| 81 | return -1; |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static void __init read_obp_memory(const char *property, |
| 86 | struct linux_prom64_registers *regs, |
| 87 | int *num_ents) |
| 88 | { |
| 89 | int node = prom_finddevice("/memory"); |
| 90 | int prop_size = prom_getproplen(node, property); |
| 91 | int ents, ret, i; |
| 92 | |
| 93 | ents = prop_size / sizeof(struct linux_prom64_registers); |
| 94 | if (ents > MAX_BANKS) { |
| 95 | prom_printf("The machine has more %s property entries than " |
| 96 | "this kernel can support (%d).\n", |
| 97 | property, MAX_BANKS); |
| 98 | prom_halt(); |
| 99 | } |
| 100 | |
| 101 | ret = prom_getproperty(node, property, (char *) regs, prop_size); |
| 102 | if (ret == -1) { |
| 103 | prom_printf("Couldn't get %s property from /memory.\n"); |
| 104 | prom_halt(); |
| 105 | } |
| 106 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 107 | /* Sanitize what we got from the firmware, by page aligning |
| 108 | * everything. |
| 109 | */ |
| 110 | for (i = 0; i < ents; i++) { |
| 111 | unsigned long base, size; |
| 112 | |
| 113 | base = regs[i].phys_addr; |
| 114 | size = regs[i].reg_size; |
| 115 | |
| 116 | size &= PAGE_MASK; |
| 117 | if (base & ~PAGE_MASK) { |
| 118 | unsigned long new_base = PAGE_ALIGN(base); |
| 119 | |
| 120 | size -= new_base - base; |
| 121 | if ((long) size < 0L) |
| 122 | size = 0UL; |
| 123 | base = new_base; |
| 124 | } |
David S. Miller | 0015d3d | 2007-03-15 00:06:34 -0700 | [diff] [blame] | 125 | if (size == 0UL) { |
| 126 | /* If it is empty, simply get rid of it. |
| 127 | * This simplifies the logic of the other |
| 128 | * functions that process these arrays. |
| 129 | */ |
| 130 | memmove(®s[i], ®s[i + 1], |
| 131 | (ents - i - 1) * sizeof(regs[0])); |
| 132 | i--; |
| 133 | ents--; |
| 134 | continue; |
| 135 | } |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 136 | regs[i].phys_addr = base; |
| 137 | regs[i].reg_size = size; |
| 138 | } |
David S. Miller | 486ad10 | 2006-06-22 00:00:00 -0700 | [diff] [blame] | 139 | |
David S. Miller | 486ad10 | 2006-06-22 00:00:00 -0700 | [diff] [blame] | 140 | *num_ents = ents; |
| 141 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 142 | sort(regs, ents, sizeof(struct linux_prom64_registers), |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 143 | cmp_p64, NULL); |
| 144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 146 | unsigned long *sparc64_valid_addr_bitmap __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 148 | /* Kernel physical address base and size in bytes. */ |
David S. Miller | 1ac4f5e | 2005-09-21 21:49:32 -0700 | [diff] [blame] | 149 | unsigned long kern_base __read_mostly; |
| 150 | unsigned long kern_size __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Initial ramdisk setup */ |
| 153 | extern unsigned long sparc_ramdisk_image64; |
| 154 | extern unsigned int sparc_ramdisk_image; |
| 155 | extern unsigned int sparc_ramdisk_size; |
| 156 | |
David S. Miller | 1ac4f5e | 2005-09-21 21:49:32 -0700 | [diff] [blame] | 157 | struct page *mem_map_zero __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
David S. Miller | 0835ae0 | 2005-10-04 15:23:20 -0700 | [diff] [blame] | 159 | unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly; |
| 160 | |
| 161 | unsigned long sparc64_kern_pri_context __read_mostly; |
| 162 | unsigned long sparc64_kern_pri_nuc_bits __read_mostly; |
| 163 | unsigned long sparc64_kern_sec_context __read_mostly; |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | int bigkernel = 0; |
| 166 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 167 | struct kmem_cache *pgtable_cache __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 169 | static void zero_ctor(void *addr, struct kmem_cache *cache, unsigned long flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
David S. Miller | 3c93646 | 2006-01-31 18:30:27 -0800 | [diff] [blame] | 171 | clear_page(addr); |
| 172 | } |
| 173 | |
David S. Miller | 9b4006d | 2006-03-18 18:12:42 -0800 | [diff] [blame] | 174 | extern void tsb_cache_init(void); |
| 175 | |
David S. Miller | 3c93646 | 2006-01-31 18:30:27 -0800 | [diff] [blame] | 176 | void pgtable_cache_init(void) |
| 177 | { |
| 178 | pgtable_cache = kmem_cache_create("pgtable_cache", |
| 179 | PAGE_SIZE, PAGE_SIZE, |
| 180 | SLAB_HWCACHE_ALIGN | |
| 181 | SLAB_MUST_HWCACHE_ALIGN, |
| 182 | zero_ctor, |
| 183 | NULL); |
| 184 | if (!pgtable_cache) { |
David S. Miller | 9b4006d | 2006-03-18 18:12:42 -0800 | [diff] [blame] | 185 | prom_printf("Could not create pgtable_cache\n"); |
David S. Miller | 3c93646 | 2006-01-31 18:30:27 -0800 | [diff] [blame] | 186 | prom_halt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
David S. Miller | 9b4006d | 2006-03-18 18:12:42 -0800 | [diff] [blame] | 188 | tsb_cache_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 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 | 17b0e19 | 2006-03-08 15:57:03 -0800 | [diff] [blame] | 217 | #define PG_dcache_cpu_shift 24UL |
| 218 | #define PG_dcache_cpu_mask (256UL - 1UL) |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 219 | |
| 220 | #if NR_CPUS > 256 |
| 221 | #error D-cache dirty tracking and thread_info->cpu need fixing for > 256 cpus |
| 222 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | #define dcache_dirty_cpu(page) \ |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 225 | (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | static __inline__ void set_dcache_dirty(struct page *page, int this_cpu) |
| 228 | { |
| 229 | unsigned long mask = this_cpu; |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 230 | unsigned long non_cpu_bits; |
| 231 | |
| 232 | non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift); |
| 233 | mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty); |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | __asm__ __volatile__("1:\n\t" |
| 236 | "ldx [%2], %%g7\n\t" |
| 237 | "and %%g7, %1, %%g1\n\t" |
| 238 | "or %%g1, %0, %%g1\n\t" |
| 239 | "casx [%2], %%g7, %%g1\n\t" |
| 240 | "cmp %%g7, %%g1\n\t" |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 241 | "membar #StoreLoad | #StoreStore\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | "bne,pn %%xcc, 1b\n\t" |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 243 | " nop" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | : /* no outputs */ |
| 245 | : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags) |
| 246 | : "g1", "g7"); |
| 247 | } |
| 248 | |
| 249 | static __inline__ void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu) |
| 250 | { |
| 251 | unsigned long mask = (1UL << PG_dcache_dirty); |
| 252 | |
| 253 | __asm__ __volatile__("! test_and_clear_dcache_dirty\n" |
| 254 | "1:\n\t" |
| 255 | "ldx [%2], %%g7\n\t" |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 256 | "srlx %%g7, %4, %%g1\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | "and %%g1, %3, %%g1\n\t" |
| 258 | "cmp %%g1, %0\n\t" |
| 259 | "bne,pn %%icc, 2f\n\t" |
| 260 | " andn %%g7, %1, %%g1\n\t" |
| 261 | "casx [%2], %%g7, %%g1\n\t" |
| 262 | "cmp %%g7, %%g1\n\t" |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 263 | "membar #StoreLoad | #StoreStore\n\t" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | "bne,pn %%xcc, 1b\n\t" |
David S. Miller | b445e26 | 2005-06-27 15:42:04 -0700 | [diff] [blame] | 265 | " nop\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | "2:" |
| 267 | : /* no outputs */ |
| 268 | : "r" (cpu), "r" (mask), "r" (&page->flags), |
David S. Miller | 48b0e54 | 2005-07-27 16:08:44 -0700 | [diff] [blame] | 269 | "i" (PG_dcache_cpu_mask), |
| 270 | "i" (PG_dcache_cpu_shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | : "g1", "g7"); |
| 272 | } |
| 273 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 274 | static inline void tsb_insert(struct tsb *ent, unsigned long tag, unsigned long pte) |
| 275 | { |
| 276 | unsigned long tsb_addr = (unsigned long) ent; |
| 277 | |
David S. Miller | 3b3ab2e | 2006-02-17 09:54:42 -0800 | [diff] [blame] | 278 | if (tlb_type == cheetah_plus || tlb_type == hypervisor) |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 279 | tsb_addr = __pa(tsb_addr); |
| 280 | |
| 281 | __tsb_insert(tsb_addr, tag, pte); |
| 282 | } |
| 283 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 284 | unsigned long _PAGE_ALL_SZ_BITS __read_mostly; |
| 285 | unsigned long _PAGE_SZBITS __read_mostly; |
| 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte) |
| 288 | { |
David S. Miller | bd40791 | 2006-01-31 18:31:38 -0800 | [diff] [blame] | 289 | struct mm_struct *mm; |
David S. Miller | 74ae998 | 2006-03-05 18:26:24 -0800 | [diff] [blame] | 290 | struct tsb *tsb; |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 291 | unsigned long tag, flags; |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 292 | unsigned long tsb_index, tsb_hash_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 294 | if (tlb_type != hypervisor) { |
| 295 | unsigned long pfn = pte_pfn(pte); |
| 296 | unsigned long pg_flags; |
| 297 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 299 | if (pfn_valid(pfn) && |
| 300 | (page = pfn_to_page(pfn), page_mapping(page)) && |
| 301 | ((pg_flags = page->flags) & (1UL << PG_dcache_dirty))) { |
| 302 | int cpu = ((pg_flags >> PG_dcache_cpu_shift) & |
| 303 | PG_dcache_cpu_mask); |
| 304 | int this_cpu = get_cpu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 306 | /* This is just to optimize away some function calls |
| 307 | * in the SMP case. |
| 308 | */ |
| 309 | if (cpu == this_cpu) |
| 310 | flush_dcache_page_impl(page); |
| 311 | else |
| 312 | smp_flush_dcache_page_impl(page, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 314 | clear_dcache_dirty_cpu(page, cpu); |
| 315 | |
| 316 | put_cpu(); |
| 317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
David S. Miller | bd40791 | 2006-01-31 18:31:38 -0800 | [diff] [blame] | 319 | |
| 320 | mm = vma->vm_mm; |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 321 | |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 322 | tsb_index = MM_TSB_BASE; |
| 323 | tsb_hash_shift = PAGE_SHIFT; |
| 324 | |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 325 | spin_lock_irqsave(&mm->context.lock, flags); |
| 326 | |
David S. Miller | dcc1e8d | 2006-03-22 00:49:59 -0800 | [diff] [blame] | 327 | #ifdef CONFIG_HUGETLB_PAGE |
| 328 | if (mm->context.tsb_block[MM_TSB_HUGE].tsb != NULL) { |
| 329 | if ((tlb_type == hypervisor && |
| 330 | (pte_val(pte) & _PAGE_SZALL_4V) == _PAGE_SZHUGE_4V) || |
| 331 | (tlb_type != hypervisor && |
| 332 | (pte_val(pte) & _PAGE_SZALL_4U) == _PAGE_SZHUGE_4U)) { |
| 333 | tsb_index = MM_TSB_HUGE; |
| 334 | tsb_hash_shift = HPAGE_SHIFT; |
| 335 | } |
| 336 | } |
| 337 | #endif |
| 338 | |
| 339 | tsb = mm->context.tsb_block[tsb_index].tsb; |
| 340 | tsb += ((address >> tsb_hash_shift) & |
| 341 | (mm->context.tsb_block[tsb_index].tsb_nentries - 1UL)); |
David S. Miller | 74ae998 | 2006-03-05 18:26:24 -0800 | [diff] [blame] | 342 | tag = (address >> 22UL); |
| 343 | tsb_insert(tsb, tag, pte_val(pte)); |
David S. Miller | 7a1ac52 | 2006-03-16 02:02:32 -0800 | [diff] [blame] | 344 | |
| 345 | spin_unlock_irqrestore(&mm->context.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void flush_dcache_page(struct page *page) |
| 349 | { |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 350 | struct address_space *mapping; |
| 351 | int this_cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
David S. Miller | 7a591cf | 2006-02-26 19:44:50 -0800 | [diff] [blame] | 353 | if (tlb_type == hypervisor) |
| 354 | return; |
| 355 | |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 356 | /* Do not bother with the expensive D-cache flush if it |
| 357 | * is merely the zero page. The 'bigcore' testcase in GDB |
| 358 | * causes this case to run millions of times. |
| 359 | */ |
| 360 | if (page == ZERO_PAGE(0)) |
| 361 | return; |
| 362 | |
| 363 | this_cpu = get_cpu(); |
| 364 | |
| 365 | mapping = page_mapping(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (mapping && !mapping_mapped(mapping)) { |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 367 | int dirty = test_bit(PG_dcache_dirty, &page->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | if (dirty) { |
David S. Miller | a9546f5 | 2005-04-17 18:03:09 -0700 | [diff] [blame] | 369 | int dirty_cpu = dcache_dirty_cpu(page); |
| 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (dirty_cpu == this_cpu) |
| 372 | goto out; |
| 373 | smp_flush_dcache_page_impl(page, dirty_cpu); |
| 374 | } |
| 375 | set_dcache_dirty(page, this_cpu); |
| 376 | } else { |
| 377 | /* We could delay the flush for the !page_mapping |
| 378 | * case too. But that case is for exec env/arg |
| 379 | * pages and those are %99 certainly going to get |
| 380 | * faulted into the tlb (and thus flushed) anyways. |
| 381 | */ |
| 382 | flush_dcache_page_impl(page); |
| 383 | } |
| 384 | |
| 385 | out: |
| 386 | put_cpu(); |
| 387 | } |
| 388 | |
Prasanna S Panchamukhi | 05e14cb | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 389 | void __kprobes flush_icache_range(unsigned long start, unsigned long end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
David S. Miller | a43fe0e | 2006-02-04 03:10:53 -0800 | [diff] [blame] | 391 | /* Cheetah and Hypervisor platform cpus have coherent I-cache. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (tlb_type == spitfire) { |
| 393 | unsigned long kaddr; |
| 394 | |
David S. Miller | a94aa25 | 2007-03-15 15:50:11 -0700 | [diff] [blame] | 395 | /* This code only runs on Spitfire cpus so this is |
| 396 | * why we can assume _PAGE_PADDR_4U. |
| 397 | */ |
| 398 | for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE) { |
| 399 | unsigned long paddr, mask = _PAGE_PADDR_4U; |
| 400 | |
| 401 | if (kaddr >= PAGE_OFFSET) |
| 402 | paddr = kaddr & mask; |
| 403 | else { |
| 404 | pgd_t *pgdp = pgd_offset_k(kaddr); |
| 405 | pud_t *pudp = pud_offset(pgdp, kaddr); |
| 406 | pmd_t *pmdp = pmd_offset(pudp, kaddr); |
| 407 | pte_t *ptep = pte_offset_kernel(pmdp, kaddr); |
| 408 | |
| 409 | paddr = pte_val(*ptep) & mask; |
| 410 | } |
| 411 | __flush_icache_page(paddr); |
| 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | void show_mem(void) |
| 417 | { |
David S. Miller | 5be4a96 | 2007-03-15 16:00:29 -0700 | [diff] [blame] | 418 | unsigned long total = 0, reserved = 0; |
| 419 | unsigned long shared = 0, cached = 0; |
| 420 | pg_data_t *pgdat; |
| 421 | |
David S. Miller | 28256ca | 2007-03-15 15:56:07 -0700 | [diff] [blame] | 422 | printk(KERN_INFO "Mem-info:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | show_free_areas(); |
David S. Miller | 28256ca | 2007-03-15 15:56:07 -0700 | [diff] [blame] | 424 | printk(KERN_INFO "Free swap: %6ldkB\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | nr_swap_pages << (PAGE_SHIFT-10)); |
David S. Miller | 5be4a96 | 2007-03-15 16:00:29 -0700 | [diff] [blame] | 426 | for_each_online_pgdat(pgdat) { |
| 427 | unsigned long i, flags; |
| 428 | |
| 429 | pgdat_resize_lock(pgdat, &flags); |
| 430 | for (i = 0; i < pgdat->node_spanned_pages; i++) { |
| 431 | struct page *page = pgdat_page_nr(pgdat, i); |
| 432 | total++; |
| 433 | if (PageReserved(page)) |
| 434 | reserved++; |
| 435 | else if (PageSwapCache(page)) |
| 436 | cached++; |
| 437 | else if (page_count(page)) |
| 438 | shared += page_count(page) - 1; |
| 439 | } |
| 440 | pgdat_resize_unlock(pgdat, &flags); |
| 441 | } |
| 442 | |
| 443 | printk(KERN_INFO "%lu pages of RAM\n", total); |
| 444 | printk(KERN_INFO "%lu reserved pages\n", reserved); |
| 445 | printk(KERN_INFO "%lu pages shared\n", shared); |
| 446 | printk(KERN_INFO "%lu pages swap cached\n", cached); |
| 447 | |
| 448 | printk(KERN_INFO "%lu pages dirty\n", |
| 449 | global_page_state(NR_FILE_DIRTY)); |
| 450 | printk(KERN_INFO "%lu pages writeback\n", |
| 451 | global_page_state(NR_WRITEBACK)); |
| 452 | printk(KERN_INFO "%lu pages mapped\n", |
| 453 | global_page_state(NR_FILE_MAPPED)); |
| 454 | printk(KERN_INFO "%lu pages slab\n", |
| 455 | global_page_state(NR_SLAB_RECLAIMABLE) + |
| 456 | global_page_state(NR_SLAB_UNRECLAIMABLE)); |
| 457 | printk(KERN_INFO "%lu pages pagetables\n", |
| 458 | global_page_state(NR_PAGETABLE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void mmu_info(struct seq_file *m) |
| 462 | { |
| 463 | if (tlb_type == cheetah) |
| 464 | seq_printf(m, "MMU Type\t: Cheetah\n"); |
| 465 | else if (tlb_type == cheetah_plus) |
| 466 | seq_printf(m, "MMU Type\t: Cheetah+\n"); |
| 467 | else if (tlb_type == spitfire) |
| 468 | seq_printf(m, "MMU Type\t: Spitfire\n"); |
David S. Miller | a43fe0e | 2006-02-04 03:10:53 -0800 | [diff] [blame] | 469 | else if (tlb_type == hypervisor) |
| 470 | seq_printf(m, "MMU Type\t: Hypervisor (sun4v)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | else |
| 472 | seq_printf(m, "MMU Type\t: ???\n"); |
| 473 | |
| 474 | #ifdef CONFIG_DEBUG_DCFLUSH |
| 475 | seq_printf(m, "DCPageFlushes\t: %d\n", |
| 476 | atomic_read(&dcpage_flushes)); |
| 477 | #ifdef CONFIG_SMP |
| 478 | seq_printf(m, "DCPageFlushesXC\t: %d\n", |
| 479 | atomic_read(&dcpage_flushes_xcall)); |
| 480 | #endif /* CONFIG_SMP */ |
| 481 | #endif /* CONFIG_DEBUG_DCFLUSH */ |
| 482 | } |
| 483 | |
David S. Miller | a94aa25 | 2007-03-15 15:50:11 -0700 | [diff] [blame] | 484 | struct linux_prom_translation { |
| 485 | unsigned long virt; |
| 486 | unsigned long size; |
| 487 | unsigned long data; |
| 488 | }; |
| 489 | |
| 490 | /* Exported for kernel TLB miss handling in ktlb.S */ |
| 491 | struct linux_prom_translation prom_trans[512] __read_mostly; |
| 492 | unsigned int prom_trans_ents __read_mostly; |
| 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | /* Exported for SMP bootup purposes. */ |
| 495 | unsigned long kern_locked_tte_data; |
| 496 | |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 497 | /* The obp translations are saved based on 8k pagesize, since obp can |
| 498 | * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS -> |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 499 | * HI_OBP_ADDRESS range are handled in ktlb.S. |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 500 | */ |
David S. Miller | 5085b4a | 2005-09-22 00:45:41 -0700 | [diff] [blame] | 501 | static inline int in_obp_range(unsigned long vaddr) |
| 502 | { |
| 503 | return (vaddr >= LOW_OBP_ADDRESS && |
| 504 | vaddr < HI_OBP_ADDRESS); |
| 505 | } |
| 506 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 507 | static int cmp_ptrans(const void *a, const void *b) |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 508 | { |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 509 | const struct linux_prom_translation *x = a, *y = b; |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 510 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 511 | if (x->virt > y->virt) |
| 512 | return 1; |
| 513 | if (x->virt < y->virt) |
| 514 | return -1; |
| 515 | return 0; |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 516 | } |
| 517 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 518 | /* Read OBP translations property into 'prom_trans[]'. */ |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 519 | static void __init read_obp_translations(void) |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 520 | { |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 521 | int n, node, ents, first, last, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | node = prom_finddevice("/virtual-memory"); |
| 524 | n = prom_getproplen(node, "translations"); |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 525 | if (unlikely(n == 0 || n == -1)) { |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 526 | prom_printf("prom_mappings: Couldn't get size.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | prom_halt(); |
| 528 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 529 | if (unlikely(n > sizeof(prom_trans))) { |
| 530 | prom_printf("prom_mappings: Size %Zd is too big.\n", n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | prom_halt(); |
| 532 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 533 | |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 534 | if ((n = prom_getproperty(node, "translations", |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 535 | (char *)&prom_trans[0], |
| 536 | sizeof(prom_trans))) == -1) { |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 537 | prom_printf("prom_mappings: Couldn't get property.\n"); |
| 538 | prom_halt(); |
| 539 | } |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 540 | |
David S. Miller | b206fc4 | 2005-09-21 22:31:13 -0700 | [diff] [blame] | 541 | n = n / sizeof(struct linux_prom_translation); |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 542 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 543 | ents = n; |
| 544 | |
| 545 | sort(prom_trans, ents, sizeof(struct linux_prom_translation), |
| 546 | cmp_ptrans, NULL); |
| 547 | |
| 548 | /* Now kick out all the non-OBP entries. */ |
| 549 | for (i = 0; i < ents; i++) { |
| 550 | if (in_obp_range(prom_trans[i].virt)) |
| 551 | break; |
| 552 | } |
| 553 | first = i; |
| 554 | for (; i < ents; i++) { |
| 555 | if (!in_obp_range(prom_trans[i].virt)) |
| 556 | break; |
| 557 | } |
| 558 | last = i; |
| 559 | |
| 560 | for (i = 0; i < (last - first); i++) { |
| 561 | struct linux_prom_translation *src = &prom_trans[i + first]; |
| 562 | struct linux_prom_translation *dest = &prom_trans[i]; |
| 563 | |
| 564 | *dest = *src; |
| 565 | } |
| 566 | for (; i < ents; i++) { |
| 567 | struct linux_prom_translation *dest = &prom_trans[i]; |
| 568 | dest->virt = dest->size = dest->data = 0x0UL; |
| 569 | } |
| 570 | |
| 571 | prom_trans_ents = last - first; |
| 572 | |
| 573 | if (tlb_type == spitfire) { |
| 574 | /* Clear diag TTE bits. */ |
| 575 | for (i = 0; i < prom_trans_ents; i++) |
| 576 | prom_trans[i].data &= ~0x0003fe0000000000UL; |
| 577 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 580 | static void __init hypervisor_tlb_lock(unsigned long vaddr, |
| 581 | unsigned long pte, |
| 582 | unsigned long mmu) |
| 583 | { |
David S. Miller | 164c220 | 2006-02-09 22:57:21 -0800 | [diff] [blame] | 584 | register unsigned long func asm("%o5"); |
| 585 | register unsigned long arg0 asm("%o0"); |
| 586 | register unsigned long arg1 asm("%o1"); |
| 587 | register unsigned long arg2 asm("%o2"); |
| 588 | register unsigned long arg3 asm("%o3"); |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 589 | |
| 590 | func = HV_FAST_MMU_MAP_PERM_ADDR; |
| 591 | arg0 = vaddr; |
| 592 | arg1 = 0; |
| 593 | arg2 = pte; |
| 594 | arg3 = mmu; |
| 595 | __asm__ __volatile__("ta 0x80" |
| 596 | : "=&r" (func), "=&r" (arg0), |
| 597 | "=&r" (arg1), "=&r" (arg2), |
| 598 | "=&r" (arg3) |
| 599 | : "0" (func), "1" (arg0), "2" (arg1), |
| 600 | "3" (arg2), "4" (arg3)); |
David S. Miller | 12e126a | 2006-02-17 14:40:30 -0800 | [diff] [blame] | 601 | if (arg0 != 0) { |
| 602 | prom_printf("hypervisor_tlb_lock[%lx:%lx:%lx:%lx]: " |
| 603 | "errors with %lx\n", vaddr, 0, pte, mmu, arg0); |
| 604 | prom_halt(); |
| 605 | } |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 606 | } |
| 607 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 608 | static unsigned long kern_large_tte(unsigned long paddr); |
| 609 | |
David S. Miller | 898cf0e | 2005-09-23 11:59:44 -0700 | [diff] [blame] | 610 | static void __init remap_kernel(void) |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 611 | { |
| 612 | unsigned long phys_page, tte_vaddr, tte_data; |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 613 | int tlb_ent = sparc64_highest_locked_tlbent(); |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | tte_vaddr = (unsigned long) KERNBASE; |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 616 | phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 617 | tte_data = kern_large_tte(phys_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | kern_locked_tte_data = tte_data; |
| 620 | |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 621 | /* Now lock us into the TLBs via Hypervisor or OBP. */ |
| 622 | if (tlb_type == hypervisor) { |
| 623 | hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU); |
| 624 | hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU); |
| 625 | if (bigkernel) { |
| 626 | tte_vaddr += 0x400000; |
| 627 | tte_data += 0x400000; |
| 628 | hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU); |
| 629 | hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU); |
| 630 | } |
| 631 | } else { |
| 632 | prom_dtlb_load(tlb_ent, tte_data, tte_vaddr); |
| 633 | prom_itlb_load(tlb_ent, tte_data, tte_vaddr); |
| 634 | if (bigkernel) { |
| 635 | tlb_ent -= 1; |
| 636 | prom_dtlb_load(tlb_ent, |
| 637 | tte_data + 0x400000, |
| 638 | tte_vaddr + 0x400000); |
| 639 | prom_itlb_load(tlb_ent, |
| 640 | tte_data + 0x400000, |
| 641 | tte_vaddr + 0x400000); |
| 642 | } |
| 643 | sparc64_highest_unlocked_tlb_ent = tlb_ent - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
David S. Miller | 0835ae0 | 2005-10-04 15:23:20 -0700 | [diff] [blame] | 645 | if (tlb_type == cheetah_plus) { |
| 646 | sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 | |
| 647 | CTX_CHEETAH_PLUS_NUC); |
| 648 | sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC; |
| 649 | sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0; |
| 650 | } |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 653 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 654 | static void __init inherit_prom_mappings(void) |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 655 | { |
| 656 | read_obp_translations(); |
David S. Miller | 405599b | 2005-09-22 00:12:35 -0700 | [diff] [blame] | 657 | |
| 658 | /* Now fixup OBP's idea about where we really are mapped. */ |
| 659 | prom_printf("Remapping the kernel... "); |
| 660 | remap_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | prom_printf("done.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | void prom_world(int enter) |
| 665 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | if (!enter) |
| 667 | set_fs((mm_segment_t) { get_thread_current_ds() }); |
| 668 | |
David S. Miller | 3487d1d | 2006-01-31 18:33:25 -0800 | [diff] [blame] | 669 | __asm__ __volatile__("flushw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | #ifdef DCACHE_ALIASING_POSSIBLE |
| 673 | void __flush_dcache_range(unsigned long start, unsigned long end) |
| 674 | { |
| 675 | unsigned long va; |
| 676 | |
| 677 | if (tlb_type == spitfire) { |
| 678 | int n = 0; |
| 679 | |
| 680 | for (va = start; va < end; va += 32) { |
| 681 | spitfire_put_dcache_tag(va & 0x3fe0, 0x0); |
| 682 | if (++n >= 512) |
| 683 | break; |
| 684 | } |
David S. Miller | a43fe0e | 2006-02-04 03:10:53 -0800 | [diff] [blame] | 685 | } else if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | start = __pa(start); |
| 687 | end = __pa(end); |
| 688 | for (va = start; va < end; va += 32) |
| 689 | __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" |
| 690 | "membar #Sync" |
| 691 | : /* no outputs */ |
| 692 | : "r" (va), |
| 693 | "i" (ASI_DCACHE_INVALIDATE)); |
| 694 | } |
| 695 | } |
| 696 | #endif /* DCACHE_ALIASING_POSSIBLE */ |
| 697 | |
David S. Miller | 85f1e1f | 2007-03-15 17:51:26 -0700 | [diff] [blame] | 698 | /* get_new_mmu_context() uses "cache + 1". */ |
| 699 | DEFINE_SPINLOCK(ctx_alloc_lock); |
| 700 | unsigned long tlb_context_cache = CTX_FIRST_VERSION - 1; |
| 701 | #define MAX_CTX_NR (1UL << CTX_NR_BITS) |
| 702 | #define CTX_BMAP_SLOTS BITS_TO_LONGS(MAX_CTX_NR) |
| 703 | DECLARE_BITMAP(mmu_context_bmap, MAX_CTX_NR); |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | /* Caller does TLB context flushing on local CPU if necessary. |
| 706 | * The caller also ensures that CTX_VALID(mm->context) is false. |
| 707 | * |
| 708 | * We must be careful about boundary cases so that we never |
| 709 | * let the user have CTX 0 (nucleus) or we ever use a CTX |
| 710 | * version of zero (and thus NO_CONTEXT would not be caught |
| 711 | * by version mis-match tests in mmu_context.h). |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 712 | * |
| 713 | * Always invoked with interrupts disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | */ |
| 715 | void get_new_mmu_context(struct mm_struct *mm) |
| 716 | { |
| 717 | unsigned long ctx, new_ctx; |
| 718 | unsigned long orig_pgsz_bits; |
David S. Miller | a77754b | 2006-03-06 19:59:50 -0800 | [diff] [blame] | 719 | unsigned long flags; |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 720 | int new_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
David S. Miller | a77754b | 2006-03-06 19:59:50 -0800 | [diff] [blame] | 722 | spin_lock_irqsave(&ctx_alloc_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK); |
| 724 | ctx = (tlb_context_cache + 1) & CTX_NR_MASK; |
| 725 | 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] | 726 | new_version = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | if (new_ctx >= (1 << CTX_NR_BITS)) { |
| 728 | new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1); |
| 729 | if (new_ctx >= ctx) { |
| 730 | int i; |
| 731 | new_ctx = (tlb_context_cache & CTX_VERSION_MASK) + |
| 732 | CTX_FIRST_VERSION; |
| 733 | if (new_ctx == 1) |
| 734 | new_ctx = CTX_FIRST_VERSION; |
| 735 | |
| 736 | /* Don't call memset, for 16 entries that's just |
| 737 | * plain silly... |
| 738 | */ |
| 739 | mmu_context_bmap[0] = 3; |
| 740 | mmu_context_bmap[1] = 0; |
| 741 | mmu_context_bmap[2] = 0; |
| 742 | mmu_context_bmap[3] = 0; |
| 743 | for (i = 4; i < CTX_BMAP_SLOTS; i += 4) { |
| 744 | mmu_context_bmap[i + 0] = 0; |
| 745 | mmu_context_bmap[i + 1] = 0; |
| 746 | mmu_context_bmap[i + 2] = 0; |
| 747 | mmu_context_bmap[i + 3] = 0; |
| 748 | } |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 749 | new_version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | goto out; |
| 751 | } |
| 752 | } |
| 753 | mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63)); |
| 754 | new_ctx |= (tlb_context_cache & CTX_VERSION_MASK); |
| 755 | out: |
| 756 | tlb_context_cache = new_ctx; |
| 757 | mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits; |
David S. Miller | a77754b | 2006-03-06 19:59:50 -0800 | [diff] [blame] | 758 | spin_unlock_irqrestore(&ctx_alloc_lock, flags); |
David S. Miller | a0663a7 | 2006-02-23 14:19:28 -0800 | [diff] [blame] | 759 | |
| 760 | if (unlikely(new_version)) |
| 761 | smp_new_mmu_context_version(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 764 | /* Find a free area for the bootmem map, avoiding the kernel image |
| 765 | * and the initial ramdisk. |
| 766 | */ |
| 767 | static unsigned long __init choose_bootmap_pfn(unsigned long start_pfn, |
| 768 | unsigned long end_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 770 | unsigned long avoid_start, avoid_end, bootmap_size; |
| 771 | int i; |
| 772 | |
David S. Miller | 3996465 | 2007-03-15 19:36:53 -0700 | [diff] [blame] | 773 | bootmap_size = bootmem_bootmap_pages(end_pfn - start_pfn); |
| 774 | bootmap_size <<= PAGE_SHIFT; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 775 | |
| 776 | avoid_start = avoid_end = 0; |
| 777 | #ifdef CONFIG_BLK_DEV_INITRD |
| 778 | avoid_start = initrd_start; |
| 779 | avoid_end = PAGE_ALIGN(initrd_end); |
| 780 | #endif |
| 781 | |
| 782 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 783 | prom_printf("choose_bootmap_pfn: kern[%lx:%lx] avoid[%lx:%lx]\n", |
| 784 | kern_base, PAGE_ALIGN(kern_base + kern_size), |
| 785 | avoid_start, avoid_end); |
| 786 | #endif |
| 787 | for (i = 0; i < pavail_ents; i++) { |
| 788 | unsigned long start, end; |
| 789 | |
| 790 | start = pavail[i].phys_addr; |
| 791 | end = start + pavail[i].reg_size; |
| 792 | |
| 793 | while (start < end) { |
| 794 | if (start >= kern_base && |
| 795 | start < PAGE_ALIGN(kern_base + kern_size)) { |
| 796 | start = PAGE_ALIGN(kern_base + kern_size); |
| 797 | continue; |
| 798 | } |
| 799 | if (start >= avoid_start && start < avoid_end) { |
| 800 | start = avoid_end; |
| 801 | continue; |
| 802 | } |
| 803 | |
| 804 | if ((end - start) < bootmap_size) |
| 805 | break; |
| 806 | |
| 807 | if (start < kern_base && |
| 808 | (start + bootmap_size) > kern_base) { |
| 809 | start = PAGE_ALIGN(kern_base + kern_size); |
| 810 | continue; |
| 811 | } |
| 812 | |
| 813 | if (start < avoid_start && |
| 814 | (start + bootmap_size) > avoid_start) { |
| 815 | start = avoid_end; |
| 816 | continue; |
| 817 | } |
| 818 | |
| 819 | /* OK, it doesn't overlap anything, use it. */ |
| 820 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 821 | prom_printf("choose_bootmap_pfn: Using %lx [%lx]\n", |
| 822 | start >> PAGE_SHIFT, start); |
| 823 | #endif |
| 824 | return start >> PAGE_SHIFT; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | prom_printf("Cannot find free area for bootmap, aborting.\n"); |
| 829 | prom_halt(); |
| 830 | } |
| 831 | |
David S. Miller | 6fc5bae | 2006-12-28 21:00:23 -0800 | [diff] [blame] | 832 | static void __init trim_pavail(unsigned long *cur_size_p, |
| 833 | unsigned long *end_of_phys_p) |
| 834 | { |
| 835 | unsigned long to_trim = *cur_size_p - cmdline_memory_size; |
| 836 | unsigned long avoid_start, avoid_end; |
| 837 | int i; |
| 838 | |
| 839 | to_trim = PAGE_ALIGN(to_trim); |
| 840 | |
| 841 | avoid_start = avoid_end = 0; |
| 842 | #ifdef CONFIG_BLK_DEV_INITRD |
| 843 | avoid_start = initrd_start; |
| 844 | avoid_end = PAGE_ALIGN(initrd_end); |
| 845 | #endif |
| 846 | |
| 847 | /* Trim some pavail[] entries in order to satisfy the |
| 848 | * requested "mem=xxx" kernel command line specification. |
| 849 | * |
| 850 | * We must not trim off the kernel image area nor the |
| 851 | * initial ramdisk range (if any). Also, we must not trim |
| 852 | * any pavail[] entry down to zero in order to preserve |
| 853 | * the invariant that all pavail[] entries have a non-zero |
| 854 | * size which is assumed by all of the code in here. |
| 855 | */ |
| 856 | for (i = 0; i < pavail_ents; i++) { |
| 857 | unsigned long start, end, kern_end; |
| 858 | unsigned long trim_low, trim_high, n; |
| 859 | |
| 860 | kern_end = PAGE_ALIGN(kern_base + kern_size); |
| 861 | |
| 862 | trim_low = start = pavail[i].phys_addr; |
| 863 | trim_high = end = start + pavail[i].reg_size; |
| 864 | |
| 865 | if (kern_base >= start && |
| 866 | kern_base < end) { |
| 867 | trim_low = kern_base; |
| 868 | if (kern_end >= end) |
| 869 | continue; |
| 870 | } |
| 871 | if (kern_end >= start && |
| 872 | kern_end < end) { |
| 873 | trim_high = kern_end; |
| 874 | } |
| 875 | if (avoid_start && |
| 876 | avoid_start >= start && |
| 877 | avoid_start < end) { |
| 878 | if (trim_low > avoid_start) |
| 879 | trim_low = avoid_start; |
| 880 | if (avoid_end >= end) |
| 881 | continue; |
| 882 | } |
| 883 | if (avoid_end && |
| 884 | avoid_end >= start && |
| 885 | avoid_end < end) { |
| 886 | if (trim_high < avoid_end) |
| 887 | trim_high = avoid_end; |
| 888 | } |
| 889 | |
| 890 | if (trim_high <= trim_low) |
| 891 | continue; |
| 892 | |
| 893 | if (trim_low == start && trim_high == end) { |
| 894 | /* Whole chunk is available for trimming. |
| 895 | * Trim all except one page, in order to keep |
| 896 | * entry non-empty. |
| 897 | */ |
| 898 | n = (end - start) - PAGE_SIZE; |
| 899 | if (n > to_trim) |
| 900 | n = to_trim; |
| 901 | |
| 902 | if (n) { |
| 903 | pavail[i].phys_addr += n; |
| 904 | pavail[i].reg_size -= n; |
| 905 | to_trim -= n; |
| 906 | } |
| 907 | } else { |
| 908 | n = (trim_low - start); |
| 909 | if (n > to_trim) |
| 910 | n = to_trim; |
| 911 | |
| 912 | if (n) { |
| 913 | pavail[i].phys_addr += n; |
| 914 | pavail[i].reg_size -= n; |
| 915 | to_trim -= n; |
| 916 | } |
| 917 | if (to_trim) { |
| 918 | n = end - trim_high; |
| 919 | if (n > to_trim) |
| 920 | n = to_trim; |
| 921 | if (n) { |
| 922 | pavail[i].reg_size -= n; |
| 923 | to_trim -= n; |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | if (!to_trim) |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | /* Recalculate. */ |
| 933 | *cur_size_p = 0UL; |
| 934 | for (i = 0; i < pavail_ents; i++) { |
| 935 | *end_of_phys_p = pavail[i].phys_addr + |
| 936 | pavail[i].reg_size; |
| 937 | *cur_size_p += pavail[i].reg_size; |
| 938 | } |
| 939 | } |
| 940 | |
David S. Miller | f1cfdb5 | 2007-03-15 22:52:18 -0700 | [diff] [blame^] | 941 | /* About pages_avail, this is the value we will use to calculate |
| 942 | * the zholes_size[] argument given to free_area_init_node(). The |
| 943 | * page allocator uses this to calculate nr_kernel_pages, |
| 944 | * nr_all_pages and zone->present_pages. On NUMA it is used |
| 945 | * to calculate zone->min_unmapped_pages and zone->min_slab_pages. |
| 946 | * |
| 947 | * So this number should really be set to what the page allocator |
| 948 | * actually ends up with. This means: |
| 949 | * 1) It should include bootmem map pages, we'll release those. |
| 950 | * 2) It should not include the kernel image, except for the |
| 951 | * __init sections which we will also release. |
| 952 | * 3) It should include the initrd image, since we'll release |
| 953 | * that too. |
| 954 | */ |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 955 | static unsigned long __init bootmem_init(unsigned long *pages_avail, |
| 956 | unsigned long phys_base) |
| 957 | { |
| 958 | unsigned long bootmap_size, end_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | unsigned long end_of_phys_memory = 0UL; |
| 960 | unsigned long bootmap_pfn, bytes_avail, size; |
| 961 | int i; |
| 962 | |
| 963 | #ifdef CONFIG_DEBUG_BOOTMEM |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 964 | prom_printf("bootmem_init: Scan pavail, "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | #endif |
| 966 | |
| 967 | bytes_avail = 0UL; |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 968 | for (i = 0; i < pavail_ents; i++) { |
| 969 | end_of_phys_memory = pavail[i].phys_addr + |
| 970 | pavail[i].reg_size; |
| 971 | bytes_avail += pavail[i].reg_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | |
David S. Miller | 6fc5bae | 2006-12-28 21:00:23 -0800 | [diff] [blame] | 974 | /* Determine the location of the initial ramdisk before trying |
| 975 | * to honor the "mem=xxx" command line argument. We must know |
| 976 | * where the kernel image and the ramdisk image are so that we |
| 977 | * do not trim those two areas from the physical memory map. |
| 978 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | #ifdef CONFIG_BLK_DEV_INITRD |
| 981 | /* Now have to check initial ramdisk, so that bootmap does not overwrite it */ |
| 982 | if (sparc_ramdisk_image || sparc_ramdisk_image64) { |
| 983 | unsigned long ramdisk_image = sparc_ramdisk_image ? |
| 984 | sparc_ramdisk_image : sparc_ramdisk_image64; |
David S. Miller | 715a0ec | 2006-09-26 23:14:21 -0700 | [diff] [blame] | 985 | ramdisk_image -= KERNBASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | initrd_start = ramdisk_image + phys_base; |
| 987 | initrd_end = initrd_start + sparc_ramdisk_size; |
| 988 | if (initrd_end > end_of_phys_memory) { |
| 989 | printk(KERN_CRIT "initrd extends beyond end of memory " |
| 990 | "(0x%016lx > 0x%016lx)\ndisabling initrd\n", |
| 991 | initrd_end, end_of_phys_memory); |
| 992 | initrd_start = 0; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 993 | initrd_end = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | #endif |
David S. Miller | 6fc5bae | 2006-12-28 21:00:23 -0800 | [diff] [blame] | 997 | |
| 998 | if (cmdline_memory_size && |
| 999 | bytes_avail > cmdline_memory_size) |
| 1000 | trim_pavail(&bytes_avail, |
| 1001 | &end_of_phys_memory); |
| 1002 | |
| 1003 | *pages_avail = bytes_avail >> PAGE_SHIFT; |
| 1004 | |
| 1005 | end_pfn = end_of_phys_memory >> PAGE_SHIFT; |
| 1006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | /* Initialize the boot-time allocator. */ |
| 1008 | max_pfn = max_low_pfn = end_pfn; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1009 | min_low_pfn = (phys_base >> PAGE_SHIFT); |
| 1010 | |
| 1011 | bootmap_pfn = choose_bootmap_pfn(min_low_pfn, end_pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
| 1013 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 1014 | prom_printf("init_bootmem(min[%lx], bootmap[%lx], max[%lx])\n", |
| 1015 | min_low_pfn, bootmap_pfn, max_low_pfn); |
| 1016 | #endif |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1017 | bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, |
David S. Miller | 17b0e19 | 2006-03-08 15:57:03 -0800 | [diff] [blame] | 1018 | min_low_pfn, end_pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | /* Now register the available physical memory with the |
| 1021 | * allocator. |
| 1022 | */ |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1023 | for (i = 0; i < pavail_ents; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | #ifdef CONFIG_DEBUG_BOOTMEM |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1025 | prom_printf("free_bootmem(pavail:%d): base[%lx] size[%lx]\n", |
| 1026 | i, pavail[i].phys_addr, pavail[i].reg_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | #endif |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1028 | free_bootmem(pavail[i].phys_addr, pavail[i].reg_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | #ifdef CONFIG_BLK_DEV_INITRD |
| 1032 | if (initrd_start) { |
| 1033 | size = initrd_end - initrd_start; |
| 1034 | |
| 1035 | /* Resert the initrd image area. */ |
| 1036 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 1037 | prom_printf("reserve_bootmem(initrd): base[%llx] size[%lx]\n", |
| 1038 | initrd_start, initrd_end); |
| 1039 | #endif |
| 1040 | reserve_bootmem(initrd_start, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | initrd_start += PAGE_OFFSET; |
| 1043 | initrd_end += PAGE_OFFSET; |
| 1044 | } |
| 1045 | #endif |
| 1046 | /* Reserve the kernel text/data/bss. */ |
| 1047 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 1048 | prom_printf("reserve_bootmem(kernel): base[%lx] size[%lx]\n", kern_base, kern_size); |
| 1049 | #endif |
| 1050 | reserve_bootmem(kern_base, kern_size); |
| 1051 | *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT; |
| 1052 | |
David S. Miller | f1cfdb5 | 2007-03-15 22:52:18 -0700 | [diff] [blame^] | 1053 | /* Add back in the initmem pages. */ |
| 1054 | size = ((unsigned long)(__init_end) & PAGE_MASK) - |
| 1055 | PAGE_ALIGN((unsigned long)__init_begin); |
| 1056 | *pages_avail += size >> PAGE_SHIFT; |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | /* Reserve the bootmem map. We do not account for it |
| 1059 | * in pages_avail because we will release that memory |
| 1060 | * in free_all_bootmem. |
| 1061 | */ |
| 1062 | size = bootmap_size; |
| 1063 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 1064 | prom_printf("reserve_bootmem(bootmap): base[%lx] size[%lx]\n", |
| 1065 | (bootmap_pfn << PAGE_SHIFT), size); |
| 1066 | #endif |
| 1067 | reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1069 | for (i = 0; i < pavail_ents; i++) { |
| 1070 | unsigned long start_pfn, end_pfn; |
| 1071 | |
| 1072 | start_pfn = pavail[i].phys_addr >> PAGE_SHIFT; |
| 1073 | end_pfn = (start_pfn + (pavail[i].reg_size >> PAGE_SHIFT)); |
| 1074 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 1075 | prom_printf("memory_present(0, %lx, %lx)\n", |
| 1076 | start_pfn, end_pfn); |
| 1077 | #endif |
| 1078 | memory_present(0, start_pfn, end_pfn); |
| 1079 | } |
| 1080 | |
| 1081 | sparse_init(); |
| 1082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return end_pfn; |
| 1084 | } |
| 1085 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1086 | static struct linux_prom64_registers pall[MAX_BANKS] __initdata; |
| 1087 | static int pall_ents __initdata; |
| 1088 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1089 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 1090 | static unsigned long kernel_map_range(unsigned long pstart, unsigned long pend, pgprot_t prot) |
| 1091 | { |
| 1092 | unsigned long vstart = PAGE_OFFSET + pstart; |
| 1093 | unsigned long vend = PAGE_OFFSET + pend; |
| 1094 | unsigned long alloc_bytes = 0UL; |
| 1095 | |
| 1096 | if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) { |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1097 | prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n", |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1098 | vstart, vend); |
| 1099 | prom_halt(); |
| 1100 | } |
| 1101 | |
| 1102 | while (vstart < vend) { |
| 1103 | unsigned long this_end, paddr = __pa(vstart); |
| 1104 | pgd_t *pgd = pgd_offset_k(vstart); |
| 1105 | pud_t *pud; |
| 1106 | pmd_t *pmd; |
| 1107 | pte_t *pte; |
| 1108 | |
| 1109 | pud = pud_offset(pgd, vstart); |
| 1110 | if (pud_none(*pud)) { |
| 1111 | pmd_t *new; |
| 1112 | |
| 1113 | new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); |
| 1114 | alloc_bytes += PAGE_SIZE; |
| 1115 | pud_populate(&init_mm, pud, new); |
| 1116 | } |
| 1117 | |
| 1118 | pmd = pmd_offset(pud, vstart); |
| 1119 | if (!pmd_present(*pmd)) { |
| 1120 | pte_t *new; |
| 1121 | |
| 1122 | new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE); |
| 1123 | alloc_bytes += PAGE_SIZE; |
| 1124 | pmd_populate_kernel(&init_mm, pmd, new); |
| 1125 | } |
| 1126 | |
| 1127 | pte = pte_offset_kernel(pmd, vstart); |
| 1128 | this_end = (vstart + PMD_SIZE) & PMD_MASK; |
| 1129 | if (this_end > vend) |
| 1130 | this_end = vend; |
| 1131 | |
| 1132 | while (vstart < this_end) { |
| 1133 | pte_val(*pte) = (paddr | pgprot_val(prot)); |
| 1134 | |
| 1135 | vstart += PAGE_SIZE; |
| 1136 | paddr += PAGE_SIZE; |
| 1137 | pte++; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | return alloc_bytes; |
| 1142 | } |
| 1143 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1144 | extern unsigned int kvmap_linear_patch[1]; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1145 | #endif /* CONFIG_DEBUG_PAGEALLOC */ |
| 1146 | |
| 1147 | static void __init mark_kpte_bitmap(unsigned long start, unsigned long end) |
| 1148 | { |
| 1149 | const unsigned long shift_256MB = 28; |
| 1150 | const unsigned long mask_256MB = ((1UL << shift_256MB) - 1UL); |
| 1151 | const unsigned long size_256MB = (1UL << shift_256MB); |
| 1152 | |
| 1153 | while (start < end) { |
| 1154 | long remains; |
| 1155 | |
David S. Miller | f7c0033 | 2006-03-05 22:18:50 -0800 | [diff] [blame] | 1156 | remains = end - start; |
| 1157 | if (remains < size_256MB) |
| 1158 | break; |
| 1159 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1160 | if (start & mask_256MB) { |
| 1161 | start = (start + size_256MB) & ~mask_256MB; |
| 1162 | continue; |
| 1163 | } |
| 1164 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1165 | while (remains >= size_256MB) { |
| 1166 | unsigned long index = start >> shift_256MB; |
| 1167 | |
| 1168 | __set_bit(index, kpte_linear_bitmap); |
| 1169 | |
| 1170 | start += size_256MB; |
| 1171 | remains -= size_256MB; |
| 1172 | } |
| 1173 | } |
| 1174 | } |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1175 | |
| 1176 | static void __init kernel_physical_mapping_init(void) |
| 1177 | { |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1178 | unsigned long i; |
| 1179 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 1180 | unsigned long mem_alloced = 0UL; |
| 1181 | #endif |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1182 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1183 | read_obp_memory("reg", &pall[0], &pall_ents); |
| 1184 | |
| 1185 | for (i = 0; i < pall_ents; i++) { |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1186 | unsigned long phys_start, phys_end; |
| 1187 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1188 | phys_start = pall[i].phys_addr; |
| 1189 | phys_end = phys_start + pall[i].reg_size; |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1190 | |
| 1191 | mark_kpte_bitmap(phys_start, phys_end); |
| 1192 | |
| 1193 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1194 | mem_alloced += kernel_map_range(phys_start, phys_end, |
| 1195 | PAGE_KERNEL); |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1196 | #endif |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1199 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1200 | printk("Allocated %ld bytes for kernel page tables.\n", |
| 1201 | mem_alloced); |
| 1202 | |
| 1203 | kvmap_linear_patch[0] = 0x01000000; /* nop */ |
| 1204 | flushi(&kvmap_linear_patch[0]); |
| 1205 | |
| 1206 | __flush_tlb_all(); |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1207 | #endif |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1210 | #ifdef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1211 | void kernel_map_pages(struct page *page, int numpages, int enable) |
| 1212 | { |
| 1213 | unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT; |
| 1214 | unsigned long phys_end = phys_start + (numpages * PAGE_SIZE); |
| 1215 | |
| 1216 | kernel_map_range(phys_start, phys_end, |
| 1217 | (enable ? PAGE_KERNEL : __pgprot(0))); |
| 1218 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 1219 | flush_tsb_kernel_range(PAGE_OFFSET + phys_start, |
| 1220 | PAGE_OFFSET + phys_end); |
| 1221 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1222 | /* we should perform an IPI and flush all tlbs, |
| 1223 | * but that can deadlock->flush only current cpu. |
| 1224 | */ |
| 1225 | __flush_tlb_kernel_range(PAGE_OFFSET + phys_start, |
| 1226 | PAGE_OFFSET + phys_end); |
| 1227 | } |
| 1228 | #endif |
| 1229 | |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 1230 | unsigned long __init find_ecache_flush_span(unsigned long size) |
| 1231 | { |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1232 | int i; |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 1233 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1234 | for (i = 0; i < pavail_ents; i++) { |
| 1235 | if (pavail[i].reg_size >= size) |
| 1236 | return pavail[i].phys_addr; |
David S. Miller | 1014757 | 2005-09-28 21:46:43 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | return ~0UL; |
| 1240 | } |
| 1241 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1242 | static void __init tsb_phys_patch(void) |
| 1243 | { |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1244 | struct tsb_ldquad_phys_patch_entry *pquad; |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1245 | struct tsb_phys_patch_entry *p; |
| 1246 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1247 | pquad = &__tsb_ldquad_phys_patch; |
| 1248 | while (pquad < &__tsb_ldquad_phys_patch_end) { |
| 1249 | unsigned long addr = pquad->addr; |
| 1250 | |
| 1251 | if (tlb_type == hypervisor) |
| 1252 | *(unsigned int *) addr = pquad->sun4v_insn; |
| 1253 | else |
| 1254 | *(unsigned int *) addr = pquad->sun4u_insn; |
| 1255 | wmb(); |
| 1256 | __asm__ __volatile__("flush %0" |
| 1257 | : /* no outputs */ |
| 1258 | : "r" (addr)); |
| 1259 | |
| 1260 | pquad++; |
| 1261 | } |
| 1262 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1263 | p = &__tsb_phys_patch; |
| 1264 | while (p < &__tsb_phys_patch_end) { |
| 1265 | unsigned long addr = p->addr; |
| 1266 | |
| 1267 | *(unsigned int *) addr = p->insn; |
| 1268 | wmb(); |
| 1269 | __asm__ __volatile__("flush %0" |
| 1270 | : /* no outputs */ |
| 1271 | : "r" (addr)); |
| 1272 | |
| 1273 | p++; |
| 1274 | } |
| 1275 | } |
| 1276 | |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1277 | /* Don't mark as init, we give this to the Hypervisor. */ |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1278 | #ifndef CONFIG_DEBUG_PAGEALLOC |
| 1279 | #define NUM_KTSB_DESCR 2 |
| 1280 | #else |
| 1281 | #define NUM_KTSB_DESCR 1 |
| 1282 | #endif |
| 1283 | static struct hv_tsb_descr ktsb_descr[NUM_KTSB_DESCR]; |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1284 | extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES]; |
| 1285 | |
| 1286 | static void __init sun4v_ktsb_init(void) |
| 1287 | { |
| 1288 | unsigned long ktsb_pa; |
| 1289 | |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1290 | /* First KTSB for PAGE_SIZE mappings. */ |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1291 | ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE); |
| 1292 | |
| 1293 | switch (PAGE_SIZE) { |
| 1294 | case 8 * 1024: |
| 1295 | default: |
| 1296 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_8K; |
| 1297 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_8K; |
| 1298 | break; |
| 1299 | |
| 1300 | case 64 * 1024: |
| 1301 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_64K; |
| 1302 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_64K; |
| 1303 | break; |
| 1304 | |
| 1305 | case 512 * 1024: |
| 1306 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_512K; |
| 1307 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_512K; |
| 1308 | break; |
| 1309 | |
| 1310 | case 4 * 1024 * 1024: |
| 1311 | ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_4MB; |
| 1312 | ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_4MB; |
| 1313 | break; |
| 1314 | }; |
| 1315 | |
David S. Miller | 3f19a84 | 2006-02-17 12:03:20 -0800 | [diff] [blame] | 1316 | ktsb_descr[0].assoc = 1; |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1317 | ktsb_descr[0].num_ttes = KERNEL_TSB_NENTRIES; |
| 1318 | ktsb_descr[0].ctx_idx = 0; |
| 1319 | ktsb_descr[0].tsb_base = ktsb_pa; |
| 1320 | ktsb_descr[0].resv = 0; |
| 1321 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1322 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1323 | /* Second KTSB for 4MB/256MB mappings. */ |
| 1324 | ktsb_pa = (kern_base + |
| 1325 | ((unsigned long)&swapper_4m_tsb[0] - KERNBASE)); |
| 1326 | |
| 1327 | ktsb_descr[1].pgsz_idx = HV_PGSZ_IDX_4MB; |
| 1328 | ktsb_descr[1].pgsz_mask = (HV_PGSZ_MASK_4MB | |
| 1329 | HV_PGSZ_MASK_256MB); |
| 1330 | ktsb_descr[1].assoc = 1; |
| 1331 | ktsb_descr[1].num_ttes = KERNEL_TSB4M_NENTRIES; |
| 1332 | ktsb_descr[1].ctx_idx = 0; |
| 1333 | ktsb_descr[1].tsb_base = ktsb_pa; |
| 1334 | ktsb_descr[1].resv = 0; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1335 | #endif |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | void __cpuinit sun4v_ktsb_register(void) |
| 1339 | { |
| 1340 | register unsigned long func asm("%o5"); |
| 1341 | register unsigned long arg0 asm("%o0"); |
| 1342 | register unsigned long arg1 asm("%o1"); |
| 1343 | unsigned long pa; |
| 1344 | |
| 1345 | pa = kern_base + ((unsigned long)&ktsb_descr[0] - KERNBASE); |
| 1346 | |
| 1347 | func = HV_FAST_MMU_TSB_CTX0; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1348 | arg0 = NUM_KTSB_DESCR; |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1349 | arg1 = pa; |
| 1350 | __asm__ __volatile__("ta %6" |
| 1351 | : "=&r" (func), "=&r" (arg0), "=&r" (arg1) |
| 1352 | : "0" (func), "1" (arg0), "2" (arg1), |
| 1353 | "i" (HV_FAST_TRAP)); |
| 1354 | } |
| 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | /* paging_init() sets up the page tables */ |
| 1357 | |
| 1358 | extern void cheetah_ecache_flush_init(void); |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1359 | extern void sun4v_patch_tlb_handlers(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
| 1361 | static unsigned long last_valid_pfn; |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1362 | pgd_t swapper_pg_dir[2048]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1364 | static void sun4u_pgprot_init(void); |
| 1365 | static void sun4v_pgprot_init(void); |
| 1366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | void __init paging_init(void) |
| 1368 | { |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1369 | unsigned long end_pfn, pages_avail, shift, phys_base; |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1370 | unsigned long real_end, i; |
| 1371 | |
David S. Miller | 481295f | 2006-02-07 21:51:08 -0800 | [diff] [blame] | 1372 | kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL; |
| 1373 | kern_size = (unsigned long)&_end - (unsigned long)KERNBASE; |
| 1374 | |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1375 | /* Invalidate both kernel TSBs. */ |
David S. Miller | 8b23427 | 2006-02-17 18:01:02 -0800 | [diff] [blame] | 1376 | memset(swapper_tsb, 0x40, sizeof(swapper_tsb)); |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1377 | #ifndef CONFIG_DEBUG_PAGEALLOC |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 1378 | memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb)); |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1379 | #endif |
David S. Miller | 8b23427 | 2006-02-17 18:01:02 -0800 | [diff] [blame] | 1380 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1381 | if (tlb_type == hypervisor) |
| 1382 | sun4v_pgprot_init(); |
| 1383 | else |
| 1384 | sun4u_pgprot_init(); |
| 1385 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1386 | if (tlb_type == cheetah_plus || |
| 1387 | tlb_type == hypervisor) |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 1388 | tsb_phys_patch(); |
| 1389 | |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1390 | if (tlb_type == hypervisor) { |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1391 | sun4v_patch_tlb_handlers(); |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1392 | sun4v_ktsb_init(); |
| 1393 | } |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 1394 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1395 | /* Find available physical memory... */ |
| 1396 | read_obp_memory("available", &pavail[0], &pavail_ents); |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1397 | |
| 1398 | phys_base = 0xffffffffffffffffUL; |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1399 | for (i = 0; i < pavail_ents; i++) |
| 1400 | phys_base = min(phys_base, pavail[i].phys_addr); |
David S. Miller | 0836a0e | 2005-09-28 21:38:08 -0700 | [diff] [blame] | 1401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | set_bit(0, mmu_context_bmap); |
| 1403 | |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1404 | shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE); |
| 1405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | real_end = (unsigned long)_end; |
| 1407 | if ((real_end > ((unsigned long)KERNBASE + 0x400000))) |
| 1408 | bigkernel = 1; |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1409 | if ((real_end > ((unsigned long)KERNBASE + 0x800000))) { |
| 1410 | prom_printf("paging_init: Kernel > 8MB, too large.\n"); |
| 1411 | prom_halt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | } |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1413 | |
| 1414 | /* Set kernel pgd to upper alias so physical page computations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | * work. |
| 1416 | */ |
| 1417 | init_mm.pgd += ((shift) / (sizeof(pgd_t))); |
| 1418 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1419 | memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
| 1421 | /* Now can init the kernel/bad page tables. */ |
| 1422 | pud_set(pud_offset(&swapper_pg_dir[0], 0), |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1423 | swapper_low_pmd_dir + (shift / sizeof(pgd_t))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 1425 | inherit_prom_mappings(); |
David S. Miller | 5085b4a | 2005-09-22 00:45:41 -0700 | [diff] [blame] | 1426 | |
David S. Miller | a8b900d | 2006-01-31 18:33:37 -0800 | [diff] [blame] | 1427 | /* Ok, we can use our TLB miss and window trap handlers safely. */ |
| 1428 | setup_tba(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 1430 | __flush_tlb_all(); |
David S. Miller | 9ad98c5 | 2005-10-05 15:12:00 -0700 | [diff] [blame] | 1431 | |
David S. Miller | 490384e | 2006-02-11 14:41:18 -0800 | [diff] [blame] | 1432 | if (tlb_type == hypervisor) |
| 1433 | sun4v_ktsb_register(); |
| 1434 | |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1435 | /* Setup bootmem... */ |
| 1436 | pages_avail = 0; |
David S. Miller | d111201 | 2006-03-08 02:16:07 -0800 | [diff] [blame] | 1437 | last_valid_pfn = end_pfn = bootmem_init(&pages_avail, phys_base); |
| 1438 | |
David S. Miller | 17b0e19 | 2006-03-08 15:57:03 -0800 | [diff] [blame] | 1439 | max_mapnr = last_valid_pfn; |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1440 | |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1441 | kernel_physical_mapping_init(); |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 1442 | |
David S. Miller | 372b07b | 2006-06-21 15:35:28 -0700 | [diff] [blame] | 1443 | prom_build_devicetree(); |
| 1444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | { |
| 1446 | unsigned long zones_size[MAX_NR_ZONES]; |
| 1447 | unsigned long zholes_size[MAX_NR_ZONES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | int znum; |
| 1449 | |
| 1450 | for (znum = 0; znum < MAX_NR_ZONES; znum++) |
| 1451 | zones_size[znum] = zholes_size[znum] = 0; |
| 1452 | |
David S. Miller | 1b51d3a | 2007-02-12 00:13:31 -0800 | [diff] [blame] | 1453 | zones_size[ZONE_NORMAL] = end_pfn; |
| 1454 | zholes_size[ZONE_NORMAL] = end_pfn - pages_avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
| 1456 | free_area_init_node(0, &contig_page_data, zones_size, |
David S. Miller | 17b0e19 | 2006-03-08 15:57:03 -0800 | [diff] [blame] | 1457 | __pa(PAGE_OFFSET) >> PAGE_SHIFT, |
| 1458 | zholes_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | device_scan(); |
| 1462 | } |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | static void __init taint_real_pages(void) |
| 1465 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | int i; |
| 1467 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1468 | read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1470 | /* Find changes discovered in the physmem available rescan and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | * reserve the lost portions in the bootmem maps. |
| 1472 | */ |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1473 | for (i = 0; i < pavail_ents; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | unsigned long old_start, old_end; |
| 1475 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1476 | old_start = pavail[i].phys_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | old_end = old_start + |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1478 | pavail[i].reg_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | while (old_start < old_end) { |
| 1480 | int n; |
| 1481 | |
David S. Miller | c2a5a46 | 2006-06-22 00:01:56 -0700 | [diff] [blame] | 1482 | for (n = 0; n < pavail_rescan_ents; n++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | unsigned long new_start, new_end; |
| 1484 | |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1485 | new_start = pavail_rescan[n].phys_addr; |
| 1486 | new_end = new_start + |
| 1487 | pavail_rescan[n].reg_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
| 1489 | if (new_start <= old_start && |
| 1490 | new_end >= (old_start + PAGE_SIZE)) { |
David S. Miller | 13edad7 | 2005-09-29 17:58:26 -0700 | [diff] [blame] | 1491 | set_bit(old_start >> 22, |
| 1492 | sparc64_valid_addr_bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | goto do_next_page; |
| 1494 | } |
| 1495 | } |
| 1496 | reserve_bootmem(old_start, PAGE_SIZE); |
| 1497 | |
| 1498 | do_next_page: |
| 1499 | old_start += PAGE_SIZE; |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | |
David S. Miller | c2a5a46 | 2006-06-22 00:01:56 -0700 | [diff] [blame] | 1504 | int __init page_in_phys_avail(unsigned long paddr) |
| 1505 | { |
| 1506 | int i; |
| 1507 | |
| 1508 | paddr &= PAGE_MASK; |
| 1509 | |
| 1510 | for (i = 0; i < pavail_rescan_ents; i++) { |
| 1511 | unsigned long start, end; |
| 1512 | |
| 1513 | start = pavail_rescan[i].phys_addr; |
| 1514 | end = start + pavail_rescan[i].reg_size; |
| 1515 | |
| 1516 | if (paddr >= start && paddr < end) |
| 1517 | return 1; |
| 1518 | } |
| 1519 | if (paddr >= kern_base && paddr < (kern_base + kern_size)) |
| 1520 | return 1; |
| 1521 | #ifdef CONFIG_BLK_DEV_INITRD |
| 1522 | if (paddr >= __pa(initrd_start) && |
| 1523 | paddr < __pa(PAGE_ALIGN(initrd_end))) |
| 1524 | return 1; |
| 1525 | #endif |
| 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | void __init mem_init(void) |
| 1531 | { |
| 1532 | unsigned long codepages, datapages, initpages; |
| 1533 | unsigned long addr, last; |
| 1534 | int i; |
| 1535 | |
| 1536 | i = last_valid_pfn >> ((22 - PAGE_SHIFT) + 6); |
| 1537 | i += 1; |
David S. Miller | 2bdb3cb | 2005-09-22 01:08:57 -0700 | [diff] [blame] | 1538 | sparc64_valid_addr_bitmap = (unsigned long *) alloc_bootmem(i << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | if (sparc64_valid_addr_bitmap == NULL) { |
| 1540 | prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n"); |
| 1541 | prom_halt(); |
| 1542 | } |
| 1543 | memset(sparc64_valid_addr_bitmap, 0, i << 3); |
| 1544 | |
| 1545 | addr = PAGE_OFFSET + kern_base; |
| 1546 | last = PAGE_ALIGN(kern_size) + addr; |
| 1547 | while (addr < last) { |
| 1548 | set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap); |
| 1549 | addr += PAGE_SIZE; |
| 1550 | } |
| 1551 | |
| 1552 | taint_real_pages(); |
| 1553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | high_memory = __va(last_valid_pfn << PAGE_SHIFT); |
| 1555 | |
| 1556 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 1557 | prom_printf("mem_init: Calling free_all_bootmem().\n"); |
| 1558 | #endif |
David S. Miller | f1cfdb5 | 2007-03-15 22:52:18 -0700 | [diff] [blame^] | 1559 | |
| 1560 | /* We subtract one to account for the mem_map_zero page |
| 1561 | * allocated below. |
| 1562 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | totalram_pages = num_physpages = free_all_bootmem() - 1; |
| 1564 | |
| 1565 | /* |
| 1566 | * Set up the zero page, mark it reserved, so that page count |
| 1567 | * is not manipulated when freeing the page from user ptes. |
| 1568 | */ |
| 1569 | mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0); |
| 1570 | if (mem_map_zero == NULL) { |
| 1571 | prom_printf("paging_init: Cannot alloc zero page.\n"); |
| 1572 | prom_halt(); |
| 1573 | } |
| 1574 | SetPageReserved(mem_map_zero); |
| 1575 | |
| 1576 | codepages = (((unsigned long) _etext) - ((unsigned long) _start)); |
| 1577 | codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT; |
| 1578 | datapages = (((unsigned long) _edata) - ((unsigned long) _etext)); |
| 1579 | datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT; |
| 1580 | initpages = (((unsigned long) __init_end) - ((unsigned long) __init_begin)); |
| 1581 | initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT; |
| 1582 | |
Christoph Lameter | 9617729 | 2007-02-10 01:43:03 -0800 | [diff] [blame] | 1583 | printk("Memory: %luk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | nr_free_pages() << (PAGE_SHIFT-10), |
| 1585 | codepages << (PAGE_SHIFT-10), |
| 1586 | datapages << (PAGE_SHIFT-10), |
| 1587 | initpages << (PAGE_SHIFT-10), |
| 1588 | PAGE_OFFSET, (last_valid_pfn << PAGE_SHIFT)); |
| 1589 | |
| 1590 | if (tlb_type == cheetah || tlb_type == cheetah_plus) |
| 1591 | cheetah_ecache_flush_init(); |
| 1592 | } |
| 1593 | |
David S. Miller | 898cf0e | 2005-09-23 11:59:44 -0700 | [diff] [blame] | 1594 | void free_initmem(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | { |
| 1596 | unsigned long addr, initend; |
| 1597 | |
| 1598 | /* |
| 1599 | * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes. |
| 1600 | */ |
| 1601 | addr = PAGE_ALIGN((unsigned long)(__init_begin)); |
| 1602 | initend = (unsigned long)(__init_end) & PAGE_MASK; |
| 1603 | for (; addr < initend; addr += PAGE_SIZE) { |
| 1604 | unsigned long page; |
| 1605 | struct page *p; |
| 1606 | |
| 1607 | page = (addr + |
| 1608 | ((unsigned long) __va(kern_base)) - |
| 1609 | ((unsigned long) KERNBASE)); |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 1610 | memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | p = virt_to_page(page); |
| 1612 | |
| 1613 | ClearPageReserved(p); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 1614 | init_page_count(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | __free_page(p); |
| 1616 | num_physpages++; |
| 1617 | totalram_pages++; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | #ifdef CONFIG_BLK_DEV_INITRD |
| 1622 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 1623 | { |
| 1624 | if (start < end) |
| 1625 | printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 1626 | for (; start < end; start += PAGE_SIZE) { |
| 1627 | struct page *p = virt_to_page(start); |
| 1628 | |
| 1629 | ClearPageReserved(p); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 1630 | init_page_count(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | __free_page(p); |
| 1632 | num_physpages++; |
| 1633 | totalram_pages++; |
| 1634 | } |
| 1635 | } |
| 1636 | #endif |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1637 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1638 | #define _PAGE_CACHE_4U (_PAGE_CP_4U | _PAGE_CV_4U) |
| 1639 | #define _PAGE_CACHE_4V (_PAGE_CP_4V | _PAGE_CV_4V) |
| 1640 | #define __DIRTY_BITS_4U (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U) |
| 1641 | #define __DIRTY_BITS_4V (_PAGE_MODIFIED_4V | _PAGE_WRITE_4V | _PAGE_W_4V) |
| 1642 | #define __ACCESS_BITS_4U (_PAGE_ACCESSED_4U | _PAGE_READ_4U | _PAGE_R) |
| 1643 | #define __ACCESS_BITS_4V (_PAGE_ACCESSED_4V | _PAGE_READ_4V | _PAGE_R) |
| 1644 | |
| 1645 | pgprot_t PAGE_KERNEL __read_mostly; |
| 1646 | EXPORT_SYMBOL(PAGE_KERNEL); |
| 1647 | |
| 1648 | pgprot_t PAGE_KERNEL_LOCKED __read_mostly; |
| 1649 | pgprot_t PAGE_COPY __read_mostly; |
David S. Miller | 0f15952 | 2006-02-18 12:43:16 -0800 | [diff] [blame] | 1650 | |
| 1651 | pgprot_t PAGE_SHARED __read_mostly; |
| 1652 | EXPORT_SYMBOL(PAGE_SHARED); |
| 1653 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1654 | pgprot_t PAGE_EXEC __read_mostly; |
| 1655 | unsigned long pg_iobits __read_mostly; |
| 1656 | |
| 1657 | unsigned long _PAGE_IE __read_mostly; |
David S. Miller | 987c74f | 2006-06-25 01:34:43 -0700 | [diff] [blame] | 1658 | EXPORT_SYMBOL(_PAGE_IE); |
David S. Miller | b2bef44 | 2006-02-23 01:55:55 -0800 | [diff] [blame] | 1659 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1660 | unsigned long _PAGE_E __read_mostly; |
David S. Miller | b2bef44 | 2006-02-23 01:55:55 -0800 | [diff] [blame] | 1661 | EXPORT_SYMBOL(_PAGE_E); |
| 1662 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1663 | unsigned long _PAGE_CACHE __read_mostly; |
David S. Miller | b2bef44 | 2006-02-23 01:55:55 -0800 | [diff] [blame] | 1664 | EXPORT_SYMBOL(_PAGE_CACHE); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1665 | |
| 1666 | static void prot_init_common(unsigned long page_none, |
| 1667 | unsigned long page_shared, |
| 1668 | unsigned long page_copy, |
| 1669 | unsigned long page_readonly, |
| 1670 | unsigned long page_exec_bit) |
| 1671 | { |
| 1672 | PAGE_COPY = __pgprot(page_copy); |
David S. Miller | 0f15952 | 2006-02-18 12:43:16 -0800 | [diff] [blame] | 1673 | PAGE_SHARED = __pgprot(page_shared); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1674 | |
| 1675 | protection_map[0x0] = __pgprot(page_none); |
| 1676 | protection_map[0x1] = __pgprot(page_readonly & ~page_exec_bit); |
| 1677 | protection_map[0x2] = __pgprot(page_copy & ~page_exec_bit); |
| 1678 | protection_map[0x3] = __pgprot(page_copy & ~page_exec_bit); |
| 1679 | protection_map[0x4] = __pgprot(page_readonly); |
| 1680 | protection_map[0x5] = __pgprot(page_readonly); |
| 1681 | protection_map[0x6] = __pgprot(page_copy); |
| 1682 | protection_map[0x7] = __pgprot(page_copy); |
| 1683 | protection_map[0x8] = __pgprot(page_none); |
| 1684 | protection_map[0x9] = __pgprot(page_readonly & ~page_exec_bit); |
| 1685 | protection_map[0xa] = __pgprot(page_shared & ~page_exec_bit); |
| 1686 | protection_map[0xb] = __pgprot(page_shared & ~page_exec_bit); |
| 1687 | protection_map[0xc] = __pgprot(page_readonly); |
| 1688 | protection_map[0xd] = __pgprot(page_readonly); |
| 1689 | protection_map[0xe] = __pgprot(page_shared); |
| 1690 | protection_map[0xf] = __pgprot(page_shared); |
| 1691 | } |
| 1692 | |
| 1693 | static void __init sun4u_pgprot_init(void) |
| 1694 | { |
| 1695 | unsigned long page_none, page_shared, page_copy, page_readonly; |
| 1696 | unsigned long page_exec_bit; |
| 1697 | |
| 1698 | PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID | |
| 1699 | _PAGE_CACHE_4U | _PAGE_P_4U | |
| 1700 | __ACCESS_BITS_4U | __DIRTY_BITS_4U | |
| 1701 | _PAGE_EXEC_4U); |
| 1702 | PAGE_KERNEL_LOCKED = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID | |
| 1703 | _PAGE_CACHE_4U | _PAGE_P_4U | |
| 1704 | __ACCESS_BITS_4U | __DIRTY_BITS_4U | |
| 1705 | _PAGE_EXEC_4U | _PAGE_L_4U); |
| 1706 | PAGE_EXEC = __pgprot(_PAGE_EXEC_4U); |
| 1707 | |
| 1708 | _PAGE_IE = _PAGE_IE_4U; |
| 1709 | _PAGE_E = _PAGE_E_4U; |
| 1710 | _PAGE_CACHE = _PAGE_CACHE_4U; |
| 1711 | |
| 1712 | pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4U | __DIRTY_BITS_4U | |
| 1713 | __ACCESS_BITS_4U | _PAGE_E_4U); |
| 1714 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1715 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 1716 | kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZBITS_4U) ^ |
| 1717 | 0xfffff80000000000; |
| 1718 | #else |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1719 | kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4U) ^ |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1720 | 0xfffff80000000000; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1721 | #endif |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1722 | kern_linear_pte_xor[0] |= (_PAGE_CP_4U | _PAGE_CV_4U | |
| 1723 | _PAGE_P_4U | _PAGE_W_4U); |
| 1724 | |
| 1725 | /* XXX Should use 256MB on Panther. XXX */ |
| 1726 | kern_linear_pte_xor[1] = kern_linear_pte_xor[0]; |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1727 | |
| 1728 | _PAGE_SZBITS = _PAGE_SZBITS_4U; |
| 1729 | _PAGE_ALL_SZ_BITS = (_PAGE_SZ4MB_4U | _PAGE_SZ512K_4U | |
| 1730 | _PAGE_SZ64K_4U | _PAGE_SZ8K_4U | |
| 1731 | _PAGE_SZ32MB_4U | _PAGE_SZ256MB_4U); |
| 1732 | |
| 1733 | |
| 1734 | page_none = _PAGE_PRESENT_4U | _PAGE_ACCESSED_4U | _PAGE_CACHE_4U; |
| 1735 | page_shared = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U | |
| 1736 | __ACCESS_BITS_4U | _PAGE_WRITE_4U | _PAGE_EXEC_4U); |
| 1737 | page_copy = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U | |
| 1738 | __ACCESS_BITS_4U | _PAGE_EXEC_4U); |
| 1739 | page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U | |
| 1740 | __ACCESS_BITS_4U | _PAGE_EXEC_4U); |
| 1741 | |
| 1742 | page_exec_bit = _PAGE_EXEC_4U; |
| 1743 | |
| 1744 | prot_init_common(page_none, page_shared, page_copy, page_readonly, |
| 1745 | page_exec_bit); |
| 1746 | } |
| 1747 | |
| 1748 | static void __init sun4v_pgprot_init(void) |
| 1749 | { |
| 1750 | unsigned long page_none, page_shared, page_copy, page_readonly; |
| 1751 | unsigned long page_exec_bit; |
| 1752 | |
| 1753 | PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4V | _PAGE_VALID | |
| 1754 | _PAGE_CACHE_4V | _PAGE_P_4V | |
| 1755 | __ACCESS_BITS_4V | __DIRTY_BITS_4V | |
| 1756 | _PAGE_EXEC_4V); |
| 1757 | PAGE_KERNEL_LOCKED = PAGE_KERNEL; |
| 1758 | PAGE_EXEC = __pgprot(_PAGE_EXEC_4V); |
| 1759 | |
| 1760 | _PAGE_IE = _PAGE_IE_4V; |
| 1761 | _PAGE_E = _PAGE_E_4V; |
| 1762 | _PAGE_CACHE = _PAGE_CACHE_4V; |
| 1763 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1764 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 1765 | kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZBITS_4V) ^ |
| 1766 | 0xfffff80000000000; |
| 1767 | #else |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1768 | kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4V) ^ |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1769 | 0xfffff80000000000; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1770 | #endif |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1771 | kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_CV_4V | |
| 1772 | _PAGE_P_4V | _PAGE_W_4V); |
| 1773 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1774 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 1775 | kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZBITS_4V) ^ |
| 1776 | 0xfffff80000000000; |
| 1777 | #else |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1778 | kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZ256MB_4V) ^ |
| 1779 | 0xfffff80000000000; |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 1780 | #endif |
David S. Miller | 9cc3a1a | 2006-02-21 20:51:13 -0800 | [diff] [blame] | 1781 | kern_linear_pte_xor[1] |= (_PAGE_CP_4V | _PAGE_CV_4V | |
| 1782 | _PAGE_P_4V | _PAGE_W_4V); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1783 | |
| 1784 | pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4V | __DIRTY_BITS_4V | |
| 1785 | __ACCESS_BITS_4V | _PAGE_E_4V); |
| 1786 | |
| 1787 | _PAGE_SZBITS = _PAGE_SZBITS_4V; |
| 1788 | _PAGE_ALL_SZ_BITS = (_PAGE_SZ16GB_4V | _PAGE_SZ2GB_4V | |
| 1789 | _PAGE_SZ256MB_4V | _PAGE_SZ32MB_4V | |
| 1790 | _PAGE_SZ4MB_4V | _PAGE_SZ512K_4V | |
| 1791 | _PAGE_SZ64K_4V | _PAGE_SZ8K_4V); |
| 1792 | |
| 1793 | page_none = _PAGE_PRESENT_4V | _PAGE_ACCESSED_4V | _PAGE_CACHE_4V; |
| 1794 | page_shared = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V | |
| 1795 | __ACCESS_BITS_4V | _PAGE_WRITE_4V | _PAGE_EXEC_4V); |
| 1796 | page_copy = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V | |
| 1797 | __ACCESS_BITS_4V | _PAGE_EXEC_4V); |
| 1798 | page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V | |
| 1799 | __ACCESS_BITS_4V | _PAGE_EXEC_4V); |
| 1800 | |
| 1801 | page_exec_bit = _PAGE_EXEC_4V; |
| 1802 | |
| 1803 | prot_init_common(page_none, page_shared, page_copy, page_readonly, |
| 1804 | page_exec_bit); |
| 1805 | } |
| 1806 | |
| 1807 | unsigned long pte_sz_bits(unsigned long sz) |
| 1808 | { |
| 1809 | if (tlb_type == hypervisor) { |
| 1810 | switch (sz) { |
| 1811 | case 8 * 1024: |
| 1812 | default: |
| 1813 | return _PAGE_SZ8K_4V; |
| 1814 | case 64 * 1024: |
| 1815 | return _PAGE_SZ64K_4V; |
| 1816 | case 512 * 1024: |
| 1817 | return _PAGE_SZ512K_4V; |
| 1818 | case 4 * 1024 * 1024: |
| 1819 | return _PAGE_SZ4MB_4V; |
| 1820 | }; |
| 1821 | } else { |
| 1822 | switch (sz) { |
| 1823 | case 8 * 1024: |
| 1824 | default: |
| 1825 | return _PAGE_SZ8K_4U; |
| 1826 | case 64 * 1024: |
| 1827 | return _PAGE_SZ64K_4U; |
| 1828 | case 512 * 1024: |
| 1829 | return _PAGE_SZ512K_4U; |
| 1830 | case 4 * 1024 * 1024: |
| 1831 | return _PAGE_SZ4MB_4U; |
| 1832 | }; |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | pte_t mk_pte_io(unsigned long page, pgprot_t prot, int space, unsigned long page_size) |
| 1837 | { |
| 1838 | pte_t pte; |
David S. Miller | cf62715 | 2006-02-12 21:10:07 -0800 | [diff] [blame] | 1839 | |
| 1840 | pte_val(pte) = page | pgprot_val(pgprot_noncached(prot)); |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1841 | pte_val(pte) |= (((unsigned long)space) << 32); |
| 1842 | pte_val(pte) |= pte_sz_bits(page_size); |
David S. Miller | cf62715 | 2006-02-12 21:10:07 -0800 | [diff] [blame] | 1843 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1844 | return pte; |
| 1845 | } |
| 1846 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1847 | static unsigned long kern_large_tte(unsigned long paddr) |
| 1848 | { |
| 1849 | unsigned long val; |
| 1850 | |
| 1851 | val = (_PAGE_VALID | _PAGE_SZ4MB_4U | |
| 1852 | _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_P_4U | |
| 1853 | _PAGE_EXEC_4U | _PAGE_L_4U | _PAGE_W_4U); |
| 1854 | if (tlb_type == hypervisor) |
| 1855 | val = (_PAGE_VALID | _PAGE_SZ4MB_4V | |
| 1856 | _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_P_4V | |
| 1857 | _PAGE_EXEC_4V | _PAGE_W_4V); |
| 1858 | |
| 1859 | return val | paddr; |
| 1860 | } |
| 1861 | |
David S. Miller | c4bce90 | 2006-02-11 21:57:54 -0800 | [diff] [blame] | 1862 | /* If not locked, zap it. */ |
| 1863 | void __flush_tlb_all(void) |
| 1864 | { |
| 1865 | unsigned long pstate; |
| 1866 | int i; |
| 1867 | |
| 1868 | __asm__ __volatile__("flushw\n\t" |
| 1869 | "rdpr %%pstate, %0\n\t" |
| 1870 | "wrpr %0, %1, %%pstate" |
| 1871 | : "=r" (pstate) |
| 1872 | : "i" (PSTATE_IE)); |
| 1873 | if (tlb_type == spitfire) { |
| 1874 | for (i = 0; i < 64; i++) { |
| 1875 | /* Spitfire Errata #32 workaround */ |
| 1876 | /* NOTE: Always runs on spitfire, so no |
| 1877 | * cheetah+ page size encodings. |
| 1878 | */ |
| 1879 | __asm__ __volatile__("stxa %0, [%1] %2\n\t" |
| 1880 | "flush %%g6" |
| 1881 | : /* No outputs */ |
| 1882 | : "r" (0), |
| 1883 | "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU)); |
| 1884 | |
| 1885 | if (!(spitfire_get_dtlb_data(i) & _PAGE_L_4U)) { |
| 1886 | __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" |
| 1887 | "membar #Sync" |
| 1888 | : /* no outputs */ |
| 1889 | : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU)); |
| 1890 | spitfire_put_dtlb_data(i, 0x0UL); |
| 1891 | } |
| 1892 | |
| 1893 | /* Spitfire Errata #32 workaround */ |
| 1894 | /* NOTE: Always runs on spitfire, so no |
| 1895 | * cheetah+ page size encodings. |
| 1896 | */ |
| 1897 | __asm__ __volatile__("stxa %0, [%1] %2\n\t" |
| 1898 | "flush %%g6" |
| 1899 | : /* No outputs */ |
| 1900 | : "r" (0), |
| 1901 | "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU)); |
| 1902 | |
| 1903 | if (!(spitfire_get_itlb_data(i) & _PAGE_L_4U)) { |
| 1904 | __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" |
| 1905 | "membar #Sync" |
| 1906 | : /* no outputs */ |
| 1907 | : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU)); |
| 1908 | spitfire_put_itlb_data(i, 0x0UL); |
| 1909 | } |
| 1910 | } |
| 1911 | } else if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 1912 | cheetah_flush_dtlb_all(); |
| 1913 | cheetah_flush_itlb_all(); |
| 1914 | } |
| 1915 | __asm__ __volatile__("wrpr %0, 0, %%pstate" |
| 1916 | : : "r" (pstate)); |
| 1917 | } |
David S. Miller | 88d7079 | 2006-03-18 19:16:23 -0800 | [diff] [blame] | 1918 | |
| 1919 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 1920 | |
| 1921 | void online_page(struct page *page) |
| 1922 | { |
| 1923 | ClearPageReserved(page); |
Nick Piggin | fcab1e5 | 2006-03-23 07:48:16 +0100 | [diff] [blame] | 1924 | init_page_count(page); |
| 1925 | __free_page(page); |
David S. Miller | 88d7079 | 2006-03-18 19:16:23 -0800 | [diff] [blame] | 1926 | totalram_pages++; |
| 1927 | num_physpages++; |
| 1928 | } |
| 1929 | |
| 1930 | int remove_memory(u64 start, u64 size) |
| 1931 | { |
| 1932 | return -EINVAL; |
| 1933 | } |
| 1934 | |
| 1935 | #endif /* CONFIG_MEMORY_HOTPLUG */ |