]> git.proxmox.com Git - mirror_qemu.git/blame - hw/acpi/cpu_hotplug.c
include/qemu/osdep.h: Don't include qapi/error.h
[mirror_qemu.git] / hw / acpi / cpu_hotplug.c
CommitLineData
81cea5e7
IM
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 */
b6a0aa05 12#include "qemu/osdep.h"
81cea5e7
IM
13#include "hw/hw.h"
14#include "hw/acpi/cpu_hotplug.h"
da34e65c 15#include "qapi/error.h"
508127e2 16#include "qom/cpu.h"
81cea5e7
IM
17
18static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
19{
20 AcpiCpuHotplug *cpus = opaque;
21 uint64_t val = cpus->sts[addr];
22
23 return val;
24}
25
26static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
27 unsigned int size)
28{
29 /* TODO: implement VCPU removal on guest signal that CPU can be removed */
30}
31
32static const MemoryRegionOps AcpiCpuHotplug_ops = {
33 .read = cpu_status_read,
34 .write = cpu_status_write,
35 .endianness = DEVICE_LITTLE_ENDIAN,
36 .valid = {
37 .min_access_size = 1,
38 .max_access_size = 1,
39 },
40};
41
cc43364d
GZ
42static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
43 Error **errp)
1be6b511 44{
1be6b511
GZ
45 CPUClass *k = CPU_GET_CLASS(cpu);
46 int64_t cpu_id;
47
48 cpu_id = k->get_arch_id(cpu);
49 if ((cpu_id / 8) >= ACPI_GPE_PROC_LEN) {
50 error_setg(errp, "acpi: invalid cpu id: %" PRIi64, cpu_id);
51 return;
52 }
53
08bba95b 54 g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
cc43364d
GZ
55}
56
57void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
58 AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
59{
60 acpi_set_cpu_present_bit(g, CPU(dev), errp);
61 if (*errp != NULL) {
62 return;
63 }
1be6b511 64
ca9b46bc 65 acpi_send_gpe_event(ar, irq, ACPI_CPU_HOTPLUG_STATUS);
1be6b511
GZ
66}
67
411b5db8
GZ
68void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
69 AcpiCpuHotplug *gpe_cpu, uint16_t base)
81cea5e7
IM
70{
71 CPUState *cpu;
72
73 CPU_FOREACH(cpu) {
cc43364d 74 acpi_set_cpu_present_bit(gpe_cpu, cpu, &error_abort);
81cea5e7
IM
75 }
76 memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
77 gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
78 memory_region_add_subregion(parent, base, &gpe_cpu->io);
79}