xref: /openbmc/qemu/include/hw/acpi/pcihp.h (revision e452053097371880910c744a5d42ae2df058a4a7)
1 /*
2  * QEMU<->ACPI BIOS PCI hotplug interface
3  *
4  * QEMU supports PCI hotplug via ACPI. This module
5  * implements the interface between QEMU and the ACPI BIOS.
6  * Interface specification - see docs/specs/acpi_pci_hotplug.rst
7  *
8  * Copyright (c) 2013, Red Hat Inc, Michael S. Tsirkin (mst@redhat.com)
9  * Copyright (c) 2006 Fabrice Bellard
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License version 2.1 as published by the Free Software Foundation.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, see <http://www.gnu.org/licenses/>
22  *
23  * Contributions after 2012-01-13 are licensed under the terms of the
24  * GNU GPL, version 2 or (at your option) any later version.
25  */
26 
27 #ifndef HW_ACPI_PCIHP_H
28 #define HW_ACPI_PCIHP_H
29 
30 #include "hw/acpi/acpi.h"
31 #include "hw/acpi/aml-build.h"
32 #include "hw/hotplug.h"
33 
34 #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"
35 #define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
36 
37 /* PCI Hot-plug registers bases. See docs/specs/acpi_pci_hotplug.rst */
38 #define ACPI_PCIHP_SEJ_BASE 0x8
39 #define ACPI_PCIHP_BNMR_BASE 0x10
40 
41 #define ACPI_PCIHP_SIZE 0x0018
42 
43 typedef struct AcpiPciHpPciStatus {
44     uint32_t up;
45     uint32_t down;
46     uint32_t hotplug_enable;
47 } AcpiPciHpPciStatus;
48 
49 #define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel"
50 #define ACPI_PCIHP_MAX_HOTPLUG_BUS 256
51 #define ACPI_PCIHP_BSEL_DEFAULT 0x0
52 
53 typedef struct AcpiPciHpState {
54     AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS];
55     uint32_t hotplug_select;
56     uint32_t acpi_index;
57     PCIBus *root;
58     MemoryRegion io;
59     uint16_t io_base;
60     uint16_t io_len;
61     bool use_acpi_hotplug_bridge;
62     bool use_acpi_root_pci_hotplug;
63 } AcpiPciHpState;
64 
65 void acpi_pcihp_init(Object *owner, AcpiPciHpState *,
66                      MemoryRegion *io, uint16_t io_base);
67 
68 bool acpi_pcihp_is_hotpluggable_bus(AcpiPciHpState *s, BusState *bus);
69 void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
70                                    DeviceState *dev, Error **errp);
71 void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
72                                DeviceState *dev, Error **errp);
73 void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
74                                  DeviceState *dev, Error **errp);
75 void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
76                                          AcpiPciHpState *s, DeviceState *dev,
77                                          Error **errp);
78 
79 void build_acpi_pci_hotplug(Aml *table, AmlRegionSpace rs, uint64_t pcihp_addr);
80 void build_append_pci_dsm_func0_common(Aml *ctx, Aml *retvar);
81 void build_append_pcihp_resources(Aml *table,
82                                   uint64_t io_addr, uint64_t io_len);
83 bool build_append_notification_callback(Aml *parent_scope, const PCIBus *bus);
84 
85 void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus);
86 
87 /* Called on reset */
88 void acpi_pcihp_reset(AcpiPciHpState *s);
89 
90 void build_append_pcihp_slots(Aml *parent_scope, PCIBus *bus);
91 
92 extern const VMStateDescription vmstate_acpi_pcihp_pci_status;
93 
94 #define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp, test_acpi_index) \
95         VMSTATE_UINT32_TEST(pcihp.hotplug_select, state, \
96                             test_pcihp), \
97         VMSTATE_STRUCT_ARRAY_TEST(pcihp.acpi_pcihp_pci_status, state, \
98                                   ACPI_PCIHP_MAX_HOTPLUG_BUS, \
99                                   test_pcihp, 1, \
100                                   vmstate_acpi_pcihp_pci_status, \
101                                   AcpiPciHpPciStatus), \
102         VMSTATE_UINT32_TEST(pcihp.acpi_index, state, \
103                             test_acpi_index)
104 
105 #endif
106