[6d7ffa65] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Jakub Jermar
|
---|
| 3 | * Copyright (c) 2006 Jakub Vana
|
---|
[6d7ffa65] | 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 |
|
---|
[06e1e95] | 30 | /** @addtogroup ia64mm
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[6d7ffa65] | 36 | #include <arch/mm/page.h>
|
---|
| 37 | #include <genarch/mm/page_ht.h>
|
---|
[c2b95d3] | 38 | #include <mm/asid.h>
|
---|
[457d18a] | 39 | #include <arch/mm/asid.h>
|
---|
[68091bd] | 40 | #include <arch/mm/vhpt.h>
|
---|
[c2b95d3] | 41 | #include <arch/types.h>
|
---|
[6461d67c] | 42 | #include <print.h>
|
---|
[6d7ffa65] | 43 | #include <mm/page.h>
|
---|
[c2b95d3] | 44 | #include <mm/frame.h>
|
---|
[6d7ffa65] | 45 | #include <config.h>
|
---|
| 46 | #include <panic.h>
|
---|
[2a003d5b] | 47 | #include <arch/asm.h>
|
---|
[c2b95d3] | 48 | #include <arch/barrier.h>
|
---|
[849386a] | 49 | #include <memstr.h>
|
---|
[6d7ffa65] | 50 |
|
---|
[c7ec94a4] | 51 | static void set_environment(void);
|
---|
[457d18a] | 52 |
|
---|
| 53 | /** Initialize ia64 virtual address translation subsystem. */
|
---|
| 54 | void page_arch_init(void)
|
---|
| 55 | {
|
---|
[f5935ed] | 56 | page_mapping_operations = &ht_mapping_operations;
|
---|
[457d18a] | 57 | pk_disable();
|
---|
[c7ec94a4] | 58 | set_environment();
|
---|
[457d18a] | 59 | }
|
---|
| 60 |
|
---|
[c2b95d3] | 61 | /** Initialize VHPT and region registers. */
|
---|
[c7ec94a4] | 62 | void set_environment(void)
|
---|
[fd537a0] | 63 | {
|
---|
[c2b95d3] | 64 | region_register rr;
|
---|
| 65 | pta_register pta;
|
---|
[fd537a0] | 66 | int i;
|
---|
[68091bd] | 67 | #ifdef CONFIG_VHPT
|
---|
[7f1c620] | 68 | uintptr_t vhpt_base;
|
---|
[68091bd] | 69 | #endif
|
---|
[5ac2e61] | 70 |
|
---|
[c2b95d3] | 71 | /*
|
---|
| 72 | * First set up kernel region register.
|
---|
[a0d74fd] | 73 | * This is redundant (see start.S) but we keep it here just for sure.
|
---|
[c2b95d3] | 74 | */
|
---|
| 75 | rr.word = rr_read(VRN_KERNEL);
|
---|
| 76 | rr.map.ve = 0; /* disable VHPT walker */
|
---|
| 77 | rr.map.ps = PAGE_WIDTH;
|
---|
[a0d74fd] | 78 | rr.map.rid = ASID2RID(ASID_KERNEL, VRN_KERNEL);
|
---|
[c2b95d3] | 79 | rr_write(VRN_KERNEL, rr.word);
|
---|
| 80 | srlz_i();
|
---|
| 81 | srlz_d();
|
---|
[a0d74fd] | 82 |
|
---|
[c2b95d3] | 83 | /*
|
---|
[9ad03fe] | 84 | * And setup the rest of region register.
|
---|
[c2b95d3] | 85 | */
|
---|
| 86 | for(i = 0; i < REGION_REGISTERS; i++) {
|
---|
| 87 | /* skip kernel rr */
|
---|
| 88 | if (i == VRN_KERNEL)
|
---|
| 89 | continue;
|
---|
[6461d67c] | 90 |
|
---|
[9459255] | 91 | rr.word = rr_read(i);
|
---|
[849386a] | 92 | rr.map.ve = 0; /* disable VHPT walker */
|
---|
[9ad03fe] | 93 | rr.map.rid = RID_KERNEL;
|
---|
| 94 | rr.map.ps = PAGE_WIDTH;
|
---|
[c2b95d3] | 95 | rr_write(i, rr.word);
|
---|
| 96 | srlz_i();
|
---|
| 97 | srlz_d();
|
---|
| 98 | }
|
---|
[6461d67c] | 99 |
|
---|
[68091bd] | 100 | #ifdef CONFIG_VHPT
|
---|
| 101 | vhpt_base = vhpt_set_up();
|
---|
| 102 | #endif
|
---|
[c2b95d3] | 103 | /*
|
---|
| 104 | * Set up PTA register.
|
---|
| 105 | */
|
---|
| 106 | pta.word = pta_read();
|
---|
[68091bd] | 107 | #ifndef CONFIG_VHPT
|
---|
[c2b95d3] | 108 | pta.map.ve = 0; /* disable VHPT walker */
|
---|
[68091bd] | 109 | pta.map.base = 0 >> PTA_BASE_SHIFT;
|
---|
| 110 | #else
|
---|
| 111 | pta.map.ve = 1; /* enable VHPT walker */
|
---|
| 112 | pta.map.base = vhpt_base >> PTA_BASE_SHIFT;
|
---|
| 113 | #endif
|
---|
[c2b95d3] | 114 | pta.map.vf = 1; /* large entry format */
|
---|
| 115 | pta.map.size = VHPT_WIDTH;
|
---|
| 116 | pta_write(pta.word);
|
---|
| 117 | srlz_i();
|
---|
| 118 | srlz_d();
|
---|
| 119 | }
|
---|
[fd537a0] | 120 |
|
---|
[849386a] | 121 | /** Calculate address of collision chain from VPN and ASID.
|
---|
| 122 | *
|
---|
[457d18a] | 123 | * Interrupts must be disabled.
|
---|
[849386a] | 124 | *
|
---|
| 125 | * @param page Address of virtual page including VRN bits.
|
---|
| 126 | * @param asid Address space identifier.
|
---|
| 127 | *
|
---|
[c7ec94a4] | 128 | * @return VHPT entry address.
|
---|
[849386a] | 129 | */
|
---|
[7f1c620] | 130 | vhpt_entry_t *vhpt_hash(uintptr_t page, asid_t asid)
|
---|
[849386a] | 131 | {
|
---|
| 132 | region_register rr_save, rr;
|
---|
[457d18a] | 133 | index_t vrn;
|
---|
| 134 | rid_t rid;
|
---|
[c7ec94a4] | 135 | vhpt_entry_t *v;
|
---|
[849386a] | 136 |
|
---|
[457d18a] | 137 | vrn = page >> VRN_SHIFT;
|
---|
| 138 | rid = ASID2RID(asid, vrn);
|
---|
| 139 |
|
---|
| 140 | rr_save.word = rr_read(vrn);
|
---|
| 141 | if (rr_save.map.rid == rid) {
|
---|
| 142 | /*
|
---|
| 143 | * The RID is already in place, compute thash and return.
|
---|
| 144 | */
|
---|
[c7ec94a4] | 145 | v = (vhpt_entry_t *) thash(page);
|
---|
| 146 | return v;
|
---|
[457d18a] | 147 | }
|
---|
| 148 |
|
---|
| 149 | /*
|
---|
| 150 | * The RID must be written to some region register.
|
---|
| 151 | * To speed things up, register indexed by vrn is used.
|
---|
| 152 | */
|
---|
[849386a] | 153 | rr.word = rr_save.word;
|
---|
[457d18a] | 154 | rr.map.rid = rid;
|
---|
| 155 | rr_write(vrn, rr.word);
|
---|
[849386a] | 156 | srlz_i();
|
---|
[c7ec94a4] | 157 | v = (vhpt_entry_t *) thash(page);
|
---|
[457d18a] | 158 | rr_write(vrn, rr_save.word);
|
---|
[849386a] | 159 | srlz_i();
|
---|
| 160 | srlz_d();
|
---|
| 161 |
|
---|
[c7ec94a4] | 162 | return v;
|
---|
[849386a] | 163 | }
|
---|
[457d18a] | 164 |
|
---|
| 165 | /** Compare ASID and VPN against PTE.
|
---|
| 166 | *
|
---|
| 167 | * Interrupts must be disabled.
|
---|
| 168 | *
|
---|
| 169 | * @param page Address of virtual page including VRN bits.
|
---|
| 170 | * @param asid Address space identifier.
|
---|
| 171 | *
|
---|
| 172 | * @return True if page and asid match the page and asid of t, false otherwise.
|
---|
| 173 | */
|
---|
[7f1c620] | 174 | bool vhpt_compare(uintptr_t page, asid_t asid, vhpt_entry_t *v)
|
---|
[457d18a] | 175 | {
|
---|
| 176 | region_register rr_save, rr;
|
---|
| 177 | index_t vrn;
|
---|
| 178 | rid_t rid;
|
---|
| 179 | bool match;
|
---|
| 180 |
|
---|
[c7ec94a4] | 181 | ASSERT(v);
|
---|
[457d18a] | 182 |
|
---|
| 183 | vrn = page >> VRN_SHIFT;
|
---|
| 184 | rid = ASID2RID(asid, vrn);
|
---|
| 185 |
|
---|
| 186 | rr_save.word = rr_read(vrn);
|
---|
| 187 | if (rr_save.map.rid == rid) {
|
---|
| 188 | /*
|
---|
| 189 | * The RID is already in place, compare ttag with t and return.
|
---|
| 190 | */
|
---|
[c7ec94a4] | 191 | return ttag(page) == v->present.tag.tag_word;
|
---|
[457d18a] | 192 | }
|
---|
| 193 |
|
---|
| 194 | /*
|
---|
| 195 | * The RID must be written to some region register.
|
---|
| 196 | * To speed things up, register indexed by vrn is used.
|
---|
| 197 | */
|
---|
| 198 | rr.word = rr_save.word;
|
---|
| 199 | rr.map.rid = rid;
|
---|
| 200 | rr_write(vrn, rr.word);
|
---|
| 201 | srlz_i();
|
---|
[c7ec94a4] | 202 | match = (ttag(page) == v->present.tag.tag_word);
|
---|
[457d18a] | 203 | rr_write(vrn, rr_save.word);
|
---|
| 204 | srlz_i();
|
---|
| 205 | srlz_d();
|
---|
| 206 |
|
---|
| 207 | return match;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | /** Set up one VHPT entry.
|
---|
| 211 | *
|
---|
[abbc16e] | 212 | * @param v VHPT entry to be set up.
|
---|
[457d18a] | 213 | * @param page Virtual address of the page mapped by the entry.
|
---|
| 214 | * @param asid Address space identifier of the address space to which page belongs.
|
---|
| 215 | * @param frame Physical address of the frame to wich page is mapped.
|
---|
| 216 | * @param flags Different flags for the mapping.
|
---|
| 217 | */
|
---|
[7f1c620] | 218 | void vhpt_set_record(vhpt_entry_t *v, uintptr_t page, asid_t asid, uintptr_t frame, int flags)
|
---|
[457d18a] | 219 | {
|
---|
| 220 | region_register rr_save, rr;
|
---|
| 221 | index_t vrn;
|
---|
| 222 | rid_t rid;
|
---|
[7f1c620] | 223 | uint64_t tag;
|
---|
[457d18a] | 224 |
|
---|
[c7ec94a4] | 225 | ASSERT(v);
|
---|
[457d18a] | 226 |
|
---|
| 227 | vrn = page >> VRN_SHIFT;
|
---|
| 228 | rid = ASID2RID(asid, vrn);
|
---|
| 229 |
|
---|
| 230 | /*
|
---|
| 231 | * Compute ttag.
|
---|
| 232 | */
|
---|
| 233 | rr_save.word = rr_read(vrn);
|
---|
| 234 | rr.word = rr_save.word;
|
---|
| 235 | rr.map.rid = rid;
|
---|
| 236 | rr_write(vrn, rr.word);
|
---|
| 237 | srlz_i();
|
---|
| 238 | tag = ttag(page);
|
---|
| 239 | rr_write(vrn, rr_save.word);
|
---|
| 240 | srlz_i();
|
---|
| 241 | srlz_d();
|
---|
| 242 |
|
---|
| 243 | /*
|
---|
| 244 | * Clear the entry.
|
---|
| 245 | */
|
---|
[c7ec94a4] | 246 | v->word[0] = 0;
|
---|
| 247 | v->word[1] = 0;
|
---|
| 248 | v->word[2] = 0;
|
---|
| 249 | v->word[3] = 0;
|
---|
[457d18a] | 250 |
|
---|
[c7ec94a4] | 251 | v->present.p = true;
|
---|
| 252 | v->present.ma = (flags & PAGE_CACHEABLE) ? MA_WRITEBACK : MA_UNCACHEABLE;
|
---|
| 253 | v->present.a = false; /* not accessed */
|
---|
| 254 | v->present.d = false; /* not dirty */
|
---|
| 255 | v->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL;
|
---|
| 256 | v->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ;
|
---|
| 257 | v->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0;
|
---|
| 258 | v->present.ppn = frame >> PPN_SHIFT;
|
---|
| 259 | v->present.ed = false; /* exception not deffered */
|
---|
| 260 | v->present.ps = PAGE_WIDTH;
|
---|
| 261 | v->present.key = 0;
|
---|
| 262 | v->present.tag.tag_word = tag;
|
---|
[457d18a] | 263 | }
|
---|
[b45c443] | 264 |
|
---|
[06e1e95] | 265 | /** @}
|
---|
[b45c443] | 266 | */
|
---|