blob: 584d0ee3c7f60de6f2a0534dc39e2df4ddeaf1b4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/asm-s390/page.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 */
8
9#ifndef _S390_PAGE_H
10#define _S390_PAGE_H
11
Sam Ravnborg52480ee2007-10-12 16:11:50 +020012#include <linux/const.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/types.h>
14
15/* PAGE_SHIFT determines the page size */
16#define PAGE_SHIFT 12
Sam Ravnborg52480ee2007-10-12 16:11:50 +020017#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#define PAGE_MASK (~(PAGE_SIZE-1))
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070019#define PAGE_DEFAULT_ACC 0
20#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#ifdef __KERNEL__
David Woodhouse274f5942006-04-27 04:47:10 +010023#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#ifndef __ASSEMBLY__
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static inline void clear_page(void *page)
27{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020028 register unsigned long reg1 asm ("1") = 0;
29 register void *reg2 asm ("2") = page;
30 register unsigned long reg3 asm ("3") = 4096;
31 asm volatile(
32 " mvcl 2,0"
33 : "+d" (reg2), "+d" (reg3) : "d" (reg1) : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
36static inline void copy_page(void *to, void *from)
37{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020038 if (MACHINE_HAS_MVPG) {
39 register unsigned long reg0 asm ("0") = 0;
40 asm volatile(
41 " mvpg %0,%1"
42 : : "a" (to), "a" (from), "d" (reg0)
43 : "memory", "cc");
44 } else
45 asm volatile(
46 " mvc 0(256,%0),0(%1)\n"
47 " mvc 256(256,%0),256(%1)\n"
48 " mvc 512(256,%0),512(%1)\n"
49 " mvc 768(256,%0),768(%1)\n"
50 " mvc 1024(256,%0),1024(%1)\n"
51 " mvc 1280(256,%0),1280(%1)\n"
52 " mvc 1536(256,%0),1536(%1)\n"
53 " mvc 1792(256,%0),1792(%1)\n"
54 " mvc 2048(256,%0),2048(%1)\n"
55 " mvc 2304(256,%0),2304(%1)\n"
56 " mvc 2560(256,%0),2560(%1)\n"
57 " mvc 2816(256,%0),2816(%1)\n"
58 " mvc 3072(256,%0),3072(%1)\n"
59 " mvc 3328(256,%0),3328(%1)\n"
60 " mvc 3584(256,%0),3584(%1)\n"
61 " mvc 3840(256,%0),3840(%1)\n"
62 : : "a" (to), "a" (from) : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define clear_user_page(page, vaddr, pg) clear_page(page)
66#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
67
Mel Gorman769848c2007-07-17 04:03:05 -070068#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
69 alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/*
73 * These are used to make use of C type-checking..
74 */
75
76typedef struct { unsigned long pgprot; } pgprot_t;
77typedef struct { unsigned long pte; } pte_t;
78
79#define pte_val(x) ((x).pte)
80#define pgprot_val(x) ((x).pgprot)
81
82#ifndef __s390x__
83
84typedef struct { unsigned long pmd; } pmd_t;
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020085typedef struct { unsigned long pud; } pud_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086typedef struct {
87 unsigned long pgd0;
88 unsigned long pgd1;
89 unsigned long pgd2;
90 unsigned long pgd3;
91 } pgd_t;
92
93#define pmd_val(x) ((x).pmd)
Martin Schwidefsky190a1d72007-10-22 12:52:48 +020094#define pud_val(x) ((x).pud)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define pgd_val(x) ((x).pgd0)
96
97#else /* __s390x__ */
98
99typedef struct {
100 unsigned long pmd0;
101 unsigned long pmd1;
102 } pmd_t;
Martin Schwidefsky190a1d72007-10-22 12:52:48 +0200103typedef struct { unsigned long pud; } pud_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104typedef struct { unsigned long pgd; } pgd_t;
105
106#define pmd_val(x) ((x).pmd0)
107#define pmd_val1(x) ((x).pmd1)
Martin Schwidefsky190a1d72007-10-22 12:52:48 +0200108#define pud_val(x) ((x).pud)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define pgd_val(x) ((x).pgd)
110
111#endif /* __s390x__ */
112
113#define __pte(x) ((pte_t) { (x) } )
114#define __pmd(x) ((pmd_t) { (x) } )
115#define __pgd(x) ((pgd_t) { (x) } )
116#define __pgprot(x) ((pgprot_t) { (x) } )
117
118/* default storage key used for all pages */
119extern unsigned int default_storage_key;
120
121static inline void
122page_set_storage_key(unsigned long addr, unsigned int skey)
123{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200124 asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
127static inline unsigned int
128page_get_storage_key(unsigned long addr)
129{
130 unsigned int skey;
131
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200132 asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr), "0" (0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return skey;
134}
135
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100136extern unsigned long max_pfn;
137
138static inline int pfn_valid(unsigned long pfn)
139{
140 unsigned long dummy;
141 int ccode;
142
143 if (pfn >= max_pfn)
144 return 0;
145
146 asm volatile(
147 " lra %0,0(%2)\n"
148 " ipm %1\n"
149 " srl %1,28\n"
150 : "=d" (dummy), "=d" (ccode)
151 : "a" (pfn << PAGE_SHIFT)
152 : "cc");
153 return !ccode;
154}
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#endif /* !__ASSEMBLY__ */
157
158/* to align the pointer to the (next) page boundary */
159#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
160
161#define __PAGE_OFFSET 0x0UL
162#define PAGE_OFFSET 0x0UL
163#define __pa(x) (unsigned long)(x)
164#define __va(x) (void *)(unsigned long)(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
Heiko Carstens0b2b6e12006-10-04 20:02:23 +0200166#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
168
169#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
170 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
171
KAMEZAWA Hiroyukiaed63042006-03-27 01:15:45 -0800172#include <asm-generic/memory_model.h>
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700173#include <asm-generic/page.h>
174
David Woodhouse274f5942006-04-27 04:47:10 +0100175#endif /* __KERNEL__ */
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#endif /* _S390_PAGE_H */