Skip to contentSkip to conversation

Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller

PATCH Superseded Peter A. G. Crosthwaite 3 participants 39 messages Aug 6, 2012 – Aug 11, 2012 Arm/Zynq architecture

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v5 cover Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller

This series reworks the SSI bus framework for SPI and add some new SPI controllers and devices:

Patches 1-5 reworks SSI to add chip-select support to SPI devices and allow for multiple SPI devices attach ed to the same bus.

Patches 6-7 fix the SPI setup in the stellaris machine model.

Patch 8 is a trivial cleanup I did along the way.

Patch 9 is a general FIFO helper API used by the upcomming patches.

Patch 10 is a device model for the m25p80 SPI flash family.

Patches 11 & 13 are the Xilinx SPI flash controller devices

Patches 12 & 14 add SPI controllers to the ML605 and Zynq machine models.

Patch 15 is Maintainerships.

CHANGELOG:
changed from v4 (Major changes):
Completely reworked SPI refactor. Please re-review from scratch.
Added Zynq SPI flash.
Factored out FIFO functionality from SPI flash controller.
changed from v3:
addressed reviewer comments from P Maydell and S Hajnoczi
added patch 5 (re Paul Brooks request)
changed from v2:
folded former SPI bus functionality into existing SSI infrastructure (suggested - Paul Brook) (all patches) made m25p80 use async io (suggested - Stefan Hajnoczi) (2/4)
instantiated two spi flashes instead of one in ml605 ref design (4/4)
changed from v1:
minor sylistic changes (1/4)
converted spi api to modified txrx style (1-3/4)
heavily refactored m25p80 model (2/4)

Peter A. G. Crosthwaite (15):
ssi: Support for multiple attached devices
ssi: Added VMSD stub
ssi: Implemented CS behaviour
ssi: Added create_slave_no_init()
qdev: allow multiple qdev_init_gpio_in() calls hw/stellaris: Removed gpio_out init array.
stellaris: Removed SSI mux
ssd0323: abort() instead of exit(1) on error.
hw: Added generic FIFO API.
m25p80: Initial implementation of SPI flash device
xilinx_spi: Initial impl. of Xilinx SPI controller
petalogix-ml605: added SPI controller with n25q128
xilinx_spips: Xilinx Zynq SPI cntrlr device model
xilinx_zynq: Added SPI controllers + flashes
MAINTAINERS: Added maintainerships for SSI

 MAINTAINERS                              |    8 +
 default-configs/arm-softmmu.mak          |    1 +
 default-configs/microblaze-softmmu.mak   |    2 +
 default-configs/microblazeel-softmmu.mak |    2 +
 hw/Makefile.objs                         |    2 +
 hw/ads7846.c                             |    1 +
 hw/arm/Makefile.objs                     |    1 +
 hw/fifo.c                                |   79 ++++
 hw/fifo.h                                |   47 +++
 hw/m25p80.c                              |  572 ++++++++++++++++++++++++++++++
 hw/max111x.c                             |    1 +
 hw/microblaze/Makefile.objs              |    1 +
 hw/petalogix_ml605_mmu.c                 |   28 ++-
 hw/qdev.c                                |   16 +-
 hw/spitz.c                               |    2 +
 hw/ssd0323.c                             |   11 +-
 hw/ssi-sd.c                              |    7 +
 hw/ssi.c                                 |   76 ++++-
 hw/ssi.h                                 |   38 ++
 hw/stellaris.c                           |  111 ++-----
 hw/xilinx_spi.c                          |  390 ++++++++++++++++++++
 hw/xilinx_spips.c                        |  352 ++++++++++++++++++
 hw/xilinx_zynq.c                         |   34 ++
 hw/z2.c                                  |    1 +
 24 files changed, 1675 insertions(+), 108 deletions(-)
 create mode 100644 hw/fifo.c
 create mode 100644 hw/fifo.h
 create mode 100644 hw/m25p80.c
 create mode 100644 hw/xilinx_spi.c
 create mode 100644 hw/xilinx_spips.c
#1 lore raw

PATCH v5 1/15 ssi: Support for multiple attached devices

Removed assertion that only one device is attached to the SSI bus.

When multiple devices are attached, all slaves have their transfer function called for transfers. Each device is responsible for knowing whether or not its CS is active, and if not returning 0. The returned data is the logical or of all responses from the (mulitple) devices.

---
 hw/ssi.c |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)
hw/ssi.c +9 -15
index e5f14a0..35d0a04 100644
@@ -2,6 +2,8 @@
  * QEMU Synchronous Serial Interface support
  *
  * Copyright (c) 2009 CodeSourcery.
+ * Copyright (c) 2012 Peter A.G. Crosthwaite ([email protected])
+ * Copyright (c) 2012 PetaLogix Pty Ltd.
  * Written by Paul Brook
  *
  * This code is licensed under the GNU GPL v2.
@@ -29,14 +31,6 @@ static int ssi_slave_init(DeviceState *dev)
 {
     SSISlave *s = SSI_SLAVE(dev);
     SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
-    SSIBus *bus;
-    BusChild *kid;
-
-    bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
-    kid = QTAILQ_FIRST(&bus->qbus.children);
-    if (kid->child != dev || QTAILQ_NEXT(kid, sibling) != NULL) {
-        hw_error("Too many devices on SSI bus");
-    }
 
     return ssc->init(s);
 }
@@ -74,16 +68,16 @@ SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
 uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
 {
     BusChild *kid;
-    SSISlave *slave;
     SSISlaveClass *ssc;
+    uint32_t r = 0;
 
-    kid = QTAILQ_FIRST(&bus->qbus.children);
-    if (!kid) {
-        return 0;
+    QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+        SSISlave *slave = SSI_SLAVE(kid->child);
+        ssc = SSI_SLAVE_GET_CLASS(slave);
+        r |= ssc->transfer(slave, val);
     }
-    slave = SSI_SLAVE(kid->child);
-    ssc = SSI_SLAVE_GET_CLASS(slave);
-    return ssc->transfer(slave, val);
+
+    return r;
 }
 
 static void ssi_slave_register_types(void)
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v5 2/15 ssi: Added VMSD stub

In reply to Peter A. G. Crosthwaite

Added VMSD stub for SSI slaves. Fields may be added to this VMSD for generic SSI slave state (e.g. the CS line state).

---
 hw/ads7846.c   |    1 +
 hw/max111x.c   |    1 +
 hw/spitz.c     |    2 ++
 hw/ssi.c       |   10 ++++++++++
 hw/ssi.h       |   10 ++++++++++
 hw/stellaris.c |    1 +
 hw/z2.c        |    1 +
 7 files changed, 26 insertions(+), 0 deletions(-)
hw/ads7846.c +1 -0
index 41c7f10..6a523f6 100644
@@ -124,6 +124,7 @@ static const VMStateDescription vmstate_ads7846 = {
     .minimum_version_id_old = 0,
     .post_load = ads7856_post_load,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ADS7846State),
         VMSTATE_INT32_ARRAY(input, ADS7846State, 8),
         VMSTATE_INT32(noise, ADS7846State),
         VMSTATE_INT32(cycle, ADS7846State),
hw/max111x.c +1 -0
index 706d89f..948fd97 100644
@@ -103,6 +103,7 @@ static const VMStateDescription vmstate_max111x = {
     .minimum_version_id = 0,
     .minimum_version_id_old = 0,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, MAX111xState),
         VMSTATE_UINT8(tb1, MAX111xState),
         VMSTATE_UINT8(rb2, MAX111xState),
         VMSTATE_UINT8(rb3, MAX111xState),
hw/spitz.c +2 -0
index 20e7835..f5d502d 100644
@@ -1087,6 +1087,7 @@ static const VMStateDescription vmstate_corgi_ssp_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, CorgiSSPState),
         VMSTATE_UINT32_ARRAY(enable, CorgiSSPState, 3),
         VMSTATE_END_OF_LIST(),
     }
@@ -1115,6 +1116,7 @@ static const VMStateDescription vmstate_spitz_lcdtg_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, SpitzLCDTG),
         VMSTATE_UINT32(bl_intensity, SpitzLCDTG),
         VMSTATE_UINT32(bl_power, SpitzLCDTG),
         VMSTATE_END_OF_LIST(),
hw/ssi.c +10 -0
index 35d0a04..2db88fc 100644
@@ -80,6 +80,16 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
     return r;
 }
 
+const VMStateDescription vmstate_ssi_slave = {
+    .name = "SSISlave",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void ssi_slave_register_types(void)
 {
     type_register_static(&ssi_bus_info);
hw/ssi.h +10 -0
index 06657d7..975f9fb 100644
@@ -38,6 +38,16 @@ struct SSISlave {
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
+extern const VMStateDescription vmstate_ssi_slave;
+
+#define VMSTATE_SSI_SLAVE(_field, _state) {                          \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(SSISlave),                                  \
+    .vmsd       = &vmstate_ssi_slave,                                \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, SSISlave),    \
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
 
 /* Master interface.  */
hw/stellaris.c +1 -0
index 562fbbf..4d26857 100644
@@ -1188,6 +1188,7 @@ static const VMStateDescription vmstate_stellaris_ssi_bus = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, stellaris_ssi_bus_state),
         VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
hw/z2.c +1 -0
index 289cee9..721aaf1 100644
@@ -165,6 +165,7 @@ static VMStateDescription vmstate_zipit_lcd_state = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ZipitLCD),
         VMSTATE_INT32(selected, ZipitLCD),
         VMSTATE_INT32(enabled, ZipitLCD),
         VMSTATE_BUFFER(buf, ZipitLCD),
Signature · 1 line
1.7.0.4
#3 lore raw

Re: [Qemu-devel] [PATCH v5 02/15] ssi: Added VMSD stub

Quoted 2 lines · Peter A. G. Crosthwaite

Added VMSD stub for SSI slaves. Fields may be added to this VMSD for generic SSI slave state (e.g. the CS line state).

This is more me being confused about how this should work than a review comment, but it seems a bit odd that we have a hierarchy Device->SSI->ADS7846[etc], where the VMState for the ADS7846 includes a field for the SSI VMState, but the SSI VMState doesn't include a field for the Device VMState.

What you've done here matches how i2c works currently, but I've just cc'd Anthony and Juan to check whether there's a better way of doing it.

Quoted 122 lines
---
 hw/ads7846.c   |    1 +
 hw/max111x.c   |    1 +
 hw/spitz.c     |    2 ++
 hw/ssi.c       |   10 ++++++++++
 hw/ssi.h       |   10 ++++++++++
 hw/stellaris.c |    1 +
 hw/z2.c        |    1 +
 7 files changed, 26 insertions(+), 0 deletions(-)
hw/ads7846.c +1 -0
index 41c7f10..6a523f6 100644
@@ -124,6 +124,7 @@ static const VMStateDescription vmstate_ads7846 = {
     .minimum_version_id_old = 0,
     .post_load = ads7856_post_load,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ADS7846State),
         VMSTATE_INT32_ARRAY(input, ADS7846State, 8),
         VMSTATE_INT32(noise, ADS7846State),
         VMSTATE_INT32(cycle, ADS7846State),
hw/max111x.c +1 -0
index 706d89f..948fd97 100644
@@ -103,6 +103,7 @@ static const VMStateDescription vmstate_max111x = {
     .minimum_version_id = 0,
     .minimum_version_id_old = 0,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, MAX111xState),
         VMSTATE_UINT8(tb1, MAX111xState),
         VMSTATE_UINT8(rb2, MAX111xState),
         VMSTATE_UINT8(rb3, MAX111xState),
