4 * Copyright (c) 2006 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2 as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
18 * Contributions after 2012-01-13 are licensed under the terms of the
19 * GNU GPL, version 2 or (at your option) any later version.
22 #include "qemu/osdep.h"
23 #include "hw/i386/pc.h"
25 #include "hw/isa/apm.h"
26 #include "hw/i2c/pm_smbus.h"
27 #include "hw/pci/pci.h"
28 #include "hw/qdev-properties.h"
29 #include "hw/acpi/acpi.h"
30 #include "sysemu/reset.h"
31 #include "sysemu/runstate.h"
32 #include "sysemu/sysemu.h"
33 #include "qapi/error.h"
34 #include "qemu/range.h"
35 #include "exec/address-spaces.h"
36 #include "hw/acpi/piix4.h"
37 #include "hw/acpi/pcihp.h"
38 #include "hw/acpi/cpu_hotplug.h"
39 #include "hw/acpi/cpu.h"
40 #include "hw/hotplug.h"
41 #include "hw/mem/pc-dimm.h"
42 #include "hw/acpi/memory_hotplug.h"
43 #include "hw/acpi/acpi_dev_interface.h"
44 #include "hw/xen/xen.h"
45 #include "migration/qemu-file-types.h"
46 #include "migration/vmstate.h"
47 #include "hw/core/cpu.h"
50 #define GPE_BASE 0xafe0
54 uint32_t up
; /* deprecated, maintained for migration compatibility */
58 typedef struct PIIX4PMState
{
77 Notifier machine_ready
;
78 Notifier powerdown_notifier
;
80 AcpiPciHpState acpi_pci_hotplug
;
81 bool use_acpi_pci_hotplug
;
87 bool cpu_hotplug_legacy
;
88 AcpiCpuHotplug gpe_cpu
;
89 CPUHotplugState cpuhp_state
;
91 MemHotplugState acpi_memory_hotplug
;
94 #define PIIX4_PM(obj) \
95 OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM)
97 static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent
,
98 PCIBus
*bus
, PIIX4PMState
*s
);
100 #define ACPI_ENABLE 0xf1
101 #define ACPI_DISABLE 0xf0
103 static void pm_tmr_timer(ACPIREGS
*ar
)
105 PIIX4PMState
*s
= container_of(ar
, PIIX4PMState
, ar
);
106 acpi_update_sci(&s
->ar
, s
->irq
);
109 static void apm_ctrl_changed(uint32_t val
, void *arg
)
111 PIIX4PMState
*s
= arg
;
112 PCIDevice
*d
= PCI_DEVICE(s
);
114 /* ACPI specs 3.0, 4.7.2.5 */
115 acpi_pm1_cnt_update(&s
->ar
, val
== ACPI_ENABLE
, val
== ACPI_DISABLE
);
116 if (val
== ACPI_ENABLE
|| val
== ACPI_DISABLE
) {
120 if (d
->config
[0x5b] & (1 << 1)) {
122 qemu_irq_raise(s
->smi_irq
);
127 static void pm_io_space_update(PIIX4PMState
*s
)
129 PCIDevice
*d
= PCI_DEVICE(s
);
131 s
->io_base
= le32_to_cpu(*(uint32_t *)(d
->config
+ 0x40));
132 s
->io_base
&= 0xffc0;
134 memory_region_transaction_begin();
135 memory_region_set_enabled(&s
->io
, d
->config
[0x80] & 1);
136 memory_region_set_address(&s
->io
, s
->io_base
);
137 memory_region_transaction_commit();
140 static void smbus_io_space_update(PIIX4PMState
*s
)
142 PCIDevice
*d
= PCI_DEVICE(s
);
144 s
->smb_io_base
= le32_to_cpu(*(uint32_t *)(d
->config
+ 0x90));
145 s
->smb_io_base
&= 0xffc0;
147 memory_region_transaction_begin();
148 memory_region_set_enabled(&s
->smb
.io
, d
->config
[0xd2] & 1);
149 memory_region_set_address(&s
->smb
.io
, s
->smb_io_base
);
150 memory_region_transaction_commit();
153 static void pm_write_config(PCIDevice
*d
,
154 uint32_t address
, uint32_t val
, int len
)
156 pci_default_write_config(d
, address
, val
, len
);
157 if (range_covers_byte(address
, len
, 0x80) ||
158 ranges_overlap(address
, len
, 0x40, 4)) {
159 pm_io_space_update((PIIX4PMState
*)d
);
161 if (range_covers_byte(address
, len
, 0xd2) ||
162 ranges_overlap(address
, len
, 0x90, 4)) {
163 smbus_io_space_update((PIIX4PMState
*)d
);
167 static int vmstate_acpi_post_load(void *opaque
, int version_id
)
169 PIIX4PMState
*s
= opaque
;
171 pm_io_space_update(s
);
172 smbus_io_space_update(s
);
176 #define VMSTATE_GPE_ARRAY(_field, _state) \
178 .name = (stringify(_field)), \
180 .info = &vmstate_info_uint16, \
181 .size = sizeof(uint16_t), \
182 .flags = VMS_SINGLE | VMS_POINTER, \
183 .offset = vmstate_offset_pointer(_state, _field, uint8_t), \
186 static const VMStateDescription vmstate_gpe
= {
189 .minimum_version_id
= 1,
190 .fields
= (VMStateField
[]) {
191 VMSTATE_GPE_ARRAY(sts
, ACPIGPE
),
192 VMSTATE_GPE_ARRAY(en
, ACPIGPE
),
193 VMSTATE_END_OF_LIST()
197 static const VMStateDescription vmstate_pci_status
= {
198 .name
= "pci_status",
200 .minimum_version_id
= 1,
201 .fields
= (VMStateField
[]) {
202 VMSTATE_UINT32(up
, struct AcpiPciHpPciStatus
),
203 VMSTATE_UINT32(down
, struct AcpiPciHpPciStatus
),
204 VMSTATE_END_OF_LIST()
208 static int acpi_load_old(QEMUFile
*f
, void *opaque
, int version_id
)
210 PIIX4PMState
*s
= opaque
;
214 ret
= pci_device_load(PCI_DEVICE(s
), f
);
218 qemu_get_be16s(f
, &s
->ar
.pm1
.evt
.sts
);
219 qemu_get_be16s(f
, &s
->ar
.pm1
.evt
.en
);
220 qemu_get_be16s(f
, &s
->ar
.pm1
.cnt
.cnt
);
222 ret
= vmstate_load_state(f
, &vmstate_apm
, &s
->apm
, 1);
227 timer_get(f
, s
->ar
.tmr
.timer
);
228 qemu_get_sbe64s(f
, &s
->ar
.tmr
.overflow_time
);
230 qemu_get_be16s(f
, (uint16_t *)s
->ar
.gpe
.sts
);
231 for (i
= 0; i
< 3; i
++) {
232 qemu_get_be16s(f
, &temp
);
235 qemu_get_be16s(f
, (uint16_t *)s
->ar
.gpe
.en
);
236 for (i
= 0; i
< 3; i
++) {
237 qemu_get_be16s(f
, &temp
);
240 ret
= vmstate_load_state(f
, &vmstate_pci_status
,
241 &s
->acpi_pci_hotplug
.acpi_pcihp_pci_status
[ACPI_PCIHP_BSEL_DEFAULT
], 1);
245 static bool vmstate_test_use_acpi_pci_hotplug(void *opaque
, int version_id
)
247 PIIX4PMState
*s
= opaque
;
248 return s
->use_acpi_pci_hotplug
;
251 static bool vmstate_test_no_use_acpi_pci_hotplug(void *opaque
, int version_id
)
253 PIIX4PMState
*s
= opaque
;
254 return !s
->use_acpi_pci_hotplug
;
257 static bool vmstate_test_use_memhp(void *opaque
)
259 PIIX4PMState
*s
= opaque
;
260 return s
->acpi_memory_hotplug
.is_enabled
;
263 static const VMStateDescription vmstate_memhp_state
= {
264 .name
= "piix4_pm/memhp",
266 .minimum_version_id
= 1,
267 .minimum_version_id_old
= 1,
268 .needed
= vmstate_test_use_memhp
,
269 .fields
= (VMStateField
[]) {
270 VMSTATE_MEMORY_HOTPLUG(acpi_memory_hotplug
, PIIX4PMState
),
271 VMSTATE_END_OF_LIST()
275 static bool vmstate_test_use_cpuhp(void *opaque
)
277 PIIX4PMState
*s
= opaque
;
278 return !s
->cpu_hotplug_legacy
;
281 static int vmstate_cpuhp_pre_load(void *opaque
)
283 Object
*obj
= OBJECT(opaque
);
284 object_property_set_bool(obj
, false, "cpu-hotplug-legacy", &error_abort
);
288 static const VMStateDescription vmstate_cpuhp_state
= {
289 .name
= "piix4_pm/cpuhp",
291 .minimum_version_id
= 1,
292 .minimum_version_id_old
= 1,
293 .needed
= vmstate_test_use_cpuhp
,
294 .pre_load
= vmstate_cpuhp_pre_load
,
295 .fields
= (VMStateField
[]) {
296 VMSTATE_CPU_HOTPLUG(cpuhp_state
, PIIX4PMState
),
297 VMSTATE_END_OF_LIST()
301 static bool piix4_vmstate_need_smbus(void *opaque
, int version_id
)
303 return pm_smbus_vmstate_needed();
306 /* qemu-kvm 1.2 uses version 3 but advertised as 2
307 * To support incoming qemu-kvm 1.2 migration, change version_id
308 * and minimum_version_id to 2 below (which breaks migration from
312 static const VMStateDescription vmstate_acpi
= {
315 .minimum_version_id
= 3,
316 .minimum_version_id_old
= 1,
317 .load_state_old
= acpi_load_old
,
318 .post_load
= vmstate_acpi_post_load
,
319 .fields
= (VMStateField
[]) {
320 VMSTATE_PCI_DEVICE(parent_obj
, PIIX4PMState
),
321 VMSTATE_UINT16(ar
.pm1
.evt
.sts
, PIIX4PMState
),
322 VMSTATE_UINT16(ar
.pm1
.evt
.en
, PIIX4PMState
),
323 VMSTATE_UINT16(ar
.pm1
.cnt
.cnt
, PIIX4PMState
),
324 VMSTATE_STRUCT(apm
, PIIX4PMState
, 0, vmstate_apm
, APMState
),
325 VMSTATE_STRUCT_TEST(smb
, PIIX4PMState
, piix4_vmstate_need_smbus
, 3,
326 pmsmb_vmstate
, PMSMBus
),
327 VMSTATE_TIMER_PTR(ar
.tmr
.timer
, PIIX4PMState
),
328 VMSTATE_INT64(ar
.tmr
.overflow_time
, PIIX4PMState
),
329 VMSTATE_STRUCT(ar
.gpe
, PIIX4PMState
, 2, vmstate_gpe
, ACPIGPE
),
331 acpi_pci_hotplug
.acpi_pcihp_pci_status
[ACPI_PCIHP_BSEL_DEFAULT
],
333 vmstate_test_no_use_acpi_pci_hotplug
,
334 2, vmstate_pci_status
,
335 struct AcpiPciHpPciStatus
),
336 VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug
, PIIX4PMState
,
337 vmstate_test_use_acpi_pci_hotplug
),
338 VMSTATE_END_OF_LIST()
340 .subsections
= (const VMStateDescription
*[]) {
341 &vmstate_memhp_state
,
342 &vmstate_cpuhp_state
,
347 static void piix4_reset(void *opaque
)
349 PIIX4PMState
*s
= opaque
;
350 PCIDevice
*d
= PCI_DEVICE(s
);
351 uint8_t *pci_conf
= d
->config
;
358 pci_conf
[0x40] = 0x01; /* PM io base read only bit */
361 if (!s
->smm_enabled
) {
362 /* Mark SMM as already inited (until KVM supports SMM). */
363 pci_conf
[0x5B] = 0x02;
365 pm_io_space_update(s
);
366 acpi_pcihp_reset(&s
->acpi_pci_hotplug
);
369 static void piix4_pm_powerdown_req(Notifier
*n
, void *opaque
)
371 PIIX4PMState
*s
= container_of(n
, PIIX4PMState
, powerdown_notifier
);
374 acpi_pm1_evt_power_down(&s
->ar
);
377 static void piix4_device_pre_plug_cb(HotplugHandler
*hotplug_dev
,
378 DeviceState
*dev
, Error
**errp
)
380 PIIX4PMState
*s
= PIIX4_PM(hotplug_dev
);
382 if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
383 acpi_pcihp_device_pre_plug_cb(hotplug_dev
, dev
, errp
);
384 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
385 if (!s
->acpi_memory_hotplug
.is_enabled
) {
387 "memory hotplug is not enabled: %s.memory-hotplug-support "
388 "is not set", object_get_typename(OBJECT(s
)));
391 !object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
392 error_setg(errp
, "acpi: device pre plug request for not supported"
393 " device type: %s", object_get_typename(OBJECT(dev
)));
397 static void piix4_device_plug_cb(HotplugHandler
*hotplug_dev
,
398 DeviceState
*dev
, Error
**errp
)
400 PIIX4PMState
*s
= PIIX4_PM(hotplug_dev
);
402 if (object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
403 if (object_dynamic_cast(OBJECT(dev
), TYPE_NVDIMM
)) {
404 nvdimm_acpi_plug_cb(hotplug_dev
, dev
);
406 acpi_memory_plug_cb(hotplug_dev
, &s
->acpi_memory_hotplug
,
409 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
410 acpi_pcihp_device_plug_cb(hotplug_dev
, &s
->acpi_pci_hotplug
, dev
, errp
);
411 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
412 if (s
->cpu_hotplug_legacy
) {
413 legacy_acpi_cpu_plug_cb(hotplug_dev
, &s
->gpe_cpu
, dev
, errp
);
415 acpi_cpu_plug_cb(hotplug_dev
, &s
->cpuhp_state
, dev
, errp
);
418 g_assert_not_reached();
422 static void piix4_device_unplug_request_cb(HotplugHandler
*hotplug_dev
,
423 DeviceState
*dev
, Error
**errp
)
425 PIIX4PMState
*s
= PIIX4_PM(hotplug_dev
);
427 if (s
->acpi_memory_hotplug
.is_enabled
&&
428 object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
429 acpi_memory_unplug_request_cb(hotplug_dev
, &s
->acpi_memory_hotplug
,
431 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
432 acpi_pcihp_device_unplug_request_cb(hotplug_dev
, &s
->acpi_pci_hotplug
,
434 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
) &&
435 !s
->cpu_hotplug_legacy
) {
436 acpi_cpu_unplug_request_cb(hotplug_dev
, &s
->cpuhp_state
, dev
, errp
);
438 error_setg(errp
, "acpi: device unplug request for not supported device"
439 " type: %s", object_get_typename(OBJECT(dev
)));
443 static void piix4_device_unplug_cb(HotplugHandler
*hotplug_dev
,
444 DeviceState
*dev
, Error
**errp
)
446 PIIX4PMState
*s
= PIIX4_PM(hotplug_dev
);
448 if (s
->acpi_memory_hotplug
.is_enabled
&&
449 object_dynamic_cast(OBJECT(dev
), TYPE_PC_DIMM
)) {
450 acpi_memory_unplug_cb(&s
->acpi_memory_hotplug
, dev
, errp
);
451 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
452 acpi_pcihp_device_unplug_cb(hotplug_dev
, &s
->acpi_pci_hotplug
, dev
,
454 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
) &&
455 !s
->cpu_hotplug_legacy
) {
456 acpi_cpu_unplug_cb(&s
->cpuhp_state
, dev
, errp
);
458 error_setg(errp
, "acpi: device unplug for not supported device"
459 " type: %s", object_get_typename(OBJECT(dev
)));
463 static void piix4_pm_machine_ready(Notifier
*n
, void *opaque
)
465 PIIX4PMState
*s
= container_of(n
, PIIX4PMState
, machine_ready
);
466 PCIDevice
*d
= PCI_DEVICE(s
);
467 MemoryRegion
*io_as
= pci_address_space_io(d
);
470 pci_conf
= d
->config
;
471 pci_conf
[0x5f] = 0x10 |
472 (memory_region_present(io_as
, 0x378) ? 0x80 : 0);
473 pci_conf
[0x63] = 0x60;
474 pci_conf
[0x67] = (memory_region_present(io_as
, 0x3f8) ? 0x08 : 0) |
475 (memory_region_present(io_as
, 0x2f8) ? 0x90 : 0);
478 static void piix4_pm_add_propeties(PIIX4PMState
*s
)
480 static const uint8_t acpi_enable_cmd
= ACPI_ENABLE
;
481 static const uint8_t acpi_disable_cmd
= ACPI_DISABLE
;
482 static const uint32_t gpe0_blk
= GPE_BASE
;
483 static const uint32_t gpe0_blk_len
= GPE_LEN
;
484 static const uint16_t sci_int
= 9;
486 object_property_add_uint8_ptr(OBJECT(s
), ACPI_PM_PROP_ACPI_ENABLE_CMD
,
487 &acpi_enable_cmd
, NULL
);
488 object_property_add_uint8_ptr(OBJECT(s
), ACPI_PM_PROP_ACPI_DISABLE_CMD
,
489 &acpi_disable_cmd
, NULL
);
490 object_property_add_uint32_ptr(OBJECT(s
), ACPI_PM_PROP_GPE0_BLK
,
492 object_property_add_uint32_ptr(OBJECT(s
), ACPI_PM_PROP_GPE0_BLK_LEN
,
493 &gpe0_blk_len
, NULL
);
494 object_property_add_uint16_ptr(OBJECT(s
), ACPI_PM_PROP_SCI_INT
,
496 object_property_add_uint32_ptr(OBJECT(s
), ACPI_PM_PROP_PM_IO_BASE
,
500 static void piix4_pm_realize(PCIDevice
*dev
, Error
**errp
)
502 PIIX4PMState
*s
= PIIX4_PM(dev
);
505 pci_conf
= dev
->config
;
506 pci_conf
[0x06] = 0x80;
507 pci_conf
[0x07] = 0x02;
508 pci_conf
[0x09] = 0x00;
509 pci_conf
[0x3d] = 0x01; // interrupt pin 1
512 apm_init(dev
, &s
->apm
, apm_ctrl_changed
, s
);
514 if (!s
->smm_enabled
) {
515 /* Mark SMM as already inited to prevent SMM from running. KVM does not
516 * support SMM mode. */
517 pci_conf
[0x5B] = 0x02;
520 /* XXX: which specification is used ? The i82731AB has different
522 pci_conf
[0x90] = s
->smb_io_base
| 1;
523 pci_conf
[0x91] = s
->smb_io_base
>> 8;
524 pci_conf
[0xd2] = 0x09;
525 pm_smbus_init(DEVICE(dev
), &s
->smb
, true);
526 memory_region_set_enabled(&s
->smb
.io
, pci_conf
[0xd2] & 1);
527 memory_region_add_subregion(pci_address_space_io(dev
),
528 s
->smb_io_base
, &s
->smb
.io
);
530 memory_region_init(&s
->io
, OBJECT(s
), "piix4-pm", 64);
531 memory_region_set_enabled(&s
->io
, false);
532 memory_region_add_subregion(pci_address_space_io(dev
),
535 acpi_pm_tmr_init(&s
->ar
, pm_tmr_timer
, &s
->io
);
536 acpi_pm1_evt_init(&s
->ar
, pm_tmr_timer
, &s
->io
);
537 acpi_pm1_cnt_init(&s
->ar
, &s
->io
, s
->disable_s3
, s
->disable_s4
, s
->s4_val
);
538 acpi_gpe_init(&s
->ar
, GPE_LEN
);
540 s
->powerdown_notifier
.notify
= piix4_pm_powerdown_req
;
541 qemu_register_powerdown_notifier(&s
->powerdown_notifier
);
543 s
->machine_ready
.notify
= piix4_pm_machine_ready
;
544 qemu_add_machine_init_done_notifier(&s
->machine_ready
);
545 qemu_register_reset(piix4_reset
, s
);
547 piix4_acpi_system_hot_add_init(pci_address_space_io(dev
),
548 pci_get_bus(dev
), s
);
549 qbus_set_hotplug_handler(BUS(pci_get_bus(dev
)), OBJECT(s
), &error_abort
);
551 piix4_pm_add_propeties(s
);
554 I2CBus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
555 qemu_irq sci_irq
, qemu_irq smi_irq
,
556 int smm_enabled
, DeviceState
**piix4_pm
)
561 dev
= DEVICE(pci_create(bus
, devfn
, TYPE_PIIX4_PM
));
562 qdev_prop_set_uint32(dev
, "smb_io_base", smb_io_base
);
569 s
->smi_irq
= smi_irq
;
570 s
->smm_enabled
= smm_enabled
;
572 s
->use_acpi_pci_hotplug
= false;
575 qdev_init_nofail(dev
);
580 static uint64_t gpe_readb(void *opaque
, hwaddr addr
, unsigned width
)
582 PIIX4PMState
*s
= opaque
;
583 uint32_t val
= acpi_gpe_ioport_readb(&s
->ar
, addr
);
585 trace_piix4_gpe_readb(addr
, width
, val
);
589 static void gpe_writeb(void *opaque
, hwaddr addr
, uint64_t val
,
592 PIIX4PMState
*s
= opaque
;
594 trace_piix4_gpe_writeb(addr
, width
, val
);
595 acpi_gpe_ioport_writeb(&s
->ar
, addr
, val
);
596 acpi_update_sci(&s
->ar
, s
->irq
);
599 static const MemoryRegionOps piix4_gpe_ops
= {
602 .valid
.min_access_size
= 1,
603 .valid
.max_access_size
= 4,
604 .impl
.min_access_size
= 1,
605 .impl
.max_access_size
= 1,
606 .endianness
= DEVICE_LITTLE_ENDIAN
,
610 static bool piix4_get_cpu_hotplug_legacy(Object
*obj
, Error
**errp
)
612 PIIX4PMState
*s
= PIIX4_PM(obj
);
614 return s
->cpu_hotplug_legacy
;
617 static void piix4_set_cpu_hotplug_legacy(Object
*obj
, bool value
, Error
**errp
)
619 PIIX4PMState
*s
= PIIX4_PM(obj
);
622 if (s
->cpu_hotplug_legacy
&& value
== false) {
623 acpi_switch_to_modern_cphp(&s
->gpe_cpu
, &s
->cpuhp_state
,
624 PIIX4_CPU_HOTPLUG_IO_BASE
);
626 s
->cpu_hotplug_legacy
= value
;
629 static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent
,
630 PCIBus
*bus
, PIIX4PMState
*s
)
632 memory_region_init_io(&s
->io_gpe
, OBJECT(s
), &piix4_gpe_ops
, s
,
633 "acpi-gpe0", GPE_LEN
);
634 memory_region_add_subregion(parent
, GPE_BASE
, &s
->io_gpe
);
636 acpi_pcihp_init(OBJECT(s
), &s
->acpi_pci_hotplug
, bus
, parent
,
637 s
->use_acpi_pci_hotplug
);
639 s
->cpu_hotplug_legacy
= true;
640 object_property_add_bool(OBJECT(s
), "cpu-hotplug-legacy",
641 piix4_get_cpu_hotplug_legacy
,
642 piix4_set_cpu_hotplug_legacy
,
644 legacy_acpi_cpu_hotplug_init(parent
, OBJECT(s
), &s
->gpe_cpu
,
645 PIIX4_CPU_HOTPLUG_IO_BASE
);
647 if (s
->acpi_memory_hotplug
.is_enabled
) {
648 acpi_memory_hotplug_init(parent
, OBJECT(s
), &s
->acpi_memory_hotplug
,
649 ACPI_MEMORY_HOTPLUG_BASE
);
653 static void piix4_ospm_status(AcpiDeviceIf
*adev
, ACPIOSTInfoList
***list
)
655 PIIX4PMState
*s
= PIIX4_PM(adev
);
657 acpi_memory_ospm_status(&s
->acpi_memory_hotplug
, list
);
658 if (!s
->cpu_hotplug_legacy
) {
659 acpi_cpu_ospm_status(&s
->cpuhp_state
, list
);
663 static void piix4_send_gpe(AcpiDeviceIf
*adev
, AcpiEventStatusBits ev
)
665 PIIX4PMState
*s
= PIIX4_PM(adev
);
667 acpi_send_gpe_event(&s
->ar
, s
->irq
, ev
);
670 static Property piix4_pm_properties
[] = {
671 DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState
, smb_io_base
, 0),
672 DEFINE_PROP_UINT8(ACPI_PM_PROP_S3_DISABLED
, PIIX4PMState
, disable_s3
, 0),
673 DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_DISABLED
, PIIX4PMState
, disable_s4
, 0),
674 DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_VAL
, PIIX4PMState
, s4_val
, 2),
675 DEFINE_PROP_BOOL("acpi-pci-hotplug-with-bridge-support", PIIX4PMState
,
676 use_acpi_pci_hotplug
, true),
677 DEFINE_PROP_BOOL("memory-hotplug-support", PIIX4PMState
,
678 acpi_memory_hotplug
.is_enabled
, true),
679 DEFINE_PROP_END_OF_LIST(),
682 static void piix4_pm_class_init(ObjectClass
*klass
, void *data
)
684 DeviceClass
*dc
= DEVICE_CLASS(klass
);
685 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
686 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(klass
);
687 AcpiDeviceIfClass
*adevc
= ACPI_DEVICE_IF_CLASS(klass
);
689 k
->realize
= piix4_pm_realize
;
690 k
->config_write
= pm_write_config
;
691 k
->vendor_id
= PCI_VENDOR_ID_INTEL
;
692 k
->device_id
= PCI_DEVICE_ID_INTEL_82371AB_3
;
694 k
->class_id
= PCI_CLASS_BRIDGE_OTHER
;
696 dc
->vmsd
= &vmstate_acpi
;
697 dc
->props
= piix4_pm_properties
;
699 * Reason: part of PIIX4 southbridge, needs to be wired up,
700 * e.g. by mips_malta_init()
702 dc
->user_creatable
= false;
703 dc
->hotpluggable
= false;
704 hc
->pre_plug
= piix4_device_pre_plug_cb
;
705 hc
->plug
= piix4_device_plug_cb
;
706 hc
->unplug_request
= piix4_device_unplug_request_cb
;
707 hc
->unplug
= piix4_device_unplug_cb
;
708 adevc
->ospm_status
= piix4_ospm_status
;
709 adevc
->send_event
= piix4_send_gpe
;
710 adevc
->madt_cpu
= pc_madt_cpu_entry
;
713 static const TypeInfo piix4_pm_info
= {
714 .name
= TYPE_PIIX4_PM
,
715 .parent
= TYPE_PCI_DEVICE
,
716 .instance_size
= sizeof(PIIX4PMState
),
717 .class_init
= piix4_pm_class_init
,
718 .interfaces
= (InterfaceInfo
[]) {
719 { TYPE_HOTPLUG_HANDLER
},
720 { TYPE_ACPI_DEVICE_IF
},
721 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
726 static void piix4_pm_register_types(void)
728 type_register_static(&piix4_pm_info
);
731 type_init(piix4_pm_register_types
)