Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * IBM System z Huge TLB Page Support for Kernel. |
| 3 | * |
| 4 | * Copyright 2007 IBM Corp. |
| 5 | * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com> |
| 6 | */ |
| 7 | |
| 8 | #include <linux/mm.h> |
| 9 | #include <linux/hugetlb.h> |
| 10 | |
| 11 | |
| 12 | void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, |
| 13 | pte_t *pteptr, pte_t pteval) |
| 14 | { |
| 15 | pmd_t *pmdp = (pmd_t *) pteptr; |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 16 | unsigned long mask; |
| 17 | |
| 18 | if (!MACHINE_HAS_HPAGE) { |
| 19 | pteptr = (pte_t *) pte_page(pteval)[1].index; |
| 20 | mask = pte_val(pteval) & |
| 21 | (_SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO); |
| 22 | pte_val(pteval) = (_SEGMENT_ENTRY + __pa(pteptr)) | mask; |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | pmd_val(*pmdp) = pte_val(pteval); |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | int arch_prepare_hugepage(struct page *page) |
| 29 | { |
| 30 | unsigned long addr = page_to_phys(page); |
| 31 | pte_t pte; |
| 32 | pte_t *ptep; |
| 33 | int i; |
| 34 | |
| 35 | if (MACHINE_HAS_HPAGE) |
| 36 | return 0; |
| 37 | |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 38 | ptep = (pte_t *) pte_alloc_one(&init_mm, addr); |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 39 | if (!ptep) |
| 40 | return -ENOMEM; |
| 41 | |
| 42 | pte = mk_pte(page, PAGE_RW); |
| 43 | for (i = 0; i < PTRS_PER_PTE; i++) { |
| 44 | set_pte_at(&init_mm, addr + i * PAGE_SIZE, ptep + i, pte); |
| 45 | pte_val(pte) += PAGE_SIZE; |
| 46 | } |
| 47 | page[1].index = (unsigned long) ptep; |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | void arch_release_hugepage(struct page *page) |
| 52 | { |
| 53 | pte_t *ptep; |
| 54 | |
| 55 | if (MACHINE_HAS_HPAGE) |
| 56 | return; |
| 57 | |
| 58 | ptep = (pte_t *) page[1].index; |
| 59 | if (!ptep) |
| 60 | return; |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 61 | page_table_free(&init_mm, (unsigned long *) ptep); |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 62 | page[1].index = 0; |
| 63 | } |
| 64 | |
Andi Kleen | a551643 | 2008-07-23 21:27:41 -0700 | [diff] [blame] | 65 | pte_t *huge_pte_alloc(struct mm_struct *mm, |
| 66 | unsigned long addr, unsigned long sz) |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 67 | { |
| 68 | pgd_t *pgdp; |
| 69 | pud_t *pudp; |
| 70 | pmd_t *pmdp = NULL; |
| 71 | |
| 72 | pgdp = pgd_offset(mm, addr); |
| 73 | pudp = pud_alloc(mm, pgdp, addr); |
| 74 | if (pudp) |
| 75 | pmdp = pmd_alloc(mm, pudp, addr); |
| 76 | return (pte_t *) pmdp; |
| 77 | } |
| 78 | |
| 79 | pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr) |
| 80 | { |
| 81 | pgd_t *pgdp; |
| 82 | pud_t *pudp; |
| 83 | pmd_t *pmdp = NULL; |
| 84 | |
| 85 | pgdp = pgd_offset(mm, addr); |
| 86 | if (pgd_present(*pgdp)) { |
| 87 | pudp = pud_offset(pgdp, addr); |
| 88 | if (pud_present(*pudp)) |
| 89 | pmdp = pmd_offset(pudp, addr); |
| 90 | } |
| 91 | return (pte_t *) pmdp; |
| 92 | } |
| 93 | |
| 94 | int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address, |
| 100 | int write) |
| 101 | { |
| 102 | return ERR_PTR(-EINVAL); |
| 103 | } |
| 104 | |
| 105 | int pmd_huge(pmd_t pmd) |
| 106 | { |
| 107 | if (!MACHINE_HAS_HPAGE) |
| 108 | return 0; |
| 109 | |
| 110 | return !!(pmd_val(pmd) & _SEGMENT_ENTRY_LARGE); |
| 111 | } |
| 112 | |
Andi Kleen | ceb8687 | 2008-07-23 21:27:50 -0700 | [diff] [blame] | 113 | int pud_huge(pud_t pud) |
| 114 | { |
| 115 | return 0; |
| 116 | } |
| 117 | |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 118 | struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address, |
| 119 | pmd_t *pmdp, int write) |
| 120 | { |
| 121 | struct page *page; |
| 122 | |
| 123 | if (!MACHINE_HAS_HPAGE) |
| 124 | return NULL; |
| 125 | |
| 126 | page = pmd_page(*pmdp); |
| 127 | if (page) |
| 128 | page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT); |
| 129 | return page; |
| 130 | } |