ia64/xen-unstable

view xen/include/asm-powerpc/mm.h @ 14239:b75609e1fa81

[POWERPC][XEN] Implement guest_physmap_{add,remove}_page().
- Use p2m array in pfn2mfn() and DOMCTL_getmemlist.
- Remove domain extent list.
- Create and use an m2p array for mfn_to_gmfn().
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Fri Mar 02 17:07:59 2007 -0600 (2007-03-02)
parents f56981f78d73
children 36e6f85cd572
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright IBM Corp. 2005, 2006, 2007
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 * Jimi Xenidis <jimix@watson.ibm.com>
20 */
22 #ifndef _ASM_MM_H_
23 #define _ASM_MM_H_
25 #include <public/xen.h>
26 #include <xen/list.h>
27 #include <xen/types.h>
28 #include <xen/mm.h>
29 #include <asm/system.h>
30 #include <asm/flushtlb.h>
31 #include <asm/page.h>
32 #include <asm/debugger.h>
34 #define memguard_guard_range(_p,_l) ((void)0)
35 #define memguard_unguard_range(_p,_l) ((void)0)
37 extern unsigned long xenheap_phys_end;
38 extern int boot_of_mem_avail(int pos, ulong *start, ulong *end);
40 /*
41 * Per-page-frame information.
42 *
43 * Every architecture must ensure the following:
44 * 1. 'struct page_info' contains a 'struct list_head list'.
45 * 2. Provide a PFN_ORDER() macro for accessing the order of a free page.
46 */
47 #define PFN_ORDER(_pfn) ((_pfn)->u.free.order)
49 /* XXX copy-and-paste job; re-examine me */
50 struct page_info
51 {
52 /* Each frame can be threaded onto a doubly-linked list. */
53 struct list_head list;
55 /* Timestamp from 'TLB clock', used to reduce need for safety flushes. */
56 u32 tlbflush_timestamp;
58 /* Reference count and various PGC_xxx flags and fields. */
59 unsigned long count_info;
61 /* Context-dependent fields follow... */
62 union {
64 /* Page is in use: ((count_info & PGC_count_mask) != 0). */
65 struct {
66 /* Owner of this page (NULL if page is anonymous). */
67 u32 _domain;
68 /* Type reference count and various PGT_xxx flags and fields. */
69 unsigned long type_info;
70 } inuse;
72 /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */
73 struct {
74 /* Mask of possibly-tainted TLBs. */
75 cpumask_t cpumask;
76 /* Order-size of the free chunk this page is the head of. */
77 u8 order;
78 } free;
80 } u;
82 };
84 /* The following page types are MUTUALLY EXCLUSIVE. */
85 #define PGT_none (0UL<<29) /* no special uses of this page */
86 #define PGT_RMA (1UL<<29) /* This page is an RMA page? */
87 #define PGT_writable_page (7UL<<29) /* has writable mappings of this page? */
88 #define PGT_type_mask (7UL<<29) /* Bits 29-31. */
90 /* Owning guest has pinned this page to its current type? */
91 #define _PGT_pinned 28
92 #define PGT_pinned (1UL<<_PGT_pinned)
93 /* Has this page been validated for use as its current type? */
94 #define _PGT_validated 27
95 #define PGT_validated (1UL<<_PGT_validated)
97 /* 16-bit count of uses of this frame as its current type. */
98 #define PGT_count_mask ((1UL<<16)-1)
100 /* Cleared when the owning guest 'frees' this page. */
101 #define _PGC_allocated 31
102 #define PGC_allocated (1UL<<_PGC_allocated)
103 /* Set on a *guest* page to mark it out-of-sync with its shadow */
104 #define _PGC_out_of_sync 30
105 #define PGC_out_of_sync (1UL<<_PGC_out_of_sync)
106 /* Set when is using a page as a page table */
107 #define _PGC_page_table 29
108 #define PGC_page_table (1UL<<_PGC_page_table)
109 /* Set when using page for RMA */
110 #define _PGC_page_RMA 28
111 #define PGC_page_RMA (1UL<<_PGC_page_RMA)
112 /* 29-bit count of references to this frame. */
113 #define PGC_count_mask ((1UL<<28)-1)
115 #define IS_XEN_HEAP_FRAME(_pfn) (page_to_maddr(_pfn) < xenheap_phys_end)
117 static inline struct domain *unpickle_domptr(u32 _domain)
118 { return ((_domain == 0) || (_domain & 1)) ? NULL : __va(_domain); }
120 static inline u32 pickle_domptr(struct domain *domain)
121 { return (domain == NULL) ? 0 : (u32)__pa(domain); }
123 #define PRtype_info "016lx"/* should only be used for printk's */
125 #define page_get_owner(_p) (unpickle_domptr((_p)->u.inuse._domain))
126 #define page_set_owner(_p,_d) ((_p)->u.inuse._domain = pickle_domptr(_d))
128 #define XENSHARE_writable 0
129 #define XENSHARE_readonly 1
130 extern void share_xen_page_with_guest(
131 struct page_info *page, struct domain *d, int readonly);
132 extern void share_xen_page_with_privileged_guests(
133 struct page_info *page, int readonly);
135 extern struct page_info *frame_table;
136 extern unsigned long max_page;
137 extern unsigned long total_pages;
138 void init_frametable(void);
139 void init_machine_to_phys_table(void);
140 void free_rma_check(struct page_info *page);
142 static inline void put_page(struct page_info *page)
143 {
144 u32 nx, x, y = page->count_info;
146 do {
147 x = y;
148 nx = x - 1;
149 }
150 while ( unlikely((y = cmpxchg(&page->count_info, x, nx)) != x) );
152 if ( unlikely((nx & PGC_count_mask) == 0) ) {
153 /* RMA pages can only be released while the domain is dying */
154 free_rma_check(page);
155 free_domheap_page(page);
156 }
157 }
159 static inline int get_page(struct page_info *page,
160 struct domain *domain)
161 {
162 u32 x, nx, y = page->count_info;
163 u32 d, nd = page->u.inuse._domain;
164 u32 _domain = pickle_domptr(domain);
166 do {
167 x = y;
168 nx = x + 1;
169 d = nd;
170 if ( unlikely((x & PGC_count_mask) == 0) || /* Not allocated? */
171 unlikely((nx & PGC_count_mask) == 0) || /* Count overflow? */
172 unlikely(d != _domain) ) /* Wrong owner? */
173 {
174 return 0;
175 }
176 y = cmpxchg(&page->count_info, x, nx);
177 }
178 while ( unlikely(y != x) );
180 return 1;
181 }
183 extern void put_page_type(struct page_info *page);
184 extern int get_page_type(struct page_info *page, unsigned long type);
186 static inline void put_page_and_type(struct page_info *page)
187 {
188 put_page_type(page);
189 put_page(page);
190 }
192 static inline int get_page_and_type(struct page_info *page,
193 struct domain *domain,
194 unsigned long type)
195 {
196 int rc = get_page(page, domain);
198 if ( likely(rc) && unlikely(!get_page_type(page, type)) )
199 {
200 put_page(page);
201 rc = 0;
202 }
204 return rc;
205 }
207 static inline int page_is_removable(struct page_info *page)
208 {
209 return ((page->count_info & PGC_count_mask) == 1);
210 }
212 extern void synchronise_pagetables(unsigned long cpu_mask);
214 /* XXX don't know what this is for */
215 typedef struct {
216 void (*enable)(struct domain *);
217 void (*disable)(struct domain *);
218 } vm_assist_info_t;
219 extern vm_assist_info_t vm_assist_info[];
221 extern unsigned long *machine_phys_mapping;
222 #define machine_to_phys_mapping (machine_phys_mapping)
223 #define INVALID_M2P_ENTRY (~0UL)
225 #define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
226 #define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)])
228 extern unsigned long mfn_to_gmfn(struct domain *d, unsigned long mfn);
230 extern unsigned long paddr_to_maddr(unsigned long paddr);
232 /* INVALID_MFN can be any value that fails mfn_valid(). */
233 #define INVALID_MFN (~0U)
235 #define PFN_TYPE_NONE 0
236 #define PFN_TYPE_LOGICAL 2
237 #define PFN_TYPE_IO 3
238 #define PFN_TYPE_FOREIGN 4
239 #define PFN_TYPE_GNTTAB 5
241 extern ulong pfn2mfn(struct domain *d, ulong pfn, int *type);
242 static inline unsigned long gmfn_to_mfn(struct domain *d, unsigned long gmfn)
243 {
244 int mtype;
245 ulong mfn;
247 mfn = pfn2mfn(d, gmfn, &mtype);
248 if (mfn != INVALID_MFN) {
249 switch (mtype) {
250 case PFN_TYPE_LOGICAL:
251 break;
252 default:
253 WARN();
254 mfn = INVALID_MFN;
255 break;
256 }
257 }
258 return mfn;
259 }
261 extern int update_grant_va_mapping(unsigned long va,
262 unsigned long val,
263 struct domain *,
264 struct vcpu *);
266 /* Arch-specific portion of memory_op hypercall. */
267 long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg);
269 extern int allocate_rma(struct domain *d, unsigned int order_pages);
270 extern uint allocate_extents(struct domain *d, uint nrpages, uint rma_nrpages);
272 extern int steal_page(struct domain *d, struct page_info *page,
273 unsigned int memflags);
275 /* XXX these just exist until we can stop #including x86 code */
276 #define access_ok(addr,size) 1
277 #define array_access_ok(addr,count,size) 1
279 #define domain_clamp_alloc_bitsize(d, b) (b)
281 #endif