Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[linux/fpc-iii.git] / arch / ia64 / mm / hugetlbpage.c
blob68232db98baa74856752a86fc63cc12678e76787
1 /*
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
9 */
11 #include <linux/init.h>
12 #include <linux/fs.h>
13 #include <linux/mm.h>
14 #include <linux/hugetlb.h>
15 #include <linux/pagemap.h>
16 #include <linux/module.h>
17 #include <linux/sysctl.h>
18 #include <linux/log2.h>
19 #include <asm/mman.h>
20 #include <asm/pgalloc.h>
21 #include <asm/tlb.h>
22 #include <asm/tlbflush.h>
24 unsigned int hpage_shift = HPAGE_SHIFT_DEFAULT;
25 EXPORT_SYMBOL(hpage_shift);
27 pte_t *
28 huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz)
30 unsigned long taddr = htlbpage_to_page(addr);
31 pgd_t *pgd;
32 pud_t *pud;
33 pmd_t *pmd;
34 pte_t *pte = NULL;
36 pgd = pgd_offset(mm, taddr);
37 pud = pud_alloc(mm, pgd, taddr);
38 if (pud) {
39 pmd = pmd_alloc(mm, pud, taddr);
40 if (pmd)
41 pte = pte_alloc_map(mm, NULL, pmd, taddr);
43 return pte;
46 pte_t *
47 huge_pte_offset (struct mm_struct *mm, unsigned long addr)
49 unsigned long taddr = htlbpage_to_page(addr);
50 pgd_t *pgd;
51 pud_t *pud;
52 pmd_t *pmd;
53 pte_t *pte = NULL;
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);
65 return pte;
68 int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
70 return 0;
73 #define mk_pte_huge(entry) { pte_val(entry) |= _PAGE_P; }
76 * Don't actually need to do any preparation, but need to make sure
77 * the address is in the right region.
79 int prepare_hugepage_range(struct file *file,
80 unsigned long addr, unsigned long len)
82 if (len & ~HPAGE_MASK)
83 return -EINVAL;
84 if (addr & ~HPAGE_MASK)
85 return -EINVAL;
86 if (REGION_NUMBER(addr) != RGN_HPAGE)
87 return -EINVAL;
89 return 0;
92 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long addr, int write)
94 struct page *page;
95 pte_t *ptep;
97 if (REGION_NUMBER(addr) != RGN_HPAGE)
98 return ERR_PTR(-EINVAL);
100 ptep = huge_pte_offset(mm, addr);
101 if (!ptep || pte_none(*ptep))
102 return NULL;
103 page = pte_page(*ptep);
104 page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
105 return page;
107 int pmd_huge(pmd_t pmd)
109 return 0;
112 int pud_huge(pud_t pud)
114 return 0;
117 int pmd_huge_support(void)
119 return 0;
122 struct page *
123 follow_huge_pmd(struct mm_struct *mm, unsigned long address, pmd_t *pmd, int write)
125 return NULL;
128 void hugetlb_free_pgd_range(struct mmu_gather *tlb,
129 unsigned long addr, unsigned long end,
130 unsigned long floor, unsigned long ceiling)
133 * This is called to free hugetlb page tables.
135 * The offset of these addresses from the base of the hugetlb
136 * region must be scaled down by HPAGE_SIZE/PAGE_SIZE so that
137 * the standard free_pgd_range will free the right page tables.
139 * If floor and ceiling are also in the hugetlb region, they
140 * must likewise be scaled down; but if outside, left unchanged.
143 addr = htlbpage_to_page(addr);
144 end = htlbpage_to_page(end);
145 if (REGION_NUMBER(floor) == RGN_HPAGE)
146 floor = htlbpage_to_page(floor);
147 if (REGION_NUMBER(ceiling) == RGN_HPAGE)
148 ceiling = htlbpage_to_page(ceiling);
150 free_pgd_range(tlb, addr, end, floor, ceiling);
153 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
154 unsigned long pgoff, unsigned long flags)
156 struct vm_unmapped_area_info info;
158 if (len > RGN_MAP_LIMIT)
159 return -ENOMEM;
160 if (len & ~HPAGE_MASK)
161 return -EINVAL;
163 /* Handle MAP_FIXED */
164 if (flags & MAP_FIXED) {
165 if (prepare_hugepage_range(file, addr, len))
166 return -EINVAL;
167 return addr;
170 /* This code assumes that RGN_HPAGE != 0. */
171 if ((REGION_NUMBER(addr) != RGN_HPAGE) || (addr & (HPAGE_SIZE - 1)))
172 addr = HPAGE_REGION_BASE;
174 info.flags = 0;
175 info.length = len;
176 info.low_limit = addr;
177 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
178 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
179 info.align_offset = 0;
180 return vm_unmapped_area(&info);
183 static int __init hugetlb_setup_sz(char *str)
185 u64 tr_pages;
186 unsigned long long size;
188 if (ia64_pal_vm_page_size(&tr_pages, NULL) != 0)
190 * shouldn't happen, but just in case.
192 tr_pages = 0x15557000UL;
194 size = memparse(str, &str);
195 if (*str || !is_power_of_2(size) || !(tr_pages & size) ||
196 size <= PAGE_SIZE ||
197 size >= (1UL << PAGE_SHIFT << MAX_ORDER)) {
198 printk(KERN_WARNING "Invalid huge page size specified\n");
199 return 1;
202 hpage_shift = __ffs(size);
204 * boot cpu already executed ia64_mmu_init, and has HPAGE_SHIFT_DEFAULT
205 * override here with new page shift.
207 ia64_set_rr(HPAGE_REGION_BASE, hpage_shift << 2);
208 return 0;
210 early_param("hugepagesz", hugetlb_setup_sz);