source: mainline/kernel/arch/ia64/src/mm/page.c@ 98000fb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 98000fb was 98000fb, checked in by Martin Decky <martin@…>, 16 years ago

remove redundant index_t and count_t types (which were always quite ambiguous and not actually needed)

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