[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 06/10] i2c:pm_smbus: Add interrupt handling
From: |
minyard |
Subject: |
[Qemu-devel] [PATCH v2 06/10] i2c:pm_smbus: Add interrupt handling |
Date: |
Mon, 20 Aug 2018 15:26:06 -0500 |
From: Corey Minyard <address@hidden>
Add the necessary code so that interrupts actually work from
the pm_smbus device.
Signed-off-by: Corey Minyard <address@hidden>
Cc: Michael S. Tsirkin <address@hidden>
Cc: Paolo Bonzini <address@hidden>
---
hw/i2c/pm_smbus.c | 14 +++++++++++++-
hw/i2c/smbus_ich9.c | 19 ++++++++++++++++++-
include/hw/i2c/pm_smbus.h | 2 ++
3 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c
index 9e11d47..664a6b1 100644
--- a/hw/i2c/pm_smbus.c
+++ b/hw/i2c/pm_smbus.c
@@ -214,6 +214,12 @@ static void smb_transaction_start(PMSMBus *s)
s->smb_stat |= STS_HOST_BUSY;
}
+static bool
+smb_irq_value(PMSMBus *s)
+{
+ return ((s->smb_stat & ~STS_HOST_BUSY) != 0) && (s->smb_ctl & CTL_INTREN);
+}
+
static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val,
unsigned width)
{
@@ -309,7 +315,9 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr,
uint64_t val,
}
out:
- return;
+ if (s->set_irq) {
+ s->set_irq(s, smb_irq_value(s));
+ }
}
static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width)
@@ -365,6 +373,10 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr
addr, unsigned width)
SMBUS_DPRINTF("SMB readb port=0x%04" HWADDR_PRIx " val=0x%02x\n",
addr, val);
+ if (s->set_irq) {
+ s->set_irq(s, smb_irq_value(s));
+ }
+
return val;
}
diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index c8b8413..316c2a4 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -40,15 +40,18 @@
typedef struct ICH9SMBState {
PCIDevice dev;
+ bool irq_enabled;
+
PMSMBus smb;
} ICH9SMBState;
static const VMStateDescription vmstate_ich9_smbus = {
.name = "ich9_smb",
- .version_id = 2,
+ .version_id = 3,
.minimum_version_id = 1,
.fields = (VMStateField[]) {
VMSTATE_PCI_DEVICE(dev, ICH9SMBState),
+ VMSTATE_BOOL_V(irq_enabled, ICH9SMBState, 3),
VMSTATE_STRUCT(smb, ICH9SMBState, 2, pmsmb_vmstate, PMSMBus),
VMSTATE_END_OF_LIST()
}
@@ -110,11 +113,25 @@ static void ich9_smb_class_init(ObjectClass *klass, void
*data)
dc->user_creatable = false;
}
+static void ich9_smb_set_irq(PMSMBus *pmsmb, bool enabled)
+{
+ ICH9SMBState *s = pmsmb->opaque;
+
+ if (enabled == s->irq_enabled) {
+ return;
+ }
+
+ s->irq_enabled = enabled;
+ pci_set_irq(&s->dev, enabled);
+}
+
I2CBus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
{
PCIDevice *d =
pci_create_simple_multifunction(bus, devfn, true,
TYPE_ICH9_SMB_DEVICE);
ICH9SMBState *s = ICH9_SMB_DEVICE(d);
+ s->smb.set_irq = ich9_smb_set_irq;
+ s->smb.opaque = s;
return s->smb.smbus;
}
diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h
index b1e1970..cfe596f 100644
--- a/include/hw/i2c/pm_smbus.h
+++ b/include/hw/i2c/pm_smbus.h
@@ -23,6 +23,8 @@ typedef struct PMSMBus {
/* Set by the user. */
bool i2c_enable;
+ void (*set_irq)(struct PMSMBus *s, bool enabled);
+ void *opaque;
/* Internally used by pm_smbus. */
--
2.7.4
- [Qemu-devel] [PATCH v2 04/10] i2c:pm_smbus: Add block transfer capability, (continued)
- [Qemu-devel] [PATCH v2 04/10] i2c:pm_smbus: Add block transfer capability, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 01/10] i2c:pm_smbus: Clean up some style issues, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 08/10] i2c:pm_smbus: Add the ability to force block transfer enable, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 09/10] i2c: Add an SMBus vmstate structure, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 05/10] i2c:pm_smbus: Fix state transfer, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 10/10] i2c: Add vmstate handling to the smbus eeprom, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 03/10] i2c:pm_smbus: Make the I2C block read command read-only, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 06/10] i2c:pm_smbus: Add interrupt handling,
minyard <=
- [Qemu-devel] [PATCH v2 07/10] Don't delay host status register busy bit when interrupts are enabled, minyard, 2018/08/20
- Re: [Qemu-devel] [PATCH v2 0/8] Make the pm_smbus code more correct, Paolo Bonzini, 2018/08/21