core.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * CPU core abstract device
  3. *
  4. * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #include "qemu/osdep.h"
  10. #include "hw/cpu/core.h"
  11. #include "qapi/visitor.h"
  12. #include "qemu/module.h"
  13. #include "qapi/error.h"
  14. #include "sysemu/cpus.h"
  15. #include "hw/boards.h"
  16. static void core_prop_get_core_id(Object *obj, Visitor *v, const char *name,
  17. void *opaque, Error **errp)
  18. {
  19. CPUCore *core = CPU_CORE(obj);
  20. int64_t value = core->core_id;
  21. visit_type_int(v, name, &value, errp);
  22. }
  23. static void core_prop_set_core_id(Object *obj, Visitor *v, const char *name,
  24. void *opaque, Error **errp)
  25. {
  26. CPUCore *core = CPU_CORE(obj);
  27. int64_t value;
  28. if (!visit_type_int(v, name, &value, errp)) {
  29. return;
  30. }
  31. if (value < 0) {
  32. error_setg(errp, "Invalid core id %"PRId64, value);
  33. return;
  34. }
  35. core->core_id = value;
  36. }
  37. static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *name,
  38. void *opaque, Error **errp)
  39. {
  40. CPUCore *core = CPU_CORE(obj);
  41. int64_t value = core->nr_threads;
  42. visit_type_int(v, name, &value, errp);
  43. }
  44. static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
  45. void *opaque, Error **errp)
  46. {
  47. CPUCore *core = CPU_CORE(obj);
  48. int64_t value;
  49. if (!visit_type_int(v, name, &value, errp)) {
  50. return;
  51. }
  52. core->nr_threads = value;
  53. }
  54. static void cpu_core_instance_init(Object *obj)
  55. {
  56. MachineState *ms = MACHINE(qdev_get_machine());
  57. CPUCore *core = CPU_CORE(obj);
  58. object_property_add(obj, "core-id", "int", core_prop_get_core_id,
  59. core_prop_set_core_id, NULL, NULL);
  60. object_property_add(obj, "nr-threads", "int", core_prop_get_nr_threads,
  61. core_prop_set_nr_threads, NULL, NULL);
  62. core->nr_threads = ms->smp.threads;
  63. }
  64. static void cpu_core_class_init(ObjectClass *oc, void *data)
  65. {
  66. DeviceClass *dc = DEVICE_CLASS(oc);
  67. set_bit(DEVICE_CATEGORY_CPU, dc->categories);
  68. }
  69. static const TypeInfo cpu_core_type_info = {
  70. .name = TYPE_CPU_CORE,
  71. .parent = TYPE_DEVICE,
  72. .abstract = true,
  73. .class_init = cpu_core_class_init,
  74. .instance_size = sizeof(CPUCore),
  75. .instance_init = cpu_core_instance_init,
  76. };
  77. static void cpu_core_register_types(void)
  78. {
  79. type_register_static(&cpu_core_type_info);
  80. }
  81. type_init(cpu_core_register_types)