Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 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.txt |
| 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 |
Chetan Pant | 61f3c91 | 2020-10-23 12:44:24 +0000 | [diff] [blame] | 13 | * License version 2.1 as published by the Free Software Foundation. |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 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 | |
Igor Mammedov | c24d5e0 | 2014-02-05 16:36:49 +0100 | [diff] [blame] | 30 | #include "hw/acpi/acpi.h" |
Igor Mammedov | 0058c08 | 2016-05-31 12:01:17 +0200 | [diff] [blame] | 31 | #include "hw/hotplug.h" |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 32 | |
Igor Mammedov | 78c2d87 | 2015-02-18 19:14:49 +0000 | [diff] [blame] | 33 | #define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base" |
| 34 | #define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len" |
| 35 | |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 36 | typedef struct AcpiPciHpPciStatus { |
Michael S. Tsirkin | 5a2223c | 2014-01-26 12:31:27 +0200 | [diff] [blame] | 37 | uint32_t up; |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 38 | uint32_t down; |
| 39 | uint32_t hotplug_enable; |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 40 | } AcpiPciHpPciStatus; |
| 41 | |
| 42 | #define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel" |
| 43 | #define ACPI_PCIHP_MAX_HOTPLUG_BUS 256 |
Igor Mammedov | e358edc | 2014-02-03 11:45:01 +0100 | [diff] [blame] | 44 | #define ACPI_PCIHP_BSEL_DEFAULT 0x0 |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 45 | |
| 46 | typedef struct AcpiPciHpState { |
| 47 | AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS]; |
| 48 | uint32_t hotplug_select; |
Igor Mammedov | b32bd76 | 2021-03-15 14:00:58 -0400 | [diff] [blame] | 49 | uint32_t acpi_index; |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 50 | PCIBus *root; |
| 51 | MemoryRegion io; |
Igor Mammedov | 99d09dd | 2014-02-03 11:44:59 +0100 | [diff] [blame] | 52 | bool legacy_piix; |
Igor Mammedov | 78c2d87 | 2015-02-18 19:14:49 +0000 | [diff] [blame] | 53 | uint16_t io_base; |
| 54 | uint16_t io_len; |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 55 | } AcpiPciHpState; |
| 56 | |
Igor Mammedov | 78c2d87 | 2015-02-18 19:14:49 +0000 | [diff] [blame] | 57 | void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root, |
Julia Suvorova | caf108b | 2021-07-13 02:42:00 +0200 | [diff] [blame] | 58 | MemoryRegion *address_space_io, bool bridges_enabled, |
| 59 | uint16_t io_base); |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 60 | |
David Hildenbrand | ec266f4 | 2018-12-12 10:16:17 +0100 | [diff] [blame] | 61 | void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, |
| 62 | DeviceState *dev, Error **errp); |
Igor Mammedov | 0058c08 | 2016-05-31 12:01:17 +0200 | [diff] [blame] | 63 | void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, |
Igor Mammedov | c24d5e0 | 2014-02-05 16:36:49 +0100 | [diff] [blame] | 64 | DeviceState *dev, Error **errp); |
Igor Mammedov | 0058c08 | 2016-05-31 12:01:17 +0200 | [diff] [blame] | 65 | void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, |
Igor Mammedov | c24d5e0 | 2014-02-05 16:36:49 +0100 | [diff] [blame] | 66 | DeviceState *dev, Error **errp); |
David Hildenbrand | c97adf3 | 2018-12-12 10:16:19 +0100 | [diff] [blame] | 67 | void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev, |
| 68 | AcpiPciHpState *s, DeviceState *dev, |
| 69 | Error **errp); |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 70 | |
| 71 | /* Called on reset */ |
Ani Sinha | 3d7e78a | 2020-08-21 22:24:03 +0530 | [diff] [blame] | 72 | void acpi_pcihp_reset(AcpiPciHpState *s, bool acpihp_root_off); |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 73 | |
| 74 | extern const VMStateDescription vmstate_acpi_pcihp_pci_status; |
| 75 | |
Igor Mammedov | b32bd76 | 2021-03-15 14:00:58 -0400 | [diff] [blame] | 76 | #define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp, test_acpi_index) \ |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 77 | VMSTATE_UINT32_TEST(pcihp.hotplug_select, state, \ |
| 78 | test_pcihp), \ |
| 79 | VMSTATE_STRUCT_ARRAY_TEST(pcihp.acpi_pcihp_pci_status, state, \ |
| 80 | ACPI_PCIHP_MAX_HOTPLUG_BUS, \ |
| 81 | test_pcihp, 1, \ |
| 82 | vmstate_acpi_pcihp_pci_status, \ |
Igor Mammedov | b32bd76 | 2021-03-15 14:00:58 -0400 | [diff] [blame] | 83 | AcpiPciHpPciStatus), \ |
| 84 | VMSTATE_UINT32_TEST(pcihp.acpi_index, state, \ |
| 85 | test_acpi_index) |
Michael S. Tsirkin | db4728e | 2013-10-14 18:01:11 +0300 | [diff] [blame] | 86 | |
| 87 | #endif |