blob: 7e268c2c9c95bfed9badfd0eff7a2ad543a21c4f [file] [log] [blame]
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +03001/*
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 Pant61f3c912020-10-23 12:44:24 +000013 * License version 2.1 as published by the Free Software Foundation.
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030014 *
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 Mammedovc24d5e02014-02-05 16:36:49 +010030#include "hw/acpi/acpi.h"
Igor Mammedov0058c082016-05-31 12:01:17 +020031#include "hw/hotplug.h"
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030032
Igor Mammedov78c2d872015-02-18 19:14:49 +000033#define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"
34#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
35
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030036typedef struct AcpiPciHpPciStatus {
Michael S. Tsirkin5a2223c2014-01-26 12:31:27 +020037 uint32_t up;
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030038 uint32_t down;
39 uint32_t hotplug_enable;
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030040} AcpiPciHpPciStatus;
41
42#define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel"
43#define ACPI_PCIHP_MAX_HOTPLUG_BUS 256
Igor Mammedove358edc2014-02-03 11:45:01 +010044#define ACPI_PCIHP_BSEL_DEFAULT 0x0
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030045
46typedef struct AcpiPciHpState {
47 AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS];
48 uint32_t hotplug_select;
Igor Mammedovb32bd762021-03-15 14:00:58 -040049 uint32_t acpi_index;
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030050 PCIBus *root;
51 MemoryRegion io;
Igor Mammedov99d09dd2014-02-03 11:44:59 +010052 bool legacy_piix;
Igor Mammedov78c2d872015-02-18 19:14:49 +000053 uint16_t io_base;
54 uint16_t io_len;
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030055} AcpiPciHpState;
56
Igor Mammedov78c2d872015-02-18 19:14:49 +000057void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root,
Julia Suvorovacaf108b2021-07-13 02:42:00 +020058 MemoryRegion *address_space_io, bool bridges_enabled,
59 uint16_t io_base);
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030060
David Hildenbrandec266f42018-12-12 10:16:17 +010061void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
62 DeviceState *dev, Error **errp);
Igor Mammedov0058c082016-05-31 12:01:17 +020063void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
Igor Mammedovc24d5e02014-02-05 16:36:49 +010064 DeviceState *dev, Error **errp);
Igor Mammedov0058c082016-05-31 12:01:17 +020065void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
Igor Mammedovc24d5e02014-02-05 16:36:49 +010066 DeviceState *dev, Error **errp);
David Hildenbrandc97adf32018-12-12 10:16:19 +010067void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
68 AcpiPciHpState *s, DeviceState *dev,
69 Error **errp);
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030070
71/* Called on reset */
Ani Sinha3d7e78a2020-08-21 22:24:03 +053072void acpi_pcihp_reset(AcpiPciHpState *s, bool acpihp_root_off);
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030073
74extern const VMStateDescription vmstate_acpi_pcihp_pci_status;
75
Igor Mammedovb32bd762021-03-15 14:00:58 -040076#define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp, test_acpi_index) \
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030077 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 Mammedovb32bd762021-03-15 14:00:58 -040083 AcpiPciHpPciStatus), \
84 VMSTATE_UINT32_TEST(pcihp.acpi_index, state, \
85 test_acpi_index)
Michael S. Tsirkindb4728e2013-10-14 18:01:11 +030086
87#endif