ia64/xen-unstable

view xen/arch/ia64/xen/dom0_ops.c @ 7924:2e74bab1981e

Add (incomplete) dom0_physinfo call to try with xm list and xen-bugtool
author djm@kirby.fc.hp.com
date Wed Nov 30 17:04:48 2005 -0600 (2005-11-30)
parents 760f5e85c706
children 0c94043f5c5b
line source
1 /******************************************************************************
2 * Arch-specific dom0_ops.c
3 *
4 * Process command requests from domain-0 guest OS.
5 *
6 * Copyright (c) 2002, K A Fraser
7 */
9 #include <xen/config.h>
10 #include <xen/types.h>
11 #include <xen/lib.h>
12 #include <xen/mm.h>
13 #include <public/dom0_ops.h>
14 #include <xen/sched.h>
15 #include <xen/event.h>
16 #include <asm/pdb.h>
17 #include <xen/trace.h>
18 #include <xen/console.h>
19 #include <public/sched_ctl.h>
21 long arch_do_dom0_op(dom0_op_t *op, dom0_op_t *u_dom0_op)
22 {
23 long ret = 0;
25 if ( !IS_PRIV(current->domain) )
26 return -EPERM;
28 switch ( op->cmd )
29 {
30 case DOM0_GETPAGEFRAMEINFO:
31 {
32 struct pfn_info *page;
33 unsigned long pfn = op->u.getpageframeinfo.pfn;
34 domid_t dom = op->u.getpageframeinfo.domain;
35 struct domain *d;
37 ret = -EINVAL;
39 if ( unlikely(pfn >= max_page) ||
40 unlikely((d = find_domain_by_id(dom)) == NULL) )
41 break;
43 page = &frame_table[pfn];
45 if ( likely(get_page(page, d)) )
46 {
47 ret = 0;
49 op->u.getpageframeinfo.type = NOTAB;
51 if ( (page->u.inuse.type_info & PGT_count_mask) != 0 )
52 {
53 switch ( page->u.inuse.type_info & PGT_type_mask )
54 {
55 default:
56 panic("No such page type\n");
57 break;
58 }
59 }
61 put_page(page);
62 }
64 put_domain(d);
66 copy_to_user(u_dom0_op, op, sizeof(*op));
67 }
68 break;
70 case DOM0_GETPAGEFRAMEINFO2:
71 {
72 #define GPF2_BATCH 128
73 int n,j;
74 int num = op->u.getpageframeinfo2.num;
75 domid_t dom = op->u.getpageframeinfo2.domain;
76 unsigned long *s_ptr = (unsigned long*) op->u.getpageframeinfo2.array;
77 struct domain *d;
78 unsigned long *l_arr;
79 ret = -ESRCH;
81 if ( unlikely((d = find_domain_by_id(dom)) == NULL) )
82 break;
84 if ( unlikely(num > 1024) )
85 {
86 ret = -E2BIG;
87 break;
88 }
90 l_arr = (unsigned long *)alloc_xenheap_page();
92 ret = 0;
93 for( n = 0; n < num; )
94 {
95 int k = ((num-n)>GPF2_BATCH)?GPF2_BATCH:(num-n);
97 if ( copy_from_user(l_arr, &s_ptr[n], k*sizeof(unsigned long)) )
98 {
99 ret = -EINVAL;
100 break;
101 }
103 for( j = 0; j < k; j++ )
104 {
105 struct pfn_info *page;
106 unsigned long mfn = l_arr[j];
108 if ( unlikely(mfn >= max_page) )
109 goto e2_err;
111 page = &frame_table[mfn];
113 if ( likely(get_page(page, d)) )
114 {
115 unsigned long type = 0;
117 switch( page->u.inuse.type_info & PGT_type_mask )
118 {
119 default:
120 panic("No such page type\n");
121 break;
122 }
124 if ( page->u.inuse.type_info & PGT_pinned )
125 type |= LPINTAB;
126 l_arr[j] |= type;
127 put_page(page);
128 }
129 else
130 {
131 e2_err:
132 l_arr[j] |= XTAB;
133 }
135 }
137 if ( copy_to_user(&s_ptr[n], l_arr, k*sizeof(unsigned long)) )
138 {
139 ret = -EINVAL;
140 break;
141 }
143 n += j;
144 }
146 free_xenheap_page((unsigned long)l_arr);
148 put_domain(d);
149 }
150 break;
151 /*
152 * NOTE: DOM0_GETMEMLIST has somewhat different semantics on IA64 -
153 * it actually allocates and maps pages.
154 */
155 case DOM0_GETMEMLIST:
156 {
157 unsigned long i;
158 struct domain *d = find_domain_by_id(op->u.getmemlist.domain);
159 unsigned long start_page = op->u.getmemlist.max_pfns >> 32;
160 unsigned long nr_pages = op->u.getmemlist.max_pfns & 0xffffffff;
161 unsigned long pfn;
162 unsigned long *buffer = op->u.getmemlist.buffer;
163 struct page *page;
165 ret = -EINVAL;
166 if ( d != NULL )
167 {
168 ret = 0;
170 /* A temp trick here. When max_pfns == -1, we assume
171 * the request is for machine contiguous pages, so request
172 * all pages at first query
173 */
174 if ((op->u.getmemlist.max_pfns == -1UL) &&
175 !test_bit(ARCH_VMX_CONTIG_MEM,&d->vcpu[0]->arch.arch_vmx.flags))
176 return vmx_alloc_contig_pages(d) ? (-ENOMEM) : 0;
178 for ( i = start_page; i < (start_page + nr_pages); i++ )
179 {
180 pfn = __gpfn_to_mfn_foreign(d, i);
182 if ( put_user(pfn, buffer) )
183 {
184 ret = -EFAULT;
185 break;
186 }
187 buffer++;
188 }
190 op->u.getmemlist.num_pfns = i - start_page;
191 copy_to_user(u_dom0_op, op, sizeof(*op));
193 put_domain(d);
194 }
195 }
196 break;
198 case DOM0_PHYSINFO:
199 {
200 dom0_physinfo_t *pi = &op->u.physinfo;
202 pi->threads_per_core = smp_num_siblings;
203 pi->cores_per_socket = 1; // FIXME
204 pi->sockets_per_node =
205 num_online_cpus() / (pi->threads_per_core * pi->cores_per_socket);
206 pi->nr_nodes = 1;
207 pi->total_pages = 99; // FIXME
208 pi->free_pages = avail_domheap_pages();
209 pi->cpu_khz = 100; // FIXME cpu_khz;
210 memset(pi->hw_cap, 0, sizeof(pi->hw_cap));
211 //memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4);
212 ret = 0;
213 if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
214 ret = -EFAULT;
215 }
216 break;
218 default:
219 printf("arch_do_dom0_op: unrecognized dom0 op: %d!!!\n",op->cmd);
220 ret = -ENOSYS;
222 }
224 return ret;
225 }