blob: 5afee8a8cdf39ea0ec3135feab5b45c269daccdd [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
10struct page;
11
12#include <linux/config.h>
13#include <asm/vm-flags.h>
14
15/* PAGE_SHIFT determines the page size */
16#define PAGE_SHIFT 12
17#define PAGE_SIZE (1UL << PAGE_SHIFT)
18#define PAGE_MASK (~(PAGE_SIZE-1))
19
20/*
21 * These are used to make use of C type-checking..
22 */
23
24#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
25#define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
26
27#define clear_user_page(page, vaddr, pg) clear_page(page)
28#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
29
Paolo 'Blaisorblade' Giarrussoc45166be32005-05-01 08:58:54 -070030#if defined(CONFIG_3_LEVEL_PGTABLES) && !defined(CONFIG_64BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32typedef struct { unsigned long pte_low, pte_high; } pte_t;
33typedef struct { unsigned long long pmd; } pmd_t;
34typedef struct { unsigned long pgd; } pgd_t;
35#define pte_val(x) ((x).pte_low | ((unsigned long long) (x).pte_high << 32))
36
37#define pte_get_bits(pte, bits) ((pte).pte_low & (bits))
38#define pte_set_bits(pte, bits) ((pte).pte_low |= (bits))
39#define pte_clear_bits(pte, bits) ((pte).pte_low &= ~(bits))
40#define pte_copy(to, from) ({ (to).pte_high = (from).pte_high; \
41 smp_wmb(); \
42 (to).pte_low = (from).pte_low; })
43#define pte_is_zero(pte) (!((pte).pte_low & ~_PAGE_NEWPAGE) && !(pte).pte_high)
44#define pte_set_val(pte, phys, prot) \
45 ({ (pte).pte_high = (phys) >> 32; \
46 (pte).pte_low = (phys) | pgprot_val(prot); })
47
Paolo 'Blaisorblade' Giarrussof7fe8782005-05-05 16:15:15 -070048#define pmd_val(x) ((x).pmd)
49#define __pmd(x) ((pmd_t) { (x) } )
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051typedef unsigned long long pfn_t;
52typedef unsigned long long phys_t;
53
54#else
55
56typedef struct { unsigned long pte; } pte_t;
57typedef struct { unsigned long pgd; } pgd_t;
58
59#ifdef CONFIG_3_LEVEL_PGTABLES
60typedef struct { unsigned long pmd; } pmd_t;
61#define pmd_val(x) ((x).pmd)
62#define __pmd(x) ((pmd_t) { (x) } )
63#endif
64
65#define pte_val(x) ((x).pte)
66
67
68#define pte_get_bits(p, bits) ((p).pte & (bits))
69#define pte_set_bits(p, bits) ((p).pte |= (bits))
70#define pte_clear_bits(p, bits) ((p).pte &= ~(bits))
71#define pte_copy(to, from) ((to).pte = (from).pte)
72#define pte_is_zero(p) (!((p).pte & ~_PAGE_NEWPAGE))
73#define pte_set_val(p, phys, prot) (p).pte = (phys | pgprot_val(prot))
74
75typedef unsigned long pfn_t;
76typedef unsigned long phys_t;
77
78#endif
79
80typedef struct { unsigned long pgprot; } pgprot_t;
81
82#define pgd_val(x) ((x).pgd)
83#define pgprot_val(x) ((x).pgprot)
84
85#define __pte(x) ((pte_t) { (x) } )
86#define __pgd(x) ((pgd_t) { (x) } )
87#define __pgprot(x) ((pgprot_t) { (x) } )
88
89/* to align the pointer to the (next) page boundary */
90#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
91
92extern unsigned long uml_physmem;
93
94#define PAGE_OFFSET (uml_physmem)
95#define KERNELBASE PAGE_OFFSET
96
97#define __va_space (8*1024*1024)
98
99extern unsigned long to_phys(void *virt);
100extern void *to_virt(unsigned long phys);
Jeff Dikeb9e0d0692005-05-28 15:51:53 -0700101
102/* Cast to unsigned long before casting to void * to avoid a warning from
103 * mmap_kmem about cutting a long long down to a void *. Not sure that
104 * casting is the right thing, but 32-bit UML can't have 64-bit virtual
105 * addresses
106 */
107#define __pa(virt) to_phys((void *) (unsigned long) virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define __va(phys) to_virt((unsigned long) phys)
109
110#define page_to_pfn(page) ((page) - mem_map)
111#define pfn_to_page(pfn) (mem_map + (pfn))
112
113#define phys_to_pfn(p) ((p) >> PAGE_SHIFT)
114#define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
115
116#define pfn_valid(pfn) ((pfn) < max_mapnr)
117#define virt_addr_valid(v) pfn_valid(phys_to_pfn(__pa(v)))
118
119/* Pure 2^n version of get_order */
120static __inline__ int get_order(unsigned long size)
121{
122 int order;
123
124 size = (size-1) >> (PAGE_SHIFT-1);
125 order = -1;
126 do {
127 size >>= 1;
128 order++;
129 } while (size);
130 return order;
131}
132
133extern struct page *arch_validate(struct page *page, int mask, int order);
134#define HAVE_ARCH_VALIDATE
135
136extern void arch_free_page(struct page *page, int order);
137#define HAVE_ARCH_FREE_PAGE
138
139#endif