2 * IA-64 Huge TLB Page Support for Kernel.
4 * Copyright (C) 2002-2004 Rohit Seth <rohit.seth@intel.com>
5 * Copyright (C) 2003-2004 Ken Chen <kenneth.w.chen@intel.com>
7 * Sep, 2003: add numa support
8 * Feb, 2004: dynamic hugetlb page size via boot parameter
11 #include <linux/config.h>
12 #include <linux/init.h>
15 #include <linux/hugetlb.h>
16 #include <linux/pagemap.h>
17 #include <linux/smp_lock.h>
18 #include <linux/slab.h>
19 #include <linux/sysctl.h>
21 #include <asm/pgalloc.h>
23 #include <asm/tlbflush.h>
25 unsigned int hpage_shift=HPAGE_SHIFT_DEFAULT;
28 huge_pte_alloc (struct mm_struct *mm, unsigned long addr)
30 unsigned long taddr = htlbpage_to_page(addr);
36 pgd = pgd_offset(mm, taddr);
37 pud = pud_alloc(mm, pgd, taddr);
39 pmd = pmd_alloc(mm, pud, taddr);
41 pte = pte_alloc_map(mm, pmd, taddr);
47 huge_pte_offset (struct mm_struct *mm, unsigned long addr)
49 unsigned long taddr = htlbpage_to_page(addr);
55 pgd = pgd_offset(mm, taddr);
56 if (pgd_present(*pgd)) {
57 pud = pud_offset(pgd, taddr);
58 if (pud_present(*pud)) {
59 pmd = pmd_offset(pud, taddr);
60 if (pmd_present(*pmd))
61 pte = pte_offset_map(pmd, taddr);
68 #define mk_pte_huge(entry) { pte_val(entry) |= _PAGE_P; }
71 * Don't actually need to do any preparation, but need to make sure
72 * the address is in the right region.
74 int prepare_hugepage_range(unsigned long addr, unsigned long len)
76 if (len & ~HPAGE_MASK)
78 if (addr & ~HPAGE_MASK)
80 if (REGION_NUMBER(addr) != RGN_HPAGE)
86 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long addr, int write)
91 if (REGION_NUMBER(addr) != RGN_HPAGE)
92 return ERR_PTR(-EINVAL);
94 ptep = huge_pte_offset(mm, addr);
95 if (!ptep || pte_none(*ptep))
97 page = pte_page(*ptep);
98 page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
101 int pmd_huge(pmd_t pmd)
106 follow_huge_pmd(struct mm_struct *mm, unsigned long address, pmd_t *pmd, int write)
111 void hugetlb_free_pgd_range(struct mmu_gather **tlb,
112 unsigned long addr, unsigned long end,
113 unsigned long floor, unsigned long ceiling)
116 * This is called only when is_hugepage_only_range(addr,),
117 * and it follows that is_hugepage_only_range(end,) also.
119 * The offset of these addresses from the base of the hugetlb
120 * region must be scaled down by HPAGE_SIZE/PAGE_SIZE so that
121 * the standard free_pgd_range will free the right page tables.
123 * If floor and ceiling are also in the hugetlb region, they
124 * must likewise be scaled down; but if outside, left unchanged.
127 addr = htlbpage_to_page(addr);
128 end = htlbpage_to_page(end);
129 if (is_hugepage_only_range(tlb->mm, floor, HPAGE_SIZE))
130 floor = htlbpage_to_page(floor);
131 if (is_hugepage_only_range(tlb->mm, ceiling, HPAGE_SIZE))
132 ceiling = htlbpage_to_page(ceiling);
134 free_pgd_range(tlb, addr, end, floor, ceiling);
137 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
138 unsigned long pgoff, unsigned long flags)
140 struct vm_area_struct *vmm;
142 if (len > RGN_MAP_LIMIT)
144 if (len & ~HPAGE_MASK)
146 /* This code assumes that RGN_HPAGE != 0. */
147 if ((REGION_NUMBER(addr) != RGN_HPAGE) || (addr & (HPAGE_SIZE - 1)))
148 addr = HPAGE_REGION_BASE;
150 addr = ALIGN(addr, HPAGE_SIZE);
151 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
152 /* At this point: (!vmm || addr < vmm->vm_end). */
153 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
155 if (!vmm || (addr + len) <= vmm->vm_start)
157 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
161 static int __init hugetlb_setup_sz(char *str)
164 unsigned long long size;
166 if (ia64_pal_vm_page_size(&tr_pages, NULL) != 0)
168 * shouldn't happen, but just in case.
170 tr_pages = 0x15557000UL;
172 size = memparse(str, &str);
173 if (*str || (size & (size-1)) || !(tr_pages & size) ||
175 size >= (1UL << PAGE_SHIFT << MAX_ORDER)) {
176 printk(KERN_WARNING "Invalid huge page size specified\n");
180 hpage_shift = __ffs(size);
182 * boot cpu already executed ia64_mmu_init, and has HPAGE_SHIFT_DEFAULT
183 * override here with new page shift.
185 ia64_set_rr(HPAGE_REGION_BASE, hpage_shift << 2);
188 __setup("hugepagesz=", hugetlb_setup_sz);