hw/spitz.c +2 -0
index 20e7835..f5d502d 100644
@@ -1087,6 +1087,7 @@ static const VMStateDescription vmstate_corgi_ssp_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, CorgiSSPState),
         VMSTATE_UINT32_ARRAY(enable, CorgiSSPState, 3),
         VMSTATE_END_OF_LIST(),
     }
@@ -1115,6 +1116,7 @@ static const VMStateDescription vmstate_spitz_lcdtg_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, SpitzLCDTG),
         VMSTATE_UINT32(bl_intensity, SpitzLCDTG),
         VMSTATE_UINT32(bl_power, SpitzLCDTG),
         VMSTATE_END_OF_LIST(),
hw/ssi.c +10 -0
index 35d0a04..2db88fc 100644
@@ -80,6 +80,16 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
     return r;
 }
 
+const VMStateDescription vmstate_ssi_slave = {
+    .name = "SSISlave",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void ssi_slave_register_types(void)
 {
     type_register_static(&ssi_bus_info);
hw/ssi.h +10 -0
index 06657d7..975f9fb 100644
@@ -38,6 +38,16 @@ struct SSISlave {
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
+extern const VMStateDescription vmstate_ssi_slave;
+
+#define VMSTATE_SSI_SLAVE(_field, _state) {                          \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(SSISlave),                                  \
+    .vmsd       = &vmstate_ssi_slave,                                \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, SSISlave),    \
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
 
 /* Master interface.  */
hw/stellaris.c +1 -0
index 562fbbf..4d26857 100644
@@ -1188,6 +1188,7 @@ static const VMStateDescription vmstate_stellaris_ssi_bus = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, stellaris_ssi_bus_state),
         VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
hw/z2.c +1 -1
index 289cee9..721aaf1 100644
@@ -165,6 +165,7 @@ static VMStateDescription vmstate_zipit_lcd_state = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ZipitLCD),
         VMSTATE_INT32(selected, ZipitLCD),
         VMSTATE_INT32(enabled, ZipitLCD),
         VMSTATE_BUFFER(buf, ZipitLCD),
--
Quoted 2 lines

1.7.0.4

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v5 02/15] ssi: Added VMSD stub

Quoted 11 lines · Peter Maydell
Quoted 2 lines · Peter A. G. Crosthwaite

Added VMSD stub for SSI slaves. Fields may be added to this VMSD for generic SSI slave state (e.g. the CS line state).

This is more me being confused about how this should work than a review comment, but it seems a bit odd that we have a hierarchy Device->SSI->ADS7846[etc], where the VMState for the ADS7846 includes a field for the SSI VMState, but the SSI VMState doesn't include a field for the Device VMState.

Quoted 3 lines

What you've done here matches how i2c works currently, but I've just cc'd Anthony and Juan to check whether there's a better way of doing it.

Oh, and just to mention the obvious, if we add fields to these vmstates we need to bump the version numbers.

-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH v5 02/15] ssi: Added VMSD stub

In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 2 lines · Peter A. G. Crosthwaite

Added VMSD stub for SSI slaves. Fields may be added to this VMSD for generic SSI slave state (e.g. the CS line state).

This is more me being confused about how this should work than a review comment, but it seems a bit odd that we have a hierarchy Device->SSI->ADS7846[etc], where the VMState for the ADS7846 includes a field for the SSI VMState, but the SSI VMState doesn't include a field for the Device VMState.

Quoted 4 lines

What you've done here matches how i2c works currently, but I've just cc'd Anthony and Juan to check whether there's a better way of doing it.

So VMSD is handled by casting to TYPE_DEVICE and populating dc->vmsd. This is only going to work for one layer of heirachy. But, I notice a few device models here and there just call vmstate_register() directly. Question is, can we call vmstate_register() from the object init function for SSI_SLAVE, seperately? This would mean that a single TYPE_DEVICE object is going to get two vmsds instead of one. The original, and one for SSI_SLAVE (which has the cs state). Sound legit? Any implementation details and pitfalls to be aware of?

Would be nice to get rid of this change pattern applied to all the existing SSI devices.

Regards,
Peter

Quoted 128 lines
Quoted 123 lines
---
 hw/ads7846.c   |    1 +
 hw/max111x.c   |    1 +
 hw/spitz.c     |    2 ++
 hw/ssi.c       |   10 ++++++++++
 hw/ssi.h       |   10 ++++++++++
 hw/stellaris.c |    1 +
 hw/z2.c        |    1 +
 7 files changed, 26 insertions(+), 0 deletions(-)
hw/ads7846.c +1 -0
index 41c7f10..6a523f6 100644
@@ -124,6 +124,7 @@ static const VMStateDescription vmstate_ads7846 = {
     .minimum_version_id_old = 0,
     .post_load = ads7856_post_load,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ADS7846State),
         VMSTATE_INT32_ARRAY(input, ADS7846State, 8),
         VMSTATE_INT32(noise, ADS7846State),
         VMSTATE_INT32(cycle, ADS7846State),
hw/max111x.c +1 -0
index 706d89f..948fd97 100644
@@ -103,6 +103,7 @@ static const VMStateDescription vmstate_max111x = {
     .minimum_version_id = 0,
     .minimum_version_id_old = 0,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, MAX111xState),
         VMSTATE_UINT8(tb1, MAX111xState),
         VMSTATE_UINT8(rb2, MAX111xState),
         VMSTATE_UINT8(rb3, MAX111xState),
hw/spitz.c +2 -0
index 20e7835..f5d502d 100644
@@ -1087,6 +1087,7 @@ static const VMStateDescription vmstate_corgi_ssp_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, CorgiSSPState),
         VMSTATE_UINT32_ARRAY(enable, CorgiSSPState, 3),
         VMSTATE_END_OF_LIST(),
     }
@@ -1115,6 +1116,7 @@ static const VMStateDescription vmstate_spitz_lcdtg_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, SpitzLCDTG),
         VMSTATE_UINT32(bl_intensity, SpitzLCDTG),
         VMSTATE_UINT32(bl_power, SpitzLCDTG),
         VMSTATE_END_OF_LIST(),
hw/ssi.c +10 -0
index 35d0a04..2db88fc 100644
@@ -80,6 +80,16 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
     return r;
 }
 
+const VMStateDescription vmstate_ssi_slave = {
+    .name = "SSISlave",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void ssi_slave_register_types(void)
 {
     type_register_static(&ssi_bus_info);
hw/ssi.h +10 -0
index 06657d7..975f9fb 100644
@@ -38,6 +38,16 @@ struct SSISlave {
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
+extern const VMStateDescription vmstate_ssi_slave;
+
+#define VMSTATE_SSI_SLAVE(_field, _state) {                          \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(SSISlave),                                  \
+    .vmsd       = &vmstate_ssi_slave,                                \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, SSISlave),    \
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
 
 /* Master interface.  */
hw/stellaris.c +1 -0
index 562fbbf..4d26857 100644
@@ -1188,6 +1188,7 @@ static const VMStateDescription vmstate_stellaris_ssi_bus = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, stellaris_ssi_bus_state),
         VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
hw/z2.c +1 -1
index 289cee9..721aaf1 100644
@@ -165,6 +165,7 @@ static VMStateDescription vmstate_zipit_lcd_state = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ZipitLCD),
         VMSTATE_INT32(selected, ZipitLCD),
         VMSTATE_INT32(enabled, ZipitLCD),
         VMSTATE_BUFFER(buf, ZipitLCD),
--
Quoted 2 lines

1.7.0.4

-- PMM

#6 lore raw

PATCH v5 3/15 ssi: Implemented CS behaviour

In reply to Peter A. G. Crosthwaite

Added default CS behaviour for SSI slaves. SSI devices can set a property to enable CS behaviour which will create a GPIO on the device which is the CS. Tristating of the bus on SSI transfers is implemented.

---
 hw/ssd0323.c |    6 ++++++
 hw/ssi-sd.c  |    6 ++++++
 hw/ssi.c     |   39 ++++++++++++++++++++++++++++++++++++++-
 hw/ssi.h     |   27 +++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletions(-)
hw/ssd0323.c +6 -0
index b0b2e94..db16d20 100644
@@ -277,6 +277,7 @@ static void ssd0323_cd(void *opaque, int n, int level)
 
 static void ssd0323_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
@@ -294,10 +295,13 @@ static void ssd0323_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->remap);
     qemu_put_be32(f, s->mode);
     qemu_put_buffer(f, s->framebuffer, sizeof(s->framebuffer));
+
+    qemu_put_be32(f, ss->cs ? 1 : 0);
 }
 
 static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
@@ -319,6 +323,8 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
     s->mode = qemu_get_be32(f);
     qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
 
+    ss->cs = !!qemu_get_be32(f);
+
     return 0;
 }
 
hw/ssi-sd.c +6 -0
index b519bdb..6fd9ab9 100644
@@ -197,6 +197,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
 
 static void ssi_sd_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -209,10 +210,13 @@ static void ssi_sd_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->arglen);
     qemu_put_be32(f, s->response_pos);
     qemu_put_be32(f, s->stopping);
+
+    qemu_put_be32(f, ss->cs ? 1 : 0);
 }
 
 static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -229,6 +233,8 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
     s->response_pos = qemu_get_be32(f);
     s->stopping = qemu_get_be32(f);
 
+    ss->cs = !!qemu_get_be32(f);
+
     return 0;
 }
 
hw/ssi.c +38 -1
index 2db88fc..2e4f2fe 100644
@@ -27,19 +27,55 @@ static const TypeInfo ssi_bus_info = {
     .instance_size = sizeof(SSIBus),
 };
 
+static void ssi_cs_default(void *opaque, int n, int level)
+{
+    SSISlave *s = SSI_SLAVE(opaque);
+    bool cs = !!level;
+    assert(n == 0);
+    if (s->cs != cs) {
+        SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
+        if (ssc->set_cs) {
+            ssc->set_cs(s, cs);
+        }
+    }
+    s->cs = cs;
+}
+
+static uint32_t ssi_transfer_raw_default(SSISlave *dev, uint32_t val)
+{
+    SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(dev);
+
+    if ((dev->cs && ssc->cs_polarity == SSI_CS_HIGH) ||
+            (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) ||
+            ssc->cs_polarity == SSI_CS_NONE) {
+        return ssc->transfer(dev, val);
+    }
+    return 0;
+}
+
 static int ssi_slave_init(DeviceState *dev)
 {
     SSISlave *s = SSI_SLAVE(dev);
     SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
 
+    if (ssc->transfer_raw == ssi_transfer_raw_default &&
+            ssc->cs_polarity != SSI_CS_NONE) {
+        qdev_init_gpio_in(&s->qdev, ssi_cs_default, 1);
+    }
+
     return ssc->init(s);
 }
 
 static void ssi_slave_class_init(ObjectClass *klass, void *data)
 {
+    SSISlaveClass *ssc = SSI_SLAVE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+
     dc->init = ssi_slave_init;
     dc->bus_type = TYPE_SSI_BUS;
+    if (!ssc->transfer_raw) {
+        ssc->transfer_raw = ssi_transfer_raw_default;
+    }
 }
 
 static TypeInfo ssi_slave_info = {
@@ -74,7 +110,7 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
     QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
         SSISlave *slave = SSI_SLAVE(kid->child);
         ssc = SSI_SLAVE_GET_CLASS(slave);
-        r |= ssc->transfer(slave, val);
+        r |= ssc->transfer_raw(slave, val);
     }
 
     return r;
@@ -86,6 +122,7 @@ const VMStateDescription vmstate_ssi_slave = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(cs, SSISlave),
         VMSTATE_END_OF_LIST()
     }
 };
hw/ssi.h +27 -0
index 975f9fb..5b69a3b 100644
@@ -23,16 +23,43 @@ typedef struct SSISlave SSISlave;
 #define SSI_SLAVE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
 
