0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef _S390_PGALLOC_H
0013 #define _S390_PGALLOC_H
0014
0015 #include <linux/threads.h>
0016 #include <linux/string.h>
0017 #include <linux/gfp.h>
0018 #include <linux/mm.h>
0019
0020 #define CRST_ALLOC_ORDER 2
0021
0022 unsigned long *crst_table_alloc(struct mm_struct *);
0023 void crst_table_free(struct mm_struct *, unsigned long *);
0024
0025 unsigned long *page_table_alloc(struct mm_struct *);
0026 struct page *page_table_alloc_pgste(struct mm_struct *mm);
0027 void page_table_free(struct mm_struct *, unsigned long *);
0028 void page_table_free_rcu(struct mmu_gather *, unsigned long *, unsigned long);
0029 void page_table_free_pgste(struct page *page);
0030 extern int page_table_allocate_pgste;
0031
0032 static inline void crst_table_init(unsigned long *crst, unsigned long entry)
0033 {
0034 memset64((u64 *)crst, entry, _CRST_ENTRIES);
0035 }
0036
0037 int crst_table_upgrade(struct mm_struct *mm, unsigned long limit);
0038
0039 static inline unsigned long check_asce_limit(struct mm_struct *mm, unsigned long addr,
0040 unsigned long len)
0041 {
0042 int rc;
0043
0044 if (addr + len > mm->context.asce_limit &&
0045 addr + len <= TASK_SIZE) {
0046 rc = crst_table_upgrade(mm, addr + len);
0047 if (rc)
0048 return (unsigned long) rc;
0049 }
0050 return addr;
0051 }
0052
0053 static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long address)
0054 {
0055 unsigned long *table = crst_table_alloc(mm);
0056
0057 if (table)
0058 crst_table_init(table, _REGION2_ENTRY_EMPTY);
0059 return (p4d_t *) table;
0060 }
0061
0062 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
0063 {
0064 if (!mm_p4d_folded(mm))
0065 crst_table_free(mm, (unsigned long *) p4d);
0066 }
0067
0068 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
0069 {
0070 unsigned long *table = crst_table_alloc(mm);
0071 if (table)
0072 crst_table_init(table, _REGION3_ENTRY_EMPTY);
0073 return (pud_t *) table;
0074 }
0075
0076 static inline void pud_free(struct mm_struct *mm, pud_t *pud)
0077 {
0078 if (!mm_pud_folded(mm))
0079 crst_table_free(mm, (unsigned long *) pud);
0080 }
0081
0082 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
0083 {
0084 unsigned long *table = crst_table_alloc(mm);
0085
0086 if (!table)
0087 return NULL;
0088 crst_table_init(table, _SEGMENT_ENTRY_EMPTY);
0089 if (!pgtable_pmd_page_ctor(virt_to_page(table))) {
0090 crst_table_free(mm, table);
0091 return NULL;
0092 }
0093 return (pmd_t *) table;
0094 }
0095
0096 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
0097 {
0098 if (mm_pmd_folded(mm))
0099 return;
0100 pgtable_pmd_page_dtor(virt_to_page(pmd));
0101 crst_table_free(mm, (unsigned long *) pmd);
0102 }
0103
0104 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p4d)
0105 {
0106 set_pgd(pgd, __pgd(_REGION1_ENTRY | __pa(p4d)));
0107 }
0108
0109 static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
0110 {
0111 set_p4d(p4d, __p4d(_REGION2_ENTRY | __pa(pud)));
0112 }
0113
0114 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
0115 {
0116 set_pud(pud, __pud(_REGION3_ENTRY | __pa(pmd)));
0117 }
0118
0119 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
0120 {
0121 return (pgd_t *) crst_table_alloc(mm);
0122 }
0123
0124 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
0125 {
0126 crst_table_free(mm, (unsigned long *) pgd);
0127 }
0128
0129 static inline void pmd_populate(struct mm_struct *mm,
0130 pmd_t *pmd, pgtable_t pte)
0131 {
0132 set_pmd(pmd, __pmd(_SEGMENT_ENTRY | __pa(pte)));
0133 }
0134
0135 #define pmd_populate_kernel(mm, pmd, pte) pmd_populate(mm, pmd, pte)
0136
0137
0138
0139
0140 #define pte_alloc_one_kernel(mm) ((pte_t *)page_table_alloc(mm))
0141 #define pte_alloc_one(mm) ((pte_t *)page_table_alloc(mm))
0142
0143 #define pte_free_kernel(mm, pte) page_table_free(mm, (unsigned long *) pte)
0144 #define pte_free(mm, pte) page_table_free(mm, (unsigned long *) pte)
0145
0146 void vmem_map_init(void);
0147 void *vmem_crst_alloc(unsigned long val);
0148 pte_t *vmem_pte_alloc(void);
0149
0150 unsigned long base_asce_alloc(unsigned long addr, unsigned long num_pages);
0151 void base_asce_free(unsigned long asce);
0152
0153 #endif