debuggers.hg

view tools/libxc/xc_core_x86.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 3e4a70d6c50a
children 3ffdb094c2c0
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 (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
17 * VA Linux Systems Japan K.K.
18 *
19 */
21 #include "xg_private.h"
22 #include "xc_core.h"
23 #include "xc_e820.h"
25 #define GET_FIELD(_p, _f) ((dinfo->guest_width==8) ? ((_p)->x64._f) : ((_p)->x32._f))
27 #ifndef MAX
28 #define MAX(_a, _b) ((_a) >= (_b) ? (_a) : (_b))
29 #endif
31 int
32 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
33 unsigned long pfn)
34 {
35 if ((pfn >= 0xa0 && pfn < 0xc0) /* VGA hole */
36 || (pfn >= (HVM_BELOW_4G_MMIO_START >> PAGE_SHIFT)
37 && pfn < (1ULL<<32) >> PAGE_SHIFT)) /* MMIO */
38 return 0;
39 return 1;
40 }
43 static int nr_gpfns(int xc_handle, domid_t domid)
44 {
45 return xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &domid) + 1;
46 }
48 int
49 xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
50 {
51 return info->hvm;
52 }
54 int
55 xc_core_arch_memory_map_get(int xc_handle, struct xc_core_arch_context *unused,
56 xc_dominfo_t *info, shared_info_any_t *live_shinfo,
57 xc_core_memory_map_t **mapp,
58 unsigned int *nr_entries)
59 {
60 unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
61 xc_core_memory_map_t *map;
63 map = malloc(sizeof(*map));
64 if ( map == NULL )
65 {
66 PERROR("Could not allocate memory");
67 return -1;
68 }
70 map->addr = 0;
71 map->size = ((uint64_t)p2m_size) << PAGE_SHIFT;
73 *mapp = map;
74 *nr_entries = 1;
75 return 0;
76 }
78 static int
79 xc_core_arch_map_p2m_rw(int xc_handle, struct domain_info_context *dinfo, xc_dominfo_t *info,
80 shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
81 unsigned long *pfnp, int rw)
82 {
83 /* Double and single indirect references to the live P2M table */
84 xen_pfn_t *live_p2m_frame_list_list = NULL;
85 xen_pfn_t *live_p2m_frame_list = NULL;
86 /* Copies of the above. */
87 xen_pfn_t *p2m_frame_list_list = NULL;
88 xen_pfn_t *p2m_frame_list = NULL;
90 uint32_t dom = info->domid;
91 int ret = -1;
92 int err;
93 int i;
95 dinfo->p2m_size = nr_gpfns(xc_handle, info->domid);
96 if ( dinfo->p2m_size < info->nr_pages )
97 {
98 ERROR("p2m_size < nr_pages -1 (%lx < %lx", dinfo->p2m_size, info->nr_pages - 1);
99 goto out;
100 }
102 live_p2m_frame_list_list =
103 xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ,
104 GET_FIELD(live_shinfo, arch.pfn_to_mfn_frame_list_list));
106 if ( !live_p2m_frame_list_list )
107 {
108 PERROR("Couldn't map p2m_frame_list_list (errno %d)", errno);
109 goto out;
110 }
112 /* Get a local copy of the live_P2M_frame_list_list */
113 if ( !(p2m_frame_list_list = malloc(PAGE_SIZE)) )
114 {
115 ERROR("Couldn't allocate p2m_frame_list_list array");
116 goto out;
117 }
118 memcpy(p2m_frame_list_list, live_p2m_frame_list_list, PAGE_SIZE);
120 /* Canonicalize guest's unsigned long vs ours */
121 if ( dinfo->guest_width > sizeof(unsigned long) )
122 for ( i = 0; i < PAGE_SIZE/sizeof(unsigned long); i++ )
123 if ( i < PAGE_SIZE/dinfo->guest_width )
124 p2m_frame_list_list[i] = ((uint64_t *)p2m_frame_list_list)[i];
125 else
126 p2m_frame_list_list[i] = 0;
127 else if ( dinfo->guest_width < sizeof(unsigned long) )
128 for ( i = PAGE_SIZE/sizeof(unsigned long) - 1; i >= 0; i-- )
129 p2m_frame_list_list[i] = ((uint32_t *)p2m_frame_list_list)[i];
131 live_p2m_frame_list =
132 xc_map_foreign_pages(xc_handle, dom, PROT_READ,
133 p2m_frame_list_list,
134 P2M_FLL_ENTRIES);
136 if ( !live_p2m_frame_list )
137 {
138 PERROR("Couldn't map p2m_frame_list");
139 goto out;
140 }
142 /* Get a local copy of the live_P2M_frame_list */
143 if ( !(p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE)) )
144 {
145 ERROR("Couldn't allocate p2m_frame_list array");
146 goto out;
147 }
148 memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE);
149 memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE);
151 /* Canonicalize guest's unsigned long vs ours */
152 if ( dinfo->guest_width > sizeof(unsigned long) )
153 for ( i = 0; i < P2M_FL_ENTRIES; i++ )
154 p2m_frame_list[i] = ((uint64_t *)p2m_frame_list)[i];
155 else if ( dinfo->guest_width < sizeof(unsigned long) )
156 for ( i = P2M_FL_ENTRIES - 1; i >= 0; i-- )
157 p2m_frame_list[i] = ((uint32_t *)p2m_frame_list)[i];
159 *live_p2m = xc_map_foreign_pages(xc_handle, dom,
160 rw ? (PROT_READ | PROT_WRITE) : PROT_READ,
161 p2m_frame_list,
162 P2M_FL_ENTRIES);
164 if ( !*live_p2m )
165 {
166 PERROR("Couldn't map p2m table");
167 goto out;
168 }
170 *pfnp = dinfo->p2m_size;
172 ret = 0;
174 out:
175 err = errno;
177 if ( live_p2m_frame_list_list )
178 munmap(live_p2m_frame_list_list, PAGE_SIZE);
180 if ( live_p2m_frame_list )
181 munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
183 if ( p2m_frame_list_list )
184 free(p2m_frame_list_list);
186 if ( p2m_frame_list )
187 free(p2m_frame_list);
189 errno = err;
190 return ret;
191 }
193 int
194 xc_core_arch_map_p2m(int xc_handle, unsigned int guest_width, xc_dominfo_t *info,
195 shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
196 unsigned long *pfnp)
197 {
198 struct domain_info_context _dinfo = { .guest_width = guest_width };
199 struct domain_info_context *dinfo = &_dinfo;
200 return xc_core_arch_map_p2m_rw(xc_handle, dinfo, info,
201 live_shinfo, live_p2m, pfnp, 0);
202 }
204 int
205 xc_core_arch_map_p2m_writable(int xc_handle, unsigned int guest_width, xc_dominfo_t *info,
206 shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
207 unsigned long *pfnp)
208 {
209 struct domain_info_context _dinfo = { .guest_width = guest_width };
210 struct domain_info_context *dinfo = &_dinfo;
211 return xc_core_arch_map_p2m_rw(xc_handle, dinfo, info,
212 live_shinfo, live_p2m, pfnp, 1);
213 }
214 /*
215 * Local variables:
216 * mode: C
217 * c-set-style: "BSD"
218 * c-basic-offset: 4
219 * tab-width: 4
220 * indent-tabs-mode: nil
221 * End:
222 */