+typedef enum {
+    SSI_CS_NONE = 0,
+    SSI_CS_LOW,
+    SSI_CS_HIGH,
+} SSICSMode;
+
 /* Slave devices.  */
 typedef struct SSISlaveClass {
     DeviceClass parent_class;
 
     int (*init)(SSISlave *dev);
+
+    /* if you have standard or no CS behaviour, just override transfer.
+     * This is called when the device cs is active (true by default).
+     */
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
+    /* called when the CS line changes. Optional, devices only need to implement
+     * this if they have side effects assoicated with the cs line (beyond
+     * tristating the txrx lines).
+     */
+    int (*set_cs)(SSISlave *dev, bool select);
+    /* define whether or not CS exists and is active low/high */
+    SSICSMode cs_polarity;
+
+    /* if you have non-standard CS behvaiour override this to take control
+     * of the CS behvaiour at the device level. transfer, set_cs, and
+     * cs_polarity are unused if this is overwritten. Transfer_raw, will
+     * always be called for the device for every txrx access the to parent bus
+     */
+    uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val);
 } SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
+
+    /* Chip select state */
+    bool cs;
 };
 
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
Signature · 1 line
1.7.0.4
#7 lore raw

Re: [Qemu-devel] [PATCH v5 03/15] ssi: Implemented CS behaviour

Quoted 25 lines · Peter A. G. Crosthwaite

Added default CS behaviour for SSI slaves. SSI devices can set a property to enable CS behaviour which will create a GPIO on the device which is the CS. Tristating of the bus on SSI transfers is implemented.

---
 hw/ssd0323.c |    6 ++++++
 hw/ssi-sd.c  |    6 ++++++
 hw/ssi.c     |   39 ++++++++++++++++++++++++++++++++++++++-
 hw/ssi.h     |   27 +++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletions(-)
hw/ssd0323.c +1 -0
index b0b2e94..db16d20 100644
@@ -277,6 +277,7 @@ static void ssd0323_cd(void *opaque, int n, int level)
 
 static void ssd0323_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 

hw/ssd0323.c static void ssd0323_save(QEMUFile *f, void *opaque) · line 299

Quoted 5 lines
hw/ssd0323.c +2 -0
@@ -294,10 +295,13 @@ static void ssd0323_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->remap);
     qemu_put_be32(f, s->mode);
     qemu_put_buffer(f, s->framebuffer, sizeof(s->framebuffer));
+
+    qemu_put_be32(f, ss->cs ? 1 : 0);

You don't need this ?: -- the standard bool-to-integer casting rules will do it for you. Also, stray blank line, and you're changing save/load format so you need to update a version number somewhere.

hw/ssd0323.c static int ssd0323_load(QEMUFile *f, void *opaque, int version_id) · line 326

Quoted 13 lines
hw/ssd0323.c +2 -0
 }
 
 static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
@@ -319,6 +323,8 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
     s->mode = qemu_get_be32(f);
     qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
 
+    ss->cs = !!qemu_get_be32(f);

!! unnecessary here.

Same comments as here and the one above apply to the other devices below.

Quoted 109 lines
hw/ssd0323.c +1 -0
+
     return 0;
 }
 
hw/ssi-sd.c +6 -0
index b519bdb..6fd9ab9 100644
@@ -197,6 +197,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
 
 static void ssi_sd_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -209,10 +210,13 @@ static void ssi_sd_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->arglen);
     qemu_put_be32(f, s->response_pos);
     qemu_put_be32(f, s->stopping);
+
+    qemu_put_be32(f, ss->cs ? 1 : 0);
 }
 
 static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -229,6 +233,8 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
     s->response_pos = qemu_get_be32(f);
     s->stopping = qemu_get_be32(f);
 
+    ss->cs = !!qemu_get_be32(f);
+
     return 0;
 }
 
hw/ssi.c +37 -1
index 2db88fc..2e4f2fe 100644
@@ -27,19 +27,55 @@ static const TypeInfo ssi_bus_info = {
     .instance_size = sizeof(SSIBus),
 };
 
+static void ssi_cs_default(void *opaque, int n, int level)
+{
+    SSISlave *s = SSI_SLAVE(opaque);
+    bool cs = !!level;
+    assert(n == 0);
+    if (s->cs != cs) {
+        SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
+        if (ssc->set_cs) {
+            ssc->set_cs(s, cs);
+        }
+    }
+    s->cs = cs;
+}
+
+static uint32_t ssi_transfer_raw_default(SSISlave *dev, uint32_t val)
+{
+    SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(dev);
+
+    if ((dev->cs && ssc->cs_polarity == SSI_CS_HIGH) ||
+            (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) ||
+            ssc->cs_polarity == SSI_CS_NONE) {
+        return ssc->transfer(dev, val);
+    }
+    return 0;
+}
+
 static int ssi_slave_init(DeviceState *dev)
 {
     SSISlave *s = SSI_SLAVE(dev);
     SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
 
+    if (ssc->transfer_raw == ssi_transfer_raw_default &&
+            ssc->cs_polarity != SSI_CS_NONE) {
+        qdev_init_gpio_in(&s->qdev, ssi_cs_default, 1);
+    }
+
     return ssc->init(s);
 }
 
 static void ssi_slave_class_init(ObjectClass *klass, void *data)
 {
+    SSISlaveClass *ssc = SSI_SLAVE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+
     dc->init = ssi_slave_init;
     dc->bus_type = TYPE_SSI_BUS;
+    if (!ssc->transfer_raw) {
+        ssc->transfer_raw = ssi_transfer_raw_default;
+    }
 }
 
 static TypeInfo ssi_slave_info = {
@@ -74,7 +110,7 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
     QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
         SSISlave *slave = SSI_SLAVE(kid->child);
         ssc = SSI_SLAVE_GET_CLASS(slave);
-        r |= ssc->transfer(slave, val);
+        r |= ssc->transfer_raw(slave, val);
     }
 
     return r;

hw/ssi.c const VMStateDescription vmstate_ssi_slave = { · line 125

Quoted 4 lines
hw/ssi.c +1 -0
@@ -86,6 +122,7 @@ const VMStateDescription vmstate_ssi_slave = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(cs, SSISlave),

New field -> must bump version. You could probably avoid this by rearranging things so this field is in the vmstate from the start rather than added in a subsequent patch.

Quoted 19 lines
hw/ssi.c +0 -0
         VMSTATE_END_OF_LIST()
     }
 };
hw/ssi.h +6 -0
index 975f9fb..5b69a3b 100644
@@ -23,16 +23,43 @@ typedef struct SSISlave SSISlave;
 #define SSI_SLAVE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
 
+typedef enum {
+    SSI_CS_NONE = 0,
+    SSI_CS_LOW,
+    SSI_CS_HIGH,
+} SSICSMode;
+
 /* Slave devices.  */
 typedef struct SSISlaveClass {

hw/ssi.h typedef struct SSISlave SSISlave; · line 43

Quoted 10 lines
hw/ssi.h +6 -0
     DeviceClass parent_class;
 
     int (*init)(SSISlave *dev);
+
+    /* if you have standard or no CS behaviour, just override transfer.
+     * This is called when the device cs is active (true by default).
+     */
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
+    /* called when the CS line changes. Optional, devices only need to implement
+     * this if they have side effects assoicated with the cs line (beyond

"associated"

hw/ssi.h typedef struct SSISlave SSISlave; · line 50

Quoted 7 lines
hw/ssi.h +7 -0
+     * tristating the txrx lines).
+     */
+    int (*set_cs)(SSISlave *dev, bool select);
+    /* define whether or not CS exists and is active low/high */
+    SSICSMode cs_polarity;
+
+    /* if you have non-standard CS behvaiour override this to take control

"behaviour" (and below)

hw/ssi.h typedef struct SSISlave SSISlave; · line 52

Quoted 2 lines
hw/ssi.h +2 -0
+     * of the CS behvaiour at the device level. transfer, set_cs, and
+     * cs_polarity are unused if this is overwritten. Transfer_raw, will

spurious comma

hw/ssi.h typedef struct SSISlave SSISlave; · line 53

Quoted 1 line
hw/ssi.h +1 -0
+     * always be called for the device for every txrx access the to parent bus

"to the"

Quoted 13 lines
hw/ssi.h +5 -1
+     */
+    uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val);
 } SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
+
+    /* Chip select state */
+    bool cs;
 };
 
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
--
Quoted 2 lines

1.7.0.4

-- PMM

#8 lore raw

Re: [Qemu-devel] [PATCH v5 03/15] ssi: Implemented CS behaviour

Quoted 26 lines · Peter Maydell
Quoted 24 lines · Peter A. G. Crosthwaite

Added default CS behaviour for SSI slaves. SSI devices can set a property to enable CS behaviour which will create a GPIO on the device which is the CS. Tristating of the bus on SSI transfers is implemented.

---
 hw/ssd0323.c |    6 ++++++
 hw/ssi-sd.c  |    6 ++++++
 hw/ssi.c     |   39 ++++++++++++++++++++++++++++++++++++++-
 hw/ssi.h     |   27 +++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletions(-)
hw/ssd0323.c +1 -0
index b0b2e94..db16d20 100644
@@ -277,6 +277,7 @@ static void ssd0323_cd(void *opaque, int n, int level)
 
 static void ssd0323_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
Quoted 12 lines

hw/ssd0323.c static void ssd0323_save(QEMUFile *f, void *opaque) · line 299

Quoted 6 lines
hw/ssd0323.c +2 -0
@@ -294,10 +295,13 @@ static void ssd0323_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->remap);
     qemu_put_be32(f, s->mode);
     qemu_put_buffer(f, s->framebuffer, sizeof(s->framebuffer));
+
+    qemu_put_be32(f, ss->cs ? 1 : 0);

You don't need this ?: -- the standard bool-to-integer casting rules will do it for you. Also, stray blank line, and you're changing save/load format so you need to update a version number somewhere.

Ok, any quick guidelines for where to find information on how to do this?

Quoted 126 lines

hw/ssd0323.c static int ssd0323_load(QEMUFile *f, void *opaque, int version_id) · line 326

Quoted 13 lines
hw/ssd0323.c +2 -0
 }
 
 static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
@@ -319,6 +323,8 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
     s->mode = qemu_get_be32(f);
     qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
 
+    ss->cs = !!qemu_get_be32(f);

!! unnecessary here.

Same comments as here and the one above apply to the other devices below.

Quoted 107 lines
hw/ssd0323.c +1 -0
+
     return 0;
 }
 
hw/ssi-sd.c +6 -0
index b519bdb..6fd9ab9 100644
@@ -197,6 +197,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
 
 static void ssi_sd_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -209,10 +210,13 @@ static void ssi_sd_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->arglen);
     qemu_put_be32(f, s->response_pos);
     qemu_put_be32(f, s->stopping);
+
+    qemu_put_be32(f, ss->cs ? 1 : 0);
 }
 
 static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -229,6 +233,8 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
     s->response_pos = qemu_get_be32(f);
     s->stopping = qemu_get_be32(f);
 
+    ss->cs = !!qemu_get_be32(f);
+
     return 0;
 }
 
hw/ssi.c +37 -1
index 2db88fc..2e4f2fe 100644
@@ -27,19 +27,55 @@ static const TypeInfo ssi_bus_info = {
     .instance_size = sizeof(SSIBus),
 };
 
