ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c @ 14100:e47738923a05

[LINUX] Purge include <linux/config.h>. It has been obsolete for some time now.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Fri Feb 23 16:56:45 2007 +0000 (2007-02-23)
parents bd4080876297
children
line source
1 /*
2 * copyright (c) 2006 IBM Corporation
3 * Authored by: Mike D. Day <ncmike@us.ibm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
10 #include <linux/err.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <asm/hypervisor.h>
15 #include <xen/features.h>
16 #include <xen/hypervisor_sysfs.h>
17 #include <xen/xenbus.h>
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Mike D. Day <ncmike@us.ibm.com>");
22 static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
23 {
24 return sprintf(buffer, "xen\n");
25 }
27 HYPERVISOR_ATTR_RO(type);
29 static int __init xen_sysfs_type_init(void)
30 {
31 return sysfs_create_file(&hypervisor_subsys.kset.kobj, &type_attr.attr);
32 }
34 static void xen_sysfs_type_destroy(void)
35 {
36 sysfs_remove_file(&hypervisor_subsys.kset.kobj, &type_attr.attr);
37 }
39 /* xen version attributes */
40 static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer)
41 {
42 int version = HYPERVISOR_xen_version(XENVER_version, NULL);
43 if (version)
44 return sprintf(buffer, "%d\n", version >> 16);
45 return -ENODEV;
46 }
48 HYPERVISOR_ATTR_RO(major);
50 static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer)
51 {
52 int version = HYPERVISOR_xen_version(XENVER_version, NULL);
53 if (version)
54 return sprintf(buffer, "%d\n", version & 0xff);
55 return -ENODEV;
56 }
58 HYPERVISOR_ATTR_RO(minor);
60 static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer)
61 {
62 int ret = -ENOMEM;
63 char *extra;
65 extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL);
66 if (extra) {
67 ret = HYPERVISOR_xen_version(XENVER_extraversion, extra);
68 if (!ret)
69 ret = sprintf(buffer, "%s\n", extra);
70 kfree(extra);
71 }
73 return ret;
74 }
76 HYPERVISOR_ATTR_RO(extra);
78 static struct attribute *version_attrs[] = {
79 &major_attr.attr,
80 &minor_attr.attr,
81 &extra_attr.attr,
82 NULL
83 };
85 static struct attribute_group version_group = {
86 .name = "version",
87 .attrs = version_attrs,
88 };
90 static int __init xen_sysfs_version_init(void)
91 {
92 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
93 &version_group);
94 }
96 static void xen_sysfs_version_destroy(void)
97 {
98 sysfs_remove_group(&hypervisor_subsys.kset.kobj, &version_group);
99 }
101 /* UUID */
103 static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer)
104 {
105 char *vm, *val;
106 int ret;
108 vm = xenbus_read(XBT_NIL, "vm", "", NULL);
109 if (IS_ERR(vm))
110 return PTR_ERR(vm);
111 val = xenbus_read(XBT_NIL, vm, "uuid", NULL);
112 kfree(vm);
113 if (IS_ERR(val))
114 return PTR_ERR(val);
115 ret = sprintf(buffer, "%s\n", val);
116 kfree(val);
117 return ret;
118 }
120 HYPERVISOR_ATTR_RO(uuid);
122 static int __init xen_sysfs_uuid_init(void)
123 {
124 return sysfs_create_file(&hypervisor_subsys.kset.kobj, &uuid_attr.attr);
125 }
127 static void xen_sysfs_uuid_destroy(void)
128 {
129 sysfs_remove_file(&hypervisor_subsys.kset.kobj, &uuid_attr.attr);
130 }
132 /* xen compilation attributes */
134 static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer)
135 {
136 int ret = -ENOMEM;
137 struct xen_compile_info *info;
139 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
140 if (info) {
141 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
142 if (!ret)
143 ret = sprintf(buffer, "%s\n", info->compiler);
144 kfree(info);
145 }
147 return ret;
148 }
150 HYPERVISOR_ATTR_RO(compiler);
152 static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer)
153 {
154 int ret = -ENOMEM;
155 struct xen_compile_info *info;
157 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
158 if (info) {
159 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
160 if (!ret)
161 ret = sprintf(buffer, "%s\n", info->compile_by);
162 kfree(info);
163 }
165 return ret;
166 }
168 HYPERVISOR_ATTR_RO(compiled_by);
170 static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer)
171 {
172 int ret = -ENOMEM;
173 struct xen_compile_info *info;
175 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
176 if (info) {
177 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
178 if (!ret)
179 ret = sprintf(buffer, "%s\n", info->compile_date);
180 kfree(info);
181 }
183 return ret;
184 }
186 HYPERVISOR_ATTR_RO(compile_date);
188 static struct attribute *xen_compile_attrs[] = {
189 &compiler_attr.attr,
190 &compiled_by_attr.attr,
191 &compile_date_attr.attr,
192 NULL
193 };
195 static struct attribute_group xen_compilation_group = {
196 .name = "compilation",
197 .attrs = xen_compile_attrs,
198 };
200 int __init static xen_compilation_init(void)
201 {
202 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
203 &xen_compilation_group);
204 }
206 static void xen_compilation_destroy(void)
207 {
208 sysfs_remove_group(&hypervisor_subsys.kset.kobj,
209 &xen_compilation_group);
210 }
212 /* xen properties info */
214 static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer)
215 {
216 int ret = -ENOMEM;
217 char *caps;
219 caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL);
220 if (caps) {
221 ret = HYPERVISOR_xen_version(XENVER_capabilities, caps);
222 if (!ret)
223 ret = sprintf(buffer, "%s\n", caps);
224 kfree(caps);
225 }
227 return ret;
228 }
230 HYPERVISOR_ATTR_RO(capabilities);
232 static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer)
233 {
234 int ret = -ENOMEM;
235 char *cset;
237 cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL);
238 if (cset) {
239 ret = HYPERVISOR_xen_version(XENVER_changeset, cset);
240 if (!ret)
241 ret = sprintf(buffer, "%s\n", cset);
242 kfree(cset);
243 }
245 return ret;
246 }
248 HYPERVISOR_ATTR_RO(changeset);
250 static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer)
251 {
252 int ret = -ENOMEM;
253 struct xen_platform_parameters *parms;
255 parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL);
256 if (parms) {
257 ret = HYPERVISOR_xen_version(XENVER_platform_parameters,
258 parms);
259 if (!ret)
260 ret = sprintf(buffer, "%lx\n", parms->virt_start);
261 kfree(parms);
262 }
264 return ret;
265 }
267 HYPERVISOR_ATTR_RO(virtual_start);
269 static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer)
270 {
271 int ret;
273 ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL);
274 if (ret > 0)
275 ret = sprintf(buffer, "%x\n", ret);
277 return ret;
278 }
280 HYPERVISOR_ATTR_RO(pagesize);
282 /* eventually there will be several more features to export */
283 static ssize_t xen_feature_show(int index, char *buffer)
284 {
285 int ret = -ENOMEM;
286 struct xen_feature_info *info;
288 info = kmalloc(sizeof(struct xen_feature_info), GFP_KERNEL);
289 if (info) {
290 info->submap_idx = index;
291 ret = HYPERVISOR_xen_version(XENVER_get_features, info);
292 if (!ret)
293 ret = sprintf(buffer, "%d\n", info->submap);
294 kfree(info);
295 }
297 return ret;
298 }
300 static ssize_t writable_pt_show(struct hyp_sysfs_attr *attr, char *buffer)
301 {
302 return xen_feature_show(XENFEAT_writable_page_tables, buffer);
303 }
305 HYPERVISOR_ATTR_RO(writable_pt);
307 static struct attribute *xen_properties_attrs[] = {
308 &capabilities_attr.attr,
309 &changeset_attr.attr,
310 &virtual_start_attr.attr,
311 &pagesize_attr.attr,
312 &writable_pt_attr.attr,
313 NULL
314 };
316 static struct attribute_group xen_properties_group = {
317 .name = "properties",
318 .attrs = xen_properties_attrs,
319 };
321 static int __init xen_properties_init(void)
322 {
323 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
324 &xen_properties_group);
325 }
327 static void xen_properties_destroy(void)
328 {
329 sysfs_remove_group(&hypervisor_subsys.kset.kobj,
330 &xen_properties_group);
331 }
333 static int __init hyper_sysfs_init(void)
334 {
335 int ret;
337 if (!is_running_on_xen())
338 return -ENODEV;
340 ret = xen_sysfs_type_init();
341 if (ret)
342 goto out;
343 ret = xen_sysfs_version_init();
344 if (ret)
345 goto version_out;
346 ret = xen_compilation_init();
347 if (ret)
348 goto comp_out;
349 ret = xen_sysfs_uuid_init();
350 if (ret)
351 goto uuid_out;
352 ret = xen_properties_init();
353 if (!ret)
354 goto out;
356 xen_sysfs_uuid_destroy();
357 uuid_out:
358 xen_compilation_destroy();
359 comp_out:
360 xen_sysfs_version_destroy();
361 version_out:
362 xen_sysfs_type_destroy();
363 out:
364 return ret;
365 }
367 static void hyper_sysfs_exit(void)
368 {
369 xen_properties_destroy();
370 xen_compilation_destroy();
371 xen_sysfs_uuid_destroy();
372 xen_sysfs_version_destroy();
373 xen_sysfs_type_destroy();
375 }
377 module_init(hyper_sysfs_init);
378 module_exit(hyper_sysfs_exit);