ia64/xen-unstable

view xen/common/kernel.c @ 19835:edfdeb150f27

Fix buildsystem to detect udev > version 124

udev removed the udevinfo symlink from versions higher than 123 and
xen's build-system could not detect if udev is in place and has the
required version.

Signed-off-by: Marc-A. Dahlhaus <mad@wol.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:02:37 2009 +0100 (2009-06-25)
parents 407e2e7dca5b
children
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/version.h>
12 #include <xen/sched.h>
13 #include <xen/paging.h>
14 #include <xen/nmi.h>
15 #include <xen/guest_access.h>
16 #include <asm/current.h>
17 #include <public/nmi.h>
18 #include <public/version.h>
19 #ifdef CONFIG_X86
20 #include <asm/shared.h>
21 #endif
23 #ifndef COMPAT
25 int tainted;
27 xen_commandline_t saved_cmdline;
29 void cmdline_parse(char *cmdline)
30 {
31 char opt[100], *optval, *optkey, *q;
32 const char *p = cmdline;
33 struct kernel_param *param;
34 int bool_assert;
36 safe_strcpy(saved_cmdline, cmdline);
38 if ( p == NULL )
39 return;
41 for ( ; ; )
42 {
43 /* Skip whitespace. */
44 while ( *p == ' ' )
45 p++;
46 if ( *p == '\0' )
47 break;
49 /* Grab the next whitespace-delimited option. */
50 q = optkey = opt;
51 while ( (*p != ' ') && (*p != '\0') )
52 {
53 if ( (q-opt) < (sizeof(opt)-1) ) /* avoid overflow */
54 *q++ = *p;
55 p++;
56 }
57 *q = '\0';
59 /* Search for value part of a key=value option. */
60 optval = strchr(opt, '=');
61 if ( optval != NULL )
62 *optval++ = '\0'; /* nul-terminate the option value */
63 else
64 optval = q; /* default option value is empty string */
66 /* Boolean parameters can be inverted with 'no-' prefix. */
67 bool_assert = !!strncmp("no-", optkey, 3);
68 if ( !bool_assert )
69 optkey += 3;
71 for ( param = &__setup_start; param <= &__setup_end; param++ )
72 {
73 if ( strcmp(param->name, optkey) )
74 continue;
76 switch ( param->type )
77 {
78 case OPT_STR:
79 strlcpy(param->var, optval, param->len);
80 break;
81 case OPT_UINT:
82 *(unsigned int *)param->var = simple_strtol(optval, NULL, 0);
83 break;
84 case OPT_BOOL:
85 case OPT_INVBOOL:
86 if ( !strcmp("no", optval) ||
87 !strcmp("off", optval) ||
88 !strcmp("false", optval) ||
89 !strcmp("0", optval) )
90 bool_assert = !bool_assert;
91 if ( param->type == OPT_INVBOOL )
92 bool_assert = !bool_assert;
93 *(int *)param->var = bool_assert;
94 break;
95 case OPT_CUSTOM:
96 ((void (*)(const char *))param->var)(optval);
97 break;
98 }
99 }
100 }
101 }
103 /**
104 * print_tainted - return a string to represent the kernel taint state.
105 *
106 * 'S' - SMP with CPUs not designed for SMP.
107 * 'M' - Machine had a machine check experience.
108 * 'B' - System has hit bad_page.
109 *
110 * The string is overwritten by the next call to print_taint().
111 */
112 char *print_tainted(char *str)
113 {
114 if ( tainted )
115 {
116 snprintf(str, TAINT_STRING_MAX_LEN, "Tainted: %c%c%c%c",
117 tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
118 tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
119 tainted & TAINT_BAD_PAGE ? 'B' : ' ',
120 tainted & TAINT_SYNC_CONSOLE ? 'C' : ' ');
121 }
122 else
123 {
124 snprintf(str, TAINT_STRING_MAX_LEN, "Not tainted");
125 }
127 return str;
128 }
130 void add_taint(unsigned flag)
131 {
132 tainted |= flag;
133 }
135 # define DO(fn) long do_##fn
137 #endif
139 /*
140 * Simple hypercalls.
141 */
143 DO(xen_version)(int cmd, XEN_GUEST_HANDLE(void) arg)
144 {
145 switch ( cmd )
146 {
147 case XENVER_version:
148 {
149 return (xen_major_version() << 16) | xen_minor_version();
150 }
152 case XENVER_extraversion:
153 {
154 xen_extraversion_t extraversion;
155 safe_strcpy(extraversion, xen_extra_version());
156 if ( copy_to_guest(arg, extraversion, ARRAY_SIZE(extraversion)) )
157 return -EFAULT;
158 return 0;
159 }
161 case XENVER_compile_info:
162 {
163 struct xen_compile_info info;
164 safe_strcpy(info.compiler, xen_compiler());
165 safe_strcpy(info.compile_by, xen_compile_by());
166 safe_strcpy(info.compile_domain, xen_compile_domain());
167 safe_strcpy(info.compile_date, xen_compile_date());
168 if ( copy_to_guest(arg, &info, 1) )
169 return -EFAULT;
170 return 0;
171 }
173 case XENVER_capabilities:
174 {
175 xen_capabilities_info_t info;
176 extern void arch_get_xen_caps(xen_capabilities_info_t *info);
178 memset(info, 0, sizeof(info));
179 arch_get_xen_caps(&info);
181 if ( copy_to_guest(arg, info, ARRAY_SIZE(info)) )
182 return -EFAULT;
183 return 0;
184 }
186 case XENVER_platform_parameters:
187 {
188 xen_platform_parameters_t params = {
189 .virt_start = HYPERVISOR_VIRT_START
190 };
191 if ( copy_to_guest(arg, &params, 1) )
192 return -EFAULT;
193 return 0;
195 }
197 case XENVER_changeset:
198 {
199 xen_changeset_info_t chgset;
200 safe_strcpy(chgset, xen_changeset());
201 if ( copy_to_guest(arg, chgset, ARRAY_SIZE(chgset)) )
202 return -EFAULT;
203 return 0;
204 }
206 case XENVER_get_features:
207 {
208 xen_feature_info_t fi;
209 struct domain *d = current->domain;
211 if ( copy_from_guest(&fi, arg, 1) )
212 return -EFAULT;
214 switch ( fi.submap_idx )
215 {
216 case 0:
217 fi.submap = 0;
218 if ( VM_ASSIST(d, VMASST_TYPE_pae_extended_cr3) )
219 fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
220 if ( paging_mode_translate(current->domain) )
221 fi.submap |=
222 (1U << XENFEAT_writable_page_tables) |
223 (1U << XENFEAT_auto_translated_physmap);
224 if ( supervisor_mode_kernel )
225 fi.submap |= 1U << XENFEAT_supervisor_mode_kernel;
226 #ifdef CONFIG_X86
227 if ( !is_hvm_vcpu(current) )
228 fi.submap |= (1U << XENFEAT_mmu_pt_update_preserve_ad) |
229 (1U << XENFEAT_highmem_assist) |
230 (1U << XENFEAT_gnttab_map_avail_bits);
231 #endif
232 break;
233 default:
234 return -EINVAL;
235 }
237 if ( copy_to_guest(arg, &fi, 1) )
238 return -EFAULT;
239 return 0;
240 }
242 case XENVER_pagesize:
243 {
244 return (!guest_handle_is_null(arg) ? -EINVAL : PAGE_SIZE);
245 }
247 case XENVER_guest_handle:
248 {
249 if ( copy_to_guest(arg, current->domain->handle,
250 ARRAY_SIZE(current->domain->handle)) )
251 return -EFAULT;
252 return 0;
253 }
255 case XENVER_commandline:
256 {
257 if ( copy_to_guest(arg, saved_cmdline, ARRAY_SIZE(saved_cmdline)) )
258 return -EFAULT;
259 return 0;
260 }
261 }
263 return -ENOSYS;
264 }
266 DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE(void) arg)
267 {
268 struct xennmi_callback cb;
269 long rc = 0;
271 switch ( cmd )
272 {
273 case XENNMI_register_callback:
274 rc = -EFAULT;
275 if ( copy_from_guest(&cb, arg, 1) )
276 break;
277 rc = register_guest_nmi_callback(cb.handler_address);
278 break;
279 case XENNMI_unregister_callback:
280 rc = unregister_guest_nmi_callback();
281 break;
282 default:
283 rc = -ENOSYS;
284 break;
285 }
287 return rc;
288 }
290 DO(vm_assist)(unsigned int cmd, unsigned int type)
291 {
292 return vm_assist(current->domain, cmd, type);
293 }
295 DO(ni_hypercall)(void)
296 {
297 /* No-op hypercall. */
298 return -ENOSYS;
299 }
301 /*
302 * Local variables:
303 * mode: C
304 * c-set-style: "BSD"
305 * c-basic-offset: 4
306 * tab-width: 4
307 * indent-tabs-mode: nil
308 * End:
309 */