1 /* $Id: init.c,v 1.209 2002/02/09 19:49:31 davem Exp $
2 * arch/sparc64/mm/init.c
4 * Copyright (C) 1996-1999 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 #include <linux/config.h>
9 #include <linux/module.h>
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>
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>
22 #include <linux/seq_file.h>
23 #include <linux/kprobes.h>
24 #include <linux/cache.h>
25 #include <linux/sort.h>
28 #include <asm/system.h>
30 #include <asm/pgalloc.h>
31 #include <asm/pgtable.h>
32 #include <asm/oplib.h>
33 #include <asm/iommu.h>
35 #include <asm/uaccess.h>
36 #include <asm/mmu_context.h>
37 #include <asm/tlbflush.h>
39 #include <asm/starfire.h>
41 #include <asm/spitfire.h>
42 #include <asm/sections.h>
44 #include <asm/hypervisor.h>
46 extern void device_scan(void);
50 static struct linux_prom64_registers pavail
[MAX_BANKS
] __initdata
;
51 static struct linux_prom64_registers pavail_rescan
[MAX_BANKS
] __initdata
;
52 static int pavail_ents __initdata
;
53 static int pavail_rescan_ents __initdata
;
55 static int cmp_p64(const void *a
, const void *b
)
57 const struct linux_prom64_registers
*x
= a
, *y
= b
;
59 if (x
->phys_addr
> y
->phys_addr
)
61 if (x
->phys_addr
< y
->phys_addr
)
66 static void __init
read_obp_memory(const char *property
,
67 struct linux_prom64_registers
*regs
,
70 int node
= prom_finddevice("/memory");
71 int prop_size
= prom_getproplen(node
, property
);
74 ents
= prop_size
/ sizeof(struct linux_prom64_registers
);
75 if (ents
> MAX_BANKS
) {
76 prom_printf("The machine has more %s property entries than "
77 "this kernel can support (%d).\n",
82 ret
= prom_getproperty(node
, property
, (char *) regs
, prop_size
);
84 prom_printf("Couldn't get %s property from /memory.\n");
90 /* Sanitize what we got from the firmware, by page aligning
93 for (i
= 0; i
< ents
; i
++) {
94 unsigned long base
, size
;
96 base
= regs
[i
].phys_addr
;
97 size
= regs
[i
].reg_size
;
100 if (base
& ~PAGE_MASK
) {
101 unsigned long new_base
= PAGE_ALIGN(base
);
103 size
-= new_base
- base
;
104 if ((long) size
< 0L)
108 regs
[i
].phys_addr
= base
;
109 regs
[i
].reg_size
= size
;
111 sort(regs
, ents
, sizeof(struct linux_prom64_registers
),
115 unsigned long *sparc64_valid_addr_bitmap __read_mostly
;
117 /* Ugly, but necessary... -DaveM */
118 unsigned long phys_base __read_mostly
;
119 unsigned long kern_base __read_mostly
;
120 unsigned long kern_size __read_mostly
;
121 unsigned long pfn_base __read_mostly
;
122 unsigned long kern_linear_pte_xor __read_mostly
;
124 /* get_new_mmu_context() uses "cache + 1". */
125 DEFINE_SPINLOCK(ctx_alloc_lock
);
126 unsigned long tlb_context_cache
= CTX_FIRST_VERSION
- 1;
127 #define CTX_BMAP_SLOTS (1UL << (CTX_NR_BITS - 6))
128 unsigned long mmu_context_bmap
[CTX_BMAP_SLOTS
];
130 /* References to special section boundaries */
131 extern char _start
[], _end
[];
133 /* Initial ramdisk setup */
134 extern unsigned long sparc_ramdisk_image64
;
135 extern unsigned int sparc_ramdisk_image
;
136 extern unsigned int sparc_ramdisk_size
;
138 struct page
*mem_map_zero __read_mostly
;
140 unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly
;
142 unsigned long sparc64_kern_pri_context __read_mostly
;
143 unsigned long sparc64_kern_pri_nuc_bits __read_mostly
;
144 unsigned long sparc64_kern_sec_context __read_mostly
;
148 kmem_cache_t
*pgtable_cache __read_mostly
;
150 static void zero_ctor(void *addr
, kmem_cache_t
*cache
, unsigned long flags
)
155 void pgtable_cache_init(void)
157 pgtable_cache
= kmem_cache_create("pgtable_cache",
158 PAGE_SIZE
, PAGE_SIZE
,
160 SLAB_MUST_HWCACHE_ALIGN
,
163 if (!pgtable_cache
) {
164 prom_printf("pgtable_cache_init(): Could not create!\n");
169 #ifdef CONFIG_DEBUG_DCFLUSH
170 atomic_t dcpage_flushes
= ATOMIC_INIT(0);
172 atomic_t dcpage_flushes_xcall
= ATOMIC_INIT(0);
176 __inline__
void flush_dcache_page_impl(struct page
*page
)
178 #ifdef CONFIG_DEBUG_DCFLUSH
179 atomic_inc(&dcpage_flushes
);
182 #ifdef DCACHE_ALIASING_POSSIBLE
183 __flush_dcache_page(page_address(page
),
184 ((tlb_type
== spitfire
) &&
185 page_mapping(page
) != NULL
));
187 if (page_mapping(page
) != NULL
&&
188 tlb_type
== spitfire
)
189 __flush_icache_page(__pa(page_address(page
)));
193 #define PG_dcache_dirty PG_arch_1
194 #define PG_dcache_cpu_shift 24
195 #define PG_dcache_cpu_mask (256 - 1)
198 #error D-cache dirty tracking and thread_info->cpu need fixing for > 256 cpus
201 #define dcache_dirty_cpu(page) \
202 (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
204 static __inline__
void set_dcache_dirty(struct page
*page
, int this_cpu
)
206 unsigned long mask
= this_cpu
;
207 unsigned long non_cpu_bits
;
209 non_cpu_bits
= ~(PG_dcache_cpu_mask
<< PG_dcache_cpu_shift
);
210 mask
= (mask
<< PG_dcache_cpu_shift
) | (1UL << PG_dcache_dirty
);
212 __asm__
__volatile__("1:\n\t"
214 "and %%g7, %1, %%g1\n\t"
215 "or %%g1, %0, %%g1\n\t"
216 "casx [%2], %%g7, %%g1\n\t"
218 "membar #StoreLoad | #StoreStore\n\t"
219 "bne,pn %%xcc, 1b\n\t"
222 : "r" (mask
), "r" (non_cpu_bits
), "r" (&page
->flags
)
226 static __inline__
void clear_dcache_dirty_cpu(struct page
*page
, unsigned long cpu
)
228 unsigned long mask
= (1UL << PG_dcache_dirty
);
230 __asm__
__volatile__("! test_and_clear_dcache_dirty\n"
233 "srlx %%g7, %4, %%g1\n\t"
234 "and %%g1, %3, %%g1\n\t"
236 "bne,pn %%icc, 2f\n\t"
237 " andn %%g7, %1, %%g1\n\t"
238 "casx [%2], %%g7, %%g1\n\t"
240 "membar #StoreLoad | #StoreStore\n\t"
241 "bne,pn %%xcc, 1b\n\t"
245 : "r" (cpu
), "r" (mask
), "r" (&page
->flags
),
246 "i" (PG_dcache_cpu_mask
),
247 "i" (PG_dcache_cpu_shift
)
251 static inline void tsb_insert(struct tsb
*ent
, unsigned long tag
, unsigned long pte
)
253 unsigned long tsb_addr
= (unsigned long) ent
;
255 if (tlb_type
== cheetah_plus
|| tlb_type
== hypervisor
)
256 tsb_addr
= __pa(tsb_addr
);
258 __tsb_insert(tsb_addr
, tag
, pte
);
261 unsigned long _PAGE_ALL_SZ_BITS __read_mostly
;
262 unsigned long _PAGE_SZBITS __read_mostly
;
264 void update_mmu_cache(struct vm_area_struct
*vma
, unsigned long address
, pte_t pte
)
266 struct mm_struct
*mm
;
269 unsigned long pg_flags
;
272 if (pfn_valid(pfn
) &&
273 (page
= pfn_to_page(pfn
), page_mapping(page
)) &&
274 ((pg_flags
= page
->flags
) & (1UL << PG_dcache_dirty
))) {
275 int cpu
= ((pg_flags
>> PG_dcache_cpu_shift
) &
277 int this_cpu
= get_cpu();
279 /* This is just to optimize away some function calls
283 flush_dcache_page_impl(page
);
285 smp_flush_dcache_page_impl(page
, cpu
);
287 clear_dcache_dirty_cpu(page
, cpu
);
293 if ((pte_val(pte
) & _PAGE_ALL_SZ_BITS
) == _PAGE_SZBITS
) {
297 tsb
= &mm
->context
.tsb
[(address
>> PAGE_SHIFT
) &
298 (mm
->context
.tsb_nentries
- 1UL)];
299 tag
= (address
>> 22UL) | CTX_HWBITS(mm
->context
) << 48UL;
300 tsb_insert(tsb
, tag
, pte_val(pte
));
304 void flush_dcache_page(struct page
*page
)
306 struct address_space
*mapping
;
309 /* Do not bother with the expensive D-cache flush if it
310 * is merely the zero page. The 'bigcore' testcase in GDB
311 * causes this case to run millions of times.
313 if (page
== ZERO_PAGE(0))
316 this_cpu
= get_cpu();
318 mapping
= page_mapping(page
);
319 if (mapping
&& !mapping_mapped(mapping
)) {
320 int dirty
= test_bit(PG_dcache_dirty
, &page
->flags
);
322 int dirty_cpu
= dcache_dirty_cpu(page
);
324 if (dirty_cpu
== this_cpu
)
326 smp_flush_dcache_page_impl(page
, dirty_cpu
);
328 set_dcache_dirty(page
, this_cpu
);
330 /* We could delay the flush for the !page_mapping
331 * case too. But that case is for exec env/arg
332 * pages and those are %99 certainly going to get
333 * faulted into the tlb (and thus flushed) anyways.
335 flush_dcache_page_impl(page
);
342 void __kprobes
flush_icache_range(unsigned long start
, unsigned long end
)
344 /* Cheetah and Hypervisor platform cpus have coherent I-cache. */
345 if (tlb_type
== spitfire
) {
348 for (kaddr
= start
; kaddr
< end
; kaddr
+= PAGE_SIZE
)
349 __flush_icache_page(__get_phys(kaddr
));
353 unsigned long page_to_pfn(struct page
*page
)
355 return (unsigned long) ((page
- mem_map
) + pfn_base
);
358 struct page
*pfn_to_page(unsigned long pfn
)
360 return (mem_map
+ (pfn
- pfn_base
));
365 printk("Mem-info:\n");
367 printk("Free swap: %6ldkB\n",
368 nr_swap_pages
<< (PAGE_SHIFT
-10));
369 printk("%ld pages of RAM\n", num_physpages
);
370 printk("%d free pages\n", nr_free_pages());
373 void mmu_info(struct seq_file
*m
)
375 if (tlb_type
== cheetah
)
376 seq_printf(m
, "MMU Type\t: Cheetah\n");
377 else if (tlb_type
== cheetah_plus
)
378 seq_printf(m
, "MMU Type\t: Cheetah+\n");
379 else if (tlb_type
== spitfire
)
380 seq_printf(m
, "MMU Type\t: Spitfire\n");
381 else if (tlb_type
== hypervisor
)
382 seq_printf(m
, "MMU Type\t: Hypervisor (sun4v)\n");
384 seq_printf(m
, "MMU Type\t: ???\n");
386 #ifdef CONFIG_DEBUG_DCFLUSH
387 seq_printf(m
, "DCPageFlushes\t: %d\n",
388 atomic_read(&dcpage_flushes
));
390 seq_printf(m
, "DCPageFlushesXC\t: %d\n",
391 atomic_read(&dcpage_flushes_xcall
));
392 #endif /* CONFIG_SMP */
393 #endif /* CONFIG_DEBUG_DCFLUSH */
396 struct linux_prom_translation
{
402 /* Exported for kernel TLB miss handling in ktlb.S */
403 struct linux_prom_translation prom_trans
[512] __read_mostly
;
404 unsigned int prom_trans_ents __read_mostly
;
406 /* Exported for SMP bootup purposes. */
407 unsigned long kern_locked_tte_data
;
409 /* The obp translations are saved based on 8k pagesize, since obp can
410 * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
411 * HI_OBP_ADDRESS range are handled in ktlb.S.
413 static inline int in_obp_range(unsigned long vaddr
)
415 return (vaddr
>= LOW_OBP_ADDRESS
&&
416 vaddr
< HI_OBP_ADDRESS
);
419 static int cmp_ptrans(const void *a
, const void *b
)
421 const struct linux_prom_translation
*x
= a
, *y
= b
;
423 if (x
->virt
> y
->virt
)
425 if (x
->virt
< y
->virt
)
430 /* Read OBP translations property into 'prom_trans[]'. */
431 static void __init
read_obp_translations(void)
433 int n
, node
, ents
, first
, last
, i
;
435 node
= prom_finddevice("/virtual-memory");
436 n
= prom_getproplen(node
, "translations");
437 if (unlikely(n
== 0 || n
== -1)) {
438 prom_printf("prom_mappings: Couldn't get size.\n");
441 if (unlikely(n
> sizeof(prom_trans
))) {
442 prom_printf("prom_mappings: Size %Zd is too big.\n", n
);
446 if ((n
= prom_getproperty(node
, "translations",
447 (char *)&prom_trans
[0],
448 sizeof(prom_trans
))) == -1) {
449 prom_printf("prom_mappings: Couldn't get property.\n");
453 n
= n
/ sizeof(struct linux_prom_translation
);
457 sort(prom_trans
, ents
, sizeof(struct linux_prom_translation
),
460 /* Now kick out all the non-OBP entries. */
461 for (i
= 0; i
< ents
; i
++) {
462 if (in_obp_range(prom_trans
[i
].virt
))
466 for (; i
< ents
; i
++) {
467 if (!in_obp_range(prom_trans
[i
].virt
))
472 for (i
= 0; i
< (last
- first
); i
++) {
473 struct linux_prom_translation
*src
= &prom_trans
[i
+ first
];
474 struct linux_prom_translation
*dest
= &prom_trans
[i
];
478 for (; i
< ents
; i
++) {
479 struct linux_prom_translation
*dest
= &prom_trans
[i
];
480 dest
->virt
= dest
->size
= dest
->data
= 0x0UL
;
483 prom_trans_ents
= last
- first
;
485 if (tlb_type
== spitfire
) {
486 /* Clear diag TTE bits. */
487 for (i
= 0; i
< prom_trans_ents
; i
++)
488 prom_trans
[i
].data
&= ~0x0003fe0000000000UL
;
492 static void __init
hypervisor_tlb_lock(unsigned long vaddr
,
496 register unsigned long func
asm("%o5");
497 register unsigned long arg0
asm("%o0");
498 register unsigned long arg1
asm("%o1");
499 register unsigned long arg2
asm("%o2");
500 register unsigned long arg3
asm("%o3");
502 func
= HV_FAST_MMU_MAP_PERM_ADDR
;
507 __asm__
__volatile__("ta 0x80"
508 : "=&r" (func
), "=&r" (arg0
),
509 "=&r" (arg1
), "=&r" (arg2
),
511 : "0" (func
), "1" (arg0
), "2" (arg1
),
512 "3" (arg2
), "4" (arg3
));
515 static unsigned long kern_large_tte(unsigned long paddr
);
517 static void __init
remap_kernel(void)
519 unsigned long phys_page
, tte_vaddr
, tte_data
;
520 int tlb_ent
= sparc64_highest_locked_tlbent();
522 tte_vaddr
= (unsigned long) KERNBASE
;
523 phys_page
= (prom_boot_mapping_phys_low
>> 22UL) << 22UL;
524 tte_data
= kern_large_tte(phys_page
);
526 kern_locked_tte_data
= tte_data
;
528 /* Now lock us into the TLBs via Hypervisor or OBP. */
529 if (tlb_type
== hypervisor
) {
530 hypervisor_tlb_lock(tte_vaddr
, tte_data
, HV_MMU_DMMU
);
531 hypervisor_tlb_lock(tte_vaddr
, tte_data
, HV_MMU_IMMU
);
533 tte_vaddr
+= 0x400000;
534 tte_data
+= 0x400000;
535 hypervisor_tlb_lock(tte_vaddr
, tte_data
, HV_MMU_DMMU
);
536 hypervisor_tlb_lock(tte_vaddr
, tte_data
, HV_MMU_IMMU
);
539 prom_dtlb_load(tlb_ent
, tte_data
, tte_vaddr
);
540 prom_itlb_load(tlb_ent
, tte_data
, tte_vaddr
);
543 prom_dtlb_load(tlb_ent
,
545 tte_vaddr
+ 0x400000);
546 prom_itlb_load(tlb_ent
,
548 tte_vaddr
+ 0x400000);
550 sparc64_highest_unlocked_tlb_ent
= tlb_ent
- 1;
552 if (tlb_type
== cheetah_plus
) {
553 sparc64_kern_pri_context
= (CTX_CHEETAH_PLUS_CTX0
|
554 CTX_CHEETAH_PLUS_NUC
);
555 sparc64_kern_pri_nuc_bits
= CTX_CHEETAH_PLUS_NUC
;
556 sparc64_kern_sec_context
= CTX_CHEETAH_PLUS_CTX0
;
561 static void __init
inherit_prom_mappings(void)
563 read_obp_translations();
565 /* Now fixup OBP's idea about where we really are mapped. */
566 prom_printf("Remapping the kernel... ");
568 prom_printf("done.\n");
571 void prom_world(int enter
)
574 set_fs((mm_segment_t
) { get_thread_current_ds() });
576 __asm__
__volatile__("flushw");
579 #ifdef DCACHE_ALIASING_POSSIBLE
580 void __flush_dcache_range(unsigned long start
, unsigned long end
)
584 if (tlb_type
== spitfire
) {
587 for (va
= start
; va
< end
; va
+= 32) {
588 spitfire_put_dcache_tag(va
& 0x3fe0, 0x0);
592 } else if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
595 for (va
= start
; va
< end
; va
+= 32)
596 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
600 "i" (ASI_DCACHE_INVALIDATE
));
603 #endif /* DCACHE_ALIASING_POSSIBLE */
605 /* Caller does TLB context flushing on local CPU if necessary.
606 * The caller also ensures that CTX_VALID(mm->context) is false.
608 * We must be careful about boundary cases so that we never
609 * let the user have CTX 0 (nucleus) or we ever use a CTX
610 * version of zero (and thus NO_CONTEXT would not be caught
611 * by version mis-match tests in mmu_context.h).
613 void get_new_mmu_context(struct mm_struct
*mm
)
615 unsigned long ctx
, new_ctx
;
616 unsigned long orig_pgsz_bits
;
619 spin_lock(&ctx_alloc_lock
);
620 orig_pgsz_bits
= (mm
->context
.sparc64_ctx_val
& CTX_PGSZ_MASK
);
621 ctx
= (tlb_context_cache
+ 1) & CTX_NR_MASK
;
622 new_ctx
= find_next_zero_bit(mmu_context_bmap
, 1 << CTX_NR_BITS
, ctx
);
623 if (new_ctx
>= (1 << CTX_NR_BITS
)) {
624 new_ctx
= find_next_zero_bit(mmu_context_bmap
, ctx
, 1);
625 if (new_ctx
>= ctx
) {
627 new_ctx
= (tlb_context_cache
& CTX_VERSION_MASK
) +
630 new_ctx
= CTX_FIRST_VERSION
;
632 /* Don't call memset, for 16 entries that's just
635 mmu_context_bmap
[0] = 3;
636 mmu_context_bmap
[1] = 0;
637 mmu_context_bmap
[2] = 0;
638 mmu_context_bmap
[3] = 0;
639 for (i
= 4; i
< CTX_BMAP_SLOTS
; i
+= 4) {
640 mmu_context_bmap
[i
+ 0] = 0;
641 mmu_context_bmap
[i
+ 1] = 0;
642 mmu_context_bmap
[i
+ 2] = 0;
643 mmu_context_bmap
[i
+ 3] = 0;
648 mmu_context_bmap
[new_ctx
>>6] |= (1UL << (new_ctx
& 63));
649 new_ctx
|= (tlb_context_cache
& CTX_VERSION_MASK
);
651 tlb_context_cache
= new_ctx
;
652 mm
->context
.sparc64_ctx_val
= new_ctx
| orig_pgsz_bits
;
653 spin_unlock(&ctx_alloc_lock
);
656 void sparc_ultra_dump_itlb(void)
660 if (tlb_type
== spitfire
) {
661 printk ("Contents of itlb: ");
662 for (slot
= 0; slot
< 14; slot
++) printk (" ");
663 printk ("%2x:%016lx,%016lx\n",
665 spitfire_get_itlb_tag(0), spitfire_get_itlb_data(0));
666 for (slot
= 1; slot
< 64; slot
+=3) {
667 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
669 spitfire_get_itlb_tag(slot
), spitfire_get_itlb_data(slot
),
671 spitfire_get_itlb_tag(slot
+1), spitfire_get_itlb_data(slot
+1),
673 spitfire_get_itlb_tag(slot
+2), spitfire_get_itlb_data(slot
+2));
675 } else if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
676 printk ("Contents of itlb0:\n");
677 for (slot
= 0; slot
< 16; slot
+=2) {
678 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
680 cheetah_get_litlb_tag(slot
), cheetah_get_litlb_data(slot
),
682 cheetah_get_litlb_tag(slot
+1), cheetah_get_litlb_data(slot
+1));
684 printk ("Contents of itlb2:\n");
685 for (slot
= 0; slot
< 128; slot
+=2) {
686 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
688 cheetah_get_itlb_tag(slot
), cheetah_get_itlb_data(slot
),
690 cheetah_get_itlb_tag(slot
+1), cheetah_get_itlb_data(slot
+1));
695 void sparc_ultra_dump_dtlb(void)
699 if (tlb_type
== spitfire
) {
700 printk ("Contents of dtlb: ");
701 for (slot
= 0; slot
< 14; slot
++) printk (" ");
702 printk ("%2x:%016lx,%016lx\n", 0,
703 spitfire_get_dtlb_tag(0), spitfire_get_dtlb_data(0));
704 for (slot
= 1; slot
< 64; slot
+=3) {
705 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
707 spitfire_get_dtlb_tag(slot
), spitfire_get_dtlb_data(slot
),
709 spitfire_get_dtlb_tag(slot
+1), spitfire_get_dtlb_data(slot
+1),
711 spitfire_get_dtlb_tag(slot
+2), spitfire_get_dtlb_data(slot
+2));
713 } else if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
714 printk ("Contents of dtlb0:\n");
715 for (slot
= 0; slot
< 16; slot
+=2) {
716 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
718 cheetah_get_ldtlb_tag(slot
), cheetah_get_ldtlb_data(slot
),
720 cheetah_get_ldtlb_tag(slot
+1), cheetah_get_ldtlb_data(slot
+1));
722 printk ("Contents of dtlb2:\n");
723 for (slot
= 0; slot
< 512; slot
+=2) {
724 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
726 cheetah_get_dtlb_tag(slot
, 2), cheetah_get_dtlb_data(slot
, 2),
728 cheetah_get_dtlb_tag(slot
+1, 2), cheetah_get_dtlb_data(slot
+1, 2));
730 if (tlb_type
== cheetah_plus
) {
731 printk ("Contents of dtlb3:\n");
732 for (slot
= 0; slot
< 512; slot
+=2) {
733 printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
735 cheetah_get_dtlb_tag(slot
, 3), cheetah_get_dtlb_data(slot
, 3),
737 cheetah_get_dtlb_tag(slot
+1, 3), cheetah_get_dtlb_data(slot
+1, 3));
743 extern unsigned long cmdline_memory_size
;
745 unsigned long __init
bootmem_init(unsigned long *pages_avail
)
747 unsigned long bootmap_size
, start_pfn
, end_pfn
;
748 unsigned long end_of_phys_memory
= 0UL;
749 unsigned long bootmap_pfn
, bytes_avail
, size
;
752 #ifdef CONFIG_DEBUG_BOOTMEM
753 prom_printf("bootmem_init: Scan pavail, ");
757 for (i
= 0; i
< pavail_ents
; i
++) {
758 end_of_phys_memory
= pavail
[i
].phys_addr
+
760 bytes_avail
+= pavail
[i
].reg_size
;
761 if (cmdline_memory_size
) {
762 if (bytes_avail
> cmdline_memory_size
) {
763 unsigned long slack
= bytes_avail
- cmdline_memory_size
;
765 bytes_avail
-= slack
;
766 end_of_phys_memory
-= slack
;
768 pavail
[i
].reg_size
-= slack
;
769 if ((long)pavail
[i
].reg_size
<= 0L) {
770 pavail
[i
].phys_addr
= 0xdeadbeefUL
;
771 pavail
[i
].reg_size
= 0UL;
774 pavail
[i
+1].reg_size
= 0Ul;
775 pavail
[i
+1].phys_addr
= 0xdeadbeefUL
;
783 *pages_avail
= bytes_avail
>> PAGE_SHIFT
;
785 /* Start with page aligned address of last symbol in kernel
786 * image. The kernel is hard mapped below PAGE_OFFSET in a
787 * 4MB locked TLB translation.
789 start_pfn
= PAGE_ALIGN(kern_base
+ kern_size
) >> PAGE_SHIFT
;
791 bootmap_pfn
= start_pfn
;
793 end_pfn
= end_of_phys_memory
>> PAGE_SHIFT
;
795 #ifdef CONFIG_BLK_DEV_INITRD
796 /* Now have to check initial ramdisk, so that bootmap does not overwrite it */
797 if (sparc_ramdisk_image
|| sparc_ramdisk_image64
) {
798 unsigned long ramdisk_image
= sparc_ramdisk_image
?
799 sparc_ramdisk_image
: sparc_ramdisk_image64
;
800 if (ramdisk_image
>= (unsigned long)_end
- 2 * PAGE_SIZE
)
801 ramdisk_image
-= KERNBASE
;
802 initrd_start
= ramdisk_image
+ phys_base
;
803 initrd_end
= initrd_start
+ sparc_ramdisk_size
;
804 if (initrd_end
> end_of_phys_memory
) {
805 printk(KERN_CRIT
"initrd extends beyond end of memory "
806 "(0x%016lx > 0x%016lx)\ndisabling initrd\n",
807 initrd_end
, end_of_phys_memory
);
811 if (initrd_start
>= (start_pfn
<< PAGE_SHIFT
) &&
812 initrd_start
< (start_pfn
<< PAGE_SHIFT
) + 2 * PAGE_SIZE
)
813 bootmap_pfn
= PAGE_ALIGN (initrd_end
) >> PAGE_SHIFT
;
817 /* Initialize the boot-time allocator. */
818 max_pfn
= max_low_pfn
= end_pfn
;
819 min_low_pfn
= pfn_base
;
821 #ifdef CONFIG_DEBUG_BOOTMEM
822 prom_printf("init_bootmem(min[%lx], bootmap[%lx], max[%lx])\n",
823 min_low_pfn
, bootmap_pfn
, max_low_pfn
);
825 bootmap_size
= init_bootmem_node(NODE_DATA(0), bootmap_pfn
, pfn_base
, end_pfn
);
827 /* Now register the available physical memory with the
830 for (i
= 0; i
< pavail_ents
; i
++) {
831 #ifdef CONFIG_DEBUG_BOOTMEM
832 prom_printf("free_bootmem(pavail:%d): base[%lx] size[%lx]\n",
833 i
, pavail
[i
].phys_addr
, pavail
[i
].reg_size
);
835 free_bootmem(pavail
[i
].phys_addr
, pavail
[i
].reg_size
);
838 #ifdef CONFIG_BLK_DEV_INITRD
840 size
= initrd_end
- initrd_start
;
842 /* Resert the initrd image area. */
843 #ifdef CONFIG_DEBUG_BOOTMEM
844 prom_printf("reserve_bootmem(initrd): base[%llx] size[%lx]\n",
845 initrd_start
, initrd_end
);
847 reserve_bootmem(initrd_start
, size
);
848 *pages_avail
-= PAGE_ALIGN(size
) >> PAGE_SHIFT
;
850 initrd_start
+= PAGE_OFFSET
;
851 initrd_end
+= PAGE_OFFSET
;
854 /* Reserve the kernel text/data/bss. */
855 #ifdef CONFIG_DEBUG_BOOTMEM
856 prom_printf("reserve_bootmem(kernel): base[%lx] size[%lx]\n", kern_base
, kern_size
);
858 reserve_bootmem(kern_base
, kern_size
);
859 *pages_avail
-= PAGE_ALIGN(kern_size
) >> PAGE_SHIFT
;
861 /* Reserve the bootmem map. We do not account for it
862 * in pages_avail because we will release that memory
863 * in free_all_bootmem.
866 #ifdef CONFIG_DEBUG_BOOTMEM
867 prom_printf("reserve_bootmem(bootmap): base[%lx] size[%lx]\n",
868 (bootmap_pfn
<< PAGE_SHIFT
), size
);
870 reserve_bootmem((bootmap_pfn
<< PAGE_SHIFT
), size
);
871 *pages_avail
-= PAGE_ALIGN(size
) >> PAGE_SHIFT
;
876 #ifdef CONFIG_DEBUG_PAGEALLOC
877 static unsigned long kernel_map_range(unsigned long pstart
, unsigned long pend
, pgprot_t prot
)
879 unsigned long vstart
= PAGE_OFFSET
+ pstart
;
880 unsigned long vend
= PAGE_OFFSET
+ pend
;
881 unsigned long alloc_bytes
= 0UL;
883 if ((vstart
& ~PAGE_MASK
) || (vend
& ~PAGE_MASK
)) {
884 prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
889 while (vstart
< vend
) {
890 unsigned long this_end
, paddr
= __pa(vstart
);
891 pgd_t
*pgd
= pgd_offset_k(vstart
);
896 pud
= pud_offset(pgd
, vstart
);
897 if (pud_none(*pud
)) {
900 new = __alloc_bootmem(PAGE_SIZE
, PAGE_SIZE
, PAGE_SIZE
);
901 alloc_bytes
+= PAGE_SIZE
;
902 pud_populate(&init_mm
, pud
, new);
905 pmd
= pmd_offset(pud
, vstart
);
906 if (!pmd_present(*pmd
)) {
909 new = __alloc_bootmem(PAGE_SIZE
, PAGE_SIZE
, PAGE_SIZE
);
910 alloc_bytes
+= PAGE_SIZE
;
911 pmd_populate_kernel(&init_mm
, pmd
, new);
914 pte
= pte_offset_kernel(pmd
, vstart
);
915 this_end
= (vstart
+ PMD_SIZE
) & PMD_MASK
;
919 while (vstart
< this_end
) {
920 pte_val(*pte
) = (paddr
| pgprot_val(prot
));
931 static struct linux_prom64_registers pall
[MAX_BANKS
] __initdata
;
932 static int pall_ents __initdata
;
934 extern unsigned int kvmap_linear_patch
[1];
936 static void __init
kernel_physical_mapping_init(void)
938 unsigned long i
, mem_alloced
= 0UL;
940 read_obp_memory("reg", &pall
[0], &pall_ents
);
942 for (i
= 0; i
< pall_ents
; i
++) {
943 unsigned long phys_start
, phys_end
;
945 phys_start
= pall
[i
].phys_addr
;
946 phys_end
= phys_start
+ pall
[i
].reg_size
;
947 mem_alloced
+= kernel_map_range(phys_start
, phys_end
,
951 printk("Allocated %ld bytes for kernel page tables.\n",
954 kvmap_linear_patch
[0] = 0x01000000; /* nop */
955 flushi(&kvmap_linear_patch
[0]);
960 void kernel_map_pages(struct page
*page
, int numpages
, int enable
)
962 unsigned long phys_start
= page_to_pfn(page
) << PAGE_SHIFT
;
963 unsigned long phys_end
= phys_start
+ (numpages
* PAGE_SIZE
);
965 kernel_map_range(phys_start
, phys_end
,
966 (enable
? PAGE_KERNEL
: __pgprot(0)));
968 flush_tsb_kernel_range(PAGE_OFFSET
+ phys_start
,
969 PAGE_OFFSET
+ phys_end
);
971 /* we should perform an IPI and flush all tlbs,
972 * but that can deadlock->flush only current cpu.
974 __flush_tlb_kernel_range(PAGE_OFFSET
+ phys_start
,
975 PAGE_OFFSET
+ phys_end
);
979 unsigned long __init
find_ecache_flush_span(unsigned long size
)
983 for (i
= 0; i
< pavail_ents
; i
++) {
984 if (pavail
[i
].reg_size
>= size
)
985 return pavail
[i
].phys_addr
;
991 static void __init
tsb_phys_patch(void)
993 struct tsb_ldquad_phys_patch_entry
*pquad
;
994 struct tsb_phys_patch_entry
*p
;
996 pquad
= &__tsb_ldquad_phys_patch
;
997 while (pquad
< &__tsb_ldquad_phys_patch_end
) {
998 unsigned long addr
= pquad
->addr
;
1000 if (tlb_type
== hypervisor
)
1001 *(unsigned int *) addr
= pquad
->sun4v_insn
;
1003 *(unsigned int *) addr
= pquad
->sun4u_insn
;
1005 __asm__
__volatile__("flush %0"
1012 p
= &__tsb_phys_patch
;
1013 while (p
< &__tsb_phys_patch_end
) {
1014 unsigned long addr
= p
->addr
;
1016 *(unsigned int *) addr
= p
->insn
;
1018 __asm__
__volatile__("flush %0"
1026 /* Don't mark as init, we give this to the Hypervisor. */
1027 static struct hv_tsb_descr ktsb_descr
[2];
1028 extern struct tsb swapper_tsb
[KERNEL_TSB_NENTRIES
];
1030 static void __init
sun4v_ktsb_init(void)
1032 unsigned long ktsb_pa
;
1034 ktsb_pa
= kern_base
+ ((unsigned long)&swapper_tsb
[0] - KERNBASE
);
1036 switch (PAGE_SIZE
) {
1039 ktsb_descr
[0].pgsz_idx
= HV_PGSZ_IDX_8K
;
1040 ktsb_descr
[0].pgsz_mask
= HV_PGSZ_MASK_8K
;
1044 ktsb_descr
[0].pgsz_idx
= HV_PGSZ_IDX_64K
;
1045 ktsb_descr
[0].pgsz_mask
= HV_PGSZ_MASK_64K
;
1049 ktsb_descr
[0].pgsz_idx
= HV_PGSZ_IDX_512K
;
1050 ktsb_descr
[0].pgsz_mask
= HV_PGSZ_MASK_512K
;
1053 case 4 * 1024 * 1024:
1054 ktsb_descr
[0].pgsz_idx
= HV_PGSZ_IDX_4MB
;
1055 ktsb_descr
[0].pgsz_mask
= HV_PGSZ_MASK_4MB
;
1059 ktsb_descr
[0].assoc
= 1;
1060 ktsb_descr
[0].num_ttes
= KERNEL_TSB_NENTRIES
;
1061 ktsb_descr
[0].ctx_idx
= 0;
1062 ktsb_descr
[0].tsb_base
= ktsb_pa
;
1063 ktsb_descr
[0].resv
= 0;
1065 /* XXX When we have a kernel large page size TSB, describe
1066 * XXX it in ktsb_descr[1] here.
1070 void __cpuinit
sun4v_ktsb_register(void)
1072 register unsigned long func
asm("%o5");
1073 register unsigned long arg0
asm("%o0");
1074 register unsigned long arg1
asm("%o1");
1077 pa
= kern_base
+ ((unsigned long)&ktsb_descr
[0] - KERNBASE
);
1079 func
= HV_FAST_MMU_TSB_CTX0
;
1080 /* XXX set arg0 to 2 when we use ktsb_descr[1], see above XXX */
1083 __asm__
__volatile__("ta %6"
1084 : "=&r" (func
), "=&r" (arg0
), "=&r" (arg1
)
1085 : "0" (func
), "1" (arg0
), "2" (arg1
),
1086 "i" (HV_FAST_TRAP
));
1089 /* paging_init() sets up the page tables */
1091 extern void cheetah_ecache_flush_init(void);
1092 extern void sun4v_patch_tlb_handlers(void);
1094 static unsigned long last_valid_pfn
;
1095 pgd_t swapper_pg_dir
[2048];
1097 static void sun4u_pgprot_init(void);
1098 static void sun4v_pgprot_init(void);
1100 void __init
paging_init(void)
1102 unsigned long end_pfn
, pages_avail
, shift
;
1103 unsigned long real_end
, i
;
1105 kern_base
= (prom_boot_mapping_phys_low
>> 22UL) << 22UL;
1106 kern_size
= (unsigned long)&_end
- (unsigned long)KERNBASE
;
1108 if (tlb_type
== hypervisor
)
1109 sun4v_pgprot_init();
1111 sun4u_pgprot_init();
1113 if (tlb_type
== cheetah_plus
||
1114 tlb_type
== hypervisor
)
1117 if (tlb_type
== hypervisor
) {
1118 sun4v_patch_tlb_handlers();
1122 /* Find available physical memory... */
1123 read_obp_memory("available", &pavail
[0], &pavail_ents
);
1125 phys_base
= 0xffffffffffffffffUL
;
1126 for (i
= 0; i
< pavail_ents
; i
++)
1127 phys_base
= min(phys_base
, pavail
[i
].phys_addr
);
1129 pfn_base
= phys_base
>> PAGE_SHIFT
;
1131 set_bit(0, mmu_context_bmap
);
1133 shift
= kern_base
+ PAGE_OFFSET
- ((unsigned long)KERNBASE
);
1135 real_end
= (unsigned long)_end
;
1136 if ((real_end
> ((unsigned long)KERNBASE
+ 0x400000)))
1138 if ((real_end
> ((unsigned long)KERNBASE
+ 0x800000))) {
1139 prom_printf("paging_init: Kernel > 8MB, too large.\n");
1143 /* Set kernel pgd to upper alias so physical page computations
1146 init_mm
.pgd
+= ((shift
) / (sizeof(pgd_t
)));
1148 memset(swapper_low_pmd_dir
, 0, sizeof(swapper_low_pmd_dir
));
1150 /* Now can init the kernel/bad page tables. */
1151 pud_set(pud_offset(&swapper_pg_dir
[0], 0),
1152 swapper_low_pmd_dir
+ (shift
/ sizeof(pgd_t
)));
1154 inherit_prom_mappings();
1156 /* Ok, we can use our TLB miss and window trap handlers safely. */
1161 if (tlb_type
== hypervisor
)
1162 sun4v_ktsb_register();
1164 /* Setup bootmem... */
1166 last_valid_pfn
= end_pfn
= bootmem_init(&pages_avail
);
1168 #ifdef CONFIG_DEBUG_PAGEALLOC
1169 kernel_physical_mapping_init();
1173 unsigned long zones_size
[MAX_NR_ZONES
];
1174 unsigned long zholes_size
[MAX_NR_ZONES
];
1175 unsigned long npages
;
1178 for (znum
= 0; znum
< MAX_NR_ZONES
; znum
++)
1179 zones_size
[znum
] = zholes_size
[znum
] = 0;
1181 npages
= end_pfn
- pfn_base
;
1182 zones_size
[ZONE_DMA
] = npages
;
1183 zholes_size
[ZONE_DMA
] = npages
- pages_avail
;
1185 free_area_init_node(0, &contig_page_data
, zones_size
,
1186 phys_base
>> PAGE_SHIFT
, zholes_size
);
1192 static void __init
taint_real_pages(void)
1196 read_obp_memory("available", &pavail_rescan
[0], &pavail_rescan_ents
);
1198 /* Find changes discovered in the physmem available rescan and
1199 * reserve the lost portions in the bootmem maps.
1201 for (i
= 0; i
< pavail_ents
; i
++) {
1202 unsigned long old_start
, old_end
;
1204 old_start
= pavail
[i
].phys_addr
;
1205 old_end
= old_start
+
1207 while (old_start
< old_end
) {
1210 for (n
= 0; pavail_rescan_ents
; n
++) {
1211 unsigned long new_start
, new_end
;
1213 new_start
= pavail_rescan
[n
].phys_addr
;
1214 new_end
= new_start
+
1215 pavail_rescan
[n
].reg_size
;
1217 if (new_start
<= old_start
&&
1218 new_end
>= (old_start
+ PAGE_SIZE
)) {
1219 set_bit(old_start
>> 22,
1220 sparc64_valid_addr_bitmap
);
1224 reserve_bootmem(old_start
, PAGE_SIZE
);
1227 old_start
+= PAGE_SIZE
;
1232 void __init
mem_init(void)
1234 unsigned long codepages
, datapages
, initpages
;
1235 unsigned long addr
, last
;
1238 i
= last_valid_pfn
>> ((22 - PAGE_SHIFT
) + 6);
1240 sparc64_valid_addr_bitmap
= (unsigned long *) alloc_bootmem(i
<< 3);
1241 if (sparc64_valid_addr_bitmap
== NULL
) {
1242 prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
1245 memset(sparc64_valid_addr_bitmap
, 0, i
<< 3);
1247 addr
= PAGE_OFFSET
+ kern_base
;
1248 last
= PAGE_ALIGN(kern_size
) + addr
;
1249 while (addr
< last
) {
1250 set_bit(__pa(addr
) >> 22, sparc64_valid_addr_bitmap
);
1256 max_mapnr
= last_valid_pfn
- pfn_base
;
1257 high_memory
= __va(last_valid_pfn
<< PAGE_SHIFT
);
1259 #ifdef CONFIG_DEBUG_BOOTMEM
1260 prom_printf("mem_init: Calling free_all_bootmem().\n");
1262 totalram_pages
= num_physpages
= free_all_bootmem() - 1;
1265 * Set up the zero page, mark it reserved, so that page count
1266 * is not manipulated when freeing the page from user ptes.
1268 mem_map_zero
= alloc_pages(GFP_KERNEL
|__GFP_ZERO
, 0);
1269 if (mem_map_zero
== NULL
) {
1270 prom_printf("paging_init: Cannot alloc zero page.\n");
1273 SetPageReserved(mem_map_zero
);
1275 codepages
= (((unsigned long) _etext
) - ((unsigned long) _start
));
1276 codepages
= PAGE_ALIGN(codepages
) >> PAGE_SHIFT
;
1277 datapages
= (((unsigned long) _edata
) - ((unsigned long) _etext
));
1278 datapages
= PAGE_ALIGN(datapages
) >> PAGE_SHIFT
;
1279 initpages
= (((unsigned long) __init_end
) - ((unsigned long) __init_begin
));
1280 initpages
= PAGE_ALIGN(initpages
) >> PAGE_SHIFT
;
1282 printk("Memory: %uk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n",
1283 nr_free_pages() << (PAGE_SHIFT
-10),
1284 codepages
<< (PAGE_SHIFT
-10),
1285 datapages
<< (PAGE_SHIFT
-10),
1286 initpages
<< (PAGE_SHIFT
-10),
1287 PAGE_OFFSET
, (last_valid_pfn
<< PAGE_SHIFT
));
1289 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
)
1290 cheetah_ecache_flush_init();
1293 void free_initmem(void)
1295 unsigned long addr
, initend
;
1298 * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
1300 addr
= PAGE_ALIGN((unsigned long)(__init_begin
));
1301 initend
= (unsigned long)(__init_end
) & PAGE_MASK
;
1302 for (; addr
< initend
; addr
+= PAGE_SIZE
) {
1307 ((unsigned long) __va(kern_base
)) -
1308 ((unsigned long) KERNBASE
));
1309 memset((void *)addr
, 0xcc, PAGE_SIZE
);
1310 p
= virt_to_page(page
);
1312 ClearPageReserved(p
);
1313 set_page_count(p
, 1);
1320 #ifdef CONFIG_BLK_DEV_INITRD
1321 void free_initrd_mem(unsigned long start
, unsigned long end
)
1324 printk ("Freeing initrd memory: %ldk freed\n", (end
- start
) >> 10);
1325 for (; start
< end
; start
+= PAGE_SIZE
) {
1326 struct page
*p
= virt_to_page(start
);
1328 ClearPageReserved(p
);
1329 set_page_count(p
, 1);
1337 #define _PAGE_CACHE_4U (_PAGE_CP_4U | _PAGE_CV_4U)
1338 #define _PAGE_CACHE_4V (_PAGE_CP_4V | _PAGE_CV_4V)
1339 #define __DIRTY_BITS_4U (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U)
1340 #define __DIRTY_BITS_4V (_PAGE_MODIFIED_4V | _PAGE_WRITE_4V | _PAGE_W_4V)
1341 #define __ACCESS_BITS_4U (_PAGE_ACCESSED_4U | _PAGE_READ_4U | _PAGE_R)
1342 #define __ACCESS_BITS_4V (_PAGE_ACCESSED_4V | _PAGE_READ_4V | _PAGE_R)
1344 pgprot_t PAGE_KERNEL __read_mostly
;
1345 EXPORT_SYMBOL(PAGE_KERNEL
);
1347 pgprot_t PAGE_KERNEL_LOCKED __read_mostly
;
1348 pgprot_t PAGE_COPY __read_mostly
;
1349 pgprot_t PAGE_EXEC __read_mostly
;
1350 unsigned long pg_iobits __read_mostly
;
1352 unsigned long _PAGE_IE __read_mostly
;
1353 unsigned long _PAGE_E __read_mostly
;
1354 unsigned long _PAGE_CACHE __read_mostly
;
1356 static void prot_init_common(unsigned long page_none
,
1357 unsigned long page_shared
,
1358 unsigned long page_copy
,
1359 unsigned long page_readonly
,
1360 unsigned long page_exec_bit
)
1362 PAGE_COPY
= __pgprot(page_copy
);
1364 protection_map
[0x0] = __pgprot(page_none
);
1365 protection_map
[0x1] = __pgprot(page_readonly
& ~page_exec_bit
);
1366 protection_map
[0x2] = __pgprot(page_copy
& ~page_exec_bit
);
1367 protection_map
[0x3] = __pgprot(page_copy
& ~page_exec_bit
);
1368 protection_map
[0x4] = __pgprot(page_readonly
);
1369 protection_map
[0x5] = __pgprot(page_readonly
);
1370 protection_map
[0x6] = __pgprot(page_copy
);
1371 protection_map
[0x7] = __pgprot(page_copy
);
1372 protection_map
[0x8] = __pgprot(page_none
);
1373 protection_map
[0x9] = __pgprot(page_readonly
& ~page_exec_bit
);
1374 protection_map
[0xa] = __pgprot(page_shared
& ~page_exec_bit
);
1375 protection_map
[0xb] = __pgprot(page_shared
& ~page_exec_bit
);
1376 protection_map
[0xc] = __pgprot(page_readonly
);
1377 protection_map
[0xd] = __pgprot(page_readonly
);
1378 protection_map
[0xe] = __pgprot(page_shared
);
1379 protection_map
[0xf] = __pgprot(page_shared
);
1382 static void __init
sun4u_pgprot_init(void)
1384 unsigned long page_none
, page_shared
, page_copy
, page_readonly
;
1385 unsigned long page_exec_bit
;
1387 PAGE_KERNEL
= __pgprot (_PAGE_PRESENT_4U
| _PAGE_VALID
|
1388 _PAGE_CACHE_4U
| _PAGE_P_4U
|
1389 __ACCESS_BITS_4U
| __DIRTY_BITS_4U
|
1391 PAGE_KERNEL_LOCKED
= __pgprot (_PAGE_PRESENT_4U
| _PAGE_VALID
|
1392 _PAGE_CACHE_4U
| _PAGE_P_4U
|
1393 __ACCESS_BITS_4U
| __DIRTY_BITS_4U
|
1394 _PAGE_EXEC_4U
| _PAGE_L_4U
);
1395 PAGE_EXEC
= __pgprot(_PAGE_EXEC_4U
);
1397 _PAGE_IE
= _PAGE_IE_4U
;
1398 _PAGE_E
= _PAGE_E_4U
;
1399 _PAGE_CACHE
= _PAGE_CACHE_4U
;
1401 pg_iobits
= (_PAGE_VALID
| _PAGE_PRESENT_4U
| __DIRTY_BITS_4U
|
1402 __ACCESS_BITS_4U
| _PAGE_E_4U
);
1404 kern_linear_pte_xor
= (_PAGE_VALID
| _PAGE_SZ4MB_4U
) ^
1406 kern_linear_pte_xor
|= (_PAGE_CP_4U
| _PAGE_CV_4U
|
1407 _PAGE_P_4U
| _PAGE_W_4U
);
1409 _PAGE_SZBITS
= _PAGE_SZBITS_4U
;
1410 _PAGE_ALL_SZ_BITS
= (_PAGE_SZ4MB_4U
| _PAGE_SZ512K_4U
|
1411 _PAGE_SZ64K_4U
| _PAGE_SZ8K_4U
|
1412 _PAGE_SZ32MB_4U
| _PAGE_SZ256MB_4U
);
1415 page_none
= _PAGE_PRESENT_4U
| _PAGE_ACCESSED_4U
| _PAGE_CACHE_4U
;
1416 page_shared
= (_PAGE_VALID
| _PAGE_PRESENT_4U
| _PAGE_CACHE_4U
|
1417 __ACCESS_BITS_4U
| _PAGE_WRITE_4U
| _PAGE_EXEC_4U
);
1418 page_copy
= (_PAGE_VALID
| _PAGE_PRESENT_4U
| _PAGE_CACHE_4U
|
1419 __ACCESS_BITS_4U
| _PAGE_EXEC_4U
);
1420 page_readonly
= (_PAGE_VALID
| _PAGE_PRESENT_4U
| _PAGE_CACHE_4U
|
1421 __ACCESS_BITS_4U
| _PAGE_EXEC_4U
);
1423 page_exec_bit
= _PAGE_EXEC_4U
;
1425 prot_init_common(page_none
, page_shared
, page_copy
, page_readonly
,
1429 static void __init
sun4v_pgprot_init(void)
1431 unsigned long page_none
, page_shared
, page_copy
, page_readonly
;
1432 unsigned long page_exec_bit
;
1434 PAGE_KERNEL
= __pgprot (_PAGE_PRESENT_4V
| _PAGE_VALID
|
1435 _PAGE_CACHE_4V
| _PAGE_P_4V
|
1436 __ACCESS_BITS_4V
| __DIRTY_BITS_4V
|
1438 PAGE_KERNEL_LOCKED
= PAGE_KERNEL
;
1439 PAGE_EXEC
= __pgprot(_PAGE_EXEC_4V
);
1441 _PAGE_IE
= _PAGE_IE_4V
;
1442 _PAGE_E
= _PAGE_E_4V
;
1443 _PAGE_CACHE
= _PAGE_CACHE_4V
;
1445 kern_linear_pte_xor
= (_PAGE_VALID
| _PAGE_SZ4MB_4V
) ^
1447 kern_linear_pte_xor
|= (_PAGE_CP_4V
| _PAGE_CV_4V
|
1448 _PAGE_P_4V
| _PAGE_W_4V
);
1450 pg_iobits
= (_PAGE_VALID
| _PAGE_PRESENT_4V
| __DIRTY_BITS_4V
|
1451 __ACCESS_BITS_4V
| _PAGE_E_4V
);
1453 _PAGE_SZBITS
= _PAGE_SZBITS_4V
;
1454 _PAGE_ALL_SZ_BITS
= (_PAGE_SZ16GB_4V
| _PAGE_SZ2GB_4V
|
1455 _PAGE_SZ256MB_4V
| _PAGE_SZ32MB_4V
|
1456 _PAGE_SZ4MB_4V
| _PAGE_SZ512K_4V
|
1457 _PAGE_SZ64K_4V
| _PAGE_SZ8K_4V
);
1459 page_none
= _PAGE_PRESENT_4V
| _PAGE_ACCESSED_4V
| _PAGE_CACHE_4V
;
1460 page_shared
= (_PAGE_VALID
| _PAGE_PRESENT_4V
| _PAGE_CACHE_4V
|
1461 __ACCESS_BITS_4V
| _PAGE_WRITE_4V
| _PAGE_EXEC_4V
);
1462 page_copy
= (_PAGE_VALID
| _PAGE_PRESENT_4V
| _PAGE_CACHE_4V
|
1463 __ACCESS_BITS_4V
| _PAGE_EXEC_4V
);
1464 page_readonly
= (_PAGE_VALID
| _PAGE_PRESENT_4V
| _PAGE_CACHE_4V
|
1465 __ACCESS_BITS_4V
| _PAGE_EXEC_4V
);
1467 page_exec_bit
= _PAGE_EXEC_4V
;
1469 prot_init_common(page_none
, page_shared
, page_copy
, page_readonly
,
1473 unsigned long pte_sz_bits(unsigned long sz
)
1475 if (tlb_type
== hypervisor
) {
1479 return _PAGE_SZ8K_4V
;
1481 return _PAGE_SZ64K_4V
;
1483 return _PAGE_SZ512K_4V
;
1484 case 4 * 1024 * 1024:
1485 return _PAGE_SZ4MB_4V
;
1491 return _PAGE_SZ8K_4U
;
1493 return _PAGE_SZ64K_4U
;
1495 return _PAGE_SZ512K_4U
;
1496 case 4 * 1024 * 1024:
1497 return _PAGE_SZ4MB_4U
;
1502 pte_t
mk_pte_io(unsigned long page
, pgprot_t prot
, int space
, unsigned long page_size
)
1506 pte_val(pte
) = page
| pgprot_val(pgprot_noncached(prot
));
1507 pte_val(pte
) |= (((unsigned long)space
) << 32);
1508 pte_val(pte
) |= pte_sz_bits(page_size
);
1513 static unsigned long kern_large_tte(unsigned long paddr
)
1517 val
= (_PAGE_VALID
| _PAGE_SZ4MB_4U
|
1518 _PAGE_CP_4U
| _PAGE_CV_4U
| _PAGE_P_4U
|
1519 _PAGE_EXEC_4U
| _PAGE_L_4U
| _PAGE_W_4U
);
1520 if (tlb_type
== hypervisor
)
1521 val
= (_PAGE_VALID
| _PAGE_SZ4MB_4V
|
1522 _PAGE_CP_4V
| _PAGE_CV_4V
| _PAGE_P_4V
|
1523 _PAGE_EXEC_4V
| _PAGE_W_4V
);
1529 * Translate PROM's mapping we capture at boot time into physical address.
1530 * The second parameter is only set from prom_callback() invocations.
1532 unsigned long prom_virt_to_phys(unsigned long promva
, int *error
)
1537 mask
= _PAGE_PADDR_4U
;
1538 if (tlb_type
== hypervisor
)
1539 mask
= _PAGE_PADDR_4V
;
1541 for (i
= 0; i
< prom_trans_ents
; i
++) {
1542 struct linux_prom_translation
*p
= &prom_trans
[i
];
1544 if (promva
>= p
->virt
&&
1545 promva
< (p
->virt
+ p
->size
)) {
1546 unsigned long base
= p
->data
& mask
;
1550 return base
+ (promva
& (8192 - 1));
1558 /* XXX We should kill off this ugly thing at so me point. XXX */
1559 unsigned long sun4u_get_pte(unsigned long addr
)
1565 unsigned long mask
= _PAGE_PADDR_4U
;
1567 if (tlb_type
== hypervisor
)
1568 mask
= _PAGE_PADDR_4V
;
1570 if (addr
>= PAGE_OFFSET
)
1573 if ((addr
>= LOW_OBP_ADDRESS
) && (addr
< HI_OBP_ADDRESS
))
1574 return prom_virt_to_phys(addr
, NULL
);
1576 pgdp
= pgd_offset_k(addr
);
1577 pudp
= pud_offset(pgdp
, addr
);
1578 pmdp
= pmd_offset(pudp
, addr
);
1579 ptep
= pte_offset_kernel(pmdp
, addr
);
1581 return pte_val(*ptep
) & mask
;
1584 /* If not locked, zap it. */
1585 void __flush_tlb_all(void)
1587 unsigned long pstate
;
1590 __asm__
__volatile__("flushw\n\t"
1591 "rdpr %%pstate, %0\n\t"
1592 "wrpr %0, %1, %%pstate"
1595 if (tlb_type
== spitfire
) {
1596 for (i
= 0; i
< 64; i
++) {
1597 /* Spitfire Errata #32 workaround */
1598 /* NOTE: Always runs on spitfire, so no
1599 * cheetah+ page size encodings.
1601 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
1605 "r" (PRIMARY_CONTEXT
), "i" (ASI_DMMU
));
1607 if (!(spitfire_get_dtlb_data(i
) & _PAGE_L_4U
)) {
1608 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
1611 : "r" (TLB_TAG_ACCESS
), "i" (ASI_DMMU
));
1612 spitfire_put_dtlb_data(i
, 0x0UL
);
1615 /* Spitfire Errata #32 workaround */
1616 /* NOTE: Always runs on spitfire, so no
1617 * cheetah+ page size encodings.
1619 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
1623 "r" (PRIMARY_CONTEXT
), "i" (ASI_DMMU
));
1625 if (!(spitfire_get_itlb_data(i
) & _PAGE_L_4U
)) {
1626 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
1629 : "r" (TLB_TAG_ACCESS
), "i" (ASI_IMMU
));
1630 spitfire_put_itlb_data(i
, 0x0UL
);
1633 } else if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
1634 cheetah_flush_dtlb_all();
1635 cheetah_flush_itlb_all();
1637 __asm__
__volatile__("wrpr %0, 0, %%pstate"