+static void ssi_cs_default(void *opaque, int n, int level)
+{
+    SSISlave *s = SSI_SLAVE(opaque);
+    bool cs = !!level;
+    assert(n == 0);
+    if (s->cs != cs) {
+        SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
+        if (ssc->set_cs) {
+            ssc->set_cs(s, cs);
+        }
+    }
+    s->cs = cs;
+}
+
+static uint32_t ssi_transfer_raw_default(SSISlave *dev, uint32_t val)
+{
+    SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(dev);
+
+    if ((dev->cs && ssc->cs_polarity == SSI_CS_HIGH) ||
+            (!dev->cs && ssc->cs_polarity == SSI_CS_LOW) ||
+            ssc->cs_polarity == SSI_CS_NONE) {
+        return ssc->transfer(dev, val);
+    }
+    return 0;
+}
+
 static int ssi_slave_init(DeviceState *dev)
 {
     SSISlave *s = SSI_SLAVE(dev);
     SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
 
+    if (ssc->transfer_raw == ssi_transfer_raw_default &&
+            ssc->cs_polarity != SSI_CS_NONE) {
+        qdev_init_gpio_in(&s->qdev, ssi_cs_default, 1);
+    }
+
     return ssc->init(s);
 }
 
 static void ssi_slave_class_init(ObjectClass *klass, void *data)
 {
+    SSISlaveClass *ssc = SSI_SLAVE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+
     dc->init = ssi_slave_init;
     dc->bus_type = TYPE_SSI_BUS;
+    if (!ssc->transfer_raw) {
+        ssc->transfer_raw = ssi_transfer_raw_default;
+    }
 }
 
 static TypeInfo ssi_slave_info = {
@@ -74,7 +110,7 @@ uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
     QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
         SSISlave *slave = SSI_SLAVE(kid->child);
         ssc = SSI_SLAVE_GET_CLASS(slave);
-        r |= ssc->transfer(slave, val);
+        r |= ssc->transfer_raw(slave, val);
     }
 
Quoted 11 lines

hw/ssi.c const VMStateDescription vmstate_ssi_slave = { · line 125

Quoted 6 lines
hw/ssi.c +1 -0
     return r;
@@ -86,6 +122,7 @@ const VMStateDescription vmstate_ssi_slave = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(cs, SSISlave),

New field -> must bump version. You could probably avoid this by rearranging things so this field is in the vmstate from the start rather than added in a subsequent patch.

So is this a bisect-ability issue between this and the previous patch? If so Ill just fold the two together, they are related enough to do so. Better to not change functionality for the sake of revision control.

Quoted 62 lines
Quoted 19 lines
hw/ssi.c +0 -0
         VMSTATE_END_OF_LIST()
     }
 };
hw/ssi.h +6 -0
index 975f9fb..5b69a3b 100644
@@ -23,16 +23,43 @@ typedef struct SSISlave SSISlave;
 #define SSI_SLAVE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
 
+typedef enum {
+    SSI_CS_NONE = 0,
+    SSI_CS_LOW,
+    SSI_CS_HIGH,
+} SSICSMode;
+
 /* Slave devices.  */
 typedef struct SSISlaveClass {

hw/ssi.h typedef struct SSISlave SSISlave; · line 43

Quoted 10 lines
hw/ssi.h +6 -0
     DeviceClass parent_class;
 
     int (*init)(SSISlave *dev);
+
+    /* if you have standard or no CS behaviour, just override transfer.
+     * This is called when the device cs is active (true by default).
+     */
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
+    /* called when the CS line changes. Optional, devices only need to implement
+     * this if they have side effects assoicated with the cs line (beyond

"associated"

hw/ssi.h typedef struct SSISlave SSISlave; · line 50

Quoted 7 lines
hw/ssi.h +7 -0
+     * tristating the txrx lines).
+     */
+    int (*set_cs)(SSISlave *dev, bool select);
+    /* define whether or not CS exists and is active low/high */
+    SSICSMode cs_polarity;
+
+    /* if you have non-standard CS behvaiour override this to take control

"behaviour" (and below)

hw/ssi.h typedef struct SSISlave SSISlave; · line 52

Quoted 2 lines
hw/ssi.h +2 -0
+     * of the CS behvaiour at the device level. transfer, set_cs, and
+     * cs_polarity are unused if this is overwritten. Transfer_raw, will

spurious comma

hw/ssi.h typedef struct SSISlave SSISlave; · line 53

Quoted 1 line
hw/ssi.h +1 -0
+     * always be called for the device for every txrx access the to parent bus

"to the"

Quoted 11 lines
hw/ssi.h +5 -0
+     */
+    uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val);
 } SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
+
+    /* Chip select state */
+    bool cs;
 };
 
Quoted 7 lines
Quoted 4 lines
hw/ssi.h +0 -1
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
--

1.7.0.4

-- PMM

Regards,
Peter

#9 lore raw

PATCH v5 4/15 ssi: Added create_slave_no_init()

In reply to Peter A. G. Crosthwaite

Slave creation function that can be used to create an SSI slave without qdev_init() being called. This give machine models a change to set properties.

---
 hw/ssi.c |    9 +++++++--
 hw/ssi.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/ssi.c +7 -2
index 2e4f2fe..c47419d 100644
@@ -86,10 +86,15 @@ static TypeInfo ssi_slave_info = {
     .abstract = true,
 };
 
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name)
+{
+    return qdev_create(&bus->qbus, name);
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
 {
-    DeviceState *dev;
-    dev = qdev_create(&bus->qbus, name);
+    DeviceState *dev = ssi_create_slave_no_init(bus, name);
+
     qdev_init_nofail(dev);
     return dev;
 }
hw/ssi.h +1 -0
index 5b69a3b..80b9664 100644
@@ -76,6 +76,7 @@ extern const VMStateDescription vmstate_ssi_slave;
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name);
 
 /* Master interface.  */
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
Signature · 1 line
1.7.0.4
#10 lore raw

Re: [Qemu-devel] [PATCH v5 04/15] ssi: Added create_slave_no_init()

Quoted 2 lines · Peter A. G. Crosthwaite

Slave creation function that can be used to create an SSI slave without qdev_init() being called. This give machine models a change to set properties.

Not convinced about this one -- I think that if machine models need to do more complicated things with the qdev device then they should just call qdev_create/set properties/qdev_init themselves.

-- PMM

Quoted 43 lines
---
 hw/ssi.c |    9 +++++++--
 hw/ssi.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/ssi.c +7 -2
index 2e4f2fe..c47419d 100644
@@ -86,10 +86,15 @@ static TypeInfo ssi_slave_info = {
     .abstract = true,
 };
 
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name)
+{
+    return qdev_create(&bus->qbus, name);
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
 {
-    DeviceState *dev;
-    dev = qdev_create(&bus->qbus, name);
+    DeviceState *dev = ssi_create_slave_no_init(bus, name);
+
     qdev_init_nofail(dev);
     return dev;
 }
hw/ssi.h +1 -1
index 5b69a3b..80b9664 100644
@@ -76,6 +76,7 @@ extern const VMStateDescription vmstate_ssi_slave;
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name);
 
 /* Master interface.  */
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
--

1.7.0.4

#11 lore raw

Re: [Qemu-devel] [PATCH v5 04/15] ssi: Added create_slave_no_init()

Quoted 9 lines · Peter Maydell
Quoted 2 lines · Peter A. G. Crosthwaite

Slave creation function that can be used to create an SSI slave without qdev_init() being called. This give machine models a change to set properties.

Not convinced about this one -- I think that if machine models need to do more complicated things with the qdev device then they should just call qdev_create/set properties/qdev_init themselves.

Yeh I tried that didnt work. See comment below.

Quoted 16 lines

-- PMM

Quoted 14 lines
---
 hw/ssi.c |    9 +++++++--
 hw/ssi.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/ssi.c +0 -0
index 2e4f2fe..c47419d 100644
@@ -86,10 +86,15 @@ static TypeInfo ssi_slave_info = {
     .abstract = true,
 };
 
Quoted 3 lines

hw/ssi.c static TypeInfo ssi_slave_info = { · line 91

Quoted 3 lines
hw/ssi.c +3 -0
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name)
+{
+    return qdev_create(&bus->qbus, name);

bus->qbus accesses requires the definition of struct SSIBus which is private to ssi.c. Machine models cant access the qbus field which they need for qdev_create().

Regards,
Peter

Quoted 26 lines
Quoted 26 lines
hw/ssi.c +4 -2
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
 {
-    DeviceState *dev;
-    dev = qdev_create(&bus->qbus, name);
+    DeviceState *dev = ssi_create_slave_no_init(bus, name);
+
     qdev_init_nofail(dev);
     return dev;
 }
hw/ssi.h +1 -1
index 5b69a3b..80b9664 100644
@@ -76,6 +76,7 @@ extern const VMStateDescription vmstate_ssi_slave;
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name);
 
 /* Master interface.  */
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
--

1.7.0.4

#12 lore raw

PATCH v5 5/15 qdev: allow multiple qdev_init_gpio_in() calls

In reply to Peter A. G. Crosthwaite

Allow multiple qdev_init_gpio_in() calls for the one device. The first call will define GPIOs 0-N-1, the next GPIOs N- ... . Allows different GPIOs to be handled with different handlers. Needed when two levels of the QOM class heirachy both define GPIO functionality, as a single GPIO handler with an index selecter is not possible.

---
 hw/qdev.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
hw/qdev.c +13 -3
index b5b74b9..ce91a72 100644
@@ -293,9 +293,19 @@ BusState *qdev_get_parent_bus(DeviceState *dev)
 
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
 {
-    assert(dev->num_gpio_in == 0);
-    dev->num_gpio_in = n;
-    dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
+    qemu_irq *new_irqs = qemu_allocate_irqs(handler, dev, n);
+
+    if (dev->num_gpio_in == 0) {
+        dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
+    } else {
+        qemu_irq *all_irqs = g_new(qemu_irq, n + dev->num_gpio_in);
+        memcpy(all_irqs, dev->gpio_in, sizeof(*all_irqs) * dev->num_gpio_in);
+        g_free(dev->gpio_in);
+        memcpy(&all_irqs[dev->num_gpio_in], new_irqs, sizeof(*all_irqs) * n),
+        g_free(new_irqs);
+        dev->gpio_in = all_irqs;
+    }
+    dev->num_gpio_in += n;
 }
 
 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
Signature · 1 line
1.7.0.4
#13 lore raw

Re: [Qemu-devel] [PATCH v5 05/15] qdev: allow multiple qdev_init_gpio_in() calls

Quoted 5 lines · Peter A. G. Crosthwaite

Allow multiple qdev_init_gpio_in() calls for the one device. The first call will define GPIOs 0-N-1, the next GPIOs N- ... . Allows different GPIOs to be handled with different handlers. Needed when two levels of the QOM class heirachy both define GPIO functionality, as a single GPIO handler with an index selecter is not possible.

I generally like this idea and I think there are a few devices in the existing codebase that could profitably use this rather than trying to sort things out in the handler function. (Long term we would ideally replace the single gpio array with a set of named arrays of Pins but this is useful in the meantime.)

Quoted 10 lines
---
 hw/qdev.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
hw/qdev.c +0 -0
index b5b74b9..ce91a72 100644

hw/qdev.c BusState *qdev_get_parent_bus(DeviceState *dev) · line 299

