sys-hypervisor.c (e3900e74f26fc924c8e9e2a922bd40369b0bb517) sys-hypervisor.c (5f141548824cebbff2e838ff401c34e667797467)
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 */

--- 6 unchanged lines hidden (view full) ---

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>
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 */

--- 6 unchanged lines hidden (view full) ---

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
23
24#define HYPERVISOR_ATTR_RO(_name) \
25static struct hyp_sysfs_attr _name##_attr = __ATTR_RO(_name)
26
27#define HYPERVISOR_ATTR_RW(_name) \
28static struct hyp_sysfs_attr _name##_attr = \
29 __ATTR(_name, 0644, _name##_show, _name##_store)
30

--- 332 unchanged lines hidden (view full) ---

363 return sysfs_create_group(hypervisor_kobj, &xen_properties_group);
364}
365
366static void xen_properties_destroy(void)
367{
368 sysfs_remove_group(hypervisor_kobj, &xen_properties_group);
369}
370
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

--- 332 unchanged lines hidden (view full) ---

366 return sysfs_create_group(hypervisor_kobj, &xen_properties_group);
367}
368
369static void xen_properties_destroy(void)
370{
371 sysfs_remove_group(hypervisor_kobj, &xen_properties_group);
372}
373
374#ifdef CONFIG_XEN_HAVE_VPMU
375struct pmu_mode {
376 const char *name;
377 uint32_t mode;
378};
379
380static struct pmu_mode pmu_modes[] = {
381 {"off", XENPMU_MODE_OFF},
382 {"self", XENPMU_MODE_SELF},
383 {"hv", XENPMU_MODE_HV},
384 {"all", XENPMU_MODE_ALL}
385};
386
387static ssize_t pmu_mode_store(struct hyp_sysfs_attr *attr,
388 const char *buffer, size_t len)
389{
390 int ret;
391 struct xen_pmu_params xp;
392 int i;
393
394 for (i = 0; i < ARRAY_SIZE(pmu_modes); i++) {
395 if (strncmp(buffer, pmu_modes[i].name, len - 1) == 0) {
396 xp.val = pmu_modes[i].mode;
397 break;
398 }
399 }
400
401 if (i == ARRAY_SIZE(pmu_modes))
402 return -EINVAL;
403
404 xp.version.maj = XENPMU_VER_MAJ;
405 xp.version.min = XENPMU_VER_MIN;
406 ret = HYPERVISOR_xenpmu_op(XENPMU_mode_set, &xp);
407 if (ret)
408 return ret;
409
410 return len;
411}
412
413static ssize_t pmu_mode_show(struct hyp_sysfs_attr *attr, char *buffer)
414{
415 int ret;
416 struct xen_pmu_params xp;
417 int i;
418 uint32_t mode;
419
420 xp.version.maj = XENPMU_VER_MAJ;
421 xp.version.min = XENPMU_VER_MIN;
422 ret = HYPERVISOR_xenpmu_op(XENPMU_mode_get, &xp);
423 if (ret)
424 return ret;
425
426 mode = (uint32_t)xp.val;
427 for (i = 0; i < ARRAY_SIZE(pmu_modes); i++) {
428 if (mode == pmu_modes[i].mode)
429 return sprintf(buffer, "%s\n", pmu_modes[i].name);
430 }
431
432 return -EINVAL;
433}
434HYPERVISOR_ATTR_RW(pmu_mode);
435
436static ssize_t pmu_features_store(struct hyp_sysfs_attr *attr,
437 const char *buffer, size_t len)
438{
439 int ret;
440 uint32_t features;
441 struct xen_pmu_params xp;
442
443 ret = kstrtou32(buffer, 0, &features);
444 if (ret)
445 return ret;
446
447 xp.val = features;
448 xp.version.maj = XENPMU_VER_MAJ;
449 xp.version.min = XENPMU_VER_MIN;
450 ret = HYPERVISOR_xenpmu_op(XENPMU_feature_set, &xp);
451 if (ret)
452 return ret;
453
454 return len;
455}
456
457static ssize_t pmu_features_show(struct hyp_sysfs_attr *attr, char *buffer)
458{
459 int ret;
460 struct xen_pmu_params xp;
461
462 xp.version.maj = XENPMU_VER_MAJ;
463 xp.version.min = XENPMU_VER_MIN;
464 ret = HYPERVISOR_xenpmu_op(XENPMU_feature_get, &xp);
465 if (ret)
466 return ret;
467
468 return sprintf(buffer, "0x%x\n", (uint32_t)xp.val);
469}
470HYPERVISOR_ATTR_RW(pmu_features);
471
472static struct attribute *xen_pmu_attrs[] = {
473 &pmu_mode_attr.attr,
474 &pmu_features_attr.attr,
475 NULL
476};
477
478static const struct attribute_group xen_pmu_group = {
479 .name = "pmu",
480 .attrs = xen_pmu_attrs,
481};
482
483static int __init xen_pmu_init(void)
484{
485 return sysfs_create_group(hypervisor_kobj, &xen_pmu_group);
486}
487
488static void xen_pmu_destroy(void)
489{
490 sysfs_remove_group(hypervisor_kobj, &xen_pmu_group);
491}
492#endif
493
371static int __init hyper_sysfs_init(void)
372{
373 int ret;
374
375 if (!xen_domain())
376 return -ENODEV;
377
378 ret = xen_sysfs_type_init();

--- 6 unchanged lines hidden (view full) ---

385 if (ret)
386 goto comp_out;
387 ret = xen_sysfs_uuid_init();
388 if (ret)
389 goto uuid_out;
390 ret = xen_properties_init();
391 if (ret)
392 goto prop_out;
494static int __init hyper_sysfs_init(void)
495{
496 int ret;
497
498 if (!xen_domain())
499 return -ENODEV;
500
501 ret = xen_sysfs_type_init();

--- 6 unchanged lines hidden (view full) ---

508 if (ret)
509 goto comp_out;
510 ret = xen_sysfs_uuid_init();
511 if (ret)
512 goto uuid_out;
513 ret = xen_properties_init();
514 if (ret)
515 goto prop_out;
393
516#ifdef CONFIG_XEN_HAVE_VPMU
517 if (xen_initial_domain()) {
518 ret = xen_pmu_init();
519 if (ret) {
520 xen_properties_destroy();
521 goto prop_out;
522 }
523 }
524#endif
394 goto out;
395
396prop_out:
397 xen_sysfs_uuid_destroy();
398uuid_out:
399 xen_compilation_destroy();
400comp_out:
401 xen_sysfs_version_destroy();
402version_out:
403 xen_sysfs_type_destroy();
404out:
405 return ret;
406}
407
408static void __exit hyper_sysfs_exit(void)
409{
525 goto out;
526
527prop_out:
528 xen_sysfs_uuid_destroy();
529uuid_out:
530 xen_compilation_destroy();
531comp_out:
532 xen_sysfs_version_destroy();
533version_out:
534 xen_sysfs_type_destroy();
535out:
536 return ret;
537}
538
539static void __exit hyper_sysfs_exit(void)
540{
541#ifdef CONFIG_XEN_HAVE_VPMU
542 xen_pmu_destroy();
543#endif
410 xen_properties_destroy();
411 xen_compilation_destroy();
412 xen_sysfs_uuid_destroy();
413 xen_sysfs_version_destroy();
414 xen_sysfs_type_destroy();
415
416}
417module_init(hyper_sysfs_init);

--- 43 unchanged lines hidden ---
544 xen_properties_destroy();
545 xen_compilation_destroy();
546 xen_sysfs_uuid_destroy();
547 xen_sysfs_version_destroy();
548 xen_sysfs_type_destroy();
549
550}
551module_init(hyper_sysfs_init);

--- 43 unchanged lines hidden ---