debuggers.hg

view tools/libxc/ia64/xc_ia64_stubs.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children f875aaa791f0
line source
1 #include "xg_private.h"
2 #include "xc_ia64.h"
4 /* this is a very ugly way of getting FPSR_DEFAULT. struct ia64_fpreg is
5 * mysteriously declared in two places: /usr/include/asm/fpu.h and
6 * /usr/include/bits/sigcontext.h. The former also defines FPSR_DEFAULT,
7 * the latter doesn't but is included (indirectly) by xg_private.h */
8 #define __ASSEMBLY__
9 #include <asm/fpu.h>
10 #undef __IA64_UL
11 #define __IA64_UL(x) ((unsigned long)(x))
12 #undef __ASSEMBLY__
14 unsigned long
15 xc_ia64_fpsr_default(void)
16 {
17 return FPSR_DEFAULT;
18 }
20 static int
21 xc_ia64_get_pfn_list(int xc_handle, uint32_t domid, xen_pfn_t *pfn_buf,
22 unsigned int start_page, unsigned int nr_pages)
23 {
24 DECLARE_DOMCTL;
25 int ret;
27 domctl.cmd = XEN_DOMCTL_getmemlist;
28 domctl.domain = (domid_t)domid;
29 domctl.u.getmemlist.max_pfns = nr_pages;
30 domctl.u.getmemlist.start_pfn = start_page;
31 domctl.u.getmemlist.num_pfns = 0;
32 set_xen_guest_handle(domctl.u.getmemlist.buffer, pfn_buf);
34 if (lock_pages(pfn_buf, nr_pages * sizeof(xen_pfn_t)) != 0) {
35 PERROR("Could not lock pfn list buffer");
36 return -1;
37 }
38 ret = do_domctl(xc_handle, &domctl);
39 unlock_pages(pfn_buf, nr_pages * sizeof(xen_pfn_t));
41 return ret < 0 ? -1 : nr_pages;
42 }
44 int
45 xc_get_pfn_list(int xc_handle, uint32_t domid, uint64_t *pfn_buf,
46 unsigned long max_pfns)
47 {
48 return xc_ia64_get_pfn_list(xc_handle, domid, (xen_pfn_t *)pfn_buf,
49 0, max_pfns);
50 }
52 long
53 xc_get_max_pages(int xc_handle, uint32_t domid)
54 {
55 struct xen_domctl domctl;
56 domctl.cmd = XEN_DOMCTL_getdomaininfo;
57 domctl.domain = (domid_t)domid;
58 return ((do_domctl(xc_handle, &domctl) < 0)
59 ? -1 : domctl.u.getdomaininfo.max_pages);
60 }
62 /*
63 * XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h
64 * Should PTRS_PER_PTE be exported by arch-ia64.h?
65 */
66 #define PTRS_PER_PTE (1UL << (PAGE_SHIFT - 3))
68 static void*
69 xc_ia64_map_foreign_p2m(int xc_handle, uint32_t dom,
70 struct xen_ia64_memmap_info *memmap_info,
71 unsigned long flags, unsigned long *p2m_size_p)
72 {
73 unsigned long gpfn_max;
74 unsigned long p2m_size;
75 void *addr;
76 privcmd_hypercall_t hypercall;
77 int ret;
78 int saved_errno;
80 gpfn_max = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom);
81 if (gpfn_max < 0)
82 return NULL;
83 p2m_size =
84 (((gpfn_max + 1) + PTRS_PER_PTE - 1) / PTRS_PER_PTE) << PAGE_SHIFT;
85 addr = mmap(NULL, p2m_size, PROT_READ, MAP_SHARED, xc_handle, 0);
86 if (addr == MAP_FAILED)
87 return NULL;
89 hypercall.op = __HYPERVISOR_ia64_dom0vp_op;
90 hypercall.arg[0] = IA64_DOM0VP_expose_foreign_p2m;
91 hypercall.arg[1] = (unsigned long)addr;
92 hypercall.arg[2] = dom;
93 hypercall.arg[3] = (unsigned long)memmap_info;
94 hypercall.arg[4] = flags;
96 if (lock_pages(memmap_info,
97 sizeof(*memmap_info) + memmap_info->efi_memmap_size) != 0) {
98 saved_errno = errno;
99 munmap(addr, p2m_size);
100 errno = saved_errno;
101 return NULL;
102 }
103 ret = do_xen_hypercall(xc_handle, &hypercall);
104 saved_errno = errno;
105 unlock_pages(memmap_info,
106 sizeof(*memmap_info) + memmap_info->efi_memmap_size);
107 if (ret < 0) {
108 munmap(addr, p2m_size);
109 errno = saved_errno;
110 return NULL;
111 }
113 *p2m_size_p = p2m_size;
114 return addr;
115 }
117 void
118 xc_ia64_p2m_init(struct xen_ia64_p2m_table *p2m_table)
119 {
120 p2m_table->size = 0;
121 p2m_table->p2m = NULL;
122 }
124 int
125 xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, int xc_handle,
126 uint32_t domid, struct xen_ia64_memmap_info *memmap_info,
127 unsigned long flag)
128 {
129 p2m_table->p2m = xc_ia64_map_foreign_p2m(xc_handle, domid, memmap_info,
130 flag, &p2m_table->size);
131 if (p2m_table->p2m == NULL) {
132 PERROR("Could not map foreign p2m. falling back to old method");
133 return -1;
134 }
135 return 0;
136 }
138 void
139 xc_ia64_p2m_unmap(struct xen_ia64_p2m_table *p2m_table)
140 {
141 if (p2m_table->p2m == NULL)
142 return;
143 munmap(p2m_table->p2m, p2m_table->size);
144 //p2m_table->p2m = NULL;
145 //p2m_table->size = 0;
146 }
148 /*
149 * XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h
150 * Should those be exported by arch-ia64.h?
151 */
152 #define _PAGE_P_BIT 0
153 #define _PAGE_P (1UL << _PAGE_P_BIT) /* page present bit */
154 #define _PAGE_PGC_ALLOCATED_BIT 59 /* _PGC_allocated */
155 #define _PAGE_PGC_ALLOCATED (1UL << _PAGE_PGC_ALLOCATED_BIT)
157 #define IA64_MAX_PHYS_BITS 50 /* max. number of physical address bits (architected) */
158 #define _PAGE_PPN_MASK (((1UL << IA64_MAX_PHYS_BITS) - 1) & ~0xfffUL)
160 int
161 xc_ia64_p2m_present(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
162 {
163 if (sizeof(p2m_table->p2m[0]) * gpfn < p2m_table->size)
164 return !!(p2m_table->p2m[gpfn] & _PAGE_P);
165 return 0;
166 }
168 int
169 xc_ia64_p2m_allocated(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
170 {
171 if (sizeof(p2m_table->p2m[0]) * gpfn < p2m_table->size) {
172 unsigned long pte = p2m_table->p2m[gpfn];
173 return !!((pte & _PAGE_P) && (pte & _PAGE_PGC_ALLOCATED));
174 }
175 return 0;
176 }
178 unsigned long
179 xc_ia64_p2m_mfn(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
180 {
181 unsigned long pte;
183 if (sizeof(p2m_table->p2m[0]) * gpfn >= p2m_table->size)
184 return INVALID_MFN;
185 pte = p2m_table->p2m[gpfn];
186 if (!(pte & _PAGE_P))
187 return INVALID_MFN;
188 return (pte & _PAGE_PPN_MASK) >> PAGE_SHIFT;
189 }
191 /*
192 * Local variables:
193 * mode: C
194 * c-set-style: "BSD"
195 * c-basic-offset: 4
196 * tab-width: 4
197 * indent-tabs-mode: nil
198 * End:
199 */