| 1 | /*
|
|---|
| 2 | * Copyright (c) 2005 - 2006 Jakub Jermar
|
|---|
| 3 | * Copyright (c) 2006 Jakub Vana
|
|---|
| 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 |
|
|---|
| 30 | /** @addtogroup ia64mm
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef KERN_ia64_PAGE_H_
|
|---|
| 37 | #define KERN_ia64_PAGE_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <arch/mm/frame.h>
|
|---|
| 40 |
|
|---|
| 41 | #define PAGE_SIZE FRAME_SIZE
|
|---|
| 42 | #define PAGE_WIDTH FRAME_WIDTH
|
|---|
| 43 |
|
|---|
| 44 | /** Bit width of the TLB-locked portion of kernel address space. */
|
|---|
| 45 | #define KERNEL_PAGE_WIDTH 28 /* 256M */
|
|---|
| 46 | #define IO_PAGE_WIDTH 26 /* 64M */
|
|---|
| 47 | #define FW_PAGE_WIDTH 28 /* 256M */
|
|---|
| 48 |
|
|---|
| 49 | #define USPACE_IO_PAGE_WIDTH 12 /* 4K */
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 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 | */
|
|---|
| 57 |
|
|---|
| 58 | /* Firmware area (bellow 4GB in phys mem) */
|
|---|
| 59 | #define FW_OFFSET 0x00000000F0000000
|
|---|
| 60 | /* Legacy IO space */
|
|---|
| 61 | #define IO_OFFSET 0x0001000000000000
|
|---|
| 62 | /* Videoram - now mapped to 0 as VGA text mode vram on 0xb8000 */
|
|---|
| 63 | #define VIO_OFFSET 0x0002000000000000
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | #define PPN_SHIFT 12
|
|---|
| 67 |
|
|---|
| 68 | #define VRN_SHIFT 61
|
|---|
| 69 | #define VRN_MASK (7ULL << VRN_SHIFT)
|
|---|
| 70 | #define VA2VRN(va) ((va) >> VRN_SHIFT)
|
|---|
| 71 |
|
|---|
| 72 | #ifdef __ASM__
|
|---|
| 73 | #define VRN_KERNEL 7
|
|---|
| 74 | #else
|
|---|
| 75 | #define VRN_KERNEL 7ULL
|
|---|
| 76 | #endif
|
|---|
| 77 |
|
|---|
| 78 | #define REGION_REGISTERS 8
|
|---|
| 79 |
|
|---|
| 80 | #define KA2PA(x) ((uintptr_t) ((x) - (VRN_KERNEL << VRN_SHIFT)))
|
|---|
| 81 | #define PA2KA(x) ((uintptr_t) ((x) + (VRN_KERNEL << VRN_SHIFT)))
|
|---|
| 82 |
|
|---|
| 83 | #define VHPT_WIDTH 20 /* 1M */
|
|---|
| 84 | #define VHPT_SIZE (1 << VHPT_WIDTH)
|
|---|
| 85 |
|
|---|
| 86 | #define PTA_BASE_SHIFT 15
|
|---|
| 87 |
|
|---|
| 88 | /** Memory Attributes. */
|
|---|
| 89 | #define MA_WRITEBACK 0x00
|
|---|
| 90 | #define MA_UNCACHEABLE 0x04
|
|---|
| 91 |
|
|---|
| 92 | /** Privilege Levels. Only the most and the least privileged ones are ever used. */
|
|---|
| 93 | #define PL_KERNEL 0x00
|
|---|
| 94 | #define PL_USER 0x03
|
|---|
| 95 |
|
|---|
| 96 | /* Access Rigths. Only certain combinations are used by the kernel. */
|
|---|
| 97 | #define AR_READ 0x00
|
|---|
| 98 | #define AR_EXECUTE 0x01
|
|---|
| 99 | #define AR_WRITE 0x02
|
|---|
| 100 |
|
|---|
| 101 | #ifndef __ASM__
|
|---|
| 102 |
|
|---|
| 103 | #include <arch/mm/as.h>
|
|---|
| 104 | #include <arch/mm/frame.h>
|
|---|
| 105 | #include <arch/interrupt.h>
|
|---|
| 106 | #include <arch/barrier.h>
|
|---|
| 107 | #include <arch/mm/asid.h>
|
|---|
| 108 | #include <typedefs.h>
|
|---|
| 109 | #include <debug.h>
|
|---|
| 110 |
|
|---|
| 111 | struct vhpt_tag_info {
|
|---|
| 112 | unsigned long long tag : 63;
|
|---|
| 113 | unsigned int ti : 1;
|
|---|
| 114 | } __attribute__ ((packed));
|
|---|
| 115 |
|
|---|
| 116 | union vhpt_tag {
|
|---|
| 117 | struct vhpt_tag_info tag_info;
|
|---|
| 118 | unsigned tag_word;
|
|---|
| 119 | };
|
|---|
| 120 |
|
|---|
| 121 | struct vhpt_entry_present {
|
|---|
| 122 | /* Word 0 */
|
|---|
| 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;
|
|---|
| 130 | unsigned long long ppn : 38;
|
|---|
| 131 | unsigned int : 2;
|
|---|
| 132 | unsigned int ed : 1;
|
|---|
| 133 | unsigned int ig1 : 11;
|
|---|
| 134 |
|
|---|
| 135 | /* Word 1 */
|
|---|
| 136 | unsigned int : 2;
|
|---|
| 137 | unsigned int ps : 6;
|
|---|
| 138 | unsigned int key : 24;
|
|---|
| 139 | unsigned int : 32;
|
|---|
| 140 |
|
|---|
| 141 | /* Word 2 */
|
|---|
| 142 | union vhpt_tag tag;
|
|---|
| 143 |
|
|---|
| 144 | /* Word 3 */
|
|---|
| 145 | uint64_t ig3 : 64;
|
|---|
| 146 | } __attribute__ ((packed));
|
|---|
| 147 |
|
|---|
| 148 | struct vhpt_entry_not_present {
|
|---|
| 149 | /* Word 0 */
|
|---|
| 150 | unsigned int p : 1;
|
|---|
| 151 | unsigned long long ig0 : 52;
|
|---|
| 152 | unsigned int ig1 : 11;
|
|---|
| 153 |
|
|---|
| 154 | /* Word 1 */
|
|---|
| 155 | unsigned int : 2;
|
|---|
| 156 | unsigned int ps : 6;
|
|---|
| 157 | unsigned long long ig2 : 56;
|
|---|
| 158 |
|
|---|
| 159 | /* Word 2 */
|
|---|
| 160 | union vhpt_tag tag;
|
|---|
| 161 |
|
|---|
| 162 | /* Word 3 */
|
|---|
| 163 | uint64_t ig3 : 64;
|
|---|
| 164 | } __attribute__ ((packed));
|
|---|
| 165 |
|
|---|
| 166 | typedef union {
|
|---|
| 167 | struct vhpt_entry_present present;
|
|---|
| 168 | struct vhpt_entry_not_present not_present;
|
|---|
| 169 | uint64_t word[4];
|
|---|
| 170 | } vhpt_entry_t;
|
|---|
| 171 |
|
|---|
| 172 | struct region_register_map {
|
|---|
| 173 | unsigned int ve : 1;
|
|---|
| 174 | unsigned int : 1;
|
|---|
| 175 | unsigned int ps : 6;
|
|---|
| 176 | unsigned int rid : 24;
|
|---|
| 177 | unsigned int : 32;
|
|---|
| 178 | } __attribute__ ((packed));
|
|---|
| 179 |
|
|---|
| 180 | typedef union {
|
|---|
| 181 | struct region_register_map map;
|
|---|
| 182 | unsigned long long word;
|
|---|
| 183 | } region_register_t;
|
|---|
| 184 |
|
|---|
| 185 | struct pta_register_map {
|
|---|
| 186 | unsigned int ve : 1;
|
|---|
| 187 | unsigned int : 1;
|
|---|
| 188 | unsigned int size : 6;
|
|---|
| 189 | unsigned int vf : 1;
|
|---|
| 190 | unsigned int : 6;
|
|---|
| 191 | unsigned long long base : 49;
|
|---|
| 192 | } __attribute__ ((packed));
|
|---|
| 193 |
|
|---|
| 194 | typedef union pta_register {
|
|---|
| 195 | struct pta_register_map map;
|
|---|
| 196 | uint64_t word;
|
|---|
| 197 | } pta_register_t;
|
|---|
| 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 | */
|
|---|
| 208 | NO_TRACE static inline uint64_t thash(uint64_t va)
|
|---|
| 209 | {
|
|---|
| 210 | uint64_t ret;
|
|---|
| 211 |
|
|---|
| 212 | asm volatile (
|
|---|
| 213 | "thash %[ret] = %[va]\n"
|
|---|
| 214 | : [ret] "=r" (ret)
|
|---|
| 215 | : [va] "r" (va)
|
|---|
| 216 | );
|
|---|
| 217 |
|
|---|
| 218 | return ret;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 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 | */
|
|---|
| 230 | NO_TRACE static inline uint64_t ttag(uint64_t va)
|
|---|
| 231 | {
|
|---|
| 232 | uint64_t ret;
|
|---|
| 233 |
|
|---|
| 234 | asm volatile (
|
|---|
| 235 | "ttag %[ret] = %[va]\n"
|
|---|
| 236 | : [ret] "=r" (ret)
|
|---|
| 237 | : [va] "r" (va)
|
|---|
| 238 | );
|
|---|
| 239 |
|
|---|
| 240 | return ret;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | /** Read Region Register.
|
|---|
| 244 | *
|
|---|
| 245 | * @param i Region register index.
|
|---|
| 246 | *
|
|---|
| 247 | * @return Current contents of rr[i].
|
|---|
| 248 | */
|
|---|
| 249 | NO_TRACE static inline uint64_t rr_read(size_t i)
|
|---|
| 250 | {
|
|---|
| 251 | uint64_t ret;
|
|---|
| 252 |
|
|---|
| 253 | ASSERT(i < REGION_REGISTERS);
|
|---|
| 254 |
|
|---|
| 255 | asm volatile (
|
|---|
| 256 | "mov %[ret] = rr[%[index]]\n"
|
|---|
| 257 | : [ret] "=r" (ret)
|
|---|
| 258 | : [index] "r" (i << VRN_SHIFT)
|
|---|
| 259 | );
|
|---|
| 260 |
|
|---|
| 261 | return ret;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | /** Write Region Register.
|
|---|
| 265 | *
|
|---|
| 266 | * @param i Region register index.
|
|---|
| 267 | * @param v Value to be written to rr[i].
|
|---|
| 268 | */
|
|---|
| 269 | NO_TRACE static inline void rr_write(size_t i, uint64_t v)
|
|---|
| 270 | {
|
|---|
| 271 | ASSERT(i < REGION_REGISTERS);
|
|---|
| 272 |
|
|---|
| 273 | asm volatile (
|
|---|
| 274 | "mov rr[%[index]] = %[value]\n"
|
|---|
| 275 | :: [index] "r" (i << VRN_SHIFT),
|
|---|
| 276 | [value] "r" (v)
|
|---|
| 277 | );
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | /** Read Page Table Register.
|
|---|
| 281 | *
|
|---|
| 282 | * @return Current value stored in PTA.
|
|---|
| 283 | */
|
|---|
| 284 | NO_TRACE static inline uint64_t pta_read(void)
|
|---|
| 285 | {
|
|---|
| 286 | uint64_t ret;
|
|---|
| 287 |
|
|---|
| 288 | asm volatile (
|
|---|
| 289 | "mov %[ret] = cr.pta\n"
|
|---|
| 290 | : [ret] "=r" (ret)
|
|---|
| 291 | );
|
|---|
| 292 |
|
|---|
| 293 | return ret;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | /** Write Page Table Register.
|
|---|
| 297 | *
|
|---|
| 298 | * @param v New value to be stored in PTA.
|
|---|
| 299 | */
|
|---|
| 300 | NO_TRACE static inline void pta_write(uint64_t v)
|
|---|
| 301 | {
|
|---|
| 302 | asm volatile (
|
|---|
| 303 | "mov cr.pta = %[value]\n"
|
|---|
| 304 | :: [value] "r" (v)
|
|---|
| 305 | );
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | extern void page_arch_init(void);
|
|---|
| 309 |
|
|---|
| 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);
|
|---|
| 313 |
|
|---|
| 314 | #endif /* __ASM__ */
|
|---|
| 315 |
|
|---|
| 316 | #endif
|
|---|
| 317 |
|
|---|
| 318 | /** @}
|
|---|
| 319 | */
|
|---|