blob: af4aee856df309796c2a54f44665981bd5693578 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/threads.h>
17#include <linux/gfp.h>
18#include <linux/mm.h>
19
20#define check_pgt_cache() do {} while (0)
21
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020022unsigned long *crst_table_alloc(struct mm_struct *, int);
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010023void crst_table_free(struct mm_struct *, unsigned long *);
Gerald Schaefer9282ed92006-09-20 15:59:37 +020024
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010025unsigned long *page_table_alloc(struct mm_struct *);
26void page_table_free(struct mm_struct *, unsigned long *);
27void disable_noexec(struct mm_struct *, struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020029static inline void clear_table(unsigned long *s, unsigned long val, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020031 *s = val;
32 n = (n / 256) - 1;
33 asm volatile(
34#ifdef CONFIG_64BIT
35 " mvc 8(248,%0),0(%0)\n"
Gerald Schaefer9282ed92006-09-20 15:59:37 +020036#else
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020037 " mvc 4(252,%0),0(%0)\n"
Gerald Schaefer9282ed92006-09-20 15:59:37 +020038#endif
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020039 "0: mvc 256(256,%0),0(%0)\n"
40 " la %0,256(%0)\n"
41 " brct %1,0b\n"
42 : "+a" (s), "+d" (n));
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020045static inline void crst_table_init(unsigned long *crst, unsigned long entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020047 clear_table(crst, entry, sizeof(unsigned long)*2048);
48 crst = get_shadow_table(crst);
49 if (crst)
50 clear_table(crst, entry, sizeof(unsigned long)*2048);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53#ifndef __s390x__
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020054
55static inline unsigned long pgd_entry_type(struct mm_struct *mm)
56{
57 return _SEGMENT_ENTRY_EMPTY;
58}
59
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020060#define pud_alloc_one(mm,address) ({ BUG(); ((pud_t *)2); })
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080061#define pud_free(mm, x) do { } while (0)
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020062
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020063#define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); })
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080064#define pmd_free(mm, x) do { } while (0)
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020065
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020066#define pgd_populate(mm, pgd, pud) BUG()
67#define pgd_populate_kernel(mm, pgd, pud) BUG()
68
69#define pud_populate(mm, pud, pmd) BUG()
70#define pud_populate_kernel(mm, pud, pmd) BUG()
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#else /* __s390x__ */
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020073
74static inline unsigned long pgd_entry_type(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020076 return _REGION3_ENTRY_EMPTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020079#define pud_alloc_one(mm,address) ({ BUG(); ((pud_t *)2); })
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080080#define pud_free(mm, x) do { } while (0)
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020081
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020082static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010084 unsigned long *table = crst_table_alloc(mm, mm->context.noexec);
85 if (table)
86 crst_table_init(table, _SEGMENT_ENTRY_EMPTY);
87 return (pmd_t *) table;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010089#define pmd_free(mm, pmd) crst_table_free(mm, (unsigned long *) pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020091#define pgd_populate(mm, pgd, pud) BUG()
92#define pgd_populate_kernel(mm, pgd, pud) BUG()
93
94static inline void pud_populate_kernel(struct mm_struct *mm,
95 pud_t *pud, pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020097 pud_val(*pud) = _REGION3_ENTRY | __pa(pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Martin Schwidefsky190a1d72007-10-22 12:52:48 +0200100static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100101{
Martin Schwidefsky190a1d72007-10-22 12:52:48 +0200102 pud_populate_kernel(mm, pud, pmd);
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100103 if (mm->context.noexec) {
104 pud = get_shadow_table(pud);
105 pmd = get_shadow_table(pmd);
106 pud_populate_kernel(mm, pud, pmd);
107 }
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#endif /* __s390x__ */
111
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200112static inline pgd_t *pgd_alloc(struct mm_struct *mm)
113{
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100114 unsigned long *crst;
115
116 INIT_LIST_HEAD(&mm->context.crst_list);
117 INIT_LIST_HEAD(&mm->context.pgtable_list);
118 crst = crst_table_alloc(mm, s390_noexec);
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200119 if (crst)
120 crst_table_init(crst, pgd_entry_type(mm));
121 return (pgd_t *) crst;
122}
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100123#define pgd_free(mm, pgd) crst_table_free(mm, (unsigned long *) pgd)
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200124
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100125static inline void pmd_populate_kernel(struct mm_struct *mm,
126 pmd_t *pmd, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200128 pmd_val(*pmd) = _SEGMENT_ENTRY + __pa(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100131static inline void pmd_populate(struct mm_struct *mm,
132 pmd_t *pmd, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100134 pmd_populate_kernel(mm, pmd, pte);
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100135 if (mm->context.noexec) {
136 pmd = get_shadow_table(pmd);
137 pmd_populate_kernel(mm, pmd, pte + PTRS_PER_PTE);
138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100140
141#define pmd_pgtable(pmd) \
142 (pgtable_t)(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144/*
145 * page table entry allocation/free routines.
146 */
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100147#define pte_alloc_one_kernel(mm, vmaddr) ((pte_t *) page_table_alloc(mm))
148#define pte_alloc_one(mm, vmaddr) ((pte_t *) page_table_alloc(mm))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100150#define pte_free_kernel(mm, pte) page_table_free(mm, (unsigned long *) pte)
151#define pte_free(mm, pte) page_table_free(mm, (unsigned long *) pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif /* _S390_PGALLOC_H */