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