Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/asm-s390/pgalloc.h |
| 3 | * |
| 4 | * S390 version |
| 5 | * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 6 | * Author(s): Hartmut Penner (hp@de.ibm.com) |
| 7 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 8 | * |
| 9 | * Derived from "include/asm-i386/pgalloc.h" |
| 10 | * Copyright (C) 1994 Linus Torvalds |
| 11 | */ |
| 12 | |
| 13 | #ifndef _S390_PGALLOC_H |
| 14 | #define _S390_PGALLOC_H |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/threads.h> |
| 17 | #include <linux/gfp.h> |
| 18 | #include <linux/mm.h> |
| 19 | |
| 20 | #define check_pgt_cache() do {} while (0) |
| 21 | |
| 22 | extern void diag10(unsigned long addr); |
| 23 | |
| 24 | /* |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 25 | * Page allocation orders. |
| 26 | */ |
| 27 | #ifndef __s390x__ |
| 28 | # define PGD_ALLOC_ORDER 1 |
| 29 | #else /* __s390x__ */ |
| 30 | # define PMD_ALLOC_ORDER 2 |
| 31 | # define PGD_ALLOC_ORDER 2 |
| 32 | #endif /* __s390x__ */ |
| 33 | |
| 34 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * Allocate and free page tables. The xxx_kernel() versions are |
| 36 | * used to allocate a kernel page table - this turns on ASN bits |
| 37 | * if any. |
| 38 | */ |
| 39 | |
| 40 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 41 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 42 | pgd_t *pgd = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ALLOC_ORDER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | int i; |
| 44 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 45 | if (!pgd) |
| 46 | return NULL; |
| 47 | for (i = 0; i < PTRS_PER_PGD; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #ifndef __s390x__ |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 49 | pmd_clear(pmd_offset(pgd + i, i*PGDIR_SIZE)); |
| 50 | #else |
| 51 | pgd_clear(pgd + i); |
| 52 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | return pgd; |
| 54 | } |
| 55 | |
| 56 | static inline void pgd_free(pgd_t *pgd) |
| 57 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 58 | free_pages((unsigned long) pgd, PGD_ALLOC_ORDER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | #ifndef __s390x__ |
| 62 | /* |
| 63 | * page middle directory allocation/free routines. |
| 64 | * We use pmd cache only on s390x, so these are dummy routines. This |
| 65 | * code never triggers because the pgd will always be present. |
| 66 | */ |
| 67 | #define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); }) |
| 68 | #define pmd_free(x) do { } while (0) |
| 69 | #define __pmd_free_tlb(tlb,x) do { } while (0) |
| 70 | #define pgd_populate(mm, pmd, pte) BUG() |
| 71 | #else /* __s390x__ */ |
| 72 | static inline pmd_t * pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr) |
| 73 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 74 | pmd_t *pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, PMD_ALLOC_ORDER); |
| 75 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 77 | if (!pmd) |
| 78 | return NULL; |
| 79 | for (i=0; i < PTRS_PER_PMD; i++) |
| 80 | pmd_clear(pmd + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return pmd; |
| 82 | } |
| 83 | |
| 84 | static inline void pmd_free (pmd_t *pmd) |
| 85 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 86 | free_pages((unsigned long) pmd, PMD_ALLOC_ORDER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | #define __pmd_free_tlb(tlb,pmd) \ |
| 90 | do { \ |
| 91 | tlb_flush_mmu(tlb, 0, 0); \ |
| 92 | pmd_free(pmd); \ |
| 93 | } while (0) |
| 94 | |
| 95 | static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd) |
| 96 | { |
| 97 | pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd); |
| 98 | } |
| 99 | |
| 100 | #endif /* __s390x__ */ |
| 101 | |
| 102 | static inline void |
| 103 | pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte) |
| 104 | { |
| 105 | #ifndef __s390x__ |
| 106 | pmd_val(pmd[0]) = _PAGE_TABLE + __pa(pte); |
| 107 | pmd_val(pmd[1]) = _PAGE_TABLE + __pa(pte+256); |
| 108 | pmd_val(pmd[2]) = _PAGE_TABLE + __pa(pte+512); |
| 109 | pmd_val(pmd[3]) = _PAGE_TABLE + __pa(pte+768); |
| 110 | #else /* __s390x__ */ |
| 111 | pmd_val(*pmd) = _PMD_ENTRY + __pa(pte); |
| 112 | pmd_val1(*pmd) = _PMD_ENTRY + __pa(pte+256); |
| 113 | #endif /* __s390x__ */ |
| 114 | } |
| 115 | |
| 116 | static inline void |
| 117 | pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page) |
| 118 | { |
| 119 | pmd_populate_kernel(mm, pmd, (pte_t *)((page-mem_map) << PAGE_SHIFT)); |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * page table entry allocation/free routines. |
| 124 | */ |
| 125 | static inline pte_t * |
| 126 | pte_alloc_one_kernel(struct mm_struct *mm, unsigned long vmaddr) |
| 127 | { |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 128 | pte_t *pte = (pte_t *) __get_free_page(GFP_KERNEL|__GFP_REPEAT); |
| 129 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Gerald Schaefer | 9282ed9 | 2006-09-20 15:59:37 +0200 | [diff] [blame] | 131 | if (!pte) |
| 132 | return NULL; |
| 133 | for (i=0; i < PTRS_PER_PTE; i++) { |
| 134 | pte_clear(mm, vmaddr, pte + i); |
| 135 | vmaddr += PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | return pte; |
| 138 | } |
| 139 | |
| 140 | static inline struct page * |
| 141 | pte_alloc_one(struct mm_struct *mm, unsigned long vmaddr) |
| 142 | { |
| 143 | pte_t *pte = pte_alloc_one_kernel(mm, vmaddr); |
| 144 | if (pte) |
| 145 | return virt_to_page(pte); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 146 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static inline void pte_free_kernel(pte_t *pte) |
| 150 | { |
| 151 | free_page((unsigned long) pte); |
| 152 | } |
| 153 | |
| 154 | static inline void pte_free(struct page *pte) |
| 155 | { |
| 156 | __free_page(pte); |
| 157 | } |
| 158 | |
| 159 | #define __pte_free_tlb(tlb,pte) tlb_remove_page(tlb,pte) |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | #endif /* _S390_PGALLOC_H */ |