[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 |
|
---|
[5bda2f3e] | 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 |
|
---|
[5bda2f3e] | 41 | #define PAGE_SIZE FRAME_SIZE
|
---|
| 42 | #define PAGE_WIDTH FRAME_WIDTH
|
---|
[30ef8ce] | 43 |
|
---|
[a0d74fd] | 44 | /** Bit width of the TLB-locked portion of kernel address space. */
|
---|
[5bda2f3e] | 45 | #define KERNEL_PAGE_WIDTH 28 /* 256M */
|
---|
| 46 | #define IO_PAGE_WIDTH 26 /* 64M */
|
---|
| 47 | #define FW_PAGE_WIDTH 28 /* 256M */
|
---|
[59e4864] | 48 |
|
---|
[5bda2f3e] | 49 | #define USPACE_IO_PAGE_WIDTH 12 /* 4K */
|
---|
[46321fb] | 50 |
|
---|
| 51 |
|
---|
[8b4d6cb] | 52 | /*
|
---|
| 53 | * Statically mapped IO spaces - offsets to 0xe...00 of virtual addresses
|
---|
| 54 | * because of "minimal virtual bits implemented is 51" it is possible to
|
---|
| 55 | * have values up to 0x0007000000000000
|
---|
| 56 | */
|
---|
[59e4864] | 57 |
|
---|
| 58 | /* Firmware area (bellow 4GB in phys mem) */
|
---|
[056ddc30] | 59 | #define FW_OFFSET 0x00000000F0000000 // FIXME: [non-ident]
|
---|
[59e4864] | 60 | /* Legacy IO space */
|
---|
[056ddc30] | 61 | #define IO_OFFSET 0x0001000000000000 // FIXME: [non-ident]
|
---|
[8b4d6cb] | 62 | /* Videoram - now mapped to 0 as VGA text mode vram on 0xb8000 */
|
---|
[056ddc30] | 63 | #define VIO_OFFSET 0x0002000000000000 // FIXME: [non-ident]
|
---|
[59e4864] | 64 |
|
---|
| 65 |
|
---|
[5bda2f3e] | 66 | #define PPN_SHIFT 12
|
---|
[0c0410b] | 67 |
|
---|
[5bda2f3e] | 68 | #define VRN_SHIFT 61
|
---|
| 69 | #define VRN_MASK (7ULL << VRN_SHIFT)
|
---|
| 70 | #define VA2VRN(va) ((va) >> VRN_SHIFT)
|
---|
[5ac2e61] | 71 |
|
---|
| 72 | #ifdef __ASM__
|
---|
[5bda2f3e] | 73 | #define VRN_KERNEL 7
|
---|
[5ac2e61] | 74 | #else
|
---|
[5bda2f3e] | 75 | #define VRN_KERNEL 7ULL
|
---|
[5ac2e61] | 76 | #endif
|
---|
| 77 |
|
---|
[5bda2f3e] | 78 | #define REGION_REGISTERS 8
|
---|
[fd537a0] | 79 |
|
---|
[5bda2f3e] | 80 | #define KA2PA(x) ((uintptr_t) ((x) - (VRN_KERNEL << VRN_SHIFT)))
|
---|
| 81 | #define PA2KA(x) ((uintptr_t) ((x) + (VRN_KERNEL << VRN_SHIFT)))
|
---|
[5ac2e61] | 82 |
|
---|
[5bda2f3e] | 83 | #define VHPT_WIDTH 20 /* 1M */
|
---|
| 84 | #define VHPT_SIZE (1 << VHPT_WIDTH)
|
---|
[fd537a0] | 85 |
|
---|
[5bda2f3e] | 86 | #define PTA_BASE_SHIFT 15
|
---|
[df09142f] | 87 |
|
---|
[457d18a] | 88 | /** Memory Attributes. */
|
---|
[5bda2f3e] | 89 | #define MA_WRITEBACK 0x00
|
---|
| 90 | #define MA_UNCACHEABLE 0x04
|
---|
[457d18a] | 91 |
|
---|
| 92 | /** Privilege Levels. Only the most and the least privileged ones are ever used. */
|
---|
[5bda2f3e] | 93 | #define PL_KERNEL 0x00
|
---|
| 94 | #define PL_USER 0x03
|
---|
[457d18a] | 95 |
|
---|
| 96 | /* Access Rigths. Only certain combinations are used by the kernel. */
|
---|
[5bda2f3e] | 97 | #define AR_READ 0x00
|
---|
| 98 | #define AR_EXECUTE 0x01
|
---|
| 99 | #define AR_WRITE 0x02
|
---|
[457d18a] | 100 |
|
---|
[5ac2e61] | 101 | #ifndef __ASM__
|
---|
[bc78c75] | 102 |
|
---|
[b3f8fb7] | 103 | #include <arch/mm/as.h>
|
---|
[a0d74fd] | 104 | #include <arch/mm/frame.h>
|
---|
[b3f8fb7] | 105 | #include <arch/interrupt.h>
|
---|
[a0d74fd] | 106 | #include <arch/barrier.h>
|
---|
| 107 | #include <arch/mm/asid.h>
|
---|
[d99c1d2] | 108 | #include <typedefs.h>
|
---|
[a0d74fd] | 109 | #include <debug.h>
|
---|
| 110 |
|
---|
[c2b95d3] | 111 | struct vhpt_tag_info {
|
---|
| 112 | unsigned long long tag : 63;
|
---|
[5bda2f3e] | 113 | unsigned int ti : 1;
|
---|
[c2b95d3] | 114 | } __attribute__ ((packed));
|
---|
[8c0d692] | 115 |
|
---|
[c2b95d3] | 116 | union vhpt_tag {
|
---|
| 117 | struct vhpt_tag_info tag_info;
|
---|
| 118 | unsigned tag_word;
|
---|
[8c0d692] | 119 | };
|
---|
| 120 |
|
---|
[c2b95d3] | 121 | struct vhpt_entry_present {
|
---|
[8c0d692] | 122 | /* Word 0 */
|
---|
[5bda2f3e] | 123 | unsigned int p : 1;
|
---|
| 124 | unsigned int : 1;
|
---|
| 125 | unsigned int ma : 3;
|
---|
| 126 | unsigned int a : 1;
|
---|
| 127 | unsigned int d : 1;
|
---|
| 128 | unsigned int pl : 2;
|
---|
| 129 | unsigned int ar : 3;
|
---|
[c2b95d3] | 130 | unsigned long long ppn : 38;
|
---|
[5bda2f3e] | 131 | unsigned int : 2;
|
---|
| 132 | unsigned int ed : 1;
|
---|
| 133 | unsigned int ig1 : 11;
|
---|
[8c0d692] | 134 |
|
---|
| 135 | /* Word 1 */
|
---|
[5bda2f3e] | 136 | unsigned int : 2;
|
---|
| 137 | unsigned int ps : 6;
|
---|
| 138 | unsigned int key : 24;
|
---|
| 139 | unsigned int : 32;
|
---|
[8c0d692] | 140 |
|
---|
| 141 | /* Word 2 */
|
---|
[c2b95d3] | 142 | union vhpt_tag tag;
|
---|
[8c0d692] | 143 |
|
---|
[5bda2f3e] | 144 | /* Word 3 */
|
---|
[7f1c620] | 145 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 146 | } __attribute__ ((packed));
|
---|
[8c0d692] | 147 |
|
---|
[c2b95d3] | 148 | struct vhpt_entry_not_present {
|
---|
[8c0d692] | 149 | /* Word 0 */
|
---|
[5bda2f3e] | 150 | unsigned int p : 1;
|
---|
[c2b95d3] | 151 | unsigned long long ig0 : 52;
|
---|
[5bda2f3e] | 152 | unsigned int ig1 : 11;
|
---|
[8c0d692] | 153 |
|
---|
| 154 | /* Word 1 */
|
---|
[5bda2f3e] | 155 | unsigned int : 2;
|
---|
| 156 | unsigned int ps : 6;
|
---|
[c2b95d3] | 157 | unsigned long long ig2 : 56;
|
---|
[5bda2f3e] | 158 |
|
---|
[8c0d692] | 159 | /* Word 2 */
|
---|
[c2b95d3] | 160 | union vhpt_tag tag;
|
---|
| 161 |
|
---|
[5bda2f3e] | 162 | /* Word 3 */
|
---|
[7f1c620] | 163 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 164 | } __attribute__ ((packed));
|
---|
| 165 |
|
---|
[5bda2f3e] | 166 | typedef union {
|
---|
[c2b95d3] | 167 | struct vhpt_entry_present present;
|
---|
| 168 | struct vhpt_entry_not_present not_present;
|
---|
[7f1c620] | 169 | uint64_t word[4];
|
---|
[c7ec94a4] | 170 | } vhpt_entry_t;
|
---|
[c2b95d3] | 171 |
|
---|
| 172 | struct region_register_map {
|
---|
[5bda2f3e] | 173 | unsigned int ve : 1;
|
---|
| 174 | unsigned int : 1;
|
---|
| 175 | unsigned int ps : 6;
|
---|
| 176 | unsigned int rid : 24;
|
---|
| 177 | unsigned int : 32;
|
---|
[c2b95d3] | 178 | } __attribute__ ((packed));
|
---|
| 179 |
|
---|
[5bda2f3e] | 180 | typedef union {
|
---|
[c2b95d3] | 181 | struct region_register_map map;
|
---|
| 182 | unsigned long long word;
|
---|
[5bda2f3e] | 183 | } region_register_t;
|
---|
[c2b95d3] | 184 |
|
---|
| 185 | struct pta_register_map {
|
---|
[5bda2f3e] | 186 | unsigned int ve : 1;
|
---|
| 187 | unsigned int : 1;
|
---|
| 188 | unsigned int size : 6;
|
---|
| 189 | unsigned int vf : 1;
|
---|
| 190 | unsigned int : 6;
|
---|
[c2b95d3] | 191 | unsigned long long base : 49;
|
---|
| 192 | } __attribute__ ((packed));
|
---|
| 193 |
|
---|
| 194 | typedef union pta_register {
|
---|
| 195 | struct pta_register_map map;
|
---|
[7f1c620] | 196 | uint64_t word;
|
---|
[5bda2f3e] | 197 | } pta_register_t;
|
---|
[c2b95d3] | 198 |
|
---|
| 199 | /** Return Translation Hashed Entry Address.
|
---|
| 200 | *
|
---|
| 201 | * VRN bits are used to read RID (ASID) from one
|
---|
| 202 | * of the eight region registers registers.
|
---|
| 203 | *
|
---|
| 204 | * @param va Virtual address including VRN bits.
|
---|
| 205 | *
|
---|
| 206 | * @return Address of the head of VHPT collision chain.
|
---|
| 207 | */
|
---|
[7a0359b] | 208 | NO_TRACE static inline uint64_t thash(uint64_t va)
|
---|
[8c0d692] | 209 | {
|
---|
[7f1c620] | 210 | uint64_t ret;
|
---|
[5bda2f3e] | 211 |
|
---|
| 212 | asm volatile (
|
---|
| 213 | "thash %[ret] = %[va]\n"
|
---|
| 214 | : [ret] "=r" (ret)
|
---|
| 215 | : [va] "r" (va)
|
---|
| 216 | );
|
---|
| 217 |
|
---|
[c2b95d3] | 218 | return ret;
|
---|
| 219 | }
|
---|
[fd537a0] | 220 |
|
---|
[c2b95d3] | 221 | /** Return Translation Hashed Entry Tag.
|
---|
| 222 | *
|
---|
| 223 | * VRN bits are used to read RID (ASID) from one
|
---|
| 224 | * of the eight region registers.
|
---|
| 225 | *
|
---|
| 226 | * @param va Virtual address including VRN bits.
|
---|
| 227 | *
|
---|
| 228 | * @return The unique tag for VPN and RID in the collision chain returned by thash().
|
---|
| 229 | */
|
---|
[7a0359b] | 230 | NO_TRACE static inline uint64_t ttag(uint64_t va)
|
---|
[fd537a0] | 231 | {
|
---|
[7f1c620] | 232 | uint64_t ret;
|
---|
[5bda2f3e] | 233 |
|
---|
| 234 | asm volatile (
|
---|
| 235 | "ttag %[ret] = %[va]\n"
|
---|
| 236 | : [ret] "=r" (ret)
|
---|
| 237 | : [va] "r" (va)
|
---|
| 238 | );
|
---|
| 239 |
|
---|
[c2b95d3] | 240 | return ret;
|
---|
| 241 | }
|
---|
[fd537a0] | 242 |
|
---|
[c2b95d3] | 243 | /** Read Region Register.
|
---|
| 244 | *
|
---|
| 245 | * @param i Region register index.
|
---|
| 246 | *
|
---|
| 247 | * @return Current contents of rr[i].
|
---|
| 248 | */
|
---|
[7a0359b] | 249 | NO_TRACE static inline uint64_t rr_read(size_t i)
|
---|
[fd537a0] | 250 | {
|
---|
[7f1c620] | 251 | uint64_t ret;
|
---|
[5bda2f3e] | 252 |
|
---|
[849386a] | 253 | ASSERT(i < REGION_REGISTERS);
|
---|
[5bda2f3e] | 254 |
|
---|
| 255 | asm volatile (
|
---|
| 256 | "mov %[ret] = rr[%[index]]\n"
|
---|
| 257 | : [ret] "=r" (ret)
|
---|
| 258 | : [index] "r" (i << VRN_SHIFT)
|
---|
| 259 | );
|
---|
| 260 |
|
---|
[c2b95d3] | 261 | return ret;
|
---|
| 262 | }
|
---|
[fd537a0] | 263 |
|
---|
[c2b95d3] | 264 | /** Write Region Register.
|
---|
| 265 | *
|
---|
| 266 | * @param i Region register index.
|
---|
| 267 | * @param v Value to be written to rr[i].
|
---|
| 268 | */
|
---|
[7a0359b] | 269 | NO_TRACE static inline void rr_write(size_t i, uint64_t v)
|
---|
[fd537a0] | 270 | {
|
---|
[849386a] | 271 | ASSERT(i < REGION_REGISTERS);
|
---|
[5bda2f3e] | 272 |
|
---|
[e7b7be3f] | 273 | asm volatile (
|
---|
[5bda2f3e] | 274 | "mov rr[%[index]] = %[value]\n"
|
---|
| 275 | :: [index] "r" (i << VRN_SHIFT),
|
---|
| 276 | [value] "r" (v)
|
---|
[a0d74fd] | 277 | );
|
---|
[c2b95d3] | 278 | }
|
---|
[5bda2f3e] | 279 |
|
---|
[c2b95d3] | 280 | /** Read Page Table Register.
|
---|
| 281 | *
|
---|
| 282 | * @return Current value stored in PTA.
|
---|
| 283 | */
|
---|
[7a0359b] | 284 | NO_TRACE static inline uint64_t pta_read(void)
|
---|
[c2b95d3] | 285 | {
|
---|
[7f1c620] | 286 | uint64_t ret;
|
---|
[c2b95d3] | 287 |
|
---|
[5bda2f3e] | 288 | asm volatile (
|
---|
| 289 | "mov %[ret] = cr.pta\n"
|
---|
| 290 | : [ret] "=r" (ret)
|
---|
| 291 | );
|
---|
[c2b95d3] | 292 |
|
---|
| 293 | return ret;
|
---|
| 294 | }
|
---|
[fd537a0] | 295 |
|
---|
[c2b95d3] | 296 | /** Write Page Table Register.
|
---|
| 297 | *
|
---|
| 298 | * @param v New value to be stored in PTA.
|
---|
| 299 | */
|
---|
[7a0359b] | 300 | NO_TRACE static inline void pta_write(uint64_t v)
|
---|
[c2b95d3] | 301 | {
|
---|
[5bda2f3e] | 302 | asm volatile (
|
---|
| 303 | "mov cr.pta = %[value]\n"
|
---|
| 304 | :: [value] "r" (v)
|
---|
| 305 | );
|
---|
[c2b95d3] | 306 | }
|
---|
| 307 |
|
---|
| 308 | extern void page_arch_init(void);
|
---|
[c7ec94a4] | 309 |
|
---|
[7f1c620] | 310 | extern vhpt_entry_t *vhpt_hash(uintptr_t page, asid_t asid);
|
---|
| 311 | extern bool vhpt_compare(uintptr_t page, asid_t asid, vhpt_entry_t *v);
|
---|
| 312 | extern void vhpt_set_record(vhpt_entry_t *v, uintptr_t page, asid_t asid, uintptr_t frame, int flags);
|
---|
[fd537a0] | 313 |
|
---|
[d1f8a87] | 314 | #endif /* __ASM__ */
|
---|
| 315 |
|
---|
[30ef8ce] | 316 | #endif
|
---|
[b45c443] | 317 |
|
---|
[7f1c620] | 318 | /** @}
|
---|
[b45c443] | 319 | */
|
---|