2 * PowerPC64 port by Mike Corrigan and Dave Engebretsen
3 * {mikejc|engebret}@us.ibm.com
5 * Copyright (c) 2000 Mike Corrigan <mikejc@us.ibm.com>
7 * SMP scalability work:
8 * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
13 * PowerPC Hashed Page Table functions
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
24 #include <linux/spinlock.h>
25 #include <linux/errno.h>
26 #include <linux/sched.h>
27 #include <linux/proc_fs.h>
28 #include <linux/stat.h>
29 #include <linux/sysctl.h>
30 #include <linux/ctype.h>
31 #include <linux/cache.h>
32 #include <linux/init.h>
33 #include <linux/signal.h>
35 #include <asm/processor.h>
36 #include <asm/pgtable.h>
38 #include <asm/mmu_context.h>
40 #include <asm/types.h>
41 #include <asm/system.h>
42 #include <asm/uaccess.h>
43 #include <asm/machdep.h>
45 #include <asm/abs_addr.h>
46 #include <asm/tlbflush.h>
50 #include <asm/cacheflush.h>
51 #include <asm/cputable.h>
52 #include <asm/abs_addr.h>
53 #include <asm/sections.h>
56 #define DBG(fmt...) udbg_printf(fmt)
62 #define DBG_LOW(fmt...) udbg_printf(fmt)
64 #define DBG_LOW(fmt...)
71 * Note: pte --> Linux PTE
72 * HPTE --> PowerPC Hashed Page Table Entry
75 * htab_initialize is called with the MMU off (of course), but
76 * the kernel has been copied down to zero so it can directly
77 * reference global data. At this point it is very difficult
78 * to print debug info.
83 extern unsigned long dart_tablebase;
84 #endif /* CONFIG_U3_DART */
86 static unsigned long _SDR1;
87 struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
90 unsigned long htab_size_bytes;
91 unsigned long htab_hash_mask;
92 int mmu_linear_psize = MMU_PAGE_4K;
93 int mmu_virtual_psize = MMU_PAGE_4K;
94 int mmu_vmalloc_psize = MMU_PAGE_4K;
95 int mmu_io_psize = MMU_PAGE_4K;
96 #ifdef CONFIG_HUGETLB_PAGE
97 int mmu_huge_psize = MMU_PAGE_16M;
98 unsigned int HPAGE_SHIFT;
100 #ifdef CONFIG_PPC_64K_PAGES
101 int mmu_ci_restrictions;
103 #ifdef CONFIG_DEBUG_PAGEALLOC
104 static u8 *linear_map_hash_slots;
105 static unsigned long linear_map_hash_count;
106 static spinlock_t linear_map_hash_lock;
107 #endif /* CONFIG_DEBUG_PAGEALLOC */
109 /* There are definitions of page sizes arrays to be used when none
110 * is provided by the firmware.
113 /* Pre-POWER4 CPUs (4k pages only)
115 struct mmu_psize_def mmu_psize_defaults_old[] = {
125 /* POWER4, GPUL, POWER5
127 * Support for 16Mb large pages
129 struct mmu_psize_def mmu_psize_defaults_gp[] = {
147 int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
148 unsigned long pstart, unsigned long mode, int psize)
150 unsigned long vaddr, paddr;
151 unsigned int step, shift;
152 unsigned long tmp_mode;
155 shift = mmu_psize_defs[psize].shift;
158 for (vaddr = vstart, paddr = pstart; vaddr < vend;
159 vaddr += step, paddr += step) {
160 unsigned long hash, hpteg;
161 unsigned long vsid = get_kernel_vsid(vaddr);
162 unsigned long va = (vsid << 28) | (vaddr & 0x0fffffff);
166 /* Make non-kernel text non-executable */
167 if (!in_kernel_text(vaddr))
168 tmp_mode = mode | HPTE_R_N;
170 hash = hpt_hash(va, shift);
171 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
173 DBG("htab_bolt_mapping: calling %p\n", ppc_md.hpte_insert);
175 BUG_ON(!ppc_md.hpte_insert);
176 ret = ppc_md.hpte_insert(hpteg, va, paddr,
177 tmp_mode, HPTE_V_BOLTED, psize);
181 #ifdef CONFIG_DEBUG_PAGEALLOC
182 if ((paddr >> PAGE_SHIFT) < linear_map_hash_count)
183 linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80;
184 #endif /* CONFIG_DEBUG_PAGEALLOC */
186 return ret < 0 ? ret : 0;
189 static int __init htab_dt_scan_page_sizes(unsigned long node,
190 const char *uname, int depth,
193 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
195 unsigned long size = 0;
197 /* We are scanning "cpu" nodes only */
198 if (type == NULL || strcmp(type, "cpu") != 0)
201 prop = (u32 *)of_get_flat_dt_prop(node,
202 "ibm,segment-page-sizes", &size);
204 DBG("Page sizes from device-tree:\n");
206 cur_cpu_spec->cpu_features &= ~(CPU_FTR_16M_PAGE);
208 unsigned int shift = prop[0];
209 unsigned int slbenc = prop[1];
210 unsigned int lpnum = prop[2];
211 unsigned int lpenc = 0;
212 struct mmu_psize_def *def;
215 size -= 3; prop += 3;
216 while(size > 0 && lpnum) {
217 if (prop[0] == shift)
219 prop += 2; size -= 2;
234 cur_cpu_spec->cpu_features |= CPU_FTR_16M_PAGE;
242 def = &mmu_psize_defs[idx];
247 def->avpnm = (1 << (shift - 23)) - 1;
250 /* We don't know for sure what's up with tlbiel, so
251 * for now we only set it for 4K and 64K pages
253 if (idx == MMU_PAGE_4K || idx == MMU_PAGE_64K)
258 DBG(" %d: shift=%02x, sllp=%04x, avpnm=%08x, "
259 "tlbiel=%d, penc=%d\n",
260 idx, shift, def->sllp, def->avpnm, def->tlbiel,
269 static void __init htab_init_page_sizes(void)
273 /* Default to 4K pages only */
274 memcpy(mmu_psize_defs, mmu_psize_defaults_old,
275 sizeof(mmu_psize_defaults_old));
278 * Try to find the available page sizes in the device-tree
280 rc = of_scan_flat_dt(htab_dt_scan_page_sizes, NULL);
281 if (rc != 0) /* Found */
285 * Not in the device-tree, let's fallback on known size
286 * list for 16M capable GP & GR
288 if (cpu_has_feature(CPU_FTR_16M_PAGE))
289 memcpy(mmu_psize_defs, mmu_psize_defaults_gp,
290 sizeof(mmu_psize_defaults_gp));
292 #ifndef CONFIG_DEBUG_PAGEALLOC
294 * Pick a size for the linear mapping. Currently, we only support
295 * 16M, 1M and 4K which is the default
297 if (mmu_psize_defs[MMU_PAGE_16M].shift)
298 mmu_linear_psize = MMU_PAGE_16M;
299 else if (mmu_psize_defs[MMU_PAGE_1M].shift)
300 mmu_linear_psize = MMU_PAGE_1M;
301 #endif /* CONFIG_DEBUG_PAGEALLOC */
303 #ifdef CONFIG_PPC_64K_PAGES
305 * Pick a size for the ordinary pages. Default is 4K, we support
306 * 64K for user mappings and vmalloc if supported by the processor.
307 * We only use 64k for ioremap if the processor
308 * (and firmware) support cache-inhibited large pages.
309 * If not, we use 4k and set mmu_ci_restrictions so that
310 * hash_page knows to switch processes that use cache-inhibited
311 * mappings to 4k pages.
313 if (mmu_psize_defs[MMU_PAGE_64K].shift) {
314 mmu_virtual_psize = MMU_PAGE_64K;
315 mmu_vmalloc_psize = MMU_PAGE_64K;
316 if (mmu_linear_psize == MMU_PAGE_4K)
317 mmu_linear_psize = MMU_PAGE_64K;
318 if (cpu_has_feature(CPU_FTR_CI_LARGE_PAGE))
319 mmu_io_psize = MMU_PAGE_64K;
321 mmu_ci_restrictions = 1;
323 #endif /* CONFIG_PPC_64K_PAGES */
325 printk(KERN_DEBUG "Page orders: linear mapping = %d, "
326 "virtual = %d, io = %d\n",
327 mmu_psize_defs[mmu_linear_psize].shift,
328 mmu_psize_defs[mmu_virtual_psize].shift,
329 mmu_psize_defs[mmu_io_psize].shift);
331 #ifdef CONFIG_HUGETLB_PAGE
332 /* Init large page size. Currently, we pick 16M or 1M depending
333 * on what is available
335 if (mmu_psize_defs[MMU_PAGE_16M].shift)
336 mmu_huge_psize = MMU_PAGE_16M;
337 /* With 4k/4level pagetables, we can't (for now) cope with a
338 * huge page size < PMD_SIZE */
339 else if (mmu_psize_defs[MMU_PAGE_1M].shift)
340 mmu_huge_psize = MMU_PAGE_1M;
342 /* Calculate HPAGE_SHIFT and sanity check it */
343 if (mmu_psize_defs[mmu_huge_psize].shift > MIN_HUGEPTE_SHIFT &&
344 mmu_psize_defs[mmu_huge_psize].shift < SID_SHIFT)
345 HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift;
347 HPAGE_SHIFT = 0; /* No huge pages dude ! */
348 #endif /* CONFIG_HUGETLB_PAGE */
351 static int __init htab_dt_scan_pftsize(unsigned long node,
352 const char *uname, int depth,
355 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
358 /* We are scanning "cpu" nodes only */
359 if (type == NULL || strcmp(type, "cpu") != 0)
362 prop = (u32 *)of_get_flat_dt_prop(node, "ibm,pft-size", NULL);
364 /* pft_size[0] is the NUMA CEC cookie */
365 ppc64_pft_size = prop[1];
371 static unsigned long __init htab_get_table_size(void)
373 unsigned long mem_size, rnd_mem_size, pteg_count;
375 /* If hash size isn't already provided by the platform, we try to
376 * retrieve it from the device-tree. If it's not there neither, we
377 * calculate it now based on the total RAM size
379 if (ppc64_pft_size == 0)
380 of_scan_flat_dt(htab_dt_scan_pftsize, NULL);
382 return 1UL << ppc64_pft_size;
384 /* round mem_size up to next power of 2 */
385 mem_size = lmb_phys_mem_size();
386 rnd_mem_size = 1UL << __ilog2(mem_size);
387 if (rnd_mem_size < mem_size)
391 pteg_count = max(rnd_mem_size >> (12 + 1), 1UL << 11);
393 return pteg_count << 7;
396 #ifdef CONFIG_MEMORY_HOTPLUG
397 void create_section_mapping(unsigned long start, unsigned long end)
399 BUG_ON(htab_bolt_mapping(start, end, __pa(start),
400 _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX,
403 #endif /* CONFIG_MEMORY_HOTPLUG */
405 static inline void make_bl(unsigned int *insn_addr, void *func)
407 unsigned long funcp = *((unsigned long *)func);
408 int offset = funcp - (unsigned long)insn_addr;
410 *insn_addr = (unsigned int)(0x48000001 | (offset & 0x03fffffc));
411 flush_icache_range((unsigned long)insn_addr, 4+
412 (unsigned long)insn_addr);
415 static void __init htab_finish_init(void)
417 extern unsigned int *htab_call_hpte_insert1;
418 extern unsigned int *htab_call_hpte_insert2;
419 extern unsigned int *htab_call_hpte_remove;
420 extern unsigned int *htab_call_hpte_updatepp;
422 #ifdef CONFIG_PPC_64K_PAGES
423 extern unsigned int *ht64_call_hpte_insert1;
424 extern unsigned int *ht64_call_hpte_insert2;
425 extern unsigned int *ht64_call_hpte_remove;
426 extern unsigned int *ht64_call_hpte_updatepp;
428 make_bl(ht64_call_hpte_insert1, ppc_md.hpte_insert);
429 make_bl(ht64_call_hpte_insert2, ppc_md.hpte_insert);
430 make_bl(ht64_call_hpte_remove, ppc_md.hpte_remove);
431 make_bl(ht64_call_hpte_updatepp, ppc_md.hpte_updatepp);
432 #endif /* CONFIG_PPC_64K_PAGES */
434 make_bl(htab_call_hpte_insert1, ppc_md.hpte_insert);
435 make_bl(htab_call_hpte_insert2, ppc_md.hpte_insert);
436 make_bl(htab_call_hpte_remove, ppc_md.hpte_remove);
437 make_bl(htab_call_hpte_updatepp, ppc_md.hpte_updatepp);
440 void __init htab_initialize(void)
443 unsigned long pteg_count;
444 unsigned long mode_rw;
445 unsigned long base = 0, size = 0;
448 extern unsigned long tce_alloc_start, tce_alloc_end;
450 DBG(" -> htab_initialize()\n");
452 /* Initialize page sizes */
453 htab_init_page_sizes();
456 * Calculate the required size of the htab. We want the number of
457 * PTEGs to equal one half the number of real pages.
459 htab_size_bytes = htab_get_table_size();
460 pteg_count = htab_size_bytes >> 7;
462 htab_hash_mask = pteg_count - 1;
464 if (firmware_has_feature(FW_FEATURE_LPAR)) {
465 /* Using a hypervisor which owns the htab */
469 /* Find storage for the HPT. Must be contiguous in
470 * the absolute address space.
472 table = lmb_alloc(htab_size_bytes, htab_size_bytes);
474 DBG("Hash table allocated at %lx, size: %lx\n", table,
477 htab_address = abs_to_virt(table);
479 /* htab absolute addr + encoded htabsize */
480 _SDR1 = table + __ilog2(pteg_count) - 11;
482 /* Initialize the HPT with no entries */
483 memset((void *)table, 0, htab_size_bytes);
486 mtspr(SPRN_SDR1, _SDR1);
489 mode_rw = _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX;
491 #ifdef CONFIG_DEBUG_PAGEALLOC
492 linear_map_hash_count = lmb_end_of_DRAM() >> PAGE_SHIFT;
493 linear_map_hash_slots = __va(lmb_alloc_base(linear_map_hash_count,
495 memset(linear_map_hash_slots, 0, linear_map_hash_count);
496 #endif /* CONFIG_DEBUG_PAGEALLOC */
498 /* On U3 based machines, we need to reserve the DART area and
499 * _NOT_ map it to avoid cache paradoxes as it's remapped non
503 /* create bolted the linear mapping in the hash table */
504 for (i=0; i < lmb.memory.cnt; i++) {
505 base = (unsigned long)__va(lmb.memory.region[i].base);
506 size = lmb.memory.region[i].size;
508 DBG("creating mapping for region: %lx : %lx\n", base, size);
510 #ifdef CONFIG_U3_DART
511 /* Do not map the DART space. Fortunately, it will be aligned
512 * in such a way that it will not cross two lmb regions and
513 * will fit within a single 16Mb page.
514 * The DART space is assumed to be a full 16Mb region even if
515 * we only use 2Mb of that space. We will use more of it later
516 * for AGP GART. We have to use a full 16Mb large page.
518 DBG("DART base: %lx\n", dart_tablebase);
520 if (dart_tablebase != 0 && dart_tablebase >= base
521 && dart_tablebase < (base + size)) {
522 unsigned long dart_table_end = dart_tablebase + 16 * MB;
523 if (base != dart_tablebase)
524 BUG_ON(htab_bolt_mapping(base, dart_tablebase,
527 if ((base + size) > dart_table_end)
528 BUG_ON(htab_bolt_mapping(dart_tablebase+16*MB,
530 __pa(dart_table_end),
535 #endif /* CONFIG_U3_DART */
536 BUG_ON(htab_bolt_mapping(base, base + size, __pa(base),
537 mode_rw, mmu_linear_psize));
541 * If we have a memory_limit and we've allocated TCEs then we need to
542 * explicitly map the TCE area at the top of RAM. We also cope with the
543 * case that the TCEs start below memory_limit.
544 * tce_alloc_start/end are 16MB aligned so the mapping should work
545 * for either 4K or 16MB pages.
547 if (tce_alloc_start) {
548 tce_alloc_start = (unsigned long)__va(tce_alloc_start);
549 tce_alloc_end = (unsigned long)__va(tce_alloc_end);
551 if (base + size >= tce_alloc_start)
552 tce_alloc_start = base + size + 1;
554 BUG_ON(htab_bolt_mapping(tce_alloc_start, tce_alloc_end,
555 __pa(tce_alloc_start), mode_rw,
561 DBG(" <- htab_initialize()\n");
566 void htab_initialize_secondary(void)
568 if (!firmware_has_feature(FW_FEATURE_LPAR))
569 mtspr(SPRN_SDR1, _SDR1);
573 * Called by asm hashtable.S for doing lazy icache flush
575 unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int trap)
579 if (!pfn_valid(pte_pfn(pte)))
582 page = pte_page(pte);
585 if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) {
587 __flush_dcache_icache(page_address(page));
588 set_bit(PG_arch_1, &page->flags);
596 * Demote a segment to using 4k pages.
597 * For now this makes the whole process use 4k pages.
599 void demote_segment_4k(struct mm_struct *mm, unsigned long addr)
601 #ifdef CONFIG_PPC_64K_PAGES
602 if (mm->context.user_psize == MMU_PAGE_4K)
604 mm->context.user_psize = MMU_PAGE_4K;
605 mm->context.sllp = SLB_VSID_USER | mmu_psize_defs[MMU_PAGE_4K].sllp;
606 get_paca()->context = mm->context;
607 slb_flush_and_rebolt();
608 #ifdef CONFIG_SPE_BASE
609 spu_flush_all_slbs(mm);
614 EXPORT_SYMBOL_GPL(demote_segment_4k);
618 * 1 - normal page fault
619 * -1 - critical hash insertion error
621 int hash_page(unsigned long ea, unsigned long access, unsigned long trap)
625 struct mm_struct *mm;
628 int rc, user_region = 0, local = 0;
631 DBG_LOW("hash_page(ea=%016lx, access=%lx, trap=%lx\n",
634 if ((ea & ~REGION_MASK) >= PGTABLE_RANGE) {
635 DBG_LOW(" out of pgtable range !\n");
639 /* Get region & vsid */
640 switch (REGION_ID(ea)) {
645 DBG_LOW(" user region with no mm !\n");
648 vsid = get_vsid(mm->context.id, ea);
649 psize = mm->context.user_psize;
651 case VMALLOC_REGION_ID:
653 vsid = get_kernel_vsid(ea);
654 if (ea < VMALLOC_END)
655 psize = mmu_vmalloc_psize;
657 psize = mmu_io_psize;
661 * Send the problem up to do_page_fault
665 DBG_LOW(" mm=%p, mm->pgdir=%p, vsid=%016lx\n", mm, mm->pgd, vsid);
672 /* Check CPU locality */
673 tmp = cpumask_of_cpu(smp_processor_id());
674 if (user_region && cpus_equal(mm->cpu_vm_mask, tmp))
677 /* Handle hugepage regions */
678 if (unlikely(in_hugepage_area(mm->context, ea))) {
679 DBG_LOW(" -> huge page !\n");
680 return hash_huge_page(mm, access, ea, vsid, local, trap);
683 /* Get PTE and page size from page tables */
684 ptep = find_linux_pte(pgdir, ea);
685 if (ptep == NULL || !pte_present(*ptep)) {
686 DBG_LOW(" no PTE !\n");
690 #ifndef CONFIG_PPC_64K_PAGES
691 DBG_LOW(" i-pte: %016lx\n", pte_val(*ptep));
693 DBG_LOW(" i-pte: %016lx %016lx\n", pte_val(*ptep),
694 pte_val(*(ptep + PTRS_PER_PTE)));
696 /* Pre-check access permissions (will be re-checked atomically
697 * in __hash_page_XX but this pre-check is a fast path
699 if (access & ~pte_val(*ptep)) {
700 DBG_LOW(" no access !\n");
704 /* Do actual hashing */
705 #ifndef CONFIG_PPC_64K_PAGES
706 rc = __hash_page_4K(ea, access, vsid, ptep, trap, local);
708 /* If _PAGE_4K_PFN is set, make sure this is a 4k segment */
709 if (pte_val(*ptep) & _PAGE_4K_PFN) {
710 demote_segment_4k(mm, ea);
714 if (mmu_ci_restrictions) {
715 /* If this PTE is non-cacheable, switch to 4k */
716 if (psize == MMU_PAGE_64K &&
717 (pte_val(*ptep) & _PAGE_NO_CACHE)) {
719 demote_segment_4k(mm, ea);
721 } else if (ea < VMALLOC_END) {
723 * some driver did a non-cacheable mapping
724 * in vmalloc space, so switch vmalloc
727 printk(KERN_ALERT "Reducing vmalloc segment "
728 "to 4kB pages because of "
729 "non-cacheable mapping\n");
730 psize = mmu_vmalloc_psize = MMU_PAGE_4K;
732 #ifdef CONFIG_SPE_BASE
733 spu_flush_all_slbs(mm);
737 if (psize != get_paca()->context.user_psize) {
738 get_paca()->context = mm->context;
739 slb_flush_and_rebolt();
741 } else if (get_paca()->vmalloc_sllp !=
742 mmu_psize_defs[mmu_vmalloc_psize].sllp) {
743 get_paca()->vmalloc_sllp =
744 mmu_psize_defs[mmu_vmalloc_psize].sllp;
745 slb_flush_and_rebolt();
748 if (psize == MMU_PAGE_64K)
749 rc = __hash_page_64K(ea, access, vsid, ptep, trap, local);
751 rc = __hash_page_4K(ea, access, vsid, ptep, trap, local);
752 #endif /* CONFIG_PPC_64K_PAGES */
754 #ifndef CONFIG_PPC_64K_PAGES
755 DBG_LOW(" o-pte: %016lx\n", pte_val(*ptep));
757 DBG_LOW(" o-pte: %016lx %016lx\n", pte_val(*ptep),
758 pte_val(*(ptep + PTRS_PER_PTE)));
760 DBG_LOW(" -> rc=%d\n", rc);
763 EXPORT_SYMBOL_GPL(hash_page);
765 void hash_preload(struct mm_struct *mm, unsigned long ea,
766 unsigned long access, unsigned long trap)
775 /* We don't want huge pages prefaulted for now
777 if (unlikely(in_hugepage_area(mm->context, ea)))
780 DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx,"
781 " trap=%lx\n", mm, mm->pgd, ea, access, trap);
783 /* Get PTE, VSID, access mask */
787 ptep = find_linux_pte(pgdir, ea);
790 vsid = get_vsid(mm->context.id, ea);
793 local_irq_save(flags);
794 mask = cpumask_of_cpu(smp_processor_id());
795 if (cpus_equal(mm->cpu_vm_mask, mask))
797 #ifndef CONFIG_PPC_64K_PAGES
798 __hash_page_4K(ea, access, vsid, ptep, trap, local);
800 if (mmu_ci_restrictions) {
801 /* If this PTE is non-cacheable, switch to 4k */
802 if (mm->context.user_psize == MMU_PAGE_64K &&
803 (pte_val(*ptep) & _PAGE_NO_CACHE))
804 demote_segment_4k(mm, ea);
806 if (mm->context.user_psize == MMU_PAGE_64K)
807 __hash_page_64K(ea, access, vsid, ptep, trap, local);
809 __hash_page_4K(ea, access, vsid, ptep, trap, local);
810 #endif /* CONFIG_PPC_64K_PAGES */
811 local_irq_restore(flags);
814 void flush_hash_page(unsigned long va, real_pte_t pte, int psize, int local)
816 unsigned long hash, index, shift, hidx, slot;
818 DBG_LOW("flush_hash_page(va=%016x)\n", va);
819 pte_iterate_hashed_subpages(pte, psize, va, index, shift) {
820 hash = hpt_hash(va, shift);
821 hidx = __rpte_to_hidx(pte, index);
822 if (hidx & _PTEIDX_SECONDARY)
824 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
825 slot += hidx & _PTEIDX_GROUP_IX;
826 DBG_LOW(" sub %d: hash=%x, hidx=%x\n", index, slot, hidx);
827 ppc_md.hpte_invalidate(slot, va, psize, local);
828 } pte_iterate_hashed_end();
831 void flush_hash_range(unsigned long number, int local)
833 if (ppc_md.flush_hash_range)
834 ppc_md.flush_hash_range(number, local);
837 struct ppc64_tlb_batch *batch =
838 &__get_cpu_var(ppc64_tlb_batch);
840 for (i = 0; i < number; i++)
841 flush_hash_page(batch->vaddr[i], batch->pte[i],
842 batch->psize, local);
847 * low_hash_fault is called when we the low level hash code failed
848 * to instert a PTE due to an hypervisor error
850 void low_hash_fault(struct pt_regs *regs, unsigned long address)
852 if (user_mode(regs)) {
855 info.si_signo = SIGBUS;
857 info.si_code = BUS_ADRERR;
858 info.si_addr = (void __user *)address;
859 force_sig_info(SIGBUS, &info, current);
862 bad_page_fault(regs, address, SIGBUS);
865 #ifdef CONFIG_DEBUG_PAGEALLOC
866 static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi)
868 unsigned long hash, hpteg, vsid = get_kernel_vsid(vaddr);
869 unsigned long va = (vsid << 28) | (vaddr & 0x0fffffff);
870 unsigned long mode = _PAGE_ACCESSED | _PAGE_DIRTY |
871 _PAGE_COHERENT | PP_RWXX | HPTE_R_N;
874 hash = hpt_hash(va, PAGE_SHIFT);
875 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
877 ret = ppc_md.hpte_insert(hpteg, va, __pa(vaddr),
878 mode, HPTE_V_BOLTED, mmu_linear_psize);
880 spin_lock(&linear_map_hash_lock);
881 BUG_ON(linear_map_hash_slots[lmi] & 0x80);
882 linear_map_hash_slots[lmi] = ret | 0x80;
883 spin_unlock(&linear_map_hash_lock);
886 static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi)
888 unsigned long hash, hidx, slot, vsid = get_kernel_vsid(vaddr);
889 unsigned long va = (vsid << 28) | (vaddr & 0x0fffffff);
891 hash = hpt_hash(va, PAGE_SHIFT);
892 spin_lock(&linear_map_hash_lock);
893 BUG_ON(!(linear_map_hash_slots[lmi] & 0x80));
894 hidx = linear_map_hash_slots[lmi] & 0x7f;
895 linear_map_hash_slots[lmi] = 0;
896 spin_unlock(&linear_map_hash_lock);
897 if (hidx & _PTEIDX_SECONDARY)
899 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
900 slot += hidx & _PTEIDX_GROUP_IX;
901 ppc_md.hpte_invalidate(slot, va, mmu_linear_psize, 0);
904 void kernel_map_pages(struct page *page, int numpages, int enable)
906 unsigned long flags, vaddr, lmi;
909 local_irq_save(flags);
910 for (i = 0; i < numpages; i++, page++) {
911 vaddr = (unsigned long)page_address(page);
912 lmi = __pa(vaddr) >> PAGE_SHIFT;
913 if (lmi >= linear_map_hash_count)
916 kernel_map_linear_page(vaddr, lmi);
918 kernel_unmap_linear_page(vaddr, lmi);
920 local_irq_restore(flags);
922 #endif /* CONFIG_DEBUG_PAGEALLOC */