ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c @ 9378:4dec7a81f8f5

Fix a build problem when enabling XEN_SYSFS on xen/ia64.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Mar 21 22:48:04 2006 +0100 (2006-03-21)
parents 349d26c1094f
children b736d3335641
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/config.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>
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Mike D. Day <ncmike@us.ibm.com>");
21 static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
22 {
23 return sprintf(buffer, "xen\n");
24 }
26 HYPERVISOR_ATTR_RO(type);
28 static int __init xen_sysfs_type_init(void)
29 {
30 return sysfs_create_file(&hypervisor_subsys.kset.kobj, &type_attr.attr);
31 }
33 static void xen_sysfs_type_destroy(void)
34 {
35 sysfs_remove_file(&hypervisor_subsys.kset.kobj, &type_attr.attr);
36 }
38 /* xen version attributes */
39 static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer)
40 {
41 int version = HYPERVISOR_xen_version(XENVER_version, NULL);
42 if (version)
43 return sprintf(buffer, "%d\n", version >> 16);
44 return -ENODEV;
45 }
47 HYPERVISOR_ATTR_RO(major);
49 static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer)
50 {
51 int version = HYPERVISOR_xen_version(XENVER_version, NULL);
52 if (version)
53 return sprintf(buffer, "%d\n", version & 0xff);
54 return -ENODEV;
55 }
57 HYPERVISOR_ATTR_RO(minor);
59 static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer)
60 {
61 int ret;
62 char *extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL);
63 if (extra) {
64 ret = HYPERVISOR_xen_version(XENVER_extraversion, extra);
65 if (!ret)
66 return sprintf(buffer, "%s\n", extra);
67 kfree(extra);
68 } else
69 ret = -ENOMEM;
70 return ret;
71 }
73 HYPERVISOR_ATTR_RO(extra);
75 static struct attribute *version_attrs[] = {
76 &major_attr.attr,
77 &minor_attr.attr,
78 &extra_attr.attr,
79 NULL
80 };
82 static struct attribute_group version_group = {
83 .name = "version",
84 .attrs = version_attrs,
85 };
87 static int __init xen_sysfs_version_init(void)
88 {
89 return sysfs_create_group(&hypervisor_subsys.kset.kobj, &version_group);
90 }
92 static void xen_sysfs_version_destroy(void)
93 {
94 sysfs_remove_group(&hypervisor_subsys.kset.kobj, &version_group);
95 }
97 /* xen compilation attributes */
99 static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer)
100 {
101 int ret;
102 struct xen_compile_info *info =
103 kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
104 if (info) {
105 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
106 if (!ret)
107 ret = sprintf(buffer, "%s\n", info->compiler);
108 kfree(info);
109 } else
110 ret = -ENOMEM;
112 return ret;
113 }
115 HYPERVISOR_ATTR_RO(compiler);
117 static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer)
118 {
119 int ret;
120 struct xen_compile_info *info;
122 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
123 if (info) {
124 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
125 if (!ret)
126 ret = sprintf(buffer, "%s\n", info->compile_by);
127 kfree(info);
128 } else
129 ret = -ENOMEM;
130 return ret;
131 }
133 HYPERVISOR_ATTR_RO(compiled_by);
135 static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer)
136 {
137 int ret;
138 struct xen_compile_info *info;
140 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
141 if (info) {
142 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
143 if (!ret)
144 ret = sprintf(buffer, "%s\n", info->compile_date);
145 kfree(info);
146 } else
147 ret = -ENOMEM;
148 return ret;
149 }
151 HYPERVISOR_ATTR_RO(compile_date);
153 static struct attribute *xen_compile_attrs[] = {
154 &compiler_attr.attr,
155 &compiled_by_attr.attr,
156 &compile_date_attr.attr,
157 NULL
158 };
160 static struct attribute_group xen_compilation_group = {
161 .name = "compilation",
162 .attrs = xen_compile_attrs,
163 };
165 int __init static xen_compilation_init(void)
166 {
167 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
168 &xen_compilation_group);
169 }
171 static void xen_compilation_destroy(void)
172 {
173 sysfs_remove_group(&hypervisor_subsys.kset.kobj,
174 &xen_compilation_group);
175 }
177 /* xen properties info */
179 static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer)
180 {
181 int ret;
182 char *caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL);
183 if (caps) {
184 ret = HYPERVISOR_xen_version(XENVER_capabilities, caps);
185 if (!ret)
186 ret = sprintf(buffer, "%s\n", caps);
187 kfree(caps);
188 } else
189 ret = -ENOMEM;
190 return ret;
191 }
193 HYPERVISOR_ATTR_RO(capabilities);
195 static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer)
196 {
197 int ret;
198 char *cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL);
199 if (cset) {
200 ret = HYPERVISOR_xen_version(XENVER_changeset, cset);
201 if (!ret)
202 ret = sprintf(buffer, "%s\n", cset);
203 kfree(cset);
204 } else
205 ret = -ENOMEM;
206 return ret;
207 }
209 HYPERVISOR_ATTR_RO(changeset);
211 static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer)
212 {
213 int ret;
214 struct xen_platform_parameters *parms =
215 kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL);
216 if (parms) {
217 ret = HYPERVISOR_xen_version(XENVER_platform_parameters, parms);
218 if (!ret)
219 ret = sprintf(buffer, "%lx\n", parms->virt_start);
220 kfree(parms);
221 } else
222 ret = -ENOMEM;
223 return ret;
224 }
226 HYPERVISOR_ATTR_RO(virtual_start);
228 /* eventually there will be several more features to export */
229 static ssize_t xen_feature_show(int index, char *buffer)
230 {
231 int ret;
233 struct xen_feature_info *info =
234 kmalloc(sizeof(struct xen_feature_info), GFP_KERNEL);
235 if (info) {
236 info->submap_idx = index;
237 ret = HYPERVISOR_xen_version(XENVER_get_features, info);
238 if (!ret)
239 ret = sprintf(buffer, "%d\n", info->submap);
240 kfree(info);
241 } else
242 ret = -ENOMEM;
243 return ret;
244 }
246 static ssize_t writable_pt_show(struct hyp_sysfs_attr *attr, char *buffer)
247 {
248 return xen_feature_show(XENFEAT_writable_page_tables, buffer);
249 }
251 HYPERVISOR_ATTR_RO(writable_pt);
253 static struct attribute *xen_properties_attrs[] = {
254 &capabilities_attr.attr,
255 &changeset_attr.attr,
256 &virtual_start_attr.attr,
257 &writable_pt_attr.attr,
258 NULL
259 };
261 static struct attribute_group xen_properties_group = {
262 .name = "properties",
263 .attrs = xen_properties_attrs,
264 };
266 static int __init xen_properties_init(void)
267 {
268 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
269 &xen_properties_group);
270 }
272 static void xen_properties_destroy(void)
273 {
274 sysfs_remove_group(&hypervisor_subsys.kset.kobj, &xen_properties_group);
275 }
277 static int __init hyper_sysfs_init(void)
278 {
279 int ret = xen_sysfs_type_init();
280 if (ret)
281 goto out;
282 ret = xen_sysfs_version_init();
283 if (ret)
284 goto version_out;
285 ret = xen_compilation_init();
286 if (ret)
287 goto comp_out;
288 ret = xen_properties_init();
289 if (!ret)
290 goto out;
292 xen_compilation_destroy();
293 comp_out:
294 xen_sysfs_version_destroy();
295 version_out:
296 xen_sysfs_type_destroy();
297 out:
298 return ret;
299 }
301 static void hyper_sysfs_exit(void)
302 {
303 xen_properties_destroy();
304 xen_compilation_destroy();
305 xen_sysfs_version_destroy();
306 xen_sysfs_type_destroy();
308 }
310 module_init(hyper_sysfs_init);
311 module_exit(hyper_sysfs_exit);