ia64/xen-unstable

view tools/libxc/ia64/xc_ia64_stubs.c @ 15847:192f2df46e67

[IA64] Foreign p2m: make xc_ia64_get_pfn_list() static

Now xc_ia64_get_pfn_list() isn't used anymore. Make it static.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Thu Sep 06 15:04:07 2007 -0600 (2007-09-06)
parents 3cde7ffdfd0f
children 716a637722e4
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;
95 hypercall.arg[5] = 0;
97 if (lock_pages(memmap_info,
98 sizeof(*memmap_info) + memmap_info->efi_memmap_size) != 0) {
99 saved_errno = errno;
100 munmap(addr, p2m_size);
101 errno = saved_errno;
102 return NULL;
103 }
104 ret = do_xen_hypercall(xc_handle, &hypercall);
105 saved_errno = errno;
106 unlock_pages(memmap_info,
107 sizeof(*memmap_info) + memmap_info->efi_memmap_size);
108 if (ret < 0) {
109 munmap(addr, p2m_size);
110 errno = saved_errno;
111 return NULL;
112 }
114 *p2m_size_p = p2m_size;
115 return addr;
116 }
118 void
119 xc_ia64_p2m_init(struct xen_ia64_p2m_table *p2m_table)
120 {
121 p2m_table->size = 0;
122 p2m_table->p2m = NULL;
123 }
125 int
126 xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, int xc_handle,
127 uint32_t domid, struct xen_ia64_memmap_info *memmap_info,
128 unsigned long flag)
129 {
130 p2m_table->p2m = xc_ia64_map_foreign_p2m(xc_handle, domid, memmap_info,
131 flag, &p2m_table->size);
132 if (p2m_table->p2m == NULL) {
133 PERROR("Could not map foreign p2m. falling back to old method");
134 return -1;
135 }
136 return 0;
137 }
139 void
140 xc_ia64_p2m_unmap(struct xen_ia64_p2m_table *p2m_table)
141 {
142 if (p2m_table->p2m == NULL)
143 return;
144 munmap(p2m_table->p2m, p2m_table->size);
145 //p2m_table->p2m = NULL;
146 //p2m_table->size = 0;
147 }
149 /*
150 * XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h
151 * Should those be exported by arch-ia64.h?
152 */
153 #define _PAGE_P_BIT 0
154 #define _PAGE_P (1UL << _PAGE_P_BIT) /* page present bit */
155 #define _PAGE_PGC_ALLOCATED_BIT 59 /* _PGC_allocated */
156 #define _PAGE_PGC_ALLOCATED (1UL << _PAGE_PGC_ALLOCATED_BIT)
158 #define IA64_MAX_PHYS_BITS 50 /* max. number of physical address bits (architected) */
159 #define _PAGE_PPN_MASK (((1UL << IA64_MAX_PHYS_BITS) - 1) & ~0xfffUL)
161 int
162 xc_ia64_p2m_present(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
163 {
164 if (sizeof(p2m_table->p2m[0]) * gpfn < p2m_table->size)
165 return !!(p2m_table->p2m[gpfn] & _PAGE_P);
166 return 0;
167 }
169 int
170 xc_ia64_p2m_allocated(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
171 {
172 if (sizeof(p2m_table->p2m[0]) * gpfn < p2m_table->size) {
173 unsigned long pte = p2m_table->p2m[gpfn];
174 return !!((pte & _PAGE_P) && (pte & _PAGE_PGC_ALLOCATED));
175 }
176 return 0;
177 }
179 unsigned long
180 xc_ia64_p2m_mfn(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
181 {
182 unsigned long pte;
184 if (sizeof(p2m_table->p2m[0]) * gpfn >= p2m_table->size)
185 return INVALID_MFN;
186 pte = p2m_table->p2m[gpfn];
187 if (!(pte & _PAGE_P))
188 return INVALID_MFN;
189 return (pte & _PAGE_PPN_MASK) >> PAGE_SHIFT;
190 }
192 /*
193 * Local variables:
194 * mode: C
195 * c-set-style: "BSD"
196 * c-basic-offset: 4
197 * tab-width: 4
198 * indent-tabs-mode: nil
199 * End:
200 */