ia64/xen-unstable

view extras/mini-os/h/mm.h @ 4146:f2d61710e4d9

bitkeeper revision 1.1236.25.24 (42366e9aQ71LQ8uCB-Y1IwVNqx5eqA)

Merge djm@kirby.fc.hp.com://home/djm/src/xen/xeno-unstable-ia64.bk
into sportsman.spdomain:/home/djm/xeno-unstable-ia64.bk
author djm@sportsman.spdomain
date Tue Mar 15 05:11:54 2005 +0000 (2005-03-15)
parents 7561a06348cf
children
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 *
3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
4 * Copyright (c) 2005, Keir A Fraser
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
25 #ifndef _MM_H_
26 #define _MM_H_
28 #ifdef __x86_64__
30 #define L1_PAGETABLE_SHIFT 12
31 #define L2_PAGETABLE_SHIFT 21
32 #define L3_PAGETABLE_SHIFT 30
33 #define L4_PAGETABLE_SHIFT 39
35 #define L1_PAGETABLE_ENTRIES 512
36 #define L2_PAGETABLE_ENTRIES 512
37 #define L3_PAGETABLE_ENTRIES 512
38 #define L4_PAGETABLE_ENTRIES 512
40 /* These are page-table limitations. Current CPUs support only 40-bit phys. */
41 #define PADDR_BITS 52
42 #define VADDR_BITS 48
43 #define PADDR_MASK ((1UL << PADDR_BITS)-1)
44 #define VADDR_MASK ((1UL << VADDR_BITS)-1)
46 #define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
48 /* Given a virtual address, get an entry offset into a page table. */
49 #define l1_table_offset(_a) \
50 (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
51 #define l2_table_offset(_a) \
52 (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
53 #define l3_table_offset(_a) \
54 (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
55 #define l4_table_offset(_a) \
56 (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
57 #endif
59 #define _PAGE_PRESENT 0x001UL
60 #define _PAGE_RW 0x002UL
61 #define _PAGE_USER 0x004UL
62 #define _PAGE_PWT 0x008UL
63 #define _PAGE_PCD 0x010UL
64 #define _PAGE_ACCESSED 0x020UL
65 #define _PAGE_DIRTY 0x040UL
66 #define _PAGE_PAT 0x080UL
67 #define _PAGE_PSE 0x080UL
68 #define _PAGE_GLOBAL 0x100UL
70 #define PAGE_SHIFT 12
71 #define PAGE_SIZE (1UL << PAGE_SHIFT)
72 #define PAGE_MASK (~(PAGE_SIZE-1))
74 #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
75 #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
76 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
78 /* to align the pointer to the (next) page boundary */
79 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
81 extern unsigned long *phys_to_machine_mapping;
82 #define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
83 #define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
84 static __inline__ unsigned long phys_to_machine(unsigned long phys)
85 {
86 unsigned long machine = pfn_to_mfn(phys >> PAGE_SHIFT);
87 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
88 return machine;
89 }
90 static __inline__ unsigned long machine_to_phys(unsigned long machine)
91 {
92 unsigned long phys = mfn_to_pfn(machine >> PAGE_SHIFT);
93 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
94 return phys;
95 }
97 #ifdef __x86_64__
98 #define VIRT_START 0xFFFFFFFF00000000UL
99 #else
100 #define VIRT_START 0xC0000000UL
101 #endif
103 #define to_phys(x) ((unsigned long)(x)-VIRT_START)
104 #define to_virt(x) ((void *)((unsigned long)(x)+VIRT_START))
105 #define __va to_virt
106 #define __pa to_phys
108 void init_mm(void);
109 unsigned long alloc_pages(int order);
111 #endif /* _MM_H_ */