ia64/xen-unstable

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