Quoted 10 lines
hw/qdev.c +4 -3
@@ -293,9 +293,19 @@ BusState *qdev_get_parent_bus(DeviceState *dev)
 
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
 {
-    assert(dev->num_gpio_in == 0);
-    dev->num_gpio_in = n;
-    dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
+    qemu_irq *new_irqs = qemu_allocate_irqs(handler, dev, n);
+
+    if (dev->num_gpio_in == 0) {
+        dev->gpio_in = qemu_allocate_irqs(handler, dev, n);

In this case we've just called qemu_allocate_irqs() twice and leaked the copy in new_irqs.

hw/qdev.c BusState *qdev_get_parent_bus(DeviceState *dev) · line 305

Quoted 6 lines
hw/qdev.c +6 -0
+    } else {
+        qemu_irq *all_irqs = g_new(qemu_irq, n + dev->num_gpio_in);
+        memcpy(all_irqs, dev->gpio_in, sizeof(*all_irqs) * dev->num_gpio_in);
+        g_free(dev->gpio_in);
+        memcpy(&all_irqs[dev->num_gpio_in], new_irqs, sizeof(*all_irqs) * n),
+        g_free(new_irqs);

I think this is rather looking into private details of what qemu_allocate_irqs does, and it would be better to define a new qemu_reallocate_irqs() in irq.c so we can use it here. (when doing so, consider whether g_renew() might help in producing nice looking code)

Quoted 9 lines
hw/qdev.c +3 -1
+        dev->gpio_in = all_irqs;
+    }
+    dev->num_gpio_in += n;
 }
 
 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
--

1.7.0.4

-- PMM

#14 lore raw

Re: [Qemu-devel] [PATCH v5 05/15] qdev: allow multiple qdev_init_gpio_in() calls

Quoted 25 lines · Peter Maydell
Quoted 5 lines · Peter A. G. Crosthwaite

Allow multiple qdev_init_gpio_in() calls for the one device. The first call will define GPIOs 0-N-1, the next GPIOs N- ... . Allows different GPIOs to be handled with different handlers. Needed when two levels of the QOM class heirachy both define GPIO functionality, as a single GPIO handler with an index selecter is not possible.

I generally like this idea and I think there are a few devices in the existing codebase that could profitably use this rather than trying to sort things out in the handler function. (Long term we would ideally replace the single gpio array with a set of named arrays of Pins but this is useful in the meantime.)

Quoted 11 lines
---
 hw/qdev.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
hw/qdev.c +0 -0
index b5b74b9..ce91a72 100644
@@ -293,9 +293,19 @@ BusState *qdev_get_parent_bus(DeviceState *dev)
 
Quoted 6 lines

hw/qdev.c BusState *qdev_get_parent_bus(DeviceState *dev) · line 296

Quoted 6 lines
hw/qdev.c +1 -3
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
 {
-    assert(dev->num_gpio_in == 0);
-    dev->num_gpio_in = n;
-    dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
+    qemu_irq *new_irqs = qemu_allocate_irqs(handler, dev, n);

RE comment below, this should be in the else condition, ill move it.

Quoted 14 lines

hw/qdev.c BusState *qdev_get_parent_bus(DeviceState *dev) · line 299

Quoted 3 lines
hw/qdev.c +3 -0
+
+    if (dev->num_gpio_in == 0) {
+        dev->gpio_in = qemu_allocate_irqs(handler, dev, n);

In this case we've just called qemu_allocate_irqs() twice and leaked the copy in new_irqs.

hw/qdev.c BusState *qdev_get_parent_bus(DeviceState *dev) · line 305

Quoted 6 lines
hw/qdev.c +6 -0
+    } else {
+        qemu_irq *all_irqs = g_new(qemu_irq, n + dev->num_gpio_in);
+        memcpy(all_irqs, dev->gpio_in, sizeof(*all_irqs) * dev->num_gpio_in);
+        g_free(dev->gpio_in);
+        memcpy(&all_irqs[dev->num_gpio_in], new_irqs, sizeof(*all_irqs) * n),
+        g_free(new_irqs);
Quoted 4 lines

I think this is rather looking into private details of what qemu_allocate_irqs does, and it would be better to define a new qemu_reallocate_irqs() in irq.c so we can use it here. (when doing so, consider whether g_renew() might help in producing nice looking code)

My understanding is Anthony is doing major refactoring in the GPIO area anyways. Long term, will this code in qdev.c/irq.c even going to exist? In this patch, I took something of a path of least resistance to just make this series work, as I suspect this patch in its current form will be short lived due to continued QOM development.

cc Andreas and Anthony.

Regards,
Peter

Quoted 14 lines
Quoted 11 lines
hw/qdev.c +3 -1
+        dev->gpio_in = all_irqs;
+    }
+    dev->num_gpio_in += n;
 }
 
 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
--

1.7.0.4

-- PMM

#15 lore raw

Re: [Qemu-devel] [PATCH v5 05/15] qdev: allow multiple qdev_init_gpio_in() calls

Quoted 14 lines · Peter Crosthwaite
Quoted 8 lines · Peter Maydell

hw/qdev.c BusState *qdev_get_parent_bus(DeviceState *dev) · line 305

Quoted 5 lines · Peter A. G. Crosthwaite
hw/qdev.c +5 -0
+        qemu_irq *all_irqs = g_new(qemu_irq, n + dev->num_gpio_in);
+        memcpy(all_irqs, dev->gpio_in, sizeof(*all_irqs) * dev->num_gpio_in);
+        g_free(dev->gpio_in);
+        memcpy(&all_irqs[dev->num_gpio_in], new_irqs, sizeof(*all_irqs) * n),
+        g_free(new_irqs);
Quoted 4 lines

I think this is rather looking into private details of what qemu_allocate_irqs does, and it would be better to define a new qemu_reallocate_irqs() in irq.c so we can use it here. (when doing so, consider whether g_renew() might help in producing nice looking code)

Quoted 5 lines

My understanding is Anthony is doing major refactoring in the GPIO area anyways. Long term, will this code in qdev.c/irq.c even going to exist? In this patch, I took something of a path of least resistance to just make this series work, as I suspect this patch in its current form will be short lived due to continued QOM development.

Yes, long term this will all disappear, but I wouldn't hold your breath (and indeed it's because I don't think the Pin reworking will hit before next release that I think this patch makes sense at all). But it will be around for a fair while, which is why the code should be in the right place. It's only adding a five or ten line function to irq.c.

-- PMM

#16 lore raw

PATCH v5 6/15 hw/stellaris: Removed gpio_out init array.

In reply to Peter A. G. Crosthwaite

stellaris_init() defines arrays of qemu_irq to decides what each of the GPIO pins are connected to. This is ok for inputs (as an input can only have one source) but is flawed for outputs as an output can connect to any number of sinks. Removed the gpio_out array completely and just replaced its setters with direct calls to qdev_connect_gpio_out().

---
 hw/stellaris.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)
hw/stellaris.c +12 -14
index 4d26857..ec55c0e 100644
@@ -1244,7 +1244,6 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
     qemu_irq *pic;
     DeviceState *gpio_dev[7];
     qemu_irq gpio_in[7][8];
-    qemu_irq gpio_out[7][8];
     qemu_irq adc;
     int sram_size;
     int flash_size;
@@ -1284,8 +1283,9 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
                                                pic[gpio_irq[i]]);
             for (j = 0; j < 8; j++) {
                 gpio_in[i][j] = qdev_get_gpio_in(gpio_dev[i], j);
-                gpio_out[i][j] = NULL;
             }
+        } else {
+            gpio_dev[i] = NULL;
         }
     }
 
@@ -1308,20 +1308,27 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
         if (board->peripherals & BP_OLED_SSI) {
             DeviceState *mux;
             void *bus;
+            qemu_irq select_pin;
 
             bus = qdev_get_child_bus(dev, "ssi");
             mux = ssi_create_slave(bus, "evb6965-ssi");
-            gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
+            select_pin = qdev_get_gpio_in(mux, 0);
+            if (gpio_dev[GPIO_D]) {
+                qdev_connect_gpio_out(gpio_dev[GPIO_D], 0, select_pin);
+            }
 
             bus = qdev_get_child_bus(mux, "ssi0");
             ssi_create_slave(bus, "ssi-sd");
 
             bus = qdev_get_child_bus(mux, "ssi1");
             dev = ssi_create_slave(bus, "ssd0323");
-            gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
+            if (gpio_dev[GPIO_C]) {
+                qdev_connect_gpio_out(gpio_dev[GPIO_C], 7,
+                                        qdev_get_gpio_in(dev, 0));
+            }
 
             /* Make sure the select pin is high.  */
-            qemu_irq_raise(gpio_out[GPIO_D][0]);
+            qemu_irq_raise(select_pin);
         }
     }
     if (board->dc4 & (1 << 28)) {
@@ -1347,15 +1354,6 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
 
         stellaris_gamepad_init(5, gpad_irq, gpad_keycode);
     }
-    for (i = 0; i < 7; i++) {
-        if (board->dc4 & (1 << i)) {
-            for (j = 0; j < 8; j++) {
-                if (gpio_out[i][j]) {
-                    qdev_connect_gpio_out(gpio_dev[i], j, gpio_out[i][j]);
-                }
-            }
-        }
-    }
 }
 
 /* FIXME: Figure out how to generate these from stellaris_boards.  */
Signature · 1 line
1.7.0.4
#17 lore raw

PATCH v5 7/15 stellaris: Removed SSI mux

In reply to Peter A. G. Crosthwaite

Removed the explicit SSI mux and wired the CS line directly up to the SSI devices.

---
 hw/ssd0323.c   |    1 +
 hw/ssi-sd.c    |    1 +
 hw/stellaris.c |   98 ++++++++++----------------------------------------------
 3 files changed, 19 insertions(+), 81 deletions(-)
hw/ssd0323.c +1 -0
index db16d20..d8a0c14 100644
@@ -352,6 +352,7 @@ static void ssd0323_class_init(ObjectClass *klass, void *data)
 
     k->init = ssd0323_init;
     k->transfer = ssd0323_transfer;
