From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Anthony Liguori <aliguori@amazon.com>,
Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PULL 18/20] pci/pcie: convert PCIE hotplug to use hotplug-handler API
Date: Mon, 10 Feb 2014 18:48:54 +0200 [thread overview]
Message-ID: <1392050814-31814-19-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1392050814-31814-1-git-send-email-mst@redhat.com>
From: Igor Mammedov <imammedo@redhat.com>
Split pcie_cap_slot_hotplug() into hotplug/unplug callbacks
and register them as "hotplug-handler" interface implementation of
PCIE_SLOT device.
Replace pci_bus_hotplug() wiring with setting link on PCI BUS
"hotplug-handler" property to PCI_BRIDGE_DEV device.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/pci/pcie.h | 5 ++++
hw/pci/pcie.c | 65 +++++++++++++++++++++++++++++++--------------------
hw/pci/pcie_port.c | 8 +++++++
3 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index 1966169..b0bf7e3 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -25,6 +25,7 @@
#include "hw/pci/pci_regs.h"
#include "hw/pci/pcie_regs.h"
#include "hw/pci/pcie_aer.h"
+#include "hw/hotplug.h"
typedef enum {
/* for attention and power indicator */
@@ -122,4 +123,8 @@ extern const VMStateDescription vmstate_pcie_device;
.offset = vmstate_offset_value(_state, _field, PCIDevice), \
}
+void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+ Error **errp);
+void pcie_cap_slot_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+ Error **errp);
#endif /* QEMU_PCIE_H */
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index ca60cf2..8ecd11e 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -26,6 +26,7 @@
#include "hw/pci/pci_bus.h"
#include "hw/pci/pcie_regs.h"
#include "qemu/range.h"
+#include "qapi/qmp/qerror.h"
//#define DEBUG_PCIE
#ifdef DEBUG_PCIE
@@ -216,28 +217,20 @@ static void pcie_cap_slot_event(PCIDevice *dev, PCIExpressHotPlugEvent event)
hotplug_event_notify(dev);
}
-static int pcie_cap_slot_hotplug(DeviceState *qdev,
- PCIDevice *pci_dev, PCIHotplugState state)
+static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,
+ DeviceState *dev,
+ uint8_t **exp_cap, Error **errp)
{
- PCIDevice *d = PCI_DEVICE(qdev);
- uint8_t *exp_cap = d->config + d->exp.exp_cap;
- uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
-
- /* Don't send event when device is enabled during qemu machine creation:
- * it is present on boot, no hotplug event is necessary. We do send an
- * event when the device is disabled later. */
- if (state == PCI_COLDPLUG_ENABLED) {
- pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
- PCI_EXP_SLTSTA_PDS);
- return 0;
- }
+ PCIDevice *pci_dev = PCI_DEVICE(dev);
+ *exp_cap = hotplug_dev->config + hotplug_dev->exp.exp_cap;
+ uint16_t sltsta = pci_get_word(*exp_cap + PCI_EXP_SLTSTA);
PCIE_DEV_PRINTF(pci_dev, "hotplug state: %d\n", state);
if (sltsta & PCI_EXP_SLTSTA_EIS) {
/* the slot is electromechanically locked.
* This error is propagated up to qdev and then to HMP/QMP.
*/
- return -EBUSY;
+ error_setg_errno(errp, -EBUSY, "slot is electromechanically locked");
}
/* TODO: multifunction hot-plug.
@@ -245,18 +238,40 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
* hot plugged/unplugged.
*/
assert(PCI_FUNC(pci_dev->devfn) == 0);
+}
- if (state == PCI_HOTPLUG_ENABLED) {
+void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+ Error **errp)
+{
+ uint8_t *exp_cap;
+
+ pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
+
+ /* Don't send event when device is enabled during qemu machine creation:
+ * it is present on boot, no hotplug event is necessary. We do send an
+ * event when the device is disabled later. */
+ if (!dev->hotplugged) {
pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
PCI_EXP_SLTSTA_PDS);
- pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
- } else {
- object_unparent(OBJECT(pci_dev));
- pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
- PCI_EXP_SLTSTA_PDS);
- pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
+ return;
}
- return 0;
+
+ pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
+ PCI_EXP_SLTSTA_PDS);
+ pcie_cap_slot_event(PCI_DEVICE(hotplug_dev), PCI_EXP_HP_EV_PDC);
+}
+
+void pcie_cap_slot_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+ Error **errp)
+{
+ uint8_t *exp_cap;
+
+ pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
+
+ object_unparent(OBJECT(dev));
+ pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
+ PCI_EXP_SLTSTA_PDS);
+ pcie_cap_slot_event(PCI_DEVICE(hotplug_dev), PCI_EXP_HP_EV_PDC);
}
/* pci express slot for pci express root/downstream port
@@ -305,8 +320,8 @@ void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot)
dev->exp.hpev_notified = false;
- pci_bus_hotplug(pci_bridge_get_sec_bus(PCI_BRIDGE(dev)),
- pcie_cap_slot_hotplug, &dev->qdev);
+ qbus_set_hotplug_handler(BUS(pci_bridge_get_sec_bus(PCI_BRIDGE(dev))),
+ DEVICE(dev), NULL);
}
void pcie_cap_slot_reset(PCIDevice *dev)
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 2adb030..fa24877 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -19,6 +19,7 @@
*/
#include "hw/pci/pcie_port.h"
+#include "hw/hotplug.h"
void pcie_port_init_reg(PCIDevice *d)
{
@@ -149,8 +150,11 @@ static Property pcie_slot_props[] = {
static void pcie_slot_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
dc->props = pcie_slot_props;
+ hc->plug = pcie_cap_slot_hotplug_cb;
+ hc->unplug = pcie_cap_slot_hot_unplug_cb;
}
static const TypeInfo pcie_slot_type_info = {
@@ -159,6 +163,10 @@ static const TypeInfo pcie_slot_type_info = {
.instance_size = sizeof(PCIESlot),
.abstract = true,
.class_init = pcie_slot_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ }
};
static void pcie_port_register_types(void)
--
MST
next prev parent reply other threads:[~2014-02-10 16:44 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-10 16:47 [Qemu-devel] [PULL 00/20] acpi,pc,pci fixes and enhancements Michael S. Tsirkin
2014-02-10 16:47 ` [Qemu-devel] [PULL 01/20] pcihp: reduce number of device check events Michael S. Tsirkin
2014-02-10 16:47 ` [Qemu-devel] [PULL 02/20] pcihp: replace enable|disable_device() with oneliners Michael S. Tsirkin
2014-02-10 16:47 ` [Qemu-devel] [PULL 03/20] pcihp: make PCI hotplug mmio handlers indifferent to PCI_HOTPLUG_ADDR Michael S. Tsirkin
2014-02-10 16:47 ` [Qemu-devel] [PULL 04/20] pcihp: make pci_read() mmio calback compatible with legacy ACPI hotplug Michael S. Tsirkin
2014-02-10 16:47 ` [Qemu-devel] [PULL 05/20] pcihp: remove unused AcpiPciHpPciStatus.device_present field Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 06/20] hw:piix4:acpi: reuse pcihp code for legacy PCI hotplug Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 07/20] qtest: don't report signals if qtest driver enabled Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 08/20] pc_piix: enable legacy hotplug for Xen Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 09/20] pc.c: better error message on initrd sizing failure Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 10/20] loader: document that errno is set Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 11/20] define hotplug interface Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 12/20] qdev: add to BusState "hotplug-handler" link Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 13/20] qdev: add "hotpluggable" property to Device Michael S. Tsirkin
2014-02-18 16:35 ` Andreas Färber
2014-02-18 16:55 ` Igor Mammedov
2014-03-07 17:56 ` Andreas Färber
2014-02-10 16:48 ` [Qemu-devel] [PULL 14/20] hw/acpi: move typeinfo to the file end Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 15/20] qdev:pci: refactor PCIDevice to use generic "hotpluggable" property Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 16/20] acpi/piix4pm: convert ACPI PCI hotplug to use hotplug-handler API Michael S. Tsirkin
2014-02-10 16:48 ` [Qemu-devel] [PULL 17/20] pci/shpc: convert SHPC " Michael S. Tsirkin
2014-02-10 16:48 ` Michael S. Tsirkin [this message]
2014-02-10 16:48 ` [Qemu-devel] [PULL 19/20] hw/pci: switch to a generic hotplug handling for PCIDevice Michael S. Tsirkin
2014-02-10 16:49 ` [Qemu-devel] [PULL 20/20] ACPI: Remove commented-out code from HPET._CRS Michael S. Tsirkin
2014-02-13 16:29 ` [Qemu-devel] [PULL 00/20] acpi,pc,pci fixes and enhancements Peter Maydell
2014-02-18 12:16 ` Stefano Stabellini
2014-02-18 12:27 ` Paolo Bonzini
2014-02-18 12:45 ` Stefano Stabellini
2014-02-18 13:08 ` Igor Mammedov
2014-02-18 14:27 ` Stefano Stabellini
2014-02-18 13:10 ` Paolo Bonzini
2014-02-18 14:25 ` Stefano Stabellini
2014-02-18 14:26 ` Paolo Bonzini
2014-02-18 17:10 ` Stefano Stabellini
2014-02-19 9:08 ` Michael S. Tsirkin
2014-02-19 9:29 ` Michael S. Tsirkin
2014-02-19 11:53 ` Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392050814-31814-19-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=aliguori@amazon.com \
--cc=imammedo@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).