at v2.6.20 164 lines 3.8 kB view raw
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 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 22extern void diag10(unsigned long addr); 23 24/* 25 * Page allocation orders. 26 */ 27#ifndef __s390x__ 28# define PTE_ALLOC_ORDER 0 29# define PMD_ALLOC_ORDER 0 30# define PGD_ALLOC_ORDER 1 31#else /* __s390x__ */ 32# define PTE_ALLOC_ORDER 0 33# define PMD_ALLOC_ORDER 2 34# define PGD_ALLOC_ORDER 2 35#endif /* __s390x__ */ 36 37/* 38 * Allocate and free page tables. The xxx_kernel() versions are 39 * used to allocate a kernel page table - this turns on ASN bits 40 * if any. 41 */ 42 43static inline pgd_t *pgd_alloc(struct mm_struct *mm) 44{ 45 pgd_t *pgd = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ALLOC_ORDER); 46 int i; 47 48 if (!pgd) 49 return NULL; 50 for (i = 0; i < PTRS_PER_PGD; i++) 51#ifndef __s390x__ 52 pmd_clear(pmd_offset(pgd + i, i*PGDIR_SIZE)); 53#else 54 pgd_clear(pgd + i); 55#endif 56 return pgd; 57} 58 59static inline void pgd_free(pgd_t *pgd) 60{ 61 free_pages((unsigned long) pgd, PGD_ALLOC_ORDER); 62} 63 64#ifndef __s390x__ 65/* 66 * page middle directory allocation/free routines. 67 * We use pmd cache only on s390x, so these are dummy routines. This 68 * code never triggers because the pgd will always be present. 69 */ 70#define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); }) 71#define pmd_free(x) do { } while (0) 72#define __pmd_free_tlb(tlb,x) do { } while (0) 73#define pgd_populate(mm, pmd, pte) BUG() 74#else /* __s390x__ */ 75static inline pmd_t * pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr) 76{ 77 pmd_t *pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, PMD_ALLOC_ORDER); 78 int i; 79 80 if (!pmd) 81 return NULL; 82 for (i=0; i < PTRS_PER_PMD; i++) 83 pmd_clear(pmd + i); 84 return pmd; 85} 86 87static inline void pmd_free (pmd_t *pmd) 88{ 89 free_pages((unsigned long) pmd, PMD_ALLOC_ORDER); 90} 91 92#define __pmd_free_tlb(tlb,pmd) \ 93 do { \ 94 tlb_flush_mmu(tlb, 0, 0); \ 95 pmd_free(pmd); \ 96 } while (0) 97 98static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd) 99{ 100 pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd); 101} 102 103#endif /* __s390x__ */ 104 105static inline void 106pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte) 107{ 108#ifndef __s390x__ 109 pmd_val(pmd[0]) = _PAGE_TABLE + __pa(pte); 110 pmd_val(pmd[1]) = _PAGE_TABLE + __pa(pte+256); 111 pmd_val(pmd[2]) = _PAGE_TABLE + __pa(pte+512); 112 pmd_val(pmd[3]) = _PAGE_TABLE + __pa(pte+768); 113#else /* __s390x__ */ 114 pmd_val(*pmd) = _PMD_ENTRY + __pa(pte); 115 pmd_val1(*pmd) = _PMD_ENTRY + __pa(pte+256); 116#endif /* __s390x__ */ 117} 118 119static inline void 120pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page) 121{ 122 pmd_populate_kernel(mm, pmd, (pte_t *)page_to_phys(page)); 123} 124 125/* 126 * page table entry allocation/free routines. 127 */ 128static inline pte_t * 129pte_alloc_one_kernel(struct mm_struct *mm, unsigned long vmaddr) 130{ 131 pte_t *pte = (pte_t *) __get_free_page(GFP_KERNEL|__GFP_REPEAT); 132 int i; 133 134 if (!pte) 135 return NULL; 136 for (i=0; i < PTRS_PER_PTE; i++) { 137 pte_clear(mm, vmaddr, pte + i); 138 vmaddr += PAGE_SIZE; 139 } 140 return pte; 141} 142 143static inline struct page * 144pte_alloc_one(struct mm_struct *mm, unsigned long vmaddr) 145{ 146 pte_t *pte = pte_alloc_one_kernel(mm, vmaddr); 147 if (pte) 148 return virt_to_page(pte); 149 return NULL; 150} 151 152static inline void pte_free_kernel(pte_t *pte) 153{ 154 free_page((unsigned long) pte); 155} 156 157static inline void pte_free(struct page *pte) 158{ 159 __free_page(pte); 160} 161 162#define __pte_free_tlb(tlb,pte) tlb_remove_page(tlb,pte) 163 164#endif /* _S390_PGALLOC_H */