ia64/xen-unstable

view xen/include/asm-ia64/vmmu.h @ 5704:9b73afea874e

Certain types of event channel are now auto-bound to vcpu0 by Xen.
Make sure that xenolinux agrees with this.
author sos22@douglas.cl.cam.ac.uk
date Fri Jul 08 15:35:43 2005 +0000 (2005-07-08)
parents 649cd37aa1ab
children 1ec2225aa8c6 8799d14bef77 9312a3e8a6f8 dfaf788ab18c
line source
2 /* -*- Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
3 /*
4 * vmmu.h: virtual memory management unit related APIs and data structure.
5 * Copyright (c) 2004, Intel Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place - Suite 330, Boston, MA 02111-1307 USA.
19 *
20 * Yaozu Dong (Eddie Dong) (Eddie.dong@intel.com)
21 */
23 #ifndef XEN_TLBthash_H
24 #define XEN_TLBthash_H
26 #include "xen/config.h"
27 #include "xen/types.h"
28 #include "public/xen.h"
29 #include "asm/tlb.h"
31 //#define THASH_TLB_TR 0
32 //#define THASH_TLB_TC 1
35 // bit definition of TR, TC search cmobination
36 //#define THASH_SECTION_TR (1<<0)
37 //#define THASH_SECTION_TC (1<<1)
39 /*
40 * Next bit definition must be same with THASH_TLB_XX
41 */
42 typedef union search_section {
43 struct {
44 u32 tr : 1;
45 u32 tc : 1;
46 u32 rsv: 30;
47 };
48 u32 v;
49 } search_section_t;
51 #define MAX_CCN_DEPTH 4 // collision chain depth
52 #define VCPU_TLB_SHIFT (22)
53 #define VCPU_TLB_SIZE (1UL<<VCPU_TLB_SHIFT)
54 #define VCPU_TLB_ORDER VCPU_TLB_SHIFT - PAGE_SHIFT
55 #define PTA_BASE_SHIFT (15)
57 #ifndef __ASSEMBLY__
58 #define HIGH_32BITS(x) bits(x,32,63)
59 #define LOW_32BITS(x) bits(x,0,31)
61 typedef enum {
62 ISIDE_TLB=0,
63 DSIDE_TLB=1
64 } CACHE_LINE_TYPE;
66 typedef struct thash_data {
67 union {
68 struct {
69 u64 p : 1; // 0
70 u64 rv1 : 1; // 1
71 u64 ma : 3; // 2-4
72 u64 a : 1; // 5
73 u64 d : 1; // 6
74 u64 pl : 2; // 7-8
75 u64 ar : 3; // 9-11
76 u64 ppn : 38; // 12-49
77 u64 rv2 : 2; // 50-51
78 u64 ed : 1; // 52
79 u64 ig1 : 11; //53-63
80 };
81 struct {
82 u64 __rv1 : 53; // 0-52
83 // next extension to ig1, only for TLB instance
84 u64 tc : 1; // 53 TR or TC
85 u64 locked : 1; // 54 entry locked or not
86 CACHE_LINE_TYPE cl : 1; // I side or D side cache line
87 u64 nomap : 1; // entry cann't be inserted into machine TLB.
88 u64 __ig1 : 5; // 56-61
89 u64 checked : 1; // for VTLB/VHPT sanity check
90 u64 invalid : 1; // invalid entry
91 };
92 u64 page_flags;
93 }; // same for VHPT and TLB
95 union {
96 struct {
97 u64 rv3 : 2; // 0-1
98 u64 ps : 6; // 2-7
99 u64 key : 24; // 8-31
100 u64 rv4 : 32; // 32-63
101 };
102 struct {
103 u64 __rv3 : 32; // 0-31
104 // next extension to rv4
105 u64 rid : 24; // 32-55
106 u64 __rv4 : 8; // 56-63
107 };
108 u64 itir;
109 };
110 union {
111 struct { // For TLB
112 u64 ig2 : 12; // 0-11
113 u64 vpn : 49; // 12-60
114 u64 vrn : 3; // 61-63
115 };
116 u64 vadr;
117 u64 ifa;
118 struct { // For VHPT
119 u64 tag : 63; // 0-62
120 u64 ti : 1; // 63, invalid entry for VHPT
121 };
122 u64 etag; // extended tag for VHPT
123 };
124 union {
125 struct thash_data *next;
126 u64 tr_idx;
127 };
128 } thash_data_t;
130 #define INVALID_VHPT(hdata) ((hdata)->ti)
131 #define INVALID_TLB(hdata) ((hdata)->invalid)
132 #define INVALID_ENTRY(hcb, hdata) \
133 ((hcb)->ht==THASH_TLB ? INVALID_TLB(hdata) : INVALID_VHPT(hdata))
135 typedef enum {
136 THASH_TLB=0,
137 THASH_VHPT
138 } THASH_TYPE;
140 struct thash_cb;
141 typedef union thash_cch_mem {
142 thash_data_t data;
143 union thash_cch_mem *next;
144 } thash_cch_mem_t;
147 /*
148 * Use to calculate the HASH index of thash_data_t.
149 */
150 typedef u64 *(THASH_FN)(PTA pta, u64 va, u64 rid, u64 ps);
151 typedef u64 *(TTAG_FN)(PTA pta, u64 va, u64 rid, u64 ps);
152 typedef u64 *(GET_MFN_FN)(domid_t d, u64 gpfn, u64 pages);
153 typedef void *(REM_NOTIFIER_FN)(struct hash_cb *hcb, thash_data_t *entry);
154 typedef void (RECYCLE_FN)(struct hash_cb *hc, u64 para);
155 typedef rr_t (GET_RR_FN)(struct vcpu *vcpu, u64 reg);
156 typedef thash_data_t *(FIND_OVERLAP_FN)(struct thash_cb *hcb,
157 u64 va, u64 ps, int rid, char cl, search_section_t s_sect);
158 typedef thash_data_t *(FIND_NEXT_OVL_FN)(struct thash_cb *hcb);
159 typedef void (REM_THASH_FN)(struct thash_cb *hcb, thash_data_t *entry);
160 typedef void (INS_THASH_FN)(struct thash_cb *hcb, thash_data_t *entry, u64 va);
162 typedef struct tlb_special {
163 thash_data_t itr[NITRS];
164 thash_data_t dtr[NDTRS];
165 struct thash_cb *vhpt;
166 } tlb_special_t;
168 typedef struct vhpt_cb {
169 //u64 pta; // pta value.
170 GET_MFN_FN *get_mfn;
171 TTAG_FN *tag_func;
172 } vhpt_special;
174 typedef struct thash_internal {
175 thash_data_t *hash_base;
176 thash_data_t *cur_cch; // head of overlap search
177 int rid;
178 int ps;
179 union {
180 u64 tag; // for VHPT
181 struct { // for TLB
182 char _tr_idx; // -1: means done of TR search
183 char cl;
184 search_section_t s_sect; // search section combinations
185 };
186 };
187 u64 _curva; // current address to search
188 u64 _eva;
189 } thash_internal_t;
191 #define THASH_CB_MAGIC 0x55aa00aa55aa55aaUL
192 typedef struct thash_cb {
193 /* THASH base information */
194 THASH_TYPE ht; // For TLB or VHPT
195 u64 magic;
196 thash_data_t *hash; // hash table pointer, aligned at thash_sz.
197 u64 hash_sz; // size of above data.
198 void *cch_buf; // base address of collision chain.
199 u64 cch_sz; // size of above data.
200 THASH_FN *hash_func;
201 GET_RR_FN *get_rr_fn;
202 RECYCLE_FN *recycle_notifier;
203 thash_cch_mem_t *cch_freelist;
204 struct vcpu *vcpu;
205 PTA pta;
206 /* VTLB/VHPT common information */
207 FIND_OVERLAP_FN *find_overlap;
208 FIND_NEXT_OVL_FN *next_overlap;
209 REM_THASH_FN *rem_hash; // remove hash entry.
210 INS_THASH_FN *ins_hash; // insert hash entry.
211 REM_NOTIFIER_FN *remove_notifier;
212 /* private information */
213 thash_internal_t priv;
214 union {
215 tlb_special_t *ts;
216 vhpt_special *vs;
217 };
218 // Internal positon information, buffer and storage etc. TBD
219 } thash_cb_t;
221 #define ITR(hcb,id) ((hcb)->ts->itr[id])
222 #define DTR(hcb,id) ((hcb)->ts->dtr[id])
223 #define INVALIDATE_HASH(hcb,hash) { \
224 INVALID_ENTRY(hcb, hash) = 1; \
225 hash->next = NULL; }
227 #define PURGABLE_ENTRY(hcb,en) \
228 ((hcb)->ht == THASH_VHPT || ( (en)->tc && !(en->locked)) )
231 /*
232 * Initialize internal control data before service.
233 */
234 extern void thash_init(thash_cb_t *hcb, u64 sz);
236 /*
237 * Insert an entry to hash table.
238 * NOTES:
239 * 1: TLB entry may be TR, TC or Foreign Map. For TR entry,
240 * itr[]/dtr[] need to be updated too.
241 * 2: Inserting to collision chain may trigger recycling if
242 * the buffer for collision chain is empty.
243 * 3: The new entry is inserted at the hash table.
244 * (I.e. head of the collision chain)
245 * 4: Return the entry in hash table or collision chain.
246 *
247 */
248 extern void thash_insert(thash_cb_t *hcb, thash_data_t *entry, u64 va);
249 extern void thash_tr_insert(thash_cb_t *hcb, thash_data_t *entry, u64 va, int idx);
251 /*
252 * Force to delete a found entry no matter TR or foreign map for TLB.
253 * NOTES:
254 * 1: TLB entry may be TR, TC or Foreign Map. For TR entry,
255 * itr[]/dtr[] need to be updated too.
256 * 2: This API must be called after thash_find_overlap() or
257 * thash_find_next_overlap().
258 * 3: Return TRUE or FALSE
259 *
260 */
261 extern void thash_remove(thash_cb_t *hcb, thash_data_t *entry);
262 extern void thash_tr_remove(thash_cb_t *hcb, thash_data_t *entry/*, int idx*/);
264 /*
265 * Find an overlap entry in hash table and its collision chain.
266 * Refer to SDM2 4.1.1.4 for overlap definition.
267 * PARAS:
268 * 1: in: TLB format entry, rid:ps must be same with vrr[].
269 * va & ps identify the address space for overlap lookup
270 * 2: section can be combination of TR, TC and FM. (THASH_SECTION_XX)
271 * 3: cl means I side or D side.
272 * RETURNS:
273 * NULL to indicate the end of findings.
274 * NOTES:
275 *
276 */
277 extern thash_data_t *thash_find_overlap(thash_cb_t *hcb,
278 thash_data_t *in, search_section_t s_sect);
279 extern thash_data_t *thash_find_overlap_ex(thash_cb_t *hcb,
280 u64 va, u64 ps, int rid, char cl, search_section_t s_sect);
283 /*
284 * Similar with thash_find_overlap but find next entry.
285 * NOTES:
286 * Intermediate position information is stored in hcb->priv.
287 */
288 extern thash_data_t *thash_find_next_overlap(thash_cb_t *hcb);
290 /*
291 * Find and purge overlap entries in hash table and its collision chain.
292 * PARAS:
293 * 1: in: TLB format entry, rid:ps must be same with vrr[].
294 * rid, va & ps identify the address space for purge
295 * 2: section can be combination of TR, TC and FM. (thash_SECTION_XX)
296 * 3: cl means I side or D side.
297 * NOTES:
298 *
299 */
300 extern void thash_purge_entries(thash_cb_t *hcb,
301 thash_data_t *in, search_section_t p_sect);
302 extern void thash_purge_entries_ex(thash_cb_t *hcb,
303 u64 rid, u64 va, u64 sz,
304 search_section_t p_sect,
305 CACHE_LINE_TYPE cl);
306 extern void thash_purge_and_insert(thash_cb_t *hcb, thash_data_t *in);
308 /*
309 * Purge all TCs or VHPT entries including those in Hash table.
310 *
311 */
312 extern void thash_purge_all(thash_cb_t *hcb);
314 /*
315 * Lookup the hash table and its collision chain to find an entry
316 * covering this address rid:va.
317 *
318 */
319 extern thash_data_t *vtlb_lookup(thash_cb_t *hcb,
320 thash_data_t *in);
321 extern thash_data_t *vtlb_lookup_ex(thash_cb_t *hcb,
322 u64 rid, u64 va,CACHE_LINE_TYPE cl);
323 extern int thash_lock_tc(thash_cb_t *hcb, u64 va, u64 size, int rid, char cl, int lock);
326 #define ITIR_RV_MASK (((1UL<<32)-1)<<32 | 0x3)
327 #define PAGE_FLAGS_RV_MASK (0x2 | (0x3UL<<50)|(((1UL<<11)-1)<<53))
328 extern u64 machine_ttag(PTA pta, u64 va, u64 rid, u64 ps);
329 extern u64 machine_thash(PTA pta, u64 va, u64 rid, u64 ps);
330 extern void purge_machine_tc_by_domid(domid_t domid);
331 extern void machine_tlb_insert(struct vcpu *d, thash_data_t *tlb);
332 extern rr_t vmmu_get_rr(struct vcpu *vcpu, u64 va);
333 extern thash_cb_t *init_domain_tlb(struct vcpu *d);
335 #define VTLB_DEBUG
336 #ifdef VTLB_DEBUG
337 extern void check_vtlb_sanity(thash_cb_t *vtlb);
338 extern void dump_vtlb(thash_cb_t *vtlb);
339 #endif
341 #endif /* __ASSEMBLY__ */
343 #endif /* XEN_TLBthash_H */