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 "hw/i386/pc.h"
23 #include "hw/isa/apm.h"
24 #include "hw/i2c/pm_smbus.h"
25 #include "hw/pci/pci.h"
26 #include "hw/acpi/acpi.h"
27 #include "sysemu/sysemu.h"
28 #include "qemu/range.h"
29 #include "exec/ioport.h"
30 #include "hw/nvram/fw_cfg.h"
31 #include "exec/address-spaces.h"
36 # define PIIX4_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
38 # define PIIX4_DPRINTF(format, ...) do { } while (0)
41 #define GPE_BASE 0xafe0
44 #define PCI_HOTPLUG_ADDR 0xae00
45 #define PCI_HOTPLUG_SIZE 0x000f
46 #define PCI_UP_BASE 0xae00
47 #define PCI_DOWN_BASE 0xae04
48 #define PCI_EJ_BASE 0xae08
49 #define PCI_RMV_BASE 0xae0c
51 #define PIIX4_PROC_BASE 0xaf00
52 #define PIIX4_PROC_LEN 32
54 #define PIIX4_PCI_HOTPLUG_STATUS 2
55 #define PIIX4_CPU_HOTPLUG_STATUS 4
58 uint32_t up
; /* deprecated, maintained for migration compatibility */
62 typedef struct CPUStatus
{
63 uint8_t sts
[PIIX4_PROC_LEN
];
66 typedef struct PIIX4PMState
{
83 Notifier machine_ready
;
84 Notifier powerdown_notifier
;
87 struct pci_status pci0_status
;
88 uint32_t pci0_hotplug_enable
;
89 uint32_t pci0_slot_device_present
;
96 Notifier cpu_added_notifier
;
99 static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent
,
100 PCIBus
*bus
, PIIX4PMState
*s
);
102 #define ACPI_ENABLE 0xf1
103 #define ACPI_DISABLE 0xf0
105 static void pm_update_sci(PIIX4PMState
*s
)
107 int sci_level
, pmsts
;
109 pmsts
= acpi_pm1_evt_get_sts(&s
->ar
);
110 sci_level
= (((pmsts
& s
->ar
.pm1
.evt
.en
) &
111 (ACPI_BITMASK_RT_CLOCK_ENABLE
|
112 ACPI_BITMASK_POWER_BUTTON_ENABLE
|
113 ACPI_BITMASK_GLOBAL_LOCK_ENABLE
|
114 ACPI_BITMASK_TIMER_ENABLE
)) != 0) ||
115 (((s
->ar
.gpe
.sts
[0] & s
->ar
.gpe
.en
[0]) &
116 (PIIX4_PCI_HOTPLUG_STATUS
| PIIX4_CPU_HOTPLUG_STATUS
)) != 0);
118 qemu_set_irq(s
->irq
, sci_level
);
119 /* schedule a timer interruption if needed */
120 acpi_pm_tmr_update(&s
->ar
, (s
->ar
.pm1
.evt
.en
& ACPI_BITMASK_TIMER_ENABLE
) &&
121 !(pmsts
& ACPI_BITMASK_TIMER_STATUS
));
124 static void pm_tmr_timer(ACPIREGS
*ar
)
126 PIIX4PMState
*s
= container_of(ar
, PIIX4PMState
, ar
);
130 static void apm_ctrl_changed(uint32_t val
, void *arg
)
132 PIIX4PMState
*s
= arg
;
134 /* ACPI specs 3.0, 4.7.2.5 */
135 acpi_pm1_cnt_update(&s
->ar
, val
== ACPI_ENABLE
, val
== ACPI_DISABLE
);
137 if (s
->dev
.config
[0x5b] & (1 << 1)) {
139 qemu_irq_raise(s
->smi_irq
);
144 static void pm_io_space_update(PIIX4PMState
*s
)
148 pm_io_base
= le32_to_cpu(*(uint32_t *)(s
->dev
.config
+ 0x40));
149 pm_io_base
&= 0xffc0;
151 memory_region_transaction_begin();
152 memory_region_set_enabled(&s
->io
, s
->dev
.config
[0x80] & 1);
153 memory_region_set_address(&s
->io
, pm_io_base
);
154 memory_region_transaction_commit();
157 static void smbus_io_space_update(PIIX4PMState
*s
)
159 s
->smb_io_base
= le32_to_cpu(*(uint32_t *)(s
->dev
.config
+ 0x90));
160 s
->smb_io_base
&= 0xffc0;
162 memory_region_transaction_begin();
163 memory_region_set_enabled(&s
->smb
.io
, s
->dev
.config
[0xd2] & 1);
164 memory_region_set_address(&s
->smb
.io
, s
->smb_io_base
);
165 memory_region_transaction_commit();
168 static void pm_write_config(PCIDevice
*d
,
169 uint32_t address
, uint32_t val
, int len
)
171 pci_default_write_config(d
, address
, val
, len
);
172 if (range_covers_byte(address
, len
, 0x80) ||
173 ranges_overlap(address
, len
, 0x40, 4)) {
174 pm_io_space_update((PIIX4PMState
*)d
);
176 if (range_covers_byte(address
, len
, 0xd2) ||
177 ranges_overlap(address
, len
, 0x90, 4)) {
178 smbus_io_space_update((PIIX4PMState
*)d
);
182 static void vmstate_pci_status_pre_save(void *opaque
)
184 struct pci_status
*pci0_status
= opaque
;
185 PIIX4PMState
*s
= container_of(pci0_status
, PIIX4PMState
, pci0_status
);
187 /* We no longer track up, so build a safe value for migrating
188 * to a version that still does... of course these might get lost
189 * by an old buggy implementation, but we try. */
190 pci0_status
->up
= s
->pci0_slot_device_present
& s
->pci0_hotplug_enable
;
193 static int vmstate_acpi_post_load(void *opaque
, int version_id
)
195 PIIX4PMState
*s
= opaque
;
197 pm_io_space_update(s
);
201 #define VMSTATE_GPE_ARRAY(_field, _state) \
203 .name = (stringify(_field)), \
205 .info = &vmstate_info_uint16, \
206 .size = sizeof(uint16_t), \
207 .flags = VMS_SINGLE | VMS_POINTER, \
208 .offset = vmstate_offset_pointer(_state, _field, uint8_t), \
211 static const VMStateDescription vmstate_gpe
= {
214 .minimum_version_id
= 1,
215 .minimum_version_id_old
= 1,
216 .fields
= (VMStateField
[]) {
217 VMSTATE_GPE_ARRAY(sts
, ACPIGPE
),
218 VMSTATE_GPE_ARRAY(en
, ACPIGPE
),
219 VMSTATE_END_OF_LIST()
223 static const VMStateDescription vmstate_pci_status
= {
224 .name
= "pci_status",
226 .minimum_version_id
= 1,
227 .minimum_version_id_old
= 1,
228 .pre_save
= vmstate_pci_status_pre_save
,
229 .fields
= (VMStateField
[]) {
230 VMSTATE_UINT32(up
, struct pci_status
),
231 VMSTATE_UINT32(down
, struct pci_status
),
232 VMSTATE_END_OF_LIST()
236 static int acpi_load_old(QEMUFile
*f
, void *opaque
, int version_id
)
238 PIIX4PMState
*s
= opaque
;
242 ret
= pci_device_load(&s
->dev
, f
);
246 qemu_get_be16s(f
, &s
->ar
.pm1
.evt
.sts
);
247 qemu_get_be16s(f
, &s
->ar
.pm1
.evt
.en
);
248 qemu_get_be16s(f
, &s
->ar
.pm1
.cnt
.cnt
);
250 ret
= vmstate_load_state(f
, &vmstate_apm
, &s
->apm
, 1);
255 qemu_get_timer(f
, s
->ar
.tmr
.timer
);
256 qemu_get_sbe64s(f
, &s
->ar
.tmr
.overflow_time
);
258 qemu_get_be16s(f
, (uint16_t *)s
->ar
.gpe
.sts
);
259 for (i
= 0; i
< 3; i
++) {
260 qemu_get_be16s(f
, &temp
);
263 qemu_get_be16s(f
, (uint16_t *)s
->ar
.gpe
.en
);
264 for (i
= 0; i
< 3; i
++) {
265 qemu_get_be16s(f
, &temp
);
268 ret
= vmstate_load_state(f
, &vmstate_pci_status
, &s
->pci0_status
, 1);
272 /* qemu-kvm 1.2 uses version 3 but advertised as 2
273 * To support incoming qemu-kvm 1.2 migration, change version_id
274 * and minimum_version_id to 2 below (which breaks migration from
278 static const VMStateDescription vmstate_acpi
= {
281 .minimum_version_id
= 3,
282 .minimum_version_id_old
= 1,
283 .load_state_old
= acpi_load_old
,
284 .post_load
= vmstate_acpi_post_load
,
285 .fields
= (VMStateField
[]) {
286 VMSTATE_PCI_DEVICE(dev
, PIIX4PMState
),
287 VMSTATE_UINT16(ar
.pm1
.evt
.sts
, PIIX4PMState
),
288 VMSTATE_UINT16(ar
.pm1
.evt
.en
, PIIX4PMState
),
289 VMSTATE_UINT16(ar
.pm1
.cnt
.cnt
, PIIX4PMState
),
290 VMSTATE_STRUCT(apm
, PIIX4PMState
, 0, vmstate_apm
, APMState
),
291 VMSTATE_TIMER(ar
.tmr
.timer
, PIIX4PMState
),
292 VMSTATE_INT64(ar
.tmr
.overflow_time
, PIIX4PMState
),
293 VMSTATE_STRUCT(ar
.gpe
, PIIX4PMState
, 2, vmstate_gpe
, ACPIGPE
),
294 VMSTATE_STRUCT(pci0_status
, PIIX4PMState
, 2, vmstate_pci_status
,
296 VMSTATE_END_OF_LIST()
300 static void acpi_piix_eject_slot(PIIX4PMState
*s
, unsigned slots
)
302 BusChild
*kid
, *next
;
303 BusState
*bus
= qdev_get_parent_bus(&s
->dev
.qdev
);
304 int slot
= ffs(slots
) - 1;
305 bool slot_free
= true;
307 /* Mark request as complete */
308 s
->pci0_status
.down
&= ~(1U << slot
);
310 QTAILQ_FOREACH_SAFE(kid
, &bus
->children
, sibling
, next
) {
311 DeviceState
*qdev
= kid
->child
;
312 PCIDevice
*dev
= PCI_DEVICE(qdev
);
313 PCIDeviceClass
*pc
= PCI_DEVICE_GET_CLASS(dev
);
314 if (PCI_SLOT(dev
->devfn
) == slot
) {
315 if (pc
->no_hotplug
) {
323 s
->pci0_slot_device_present
&= ~(1U << slot
);
327 static void piix4_update_hotplug(PIIX4PMState
*s
)
329 PCIDevice
*dev
= &s
->dev
;
330 BusState
*bus
= qdev_get_parent_bus(&dev
->qdev
);
331 BusChild
*kid
, *next
;
333 /* Execute any pending removes during reset */
334 while (s
->pci0_status
.down
) {
335 acpi_piix_eject_slot(s
, s
->pci0_status
.down
);
338 s
->pci0_hotplug_enable
= ~0;
339 s
->pci0_slot_device_present
= 0;
341 QTAILQ_FOREACH_SAFE(kid
, &bus
->children
, sibling
, next
) {
342 DeviceState
*qdev
= kid
->child
;
343 PCIDevice
*pdev
= PCI_DEVICE(qdev
);
344 PCIDeviceClass
*pc
= PCI_DEVICE_GET_CLASS(pdev
);
345 int slot
= PCI_SLOT(pdev
->devfn
);
347 if (pc
->no_hotplug
) {
348 s
->pci0_hotplug_enable
&= ~(1U << slot
);
351 s
->pci0_slot_device_present
|= (1U << slot
);
355 static void piix4_reset(void *opaque
)
357 PIIX4PMState
*s
= opaque
;
358 uint8_t *pci_conf
= s
->dev
.config
;
365 pci_conf
[0x40] = 0x01; /* PM io base read only bit */
368 if (s
->kvm_enabled
) {
369 /* Mark SMM as already inited (until KVM supports SMM). */
370 pci_conf
[0x5B] = 0x02;
372 piix4_update_hotplug(s
);
375 static void piix4_pm_powerdown_req(Notifier
*n
, void *opaque
)
377 PIIX4PMState
*s
= container_of(n
, PIIX4PMState
, powerdown_notifier
);
380 acpi_pm1_evt_power_down(&s
->ar
);
383 static void piix4_pm_machine_ready(Notifier
*n
, void *opaque
)
385 PIIX4PMState
*s
= container_of(n
, PIIX4PMState
, machine_ready
);
388 pci_conf
= s
->dev
.config
;
389 pci_conf
[0x5f] = (isa_is_ioport_assigned(0x378) ? 0x80 : 0) | 0x10;
390 pci_conf
[0x63] = 0x60;
391 pci_conf
[0x67] = (isa_is_ioport_assigned(0x3f8) ? 0x08 : 0) |
392 (isa_is_ioport_assigned(0x2f8) ? 0x90 : 0);
396 static int piix4_pm_initfn(PCIDevice
*dev
)
398 PIIX4PMState
*s
= DO_UPCAST(PIIX4PMState
, dev
, dev
);
401 pci_conf
= s
->dev
.config
;
402 pci_conf
[0x06] = 0x80;
403 pci_conf
[0x07] = 0x02;
404 pci_conf
[0x09] = 0x00;
405 pci_conf
[0x3d] = 0x01; // interrupt pin 1
408 apm_init(dev
, &s
->apm
, apm_ctrl_changed
, s
);
410 if (s
->kvm_enabled
) {
411 /* Mark SMM as already inited to prevent SMM from running. KVM does not
412 * support SMM mode. */
413 pci_conf
[0x5B] = 0x02;
416 /* XXX: which specification is used ? The i82731AB has different
418 pci_conf
[0x90] = s
->smb_io_base
| 1;
419 pci_conf
[0x91] = s
->smb_io_base
>> 8;
420 pci_conf
[0xd2] = 0x09;
421 pm_smbus_init(&s
->dev
.qdev
, &s
->smb
);
422 memory_region_set_enabled(&s
->smb
.io
, pci_conf
[0xd2] & 1);
423 memory_region_add_subregion(pci_address_space_io(dev
),
424 s
->smb_io_base
, &s
->smb
.io
);
426 memory_region_init(&s
->io
, "piix4-pm", 64);
427 memory_region_set_enabled(&s
->io
, false);
428 memory_region_add_subregion(pci_address_space_io(dev
),
431 acpi_pm_tmr_init(&s
->ar
, pm_tmr_timer
, &s
->io
);
432 acpi_pm1_evt_init(&s
->ar
, pm_tmr_timer
, &s
->io
);
433 acpi_pm1_cnt_init(&s
->ar
, &s
->io
, s
->s4_val
);
434 acpi_gpe_init(&s
->ar
, GPE_LEN
);
436 s
->powerdown_notifier
.notify
= piix4_pm_powerdown_req
;
437 qemu_register_powerdown_notifier(&s
->powerdown_notifier
);
439 s
->machine_ready
.notify
= piix4_pm_machine_ready
;
440 qemu_add_machine_init_done_notifier(&s
->machine_ready
);
441 qemu_register_reset(piix4_reset
, s
);
443 piix4_acpi_system_hot_add_init(pci_address_space_io(dev
), dev
->bus
, s
);
448 i2c_bus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
449 qemu_irq sci_irq
, qemu_irq smi_irq
,
450 int kvm_enabled
, void *fw_cfg
)
455 dev
= pci_create(bus
, devfn
, "PIIX4_PM");
456 qdev_prop_set_uint32(&dev
->qdev
, "smb_io_base", smb_io_base
);
458 s
= DO_UPCAST(PIIX4PMState
, dev
, dev
);
460 s
->smi_irq
= smi_irq
;
461 s
->kvm_enabled
= kvm_enabled
;
463 qdev_init_nofail(&dev
->qdev
);
466 uint8_t suspend
[6] = {128, 0, 0, 129, 128, 128};
467 suspend
[3] = 1 | ((!s
->disable_s3
) << 7);
468 suspend
[4] = s
->s4_val
| ((!s
->disable_s4
) << 7);
470 fw_cfg_add_file(fw_cfg
, "etc/system-states", g_memdup(suspend
, 6), 6);
476 static Property piix4_pm_properties
[] = {
477 DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState
, smb_io_base
, 0),
478 DEFINE_PROP_UINT8("disable_s3", PIIX4PMState
, disable_s3
, 0),
479 DEFINE_PROP_UINT8("disable_s4", PIIX4PMState
, disable_s4
, 0),
480 DEFINE_PROP_UINT8("s4_val", PIIX4PMState
, s4_val
, 2),
481 DEFINE_PROP_END_OF_LIST(),
484 static void piix4_pm_class_init(ObjectClass
*klass
, void *data
)
486 DeviceClass
*dc
= DEVICE_CLASS(klass
);
487 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
490 k
->init
= piix4_pm_initfn
;
491 k
->config_write
= pm_write_config
;
492 k
->vendor_id
= PCI_VENDOR_ID_INTEL
;
493 k
->device_id
= PCI_DEVICE_ID_INTEL_82371AB_3
;
495 k
->class_id
= PCI_CLASS_BRIDGE_OTHER
;
498 dc
->vmsd
= &vmstate_acpi
;
499 dc
->props
= piix4_pm_properties
;
502 static const TypeInfo piix4_pm_info
= {
504 .parent
= TYPE_PCI_DEVICE
,
505 .instance_size
= sizeof(PIIX4PMState
),
506 .class_init
= piix4_pm_class_init
,
509 static void piix4_pm_register_types(void)
511 type_register_static(&piix4_pm_info
);
514 type_init(piix4_pm_register_types
)
516 static uint64_t gpe_readb(void *opaque
, hwaddr addr
, unsigned width
)
518 PIIX4PMState
*s
= opaque
;
519 uint32_t val
= acpi_gpe_ioport_readb(&s
->ar
, addr
);
521 PIIX4_DPRINTF("gpe read %x == %x\n", addr
, val
);
525 static void gpe_writeb(void *opaque
, hwaddr addr
, uint64_t val
,
528 PIIX4PMState
*s
= opaque
;
530 acpi_gpe_ioport_writeb(&s
->ar
, addr
, val
);
533 PIIX4_DPRINTF("gpe write %x <== %d\n", addr
, val
);
536 static const MemoryRegionOps piix4_gpe_ops
= {
539 .valid
.min_access_size
= 1,
540 .valid
.max_access_size
= 4,
541 .impl
.min_access_size
= 1,
542 .impl
.max_access_size
= 1,
543 .endianness
= DEVICE_LITTLE_ENDIAN
,
546 static uint64_t pci_read(void *opaque
, hwaddr addr
, unsigned int size
)
548 PIIX4PMState
*s
= opaque
;
552 case PCI_UP_BASE
- PCI_HOTPLUG_ADDR
:
553 /* Manufacture an "up" value to cause a device check on any hotplug
554 * slot with a device. Extra device checks are harmless. */
555 val
= s
->pci0_slot_device_present
& s
->pci0_hotplug_enable
;
556 PIIX4_DPRINTF("pci_up_read %x\n", val
);
558 case PCI_DOWN_BASE
- PCI_HOTPLUG_ADDR
:
559 val
= s
->pci0_status
.down
;
560 PIIX4_DPRINTF("pci_down_read %x\n", val
);
562 case PCI_EJ_BASE
- PCI_HOTPLUG_ADDR
:
563 /* No feature defined yet */
564 PIIX4_DPRINTF("pci_features_read %x\n", val
);
566 case PCI_RMV_BASE
- PCI_HOTPLUG_ADDR
:
567 val
= s
->pci0_hotplug_enable
;
576 static void pci_write(void *opaque
, hwaddr addr
, uint64_t data
,
580 case PCI_EJ_BASE
- PCI_HOTPLUG_ADDR
:
581 acpi_piix_eject_slot(opaque
, (uint32_t)data
);
582 PIIX4_DPRINTF("pciej write %" HWADDR_PRIx
" <== % " PRIu64
"\n",
590 static const MemoryRegionOps piix4_pci_ops
= {
593 .endianness
= DEVICE_LITTLE_ENDIAN
,
595 .min_access_size
= 4,
596 .max_access_size
= 4,
600 static uint64_t cpu_status_read(void *opaque
, hwaddr addr
, unsigned int size
)
602 PIIX4PMState
*s
= opaque
;
603 CPUStatus
*cpus
= &s
->gpe_cpu
;
604 uint64_t val
= cpus
->sts
[addr
];
609 static void cpu_status_write(void *opaque
, hwaddr addr
, uint64_t data
,
612 /* TODO: implement VCPU removal on guest signal that CPU can be removed */
615 static const MemoryRegionOps cpu_hotplug_ops
= {
616 .read
= cpu_status_read
,
617 .write
= cpu_status_write
,
618 .endianness
= DEVICE_LITTLE_ENDIAN
,
620 .min_access_size
= 1,
621 .max_access_size
= 1,
630 static void piix4_cpu_hotplug_req(PIIX4PMState
*s
, CPUState
*cpu
,
631 HotplugEventType action
)
633 CPUStatus
*g
= &s
->gpe_cpu
;
634 ACPIGPE
*gpe
= &s
->ar
.gpe
;
635 CPUClass
*k
= CPU_GET_CLASS(cpu
);
640 *gpe
->sts
= *gpe
->sts
| PIIX4_CPU_HOTPLUG_STATUS
;
641 cpu_id
= k
->get_arch_id(CPU(cpu
));
642 if (action
== PLUG
) {
643 g
->sts
[cpu_id
/ 8] |= (1 << (cpu_id
% 8));
645 g
->sts
[cpu_id
/ 8] &= ~(1 << (cpu_id
% 8));
650 static void piix4_cpu_added_req(Notifier
*n
, void *opaque
)
652 PIIX4PMState
*s
= container_of(n
, PIIX4PMState
, cpu_added_notifier
);
654 piix4_cpu_hotplug_req(s
, CPU(opaque
), PLUG
);
657 static void piix4_init_cpu_status(CPUState
*cpu
, void *data
)
659 CPUStatus
*g
= (CPUStatus
*)data
;
660 CPUClass
*k
= CPU_GET_CLASS(cpu
);
661 int64_t id
= k
->get_arch_id(cpu
);
663 g_assert((id
/ 8) < PIIX4_PROC_LEN
);
664 g
->sts
[id
/ 8] |= (1 << (id
% 8));
667 static int piix4_device_hotplug(DeviceState
*qdev
, PCIDevice
*dev
,
668 PCIHotplugState state
);
670 static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent
,
671 PCIBus
*bus
, PIIX4PMState
*s
)
673 memory_region_init_io(&s
->io_gpe
, &piix4_gpe_ops
, s
, "apci-gpe0",
675 memory_region_add_subregion(parent
, GPE_BASE
, &s
->io_gpe
);
677 memory_region_init_io(&s
->io_pci
, &piix4_pci_ops
, s
, "apci-pci-hotplug",
679 memory_region_add_subregion(parent
, PCI_HOTPLUG_ADDR
,
681 pci_bus_hotplug(bus
, piix4_device_hotplug
, &s
->dev
.qdev
);
683 qemu_for_each_cpu(piix4_init_cpu_status
, &s
->gpe_cpu
);
684 memory_region_init_io(&s
->io_cpu
, &cpu_hotplug_ops
, s
, "apci-cpu-hotplug",
686 memory_region_add_subregion(parent
, PIIX4_PROC_BASE
, &s
->io_cpu
);
687 s
->cpu_added_notifier
.notify
= piix4_cpu_added_req
;
688 qemu_register_cpu_added_notifier(&s
->cpu_added_notifier
);
691 static void enable_device(PIIX4PMState
*s
, int slot
)
693 s
->ar
.gpe
.sts
[0] |= PIIX4_PCI_HOTPLUG_STATUS
;
694 s
->pci0_slot_device_present
|= (1U << slot
);
697 static void disable_device(PIIX4PMState
*s
, int slot
)
699 s
->ar
.gpe
.sts
[0] |= PIIX4_PCI_HOTPLUG_STATUS
;
700 s
->pci0_status
.down
|= (1U << slot
);
703 static int piix4_device_hotplug(DeviceState
*qdev
, PCIDevice
*dev
,
704 PCIHotplugState state
)
706 int slot
= PCI_SLOT(dev
->devfn
);
707 PIIX4PMState
*s
= DO_UPCAST(PIIX4PMState
, dev
,
710 /* Don't send event when device is enabled during qemu machine creation:
711 * it is present on boot, no hotplug event is necessary. We do send an
712 * event when the device is disabled later. */
713 if (state
== PCI_COLDPLUG_ENABLED
) {
714 s
->pci0_slot_device_present
|= (1U << slot
);
718 if (state
== PCI_HOTPLUG_ENABLED
) {
719 enable_device(s
, slot
);
721 disable_device(s
, slot
);