[PATCH 11/15] ipmi: Add PCI IPMI interfaces

2019-09-19 Thread minyard
From: Corey Minyard 

Pretty straightforward, just hook the current KCS and BT code into
the PCI system with the proper configuration.

Cc: Michael S. Tsirkin 
Cc: M: Marcel Apfelbaum 
Signed-off-by: Corey Minyard 
---
 default-configs/i386-softmmu.mak |   2 +
 hw/i386/Kconfig  |   2 +
 hw/ipmi/Kconfig  |  10 +++
 hw/ipmi/Makefile.objs|   2 +
 hw/ipmi/pci_ipmi_bt.c| 146 +++
 hw/ipmi/pci_ipmi_kcs.c   | 146 +++
 include/hw/pci/pci.h |   1 +
 7 files changed, 309 insertions(+)
 create mode 100644 hw/ipmi/pci_ipmi_bt.c
 create mode 100644 hw/ipmi/pci_ipmi_kcs.c

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index ba3fb3ff50..2294c0be5a 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -10,6 +10,8 @@
 #CONFIG_ISA_DEBUG=n
 #CONFIG_ISA_IPMI_BT=n
 #CONFIG_ISA_IPMI_KCS=n
+#CONFIG_PCI_IPMI_KCS=n
+#CONFIG_PCI_IPMI_BT=n
 #CONFIG_PCI_DEVICES=n
 #CONFIG_PVPANIC=n
 #CONFIG_QXL=n
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index c7a9d6315c..d10f4e3e8b 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -8,6 +8,8 @@ config PC
 imply HYPERV
 imply ISA_IPMI_KCS
 imply ISA_IPMI_BT
+imply PCI_IPMI_KCS
+imply PCI_IPMI_BT
 imply ISA_DEBUG
 imply PARALLEL
 imply PCI_DEVICES
diff --git a/hw/ipmi/Kconfig b/hw/ipmi/Kconfig
index b944fae100..12db4e81ad 100644
--- a/hw/ipmi/Kconfig
+++ b/hw/ipmi/Kconfig
@@ -20,3 +20,13 @@ config ISA_IPMI_BT
 bool
 depends on ISA_BUS
 select IPMI
+
+config PCI_IPMI_KCS
+bool
+depends on PCI
+select IPMI
+
+config PCI_IPMI_BT
+bool
+depends on PCI
+select IPMI
diff --git a/hw/ipmi/Makefile.objs b/hw/ipmi/Makefile.objs
index 4ffa45a66c..2d7f080a86 100644
--- a/hw/ipmi/Makefile.objs
+++ b/hw/ipmi/Makefile.objs
@@ -2,4 +2,6 @@ common-obj-$(CONFIG_IPMI) += ipmi.o ipmi_kcs.o ipmi_bt.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_EXTERN) += ipmi_bmc_extern.o
 common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
+common-obj-$(CONFIG_PCI_IPMI_KCS) += pci_ipmi_kcs.o
 common-obj-$(CONFIG_ISA_IPMI_BT) += isa_ipmi_bt.o
+common-obj-$(CONFIG_PCI_IPMI_BT) += pci_ipmi_bt.o
diff --git a/hw/ipmi/pci_ipmi_bt.c b/hw/ipmi/pci_ipmi_bt.c
new file mode 100644
index 00..6ed925a665
--- /dev/null
+++ b/hw/ipmi/pci_ipmi_bt.c
@@ -0,0 +1,146 @@
+/*
+ * QEMU PCI IPMI BT emulation
+ *
+ * Copyright (c) 2017 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "migration/vmstate.h"
+#include "qapi/error.h"
+#include "hw/ipmi/ipmi_bt.h"
+#include "hw/pci/pci.h"
+
+#define TYPE_PCI_IPMI_BT "pci-ipmi-bt"
+#define PCI_IPMI_BT(obj) OBJECT_CHECK(PCIIPMIBTDevice, (obj), \
+   TYPE_PCI_IPMI_BT)
+
+typedef struct PCIIPMIBTDevice {
+PCIDevice dev;
+IPMIBT bt;
+bool irq_enabled;
+uint32_t uuid;
+} PCIIPMIBTDevice;
+
+static void pci_ipmi_raise_irq(IPMIBT *ik)
+{
+PCIIPMIBTDevice *pik = ik->opaque;
+
+pci_set_irq(>dev, true);
+}
+
+static void pci_ipmi_lower_irq(IPMIBT *ik)
+{
+PCIIPMIBTDevice *pik = ik->opaque;
+
+pci_set_irq(>dev, false);
+}
+
+static void pci_ipmi_bt_realize(PCIDevice *pd, Error **errp)
+{
+PCIIPMIBTDevice *pik = PCI_IPMI_BT(pd);
+IPMIInterface *ii = IPMI_INTERFACE(pd);
+IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
+
+if (!pik->bt.bmc) {
+error_setg(errp, "IPMI device requires a bmc attribute to be set");
+return;
+}
+
+pik->uuid = ipmi_next_uuid();
+
+pik->bt.bmc->intf = ii;
+pik->bt.opaque = pik;
+
+pci_config_set_prog_interface(pd->config, 0x02); /* BT */
+pci_config_set_interrupt_pin(pd->config, 0x01);
+pik->bt.use_irq = 1;
+pik->bt.raise_irq = pci_ipmi_raise_irq;
+

[Qemu-devel] [PATCH 11/15] ipmi: Add PCI IPMI interfaces