+    k->cs_polarity = SSI_CS_HIGH;
 }
 
 static TypeInfo ssd0323_info = {
hw/ssi-sd.c +1 -0
index 6fd9ab9..1b1f625 100644
@@ -256,6 +256,7 @@ static void ssi_sd_class_init(ObjectClass *klass, void *data)
 
     k->init = ssi_sd_init;
     k->transfer = ssi_sd_transfer;
+    k->cs_polarity = SSI_CS_LOW;
 }
 
 static TypeInfo ssi_sd_info = {
hw/stellaris.c +17 -81

132 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#18 lore raw

PATCH v5 8/15 ssd0323: abort() instead of exit(1) on error.

In reply to Peter A. G. Crosthwaite

To be more consistent with the newer ways of error signalling. That and SIGABT is easier to debug with than exit(1).

---
 hw/ssd0323.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/ssd0323.c +3 -1
index d8a0c14..0800866 100644
@@ -19,7 +19,9 @@
 #define DPRINTF(fmt, ...) \
 do { printf("ssd0323: " fmt , ## __VA_ARGS__); } while (0)
 #define BADF(fmt, ...) \
-do { fprintf(stderr, "ssd0323: error: " fmt , ## __VA_ARGS__); exit(1);} while (0)
+do { \
+    fprintf(stderr, "ssd0323: error: " fmt , ## __VA_ARGS__); abort(); \
+} while (0)
 #else
 #define DPRINTF(fmt, ...) do {} while(0)
 #define BADF(fmt, ...) \
Signature · 1 line
1.7.0.4
#20 lore raw

Re: [Qemu-devel] [PATCH v5 08/15] ssd0323: abort() instead of exit(1) on error.

Quoted 9 lines · Peter Maydell
Quoted 4 lines · Peter A. G. Crosthwaite

To be more consistent with the newer ways of error signalling. That and SIGABT is easier to debug with than exit(1).

This is independent of the rest of the series, do we want to en-queue to arm-devs and ill remove from series? One less diff for me and one less spam for the mailing list :)

Regards,
Peter

Quoted 1 line

-- PMM

#21 lore raw

Re: [Qemu-devel] [PATCH v5 08/15] ssd0323: abort() instead of exit(1) on error.

Quoted 6 lines · Peter Crosthwaite
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Peter A. G. Crosthwaite

To be more consistent with the newer ways of error signalling. That and SIGABT is easier to debug with than exit(1).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This is independent of the rest of the series, do we want to en-queue to arm-devs and ill remove from series? One less diff for me and one less spam for the mailing list :)

Might as well. Applied to arm-devs.next.

-- PMM

#22 lore raw

PATCH v5 9/15 hw: Added generic FIFO API.

In reply to Peter A. G. Crosthwaite

Added a FIFO API that can be used to create and operate byte FIFOs.

---
 hw/Makefile.objs |    1 +
 hw/fifo.c        |   79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/fifo.h        |   47 ++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+), 0 deletions(-)
 create mode 100644 hw/fifo.c
 create mode 100644 hw/fifo.h
hw/Makefile.objs +1 -0
index 8327e55..6ba570e 100644
@@ -15,6 +15,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-y += fifo.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
hw/fifo.c new file +79 -0

79 lines not on this page · raw message

hw/fifo.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#23 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

Quoted 16 lines · Peter A. G. Crosthwaite

Added a FIFO API that can be used to create and operate byte FIFOs.

---
  hw/Makefile.objs |    1 +
  hw/fifo.c        |   79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/fifo.h        |   47 ++++++++++++++++++++++++++++++++
  3 files changed, 127 insertions(+), 0 deletions(-)

create mode 100644 hw/fifo.c
create mode 100644 hw/fifo.h

hw/Makefile.objs +0 -0
index 8327e55..6ba570e 100644

hw/Makefile.objs hw-obj-$(CONFIG_ECC) += ecc.o · line 18

Quoted 4 lines
hw/Makefile.objs +1 -0
@@ -15,6 +15,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
  hw-obj-$(CONFIG_NAND) += nand.o
  hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
  hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-y += fifo.o

Perhaps it'd be better to make it common object and put it into root directory, like its done for bitops.c and bitmap.c

Quoted 33 lines
hw/Makefile.objs +0 -0
  hw-obj-$(CONFIG_M48T59) += m48t59.o
  hw-obj-$(CONFIG_ESCC) += escc.o
hw/fifo.c new file +24 -0
new file mode 100644
index 0000000..5e14e1e
@@ -0,0 +1,79 @@
+/*
+ * Generic FIFO component, implemented as a circular buffer.
+ *
+ * Copyright (c) 2012 Peter A. G. Crosthwaite
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fifo.h"
+
+void fifo8_create(Fifo8 *fifo, uint32_t capacity)
+{
+    fifo->data = g_new(uint8_t, capacity);
+    fifo->capacity = capacity;
+    fifo->head = 0;
+    fifo->num = 0;
+}
+

hw/fifo.c line 34

Quoted 10 lines
hw/fifo.c new file +10 -0
+void fifo8_destroy(Fifo8 *fifo)
+{
+    g_free(fifo->data);
+}
+
+void fifo8_push(Fifo8 *fifo, uint8_t data)
+{
+    if (fifo->num == fifo->capacity) {
+        abort();
+    }

I think its too harsh to abort here (and in pop() too), fifo overrun/underrun condition is absolutely normal for most of the devices, usually it would just trigger an interrupt. I suggest return a error code instead and let a caller decide what should happen in this situation.

Quoted 24 lines
hw/fifo.c new file +24 -0
+    fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data;
+    fifo->num++;
+}
+
+uint8_t fifo8_pop(Fifo8 *fifo)
+{
+    uint8_t ret;
+
+    if (fifo->num == 0) {
+        abort();
+    }
+    ret = fifo->data[fifo->head++];
+    fifo->head %= fifo->capacity;
+    fifo->num--;
+    return ret;
+}
+
+void fifo8_reset(Fifo8 *fifo)
+{
+    fifo->num = 0;
+}
+
+bool fifo8_is_empty(Fifo8 *fifo)
+{

hw/fifo.c line 68

Quoted 10 lines
hw/fifo.c new file +10 -0
+    return (fifo->num == 0);
+}
+
+bool fifo8_is_full(Fifo8 *fifo)
+{
+    return (fifo->num == fifo->capacity);
+}
+
+const VMStateDescription vmstate_fifo8 = {
+    .name = "SSISlave",

thats not a good name for a generic fifo)

hw/fifo.c line 72

Quoted 4 lines
hw/fifo.c new file +4 -0
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {

too much spaces here

Quoted 60 lines
hw/fifo.c new file +7 -0
+        VMSTATE_VBUFFER_UINT32(data, Fifo8, 1, NULL, 0, capacity),
+        VMSTATE_UINT32(head, Fifo8),
+        VMSTATE_UINT32(num, Fifo8),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
hw/fifo.h new file +47 -0
new file mode 100644
index 0000000..3fb09ff
@@ -0,0 +1,47 @@
+#ifndef FIFO_H
+#define FIFO_H
+
+#include "hw.h"
+
+typedef struct {
+    /* All fields are private */
+    uint8_t *data;
+    uint32_t capacity;
+    uint32_t head;
+    uint32_t num;
+} Fifo8;
+
+/* create a fifo of the specified size */
+
+void fifo8_create(Fifo8 *, uint32_t);
+
+/* cleanup a fifo */
+
+void fifo8_destroy(Fifo8 *);
+
+/* push a data byte to the fifo. Behaviour is undefined if the fifo is full */
+
+void fifo8_push(Fifo8 *, uint8_t);
+
+/* pop a data byte from the fifo. Behviour is undefined if the fifo is empty */
+
+uint8_t fifo8_pop(Fifo8 *);
+
+/* reset (empty) the fifo */
+
+void fifo8_reset(Fifo8 *);
+
+bool fifo8_is_empty(Fifo8 *);
+bool fifo8_is_full(Fifo8 *);
+
+extern const VMStateDescription vmstate_fifo8;
+
+#define VMSTATE_FIFO8(_field, _state) {                              \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(Fifo8),                                     \
+    .vmsd       = &vmstate_fifo8,                                    \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, Fifo8),       \
+}
+
+#endif /* FIFO_H */
#24 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

In reply to Peter A. G. Crosthwaite
Quoted 1 line · Peter A. G. Crosthwaite

Added a FIFO API that can be used to create and operate byte FIFOs.

I'm not asking for actual conversions, but it would be nice to see a list of some devices that could in principle be moved to using this FIFO, as an indication of its general utility.

Would it make sense for the FIFO to be a QOM object, or is that a silly idea?

-- PMM

#25 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

Quoted 12 lines · Peter Maydell
Quoted 1 line · Peter A. G. Crosthwaite

Added a FIFO API that can be used to create and operate byte FIFOs.

I'm not asking for actual conversions, but it would be nice to see a list of some devices that could in principle be moved to using this FIFO, as an indication of its general utility.

Would it make sense for the FIFO to be a QOM object, or is that a silly idea?

-- PMM

FIFO introspection capability could be useful I think, and we could implement device-specific fifo "mutants" then (for example, PL330 fifo could be a general FIFO object + "tag" variable).

#26 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

In reply to Peter Maydell
Quoted 8 lines · Peter Maydell
Quoted 1 line · Peter A. G. Crosthwaite

Added a FIFO API that can be used to create and operate byte FIFOs.

I'm not asking for actual conversions, but it would be nice to see a list of some devices that could in principle be moved to using this FIFO, as an indication of its general utility.

The two device models in this series. mcf_uart.c, strongarm.c (StrongARMUARTState), xilinx_uartlite, cadence_uart.c, sh_serial.c, tsc210x.c to name the ones Ive just had a brief look over. There are more. grep -i fifo hw | grep uint8_t gives you a short list of files to look for potential clients.

Dominated by uarts as they are the ones that need 8-bit fifos. Usability is greatly expanded if the fifo can be an arbitrary data type (uint32_t, uint16_t, struct foo), but that is a much harder problem to solve that id like to say is out of scope of this series. I think this is what Igor is getting at RE his PL330 comments on his continuation of this thread. Can we get the ball rolling with uint8_t then talk about generalisation strategy?

Quoted 2 lines

Would it make sense for the FIFO to be a QOM object, or is that a silly idea?

There could be merit in making the data entries some form of QOM object. It would hurt performance, but could solve the arbitrary data problem.

Regards,
Peter

Quoted 2 lines

-- PMM

#27 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

In reply to Peter A. G. Crosthwaite
Quoted 149 lines · Peter A. G. Crosthwaite

Added a FIFO API that can be used to create and operate byte FIFOs.

---
  hw/Makefile.objs |    1 +
  hw/fifo.c        |   79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/fifo.h        |   47 ++++++++++++++++++++++++++++++++
  3 files changed, 127 insertions(+), 0 deletions(-)

create mode 100644 hw/fifo.c
create mode 100644 hw/fifo.h

hw/Makefile.objs +1 -0
index 8327e55..6ba570e 100644
@@ -15,6 +15,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
  hw-obj-$(CONFIG_NAND) += nand.o
  hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
  hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-y += fifo.o
 
  hw-obj-$(CONFIG_M48T59) += m48t59.o
  hw-obj-$(CONFIG_ESCC) += escc.o
hw/fifo.c new file +79 -0
new file mode 100644
index 0000000..5e14e1e
@@ -0,0 +1,79 @@
+/*
+ * Generic FIFO component, implemented as a circular buffer.
+ *
+ * Copyright (c) 2012 Peter A. G. Crosthwaite
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fifo.h"
+
+void fifo8_create(Fifo8 *fifo, uint32_t capacity)
+{
+    fifo->data = g_new(uint8_t, capacity);
+    fifo->capacity = capacity;
+    fifo->head = 0;
+    fifo->num = 0;
+}
+
+void fifo8_destroy(Fifo8 *fifo)
+{
+    g_free(fifo->data);
+}
+
+void fifo8_push(Fifo8 *fifo, uint8_t data)
+{
+    if (fifo->num == fifo->capacity) {
+        abort();
+    }
+    fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data;
+    fifo->num++;
+}
+
+uint8_t fifo8_pop(Fifo8 *fifo)
+{
+    uint8_t ret;
+
+    if (fifo->num == 0) {
+        abort();
+    }
+    ret = fifo->data[fifo->head++];
+    fifo->head %= fifo->capacity;
+    fifo->num--;
+    return ret;
+}
+
+void fifo8_reset(Fifo8 *fifo)
+{
+    fifo->num = 0;
+}
+
+bool fifo8_is_empty(Fifo8 *fifo)
+{
+    return (fifo->num == 0);
+}
+
+bool fifo8_is_full(Fifo8 *fifo)
+{
+    return (fifo->num == fifo->capacity);
+}
+
+const VMStateDescription vmstate_fifo8 = {
+    .name = "SSISlave",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_VBUFFER_UINT32(data, Fifo8, 1, NULL, 0, capacity),
+        VMSTATE_UINT32(head, Fifo8),
+        VMSTATE_UINT32(num, Fifo8),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
hw/fifo.h new file +35 -0
new file mode 100644
index 0000000..3fb09ff
@@ -0,0 +1,47 @@
+#ifndef FIFO_H
+#define FIFO_H
+
+#include "hw.h"
+
+typedef struct {
+    /* All fields are private */
+    uint8_t *data;
+    uint32_t capacity;
+    uint32_t head;
+    uint32_t num;
+} Fifo8;
+
+/* create a fifo of the specified size */
+
+void fifo8_create(Fifo8 *, uint32_t);
+
+/* cleanup a fifo */
+
+void fifo8_destroy(Fifo8 *);
+
+/* push a data byte to the fifo. Behaviour is undefined if the fifo is full */
+
+void fifo8_push(Fifo8 *, uint8_t);
+
+/* pop a data byte from the fifo. Behviour is undefined if the fifo is empty */
+
+uint8_t fifo8_pop(Fifo8 *);
+
+/* reset (empty) the fifo */
+
+void fifo8_reset(Fifo8 *);
+
+bool fifo8_is_empty(Fifo8 *);
+bool fifo8_is_full(Fifo8 *);

