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