| 1 | /* |
|---|
| 2 | * Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com> |
|---|
| 3 | * Common stuff for memory and page handling. |
|---|
| 4 | * Parts are taken from FreeBSD. |
|---|
| 5 | * |
|---|
| 6 | **************************************************************************** |
|---|
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 8 | * of this software and associated documentation files (the "Software"), to |
|---|
| 9 | * deal in the Software without restriction, including without limitation the |
|---|
| 10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|---|
| 11 | * sell copies of the Software, and to permit persons to whom the Software is |
|---|
| 12 | * furnished to do so, subject to the following conditions: |
|---|
| 13 | * |
|---|
| 14 | * The above copyright notice and this permission notice shall be included in |
|---|
| 15 | * all copies or substantial portions of the Software. |
|---|
| 16 | * |
|---|
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|---|
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|---|
| 23 | * DEALINGS IN THE SOFTWARE. |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #if !defined(_PAGE_H_) |
|---|
| 28 | #define _PAGE_H_ |
|---|
| 29 | |
|---|
| 30 | #include "os.h" |
|---|
| 31 | #include "ia64_cpu.h" |
|---|
| 32 | |
|---|
| 33 | #define PTE_KERNEL_ATTR ((PTE_P<<PTE_P_SHIFT) |\ |
|---|
| 34 | (PTE_MA_WB<<PTE_MA_SHIFT) |\ |
|---|
| 35 | (PTE_D<<PTE_D_SHIFT) |\ |
|---|
| 36 | (PTE_A<<PTE_A_SHIFT) |\ |
|---|
| 37 | (PTE_PL_KERN<<PTE_PL_SHIFT) |\ |
|---|
| 38 | (PTE_AR_RWX<<PTE_AR_SHIFT)) |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | /* The kernel tr page size for text and data. */ |
|---|
| 42 | #define KERNEL_TR_PAGE_SIZE PTE_PS_1M |
|---|
| 43 | /* The efi-pal page size for text and data. */ |
|---|
| 44 | #define PAL_TR_PAGE_SIZE PTE_PS_1M |
|---|
| 45 | |
|---|
| 46 | /* Commonly 16K pages are used. */ |
|---|
| 47 | #define PAGE_SHIFT 14 /* 16K pages */ |
|---|
| 48 | #define PAGE_SIZE (1<<(PAGE_SHIFT)) |
|---|
| 49 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
|---|
| 50 | |
|---|
| 51 | #define KSTACK_PAGES 4 /* 4 pages for the kernel stack + bsp */ |
|---|
| 52 | |
|---|
| 53 | #define IA64_TR_KERNEL 0 /* itr0, dtr0: maps kernel image (code) */ |
|---|
| 54 | #define IA64_TR_PAL 1 /* itr1: maps pal code */ |
|---|
| 55 | |
|---|
| 56 | /* |
|---|
| 57 | * Manipulating region bits of an address. |
|---|
| 58 | */ |
|---|
| 59 | #define IA64_RR_BASE(n) ((UL_TYPE(n)) << 61) |
|---|
| 60 | #define IA64_RR_MASK(x) ((UL_TYPE(x)) & ((1L << 61) - 1)) |
|---|
| 61 | #define IA64_RR_EXTR(x) ((x) >> 61) |
|---|
| 62 | |
|---|
| 63 | #define IA64_PHYS_TO_RR5(x) ((x) | IA64_RR_BASE(5)) |
|---|
| 64 | #define IA64_PHYS_TO_RR7(x) ((x) | IA64_RR_BASE(7)) |
|---|
| 65 | |
|---|
| 66 | #define __pa(x) IA64_RR_MASK(x) |
|---|
| 67 | #define __va(x) IA64_PHYS_TO_RR7(x) |
|---|
| 68 | |
|---|
| 69 | #define roundup_page(x) ((((unsigned long)(x)) + PAGE_SIZE -1) & PAGE_MASK) |
|---|
| 70 | #define trunc_page(x) ((unsigned long)(x) & PAGE_MASK) |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | #if !defined(__ASSEMBLY__) |
|---|
| 74 | |
|---|
| 75 | /* Contains the parts of the physically memory. */ |
|---|
| 76 | extern paddr_t phys_avail[]; |
|---|
| 77 | |
|---|
| 78 | #define page_to_pfn(page) ((uint64_t)(page) >> PAGE_SHIFT) |
|---|
| 79 | #define pfn_to_page(pfn) ((uint64_t)pfn << PAGE_SHIFT) |
|---|
| 80 | /* Get phyiscal address of page of virtual address. */ |
|---|
| 81 | #define virt_to_page(addr) ((uint64_t)__pa(addr) & PAGE_MASK) |
|---|
| 82 | #define virt_to_pfn(addr) (page_to_pfn(virt_to_page(addr))) |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | #endif /* __ASSEMBLY__ */ |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | /* For both see minios-ia64.lds. */ |
|---|
| 89 | /* This is where the kernel virtually starts. */ |
|---|
| 90 | #define KERNEL_START IA64_PHYS_TO_RR5(0x100000000) |
|---|
| 91 | /* !!!!! |
|---|
| 92 | * For physical start of kernel |
|---|
| 93 | * Currently used in arch/ia64/fw.S. |
|---|
| 94 | * !!!!! |
|---|
| 95 | */ |
|---|
| 96 | #define KERNEL_PHYS_START_SHIFT 20 |
|---|
| 97 | |
|---|
| 98 | /* A region 5 address to physical address */ |
|---|
| 99 | #define KERN_VIRT_2_PHYS(x) (((x) - KERNEL_START) + \ |
|---|
| 100 | (1 << KERNEL_PHYS_START_SHIFT)) |
|---|
| 101 | |
|---|
| 102 | // This is xen specific ! |
|---|
| 103 | #define PAGE_SHIFT_XEN_16K 14 // For 16KB page size |
|---|
| 104 | #define mfn_to_virt(mfn) ((void*)__va((mfn) << PAGE_SHIFT_XEN_16K)) |
|---|
| 105 | |
|---|
| 106 | #endif /* !defined(_PAGE_H_) */ |
|---|