1cff7e81bSJeremy Fitzhardinge /* 2cff7e81bSJeremy Fitzhardinge * copyright (c) 2006 IBM Corporation 3cff7e81bSJeremy Fitzhardinge * Authored by: Mike D. Day <ncmike@us.ibm.com> 4cff7e81bSJeremy Fitzhardinge * 5cff7e81bSJeremy Fitzhardinge * This program is free software; you can redistribute it and/or modify 6cff7e81bSJeremy Fitzhardinge * it under the terms of the GNU General Public License version 2 as 7cff7e81bSJeremy Fitzhardinge * published by the Free Software Foundation. 8cff7e81bSJeremy Fitzhardinge */ 9cff7e81bSJeremy Fitzhardinge 10*5a0e3ad6STejun Heo #include <linux/slab.h> 11cff7e81bSJeremy Fitzhardinge #include <linux/kernel.h> 12cff7e81bSJeremy Fitzhardinge #include <linux/module.h> 13cff7e81bSJeremy Fitzhardinge #include <linux/kobject.h> 14cff7e81bSJeremy Fitzhardinge 15cff7e81bSJeremy Fitzhardinge #include <asm/xen/hypervisor.h> 16cff7e81bSJeremy Fitzhardinge #include <asm/xen/hypercall.h> 17cff7e81bSJeremy Fitzhardinge 181ccbf534SJeremy Fitzhardinge #include <xen/xen.h> 19cff7e81bSJeremy Fitzhardinge #include <xen/xenbus.h> 20cff7e81bSJeremy Fitzhardinge #include <xen/interface/xen.h> 21cff7e81bSJeremy Fitzhardinge #include <xen/interface/version.h> 22cff7e81bSJeremy Fitzhardinge 23cff7e81bSJeremy Fitzhardinge #define HYPERVISOR_ATTR_RO(_name) \ 24cff7e81bSJeremy Fitzhardinge static struct hyp_sysfs_attr _name##_attr = __ATTR_RO(_name) 25cff7e81bSJeremy Fitzhardinge 26cff7e81bSJeremy Fitzhardinge #define HYPERVISOR_ATTR_RW(_name) \ 27cff7e81bSJeremy Fitzhardinge static struct hyp_sysfs_attr _name##_attr = \ 28cff7e81bSJeremy Fitzhardinge __ATTR(_name, 0644, _name##_show, _name##_store) 29cff7e81bSJeremy Fitzhardinge 30cff7e81bSJeremy Fitzhardinge struct hyp_sysfs_attr { 31cff7e81bSJeremy Fitzhardinge struct attribute attr; 32cff7e81bSJeremy Fitzhardinge ssize_t (*show)(struct hyp_sysfs_attr *, char *); 33cff7e81bSJeremy Fitzhardinge ssize_t (*store)(struct hyp_sysfs_attr *, const char *, size_t); 34cff7e81bSJeremy Fitzhardinge void *hyp_attr_data; 35cff7e81bSJeremy Fitzhardinge }; 36cff7e81bSJeremy Fitzhardinge 37cff7e81bSJeremy Fitzhardinge static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer) 38cff7e81bSJeremy Fitzhardinge { 39cff7e81bSJeremy Fitzhardinge return sprintf(buffer, "xen\n"); 40cff7e81bSJeremy Fitzhardinge } 41cff7e81bSJeremy Fitzhardinge 42cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(type); 43cff7e81bSJeremy Fitzhardinge 44cff7e81bSJeremy Fitzhardinge static int __init xen_sysfs_type_init(void) 45cff7e81bSJeremy Fitzhardinge { 46cff7e81bSJeremy Fitzhardinge return sysfs_create_file(hypervisor_kobj, &type_attr.attr); 47cff7e81bSJeremy Fitzhardinge } 48cff7e81bSJeremy Fitzhardinge 49cff7e81bSJeremy Fitzhardinge static void xen_sysfs_type_destroy(void) 50cff7e81bSJeremy Fitzhardinge { 51cff7e81bSJeremy Fitzhardinge sysfs_remove_file(hypervisor_kobj, &type_attr.attr); 52cff7e81bSJeremy Fitzhardinge } 53cff7e81bSJeremy Fitzhardinge 54cff7e81bSJeremy Fitzhardinge /* xen version attributes */ 55cff7e81bSJeremy Fitzhardinge static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer) 56cff7e81bSJeremy Fitzhardinge { 57cff7e81bSJeremy Fitzhardinge int version = HYPERVISOR_xen_version(XENVER_version, NULL); 58cff7e81bSJeremy Fitzhardinge if (version) 59cff7e81bSJeremy Fitzhardinge return sprintf(buffer, "%d\n", version >> 16); 60cff7e81bSJeremy Fitzhardinge return -ENODEV; 61cff7e81bSJeremy Fitzhardinge } 62cff7e81bSJeremy Fitzhardinge 63cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(major); 64cff7e81bSJeremy Fitzhardinge 65cff7e81bSJeremy Fitzhardinge static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer) 66cff7e81bSJeremy Fitzhardinge { 67cff7e81bSJeremy Fitzhardinge int version = HYPERVISOR_xen_version(XENVER_version, NULL); 68cff7e81bSJeremy Fitzhardinge if (version) 69cff7e81bSJeremy Fitzhardinge return sprintf(buffer, "%d\n", version & 0xff); 70cff7e81bSJeremy Fitzhardinge return -ENODEV; 71cff7e81bSJeremy Fitzhardinge } 72cff7e81bSJeremy Fitzhardinge 73cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(minor); 74cff7e81bSJeremy Fitzhardinge 75cff7e81bSJeremy Fitzhardinge static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer) 76cff7e81bSJeremy Fitzhardinge { 77cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 78cff7e81bSJeremy Fitzhardinge char *extra; 79cff7e81bSJeremy Fitzhardinge 80cff7e81bSJeremy Fitzhardinge extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL); 81cff7e81bSJeremy Fitzhardinge if (extra) { 82cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_extraversion, extra); 83cff7e81bSJeremy Fitzhardinge if (!ret) 84cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", extra); 85cff7e81bSJeremy Fitzhardinge kfree(extra); 86cff7e81bSJeremy Fitzhardinge } 87cff7e81bSJeremy Fitzhardinge 88cff7e81bSJeremy Fitzhardinge return ret; 89cff7e81bSJeremy Fitzhardinge } 90cff7e81bSJeremy Fitzhardinge 91cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(extra); 92cff7e81bSJeremy Fitzhardinge 93cff7e81bSJeremy Fitzhardinge static struct attribute *version_attrs[] = { 94cff7e81bSJeremy Fitzhardinge &major_attr.attr, 95cff7e81bSJeremy Fitzhardinge &minor_attr.attr, 96cff7e81bSJeremy Fitzhardinge &extra_attr.attr, 97cff7e81bSJeremy Fitzhardinge NULL 98cff7e81bSJeremy Fitzhardinge }; 99cff7e81bSJeremy Fitzhardinge 100cff7e81bSJeremy Fitzhardinge static struct attribute_group version_group = { 101cff7e81bSJeremy Fitzhardinge .name = "version", 102cff7e81bSJeremy Fitzhardinge .attrs = version_attrs, 103cff7e81bSJeremy Fitzhardinge }; 104cff7e81bSJeremy Fitzhardinge 105cff7e81bSJeremy Fitzhardinge static int __init xen_sysfs_version_init(void) 106cff7e81bSJeremy Fitzhardinge { 107cff7e81bSJeremy Fitzhardinge return sysfs_create_group(hypervisor_kobj, &version_group); 108cff7e81bSJeremy Fitzhardinge } 109cff7e81bSJeremy Fitzhardinge 110cff7e81bSJeremy Fitzhardinge static void xen_sysfs_version_destroy(void) 111cff7e81bSJeremy Fitzhardinge { 112cff7e81bSJeremy Fitzhardinge sysfs_remove_group(hypervisor_kobj, &version_group); 113cff7e81bSJeremy Fitzhardinge } 114cff7e81bSJeremy Fitzhardinge 115cff7e81bSJeremy Fitzhardinge /* UUID */ 116cff7e81bSJeremy Fitzhardinge 117cff7e81bSJeremy Fitzhardinge static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer) 118cff7e81bSJeremy Fitzhardinge { 119cff7e81bSJeremy Fitzhardinge char *vm, *val; 120cff7e81bSJeremy Fitzhardinge int ret; 121cff7e81bSJeremy Fitzhardinge extern int xenstored_ready; 122cff7e81bSJeremy Fitzhardinge 123cff7e81bSJeremy Fitzhardinge if (!xenstored_ready) 124cff7e81bSJeremy Fitzhardinge return -EBUSY; 125cff7e81bSJeremy Fitzhardinge 126cff7e81bSJeremy Fitzhardinge vm = xenbus_read(XBT_NIL, "vm", "", NULL); 127cff7e81bSJeremy Fitzhardinge if (IS_ERR(vm)) 128cff7e81bSJeremy Fitzhardinge return PTR_ERR(vm); 129cff7e81bSJeremy Fitzhardinge val = xenbus_read(XBT_NIL, vm, "uuid", NULL); 130cff7e81bSJeremy Fitzhardinge kfree(vm); 131cff7e81bSJeremy Fitzhardinge if (IS_ERR(val)) 132cff7e81bSJeremy Fitzhardinge return PTR_ERR(val); 133cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", val); 134cff7e81bSJeremy Fitzhardinge kfree(val); 135cff7e81bSJeremy Fitzhardinge return ret; 136cff7e81bSJeremy Fitzhardinge } 137cff7e81bSJeremy Fitzhardinge 138cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(uuid); 139cff7e81bSJeremy Fitzhardinge 140cff7e81bSJeremy Fitzhardinge static int __init xen_sysfs_uuid_init(void) 141cff7e81bSJeremy Fitzhardinge { 142cff7e81bSJeremy Fitzhardinge return sysfs_create_file(hypervisor_kobj, &uuid_attr.attr); 143cff7e81bSJeremy Fitzhardinge } 144cff7e81bSJeremy Fitzhardinge 145cff7e81bSJeremy Fitzhardinge static void xen_sysfs_uuid_destroy(void) 146cff7e81bSJeremy Fitzhardinge { 147cff7e81bSJeremy Fitzhardinge sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr); 148cff7e81bSJeremy Fitzhardinge } 149cff7e81bSJeremy Fitzhardinge 150cff7e81bSJeremy Fitzhardinge /* xen compilation attributes */ 151cff7e81bSJeremy Fitzhardinge 152cff7e81bSJeremy Fitzhardinge static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer) 153cff7e81bSJeremy Fitzhardinge { 154cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 155cff7e81bSJeremy Fitzhardinge struct xen_compile_info *info; 156cff7e81bSJeremy Fitzhardinge 157cff7e81bSJeremy Fitzhardinge info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 158cff7e81bSJeremy Fitzhardinge if (info) { 159cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_compile_info, info); 160cff7e81bSJeremy Fitzhardinge if (!ret) 161cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", info->compiler); 162cff7e81bSJeremy Fitzhardinge kfree(info); 163cff7e81bSJeremy Fitzhardinge } 164cff7e81bSJeremy Fitzhardinge 165cff7e81bSJeremy Fitzhardinge return ret; 166cff7e81bSJeremy Fitzhardinge } 167cff7e81bSJeremy Fitzhardinge 168cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(compiler); 169cff7e81bSJeremy Fitzhardinge 170cff7e81bSJeremy Fitzhardinge static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer) 171cff7e81bSJeremy Fitzhardinge { 172cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 173cff7e81bSJeremy Fitzhardinge struct xen_compile_info *info; 174cff7e81bSJeremy Fitzhardinge 175cff7e81bSJeremy Fitzhardinge info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 176cff7e81bSJeremy Fitzhardinge if (info) { 177cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_compile_info, info); 178cff7e81bSJeremy Fitzhardinge if (!ret) 179cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", info->compile_by); 180cff7e81bSJeremy Fitzhardinge kfree(info); 181cff7e81bSJeremy Fitzhardinge } 182cff7e81bSJeremy Fitzhardinge 183cff7e81bSJeremy Fitzhardinge return ret; 184cff7e81bSJeremy Fitzhardinge } 185cff7e81bSJeremy Fitzhardinge 186cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(compiled_by); 187cff7e81bSJeremy Fitzhardinge 188cff7e81bSJeremy Fitzhardinge static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer) 189cff7e81bSJeremy Fitzhardinge { 190cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 191cff7e81bSJeremy Fitzhardinge struct xen_compile_info *info; 192cff7e81bSJeremy Fitzhardinge 193cff7e81bSJeremy Fitzhardinge info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); 194cff7e81bSJeremy Fitzhardinge if (info) { 195cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_compile_info, info); 196cff7e81bSJeremy Fitzhardinge if (!ret) 197cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", info->compile_date); 198cff7e81bSJeremy Fitzhardinge kfree(info); 199cff7e81bSJeremy Fitzhardinge } 200cff7e81bSJeremy Fitzhardinge 201cff7e81bSJeremy Fitzhardinge return ret; 202cff7e81bSJeremy Fitzhardinge } 203cff7e81bSJeremy Fitzhardinge 204cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(compile_date); 205cff7e81bSJeremy Fitzhardinge 206cff7e81bSJeremy Fitzhardinge static struct attribute *xen_compile_attrs[] = { 207cff7e81bSJeremy Fitzhardinge &compiler_attr.attr, 208cff7e81bSJeremy Fitzhardinge &compiled_by_attr.attr, 209cff7e81bSJeremy Fitzhardinge &compile_date_attr.attr, 210cff7e81bSJeremy Fitzhardinge NULL 211cff7e81bSJeremy Fitzhardinge }; 212cff7e81bSJeremy Fitzhardinge 213cff7e81bSJeremy Fitzhardinge static struct attribute_group xen_compilation_group = { 214cff7e81bSJeremy Fitzhardinge .name = "compilation", 215cff7e81bSJeremy Fitzhardinge .attrs = xen_compile_attrs, 216cff7e81bSJeremy Fitzhardinge }; 217cff7e81bSJeremy Fitzhardinge 218cff7e81bSJeremy Fitzhardinge int __init static xen_compilation_init(void) 219cff7e81bSJeremy Fitzhardinge { 220cff7e81bSJeremy Fitzhardinge return sysfs_create_group(hypervisor_kobj, &xen_compilation_group); 221cff7e81bSJeremy Fitzhardinge } 222cff7e81bSJeremy Fitzhardinge 223cff7e81bSJeremy Fitzhardinge static void xen_compilation_destroy(void) 224cff7e81bSJeremy Fitzhardinge { 225cff7e81bSJeremy Fitzhardinge sysfs_remove_group(hypervisor_kobj, &xen_compilation_group); 226cff7e81bSJeremy Fitzhardinge } 227cff7e81bSJeremy Fitzhardinge 228cff7e81bSJeremy Fitzhardinge /* xen properties info */ 229cff7e81bSJeremy Fitzhardinge 230cff7e81bSJeremy Fitzhardinge static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer) 231cff7e81bSJeremy Fitzhardinge { 232cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 233cff7e81bSJeremy Fitzhardinge char *caps; 234cff7e81bSJeremy Fitzhardinge 235cff7e81bSJeremy Fitzhardinge caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL); 236cff7e81bSJeremy Fitzhardinge if (caps) { 237cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_capabilities, caps); 238cff7e81bSJeremy Fitzhardinge if (!ret) 239cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", caps); 240cff7e81bSJeremy Fitzhardinge kfree(caps); 241cff7e81bSJeremy Fitzhardinge } 242cff7e81bSJeremy Fitzhardinge 243cff7e81bSJeremy Fitzhardinge return ret; 244cff7e81bSJeremy Fitzhardinge } 245cff7e81bSJeremy Fitzhardinge 246cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(capabilities); 247cff7e81bSJeremy Fitzhardinge 248cff7e81bSJeremy Fitzhardinge static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer) 249cff7e81bSJeremy Fitzhardinge { 250cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 251cff7e81bSJeremy Fitzhardinge char *cset; 252cff7e81bSJeremy Fitzhardinge 253cff7e81bSJeremy Fitzhardinge cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL); 254cff7e81bSJeremy Fitzhardinge if (cset) { 255cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_changeset, cset); 256cff7e81bSJeremy Fitzhardinge if (!ret) 257cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%s\n", cset); 258cff7e81bSJeremy Fitzhardinge kfree(cset); 259cff7e81bSJeremy Fitzhardinge } 260cff7e81bSJeremy Fitzhardinge 261cff7e81bSJeremy Fitzhardinge return ret; 262cff7e81bSJeremy Fitzhardinge } 263cff7e81bSJeremy Fitzhardinge 264cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(changeset); 265cff7e81bSJeremy Fitzhardinge 266cff7e81bSJeremy Fitzhardinge static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer) 267cff7e81bSJeremy Fitzhardinge { 268cff7e81bSJeremy Fitzhardinge int ret = -ENOMEM; 269cff7e81bSJeremy Fitzhardinge struct xen_platform_parameters *parms; 270cff7e81bSJeremy Fitzhardinge 271cff7e81bSJeremy Fitzhardinge parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL); 272cff7e81bSJeremy Fitzhardinge if (parms) { 273cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_platform_parameters, 274cff7e81bSJeremy Fitzhardinge parms); 275cff7e81bSJeremy Fitzhardinge if (!ret) 276cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%lx\n", parms->virt_start); 277cff7e81bSJeremy Fitzhardinge kfree(parms); 278cff7e81bSJeremy Fitzhardinge } 279cff7e81bSJeremy Fitzhardinge 280cff7e81bSJeremy Fitzhardinge return ret; 281cff7e81bSJeremy Fitzhardinge } 282cff7e81bSJeremy Fitzhardinge 283cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(virtual_start); 284cff7e81bSJeremy Fitzhardinge 285cff7e81bSJeremy Fitzhardinge static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer) 286cff7e81bSJeremy Fitzhardinge { 287cff7e81bSJeremy Fitzhardinge int ret; 288cff7e81bSJeremy Fitzhardinge 289cff7e81bSJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL); 290cff7e81bSJeremy Fitzhardinge if (ret > 0) 291cff7e81bSJeremy Fitzhardinge ret = sprintf(buffer, "%x\n", ret); 292cff7e81bSJeremy Fitzhardinge 293cff7e81bSJeremy Fitzhardinge return ret; 294cff7e81bSJeremy Fitzhardinge } 295cff7e81bSJeremy Fitzhardinge 296cff7e81bSJeremy Fitzhardinge HYPERVISOR_ATTR_RO(pagesize); 297cff7e81bSJeremy Fitzhardinge 298cff7e81bSJeremy Fitzhardinge static ssize_t xen_feature_show(int index, char *buffer) 299cff7e81bSJeremy Fitzhardinge { 300a649b720SJeremy Fitzhardinge ssize_t ret; 301a649b720SJeremy Fitzhardinge struct xen_feature_info info; 302cff7e81bSJeremy Fitzhardinge 303a649b720SJeremy Fitzhardinge info.submap_idx = index; 304a649b720SJeremy Fitzhardinge ret = HYPERVISOR_xen_version(XENVER_get_features, &info); 305cff7e81bSJeremy Fitzhardinge if (!ret) 306a649b720SJeremy Fitzhardinge ret = sprintf(buffer, "%08x", info.submap); 307cff7e81bSJeremy Fitzhardinge 308cff7e81bSJeremy Fitzhardinge return ret; 309cff7e81bSJeremy Fitzhardinge } 310cff7e81bSJeremy Fitzhardinge 311a649b720SJeremy Fitzhardinge static ssize_t features_show(struct hyp_sysfs_attr *attr, char *buffer) 312cff7e81bSJeremy Fitzhardinge { 313a649b720SJeremy Fitzhardinge ssize_t len; 314a649b720SJeremy Fitzhardinge int i; 315a649b720SJeremy Fitzhardinge 316a649b720SJeremy Fitzhardinge len = 0; 317a649b720SJeremy Fitzhardinge for (i = XENFEAT_NR_SUBMAPS-1; i >= 0; i--) { 318a649b720SJeremy Fitzhardinge int ret = xen_feature_show(i, buffer + len); 319a649b720SJeremy Fitzhardinge if (ret < 0) { 320a649b720SJeremy Fitzhardinge if (len == 0) 321a649b720SJeremy Fitzhardinge len = ret; 322a649b720SJeremy Fitzhardinge break; 323a649b720SJeremy Fitzhardinge } 324a649b720SJeremy Fitzhardinge len += ret; 325a649b720SJeremy Fitzhardinge } 326a649b720SJeremy Fitzhardinge if (len > 0) 327a649b720SJeremy Fitzhardinge buffer[len++] = '\n'; 328a649b720SJeremy Fitzhardinge 329a649b720SJeremy Fitzhardinge return len; 330cff7e81bSJeremy Fitzhardinge } 331cff7e81bSJeremy Fitzhardinge 332a649b720SJeremy Fitzhardinge HYPERVISOR_ATTR_RO(features); 333cff7e81bSJeremy Fitzhardinge 334cff7e81bSJeremy Fitzhardinge static struct attribute *xen_properties_attrs[] = { 335cff7e81bSJeremy Fitzhardinge &capabilities_attr.attr, 336cff7e81bSJeremy Fitzhardinge &changeset_attr.attr, 337cff7e81bSJeremy Fitzhardinge &virtual_start_attr.attr, 338cff7e81bSJeremy Fitzhardinge &pagesize_attr.attr, 339a649b720SJeremy Fitzhardinge &features_attr.attr, 340cff7e81bSJeremy Fitzhardinge NULL 341cff7e81bSJeremy Fitzhardinge }; 342cff7e81bSJeremy Fitzhardinge 343cff7e81bSJeremy Fitzhardinge static struct attribute_group xen_properties_group = { 344cff7e81bSJeremy Fitzhardinge .name = "properties", 345cff7e81bSJeremy Fitzhardinge .attrs = xen_properties_attrs, 346cff7e81bSJeremy Fitzhardinge }; 347cff7e81bSJeremy Fitzhardinge 348cff7e81bSJeremy Fitzhardinge static int __init xen_properties_init(void) 349cff7e81bSJeremy Fitzhardinge { 350cff7e81bSJeremy Fitzhardinge return sysfs_create_group(hypervisor_kobj, &xen_properties_group); 351cff7e81bSJeremy Fitzhardinge } 352cff7e81bSJeremy Fitzhardinge 353cff7e81bSJeremy Fitzhardinge static void xen_properties_destroy(void) 354cff7e81bSJeremy Fitzhardinge { 355cff7e81bSJeremy Fitzhardinge sysfs_remove_group(hypervisor_kobj, &xen_properties_group); 356cff7e81bSJeremy Fitzhardinge } 357cff7e81bSJeremy Fitzhardinge 358cff7e81bSJeremy Fitzhardinge static int __init hyper_sysfs_init(void) 359cff7e81bSJeremy Fitzhardinge { 360cff7e81bSJeremy Fitzhardinge int ret; 361cff7e81bSJeremy Fitzhardinge 362cff7e81bSJeremy Fitzhardinge if (!xen_domain()) 363cff7e81bSJeremy Fitzhardinge return -ENODEV; 364cff7e81bSJeremy Fitzhardinge 365cff7e81bSJeremy Fitzhardinge ret = xen_sysfs_type_init(); 366cff7e81bSJeremy Fitzhardinge if (ret) 367cff7e81bSJeremy Fitzhardinge goto out; 368cff7e81bSJeremy Fitzhardinge ret = xen_sysfs_version_init(); 369cff7e81bSJeremy Fitzhardinge if (ret) 370cff7e81bSJeremy Fitzhardinge goto version_out; 371cff7e81bSJeremy Fitzhardinge ret = xen_compilation_init(); 372cff7e81bSJeremy Fitzhardinge if (ret) 373cff7e81bSJeremy Fitzhardinge goto comp_out; 374cff7e81bSJeremy Fitzhardinge ret = xen_sysfs_uuid_init(); 375cff7e81bSJeremy Fitzhardinge if (ret) 376cff7e81bSJeremy Fitzhardinge goto uuid_out; 377cff7e81bSJeremy Fitzhardinge ret = xen_properties_init(); 378cff7e81bSJeremy Fitzhardinge if (ret) 379cff7e81bSJeremy Fitzhardinge goto prop_out; 380cff7e81bSJeremy Fitzhardinge 381cff7e81bSJeremy Fitzhardinge goto out; 382cff7e81bSJeremy Fitzhardinge 383cff7e81bSJeremy Fitzhardinge prop_out: 384cff7e81bSJeremy Fitzhardinge xen_sysfs_uuid_destroy(); 385cff7e81bSJeremy Fitzhardinge uuid_out: 386cff7e81bSJeremy Fitzhardinge xen_compilation_destroy(); 387cff7e81bSJeremy Fitzhardinge comp_out: 388cff7e81bSJeremy Fitzhardinge xen_sysfs_version_destroy(); 389cff7e81bSJeremy Fitzhardinge version_out: 390cff7e81bSJeremy Fitzhardinge xen_sysfs_type_destroy(); 391cff7e81bSJeremy Fitzhardinge out: 392cff7e81bSJeremy Fitzhardinge return ret; 393cff7e81bSJeremy Fitzhardinge } 394cff7e81bSJeremy Fitzhardinge 395cff7e81bSJeremy Fitzhardinge static void __exit hyper_sysfs_exit(void) 396cff7e81bSJeremy Fitzhardinge { 397cff7e81bSJeremy Fitzhardinge xen_properties_destroy(); 398cff7e81bSJeremy Fitzhardinge xen_compilation_destroy(); 399cff7e81bSJeremy Fitzhardinge xen_sysfs_uuid_destroy(); 400cff7e81bSJeremy Fitzhardinge xen_sysfs_version_destroy(); 401cff7e81bSJeremy Fitzhardinge xen_sysfs_type_destroy(); 402cff7e81bSJeremy Fitzhardinge 403cff7e81bSJeremy Fitzhardinge } 404cff7e81bSJeremy Fitzhardinge module_init(hyper_sysfs_init); 405cff7e81bSJeremy Fitzhardinge module_exit(hyper_sysfs_exit); 406cff7e81bSJeremy Fitzhardinge 407cff7e81bSJeremy Fitzhardinge static ssize_t hyp_sysfs_show(struct kobject *kobj, 408cff7e81bSJeremy Fitzhardinge struct attribute *attr, 409cff7e81bSJeremy Fitzhardinge char *buffer) 410cff7e81bSJeremy Fitzhardinge { 411cff7e81bSJeremy Fitzhardinge struct hyp_sysfs_attr *hyp_attr; 412cff7e81bSJeremy Fitzhardinge hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr); 413cff7e81bSJeremy Fitzhardinge if (hyp_attr->show) 414cff7e81bSJeremy Fitzhardinge return hyp_attr->show(hyp_attr, buffer); 415cff7e81bSJeremy Fitzhardinge return 0; 416cff7e81bSJeremy Fitzhardinge } 417cff7e81bSJeremy Fitzhardinge 418cff7e81bSJeremy Fitzhardinge static ssize_t hyp_sysfs_store(struct kobject *kobj, 419cff7e81bSJeremy Fitzhardinge struct attribute *attr, 420cff7e81bSJeremy Fitzhardinge const char *buffer, 421cff7e81bSJeremy Fitzhardinge size_t len) 422cff7e81bSJeremy Fitzhardinge { 423cff7e81bSJeremy Fitzhardinge struct hyp_sysfs_attr *hyp_attr; 424cff7e81bSJeremy Fitzhardinge hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr); 425cff7e81bSJeremy Fitzhardinge if (hyp_attr->store) 426cff7e81bSJeremy Fitzhardinge return hyp_attr->store(hyp_attr, buffer, len); 427cff7e81bSJeremy Fitzhardinge return 0; 428cff7e81bSJeremy Fitzhardinge } 429cff7e81bSJeremy Fitzhardinge 43052cf25d0SEmese Revfy static const struct sysfs_ops hyp_sysfs_ops = { 431cff7e81bSJeremy Fitzhardinge .show = hyp_sysfs_show, 432cff7e81bSJeremy Fitzhardinge .store = hyp_sysfs_store, 433cff7e81bSJeremy Fitzhardinge }; 434cff7e81bSJeremy Fitzhardinge 435cff7e81bSJeremy Fitzhardinge static struct kobj_type hyp_sysfs_kobj_type = { 436cff7e81bSJeremy Fitzhardinge .sysfs_ops = &hyp_sysfs_ops, 437cff7e81bSJeremy Fitzhardinge }; 438cff7e81bSJeremy Fitzhardinge 439cff7e81bSJeremy Fitzhardinge static int __init hypervisor_subsys_init(void) 440cff7e81bSJeremy Fitzhardinge { 441cff7e81bSJeremy Fitzhardinge if (!xen_domain()) 442cff7e81bSJeremy Fitzhardinge return -ENODEV; 443cff7e81bSJeremy Fitzhardinge 444cff7e81bSJeremy Fitzhardinge hypervisor_kobj->ktype = &hyp_sysfs_kobj_type; 445cff7e81bSJeremy Fitzhardinge return 0; 446cff7e81bSJeremy Fitzhardinge } 447cff7e81bSJeremy Fitzhardinge device_initcall(hypervisor_subsys_init); 448