direct-io.hg

view xen/include/asm-ia64/mm.h @ 10582:dcb50b04faec

[IA64] add volatile to mpt_table

mpt_table is accessed concurrently by cpus, so it needs volatile qualifier

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild.aw
date Mon Jun 19 12:13:11 2006 -0600 (2006-06-19)
parents 0d1dab1d9b67
children d60da6514d65
line source
1 /*
2 * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
3 * VA Linux Systems Japan K.K.
4 * dom0 vp model support
5 */
6 #ifndef __ASM_IA64_MM_H__
7 #define __ASM_IA64_MM_H__
9 #include <xen/config.h>
10 #ifdef LINUX_2_6
11 #include <linux/gfp.h>
12 #endif
13 #include <xen/list.h>
14 #include <xen/spinlock.h>
15 #include <xen/perfc.h>
16 #include <xen/sched.h>
18 #include <asm/processor.h>
19 #include <asm/atomic.h>
20 #include <asm/tlbflush.h>
21 #include <asm/io.h>
23 #include <public/xen.h>
25 /*
26 * The following is for page_alloc.c.
27 */
29 typedef unsigned long page_flags_t;
31 /*
32 * Per-page-frame information.
33 *
34 * Every architecture must ensure the following:
35 * 1. 'struct page_info' contains a 'struct list_head list'.
36 * 2. Provide a PFN_ORDER() macro for accessing the order of a free page.
37 */
38 #define PFN_ORDER(_pfn) ((_pfn)->u.free.order)
40 #define PRtype_info "016lx"
42 struct page_info
43 {
44 /* Each frame can be threaded onto a doubly-linked list. */
45 struct list_head list;
47 /* Reference count and various PGC_xxx flags and fields. */
48 u32 count_info;
50 /* Context-dependent fields follow... */
51 union {
53 /* Page is in use: ((count_info & PGC_count_mask) != 0). */
54 struct {
55 /* Owner of this page (NULL if page is anonymous). */
56 u32 _domain; /* pickled format */
57 /* Type reference count and various PGT_xxx flags and fields. */
58 unsigned long type_info;
59 } __attribute__ ((packed)) inuse;
61 /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */
62 struct {
63 /* Order-size of the free chunk this page is the head of. */
64 u32 order;
65 /* Mask of possibly-tainted TLBs. */
66 cpumask_t cpumask;
67 } __attribute__ ((packed)) free;
69 } u;
71 /* Timestamp from 'TLB clock', used to reduce need for safety flushes. */
72 u32 tlbflush_timestamp;
74 #if 0
75 // following added for Linux compiling
76 page_flags_t flags;
77 atomic_t _count;
78 struct list_head lru; // is this the same as above "list"?
79 #endif
80 };
82 #define set_page_count(p,v) atomic_set(&(p)->_count, v - 1)
84 /*
85 * Still small set of flags defined by far on IA-64.
86 * IA-64 should make it a definition same as x86_64.
87 */
88 /* The following page types are MUTUALLY EXCLUSIVE. */
89 #define PGT_none (0<<29) /* no special uses of this page */
90 #define PGT_l1_page_table (1<<29) /* using this page as an L1 page table? */
91 #define PGT_l2_page_table (2<<29) /* using this page as an L2 page table? */
92 #define PGT_l3_page_table (3<<29) /* using this page as an L3 page table? */
93 #define PGT_l4_page_table (4<<29) /* using this page as an L4 page table? */
94 /* Value 5 reserved. See asm-x86/mm.h */
95 /* Value 6 reserved. See asm-x86/mm.h */
96 #define PGT_writable_page (7<<29) /* has writable mappings of this page? */
97 #define PGT_type_mask (7<<29) /* Bits 29-31. */
99 /* Has this page been validated for use as its current type? */
100 #define _PGT_validated 28
101 #define PGT_validated (1<<_PGT_validated)
102 /* Owning guest has pinned this page to its current type? */
103 #define _PGT_pinned 27
104 #define PGT_pinned (1U<<_PGT_pinned)
106 /* The 27 most significant bits of virt address if this is a page table. */
107 #define PGT_va_shift 32
108 #define PGT_va_mask ((unsigned long)((1U<<28)-1)<<PGT_va_shift)
109 /* Is the back pointer still mutable (i.e. not fixed yet)? */
110 #define PGT_va_mutable ((unsigned long)((1U<<28)-1)<<PGT_va_shift)
111 /* Is the back pointer unknown (e.g., p.t. is mapped at multiple VAs)? */
112 #define PGT_va_unknown ((unsigned long)((1U<<28)-2)<<PGT_va_shift)
114 /* 16-bit count of uses of this frame as its current type. */
115 #define PGT_count_mask ((1U<<16)-1)
117 /* Cleared when the owning guest 'frees' this page. */
118 #define _PGC_allocated 31
119 #define PGC_allocated (1U<<_PGC_allocated)
120 /* Bit 30 reserved. See asm-x86/mm.h */
121 /* Bit 29 reserved. See asm-x86/mm.h */
122 /* 29-bit count of references to this frame. */
123 #define PGC_count_mask ((1U<<29)-1)
125 #define IS_XEN_HEAP_FRAME(_pfn) ((page_to_maddr(_pfn) < xenheap_phys_end) \
126 && (page_to_maddr(_pfn) >= xen_pstart))
128 static inline struct domain *unpickle_domptr(u32 _d)
129 { return (_d == 0) ? NULL : __va(_d); }
130 static inline u32 pickle_domptr(struct domain *_d)
131 { return (_d == NULL) ? 0 : (u32)__pa(_d); }
133 #define page_get_owner(_p) (unpickle_domptr((_p)->u.inuse._domain))
134 #define page_set_owner(_p, _d) ((_p)->u.inuse._domain = pickle_domptr(_d))
136 #define XENSHARE_writable 0
137 #define XENSHARE_readonly 1
138 void share_xen_page_with_guest(struct page_info *page,
139 struct domain *d, int readonly);
140 void share_xen_page_with_privileged_guests(struct page_info *page,
141 int readonly);
143 extern struct page_info *frame_table;
144 extern unsigned long frame_table_size;
145 extern struct list_head free_list;
146 extern spinlock_t free_list_lock;
147 extern unsigned int free_pfns;
148 extern unsigned long max_page;
150 extern void __init init_frametable(void);
151 void add_to_domain_alloc_list(unsigned long ps, unsigned long pe);
153 extern unsigned long gmfn_to_mfn_foreign(struct domain *d, unsigned long gpfn);
155 static inline void put_page(struct page_info *page)
156 {
157 u32 nx, x, y = page->count_info;
159 do {
160 x = y;
161 nx = x - 1;
162 }
163 while (unlikely((y = cmpxchg_rel(&page->count_info, x, nx)) != x));
165 if (unlikely((nx & PGC_count_mask) == 0))
166 free_domheap_page(page);
167 }
169 /* count_info and ownership are checked atomically. */
170 static inline int get_page(struct page_info *page,
171 struct domain *domain)
172 {
173 u64 x, nx, y = *((u64*)&page->count_info);
174 u32 _domain = pickle_domptr(domain);
176 do {
177 x = y;
178 nx = x + 1;
179 if (unlikely((x & PGC_count_mask) == 0) || /* Not allocated? */
180 unlikely((nx & PGC_count_mask) == 0) || /* Count overflow? */
181 unlikely((x >> 32) != _domain)) { /* Wrong owner? */
183 DPRINTK("Error pfn %lx: rd=%p, od=%p, caf=%016lx, taf=%"
184 PRtype_info "\n", page_to_mfn(page), domain,
185 unpickle_domptr(x >> 32), x, page->u.inuse.type_info);
186 return 0;
187 }
188 }
189 while(unlikely((y = cmpxchg_acq((u64*)&page->count_info, x, nx)) != x));
190 return 1;
191 }
193 extern void put_page_type(struct page_info *page);
194 extern int get_page_type(struct page_info *page, u32 type);
196 static inline void put_page_and_type(struct page_info *page)
197 {
198 put_page_type(page);
199 put_page(page);
200 }
203 static inline int get_page_and_type(struct page_info *page,
204 struct domain *domain,
205 u32 type)
206 {
207 int rc = get_page(page, domain);
209 if ( likely(rc) && unlikely(!get_page_type(page, type)) )
210 {
211 put_page(page);
212 rc = 0;
213 }
215 return rc;
216 }
218 #define set_machinetophys(_mfn, _pfn) do { } while(0);
220 #ifdef MEMORY_GUARD
221 void *memguard_init(void *heap_start);
222 void memguard_guard_stack(void *p);
223 void memguard_guard_range(void *p, unsigned long l);
224 void memguard_unguard_range(void *p, unsigned long l);
225 #else
226 #define memguard_init(_s) (_s)
227 #define memguard_guard_stack(_p) ((void)0)
228 #define memguard_guard_range(_p,_l) ((void)0)
229 #define memguard_unguard_range(_p,_l) ((void)0)
230 #endif
232 // prototype of misc memory stuff
233 //unsigned long __get_free_pages(unsigned int mask, unsigned int order);
234 //void __free_pages(struct page_info *page, unsigned int order);
235 void *pgtable_quicklist_alloc(void);
236 void pgtable_quicklist_free(void *pgtable_entry);
238 // FOLLOWING FROM linux-2.6.7/include/mm.h
240 /*
241 * This struct defines a memory VMM memory area. There is one of these
242 * per VM-area/task. A VM area is any part of the process virtual memory
243 * space that has a special rule for the page-fault handlers (ie a shared
244 * library, the executable area etc).
245 */
246 struct vm_area_struct {
247 struct mm_struct * vm_mm; /* The address space we belong to. */
248 unsigned long vm_start; /* Our start address within vm_mm. */
249 unsigned long vm_end; /* The first byte after our end address
250 within vm_mm. */
252 /* linked list of VM areas per task, sorted by address */
253 struct vm_area_struct *vm_next;
255 pgprot_t vm_page_prot; /* Access permissions of this VMA. */
256 unsigned long vm_flags; /* Flags, listed below. */
258 #ifndef XEN
259 struct rb_node vm_rb;
261 // XEN doesn't need all the backing store stuff
262 /*
263 * For areas with an address space and backing store,
264 * linkage into the address_space->i_mmap prio tree, or
265 * linkage to the list of like vmas hanging off its node, or
266 * linkage of vma in the address_space->i_mmap_nonlinear list.
267 */
268 union {
269 struct {
270 struct list_head list;
271 void *parent; /* aligns with prio_tree_node parent */
272 struct vm_area_struct *head;
273 } vm_set;
275 struct prio_tree_node prio_tree_node;
276 } shared;
278 /*
279 * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
280 * list, after a COW of one of the file pages. A MAP_SHARED vma
281 * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
282 * or brk vma (with NULL file) can only be in an anon_vma list.
283 */
284 struct list_head anon_vma_node; /* Serialized by anon_vma->lock */
285 struct anon_vma *anon_vma; /* Serialized by page_table_lock */
287 /* Function pointers to deal with this struct. */
288 struct vm_operations_struct * vm_ops;
290 /* Information about our backing store: */
291 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
292 units, *not* PAGE_CACHE_SIZE */
293 struct file * vm_file; /* File we map to (can be NULL). */
294 void * vm_private_data; /* was vm_pte (shared mem) */
296 #ifdef CONFIG_NUMA
297 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
298 #endif
299 #endif
300 };
301 /*
302 * vm_flags..
303 */
304 #define VM_READ 0x00000001 /* currently active flags */
305 #define VM_WRITE 0x00000002
306 #define VM_EXEC 0x00000004
307 #define VM_SHARED 0x00000008
309 #define VM_MAYREAD 0x00000010 /* limits for mprotect() etc */
310 #define VM_MAYWRITE 0x00000020
311 #define VM_MAYEXEC 0x00000040
312 #define VM_MAYSHARE 0x00000080
314 #define VM_GROWSDOWN 0x00000100 /* general info on the segment */
315 #define VM_GROWSUP 0x00000200
316 #define VM_SHM 0x00000400 /* shared memory area, don't swap out */
317 #define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
319 #define VM_EXECUTABLE 0x00001000
320 #define VM_LOCKED 0x00002000
321 #define VM_IO 0x00004000 /* Memory mapped I/O or similar */
323 /* Used by sys_madvise() */
324 #define VM_SEQ_READ 0x00008000 /* App will access data sequentially */
325 #define VM_RAND_READ 0x00010000 /* App will not benefit from clustered reads */
327 #define VM_DONTCOPY 0x00020000 /* Do not copy this vma on fork */
328 #define VM_DONTEXPAND 0x00040000 /* Cannot expand with mremap() */
329 #define VM_RESERVED 0x00080000 /* Don't unmap it from swap_out */
330 #define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */
331 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
332 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
334 #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
335 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
336 #endif
338 #ifdef CONFIG_STACK_GROWSUP
339 #define VM_STACK_FLAGS (VM_GROWSUP | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
340 #else
341 #define VM_STACK_FLAGS (VM_GROWSDOWN | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
342 #endif
344 #if 0 /* removed when rebasing to 2.6.13 */
345 /*
346 * The zone field is never updated after free_area_init_core()
347 * sets it, so none of the operations on it need to be atomic.
348 * We'll have up to (MAX_NUMNODES * MAX_NR_ZONES) zones total,
349 * so we use (MAX_NODES_SHIFT + MAX_ZONES_SHIFT) here to get enough bits.
350 */
351 #define NODEZONE_SHIFT (sizeof(page_flags_t)*8 - MAX_NODES_SHIFT - MAX_ZONES_SHIFT)
352 #define NODEZONE(node, zone) ((node << ZONES_SHIFT) | zone)
354 static inline unsigned long page_zonenum(struct page_info *page)
355 {
356 return (page->flags >> NODEZONE_SHIFT) & (~(~0UL << ZONES_SHIFT));
357 }
358 static inline unsigned long page_to_nid(struct page_info *page)
359 {
360 return (page->flags >> (NODEZONE_SHIFT + ZONES_SHIFT));
361 }
363 struct zone;
364 extern struct zone *zone_table[];
366 static inline struct zone *page_zone(struct page_info *page)
367 {
368 return zone_table[page->flags >> NODEZONE_SHIFT];
369 }
371 static inline void set_page_zone(struct page_info *page, unsigned long nodezone_num)
372 {
373 page->flags &= ~(~0UL << NODEZONE_SHIFT);
374 page->flags |= nodezone_num << NODEZONE_SHIFT;
375 }
376 #endif
378 #ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */
379 extern unsigned long max_mapnr;
380 #endif
382 static inline void *lowmem_page_address(struct page_info *page)
383 {
384 return __va(page_to_mfn(page) << PAGE_SHIFT);
385 }
387 #if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)
388 #define HASHED_PAGE_VIRTUAL
389 #endif
391 #if defined(WANT_PAGE_VIRTUAL)
392 #define page_address(page) ((page)->virtual)
393 #define set_page_address(page, address) \
394 do { \
395 (page)->virtual = (address); \
396 } while(0)
397 #define page_address_init() do { } while(0)
398 #endif
400 #if defined(HASHED_PAGE_VIRTUAL)
401 void *page_address(struct page_info *page);
402 void set_page_address(struct page_info *page, void *virtual);
403 void page_address_init(void);
404 #endif
406 #if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL)
407 #define page_address(page) lowmem_page_address(page)
408 #define set_page_address(page, address) do { } while(0)
409 #define page_address_init() do { } while(0)
410 #endif
413 #ifndef CONFIG_DEBUG_PAGEALLOC
414 static inline void
415 kernel_map_pages(struct page_info *page, int numpages, int enable)
416 {
417 }
418 #endif
420 extern unsigned long num_physpages;
421 extern unsigned long totalram_pages;
422 extern int nr_swap_pages;
424 extern void alloc_dom_xen_and_dom_io(void);
425 extern void relinquish_mm(struct domain* d);
426 extern struct page_info * assign_new_domain_page(struct domain *d, unsigned long mpaddr);
427 extern void assign_new_domain0_page(struct domain *d, unsigned long mpaddr);
428 extern void __assign_domain_page(struct domain *d, unsigned long mpaddr, unsigned long physaddr, unsigned long flags);
429 extern void assign_domain_page(struct domain *d, unsigned long mpaddr, unsigned long physaddr);
430 extern void assign_domain_io_page(struct domain *d, unsigned long mpaddr, unsigned long flags);
431 extern unsigned long lookup_domain_mpa(struct domain *d, unsigned long mpaddr);
432 extern void *domain_mpa_to_imva(struct domain *d, unsigned long mpaddr);
434 #ifdef CONFIG_XEN_IA64_DOM0_VP
435 extern unsigned long assign_domain_mmio_page(struct domain *d, unsigned long mpaddr, unsigned long size);
436 extern unsigned long assign_domain_mach_page(struct domain *d, unsigned long mpaddr, unsigned long size, unsigned long flags);
437 int domain_page_mapped(struct domain *d, unsigned long mpaddr);
438 int efi_mmio(unsigned long physaddr, unsigned long size);
439 extern unsigned long __lookup_domain_mpa(struct domain *d, unsigned long mpaddr);
440 extern unsigned long ____lookup_domain_mpa(struct domain *d, unsigned long mpaddr);
441 extern unsigned long do_dom0vp_op(unsigned long cmd, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3);
442 extern unsigned long dom0vp_zap_physmap(struct domain *d, unsigned long gpfn, unsigned int extent_order);
443 extern unsigned long dom0vp_add_physmap(struct domain* d, unsigned long gpfn, unsigned long mfn, unsigned long flags, domid_t domid);
444 #endif
446 extern volatile unsigned long *mpt_table;
447 extern unsigned long gmfn_to_mfn_foreign(struct domain *d, unsigned long gpfn);
448 extern u64 translate_domain_pte(u64 pteval, u64 address, u64 itir__, u64* logps);
449 #define machine_to_phys_mapping mpt_table
451 #define INVALID_M2P_ENTRY (~0UL)
452 #define VALID_M2P(_e) (!((_e) & (1UL<<63)))
453 #define IS_INVALID_M2P_ENTRY(_e) (!VALID_M2P(_e))
455 #define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
456 #define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)])
458 /* If pmt table is provided by control pannel later, we need __get_user
459 * here. However if it's allocated by HV, we should access it directly
460 */
462 #define mfn_to_gmfn(_d, mfn) \
463 get_gpfn_from_mfn(mfn)
465 #define gmfn_to_mfn(_d, gpfn) \
466 gmfn_to_mfn_foreign((_d), (gpfn))
468 #define __gpfn_invalid(_d, gpfn) \
469 (lookup_domain_mpa((_d), ((gpfn)<<PAGE_SHIFT)) & GPFN_INV_MASK)
471 #define __gmfn_valid(_d, gpfn) !__gpfn_invalid(_d, gpfn)
473 /* Return I/O type if trye */
474 #define __gpfn_is_io(_d, gpfn) \
475 ({ \
476 u64 pte, ret=0; \
477 pte=lookup_domain_mpa((_d), ((gpfn)<<PAGE_SHIFT)); \
478 if(!(pte&GPFN_INV_MASK)) \
479 ret = pte & GPFN_IO_MASK; \
480 ret; \
481 })
483 #define __gpfn_is_mem(_d, gpfn) \
484 ({ \
485 u64 pte, ret=0; \
486 pte=lookup_domain_mpa((_d), ((gpfn)<<PAGE_SHIFT)); \
487 if((!(pte&GPFN_INV_MASK))&&((pte & GPFN_IO_MASK)==GPFN_MEM)) \
488 ret = 1; \
489 ret; \
490 })
493 #define __gpa_to_mpa(_d, gpa) \
494 ((gmfn_to_mfn((_d),(gpa)>>PAGE_SHIFT)<<PAGE_SHIFT)|((gpa)&~PAGE_MASK))
496 /* Arch-specific portion of memory_op hypercall. */
497 #define arch_memory_op(op, arg) (-ENOSYS)
499 #ifndef CONFIG_XEN_IA64_DOM0_VP
500 #define steal_page(d, p, f) 0
501 #else
502 int steal_page(
503 struct domain *d, struct page_info *page, unsigned int memflags);
504 #endif
506 #endif /* __ASM_IA64_MM_H__ */