2019-08-19 Thread minyard
From: Corey Minyard 

Pretty straightforward, just hook the current KCS and BT code into
the PCI system with the proper configuration.

Cc: Michael S. Tsirkin 
Cc: M: Marcel Apfelbaum 
Signed-off-by: Corey Minyard 
---
 default-configs/i386-softmmu.mak |   2 +
 hw/i386/Kconfig  |   2 +
 hw/ipmi/Kconfig  |  10 +++
 hw/ipmi/Makefile.objs|   2 +
 hw/ipmi/pci_ipmi_bt.c| 146 +++
 hw/ipmi/pci_ipmi_kcs.c   | 146 +++
 include/hw/pci/pci.h |   1 +
 7 files changed, 309 insertions(+)
 create mode 100644 hw/ipmi/pci_ipmi_bt.c
 create mode 100644 hw/ipmi/pci_ipmi_kcs.c

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index cd5ea391e8..b819582d78 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -10,6 +10,8 @@
 #CONFIG_ISA_DEBUG=n
 #CONFIG_ISA_IPMI_BT=n
 #CONFIG_ISA_IPMI_KCS=n
+#CONFIG_PCI_IPMI_KCS=n
+#CONFIG_PCI_IPMI_BT=n
 #CONFIG_PCI_DEVICES=n
 #CONFIG_PVPANIC=n
 #CONFIG_QXL=n
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 6350438036..b4efaa0818 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -8,6 +8,8 @@ config PC
 imply HYPERV
 imply ISA_IPMI_KCS
 imply ISA_IPMI_BT
+imply PCI_IPMI_KCS
+imply PCI_IPMI_BT
 imply ISA_DEBUG
 imply PARALLEL
 imply PCI_DEVICES
diff --git a/hw/ipmi/Kconfig b/hw/ipmi/Kconfig
index b944fae100..12db4e81ad 100644
--- a/hw/ipmi/Kconfig
+++ b/hw/ipmi/Kconfig
@@ -20,3 +20,13 @@ config ISA_IPMI_BT
 bool
 depends on ISA_BUS
 select IPMI
+
+config PCI_IPMI_KCS
+bool
+depends on PCI
+select IPMI
+
+config PCI_IPMI_BT
+bool
+depends on PCI
+select IPMI
diff --git a/hw/ipmi/Makefile.objs b/hw/ipmi/Makefile.objs
index 4ffa45a66c..2d7f080a86 100644
--- a/hw/ipmi/Makefile.objs
+++ b/hw/ipmi/Makefile.objs
@@ -2,4 +2,6 @@ common-obj-$(CONFIG_IPMI) += ipmi.o ipmi_kcs.o ipmi_bt.o
 common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o
 common-obj-$(CONFIG_IPMI_EXTERN) += ipmi_bmc_extern.o
 common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o
+common-obj-$(CONFIG_PCI_IPMI_KCS) += pci_ipmi_kcs.o
 common-obj-$(CONFIG_ISA_IPMI_BT) += isa_ipmi_bt.o
+common-obj-$(CONFIG_PCI_IPMI_BT) += pci_ipmi_bt.o
diff --git a/hw/ipmi/pci_ipmi_bt.c b/hw/ipmi/pci_ipmi_bt.c
new file mode 100644
index 00..6ed925a665
--- /dev/null
+++ b/hw/ipmi/pci_ipmi_bt.c
@@ -0,0 +1,146 @@
+/*
+ * QEMU PCI IPMI BT emulation
+ *
+ * Copyright (c) 2017 Corey Minyard, MontaVista Software, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "migration/vmstate.h"
+#include "qapi/error.h"
+#include "hw/ipmi/ipmi_bt.h"
+#include "hw/pci/pci.h"
+
+#define TYPE_PCI_IPMI_BT "pci-ipmi-bt"
+#define PCI_IPMI_BT(obj) OBJECT_CHECK(PCIIPMIBTDevice, (obj), \
+   TYPE_PCI_IPMI_BT)
+
+typedef struct PCIIPMIBTDevice {
+PCIDevice dev;
+IPMIBT bt;
+bool irq_enabled;
+uint32_t uuid;
+} PCIIPMIBTDevice;
+
+static void pci_ipmi_raise_irq(IPMIBT *ik)
+{
+PCIIPMIBTDevice *pik = ik->opaque;
+
+pci_set_irq(>dev, true);
+}
+
+static void pci_ipmi_lower_irq(IPMIBT *ik)
+{
+PCIIPMIBTDevice *pik = ik->opaque;
+
+pci_set_irq(>dev, false);
+}
+
+static void pci_ipmi_bt_realize(PCIDevice *pd, Error **errp)
+{
+PCIIPMIBTDevice *pik = PCI_IPMI_BT(pd);
+IPMIInterface *ii = IPMI_INTERFACE(pd);
+IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
+
+if (!pik->bt.bmc) {
+error_setg(errp, "IPMI device requires a bmc attribute to be set");
+return;
+}
+
+pik->uuid = ipmi_next_uuid();
+
+pik->bt.bmc->intf = ii;
+pik->bt.opaque = pik;
+
+pci_config_set_prog_interface(pd->config, 0x02); /* BT */
+pci_config_set_interrupt_pin(pd->config, 0x01);
+pik->bt.use_irq = 1;
+pik->bt.raise_irq = pci_ipmi_raise_irq;
+