[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/32] i2c: Fix SMBus read transactions to avoid doub
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 25/32] i2c: Fix SMBus read transactions to avoid double events |
Date: |
Mon, 24 Oct 2016 18:25:21 +0100 |
From: Corey Minyard <address@hidden>
Change 2293c27faddf (i2c: implement broadcast write) added broadcast
capability to the I2C bus, but it broke SMBus read transactions.
An SMBus read transaction does two i2c_start_transaction() calls
without an intervening i2c_end_transfer() call. This will
result in i2c_start_transfer() adding the same device to the
current_devs list twice, and then the ->event() for the same
device gets called twice in the second call to i2c_start_transfer(),
resulting in the smbus code getting confused.
Note that this happens even with pure I2C devices when simulating
SMBus over I2C.
This fix only scans the bus if the current set of devices is empty.
This means that the current set of devices stays fixed until
i2c_end_transfer() is called, which is really what you want.
This also deletes the empty check from the top of i2c_end_transfer().
It's unnecessary, and it prevents the broadcast variable from being
set to false at the end of the transaction if no devices were on
the bus.
Cc: KONRAD Frederic <address@hidden>
Cc: Alistair Francis <address@hidden>
Cc: Peter Crosthwaite <address@hidden>
Cc: Kwon <address@hidden>
Cc: Peter Maydell <address@hidden>
Signed-off-by: Corey Minyard <address@hidden>
Reviewed-by: KONRAD Frederic <address@hidden>
Tested-by: KONRAD Frederic <address@hidden>
Message-id: address@hidden
Signed-off-by: Peter Maydell <address@hidden>
---
hw/i2c/core.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 4afbe0b..bd8f167 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -104,15 +104,25 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int
recv)
bus->broadcast = true;
}
- QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
- DeviceState *qdev = kid->child;
- I2CSlave *candidate = I2C_SLAVE(qdev);
- if ((candidate->address == address) || (bus->broadcast)) {
- node = g_malloc(sizeof(struct I2CNode));
- node->elt = candidate;
- QLIST_INSERT_HEAD(&bus->current_devs, node, next);
- if (!bus->broadcast) {
- break;
+ /*
+ * If there are already devices in the list, that means we are in
+ * the middle of a transaction and we shouldn't rescan the bus.
+ *
+ * This happens with any SMBus transaction, even on a pure I2C
+ * device. The interface does a transaction start without
+ * terminating the previous transaction.
+ */
+ if (QLIST_EMPTY(&bus->current_devs)) {
+ QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+ DeviceState *qdev = kid->child;
+ I2CSlave *candidate = I2C_SLAVE(qdev);
+ if ((candidate->address == address) || (bus->broadcast)) {
+ node = g_malloc(sizeof(struct I2CNode));
+ node->elt = candidate;
+ QLIST_INSERT_HEAD(&bus->current_devs, node, next);
+ if (!bus->broadcast) {
+ break;
+ }
}
}
}
@@ -137,10 +147,6 @@ void i2c_end_transfer(I2CBus *bus)
I2CSlaveClass *sc;
I2CNode *node, *next;
- if (QLIST_EMPTY(&bus->current_devs)) {
- return;
- }
-
QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) {
sc = I2C_SLAVE_GET_CLASS(node->elt);
if (sc->event) {
--
2.7.4
- [Qemu-devel] [PULL 29/32] hw/arm: QOM'ify strongarm.c, (continued)
- [Qemu-devel] [PULL 29/32] hw/arm: QOM'ify strongarm.c, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 30/32] hw/display: QOM'ify pl110.c, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 16/32] hw/ptimer: Add "no counter round down" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 27/32] hw/arm: QOM'ify musicpal.c, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 24/32] timer: a9gtimer: remove loop to auto-increment comparator, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 12/32] hw/ptimer: Add "no immediate trigger" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 14/32] hw/ptimer: Add "no immediate reload" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 07/32] hw/arm/virt: Set minimum_page_bits to 12, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 11/32] tests: ptimer: Add tests for "continuous trigger" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 06/32] target-arm: Make page size a runtime setting, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 25/32] i2c: Fix SMBus read transactions to avoid double events,
Peter Maydell <=
- [Qemu-devel] [PULL 26/32] timer: stm32f2xx_timer: add check for prescaler value, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 31/32] target-arm: Implement new HLT trap for semihosting, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 18/32] tests: ptimer: Change the copyright comment, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 10/32] hw/ptimer: Add "continuous trigger" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 21/32] tests: Add tests for the ARM MPTimer, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 13/32] tests: ptimer: Add tests for "no immediate trigger" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 02/32] exec.c: Remove static allocation of sub_section of sub_page, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 28/32] hw/arm: QOM'ify pxa2xx_gpio.c, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 08/32] hw/ptimer: Add "wraparound after one period" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 05/32] migration/savevm.c: migrate non-default page size, Peter Maydell, 2016/10/24