Linux Audio

Check our new training course

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