ia64/xen-unstable

view xen/common/kernel.c @ 8976:4f4625f80528

Rename XENFEAT_ring0_kernel to slightly more generic XENFEAT_supervisor_mode_kernel.
Add comments in public header version.h to explain what all the different
feature flags mean. Add a new flag XENFEAT_pae_pgdir_above_4gb to inform the guest
that its PAE page directories do not need to conform to the usual hardware
restriction.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Feb 23 11:59:27 2006 +0100 (2006-02-23)
parents 138e145f83f6
children ee8041b0ab86
line source
1 /******************************************************************************
2 * kernel.c
3 *
4 * Copyright (c) 2002-2005 K A Fraser
5 */
7 #include <xen/config.h>
8 #include <xen/init.h>
9 #include <xen/lib.h>
10 #include <xen/errno.h>
11 #include <xen/compile.h>
12 #include <xen/sched.h>
13 #include <xen/shadow.h>
14 #include <asm/current.h>
15 #include <public/nmi.h>
16 #include <public/version.h>
18 int tainted;
20 void cmdline_parse(char *cmdline)
21 {
22 char opt[100], *optval, *p = cmdline, *q;
23 struct kernel_param *param;
25 if ( p == NULL )
26 return;
28 /* Skip whitespace and the image name. */
29 while ( *p == ' ' )
30 p++;
31 if ( (p = strchr(p, ' ')) == NULL )
32 return;
34 for ( ; ; )
35 {
36 /* Skip whitespace. */
37 while ( *p == ' ' )
38 p++;
39 if ( *p == '\0' )
40 break;
42 /* Grab the next whitespace-delimited option. */
43 q = opt;
44 while ( (*p != ' ') && (*p != '\0') )
45 *q++ = *p++;
46 *q = '\0';
48 /* Search for value part of a key=value option. */
49 optval = strchr(opt, '=');
50 if ( optval != NULL )
51 *optval++ = '\0';
53 for ( param = &__setup_start; param <= &__setup_end; param++ )
54 {
55 if ( strcmp(param->name, opt ) != 0 )
56 continue;
58 switch ( param->type )
59 {
60 case OPT_STR:
61 if ( optval != NULL )
62 {
63 strncpy(param->var, optval, param->len);
64 ((char *)param->var)[param->len-1] = '\0';
65 }
66 break;
67 case OPT_UINT:
68 if ( optval != NULL )
69 *(unsigned int *)param->var =
70 simple_strtol(optval, (char **)&optval, 0);
71 break;
72 case OPT_BOOL:
73 *(int *)param->var = 1;
74 break;
75 case OPT_CUSTOM:
76 if ( optval != NULL )
77 ((void (*)(char *))param->var)(optval);
78 break;
79 }
80 }
81 }
82 }
84 /**
85 * print_tainted - return a string to represent the kernel taint state.
86 *
87 * 'S' - SMP with CPUs not designed for SMP.
88 * 'M' - Machine had a machine check experience.
89 * 'B' - System has hit bad_page.
90 *
91 * The string is overwritten by the next call to print_taint().
92 */
93 char *print_tainted(char *str)
94 {
95 if ( tainted )
96 {
97 snprintf(str, TAINT_STRING_MAX_LEN, "Tainted: %c%c%c",
98 tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
99 tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
100 tainted & TAINT_BAD_PAGE ? 'B' : ' ');
101 }
102 else
103 {
104 snprintf(str, TAINT_STRING_MAX_LEN, "Not tainted");
105 }
107 return str;
108 }
110 void add_taint(unsigned flag)
111 {
112 tainted |= flag;
113 }
115 /*
116 * Simple hypercalls.
117 */
119 long do_xen_version(int cmd, void *arg)
120 {
121 switch ( cmd )
122 {
123 case XENVER_version:
124 {
125 return (XEN_VERSION<<16) | (XEN_SUBVERSION);
126 }
128 case XENVER_extraversion:
129 {
130 xen_extraversion_t extraversion;
131 safe_strcpy(extraversion, XEN_EXTRAVERSION);
132 if ( copy_to_user(arg, extraversion, sizeof(extraversion)) )
133 return -EFAULT;
134 return 0;
135 }
137 case XENVER_compile_info:
138 {
139 struct xen_compile_info info;
140 safe_strcpy(info.compiler, XEN_COMPILER);
141 safe_strcpy(info.compile_by, XEN_COMPILE_BY);
142 safe_strcpy(info.compile_domain, XEN_COMPILE_DOMAIN);
143 safe_strcpy(info.compile_date, XEN_COMPILE_DATE);
144 if ( copy_to_user(arg, &info, sizeof(info)) )
145 return -EFAULT;
146 return 0;
147 }
149 case XENVER_capabilities:
150 {
151 xen_capabilities_info_t info;
152 extern void arch_get_xen_caps(xen_capabilities_info_t info);
154 memset(info, 0, sizeof(info));
155 arch_get_xen_caps(info);
157 if ( copy_to_user(arg, info, sizeof(info)) )
158 return -EFAULT;
159 return 0;
160 }
162 case XENVER_platform_parameters:
163 {
164 xen_platform_parameters_t params = {
165 .virt_start = HYPERVISOR_VIRT_START
166 };
167 if ( copy_to_user(arg, &params, sizeof(params)) )
168 return -EFAULT;
169 return 0;
171 }
173 case XENVER_changeset:
174 {
175 xen_changeset_info_t chgset;
176 safe_strcpy(chgset, XEN_CHANGESET);
177 if ( copy_to_user(arg, chgset, sizeof(chgset)) )
178 return -EFAULT;
179 return 0;
180 }
182 case XENVER_get_features:
183 {
184 xen_feature_info_t fi;
186 if ( copy_from_user(&fi, arg, sizeof(fi)) )
187 return -EFAULT;
189 switch ( fi.submap_idx )
190 {
191 case 0:
192 fi.submap = 0;
193 if ( shadow_mode_translate(current->domain) )
194 fi.submap |=
195 (1U << XENFEAT_writable_page_tables) |
196 (1U << XENFEAT_auto_translated_physmap) |
197 (1U << XENFEAT_pae_pgdir_above_4gb);
198 break;
199 default:
200 return -EINVAL;
201 }
203 if ( copy_to_user(arg, &fi, sizeof(fi)) )
204 return -EFAULT;
205 return 0;
206 }
208 }
210 return -ENOSYS;
211 }
213 long do_nmi_op(unsigned int cmd, void *arg)
214 {
215 struct vcpu *v = current;
216 struct domain *d = current->domain;
217 long rc = 0;
219 switch ( cmd )
220 {
221 case XENNMI_register_callback:
222 if ( (d->domain_id != 0) || (v->vcpu_id != 0) )
223 {
224 rc = -EINVAL;
225 }
226 else
227 {
228 v->nmi_addr = (unsigned long)arg;
229 #ifdef CONFIG_X86
230 /*
231 * If no handler was registered we can 'lose the NMI edge'.
232 * Re-assert it now.
233 */
234 if ( d->shared_info->arch.nmi_reason != 0 )
235 set_bit(_VCPUF_nmi_pending, &v->vcpu_flags);
236 #endif
237 }
238 break;
239 case XENNMI_unregister_callback:
240 v->nmi_addr = 0;
241 break;
242 default:
243 rc = -ENOSYS;
244 break;
245 }
247 return rc;
248 }
250 long do_vm_assist(unsigned int cmd, unsigned int type)
251 {
252 return vm_assist(current->domain, cmd, type);
253 }
255 long do_ni_hypercall(void)
256 {
257 /* No-op hypercall. */
258 return -ENOSYS;
259 }
261 /*
262 * Local variables:
263 * mode: C
264 * c-set-style: "BSD"
265 * c-basic-offset: 4
266 * tab-width: 4
267 * indent-tabs-mode: nil
268 * End:
269 */