xref: /qemu/include/hw/acpi/pcihp.h (revision a28b0f857e55b4a4b8de590d32c0183253c6aa40)
1db4728e6SMichael S. Tsirkin /*
2db4728e6SMichael S. Tsirkin  * QEMU<->ACPI BIOS PCI hotplug interface
3db4728e6SMichael S. Tsirkin  *
4db4728e6SMichael S. Tsirkin  * QEMU supports PCI hotplug via ACPI. This module
5db4728e6SMichael S. Tsirkin  * implements the interface between QEMU and the ACPI BIOS.
6db4728e6SMichael S. Tsirkin  * Interface specification - see docs/specs/acpi_pci_hotplug.txt
7db4728e6SMichael S. Tsirkin  *
8db4728e6SMichael S. Tsirkin  * Copyright (c) 2013, Red Hat Inc, Michael S. Tsirkin (mst@redhat.com)
9db4728e6SMichael S. Tsirkin  * Copyright (c) 2006 Fabrice Bellard
10db4728e6SMichael S. Tsirkin  *
11db4728e6SMichael S. Tsirkin  * This library is free software; you can redistribute it and/or
12db4728e6SMichael S. Tsirkin  * modify it under the terms of the GNU Lesser General Public
1361f3c91aSChetan Pant  * License version 2.1 as published by the Free Software Foundation.
14db4728e6SMichael S. Tsirkin  *
15db4728e6SMichael S. Tsirkin  * This library is distributed in the hope that it will be useful,
16db4728e6SMichael S. Tsirkin  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17db4728e6SMichael S. Tsirkin  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18db4728e6SMichael S. Tsirkin  * Lesser General Public License for more details.
19db4728e6SMichael S. Tsirkin  *
20db4728e6SMichael S. Tsirkin  * You should have received a copy of the GNU Lesser General Public
21db4728e6SMichael S. Tsirkin  * License along with this library; if not, see <http://www.gnu.org/licenses/>
22db4728e6SMichael S. Tsirkin  *
23db4728e6SMichael S. Tsirkin  * Contributions after 2012-01-13 are licensed under the terms of the
24db4728e6SMichael S. Tsirkin  * GNU GPL, version 2 or (at your option) any later version.
25db4728e6SMichael S. Tsirkin  */
26db4728e6SMichael S. Tsirkin 
27db4728e6SMichael S. Tsirkin #ifndef HW_ACPI_PCIHP_H
28db4728e6SMichael S. Tsirkin #define HW_ACPI_PCIHP_H
29db4728e6SMichael S. Tsirkin 
30c24d5e0bSIgor Mammedov #include "hw/acpi/acpi.h"
310058c082SIgor Mammedov #include "hw/hotplug.h"
32db4728e6SMichael S. Tsirkin 
3378c2d872SIgor Mammedov #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"
3478c2d872SIgor Mammedov #define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
3578c2d872SIgor Mammedov 
36db4728e6SMichael S. Tsirkin typedef struct AcpiPciHpPciStatus {
375a2223caSMichael S. Tsirkin     uint32_t up;
38db4728e6SMichael S. Tsirkin     uint32_t down;
39db4728e6SMichael S. Tsirkin     uint32_t hotplug_enable;
40db4728e6SMichael S. Tsirkin } AcpiPciHpPciStatus;
41db4728e6SMichael S. Tsirkin 
42db4728e6SMichael S. Tsirkin #define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel"
43db4728e6SMichael S. Tsirkin #define ACPI_PCIHP_MAX_HOTPLUG_BUS 256
44e358edc8SIgor Mammedov #define ACPI_PCIHP_BSEL_DEFAULT 0x0
45db4728e6SMichael S. Tsirkin 
46db4728e6SMichael S. Tsirkin typedef struct AcpiPciHpState {
47db4728e6SMichael S. Tsirkin     AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS];
48db4728e6SMichael S. Tsirkin     uint32_t hotplug_select;
49b32bd763SIgor Mammedov     uint32_t acpi_index;
50db4728e6SMichael S. Tsirkin     PCIBus *root;
51db4728e6SMichael S. Tsirkin     MemoryRegion io;
5278c2d872SIgor Mammedov     uint16_t io_base;
5378c2d872SIgor Mammedov     uint16_t io_len;
546536e427SIgor Mammedov     bool use_acpi_hotplug_bridge;
556536e427SIgor Mammedov     bool use_acpi_root_pci_hotplug;
56db4728e6SMichael S. Tsirkin } AcpiPciHpState;
57db4728e6SMichael S. Tsirkin 
5878c2d872SIgor Mammedov void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root,
59305ab2b9SPhilippe Mathieu-Daudé                      MemoryRegion *io, uint16_t io_base);
60db4728e6SMichael S. Tsirkin 
61*07153411SGustavo Romero bool acpi_pcihp_is_hotpluggable_bus(AcpiPciHpState *s, BusState *bus);
62ec266f40SDavid Hildenbrand void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
63ec266f40SDavid Hildenbrand                                    DeviceState *dev, Error **errp);
640058c082SIgor Mammedov void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
65c24d5e0bSIgor Mammedov                                DeviceState *dev, Error **errp);
660058c082SIgor Mammedov void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
67c24d5e0bSIgor Mammedov                                  DeviceState *dev, Error **errp);
68c97adf3cSDavid Hildenbrand void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
69c97adf3cSDavid Hildenbrand                                          AcpiPciHpState *s, DeviceState *dev,
70c97adf3cSDavid Hildenbrand                                          Error **errp);
71db4728e6SMichael S. Tsirkin 
72db4728e6SMichael S. Tsirkin /* Called on reset */
736536e427SIgor Mammedov void acpi_pcihp_reset(AcpiPciHpState *s);
74db4728e6SMichael S. Tsirkin 
7502c10613SIgor Mammedov void build_append_pcihp_slots(Aml *parent_scope, PCIBus *bus);
7602c10613SIgor Mammedov 
77db4728e6SMichael S. Tsirkin extern const VMStateDescription vmstate_acpi_pcihp_pci_status;
78db4728e6SMichael S. Tsirkin 
79b32bd763SIgor Mammedov #define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp, test_acpi_index) \
80db4728e6SMichael S. Tsirkin         VMSTATE_UINT32_TEST(pcihp.hotplug_select, state, \
81db4728e6SMichael S. Tsirkin                             test_pcihp), \
82db4728e6SMichael S. Tsirkin         VMSTATE_STRUCT_ARRAY_TEST(pcihp.acpi_pcihp_pci_status, state, \
83db4728e6SMichael S. Tsirkin                                   ACPI_PCIHP_MAX_HOTPLUG_BUS, \
84db4728e6SMichael S. Tsirkin                                   test_pcihp, 1, \
85db4728e6SMichael S. Tsirkin                                   vmstate_acpi_pcihp_pci_status, \
86b32bd763SIgor Mammedov                                   AcpiPciHpPciStatus), \
87b32bd763SIgor Mammedov         VMSTATE_UINT32_TEST(pcihp.acpi_index, state, \
88b32bd763SIgor Mammedov                             test_acpi_index)
89db4728e6SMichael S. Tsirkin 
90db4728e6SMichael S. Tsirkin #endif
91