Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 10 | struct page; |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/vm-flags.h> |
| 13 | |
| 14 | /* PAGE_SHIFT determines the page size */ |
| 15 | #define PAGE_SHIFT 12 |
| 16 | #define PAGE_SIZE (1UL << PAGE_SHIFT) |
| 17 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 18 | |
| 19 | /* |
| 20 | * These are used to make use of C type-checking.. |
| 21 | */ |
| 22 | |
| 23 | #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) |
| 24 | #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE) |
| 25 | |
| 26 | #define clear_user_page(page, vaddr, pg) clear_page(page) |
| 27 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) |
| 28 | |
Paolo 'Blaisorblade' Giarrusso | c45166b | 2005-05-01 08:58:54 -0700 | [diff] [blame] | 29 | #if defined(CONFIG_3_LEVEL_PGTABLES) && !defined(CONFIG_64BIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | typedef struct { unsigned long pte_low, pte_high; } pte_t; |
| 32 | typedef struct { unsigned long long pmd; } pmd_t; |
| 33 | typedef struct { unsigned long pgd; } pgd_t; |
| 34 | #define pte_val(x) ((x).pte_low | ((unsigned long long) (x).pte_high << 32)) |
| 35 | |
| 36 | #define pte_get_bits(pte, bits) ((pte).pte_low & (bits)) |
| 37 | #define pte_set_bits(pte, bits) ((pte).pte_low |= (bits)) |
| 38 | #define pte_clear_bits(pte, bits) ((pte).pte_low &= ~(bits)) |
| 39 | #define pte_copy(to, from) ({ (to).pte_high = (from).pte_high; \ |
| 40 | smp_wmb(); \ |
| 41 | (to).pte_low = (from).pte_low; }) |
| 42 | #define pte_is_zero(pte) (!((pte).pte_low & ~_PAGE_NEWPAGE) && !(pte).pte_high) |
| 43 | #define pte_set_val(pte, phys, prot) \ |
| 44 | ({ (pte).pte_high = (phys) >> 32; \ |
| 45 | (pte).pte_low = (phys) | pgprot_val(prot); }) |
| 46 | |
Paolo 'Blaisorblade' Giarrusso | f7fe878 | 2005-05-05 16:15:15 -0700 | [diff] [blame] | 47 | #define pmd_val(x) ((x).pmd) |
| 48 | #define __pmd(x) ((pmd_t) { (x) } ) |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | typedef unsigned long long pfn_t; |
| 51 | typedef unsigned long long phys_t; |
| 52 | |
| 53 | #else |
| 54 | |
| 55 | typedef struct { unsigned long pte; } pte_t; |
| 56 | typedef struct { unsigned long pgd; } pgd_t; |
| 57 | |
| 58 | #ifdef CONFIG_3_LEVEL_PGTABLES |
| 59 | typedef struct { unsigned long pmd; } pmd_t; |
| 60 | #define pmd_val(x) ((x).pmd) |
| 61 | #define __pmd(x) ((pmd_t) { (x) } ) |
| 62 | #endif |
| 63 | |
| 64 | #define pte_val(x) ((x).pte) |
| 65 | |
| 66 | |
| 67 | #define pte_get_bits(p, bits) ((p).pte & (bits)) |
| 68 | #define pte_set_bits(p, bits) ((p).pte |= (bits)) |
| 69 | #define pte_clear_bits(p, bits) ((p).pte &= ~(bits)) |
| 70 | #define pte_copy(to, from) ((to).pte = (from).pte) |
| 71 | #define pte_is_zero(p) (!((p).pte & ~_PAGE_NEWPAGE)) |
| 72 | #define pte_set_val(p, phys, prot) (p).pte = (phys | pgprot_val(prot)) |
| 73 | |
| 74 | typedef unsigned long pfn_t; |
| 75 | typedef unsigned long phys_t; |
| 76 | |
| 77 | #endif |
| 78 | |
| 79 | typedef struct { unsigned long pgprot; } pgprot_t; |
| 80 | |
| 81 | #define pgd_val(x) ((x).pgd) |
| 82 | #define pgprot_val(x) ((x).pgprot) |
| 83 | |
| 84 | #define __pte(x) ((pte_t) { (x) } ) |
| 85 | #define __pgd(x) ((pgd_t) { (x) } ) |
| 86 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 87 | |
| 88 | /* to align the pointer to the (next) page boundary */ |
| 89 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) |
| 90 | |
| 91 | extern unsigned long uml_physmem; |
| 92 | |
| 93 | #define PAGE_OFFSET (uml_physmem) |
| 94 | #define KERNELBASE PAGE_OFFSET |
| 95 | |
| 96 | #define __va_space (8*1024*1024) |
| 97 | |
Paolo 'Blaisorblade' Giarrusso | d99c402 | 2005-09-10 19:44:56 +0200 | [diff] [blame] | 98 | #include "mem.h" |
Jeff Dike | b9e0d06 | 2005-05-28 15:51:53 -0700 | [diff] [blame] | 99 | |
| 100 | /* Cast to unsigned long before casting to void * to avoid a warning from |
| 101 | * mmap_kmem about cutting a long long down to a void *. Not sure that |
| 102 | * casting is the right thing, but 32-bit UML can't have 64-bit virtual |
| 103 | * addresses |
| 104 | */ |
Linus Torvalds | 75cd968 | 2005-08-15 17:40:46 -0700 | [diff] [blame] | 105 | #define __pa(virt) to_phys((void *) (unsigned long) (virt)) |
| 106 | #define __va(phys) to_virt((unsigned long) (phys)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define phys_to_pfn(p) ((p) >> PAGE_SHIFT) |
| 109 | #define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT) |
| 110 | |
| 111 | #define pfn_valid(pfn) ((pfn) < max_mapnr) |
| 112 | #define virt_addr_valid(v) pfn_valid(phys_to_pfn(__pa(v))) |
| 113 | |
Al Viro | 53f9fc9 | 2005-10-21 03:22:24 -0400 | [diff] [blame] | 114 | extern struct page *arch_validate(struct page *page, gfp_t mask, int order); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #define HAVE_ARCH_VALIDATE |
| 116 | |
KAMEZAWA Hiroyuki | 9828c18 | 2006-03-27 01:15:50 -0800 | [diff] [blame] | 117 | #include <asm-generic/memory_model.h> |
Stephen Rothwell | fd4fd5a | 2005-09-03 15:54:30 -0700 | [diff] [blame] | 118 | #include <asm-generic/page.h> |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #endif |