cpu_hotplug.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * QEMU ACPI hotplug utilities
  3. *
  4. * Copyright (C) 2013 Red Hat Inc
  5. *
  6. * Authors:
  7. * Igor Mammedov <imammedo@redhat.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #include "hw/hw.h"
  13. #include "hw/acpi/cpu_hotplug.h"
  14. static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
  15. {
  16. AcpiCpuHotplug *cpus = opaque;
  17. uint64_t val = cpus->sts[addr];
  18. return val;
  19. }
  20. static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
  21. unsigned int size)
  22. {
  23. /* TODO: implement VCPU removal on guest signal that CPU can be removed */
  24. }
  25. static const MemoryRegionOps AcpiCpuHotplug_ops = {
  26. .read = cpu_status_read,
  27. .write = cpu_status_write,
  28. .endianness = DEVICE_LITTLE_ENDIAN,
  29. .valid = {
  30. .min_access_size = 1,
  31. .max_access_size = 1,
  32. },
  33. };
  34. void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
  35. {
  36. CPUClass *k = CPU_GET_CLASS(cpu);
  37. int64_t cpu_id;
  38. *gpe->sts = *gpe->sts | ACPI_CPU_HOTPLUG_STATUS;
  39. cpu_id = k->get_arch_id(CPU(cpu));
  40. g_assert((cpu_id / 8) < ACPI_GPE_PROC_LEN);
  41. g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
  42. }
  43. void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  44. AcpiCpuHotplug *gpe_cpu, uint16_t base)
  45. {
  46. CPUState *cpu;
  47. CPU_FOREACH(cpu) {
  48. CPUClass *cc = CPU_GET_CLASS(cpu);
  49. int64_t id = cc->get_arch_id(cpu);
  50. g_assert((id / 8) < ACPI_GPE_PROC_LEN);
  51. gpe_cpu->sts[id / 8] |= (1 << (id % 8));
  52. }
  53. memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
  54. gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
  55. memory_region_add_subregion(parent, base, &gpe_cpu->io);
  56. }