Full support for Ginger Console
[linux-ginger.git] / arch / s390 / mm / hugetlbpage.c
blobf28c43d2f61dd6b679b8cc8afb14c12e57e33273
1 /*
2 * IBM System z Huge TLB Page Support for Kernel.
4 * Copyright 2007 IBM Corp.
5 * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com>
6 */
8 #include <linux/mm.h>
9 #include <linux/hugetlb.h>
12 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
13 pte_t *pteptr, pte_t pteval)
15 pmd_t *pmdp = (pmd_t *) pteptr;
16 pte_t shadow_pteval = pteval;
17 unsigned long mask;
19 if (!MACHINE_HAS_HPAGE) {
20 pteptr = (pte_t *) pte_page(pteval)[1].index;
21 mask = pte_val(pteval) &
22 (_SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO);
23 pte_val(pteval) = (_SEGMENT_ENTRY + __pa(pteptr)) | mask;
24 if (mm->context.noexec) {
25 pteptr += PTRS_PER_PTE;
26 pte_val(shadow_pteval) =
27 (_SEGMENT_ENTRY + __pa(pteptr)) | mask;
31 pmd_val(*pmdp) = pte_val(pteval);
32 if (mm->context.noexec) {
33 pmdp = get_shadow_table(pmdp);
34 pmd_val(*pmdp) = pte_val(shadow_pteval);
38 int arch_prepare_hugepage(struct page *page)
40 unsigned long addr = page_to_phys(page);
41 pte_t pte;
42 pte_t *ptep;
43 int i;
45 if (MACHINE_HAS_HPAGE)
46 return 0;
48 ptep = (pte_t *) pte_alloc_one(&init_mm, address);
49 if (!ptep)
50 return -ENOMEM;
52 pte = mk_pte(page, PAGE_RW);
53 for (i = 0; i < PTRS_PER_PTE; i++) {
54 set_pte_at(&init_mm, addr + i * PAGE_SIZE, ptep + i, pte);
55 pte_val(pte) += PAGE_SIZE;
57 page[1].index = (unsigned long) ptep;
58 return 0;
61 void arch_release_hugepage(struct page *page)
63 pte_t *ptep;
65 if (MACHINE_HAS_HPAGE)
66 return;
68 ptep = (pte_t *) page[1].index;
69 if (!ptep)
70 return;
71 pte_free(&init_mm, ptep);
72 page[1].index = 0;
75 pte_t *huge_pte_alloc(struct mm_struct *mm,
76 unsigned long addr, unsigned long sz)
78 pgd_t *pgdp;
79 pud_t *pudp;
80 pmd_t *pmdp = NULL;
82 pgdp = pgd_offset(mm, addr);
83 pudp = pud_alloc(mm, pgdp, addr);
84 if (pudp)
85 pmdp = pmd_alloc(mm, pudp, addr);
86 return (pte_t *) pmdp;
89 pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
91 pgd_t *pgdp;
92 pud_t *pudp;
93 pmd_t *pmdp = NULL;
95 pgdp = pgd_offset(mm, addr);
96 if (pgd_present(*pgdp)) {
97 pudp = pud_offset(pgdp, addr);
98 if (pud_present(*pudp))
99 pmdp = pmd_offset(pudp, addr);
101 return (pte_t *) pmdp;
104 int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
106 return 0;
109 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
110 int write)
112 return ERR_PTR(-EINVAL);
115 int pmd_huge(pmd_t pmd)
117 if (!MACHINE_HAS_HPAGE)
118 return 0;
120 return !!(pmd_val(pmd) & _SEGMENT_ENTRY_LARGE);
123 int pud_huge(pud_t pud)
125 return 0;
128 struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
129 pmd_t *pmdp, int write)
131 struct page *page;
133 if (!MACHINE_HAS_HPAGE)
134 return NULL;
136 page = pmd_page(*pmdp);
137 if (page)
138 page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
139 return page;