hw/fifo.h line 45

Quoted 10 lines
hw/fifo.h new file +10 -0
+
+extern const VMStateDescription vmstate_fifo8;
+
+#define VMSTATE_FIFO8(_field, _state) {                              \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(Fifo8),                                     \
+    .vmsd       = &vmstate_fifo8,                                    \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, Fifo8),       \
+}

how about implementing this as a wrapper to VMSTATE_STRUCT_TEST() macro instead? And maybe this should go to vmstate.h header

Quoted 2 lines
hw/fifo.h new file +2 -0
+
+#endif /* FIFO_H */
#28 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

Quoted 6 lines
Quoted 6 lines
hw/fifo.h new file +6 -0
+
+extern const VMStateDescription vmstate_fifo8;
+
+#define VMSTATE_FIFO8(_field, _state) {                              \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(Fifo8),                                     \
Quoted 8 lines

hw/fifo.h line 45

Quoted 4 lines
hw/fifo.h new file +4 -0
+    .vmsd       = &vmstate_fifo8,                                    \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, Fifo8),       \
+}

how about implementing this as a wrapper to VMSTATE_STRUCT_TEST() macro instead?

This has no existing precedent in QEMU so I am unsure of what you mean?

And maybe this should go to vmstate.h header

I disagree. All other clients of VMS_STRUCT are out in their repective device specific headers (pci.h, i2c.h) etc. Unless this is new established policy, I dont really want to change the current adopted approach.

Regards,
Peter

Quoted 6 lines
Quoted 4 lines
(quoted diff) +2 -0
+
+#endif /* FIFO_H */
#29 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

Quoted 13 lines · Peter Crosthwaite
Quoted 5 lines
Quoted 5 lines
hw/fifo.h new file +5 -0
+
+extern const VMStateDescription vmstate_fifo8;
+
+#define VMSTATE_FIFO8(_field, _state) {                              \
+    .name       = (stringify(_field)),                               \
Quoted 8 lines

hw/fifo.h line 45

Quoted 5 lines
hw/fifo.h new file +5 -0
+    .size       = sizeof(Fifo8),                                     \
+    .vmsd       = &vmstate_fifo8,                                    \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, Fifo8),       \
+}

how about implementing this as a wrapper to VMSTATE_STRUCT_TEST() macro instead?

Quoted 1 line

This has no existing precedent in QEMU so I am unsure of what you mean?

I meant VMSTATE_TIMER_TEST() in vmstate.h as an example, which is a wrapper to VMSTATE_POINTER_TEST(). With this approach, fifo macro could be

#define VMSTATE_FIFO8(_field, _state) \
VMSTATE_STRUCT(_field, _state, 0, vmstate_fifo8, Fifo8)

Quoted 7 lines

And maybe this should go to vmstate.h header

I disagree. All other clients of VMS_STRUCT are out in their repective device specific headers (pci.h, i2c.h) etc. Unless this is new established policy, I dont really want to change the current adopted approach.

Yeah, looks like you're right.

Quoted 7 lines

Regards,
Peter

Quoted 4 lines
Quoted 3 lines
(quoted diff) +2 -0
+
+#endif /* FIFO_H */
#30 lore raw

Re: [Qemu-devel] [PATCH v5 09/15] hw: Added generic FIFO API.

Quoted 17 lines · Igor Mitsyanko
Quoted 16 lines · Peter Crosthwaite
Quoted 15 lines

hw/fifo.h line 45

Quoted 11 lines
hw/fifo.h new file +10 -0
+
+extern const VMStateDescription vmstate_fifo8;
+
+#define VMSTATE_FIFO8(_field, _state) {                              \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(Fifo8),                                     \
+    .vmsd       = &vmstate_fifo8,                                    \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, Fifo8),       \
+}

how about implementing this as a wrapper to VMSTATE_STRUCT_TEST() macro instead?

Quoted 9 lines
Quoted 1 line

This has no existing precedent in QEMU so I am unsure of what you mean?

I meant VMSTATE_TIMER_TEST() in vmstate.h as an example, which is a wrapper to VMSTATE_POINTER_TEST(). With this approach, fifo macro could be

#define VMSTATE_FIFO8(_field, _state) \
VMSTATE_STRUCT(_field, _state, 0, vmstate_fifo8, Fifo8)

Yeh just greppin around it looks like this is functionally equivalent. VMSTATE_IDE_BUS looks like a reasonable precedent for that. Any opinions one way or the other RE with my original approach (based on I2C) vs Igors shortened version?

Regards,
Peter

Quoted 23 lines
Quoted 9 lines

And maybe this should go to vmstate.h header

I disagree. All other clients of VMS_STRUCT are out in their repective device specific headers (pci.h, i2c.h) etc. Unless this is new established policy, I dont really want to change the current adopted approach.

Yeah, looks like you're right.

Quoted 8 lines

Regards,
Peter

Quoted 5 lines
Quoted 3 lines
(quoted diff) +2 -0
+
+#endif /* FIFO_H */
#31 lore raw

PATCH v5 10/15 m25p80: Initial implementation of SPI flash device

In reply to Peter A. G. Crosthwaite

Added device model for m25p80 style SPI flash family.

---
changed from v4:
Added write-1 flag (EEPROM mode).
n25q128 table entry indentation fix.
updated for new SSI interface.
various debug messages cleaned up and added.
changed from v3:
changed licence to v2 or later (PMM review)
generalised device model - rather than being fixed to the fl064k, it can handle a wide range of m25p80 devices refactored erase commands (previously they were fl064k specific and used spansions broken terminology) typdef'd strcuts and enums
fixed some camel casing
added comment to explain why bdrv_sync_complete is a nop (PMM review)
removed hardcoded "512" for BDRV_SECTOR_SIZE
flash_sync_area: use bdrv_aio_writev instead of bdrv_write flash_chip_erase/flash_block_erase32k/flash_sector_erase: consolidated to one function
decode_new_cmd: fixed multi-statement lines (PMM review)
CHIP_ERASE->BULK_ERASE
init: drive_get -> drive_get_next (PMM review)
changed from v2:
updated for SSI slave interface
used async io (suggested - Stefan Hajnoczi)
changed from v1:
converted spi api to modified txrx style
factored out lots of common code and inlined overly short single call functions.
undated for txrx style spi interface

 default-configs/arm-softmmu.mak          |    1 +
 default-configs/microblaze-softmmu.mak   |    2 +
 default-configs/microblazeel-softmmu.mak |    2 +
 hw/Makefile.objs                         |    1 +
 hw/m25p80.c                              |  572 ++++++++++++++++++++++++++++++
 5 files changed, 578 insertions(+), 0 deletions(-)
 create mode 100644 hw/m25p80.c
default-configs/arm-softmmu.mak +1 -0
index e542b4f..ce5ff25 100644
@@ -22,6 +22,7 @@ CONFIG_ADS7846=y
 CONFIG_MAX111X=y
 CONFIG_SSI=y
 CONFIG_SSI_SD=y
+CONFIG_SSI_M25P80=y
 CONFIG_LAN9118=y
 CONFIG_SMC91C111=y
 CONFIG_DS1338=y
default-configs/microblaze-softmmu.mak +2 -0
index 64c9485..2f442e5 100644
@@ -5,3 +5,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
 CONFIG_XILINX=y
 CONFIG_XILINX_AXI=y
+CONFIG_SSI=y
+CONFIG_SSI_M25P80=y
default-configs/microblazeel-softmmu.mak +2 -0
index a962276..af9a3cd 100644
@@ -5,3 +5,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
 CONFIG_XILINX=y
 CONFIG_XILINX_AXI=y
+CONFIG_SSI=y
+CONFIG_SSI_M25P80=y
hw/Makefile.objs +1 -0
index 6ba570e..e6a94d6 100644
@@ -143,6 +143,7 @@ common-obj-y += scsi-disk.o cdrom.o hd-geometry.o block-common.o
 common-obj-y += scsi-generic.o scsi-bus.o
 common-obj-y += hid.o
 common-obj-$(CONFIG_SSI) += ssi.o
+common-obj-$(CONFIG_SSI_M25P80) += m25p80.o
 common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
 common-obj-$(CONFIG_SD) += sd.o
 common-obj-y += bt.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
hw/m25p80.c new file +572 -0

572 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#32 lore raw

PATCH v5 11/15 xilinx_spi: Initial impl. of Xilinx SPI controller

In reply to Peter A. G. Crosthwaite

Device model for xilinx XPS SPI controller (v2.0)

---
changed from v4 (Near total rewrite):
removed timer delay. This was innacturate anyways removed for simlicity. updated for new SSI interface.
factored out txrx fifos using fifo.h
changed from v3:
typedef'd struct XilinxSPI
changed unsigned int -> uin32_t
removed unused vars (c_fifo_exist and cmd_ongoing)
txfifo_reset removed duplicate s->regs[R_SPISR] &= ~SR_TX_FULL (PMM review)
reset: changed to Device Class style reset
reset: stope the ptimer (pmm review)
xlx_spi_update_irq: dont -> don't (PMM review)
init: set irq_line to 1 (force refresh on vmsd load)
init: dropped call to reset
implemetned vmsd
changed from v2:
converted spi api to ssi api
changed from v1:
converted spi api to modified txrx style

 hw/microblaze/Makefile.objs |    1 +
 hw/xilinx_spi.c             |  390 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 391 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spi.c
hw/microblaze/Makefile.objs +1 -0
index 274d2c5..3028e65 100644
@@ -1,6 +1,7 @@
 obj-y = petalogix_s3adsp1800_mmu.o
 obj-y += petalogix_ml605_mmu.o
 obj-y += microblaze_boot.o
+obj-y += xilinx_spi.o
 
 obj-y += microblaze_pic_cpu.o
 obj-y += xilinx_ethlite.o
hw/xilinx_spi.c new file +390 -0

390 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#33 lore raw

PATCH v5 12/15 petalogix-ml605: added SPI controller with n25q128

In reply to Peter A. G. Crosthwaite

Added SPI controller to the reference design, with two n25q128 spi-flashes connected.

---
 hw/petalogix_ml605_mmu.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
hw/petalogix_ml605_mmu.c +27 -1
index 6a7d0c0..f0ecc1f 100644
@@ -36,6 +36,7 @@
 #include "blockdev.h"
 #include "pc.h"
 #include "exec-memory.h"
+#include "ssi.h"
 
 #include "microblaze_boot.h"
 #include "microblaze_pic_cpu.h"
@@ -54,6 +55,8 @@
 #define AXIENET_BASEADDR 0x82780000
 #define AXIDMA_BASEADDR 0x84600000
 
+#define NUM_SPI_FLASHES 2
+
 static void machine_cpu_reset(MicroBlazeCPU *cpu)
 {
     CPUMBState *env = &cpu->env;
@@ -78,6 +81,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
     MemoryRegion *address_space_mem = get_system_memory();
     DeviceState *dev;
     MicroBlazeCPU *cpu;
+    SysBusDevice *busdev;
     CPUMBState *env;
     DriveInfo *dinfo;
     int i;
@@ -135,9 +139,31 @@ petalogix_ml605_init(ram_addr_t ram_size,
                                      irq[1], irq[0], 100 * 1000000);
     }
 
