[30ef8ce] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 - 2006 Jakub Jermar
|
---|
| 3 | * Copyright (c) 2006 Jakub Vana
|
---|
[30ef8ce] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[7f1c620] | 30 | /** @addtogroup ia64mm
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[06e1e95] | 36 | #ifndef KERN_ia64_PAGE_H_
|
---|
| 37 | #define KERN_ia64_PAGE_H_
|
---|
[30ef8ce] | 38 |
|
---|
[d1f8a87] | 39 | #include <arch/mm/frame.h>
|
---|
| 40 |
|
---|
[30ef8ce] | 41 | #define PAGE_SIZE FRAME_SIZE
|
---|
[fd537a0] | 42 | #define PAGE_WIDTH FRAME_WIDTH
|
---|
[30ef8ce] | 43 |
|
---|
[d1f8a87] | 44 | #ifdef KERNEL
|
---|
| 45 |
|
---|
[a0d74fd] | 46 | /** Bit width of the TLB-locked portion of kernel address space. */
|
---|
[d0485c6] | 47 | #define KERNEL_PAGE_WIDTH 28 /* 256M */
|
---|
[7208b6c] | 48 | #define IO_PAGE_WIDTH 26 /* 64M */
|
---|
[59e4864] | 49 | #define FW_PAGE_WIDTH 28 /* 256M */
|
---|
| 50 |
|
---|
| 51 | /** Staticly mapped IO spaces */
|
---|
| 52 |
|
---|
| 53 | /* Firmware area (bellow 4GB in phys mem) */
|
---|
| 54 | #define FW_OFFSET 0x00000000F0000000
|
---|
| 55 | /* Legacy IO space */
|
---|
| 56 | #define IO_OFFSET 0x0001000000000000
|
---|
| 57 | /* Videoram - now mapped to 0 as VGA text mode vram on 0xb8000*/
|
---|
| 58 | #define VIO_OFFSET 0x0002000000000000
|
---|
| 59 |
|
---|
| 60 |
|
---|
[7208b6c] | 61 |
|
---|
[30ef8ce] | 62 |
|
---|
[457d18a] | 63 | #define PPN_SHIFT 12
|
---|
[0c0410b] | 64 |
|
---|
[849386a] | 65 | #define VRN_SHIFT 61
|
---|
| 66 | #define VRN_MASK (7LL << VRN_SHIFT)
|
---|
[a0d74fd] | 67 | #define VA2VRN(va) ((va)>>VRN_SHIFT)
|
---|
[5ac2e61] | 68 |
|
---|
| 69 | #ifdef __ASM__
|
---|
| 70 | #define VRN_KERNEL 7
|
---|
| 71 | #else
|
---|
| 72 | #define VRN_KERNEL 7LL
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
[c2b95d3] | 75 | #define REGION_REGISTERS 8
|
---|
[fd537a0] | 76 |
|
---|
[7f1c620] | 77 | #define KA2PA(x) ((uintptr_t) (x-(VRN_KERNEL<<VRN_SHIFT)))
|
---|
| 78 | #define PA2KA(x) ((uintptr_t) (x+(VRN_KERNEL<<VRN_SHIFT)))
|
---|
[5ac2e61] | 79 |
|
---|
[d0485c6] | 80 | #define VHPT_WIDTH 20 /* 1M */
|
---|
[c7ec94a4] | 81 | #define VHPT_SIZE (1 << VHPT_WIDTH)
|
---|
[fd537a0] | 82 |
|
---|
[df09142f] | 83 | #define PTA_BASE_SHIFT 15
|
---|
| 84 |
|
---|
[457d18a] | 85 | /** Memory Attributes. */
|
---|
| 86 | #define MA_WRITEBACK 0x0
|
---|
| 87 | #define MA_UNCACHEABLE 0x4
|
---|
| 88 |
|
---|
| 89 | /** Privilege Levels. Only the most and the least privileged ones are ever used. */
|
---|
| 90 | #define PL_KERNEL 0x0
|
---|
| 91 | #define PL_USER 0x3
|
---|
| 92 |
|
---|
| 93 | /* Access Rigths. Only certain combinations are used by the kernel. */
|
---|
| 94 | #define AR_READ 0x0
|
---|
| 95 | #define AR_EXECUTE 0x1
|
---|
| 96 | #define AR_WRITE 0x2
|
---|
| 97 |
|
---|
[5ac2e61] | 98 | #ifndef __ASM__
|
---|
[bc78c75] | 99 |
|
---|
[b3f8fb7] | 100 | #include <arch/mm/as.h>
|
---|
[a0d74fd] | 101 | #include <arch/mm/frame.h>
|
---|
[b3f8fb7] | 102 | #include <arch/interrupt.h>
|
---|
[a0d74fd] | 103 | #include <arch/barrier.h>
|
---|
| 104 | #include <arch/mm/asid.h>
|
---|
| 105 | #include <arch/types.h>
|
---|
| 106 | #include <debug.h>
|
---|
| 107 |
|
---|
[c2b95d3] | 108 | struct vhpt_tag_info {
|
---|
| 109 | unsigned long long tag : 63;
|
---|
| 110 | unsigned ti : 1;
|
---|
| 111 | } __attribute__ ((packed));
|
---|
[8c0d692] | 112 |
|
---|
[c2b95d3] | 113 | union vhpt_tag {
|
---|
| 114 | struct vhpt_tag_info tag_info;
|
---|
| 115 | unsigned tag_word;
|
---|
[8c0d692] | 116 | };
|
---|
| 117 |
|
---|
[c2b95d3] | 118 | struct vhpt_entry_present {
|
---|
[8c0d692] | 119 | /* Word 0 */
|
---|
[c2b95d3] | 120 | unsigned p : 1;
|
---|
| 121 | unsigned : 1;
|
---|
| 122 | unsigned ma : 3;
|
---|
| 123 | unsigned a : 1;
|
---|
| 124 | unsigned d : 1;
|
---|
| 125 | unsigned pl : 2;
|
---|
| 126 | unsigned ar : 3;
|
---|
| 127 | unsigned long long ppn : 38;
|
---|
| 128 | unsigned : 2;
|
---|
| 129 | unsigned ed : 1;
|
---|
| 130 | unsigned ig1 : 11;
|
---|
[8c0d692] | 131 |
|
---|
| 132 | /* Word 1 */
|
---|
[c2b95d3] | 133 | unsigned : 2;
|
---|
| 134 | unsigned ps : 6;
|
---|
| 135 | unsigned key : 24;
|
---|
| 136 | unsigned : 32;
|
---|
[8c0d692] | 137 |
|
---|
| 138 | /* Word 2 */
|
---|
[c2b95d3] | 139 | union vhpt_tag tag;
|
---|
[8c0d692] | 140 |
|
---|
[c2b95d3] | 141 | /* Word 3 */
|
---|
[7f1c620] | 142 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 143 | } __attribute__ ((packed));
|
---|
[8c0d692] | 144 |
|
---|
[c2b95d3] | 145 | struct vhpt_entry_not_present {
|
---|
[8c0d692] | 146 | /* Word 0 */
|
---|
[c2b95d3] | 147 | unsigned p : 1;
|
---|
| 148 | unsigned long long ig0 : 52;
|
---|
| 149 | unsigned ig1 : 11;
|
---|
[8c0d692] | 150 |
|
---|
| 151 | /* Word 1 */
|
---|
[c2b95d3] | 152 | unsigned : 2;
|
---|
| 153 | unsigned ps : 6;
|
---|
| 154 | unsigned long long ig2 : 56;
|
---|
[8c0d692] | 155 |
|
---|
| 156 | /* Word 2 */
|
---|
[c2b95d3] | 157 | union vhpt_tag tag;
|
---|
| 158 |
|
---|
[8c0d692] | 159 | /* Word 3 */
|
---|
[7f1c620] | 160 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 161 | } __attribute__ ((packed));
|
---|
| 162 |
|
---|
| 163 | typedef union vhpt_entry {
|
---|
| 164 | struct vhpt_entry_present present;
|
---|
| 165 | struct vhpt_entry_not_present not_present;
|
---|
[7f1c620] | 166 | uint64_t word[4];
|
---|
[c7ec94a4] | 167 | } vhpt_entry_t;
|
---|
[c2b95d3] | 168 |
|
---|
| 169 | struct region_register_map {
|
---|
| 170 | unsigned ve : 1;
|
---|
| 171 | unsigned : 1;
|
---|
| 172 | unsigned ps : 6;
|
---|
| 173 | unsigned rid : 24;
|
---|
| 174 | unsigned : 32;
|
---|
| 175 | } __attribute__ ((packed));
|
---|
| 176 |
|
---|
| 177 | typedef union region_register {
|
---|
| 178 | struct region_register_map map;
|
---|
| 179 | unsigned long long word;
|
---|
| 180 | } region_register;
|
---|
| 181 |
|
---|
| 182 | struct pta_register_map {
|
---|
| 183 | unsigned ve : 1;
|
---|
| 184 | unsigned : 1;
|
---|
| 185 | unsigned size : 6;
|
---|
| 186 | unsigned vf : 1;
|
---|
| 187 | unsigned : 6;
|
---|
| 188 | unsigned long long base : 49;
|
---|
| 189 | } __attribute__ ((packed));
|
---|
| 190 |
|
---|
| 191 | typedef union pta_register {
|
---|
| 192 | struct pta_register_map map;
|
---|
[7f1c620] | 193 | uint64_t word;
|
---|
[c2b95d3] | 194 | } pta_register;
|
---|
| 195 |
|
---|
| 196 | /** Return Translation Hashed Entry Address.
|
---|
| 197 | *
|
---|
| 198 | * VRN bits are used to read RID (ASID) from one
|
---|
| 199 | * of the eight region registers registers.
|
---|
| 200 | *
|
---|
| 201 | * @param va Virtual address including VRN bits.
|
---|
| 202 | *
|
---|
| 203 | * @return Address of the head of VHPT collision chain.
|
---|
| 204 | */
|
---|
[7f1c620] | 205 | static inline uint64_t thash(uint64_t va)
|
---|
[8c0d692] | 206 | {
|
---|
[7f1c620] | 207 | uint64_t ret;
|
---|
[8c0d692] | 208 |
|
---|
[e7b7be3f] | 209 | asm volatile ("thash %0 = %1\n" : "=r" (ret) : "r" (va));
|
---|
[6d7ffa65] | 210 |
|
---|
[c2b95d3] | 211 | return ret;
|
---|
| 212 | }
|
---|
[fd537a0] | 213 |
|
---|
[c2b95d3] | 214 | /** Return Translation Hashed Entry Tag.
|
---|
| 215 | *
|
---|
| 216 | * VRN bits are used to read RID (ASID) from one
|
---|
| 217 | * of the eight region registers.
|
---|
| 218 | *
|
---|
| 219 | * @param va Virtual address including VRN bits.
|
---|
| 220 | *
|
---|
| 221 | * @return The unique tag for VPN and RID in the collision chain returned by thash().
|
---|
| 222 | */
|
---|
[7f1c620] | 223 | static inline uint64_t ttag(uint64_t va)
|
---|
[fd537a0] | 224 | {
|
---|
[7f1c620] | 225 | uint64_t ret;
|
---|
[fd537a0] | 226 |
|
---|
[e7b7be3f] | 227 | asm volatile ("ttag %0 = %1\n" : "=r" (ret) : "r" (va));
|
---|
[fd537a0] | 228 |
|
---|
[c2b95d3] | 229 | return ret;
|
---|
| 230 | }
|
---|
[fd537a0] | 231 |
|
---|
[c2b95d3] | 232 | /** Read Region Register.
|
---|
| 233 | *
|
---|
| 234 | * @param i Region register index.
|
---|
| 235 | *
|
---|
| 236 | * @return Current contents of rr[i].
|
---|
| 237 | */
|
---|
[7f1c620] | 238 | static inline uint64_t rr_read(index_t i)
|
---|
[fd537a0] | 239 | {
|
---|
[7f1c620] | 240 | uint64_t ret;
|
---|
[849386a] | 241 | ASSERT(i < REGION_REGISTERS);
|
---|
[e7b7be3f] | 242 | asm volatile ("mov %0 = rr[%1]\n" : "=r" (ret) : "r" (i << VRN_SHIFT));
|
---|
[c2b95d3] | 243 | return ret;
|
---|
| 244 | }
|
---|
[fd537a0] | 245 |
|
---|
[c2b95d3] | 246 | /** Write Region Register.
|
---|
| 247 | *
|
---|
| 248 | * @param i Region register index.
|
---|
| 249 | * @param v Value to be written to rr[i].
|
---|
| 250 | */
|
---|
[7f1c620] | 251 | static inline void rr_write(index_t i, uint64_t v)
|
---|
[fd537a0] | 252 | {
|
---|
[849386a] | 253 | ASSERT(i < REGION_REGISTERS);
|
---|
[e7b7be3f] | 254 | asm volatile (
|
---|
[a0d74fd] | 255 | "mov rr[%0] = %1\n"
|
---|
| 256 | :
|
---|
| 257 | : "r" (i << VRN_SHIFT), "r" (v)
|
---|
| 258 | );
|
---|
[c2b95d3] | 259 | }
|
---|
| 260 |
|
---|
| 261 | /** Read Page Table Register.
|
---|
| 262 | *
|
---|
| 263 | * @return Current value stored in PTA.
|
---|
| 264 | */
|
---|
[7f1c620] | 265 | static inline uint64_t pta_read(void)
|
---|
[c2b95d3] | 266 | {
|
---|
[7f1c620] | 267 | uint64_t ret;
|
---|
[c2b95d3] | 268 |
|
---|
[e7b7be3f] | 269 | asm volatile ("mov %0 = cr.pta\n" : "=r" (ret));
|
---|
[c2b95d3] | 270 |
|
---|
| 271 | return ret;
|
---|
| 272 | }
|
---|
[fd537a0] | 273 |
|
---|
[c2b95d3] | 274 | /** Write Page Table Register.
|
---|
| 275 | *
|
---|
| 276 | * @param v New value to be stored in PTA.
|
---|
| 277 | */
|
---|
[7f1c620] | 278 | static inline void pta_write(uint64_t v)
|
---|
[c2b95d3] | 279 | {
|
---|
[e7b7be3f] | 280 | asm volatile ("mov cr.pta = %0\n" : : "r" (v));
|
---|
[c2b95d3] | 281 | }
|
---|
| 282 |
|
---|
| 283 | extern void page_arch_init(void);
|
---|
[c7ec94a4] | 284 |
|
---|
[7f1c620] | 285 | extern vhpt_entry_t *vhpt_hash(uintptr_t page, asid_t asid);
|
---|
| 286 | extern bool vhpt_compare(uintptr_t page, asid_t asid, vhpt_entry_t *v);
|
---|
| 287 | extern void vhpt_set_record(vhpt_entry_t *v, uintptr_t page, asid_t asid, uintptr_t frame, int flags);
|
---|
[fd537a0] | 288 |
|
---|
[d1f8a87] | 289 | #endif /* __ASM__ */
|
---|
| 290 |
|
---|
| 291 | #endif /* KERNEL */
|
---|
[5ac2e61] | 292 |
|
---|
[30ef8ce] | 293 | #endif
|
---|
[b45c443] | 294 |
|
---|
[7f1c620] | 295 | /** @}
|
---|
[b45c443] | 296 | */
|
---|