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