+    {
+        SSIBus *spi;
+
+        dev = qdev_create(NULL, "xilinx,spi");
+        qdev_prop_set_uint8(dev, "num-cs", NUM_SPI_FLASHES);
+        qdev_init_nofail(dev);
+        busdev = sysbus_from_qdev(dev);
+        sysbus_mmio_map(busdev, 0, 0x40a00000);
+        sysbus_connect_irq(busdev, 0, irq[4]);
+
+        spi = (SSIBus *)qdev_get_child_bus(dev, "spi");
+
+        for (i = 0; i < NUM_SPI_FLASHES; i++) {
+            qemu_irq cs_line;
+
+            dev = ssi_create_slave_no_init(spi, "m25p80");
+            qdev_prop_set_string(dev, "partname", (char *)"n25q128");
+            qdev_init_nofail(dev);
+            cs_line = qdev_get_gpio_in(dev, 0);
+            sysbus_connect_irq(busdev, i+1, cs_line);
+        }
+    }
+
     microblaze_load_kernel(cpu, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
                                                             machine_cpu_reset);
-
 }
 
 static QEMUMachine petalogix_ml605_machine = {
Signature · 1 line
1.7.0.4
#34 lore raw

Re: [Qemu-devel] [PATCH v5 12/15] petalogix-ml605: added SPI controller with n25q128

Quoted 48 lines · Peter A. G. Crosthwaite

Added SPI controller to the reference design, with two n25q128 spi-flashes connected.

---
 hw/petalogix_ml605_mmu.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
hw/petalogix_ml605_mmu.c +11 -0
index 6a7d0c0..f0ecc1f 100644
@@ -36,6 +36,7 @@
 #include "blockdev.h"
 #include "pc.h"
 #include "exec-memory.h"
+#include "ssi.h"
 
 #include "microblaze_boot.h"
 #include "microblaze_pic_cpu.h"
@@ -54,6 +55,8 @@
 #define AXIENET_BASEADDR 0x82780000
 #define AXIDMA_BASEADDR 0x84600000
 
+#define NUM_SPI_FLASHES 2
+
 static void machine_cpu_reset(MicroBlazeCPU *cpu)
 {
     CPUMBState *env = &cpu->env;
@@ -78,6 +81,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
     MemoryRegion *address_space_mem = get_system_memory();
     DeviceState *dev;
     MicroBlazeCPU *cpu;
+    SysBusDevice *busdev;
     CPUMBState *env;
     DriveInfo *dinfo;
     int i;
@@ -135,9 +139,31 @@ petalogix_ml605_init(ram_addr_t ram_size,
                                      irq[1], irq[0], 100 * 1000000);
     }
 
+    {
+        SSIBus *spi;
+
+        dev = qdev_create(NULL, "xilinx,spi");
+        qdev_prop_set_uint8(dev, "num-cs", NUM_SPI_FLASHES);
+        qdev_init_nofail(dev);
+        busdev = sysbus_from_qdev(dev);

hw/petalogix_ml605_mmu.c petalogix_ml605_init(ram_addr_t ram_size, · line 158

Quoted 10 lines
hw/petalogix_ml605_mmu.c +10 -0
+        sysbus_mmio_map(busdev, 0, 0x40a00000);
+        sysbus_connect_irq(busdev, 0, irq[4]);
+
+        spi = (SSIBus *)qdev_get_child_bus(dev, "spi");
+
+        for (i = 0; i < NUM_SPI_FLASHES; i++) {
+            qemu_irq cs_line;
+
+            dev = ssi_create_slave_no_init(spi, "m25p80");
+            qdev_prop_set_string(dev, "partname", (char *)"n25q128");

Why the cast?

Quoted 13 lines
hw/petalogix_ml605_mmu.c +6 -2
+            qdev_init_nofail(dev);
+            cs_line = qdev_get_gpio_in(dev, 0);
+            sysbus_connect_irq(busdev, i+1, cs_line);
+        }
+    }
+
     microblaze_load_kernel(cpu, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
                                                             machine_cpu_reset);
-
 }
 
 static QEMUMachine petalogix_ml605_machine = {
--
Quoted 2 lines

1.7.0.4

-- PMM

#35 lore raw

Re: [Qemu-devel] [PATCH v5 12/15] petalogix-ml605: added SPI controller with n25q128

Quoted 54 lines · Peter Maydell
Quoted 52 lines · Peter A. G. Crosthwaite

Added SPI controller to the reference design, with two n25q128 spi-flashes connected.

---
 hw/petalogix_ml605_mmu.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
hw/petalogix_ml605_mmu.c +15 -0
index 6a7d0c0..f0ecc1f 100644
@@ -36,6 +36,7 @@
 #include "blockdev.h"
 #include "pc.h"
 #include "exec-memory.h"
+#include "ssi.h"
 
 #include "microblaze_boot.h"
 #include "microblaze_pic_cpu.h"
@@ -54,6 +55,8 @@
 #define AXIENET_BASEADDR 0x82780000
 #define AXIDMA_BASEADDR 0x84600000
 
+#define NUM_SPI_FLASHES 2
+
 static void machine_cpu_reset(MicroBlazeCPU *cpu)
 {
     CPUMBState *env = &cpu->env;
@@ -78,6 +81,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
     MemoryRegion *address_space_mem = get_system_memory();
     DeviceState *dev;
     MicroBlazeCPU *cpu;
+    SysBusDevice *busdev;
     CPUMBState *env;
     DriveInfo *dinfo;
     int i;
@@ -135,9 +139,31 @@ petalogix_ml605_init(ram_addr_t ram_size,
                                      irq[1], irq[0], 100 * 1000000);
     }
 
+    {
+        SSIBus *spi;
+
+        dev = qdev_create(NULL, "xilinx,spi");
+        qdev_prop_set_uint8(dev, "num-cs", NUM_SPI_FLASHES);
+        qdev_init_nofail(dev);
+        busdev = sysbus_from_qdev(dev);
+        sysbus_mmio_map(busdev, 0, 0x40a00000);
+        sysbus_connect_irq(busdev, 0, irq[4]);
+
+        spi = (SSIBus *)qdev_get_child_bus(dev, "spi");
Quoted 9 lines

hw/petalogix_ml605_mmu.c petalogix_ml605_init(ram_addr_t ram_size, · line 158

Quoted 6 lines
hw/petalogix_ml605_mmu.c +6 -0
+
+        for (i = 0; i < NUM_SPI_FLASHES; i++) {
+            qemu_irq cs_line;
+
+            dev = ssi_create_slave_no_init(spi, "m25p80");
+            qdev_prop_set_string(dev, "partname", (char *)"n25q128");

Why the cast?

Used to issue a warning, but just checked and this was fixed recently (3b25597bcf7fa8c92ba2107fbdb260ce0eccd64b). Can remove it now. Will do so in the next revision.

Regards,
Peter

Quoted 18 lines
Quoted 13 lines
hw/petalogix_ml605_mmu.c +6 -2
+            qdev_init_nofail(dev);
+            cs_line = qdev_get_gpio_in(dev, 0);
+            sysbus_connect_irq(busdev, i+1, cs_line);
+        }
+    }
+
     microblaze_load_kernel(cpu, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
                                                             machine_cpu_reset);
-
 }
 
 static QEMUMachine petalogix_ml605_machine = {
--
Quoted 2 lines

1.7.0.4

-- PMM

#36 lore raw

PATCH v5 13/15 xilinx_spips: Xilinx Zynq SPI cntrlr device model

In reply to Peter A. G. Crosthwaite

Added device model for the Xilinx Zynq SPI controller (SPIPS).

---
 hw/arm/Makefile.objs |    1 +
 hw/xilinx_spips.c    |  352 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 353 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spips.c
hw/arm/Makefile.objs +1 -0
index c413780..bb5a5ba 100644
@@ -6,6 +6,7 @@ obj-y += cadence_uart.o
 obj-y += cadence_ttc.o
 obj-y += cadence_gem.o
 obj-y += xilinx_zynq.o zynq_slcr.o
+obj-y += xilinx_spips.o
 obj-y += arm_gic.o arm_gic_common.o
 obj-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
hw/xilinx_spips.c new file +352 -0

352 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#37 lore raw

PATCH v5 14/15 xilinx_zynq: Added SPI controllers + flashes

In reply to Peter A. G. Crosthwaite

Added the two SPI controllers to the zynq machine model. Attached two SPI flash devices to each controller.

---
 hw/xilinx_zynq.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
hw/xilinx_zynq.c +34 -0
index 7e6c273..e273711 100644
@@ -24,6 +24,9 @@
 #include "flash.h"
 #include "blockdev.h"
 #include "loader.h"
+#include "ssi.h"
+
+#define NUM_SPI_FLASHES 2
 
 #define FLASH_SIZE (64 * 1024 * 1024)
 #define FLASH_SECTOR_SIZE (128 * 1024)
@@ -46,6 +49,34 @@ static void gem_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     sysbus_connect_irq(s, 0, irq);
 }
 
+static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq)
+{
+    DeviceState *dev;
+    SysBusDevice *busdev;
+    SSIBus *spi;
+    int i;
+
+    dev = qdev_create(NULL, "xilinx,spips");
+    qdev_init_nofail(dev);
+    busdev = sysbus_from_qdev(dev);
+    sysbus_mmio_map(busdev, 0, base_addr);
+    sysbus_connect_irq(busdev, 0, irq);
+
+    spi = (SSIBus *)qdev_get_child_bus(dev, "spi");
+
+    for (i = 0; i < NUM_SPI_FLASHES; ++i) {
+        qemu_irq cs_line;
+
+        dev = ssi_create_slave_no_init(spi, "m25p80");
+        qdev_prop_set_string(dev, "partname", (char *)"n25q128");
+        qdev_init_nofail(dev);
+
+        cs_line = qdev_get_gpio_in(dev, 0);
+        sysbus_connect_irq(busdev, i+1, cs_line);
+    }
+
+}
+
 static void zynq_init(ram_addr_t ram_size, const char *boot_device,
                         const char *kernel_filename, const char *kernel_cmdline,
                         const char *initrd_filename, const char *cpu_model)
@@ -113,6 +144,9 @@ static void zynq_init(ram_addr_t ram_size, const char *boot_device,
         pic[n] = qdev_get_gpio_in(dev, n);
     }
 
+    zynq_init_spi_flashes(0xE0006000, pic[58-IRQ_OFFSET]);
+    zynq_init_spi_flashes(0xE0007000, pic[81-IRQ_OFFSET]);
+
     sysbus_create_simple("cadence_uart", 0xE0000000, pic[59-IRQ_OFFSET]);
     sysbus_create_simple("cadence_uart", 0xE0001000, pic[82-IRQ_OFFSET]);
 
Signature · 1 line
1.7.0.4
#38 lore raw

PATCH v5 15/15 MAINTAINERS: Added maintainerships for SSI

In reply to Peter A. G. Crosthwaite

Added maintainership for SSI, M25P80 and the Xilinx SPI controllers.

---
 MAINTAINERS |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
index 2d219d2..0f28f19 100644
@@ -268,6 +268,7 @@ S: Maintained
 F: hw/xilinx_zynq.c
 F: hw/zynq_slcr.c
 F: hw/cadence_*
+F: hw/xilinx_spips.c
 
 CRIS Machines
 -------------
@@ -455,6 +456,12 @@ M: Paul Brook <[email protected]>
 S: Odd Fixes
 F: hw/lsi53c895a.c
 
+SSI
+M: Peter Crosthwaite <[email protected]>
+S: Maintained
+F: hw/ssi.*
+F: hw/m25p80.c
+
 USB
 M: Gerd Hoffmann <[email protected]>
 S: Maintained
@@ -498,6 +505,7 @@ F: hw/xilinx_intc.c
 F: hw/xilinx_ethlite.c
 F: hw/xilinx_timer.c
 F: hw/xilinx.h
+F: hw/xilinx_spi.c
 
 Subsystems
 ----------
Signature · 1 line
1.7.0.4