blob: e13d41c392ae4f4940a41e6c8049099c71d28a04 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
3 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
5 */
6
7#ifndef __UM_PAGE_H
8#define __UM_PAGE_H
9
Cyrill Gorcunova7dfa942008-05-12 14:01:56 -070010#include <linux/const.h>
11
12/* PAGE_SHIFT determines the page size */
13#define PAGE_SHIFT 12
14#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
15#define PAGE_MASK (~(PAGE_SIZE-1))
16
17#ifndef __ASSEMBLY__
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019struct page;
20
Dan Williams16da3062016-01-15 16:56:08 -080021#include <linux/pfn.h>
Jeff Dikee8012b52007-10-16 01:27:16 -070022#include <linux/types.h>
Al Viroab785c12011-08-18 20:02:19 +010023#include <asm/vm-flags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*
26 * These are used to make use of C type-checking..
27 */
28
29#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
30#define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
31
32#define clear_user_page(page, vaddr, pg) clear_page(page)
33#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
34
Paolo 'Blaisorblade' Giarrussoc45166be32005-05-01 08:58:54 -070035#if defined(CONFIG_3_LEVEL_PGTABLES) && !defined(CONFIG_64BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37typedef struct { unsigned long pte_low, pte_high; } pte_t;
Jeff Dike655e4ed2008-02-04 22:30:55 -080038typedef struct { unsigned long pmd; } pmd_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039typedef struct { unsigned long pgd; } pgd_t;
40#define pte_val(x) ((x).pte_low | ((unsigned long long) (x).pte_high << 32))
41
42#define pte_get_bits(pte, bits) ((pte).pte_low & (bits))
43#define pte_set_bits(pte, bits) ((pte).pte_low |= (bits))
44#define pte_clear_bits(pte, bits) ((pte).pte_low &= ~(bits))
45#define pte_copy(to, from) ({ (to).pte_high = (from).pte_high; \
46 smp_wmb(); \
47 (to).pte_low = (from).pte_low; })
48#define pte_is_zero(pte) (!((pte).pte_low & ~_PAGE_NEWPAGE) && !(pte).pte_high)
49#define pte_set_val(pte, phys, prot) \
50 ({ (pte).pte_high = (phys) >> 32; \
51 (pte).pte_low = (phys) | pgprot_val(prot); })
52
Paolo 'Blaisorblade' Giarrussof7fe8782005-05-05 16:15:15 -070053#define pmd_val(x) ((x).pmd)
54#define __pmd(x) ((pmd_t) { (x) } )
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056typedef unsigned long long phys_t;
57
58#else
59
60typedef struct { unsigned long pte; } pte_t;
61typedef struct { unsigned long pgd; } pgd_t;
62
63#ifdef CONFIG_3_LEVEL_PGTABLES
64typedef struct { unsigned long pmd; } pmd_t;
65#define pmd_val(x) ((x).pmd)
66#define __pmd(x) ((pmd_t) { (x) } )
67#endif
68
69#define pte_val(x) ((x).pte)
70
71
72#define pte_get_bits(p, bits) ((p).pte & (bits))
73#define pte_set_bits(p, bits) ((p).pte |= (bits))
74#define pte_clear_bits(p, bits) ((p).pte &= ~(bits))
75#define pte_copy(to, from) ((to).pte = (from).pte)
76#define pte_is_zero(p) (!((p).pte & ~_PAGE_NEWPAGE))
77#define pte_set_val(p, phys, prot) (p).pte = (phys | pgprot_val(prot))
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079typedef unsigned long phys_t;
80
81#endif
82
83typedef struct { unsigned long pgprot; } pgprot_t;
84
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080085typedef struct page *pgtable_t;
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define pgd_val(x) ((x).pgd)
88#define pgprot_val(x) ((x).pgprot)
89
90#define __pte(x) ((pte_t) { (x) } )
91#define __pgd(x) ((pgd_t) { (x) } )
92#define __pgprot(x) ((pgprot_t) { (x) } )
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern unsigned long uml_physmem;
95
96#define PAGE_OFFSET (uml_physmem)
97#define KERNELBASE PAGE_OFFSET
98
99#define __va_space (8*1024*1024)
100
Al Viro37185b32012-10-08 03:27:32 +0100101#include <mem.h>
Jeff Dikeb9e0d0692005-05-28 15:51:53 -0700102
103/* Cast to unsigned long before casting to void * to avoid a warning from
104 * mmap_kmem about cutting a long long down to a void *. Not sure that
105 * casting is the right thing, but 32-bit UML can't have 64-bit virtual
106 * addresses
107 */
Linus Torvalds75cd9682005-08-15 17:40:46 -0700108#define __pa(virt) to_phys((void *) (unsigned long) (virt))
109#define __va(phys) to_virt((unsigned long) (phys))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Dan Williams16da3062016-01-15 16:56:08 -0800111#define phys_to_pfn(p) ((p) >> PAGE_SHIFT)
112#define pfn_to_phys(pfn) PFN_PHYS(pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114#define pfn_valid(pfn) ((pfn) < max_mapnr)
115#define virt_addr_valid(v) pfn_valid(phys_to_pfn(__pa(v)))
116
KAMEZAWA Hiroyuki9828c182006-03-27 01:15:50 -0800117#include <asm-generic/memory_model.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +0000118#include <asm-generic/getorder.h>
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700119
Cyrill Gorcunova7dfa942008-05-12 14:01:56 -0700120#endif /* __ASSEMBLY__ */
Andy Lutomirskia6c19df2014-08-08 14:23:40 -0700121
122#ifdef CONFIG_X86_32
123#define __HAVE_ARCH_GATE_AREA 1
124#endif
125
Cyrill Gorcunova7dfa942008-05-12 14:01:56 -0700126#endif /* __UM_PAGE_H */