Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  copyright (c) 2006 IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Authored by: Mike D. Day <ncmike@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/xen/hypervisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/xen/hypercall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <xen/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <xen/xenbus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <xen/interface/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <xen/interface/version.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #ifdef CONFIG_XEN_HAVE_VPMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <xen/interface/xenpmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define HYPERVISOR_ATTR_RO(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct hyp_sysfs_attr  _name##_attr = __ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define HYPERVISOR_ATTR_RW(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct hyp_sysfs_attr _name##_attr = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	__ATTR(_name, 0644, _name##_show, _name##_store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct hyp_sysfs_attr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	ssize_t (*show)(struct hyp_sysfs_attr *, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	ssize_t (*store)(struct hyp_sysfs_attr *, const char *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	void *hyp_attr_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	return sprintf(buffer, "xen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) HYPERVISOR_ATTR_RO(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int __init xen_sysfs_type_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static ssize_t guest_type_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	const char *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	switch (xen_domain_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case XEN_NATIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		/* ARM only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		type = "Xen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	case XEN_PV_DOMAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		type = "PV";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	case XEN_HVM_DOMAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		type = xen_pvh_domain() ? "PVH" : "HVM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return sprintf(buffer, "%s\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) HYPERVISOR_ATTR_RO(guest_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int __init xen_sysfs_guest_type_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return sysfs_create_file(hypervisor_kobj, &guest_type_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /* xen version attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	int version = HYPERVISOR_xen_version(XENVER_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return sprintf(buffer, "%d\n", version >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) HYPERVISOR_ATTR_RO(major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int version = HYPERVISOR_xen_version(XENVER_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return sprintf(buffer, "%d\n", version & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) HYPERVISOR_ATTR_RO(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	char *extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		ret = HYPERVISOR_xen_version(XENVER_extraversion, extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			ret = sprintf(buffer, "%s\n", extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		kfree(extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) HYPERVISOR_ATTR_RO(extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static struct attribute *version_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	&major_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	&minor_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	&extra_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static const struct attribute_group version_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.name = "version",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.attrs = version_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int __init xen_sysfs_version_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return sysfs_create_group(hypervisor_kobj, &version_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* UUID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static ssize_t uuid_show_fallback(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	char *vm, *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	extern int xenstored_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!xenstored_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	vm = xenbus_read(XBT_NIL, "vm", "", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (IS_ERR(vm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return PTR_ERR(vm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	val = xenbus_read(XBT_NIL, vm, "uuid", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	kfree(vm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (IS_ERR(val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return PTR_ERR(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	ret = sprintf(buffer, "%s\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kfree(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	xen_domain_handle_t uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	ret = HYPERVISOR_xen_version(XENVER_guest_handle, uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		return uuid_show_fallback(attr, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	ret = sprintf(buffer, "%pU\n", uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) HYPERVISOR_ATTR_RO(uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int __init xen_sysfs_uuid_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return sysfs_create_file(hypervisor_kobj, &uuid_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* xen compilation attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct xen_compile_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			ret = sprintf(buffer, "%s\n", info->compiler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) HYPERVISOR_ATTR_RO(compiler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct xen_compile_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			ret = sprintf(buffer, "%s\n", info->compile_by);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) HYPERVISOR_ATTR_RO(compiled_by);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct xen_compile_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			ret = sprintf(buffer, "%s\n", info->compile_date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) HYPERVISOR_ATTR_RO(compile_date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static struct attribute *xen_compile_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	&compiler_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	&compiled_by_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	&compile_date_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static const struct attribute_group xen_compilation_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.name = "compilation",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.attrs = xen_compile_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int __init xen_sysfs_compilation_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return sysfs_create_group(hypervisor_kobj, &xen_compilation_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* xen properties info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	char *caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (caps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		ret = HYPERVISOR_xen_version(XENVER_capabilities, caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			ret = sprintf(buffer, "%s\n", caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		kfree(caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) HYPERVISOR_ATTR_RO(capabilities);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	char *cset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (cset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		ret = HYPERVISOR_xen_version(XENVER_changeset, cset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			ret = sprintf(buffer, "%s\n", cset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		kfree(cset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) HYPERVISOR_ATTR_RO(changeset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct xen_platform_parameters *parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (parms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		ret = HYPERVISOR_xen_version(XENVER_platform_parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 					     parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			ret = sprintf(buffer, "%"PRI_xen_ulong"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				      parms->virt_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		kfree(parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) HYPERVISOR_ATTR_RO(virtual_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		ret = sprintf(buffer, "%x\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) HYPERVISOR_ATTR_RO(pagesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static ssize_t xen_feature_show(int index, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct xen_feature_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	info.submap_idx = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	ret = HYPERVISOR_xen_version(XENVER_get_features, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		ret = sprintf(buffer, "%08x", info.submap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static ssize_t features_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	ssize_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	for (i = XENFEAT_NR_SUBMAPS-1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		int ret = xen_feature_show(i, buffer + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				len = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		buffer[len++] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) HYPERVISOR_ATTR_RO(features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static ssize_t buildid_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct xen_build_id *buildid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	ret = HYPERVISOR_xen_version(XENVER_build_id, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		if (ret == -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			ret = sprintf(buffer, "<denied>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	buildid = kmalloc(sizeof(*buildid) + ret, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (!buildid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	buildid->len = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	ret = HYPERVISOR_xen_version(XENVER_build_id, buildid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		ret = sprintf(buffer, "%s", buildid->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	kfree(buildid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) HYPERVISOR_ATTR_RO(buildid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static struct attribute *xen_properties_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	&capabilities_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	&changeset_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	&virtual_start_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	&pagesize_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	&features_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	&buildid_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static const struct attribute_group xen_properties_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	.name = "properties",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	.attrs = xen_properties_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int __init xen_sysfs_properties_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return sysfs_create_group(hypervisor_kobj, &xen_properties_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) #ifdef CONFIG_XEN_HAVE_VPMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct pmu_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	uint32_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static struct pmu_mode pmu_modes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	{"off", XENPMU_MODE_OFF},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	{"self", XENPMU_MODE_SELF},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	{"hv", XENPMU_MODE_HV},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	{"all", XENPMU_MODE_ALL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static ssize_t pmu_mode_store(struct hyp_sysfs_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			      const char *buffer, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	struct xen_pmu_params xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	for (i = 0; i < ARRAY_SIZE(pmu_modes); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (strncmp(buffer, pmu_modes[i].name, len - 1) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			xp.val = pmu_modes[i].mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (i == ARRAY_SIZE(pmu_modes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	xp.version.maj = XENPMU_VER_MAJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	xp.version.min = XENPMU_VER_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	ret = HYPERVISOR_xenpmu_op(XENPMU_mode_set, &xp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static ssize_t pmu_mode_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	struct xen_pmu_params xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	uint32_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	xp.version.maj = XENPMU_VER_MAJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	xp.version.min = XENPMU_VER_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	ret = HYPERVISOR_xenpmu_op(XENPMU_mode_get, &xp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	mode = (uint32_t)xp.val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	for (i = 0; i < ARRAY_SIZE(pmu_modes); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		if (mode == pmu_modes[i].mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			return sprintf(buffer, "%s\n", pmu_modes[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) HYPERVISOR_ATTR_RW(pmu_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static ssize_t pmu_features_store(struct hyp_sysfs_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 				  const char *buffer, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	uint32_t features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	struct xen_pmu_params xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	ret = kstrtou32(buffer, 0, &features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	xp.val = features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	xp.version.maj = XENPMU_VER_MAJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	xp.version.min = XENPMU_VER_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	ret = HYPERVISOR_xenpmu_op(XENPMU_feature_set, &xp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static ssize_t pmu_features_show(struct hyp_sysfs_attr *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	struct xen_pmu_params xp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	xp.version.maj = XENPMU_VER_MAJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	xp.version.min = XENPMU_VER_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	ret = HYPERVISOR_xenpmu_op(XENPMU_feature_get, &xp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	return sprintf(buffer, "0x%x\n", (uint32_t)xp.val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) HYPERVISOR_ATTR_RW(pmu_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static struct attribute *xen_pmu_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	&pmu_mode_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	&pmu_features_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static const struct attribute_group xen_pmu_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	.name = "pmu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	.attrs = xen_pmu_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static int __init xen_sysfs_pmu_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	return sysfs_create_group(hypervisor_kobj, &xen_pmu_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static int __init hyper_sysfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	if (!xen_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	ret = xen_sysfs_type_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	ret = xen_sysfs_guest_type_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		goto guest_type_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	ret = xen_sysfs_version_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		goto version_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	ret = xen_sysfs_compilation_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		goto comp_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	ret = xen_sysfs_uuid_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		goto uuid_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	ret = xen_sysfs_properties_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		goto prop_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #ifdef CONFIG_XEN_HAVE_VPMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (xen_initial_domain()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		ret = xen_sysfs_pmu_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			sysfs_remove_group(hypervisor_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 					   &xen_properties_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			goto prop_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) prop_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) uuid_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	sysfs_remove_group(hypervisor_kobj, &xen_compilation_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) comp_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	sysfs_remove_group(hypervisor_kobj, &version_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) version_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	sysfs_remove_file(hypervisor_kobj, &guest_type_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) guest_type_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	sysfs_remove_file(hypervisor_kobj, &type_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) device_initcall(hyper_sysfs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static ssize_t hyp_sysfs_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 			      struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 			      char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	struct hyp_sysfs_attr *hyp_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	if (hyp_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		return hyp_attr->show(hyp_attr, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static ssize_t hyp_sysfs_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 			       struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			       const char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 			       size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	struct hyp_sysfs_attr *hyp_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (hyp_attr->store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		return hyp_attr->store(hyp_attr, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static const struct sysfs_ops hyp_sysfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	.show = hyp_sysfs_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	.store = hyp_sysfs_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static struct kobj_type hyp_sysfs_kobj_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	.sysfs_ops = &hyp_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static int __init hypervisor_subsys_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (!xen_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	hypervisor_kobj->ktype = &hyp_sysfs_kobj_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) device_initcall(hypervisor_subsys_init);