All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups
@ 2017-10-14 18:38 Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE Mark Cave-Ayland
                   ` (14 more replies)
  0 siblings, 15 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This patchset aims to tidy-up the sparc32_dma code by improving the
modelling of the espdma/ledma devices using both QOM and the memory
API which didn't exist when the code was first written.

The result is that it is now possible to remove both the iommu_opaque
and is_ledma workarounds from the code, and the code for wiring up
the espdma/ledma and respective devices is also a lot more readable.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

v3:
- Add missing sysbus.h include to esp.h in patch 7

v2:
- Make esp/lance devices children of espdma/ledma devices respectively
- Add len parameter to ledma/espdma tracepoints

Mark Cave-Ayland (13):
  sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
  sparc32_dma: split esp and le into separate DMA devices
  sparc32_dma: move type declarations from sparc32_dma.c to
    sparc32_dma.h
  sun4m: move DMA device wiring from sparc32_dma_init() to
    sun4m_hw_init()
  sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
  sparc32_dma: use object link instead of qdev property to pass IOMMU
    reference
  esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h
  sparc32_dma: make esp device child of espdma device
  lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h
  sparc32_dma: make lance device child of ledma device
  sparc32_dma: introduce new SPARC32_DMA type container object
  sparc32_dma: remove is_ledma hack and replace with memory region
    alias
  sparc32_dma: add len to esp/le DMA memory tracing

 hw/dma/sparc32_dma.c           |  236 +++++++++++++++++++++++++++++-----------
 hw/dma/sun4m_iommu.c           |   14 ---
 hw/dma/trace-events            |    8 +-
 hw/net/lance.c                 |    9 --
 hw/scsi/esp.c                  |   13 ---
 hw/sparc/sun4m.c               |   82 ++++++--------
 include/hw/scsi/esp.h          |   14 +++
 include/hw/sparc/sparc32_dma.h |   55 ++++++++++
 include/hw/sparc/sun4m.h       |   29 +++++
 9 files changed, 307 insertions(+), 153 deletions(-)

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-19  4:26   ` Philippe Mathieu-Daudé
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices Mark Cave-Ayland
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

Also update the function names to match as appropriate. While we're
here rename the type from sparc32_dma to sparc32-dma in order to
match the current QOM convention.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c |   67 +++++++++++++++++++++++++-------------------------
 hw/sparc/sun4m.c     |    2 +-
 2 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index eb491b5..a8d31c1 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -61,12 +61,13 @@
 /* XXX SCSI and ethernet should have different read-only bit masks */
 #define DMA_CSR_RO_MASK 0xfe000007
 
-#define TYPE_SPARC32_DMA "sparc32_dma"
-#define SPARC32_DMA(obj) OBJECT_CHECK(DMAState, (obj), TYPE_SPARC32_DMA)
+#define TYPE_SPARC32_DMA_DEVICE "sparc32-dma-device"
+#define SPARC32_DMA_DEVICE(obj) OBJECT_CHECK(DMADeviceState, (obj), \
+                                             TYPE_SPARC32_DMA_DEVICE)
 
-typedef struct DMAState DMAState;
+typedef struct DMADeviceState DMADeviceState;
 
-struct DMAState {
+struct DMADeviceState {
     SysBusDevice parent_obj;
 
     MemoryRegion iomem;
@@ -86,7 +87,7 @@ enum {
 void ledma_memory_read(void *opaque, hwaddr addr,
                        uint8_t *buf, int len, int do_bswap)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
     int i;
 
     addr |= s->dmaregs[3];
@@ -106,7 +107,7 @@ void ledma_memory_read(void *opaque, hwaddr addr,
 void ledma_memory_write(void *opaque, hwaddr addr,
                         uint8_t *buf, int len, int do_bswap)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
     int l, i;
     uint16_t tmp_buf[32];
 
@@ -134,7 +135,7 @@ void ledma_memory_write(void *opaque, hwaddr addr,
 
 static void dma_set_irq(void *opaque, int irq, int level)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
     if (level) {
         s->dmaregs[0] |= DMA_INTR;
         if (s->dmaregs[0] & DMA_INTREN) {
@@ -154,7 +155,7 @@ static void dma_set_irq(void *opaque, int irq, int level)
 
 void espdma_memory_read(void *opaque, uint8_t *buf, int len)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
 
     trace_espdma_memory_read(s->dmaregs[1]);
     sparc_iommu_memory_read(s->iommu, s->dmaregs[1], buf, len);
@@ -163,7 +164,7 @@ void espdma_memory_read(void *opaque, uint8_t *buf, int len)
 
 void espdma_memory_write(void *opaque, uint8_t *buf, int len)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
 
     trace_espdma_memory_write(s->dmaregs[1]);
     sparc_iommu_memory_write(s->iommu, s->dmaregs[1], buf, len);
@@ -173,7 +174,7 @@ void espdma_memory_write(void *opaque, uint8_t *buf, int len)
 static uint64_t dma_mem_read(void *opaque, hwaddr addr,
                              unsigned size)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
     uint32_t saddr;
 
     if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
@@ -190,7 +191,7 @@ static uint64_t dma_mem_read(void *opaque, hwaddr addr,
 static void dma_mem_write(void *opaque, hwaddr addr,
                           uint64_t val, unsigned size)
 {
-    DMAState *s = opaque;
+    DMADeviceState *s = opaque;
     uint32_t saddr;
 
     if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
@@ -252,28 +253,28 @@ static const MemoryRegionOps dma_mem_ops = {
     },
 };
 
-static void dma_reset(DeviceState *d)
+static void sparc32_dma_device_reset(DeviceState *d)
 {
-    DMAState *s = SPARC32_DMA(d);
+    DMADeviceState *s = SPARC32_DMA_DEVICE(d);
 
     memset(s->dmaregs, 0, DMA_SIZE);
     s->dmaregs[0] = DMA_VER;
 }
 
-static const VMStateDescription vmstate_dma = {
+static const VMStateDescription vmstate_sparc32_dma_device = {
     .name ="sparc32_dma",
     .version_id = 2,
     .minimum_version_id = 2,
     .fields = (VMStateField[]) {
-        VMSTATE_UINT32_ARRAY(dmaregs, DMAState, DMA_REGS),
+        VMSTATE_UINT32_ARRAY(dmaregs, DMADeviceState, DMA_REGS),
         VMSTATE_END_OF_LIST()
     }
 };
 
-static void sparc32_dma_init(Object *obj)
+static void sparc32_dma_device_init(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
-    DMAState *s = SPARC32_DMA(obj);
+    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
     sysbus_init_irq(sbd, &s->irq);
@@ -284,9 +285,9 @@ static void sparc32_dma_init(Object *obj)
     qdev_init_gpio_out(dev, s->gpio, 2);
 }
 
-static void sparc32_dma_realize(DeviceState *dev, Error **errp)
+static void sparc32_dma_device_realize(DeviceState *dev, Error **errp)
 {
-    DMAState *s = SPARC32_DMA(dev);
+    DMADeviceState *s = SPARC32_DMA_DEVICE(dev);
     int reg_size;
 
     reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE;
@@ -294,35 +295,35 @@ static void sparc32_dma_realize(DeviceState *dev, Error **errp)
                           "dma", reg_size);
 }
 
-static Property sparc32_dma_properties[] = {
-    DEFINE_PROP_PTR("iommu_opaque", DMAState, iommu),
-    DEFINE_PROP_UINT32("is_ledma", DMAState, is_ledma, 0),
+static Property sparc32_dma_device_properties[] = {
+    DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
+    DEFINE_PROP_UINT32("is_ledma", DMADeviceState, is_ledma, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void sparc32_dma_class_init(ObjectClass *klass, void *data)
+static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    dc->reset = dma_reset;
-    dc->vmsd = &vmstate_dma;
-    dc->props = sparc32_dma_properties;
-    dc->realize = sparc32_dma_realize;
+    dc->reset = sparc32_dma_device_reset;
+    dc->vmsd = &vmstate_sparc32_dma_device;
+    dc->props = sparc32_dma_device_properties;
+    dc->realize = sparc32_dma_device_realize;
     /* Reason: pointer property "iommu_opaque" */
     dc->user_creatable = false;
 }
 
-static const TypeInfo sparc32_dma_info = {
-    .name          = TYPE_SPARC32_DMA,
+static const TypeInfo sparc32_dma_device_info = {
+    .name          = TYPE_SPARC32_DMA_DEVICE,
     .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(DMAState),
-    .instance_init = sparc32_dma_init,
-    .class_init    = sparc32_dma_class_init,
+    .instance_size = sizeof(DMADeviceState),
+    .instance_init = sparc32_dma_device_init,
+    .class_init    = sparc32_dma_device_class_init,
 };
 
 static void sparc32_dma_register_types(void)
 {
-    type_register_static(&sparc32_dma_info);
+    type_register_static(&sparc32_dma_device_info);
 }
 
 type_init(sparc32_dma_register_types)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index e1bdd48..82c553c 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -313,7 +313,7 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_create(NULL, "sparc32_dma");
+    dev = qdev_create(NULL, "sparc32-dma-device");
     qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
     qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
     qdev_init_nofail(dev);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-19  4:33   ` Philippe Mathieu-Daudé
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 03/13] sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h Mark Cave-Ayland
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

Due to slight differences in behaviour accessing the registers for the
esp and le devices, create two separate SPARC32_DMA_DEVICE types and
update the sun4m machine to use.

Note that by using different device types we already know the size of
the register block and the value of is_ledma at init time, allowing us to
drop the SPARC32_DMA_DEVICE realize function and the is_ledma device
property.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c |   63 ++++++++++++++++++++++++++++++++++++++++----------
 hw/sparc/sun4m.c     |    3 +--
 2 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index a8d31c1..e4ff4a8 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -78,6 +78,22 @@ struct DMADeviceState {
     uint32_t is_ledma;
 };
 
+#define TYPE_SPARC32_ESPDMA_DEVICE "sparc32-espdma"
+#define SPARC32_ESPDMA_DEVICE(obj) OBJECT_CHECK(ESPDMADeviceState, (obj), \
+                                                TYPE_SPARC32_ESPDMA_DEVICE)
+
+typedef struct ESPDMADeviceState {
+    DMADeviceState parent_obj;
+} ESPDMADeviceState;
+
+#define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"
+#define SPARC32_LEDMA_DEVICE(obj) OBJECT_CHECK(LEDMADeviceState, (obj), \
+                                               TYPE_SPARC32_LEDMA_DEVICE)
+
+typedef struct LEDMADeviceState {
+    DMADeviceState parent_obj;
+} LEDMADeviceState;
+
 enum {
     GPIO_RESET = 0,
     GPIO_DMA,
@@ -285,19 +301,8 @@ static void sparc32_dma_device_init(Object *obj)
     qdev_init_gpio_out(dev, s->gpio, 2);
 }
 
-static void sparc32_dma_device_realize(DeviceState *dev, Error **errp)
-{
-    DMADeviceState *s = SPARC32_DMA_DEVICE(dev);
-    int reg_size;
-
-    reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE;
-    memory_region_init_io(&s->iomem, OBJECT(dev), &dma_mem_ops, s,
-                          "dma", reg_size);
-}
-
 static Property sparc32_dma_device_properties[] = {
     DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
-    DEFINE_PROP_UINT32("is_ledma", DMADeviceState, is_ledma, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -308,7 +313,6 @@ static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
     dc->reset = sparc32_dma_device_reset;
     dc->vmsd = &vmstate_sparc32_dma_device;
     dc->props = sparc32_dma_device_properties;
-    dc->realize = sparc32_dma_device_realize;
     /* Reason: pointer property "iommu_opaque" */
     dc->user_creatable = false;
 }
@@ -316,14 +320,49 @@ static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
 static const TypeInfo sparc32_dma_device_info = {
     .name          = TYPE_SPARC32_DMA_DEVICE,
     .parent        = TYPE_SYS_BUS_DEVICE,
+    .abstract      = true,
     .instance_size = sizeof(DMADeviceState),
     .instance_init = sparc32_dma_device_init,
     .class_init    = sparc32_dma_device_class_init,
 };
 
+static void sparc32_espdma_device_init(Object *obj)
+{
+    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
+
+    memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
+                          "espdma-mmio", DMA_SIZE);
+    s->is_ledma = 0;
+}
+
+static const TypeInfo sparc32_espdma_device_info = {
+    .name          = TYPE_SPARC32_ESPDMA_DEVICE,
+    .parent        = TYPE_SPARC32_DMA_DEVICE,
+    .instance_size = sizeof(ESPDMADeviceState),
+    .instance_init = sparc32_espdma_device_init,
+};
+
+static void sparc32_ledma_device_init(Object *obj)
+{
+    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
+
+    memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
+                          "ledma-mmio", DMA_ETH_SIZE);
+    s->is_ledma = 1;
+}
+
+static const TypeInfo sparc32_ledma_device_info = {
+    .name          = TYPE_SPARC32_LEDMA_DEVICE,
+    .parent        = TYPE_SPARC32_DMA_DEVICE,
+    .instance_size = sizeof(LEDMADeviceState),
+    .instance_init = sparc32_ledma_device_init,
+};
+
 static void sparc32_dma_register_types(void)
 {
     type_register_static(&sparc32_dma_device_info);
+    type_register_static(&sparc32_espdma_device_info);
+    type_register_static(&sparc32_ledma_device_info);
 }
 
 type_init(sparc32_dma_register_types)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 82c553c..88a9752 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -313,9 +313,8 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_create(NULL, "sparc32-dma-device");
+    dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");
     qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
-    qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
     qdev_init_nofail(dev);
     s = SYS_BUS_DEVICE(dev);
     sysbus_connect_irq(s, 0, parent_irq);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 03/13] sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 04/13] sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init() Mark Cave-Ayland
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c           |   34 ----------------------------------
 include/hw/sparc/sparc32_dma.h |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index e4ff4a8..ae8fa06 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -40,7 +40,6 @@
  * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/DMA2.txt
  */
 
-#define DMA_REGS 4
 #define DMA_SIZE (4 * sizeof(uint32_t))
 /* We need the mask, because one instance of the device is not page
    aligned (ledma, start address 0x0010) */
@@ -61,39 +60,6 @@
 /* XXX SCSI and ethernet should have different read-only bit masks */
 #define DMA_CSR_RO_MASK 0xfe000007
 
-#define TYPE_SPARC32_DMA_DEVICE "sparc32-dma-device"
-#define SPARC32_DMA_DEVICE(obj) OBJECT_CHECK(DMADeviceState, (obj), \
-                                             TYPE_SPARC32_DMA_DEVICE)
-
-typedef struct DMADeviceState DMADeviceState;
-
-struct DMADeviceState {
-    SysBusDevice parent_obj;
-
-    MemoryRegion iomem;
-    uint32_t dmaregs[DMA_REGS];
-    qemu_irq irq;
-    void *iommu;
-    qemu_irq gpio[2];
-    uint32_t is_ledma;
-};
-
-#define TYPE_SPARC32_ESPDMA_DEVICE "sparc32-espdma"
-#define SPARC32_ESPDMA_DEVICE(obj) OBJECT_CHECK(ESPDMADeviceState, (obj), \
-                                                TYPE_SPARC32_ESPDMA_DEVICE)
-
-typedef struct ESPDMADeviceState {
-    DMADeviceState parent_obj;
-} ESPDMADeviceState;
-
-#define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"
-#define SPARC32_LEDMA_DEVICE(obj) OBJECT_CHECK(LEDMADeviceState, (obj), \
-                                               TYPE_SPARC32_LEDMA_DEVICE)
-
-typedef struct LEDMADeviceState {
-    DMADeviceState parent_obj;
-} LEDMADeviceState;
-
 enum {
     GPIO_RESET = 0,
     GPIO_DMA,
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index 9497b13..df7491d 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -1,6 +1,43 @@
 #ifndef SPARC32_DMA_H
 #define SPARC32_DMA_H
 
+#include "hw/sysbus.h"
+
+#define DMA_REGS 4
+
+#define TYPE_SPARC32_DMA_DEVICE "sparc32-dma-device"
+#define SPARC32_DMA_DEVICE(obj) OBJECT_CHECK(DMADeviceState, (obj), \
+                                             TYPE_SPARC32_DMA_DEVICE)
+
+typedef struct DMADeviceState DMADeviceState;
+
+struct DMADeviceState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    uint32_t dmaregs[DMA_REGS];
+    qemu_irq irq;
+    void *iommu;
+    qemu_irq gpio[2];
+    uint32_t is_ledma;
+};
+
+#define TYPE_SPARC32_ESPDMA_DEVICE "sparc32-espdma"
+#define SPARC32_ESPDMA_DEVICE(obj) OBJECT_CHECK(ESPDMADeviceState, (obj), \
+                                                TYPE_SPARC32_ESPDMA_DEVICE)
+
+typedef struct ESPDMADeviceState {
+    DMADeviceState parent_obj;
+} ESPDMADeviceState;
+
+#define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"
+#define SPARC32_LEDMA_DEVICE(obj) OBJECT_CHECK(LEDMADeviceState, (obj), \
+                                               TYPE_SPARC32_LEDMA_DEVICE)
+
+typedef struct LEDMADeviceState {
+    DMADeviceState parent_obj;
+} LEDMADeviceState;
+
 /* sparc32_dma.c */
 void ledma_memory_read(void *opaque, hwaddr addr,
                        uint8_t *buf, int len, int do_bswap);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 04/13] sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init()
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (2 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 03/13] sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h Mark Cave-Ayland
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

By using the sysbus interface it is possible to wire up the esp/le devices
to the sun4m DMA controller directly during sun4m_hw_init() instead of
passing qemu_irqs into the sparc32_dma_init() function.

This is an intermediate step to allow further reorganisation as more logic
is moved into the relevant SPARC32 DMA devices; there will be a final
refactoring of sparc32_dma_init() once this work is complete.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/sparc/sun4m.c |   29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 88a9752..4f2ed4b 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -307,8 +307,7 @@ static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
     return s;
 }
 
-static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
-                              void *iommu, qemu_irq *dev_irq, int is_ledma)
+static void *sparc32_dma_init(hwaddr daddr, void *iommu, int is_ledma)
 {
     DeviceState *dev;
     SysBusDevice *s;
@@ -317,8 +316,6 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
     qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
     qdev_init_nofail(dev);
     s = SYS_BUS_DEVICE(dev);
-    sysbus_connect_irq(s, 0, parent_irq);
-    *dev_irq = qdev_get_gpio_in(dev, 0);
     sysbus_mmio_map(s, 0, daddr);
 
     return s;
@@ -821,9 +818,10 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     DeviceState *slavio_intctl;
     const char *cpu_model = machine->cpu_model;
     unsigned int i;
-    void *iommu, *espdma, *ledma, *nvram;
-    qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
-        espdma_irq, ledma_irq;
+    void *iommu, *nvram;
+    DeviceState *espdma, *ledma;
+    SysBusDevice *sbd;
+    qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
     qemu_irq esp_reset, dma_enable;
     qemu_irq fdc_tc;
     unsigned long kernel_size;
@@ -882,11 +880,13 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
         empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
     }
 
-    espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
-                              iommu, &espdma_irq, 0);
+    espdma = sparc32_dma_init(hwdef->dma_base, iommu, 0);
+    sbd = SYS_BUS_DEVICE(espdma);
+    sysbus_connect_irq(sbd, 0, slavio_irq[18]);
 
-    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
-                             slavio_irq[16], iommu, &ledma_irq, 1);
+    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL, iommu, 1);
+    sbd = SYS_BUS_DEVICE(ledma);
+    sysbus_connect_irq(sbd, 0, slavio_irq[16]);
 
     if (graphic_depth != 8 && graphic_depth != 24) {
         error_report("Unsupported depth: %d", graphic_depth);
@@ -939,7 +939,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
         empty_slot_init(hwdef->sx_base, 0x2000);
     }
 
-    lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
+    lance_init(&nd_table[0], hwdef->le_base, ledma,
+               qdev_get_gpio_in(ledma, 0));
 
     nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 1968, 8);
 
@@ -971,7 +972,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
 
     esp_init(hwdef->esp_base, 2,
              espdma_memory_read, espdma_memory_write,
-             espdma, espdma_irq, &esp_reset, &dma_enable);
+             espdma,
+             qdev_get_gpio_in(espdma, 0),
+             &esp_reset, &dma_enable);
 
     qdev_connect_gpio_out(espdma, 0, esp_reset);
     qdev_connect_gpio_out(espdma, 1, dma_enable);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (3 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 04/13] sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init() Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-19  4:37   ` Philippe Mathieu-Daudé
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 06/13] sparc32_dma: use object link instead of qdev property to pass IOMMU reference Mark Cave-Ayland
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This is in preparation to allow the type to be used elsewhere.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sun4m_iommu.c     |   14 --------------
 include/hw/sparc/sun4m.h |   16 ++++++++++++++++
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/hw/dma/sun4m_iommu.c b/hw/dma/sun4m_iommu.c
index 335ef63..840064b 100644
--- a/hw/dma/sun4m_iommu.c
+++ b/hw/dma/sun4m_iommu.c
@@ -36,7 +36,6 @@
  * http://mediacast.sun.com/users/Barton808/media/Sun4M_SystemArchitecture_edited2.pdf
  */
 
-#define IOMMU_NREGS         (4*4096/4)
 #define IOMMU_CTRL          (0x0000 >> 2)
 #define IOMMU_CTRL_IMPL     0xf0000000 /* Implementation */
 #define IOMMU_CTRL_VERS     0x0f000000 /* Version */
@@ -128,19 +127,6 @@
 #define IOMMU_PAGE_SIZE     (1 << IOMMU_PAGE_SHIFT)
 #define IOMMU_PAGE_MASK     ~(IOMMU_PAGE_SIZE - 1)
 
-#define TYPE_SUN4M_IOMMU "iommu"
-#define SUN4M_IOMMU(obj) OBJECT_CHECK(IOMMUState, (obj), TYPE_SUN4M_IOMMU)
-
-typedef struct IOMMUState {
-    SysBusDevice parent_obj;
-
-    MemoryRegion iomem;
-    uint32_t regs[IOMMU_NREGS];
-    hwaddr iostart;
-    qemu_irq irq;
-    uint32_t version;
-} IOMMUState;
-
 static uint64_t iommu_mem_read(void *opaque, hwaddr addr,
                                unsigned size)
 {
diff --git a/include/hw/sparc/sun4m.h b/include/hw/sparc/sun4m.h
index 580d87b..1f1cf91 100644
--- a/include/hw/sparc/sun4m.h
+++ b/include/hw/sparc/sun4m.h
@@ -4,10 +4,26 @@
 #include "qemu-common.h"
 #include "exec/hwaddr.h"
 #include "qapi/qmp/types.h"
+#include "hw/sysbus.h"
 
 /* Devices used by sparc32 system.  */
 
 /* iommu.c */
+#define TYPE_SUN4M_IOMMU "iommu"
+#define SUN4M_IOMMU(obj) OBJECT_CHECK(IOMMUState, (obj), TYPE_SUN4M_IOMMU)
+
+#define IOMMU_NREGS         (4 * 4096 / 4)
+
+typedef struct IOMMUState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    uint32_t regs[IOMMU_NREGS];
+    hwaddr iostart;
+    qemu_irq irq;
+    uint32_t version;
+} IOMMUState;
+
 void sparc_iommu_memory_rw(void *opaque, hwaddr addr,
                                  uint8_t *buf, int len, int is_write);
 static inline void sparc_iommu_memory_read(void *opaque,
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 06/13] sparc32_dma: use object link instead of qdev property to pass IOMMU reference
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (4 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-19  4:38   ` Philippe Mathieu-Daudé
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 07/13] esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h Mark Cave-Ayland
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This enables us to remove the last remaining (opaque) qdev property. Whilst we
are here, also update iommu_init() to use TYPE_SUN4M_IOMMU instead of a
hardcoded string.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c |   13 +++++--------
 hw/sparc/sun4m.c     |    4 ++--
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index ae8fa06..c56a2ba 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -263,24 +263,21 @@ static void sparc32_dma_device_init(Object *obj)
 
     sysbus_init_mmio(sbd, &s->iomem);
 
+    object_property_add_link(OBJECT(dev), "iommu", TYPE_SUN4M_IOMMU,
+                             (Object **) &s->iommu,
+                             qdev_prop_allow_set_link_before_realize,
+                             0, NULL);
+
     qdev_init_gpio_in(dev, dma_set_irq, 1);
     qdev_init_gpio_out(dev, s->gpio, 2);
 }
 
-static Property sparc32_dma_device_properties[] = {
-    DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->reset = sparc32_dma_device_reset;
     dc->vmsd = &vmstate_sparc32_dma_device;
-    dc->props = sparc32_dma_device_properties;
-    /* Reason: pointer property "iommu_opaque" */
-    dc->user_creatable = false;
 }
 
 static const TypeInfo sparc32_dma_device_info = {
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 4f2ed4b..12d36b5 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -297,7 +297,7 @@ static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_create(NULL, "iommu");
+    dev = qdev_create(NULL, TYPE_SUN4M_IOMMU);
     qdev_prop_set_uint32(dev, "version", version);
     qdev_init_nofail(dev);
     s = SYS_BUS_DEVICE(dev);
@@ -313,7 +313,7 @@ static void *sparc32_dma_init(hwaddr daddr, void *iommu, int is_ledma)
     SysBusDevice *s;
 
     dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");
-    qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
+    object_property_set_link(OBJECT(dev), OBJECT(iommu), "iommu", &error_abort);
     qdev_init_nofail(dev);
     s = SYS_BUS_DEVICE(dev);
     sysbus_mmio_map(s, 0, daddr);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 07/13] esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (5 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 06/13] sparc32_dma: use object link instead of qdev property to pass IOMMU reference Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-25 10:42   ` Peter Maydell
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 08/13] sparc32_dma: make esp device child of espdma device Mark Cave-Ayland
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland, Paolo Bonzini

This enables them to be used outside of esp.c.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
CC: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi/esp.c         |   13 -------------
 include/hw/scsi/esp.h |   14 ++++++++++++++
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 22c2d91..ee586e7 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -592,19 +592,6 @@ const VMStateDescription vmstate_esp = {
     }
 };
 
-#define TYPE_ESP "esp"
-#define ESP_STATE(obj) OBJECT_CHECK(SysBusESPState, (obj), TYPE_ESP)
-
-typedef struct {
-    /*< private >*/
-    SysBusDevice parent_obj;
-    /*< public >*/
-
-    MemoryRegion iomem;
-    uint32_t it_shift;
-    ESPState esp;
-} SysBusESPState;
-
 static void sysbus_esp_mem_write(void *opaque, hwaddr addr,
                                  uint64_t val, unsigned int size)
 {
diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
index d2c4886..3b160f8 100644
--- a/include/hw/scsi/esp.h
+++ b/include/hw/scsi/esp.h
@@ -2,6 +2,7 @@
 #define QEMU_HW_ESP_H
 
 #include "hw/scsi/scsi.h"
+#include "hw/sysbus.h"
 
 /* esp.c */
 #define ESP_MAX_DEVS 7
@@ -52,6 +53,19 @@ struct ESPState {
     void (*dma_cb)(ESPState *s);
 };
 
+#define TYPE_ESP "esp"
+#define ESP_STATE(obj) OBJECT_CHECK(SysBusESPState, (obj), TYPE_ESP)
+
+typedef struct {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
+    MemoryRegion iomem;
+    uint32_t it_shift;
+    ESPState esp;
+} SysBusESPState;
+
 #define ESP_TCLO   0x0
 #define ESP_TCMID  0x1
 #define ESP_FIFO   0x2
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 08/13] sparc32_dma: make esp device child of espdma device
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (6 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 07/13] esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 09/13] lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h Mark Cave-Ayland
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This makes it possible to reference the esp device from the espdma device as
required, and by wiring up the device ourselves in sun4m.c we can drop use
of the esp_init() function.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c           |   26 ++++++++++++++++++++++++++
 hw/sparc/sun4m.c               |   19 ++++++++-----------
 include/hw/sparc/sparc32_dma.h |    3 +++
 3 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index c56a2ba..6009b94 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -298,11 +298,37 @@ static void sparc32_espdma_device_init(Object *obj)
     s->is_ledma = 0;
 }
 
+static void sparc32_espdma_device_realize(DeviceState *dev, Error **errp)
+{
+    DeviceState *d;
+    SysBusESPState *sysbus;
+    ESPState *esp;
+
+    d = qdev_create(NULL, TYPE_ESP);
+    object_property_add_child(OBJECT(dev), "esp", OBJECT(d), errp);
+    sysbus = ESP_STATE(d);
+    esp = &sysbus->esp;
+    esp->dma_memory_read = espdma_memory_read;
+    esp->dma_memory_write = espdma_memory_write;
+    esp->dma_opaque = SPARC32_DMA_DEVICE(dev);
+    sysbus->it_shift = 2;
+    esp->dma_enabled = 1;
+    qdev_init_nofail(d);
+}
+
+static void sparc32_espdma_device_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = sparc32_espdma_device_realize;
+}
+
 static const TypeInfo sparc32_espdma_device_info = {
     .name          = TYPE_SPARC32_ESPDMA_DEVICE,
     .parent        = TYPE_SPARC32_DMA_DEVICE,
     .instance_size = sizeof(ESPDMADeviceState),
     .instance_init = sparc32_espdma_device_init,
+    .class_init    = sparc32_espdma_device_class_init,
 };
 
 static void sparc32_ledma_device_init(Object *obj)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 12d36b5..4626c85 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -819,10 +819,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     const char *cpu_model = machine->cpu_model;
     unsigned int i;
     void *iommu, *nvram;
-    DeviceState *espdma, *ledma;
+    DeviceState *espdma, *esp, *ledma;
     SysBusDevice *sbd;
     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
-    qemu_irq esp_reset, dma_enable;
     qemu_irq fdc_tc;
     unsigned long kernel_size;
     DriveInfo *fd[MAX_FD];
@@ -884,6 +883,13 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     sbd = SYS_BUS_DEVICE(espdma);
     sysbus_connect_irq(sbd, 0, slavio_irq[18]);
 
+    esp = DEVICE(object_resolve_path_component(OBJECT(espdma), "esp"));
+    sbd = SYS_BUS_DEVICE(esp);
+    sysbus_mmio_map(sbd, 0, hwdef->esp_base);
+    sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(espdma, 0));
+    qdev_connect_gpio_out(espdma, 0, qdev_get_gpio_in(esp, 0));
+    qdev_connect_gpio_out(espdma, 1, qdev_get_gpio_in(esp, 1));
+
     ledma = sparc32_dma_init(hwdef->dma_base + 16ULL, iommu, 1);
     sbd = SYS_BUS_DEVICE(ledma);
     sysbus_connect_irq(sbd, 0, slavio_irq[16]);
@@ -970,15 +976,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
                      slavio_irq[30], fdc_tc);
 
-    esp_init(hwdef->esp_base, 2,
-             espdma_memory_read, espdma_memory_write,
-             espdma,
-             qdev_get_gpio_in(espdma, 0),
-             &esp_reset, &dma_enable);
-
-    qdev_connect_gpio_out(espdma, 0, esp_reset);
-    qdev_connect_gpio_out(espdma, 1, dma_enable);
-
     if (hwdef->cs_base) {
         sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
                              slavio_irq[5]);
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index df7491d..365160f 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -2,6 +2,7 @@
 #define SPARC32_DMA_H
 
 #include "hw/sysbus.h"
+#include "hw/scsi/esp.h"
 
 #define DMA_REGS 4
 
@@ -28,6 +29,8 @@ struct DMADeviceState {
 
 typedef struct ESPDMADeviceState {
     DMADeviceState parent_obj;
+
+    SysBusESPState *esp;
 } ESPDMADeviceState;
 
 #define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 09/13] lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (7 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 08/13] sparc32_dma: make esp device child of espdma device Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-25 10:44   ` Peter Maydell
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 10/13] sparc32_dma: make lance device child of ledma device Mark Cave-Ayland
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland, Jason Wang

This enables them to be used outside of lance.c.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
CC: Jason Wang <jasowang@redhat.com>
---
 hw/net/lance.c           |    9 ---------
 include/hw/sparc/sun4m.h |   13 +++++++++++++
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/hw/net/lance.c b/hw/net/lance.c
index 92b0c68..ef7747d 100644
--- a/hw/net/lance.c
+++ b/hw/net/lance.c
@@ -45,15 +45,6 @@
 #include "trace.h"
 #include "sysemu/sysemu.h"
 
-#define TYPE_LANCE "lance"
-#define SYSBUS_PCNET(obj) \
-    OBJECT_CHECK(SysBusPCNetState, (obj), TYPE_LANCE)
-
-typedef struct {
-    SysBusDevice parent_obj;
-
-    PCNetState state;
-} SysBusPCNetState;
 
 static void parent_lance_reset(void *opaque, int irq, int level)
 {
diff --git a/include/hw/sparc/sun4m.h b/include/hw/sparc/sun4m.h
index 1f1cf91..a4f5f09 100644
--- a/include/hw/sparc/sun4m.h
+++ b/include/hw/sparc/sun4m.h
@@ -5,6 +5,8 @@
 #include "exec/hwaddr.h"
 #include "qapi/qmp/types.h"
 #include "hw/sysbus.h"
+#include "net/net.h"
+#include "hw/net/pcnet.h"
 
 /* Devices used by sparc32 system.  */
 
@@ -40,6 +42,17 @@ static inline void sparc_iommu_memory_write(void *opaque,
     sparc_iommu_memory_rw(opaque, addr, buf, len, 1);
 }
 
+/* lance.c */
+#define TYPE_LANCE "lance"
+#define SYSBUS_PCNET(obj) \
+    OBJECT_CHECK(SysBusPCNetState, (obj), TYPE_LANCE)
+
+typedef struct {
+    SysBusDevice parent_obj;
+
+    PCNetState state;
+} SysBusPCNetState;
+
 /* sparc32_dma.c */
 #include "hw/sparc/sparc32_dma.h"
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 10/13] sparc32_dma: make lance device child of ledma device
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (8 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 09/13] lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h Mark Cave-Ayland
@ 2017-10-14 18:38 ` Mark Cave-Ayland
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 11/13] sparc32_dma: introduce new SPARC32_DMA type container object Mark Cave-Ayland
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:38 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This makes it possible to reference the lance device from the ledma device as
required.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c           |   23 ++++++++++++++++++++++-
 hw/sparc/sun4m.c               |   31 +++++++------------------------
 include/hw/sparc/sparc32_dma.h |    3 +++
 3 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index 6009b94..d507ca3 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -28,7 +28,6 @@
 #include "qemu/osdep.h"
 #include "hw/hw.h"
 #include "hw/sparc/sparc32_dma.h"
-#include "hw/sparc/sun4m.h"
 #include "hw/sysbus.h"
 #include "trace.h"
 
@@ -340,11 +339,33 @@ static void sparc32_ledma_device_init(Object *obj)
     s->is_ledma = 1;
 }
 
+static void sparc32_ledma_device_realize(DeviceState *dev, Error **errp)
+{
+    DeviceState *d;
+    NICInfo *nd = &nd_table[0];
+
+    qemu_check_nic_model(nd, "lance");
+
+    d = qdev_create(NULL, "lance");
+    object_property_add_child(OBJECT(dev), "lance", OBJECT(d), errp);
+    qdev_set_nic_properties(d, nd);
+    qdev_prop_set_ptr(d, "dma", dev);
+    qdev_init_nofail(d);
+}
+
+static void sparc32_ledma_device_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = sparc32_ledma_device_realize;
+}
+
 static const TypeInfo sparc32_ledma_device_info = {
     .name          = TYPE_SPARC32_LEDMA_DEVICE,
     .parent        = TYPE_SPARC32_DMA_DEVICE,
     .instance_size = sizeof(LEDMADeviceState),
     .instance_init = sparc32_ledma_device_init,
+    .class_init    = sparc32_ledma_device_class_init,
 };
 
 static void sparc32_dma_register_types(void)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 4626c85..ae486a4 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -321,26 +321,6 @@ static void *sparc32_dma_init(hwaddr daddr, void *iommu, int is_ledma)
     return s;
 }
 
-static void lance_init(NICInfo *nd, hwaddr leaddr,
-                       void *dma_opaque, qemu_irq irq)
-{
-    DeviceState *dev;
-    SysBusDevice *s;
-    qemu_irq reset;
-
-    qemu_check_nic_model(&nd_table[0], "lance");
-
-    dev = qdev_create(NULL, "lance");
-    qdev_set_nic_properties(dev, nd);
-    qdev_prop_set_ptr(dev, "dma", dma_opaque);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    sysbus_mmio_map(s, 0, leaddr);
-    sysbus_connect_irq(s, 0, irq);
-    reset = qdev_get_gpio_in(dev, 0);
-    qdev_connect_gpio_out(dma_opaque, 0, reset);
-}
-
 static DeviceState *slavio_intctl_init(hwaddr addr,
                                        hwaddr addrg,
                                        qemu_irq **parent_irq)
@@ -819,7 +799,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     const char *cpu_model = machine->cpu_model;
     unsigned int i;
     void *iommu, *nvram;
-    DeviceState *espdma, *esp, *ledma;
+    DeviceState *espdma, *esp, *ledma, *lance;
     SysBusDevice *sbd;
     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
     qemu_irq fdc_tc;
@@ -894,6 +874,12 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     sbd = SYS_BUS_DEVICE(ledma);
     sysbus_connect_irq(sbd, 0, slavio_irq[16]);
 
+    lance = DEVICE(object_resolve_path_component(OBJECT(ledma), "lance"));
+    sbd = SYS_BUS_DEVICE(lance);
+    sysbus_mmio_map(sbd, 0, hwdef->le_base);
+    sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(ledma, 0));
+    qdev_connect_gpio_out(ledma, 0, qdev_get_gpio_in(lance, 0));
+
     if (graphic_depth != 8 && graphic_depth != 24) {
         error_report("Unsupported depth: %d", graphic_depth);
         exit (1);
@@ -945,9 +931,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
         empty_slot_init(hwdef->sx_base, 0x2000);
     }
 
-    lance_init(&nd_table[0], hwdef->le_base, ledma,
-               qdev_get_gpio_in(ledma, 0));
-
     nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index 365160f..5f39c28 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -3,6 +3,7 @@
 
 #include "hw/sysbus.h"
 #include "hw/scsi/esp.h"
+#include "hw/sparc/sun4m.h"
 
 #define DMA_REGS 4
 
@@ -39,6 +40,8 @@ typedef struct ESPDMADeviceState {
 
 typedef struct LEDMADeviceState {
     DMADeviceState parent_obj;
+
+    SysBusPCNetState *lance;
 } LEDMADeviceState;
 
 /* sparc32_dma.c */
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 11/13] sparc32_dma: introduce new SPARC32_DMA type container object
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (9 preceding siblings ...)
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 10/13] sparc32_dma: make lance device child of ledma device Mark Cave-Ayland
@ 2017-10-14 18:39 ` Mark Cave-Ayland
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 12/13] sparc32_dma: remove is_ledma hack and replace with memory region alias Mark Cave-Ayland
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:39 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

Create a new SPARC32_DMA container object (including an appropriate container
memory region) and add instances of the SPARC32_ESPDMA_DEVICE and
SPARC32_LEDMA_DEVICE as child objects. The benefit is that most of the gpio
wiring complexity between esp/espdma and lance/ledma is now hidden within the
SPARC32_DMA realize function.

Since the sun4m IOMMU is already QOMified we can find a reference to
it using object_resolve_path_type() allowing us to completely remove all external
references to the iommu pointer.

Finally we rework sun4m's sparc32_dma_init() to invoke the new SPARC32_DMA object
and wire up the remaining board memory regions/IRQs.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c           |   70 ++++++++++++++++++++++++++++++++++++++++
 hw/sparc/sun4m.c               |   66 ++++++++++++++++++-------------------
 include/hw/sparc/sparc32_dma.h |   12 +++++++
 3 files changed, 114 insertions(+), 34 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index d507ca3..ba62927 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -29,6 +29,7 @@
 #include "hw/hw.h"
 #include "hw/sparc/sparc32_dma.h"
 #include "hw/sysbus.h"
+#include "qapi/error.h"
 #include "trace.h"
 
 /*
@@ -368,11 +369,80 @@ static const TypeInfo sparc32_ledma_device_info = {
     .class_init    = sparc32_ledma_device_class_init,
 };
 
+static void sparc32_dma_realize(DeviceState *dev, Error **errp)
+{
+    SPARC32DMAState *s = SPARC32_DMA(dev);
+    DeviceState *espdma, *esp, *ledma, *lance;
+    SysBusDevice *sbd;
+    Object *iommu;
+
+    iommu = object_resolve_path_type("", TYPE_SUN4M_IOMMU, NULL);
+    if (!iommu) {
+        error_setg(errp, "unable to locate sun4m IOMMU device");
+        return;
+    }
+
+    espdma = qdev_create(NULL, TYPE_SPARC32_ESPDMA_DEVICE);
+    object_property_set_link(OBJECT(espdma), iommu, "iommu", errp);
+    object_property_add_child(OBJECT(s), "espdma", OBJECT(espdma), errp);
+    qdev_init_nofail(espdma);
+
+    esp = DEVICE(object_resolve_path_component(OBJECT(espdma), "esp"));
+    sbd = SYS_BUS_DEVICE(esp);
+    sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(espdma, 0));
+    qdev_connect_gpio_out(espdma, 0, qdev_get_gpio_in(esp, 0));
+    qdev_connect_gpio_out(espdma, 1, qdev_get_gpio_in(esp, 1));
+
+    sbd = SYS_BUS_DEVICE(espdma);
+    memory_region_add_subregion(&s->dmamem, 0x0,
+                                sysbus_mmio_get_region(sbd, 0));
+
+    ledma = qdev_create(NULL, TYPE_SPARC32_LEDMA_DEVICE);
+    object_property_set_link(OBJECT(ledma), iommu, "iommu", errp);
+    object_property_add_child(OBJECT(s), "ledma", OBJECT(ledma), errp);
+    qdev_init_nofail(ledma);
+
+    lance = DEVICE(object_resolve_path_component(OBJECT(ledma), "lance"));
+    sbd = SYS_BUS_DEVICE(lance);
+    sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(ledma, 0));
+    qdev_connect_gpio_out(ledma, 0, qdev_get_gpio_in(lance, 0));
+
+    sbd = SYS_BUS_DEVICE(ledma);
+    memory_region_add_subregion(&s->dmamem, 0x10,
+                                sysbus_mmio_get_region(sbd, 0));
+}
+
+static void sparc32_dma_init(Object *obj)
+{
+    SPARC32DMAState *s = SPARC32_DMA(obj);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+
+    memory_region_init(&s->dmamem, OBJECT(s), "dma", DMA_SIZE + DMA_ETH_SIZE);
+    sysbus_init_mmio(sbd, &s->dmamem);
+}
+
+static void sparc32_dma_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = sparc32_dma_realize;
+}
+
+static const TypeInfo sparc32_dma_info = {
+    .name          = TYPE_SPARC32_DMA,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(SPARC32DMAState),
+    .instance_init = sparc32_dma_init,
+    .class_init    = sparc32_dma_class_init,
+};
+
+
 static void sparc32_dma_register_types(void)
 {
     type_register_static(&sparc32_dma_device_info);
     type_register_static(&sparc32_espdma_device_info);
     type_register_static(&sparc32_ledma_device_info);
+    type_register_static(&sparc32_dma_info);
 }
 
 type_init(sparc32_dma_register_types)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index ae486a4..5017ae5 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -307,18 +307,36 @@ static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
     return s;
 }
 
-static void *sparc32_dma_init(hwaddr daddr, void *iommu, int is_ledma)
+static void *sparc32_dma_init(hwaddr dma_base,
+                              hwaddr esp_base, qemu_irq espdma_irq,
+                              hwaddr le_base, qemu_irq ledma_irq)
 {
-    DeviceState *dev;
-    SysBusDevice *s;
+    DeviceState *dma;
+    ESPDMADeviceState *espdma;
+    LEDMADeviceState *ledma;
+    SysBusESPState *esp;
+    SysBusPCNetState *lance;
 
-    dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");
-    object_property_set_link(OBJECT(dev), OBJECT(iommu), "iommu", &error_abort);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    sysbus_mmio_map(s, 0, daddr);
+    dma = qdev_create(NULL, TYPE_SPARC32_DMA);
+    qdev_init_nofail(dma);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dma), 0, dma_base);
 
-    return s;
+    espdma = SPARC32_ESPDMA_DEVICE(object_resolve_path_component(
+                                   OBJECT(dma), "espdma"));
+    sysbus_connect_irq(SYS_BUS_DEVICE(espdma), 0, espdma_irq);
+
+    esp = ESP_STATE(object_resolve_path_component(OBJECT(espdma), "esp"));
+    sysbus_mmio_map(SYS_BUS_DEVICE(esp), 0, esp_base);
+
+    ledma = SPARC32_LEDMA_DEVICE(object_resolve_path_component(
+                                 OBJECT(dma), "ledma"));
+    sysbus_connect_irq(SYS_BUS_DEVICE(ledma), 0, ledma_irq);
+
+    lance = SYSBUS_PCNET(object_resolve_path_component(
+                         OBJECT(ledma), "lance"));
+    sysbus_mmio_map(SYS_BUS_DEVICE(lance), 0, le_base);
+
+    return dma;
 }
 
 static DeviceState *slavio_intctl_init(hwaddr addr,
@@ -798,9 +816,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     DeviceState *slavio_intctl;
     const char *cpu_model = machine->cpu_model;
     unsigned int i;
-    void *iommu, *nvram;
-    DeviceState *espdma, *esp, *ledma, *lance;
-    SysBusDevice *sbd;
+    void *nvram;
     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
     qemu_irq fdc_tc;
     unsigned long kernel_size;
@@ -848,8 +864,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
         afx_init(hwdef->afx_base);
     }
 
-    iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
-                       slavio_irq[30]);
+    iommu_init(hwdef->iommu_base, hwdef->iommu_version, slavio_irq[30]);
 
     if (hwdef->iommu_pad_base) {
         /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
@@ -859,26 +874,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
         empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
     }
 
-    espdma = sparc32_dma_init(hwdef->dma_base, iommu, 0);
-    sbd = SYS_BUS_DEVICE(espdma);
-    sysbus_connect_irq(sbd, 0, slavio_irq[18]);
-
-    esp = DEVICE(object_resolve_path_component(OBJECT(espdma), "esp"));
-    sbd = SYS_BUS_DEVICE(esp);
-    sysbus_mmio_map(sbd, 0, hwdef->esp_base);
-    sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(espdma, 0));
-    qdev_connect_gpio_out(espdma, 0, qdev_get_gpio_in(esp, 0));
-    qdev_connect_gpio_out(espdma, 1, qdev_get_gpio_in(esp, 1));
-
-    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL, iommu, 1);
-    sbd = SYS_BUS_DEVICE(ledma);
-    sysbus_connect_irq(sbd, 0, slavio_irq[16]);
-
-    lance = DEVICE(object_resolve_path_component(OBJECT(ledma), "lance"));
-    sbd = SYS_BUS_DEVICE(lance);
-    sysbus_mmio_map(sbd, 0, hwdef->le_base);
-    sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(ledma, 0));
-    qdev_connect_gpio_out(ledma, 0, qdev_get_gpio_in(lance, 0));
+    sparc32_dma_init(hwdef->dma_base,
+                     hwdef->esp_base, slavio_irq[18],
+                     hwdef->le_base, slavio_irq[16]);
 
     if (graphic_depth != 8 && graphic_depth != 24) {
         error_report("Unsupported depth: %d", graphic_depth);
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index 5f39c28..e52cd1d 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -44,6 +44,18 @@ typedef struct LEDMADeviceState {
     SysBusPCNetState *lance;
 } LEDMADeviceState;
 
+#define TYPE_SPARC32_DMA "sparc32-dma"
+#define SPARC32_DMA(obj) OBJECT_CHECK(SPARC32DMAState, (obj), \
+                                      TYPE_SPARC32_DMA)
+
+typedef struct SPARC32DMAState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion dmamem;
+    ESPDMADeviceState *espdma;
+    LEDMADeviceState *ledma;
+} SPARC32DMAState;
+
 /* sparc32_dma.c */
 void ledma_memory_read(void *opaque, hwaddr addr,
                        uint8_t *buf, int len, int do_bswap);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 12/13] sparc32_dma: remove is_ledma hack and replace with memory region alias
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (10 preceding siblings ...)
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 11/13] sparc32_dma: introduce new SPARC32_DMA type container object Mark Cave-Ayland
@ 2017-10-14 18:39 ` Mark Cave-Ayland
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 13/13] sparc32_dma: add len to esp/le DMA memory tracing Mark Cave-Ayland
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:39 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This hack originated from before the memory region API was introduced, and
increased the size of the ledma DMA device to capture incorrect accesses
beyond the end of the ledma device. A full analysis can be found on Artyom's
blog at http://tyom.blogspot.co.uk/2010/10/bug-in-all-solaris-versions-after-57.html.

With the memory API we can now simply alias the incorrect access onto its
intended destination allowing us to remove the hack.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c           |   20 ++++++--------------
 include/hw/sparc/sparc32_dma.h |    2 +-
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index ba62927..bb7d70a 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -159,12 +159,6 @@ static uint64_t dma_mem_read(void *opaque, hwaddr addr,
     DMADeviceState *s = opaque;
     uint32_t saddr;
 
-    if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
-        /* aliased to espdma, but we can't get there from here */
-        /* buggy driver if using undocumented behavior, just return 0 */
-        trace_sparc32_dma_mem_readl(addr, 0);
-        return 0;
-    }
     saddr = (addr & DMA_MASK) >> 2;
     trace_sparc32_dma_mem_readl(addr, s->dmaregs[saddr]);
     return s->dmaregs[saddr];
@@ -176,11 +170,6 @@ static void dma_mem_write(void *opaque, hwaddr addr,
     DMADeviceState *s = opaque;
     uint32_t saddr;
 
-    if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
-        /* aliased to espdma, but we can't get there from here */
-        trace_sparc32_dma_mem_writel(addr, 0, val);
-        return;
-    }
     saddr = (addr & DMA_MASK) >> 2;
     trace_sparc32_dma_mem_writel(addr, s->dmaregs[saddr], val);
     switch (saddr) {
@@ -295,7 +284,6 @@ static void sparc32_espdma_device_init(Object *obj)
 
     memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
                           "espdma-mmio", DMA_SIZE);
-    s->is_ledma = 0;
 }
 
 static void sparc32_espdma_device_realize(DeviceState *dev, Error **errp)
@@ -336,8 +324,7 @@ static void sparc32_ledma_device_init(Object *obj)
     DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
-                          "ledma-mmio", DMA_ETH_SIZE);
-    s->is_ledma = 1;
+                          "ledma-mmio", DMA_SIZE);
 }
 
 static void sparc32_ledma_device_realize(DeviceState *dev, Error **errp)
@@ -410,6 +397,11 @@ static void sparc32_dma_realize(DeviceState *dev, Error **errp)
     sbd = SYS_BUS_DEVICE(ledma);
     memory_region_add_subregion(&s->dmamem, 0x10,
                                 sysbus_mmio_get_region(sbd, 0));
+
+    /* Add ledma alias to handle SunOS 5.7 - Solaris 9 invalid access bug */
+    memory_region_init_alias(&s->ledma_alias, OBJECT(dev), "ledma-alias",
+                             sysbus_mmio_get_region(sbd, 0), 0x4, 0x4);
+    memory_region_add_subregion(&s->dmamem, 0x20, &s->ledma_alias);
 }
 
 static void sparc32_dma_init(Object *obj)
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index e52cd1d..f78180f 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -21,7 +21,6 @@ struct DMADeviceState {
     qemu_irq irq;
     void *iommu;
     qemu_irq gpio[2];
-    uint32_t is_ledma;
 };
 
 #define TYPE_SPARC32_ESPDMA_DEVICE "sparc32-espdma"
@@ -52,6 +51,7 @@ typedef struct SPARC32DMAState {
     SysBusDevice parent_obj;
 
     MemoryRegion dmamem;
+    MemoryRegion ledma_alias;
     ESPDMADeviceState *espdma;
     LEDMADeviceState *ledma;
 } SPARC32DMAState;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [Qemu-devel] [PATCHv3 13/13] sparc32_dma: add len to esp/le DMA memory tracing
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (11 preceding siblings ...)
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 12/13] sparc32_dma: remove is_ledma hack and replace with memory region alias Mark Cave-Ayland
@ 2017-10-14 18:39 ` Mark Cave-Ayland
  2017-10-19  4:45   ` Philippe Mathieu-Daudé
  2017-10-14 19:23 ` [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups no-reply
  2017-10-18  9:12 ` Artyom Tarasenko
  14 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-14 18:39 UTC (permalink / raw)
  To: qemu-devel, atar4qemu; +Cc: Mark Cave-Ayland

This is surprisingly useful when trying to debug DMA issues.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c |    8 ++++----
 hw/dma/trace-events  |    8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index bb7d70a..fbb072a 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -73,7 +73,7 @@ void ledma_memory_read(void *opaque, hwaddr addr,
     int i;
 
     addr |= s->dmaregs[3];
-    trace_ledma_memory_read(addr);
+    trace_ledma_memory_read(addr, len);
     if (do_bswap) {
         sparc_iommu_memory_read(s->iommu, addr, buf, len);
     } else {
@@ -94,7 +94,7 @@ void ledma_memory_write(void *opaque, hwaddr addr,
     uint16_t tmp_buf[32];
 
     addr |= s->dmaregs[3];
-    trace_ledma_memory_write(addr);
+    trace_ledma_memory_write(addr, len);
     if (do_bswap) {
         sparc_iommu_memory_write(s->iommu, addr, buf, len);
     } else {
@@ -139,7 +139,7 @@ void espdma_memory_read(void *opaque, uint8_t *buf, int len)
 {
     DMADeviceState *s = opaque;
 
-    trace_espdma_memory_read(s->dmaregs[1]);
+    trace_espdma_memory_read(s->dmaregs[1], len);
     sparc_iommu_memory_read(s->iommu, s->dmaregs[1], buf, len);
     s->dmaregs[1] += len;
 }
@@ -148,7 +148,7 @@ void espdma_memory_write(void *opaque, uint8_t *buf, int len)
 {
     DMADeviceState *s = opaque;
 
-    trace_espdma_memory_write(s->dmaregs[1]);
+    trace_espdma_memory_write(s->dmaregs[1], len);
     sparc_iommu_memory_write(s->iommu, s->dmaregs[1], buf, len);
     s->dmaregs[1] += len;
 }
diff --git a/hw/dma/trace-events b/hw/dma/trace-events
index 428469a..6b367f0 100644
--- a/hw/dma/trace-events
+++ b/hw/dma/trace-events
@@ -7,12 +7,12 @@ rc4030_read(uint64_t addr, uint32_t ret) "read reg[0x%"PRIx64"] = 0x%x"
 rc4030_write(uint64_t addr, uint32_t val) "write reg[0x%"PRIx64"] = 0x%x"
 
 # hw/dma/sparc32_dma.c
-ledma_memory_read(uint64_t addr) "DMA read addr 0x%"PRIx64
-ledma_memory_write(uint64_t addr) "DMA write addr 0x%"PRIx64
+ledma_memory_read(uint64_t addr, int len) "DMA read addr 0x%"PRIx64 " len %d"
+ledma_memory_write(uint64_t addr, int len) "DMA write addr 0x%"PRIx64 " len %d"
 sparc32_dma_set_irq_raise(void) "Raise IRQ"
 sparc32_dma_set_irq_lower(void) "Lower IRQ"
-espdma_memory_read(uint32_t addr) "DMA read addr 0x%08x"
-espdma_memory_write(uint32_t addr) "DMA write addr 0x%08x"
+espdma_memory_read(uint32_t addr, int len) "DMA read addr 0x%08x len %d"
+espdma_memory_write(uint32_t addr, int len) "DMA write addr 0x%08x len %d"
 sparc32_dma_mem_readl(uint64_t addr, uint32_t ret) "read dmareg 0x%"PRIx64": 0x%08x"
 sparc32_dma_mem_writel(uint64_t addr, uint32_t old, uint32_t val) "write dmareg 0x%"PRIx64": 0x%08x -> 0x%08x"
 sparc32_dma_enable_raise(void) "Raise DMA enable"
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (12 preceding siblings ...)
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 13/13] sparc32_dma: add len to esp/le DMA memory tracing Mark Cave-Ayland
@ 2017-10-14 19:23 ` no-reply
  2017-10-15  7:14   ` Mark Cave-Ayland
  2017-10-18  9:12 ` Artyom Tarasenko
  14 siblings, 1 reply; 29+ messages in thread
From: no-reply @ 2017-10-14 19:23 UTC (permalink / raw)
  To: mark.cave-ayland; +Cc: famz, qemu-devel, atar4qemu

Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 1508006342-5304-1-git-send-email-mark.cave-ayland@ilande.co.uk
Subject: [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
49376f2097 sparc32_dma: add len to esp/le DMA memory tracing
d1747b9946 sparc32_dma: remove is_ledma hack and replace with memory region alias
aff708b794 sparc32_dma: introduce new SPARC32_DMA type container object
c1d8e324e2 sparc32_dma: make lance device child of ledma device
89f91116dd lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h
dead665d1d sparc32_dma: make esp device child of espdma device
1afaa63bbd esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h
9e05523632 sparc32_dma: use object link instead of qdev property to pass IOMMU reference
80b9835896 sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
66a36aaa11 sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init()
d2fd9ca3eb sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h
74c5135edf sparc32_dma: split esp and le into separate DMA devices
cc07b7035d sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE

=== OUTPUT BEGIN ===
Checking PATCH 1/13: sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE...
Checking PATCH 2/13: sparc32_dma: split esp and le into separate DMA devices...
Checking PATCH 3/13: sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h...
Checking PATCH 4/13: sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init()...
ERROR: spaces required around that '*' (ctx:WxV)
#51: FILE: hw/sparc/sun4m.c:824:
+    qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
              ^

total: 1 errors, 0 warnings, 66 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 5/13: sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h...
Checking PATCH 6/13: sparc32_dma: use object link instead of qdev property to pass IOMMU reference...
Checking PATCH 7/13: esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h...
Checking PATCH 8/13: sparc32_dma: make esp device child of espdma device...
Checking PATCH 9/13: lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h...
Checking PATCH 10/13: sparc32_dma: make lance device child of ledma device...
Checking PATCH 11/13: sparc32_dma: introduce new SPARC32_DMA type container object...
Checking PATCH 12/13: sparc32_dma: remove is_ledma hack and replace with memory region alias...
Checking PATCH 13/13: sparc32_dma: add len to esp/le DMA memory tracing...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups
  2017-10-14 19:23 ` [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups no-reply
@ 2017-10-15  7:14   ` Mark Cave-Ayland
  0 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-15  7:14 UTC (permalink / raw)
  To: qemu-devel, no-reply; +Cc: famz, atar4qemu

On 14/10/17 20:23, no-reply@patchew.org wrote:

> Hi,
> 
> This series seems to have some coding style problems. See output below for
> more information:
> 
> Type: series
> Message-id: 1508006342-5304-1-git-send-email-mark.cave-ayland@ilande.co.uk
> Subject: [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups
> 
> === TEST SCRIPT BEGIN ===
> #!/bin/bash
> 
> BASE=base
> n=1
> total=$(git log --oneline $BASE.. | wc -l)
> failed=0
> 
> git config --local diff.renamelimit 0
> git config --local diff.renames True
> 
> commits="$(git log --format=%H --reverse $BASE..)"
> for c in $commits; do
>     echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
>     if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
>         failed=1
>         echo
>     fi
>     n=$((n+1))
> done
> 
> exit $failed
> === TEST SCRIPT END ===
> 
> Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
> Switched to a new branch 'test'
> 49376f2097 sparc32_dma: add len to esp/le DMA memory tracing
> d1747b9946 sparc32_dma: remove is_ledma hack and replace with memory region alias
> aff708b794 sparc32_dma: introduce new SPARC32_DMA type container object
> c1d8e324e2 sparc32_dma: make lance device child of ledma device
> 89f91116dd lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h
> dead665d1d sparc32_dma: make esp device child of espdma device
> 1afaa63bbd esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h
> 9e05523632 sparc32_dma: use object link instead of qdev property to pass IOMMU reference
> 80b9835896 sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
> 66a36aaa11 sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init()
> d2fd9ca3eb sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h
> 74c5135edf sparc32_dma: split esp and le into separate DMA devices
> cc07b7035d sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
> 
> === OUTPUT BEGIN ===
> Checking PATCH 1/13: sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE...
> Checking PATCH 2/13: sparc32_dma: split esp and le into separate DMA devices...
> Checking PATCH 3/13: sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h...
> Checking PATCH 4/13: sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init()...
> ERROR: spaces required around that '*' (ctx:WxV)
> #51: FILE: hw/sparc/sun4m.c:824:
> +    qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
>               ^
> 
> total: 1 errors, 0 warnings, 66 lines checked
> 
> Your patch has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
> 
> Checking PATCH 5/13: sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h...
> Checking PATCH 6/13: sparc32_dma: use object link instead of qdev property to pass IOMMU reference...
> Checking PATCH 7/13: esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h...
> Checking PATCH 8/13: sparc32_dma: make esp device child of espdma device...
> Checking PATCH 9/13: lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h...
> Checking PATCH 10/13: sparc32_dma: make lance device child of ledma device...
> Checking PATCH 11/13: sparc32_dma: introduce new SPARC32_DMA type container object...
> Checking PATCH 12/13: sparc32_dma: remove is_ledma hack and replace with memory region alias...
> Checking PATCH 13/13: sparc32_dma: add len to esp/le DMA memory tracing...
> === OUTPUT END ===
> 
> Test command exited with code: 1
> 
> 
> ---
> Email generated automatically by Patchew [http://patchew.org/].
> Please send your feedback to patchew-devel@freelists.org

I had a brief chat with Fam about this on IRC and he agreed it was a
false positive - however I am still confused as to why I don't see this
locally?

>From my github repository at https://github.com/mcayland/qemu.git:

$ git checkout for-fam
Previous HEAD position was f90ea7b... Merge remote-tracking branch
'remotes/pmaydell/tags/pull-target-arm-20171012' into staging
Branch for-fam set up to track remote branch for-fam from mcayland-github.
Switched to a new branch 'for-fam'

$ git format-patch -o /tmp/qemu f90ea7b
/tmp/qemu/0001-sparc32_dma-rename-SPARC32_DMA-type-to-SPARC32_DMA_D.patch
/tmp/qemu/0002-sparc32_dma-split-esp-and-le-into-separate-DMA-devic.patch
/tmp/qemu/0003-sparc32_dma-move-type-declarations-from-sparc32_dma..patch
/tmp/qemu/0004-sun4m-move-DMA-device-wiring-from-sparc32_dma_init-t.patch
/tmp/qemu/0005-sun4m_iommu-move-TYPE_SUN4M_IOMMU-declaration-to-sun.patch
/tmp/qemu/0006-sparc32_dma-use-object-link-instead-of-qdev-property.patch
/tmp/qemu/0007-esp-move-TYPE_ESP-and-SysBusESPState-from-esp.c-to-e.patch
/tmp/qemu/0008-sparc32_dma-make-esp-device-child-of-espdma-device.patch
/tmp/qemu/0009-lance-move-TYPE_LANCE-and-SysBusPCNetState-from-lanc.patch
/tmp/qemu/0010-sparc32_dma-make-lance-device-child-of-ledma-device.patch
/tmp/qemu/0011-sparc32_dma-introduce-new-SPARC32_DMA-type-container.patch
/tmp/qemu/0012-sparc32_dma-remove-is_ledma-hack-and-replace-with-me.patch
/tmp/qemu/0013-sparc32_dma-add-len-to-esp-le-DMA-memory-tracing.patch

$ ./scripts/checkpatch.pl /tmp/qemu/*
total: 0 errors, 0 warnings, 175 lines checked

/tmp/qemu/0001-sparc32_dma-rename-SPARC32_DMA-type-to-SPARC32_DMA_D.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 107 lines checked

/tmp/qemu/0002-sparc32_dma-split-esp-and-le-into-separate-DMA-devic.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 89 lines checked

/tmp/qemu/0003-sparc32_dma-move-type-declarations-from-sparc32_dma..patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 66 lines checked

/tmp/qemu/0004-sun4m-move-DMA-device-wiring-from-sparc32_dma_init-t.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 52 lines checked

/tmp/qemu/0005-sun4m_iommu-move-TYPE_SUN4M_IOMMU-declaration-to-sun.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 45 lines checked

/tmp/qemu/0006-sparc32_dma-use-object-link-instead-of-qdev-property.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 45 lines checked

/tmp/qemu/0007-esp-move-TYPE_ESP-and-SysBusESPState-from-esp.c-to-e.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 91 lines checked

/tmp/qemu/0008-sparc32_dma-make-esp-device-child-of-espdma-device.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 40 lines checked

/tmp/qemu/0009-lance-move-TYPE_LANCE-and-SysBusPCNetState-from-lanc.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 110 lines checked

/tmp/qemu/0010-sparc32_dma-make-lance-device-child-of-ledma-device.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 198 lines checked

/tmp/qemu/0011-sparc32_dma-introduce-new-SPARC32_DMA-type-container.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 64 lines checked

/tmp/qemu/0012-sparc32_dma-remove-is_ledma-hack-and-replace-with-me.patch
has no obvious style problems and is ready for submission.
total: 0 errors, 0 warnings, 48 lines checked

/tmp/qemu/0013-sparc32_dma-add-len-to-esp-le-DMA-memory-tracing.patch
has no obvious style problems and is ready for submission.

So I don't see the warning here at all?

$ md5sum scripts/checkpatch.pl
6c5d64bb35ab9fbe2a2da67d8c151d86  scripts/checkpatch.pl


ATB,

Mark.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups
  2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
                   ` (13 preceding siblings ...)
  2017-10-14 19:23 ` [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups no-reply
@ 2017-10-18  9:12 ` Artyom Tarasenko
  14 siblings, 0 replies; 29+ messages in thread
From: Artyom Tarasenko @ 2017-10-18  9:12 UTC (permalink / raw)
  To: Mark Cave-Ayland; +Cc: qemu-devel

On Sat, Oct 14, 2017 at 8:38 PM, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
> This patchset aims to tidy-up the sparc32_dma code by improving the
> modelling of the espdma/ledma devices using both QOM and the memory
> API which didn't exist when the code was first written.
>
> The result is that it is now possible to remove both the iommu_opaque
> and is_ledma workarounds from the code, and the code for wiring up
> the espdma/ledma and respective devices is also a lot more readable.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Artyom Tarasenko <atar4qemu@gmail.com>

>
> v3:
> - Add missing sysbus.h include to esp.h in patch 7
>
> v2:
> - Make esp/lance devices children of espdma/ledma devices respectively
> - Add len parameter to ledma/espdma tracepoints
>
> Mark Cave-Ayland (13):
>   sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
>   sparc32_dma: split esp and le into separate DMA devices
>   sparc32_dma: move type declarations from sparc32_dma.c to
>     sparc32_dma.h
>   sun4m: move DMA device wiring from sparc32_dma_init() to
>     sun4m_hw_init()
>   sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
>   sparc32_dma: use object link instead of qdev property to pass IOMMU
>     reference
>   esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h
>   sparc32_dma: make esp device child of espdma device
>   lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h
>   sparc32_dma: make lance device child of ledma device
>   sparc32_dma: introduce new SPARC32_DMA type container object
>   sparc32_dma: remove is_ledma hack and replace with memory region
>     alias
>   sparc32_dma: add len to esp/le DMA memory tracing
>
>  hw/dma/sparc32_dma.c           |  236 +++++++++++++++++++++++++++++-----------
>  hw/dma/sun4m_iommu.c           |   14 ---
>  hw/dma/trace-events            |    8 +-
>  hw/net/lance.c                 |    9 --
>  hw/scsi/esp.c                  |   13 ---
>  hw/sparc/sun4m.c               |   82 ++++++--------
>  include/hw/scsi/esp.h          |   14 +++
>  include/hw/sparc/sparc32_dma.h |   55 ++++++++++
>  include/hw/sparc/sun4m.h       |   29 +++++
>  9 files changed, 307 insertions(+), 153 deletions(-)
>
> --
> 1.7.10.4
>



-- 
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE Mark Cave-Ayland
@ 2017-10-19  4:26   ` Philippe Mathieu-Daudé
  2017-10-20 12:39     ` Mark Cave-Ayland
  0 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-19  4:26 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

Hi Mark,

On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:
> Also update the function names to match as appropriate. While we're
> here rename the type from sparc32_dma to sparc32-dma in order to
> match the current QOM convention.

Where can I read on the QOM convention?

> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/dma/sparc32_dma.c |   67 +++++++++++++++++++++++++-------------------------
>  hw/sparc/sun4m.c     |    2 +-
>  2 files changed, 35 insertions(+), 34 deletions(-)
> 
> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
> index eb491b5..a8d31c1 100644
> --- a/hw/dma/sparc32_dma.c
> +++ b/hw/dma/sparc32_dma.c
> @@ -61,12 +61,13 @@
>  /* XXX SCSI and ethernet should have different read-only bit masks */
>  #define DMA_CSR_RO_MASK 0xfe000007
>  
> -#define TYPE_SPARC32_DMA "sparc32_dma"
> -#define SPARC32_DMA(obj) OBJECT_CHECK(DMAState, (obj), TYPE_SPARC32_DMA)
> +#define TYPE_SPARC32_DMA_DEVICE "sparc32-dma-device"
> +#define SPARC32_DMA_DEVICE(obj) OBJECT_CHECK(DMADeviceState, (obj), \

not sure this is an improvement.

> +                                             TYPE_SPARC32_DMA_DEVICE)
>  
> -typedef struct DMAState DMAState;
> +typedef struct DMADeviceState DMADeviceState;
>  
> -struct DMAState {
> +struct DMADeviceState {
>      SysBusDevice parent_obj;
>  
>      MemoryRegion iomem;
> @@ -86,7 +87,7 @@ enum {
>  void ledma_memory_read(void *opaque, hwaddr addr,
>                         uint8_t *buf, int len, int do_bswap)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>      int i;
>  
>      addr |= s->dmaregs[3];
> @@ -106,7 +107,7 @@ void ledma_memory_read(void *opaque, hwaddr addr,
>  void ledma_memory_write(void *opaque, hwaddr addr,
>                          uint8_t *buf, int len, int do_bswap)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>      int l, i;
>      uint16_t tmp_buf[32];
>  
> @@ -134,7 +135,7 @@ void ledma_memory_write(void *opaque, hwaddr addr,
>  
>  static void dma_set_irq(void *opaque, int irq, int level)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>      if (level) {
>          s->dmaregs[0] |= DMA_INTR;
>          if (s->dmaregs[0] & DMA_INTREN) {
> @@ -154,7 +155,7 @@ static void dma_set_irq(void *opaque, int irq, int level)
>  
>  void espdma_memory_read(void *opaque, uint8_t *buf, int len)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>  
>      trace_espdma_memory_read(s->dmaregs[1]);
>      sparc_iommu_memory_read(s->iommu, s->dmaregs[1], buf, len);
> @@ -163,7 +164,7 @@ void espdma_memory_read(void *opaque, uint8_t *buf, int len)
>  
>  void espdma_memory_write(void *opaque, uint8_t *buf, int len)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>  
>      trace_espdma_memory_write(s->dmaregs[1]);
>      sparc_iommu_memory_write(s->iommu, s->dmaregs[1], buf, len);
> @@ -173,7 +174,7 @@ void espdma_memory_write(void *opaque, uint8_t *buf, int len)
>  static uint64_t dma_mem_read(void *opaque, hwaddr addr,
>                               unsigned size)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>      uint32_t saddr;
>  
>      if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
> @@ -190,7 +191,7 @@ static uint64_t dma_mem_read(void *opaque, hwaddr addr,
>  static void dma_mem_write(void *opaque, hwaddr addr,
>                            uint64_t val, unsigned size)
>  {
> -    DMAState *s = opaque;
> +    DMADeviceState *s = opaque;
>      uint32_t saddr;
>  
>      if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
> @@ -252,28 +253,28 @@ static const MemoryRegionOps dma_mem_ops = {
>      },
>  };
>  
> -static void dma_reset(DeviceState *d)
> +static void sparc32_dma_device_reset(DeviceState *d)
>  {
> -    DMAState *s = SPARC32_DMA(d);
> +    DMADeviceState *s = SPARC32_DMA_DEVICE(d);
>  
>      memset(s->dmaregs, 0, DMA_SIZE);
>      s->dmaregs[0] = DMA_VER;
>  }
>  
> -static const VMStateDescription vmstate_dma = {
> +static const VMStateDescription vmstate_sparc32_dma_device = {
>      .name ="sparc32_dma",
>      .version_id = 2,
>      .minimum_version_id = 2,
>      .fields = (VMStateField[]) {
> -        VMSTATE_UINT32_ARRAY(dmaregs, DMAState, DMA_REGS),
> +        VMSTATE_UINT32_ARRAY(dmaregs, DMADeviceState, DMA_REGS),
>          VMSTATE_END_OF_LIST()
>      }
>  };
>  
> -static void sparc32_dma_init(Object *obj)
> +static void sparc32_dma_device_init(Object *obj)
>  {
>      DeviceState *dev = DEVICE(obj);
> -    DMAState *s = SPARC32_DMA(obj);
> +    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
>  
>      sysbus_init_irq(sbd, &s->irq);
> @@ -284,9 +285,9 @@ static void sparc32_dma_init(Object *obj)
>      qdev_init_gpio_out(dev, s->gpio, 2);
>  }
>  
> -static void sparc32_dma_realize(DeviceState *dev, Error **errp)
> +static void sparc32_dma_device_realize(DeviceState *dev, Error **errp)
>  {
> -    DMAState *s = SPARC32_DMA(dev);
> +    DMADeviceState *s = SPARC32_DMA_DEVICE(dev);
>      int reg_size;
>  
>      reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE;
> @@ -294,35 +295,35 @@ static void sparc32_dma_realize(DeviceState *dev, Error **errp)
>                            "dma", reg_size);
>  }
>  
> -static Property sparc32_dma_properties[] = {
> -    DEFINE_PROP_PTR("iommu_opaque", DMAState, iommu),
> -    DEFINE_PROP_UINT32("is_ledma", DMAState, is_ledma, 0),
> +static Property sparc32_dma_device_properties[] = {
> +    DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
> +    DEFINE_PROP_UINT32("is_ledma", DMADeviceState, is_ledma, 0),
>      DEFINE_PROP_END_OF_LIST(),
>  };
>  
> -static void sparc32_dma_class_init(ObjectClass *klass, void *data)
> +static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
> -    dc->reset = dma_reset;
> -    dc->vmsd = &vmstate_dma;
> -    dc->props = sparc32_dma_properties;
> -    dc->realize = sparc32_dma_realize;
> +    dc->reset = sparc32_dma_device_reset;
> +    dc->vmsd = &vmstate_sparc32_dma_device;
> +    dc->props = sparc32_dma_device_properties;
> +    dc->realize = sparc32_dma_device_realize;
>      /* Reason: pointer property "iommu_opaque" */
>      dc->user_creatable = false;
>  }
>  
> -static const TypeInfo sparc32_dma_info = {
> -    .name          = TYPE_SPARC32_DMA,
> +static const TypeInfo sparc32_dma_device_info = {
> +    .name          = TYPE_SPARC32_DMA_DEVICE,
>      .parent        = TYPE_SYS_BUS_DEVICE,
> -    .instance_size = sizeof(DMAState),
> -    .instance_init = sparc32_dma_init,
> -    .class_init    = sparc32_dma_class_init,
> +    .instance_size = sizeof(DMADeviceState),
> +    .instance_init = sparc32_dma_device_init,
> +    .class_init    = sparc32_dma_device_class_init,
>  };
>  
>  static void sparc32_dma_register_types(void)
>  {
> -    type_register_static(&sparc32_dma_info);
> +    type_register_static(&sparc32_dma_device_info);
>  }
>  
>  type_init(sparc32_dma_register_types)
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index e1bdd48..82c553c 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -313,7 +313,7 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
>      DeviceState *dev;
>      SysBusDevice *s;
>  
> -    dev = qdev_create(NULL, "sparc32_dma");
> +    dev = qdev_create(NULL, "sparc32-dma-device");

Can you use TYPE_SPARC32_DMA_DEVICE instead here?

>      qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
>      qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
>      qdev_init_nofail(dev);
> 

Regards,

Phil.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices Mark Cave-Ayland
@ 2017-10-19  4:33   ` Philippe Mathieu-Daudé
  2017-10-20 12:41     ` Mark Cave-Ayland
  0 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-19  4:33 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:
> Due to slight differences in behaviour accessing the registers for the
> esp and le devices, create two separate SPARC32_DMA_DEVICE types and
> update the sun4m machine to use.
> 
> Note that by using different device types we already know the size of
> the register block and the value of is_ledma at init time, allowing us to
> drop the SPARC32_DMA_DEVICE realize function and the is_ledma device
> property.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/dma/sparc32_dma.c |   63 ++++++++++++++++++++++++++++++++++++++++----------
>  hw/sparc/sun4m.c     |    3 +--
>  2 files changed, 52 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
> index a8d31c1..e4ff4a8 100644
> --- a/hw/dma/sparc32_dma.c
> +++ b/hw/dma/sparc32_dma.c
> @@ -78,6 +78,22 @@ struct DMADeviceState {
>      uint32_t is_ledma;
>  };
>  
> +#define TYPE_SPARC32_ESPDMA_DEVICE "sparc32-espdma"
> +#define SPARC32_ESPDMA_DEVICE(obj) OBJECT_CHECK(ESPDMADeviceState, (obj), \
> +                                                TYPE_SPARC32_ESPDMA_DEVICE)
> +
> +typedef struct ESPDMADeviceState {
> +    DMADeviceState parent_obj;
> +} ESPDMADeviceState;
> +
> +#define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"
> +#define SPARC32_LEDMA_DEVICE(obj) OBJECT_CHECK(LEDMADeviceState, (obj), \
> +                                               TYPE_SPARC32_LEDMA_DEVICE)
> +
> +typedef struct LEDMADeviceState {
> +    DMADeviceState parent_obj;
> +} LEDMADeviceState;
> +
>  enum {
>      GPIO_RESET = 0,
>      GPIO_DMA,
> @@ -285,19 +301,8 @@ static void sparc32_dma_device_init(Object *obj)
>      qdev_init_gpio_out(dev, s->gpio, 2);
>  }
>  
> -static void sparc32_dma_device_realize(DeviceState *dev, Error **errp)
> -{
> -    DMADeviceState *s = SPARC32_DMA_DEVICE(dev);
> -    int reg_size;
> -
> -    reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE;
> -    memory_region_init_io(&s->iomem, OBJECT(dev), &dma_mem_ops, s,
> -                          "dma", reg_size);
> -}
> -
>  static Property sparc32_dma_device_properties[] = {
>      DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
> -    DEFINE_PROP_UINT32("is_ledma", DMADeviceState, is_ledma, 0),
>      DEFINE_PROP_END_OF_LIST(),
>  };
>  
> @@ -308,7 +313,6 @@ static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>      dc->reset = sparc32_dma_device_reset;
>      dc->vmsd = &vmstate_sparc32_dma_device;
>      dc->props = sparc32_dma_device_properties;
> -    dc->realize = sparc32_dma_device_realize;
>      /* Reason: pointer property "iommu_opaque" */
>      dc->user_creatable = false;
>  }
> @@ -316,14 +320,49 @@ static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>  static const TypeInfo sparc32_dma_device_info = {
>      .name          = TYPE_SPARC32_DMA_DEVICE,
>      .parent        = TYPE_SYS_BUS_DEVICE,
> +    .abstract      = true,
>      .instance_size = sizeof(DMADeviceState),
>      .instance_init = sparc32_dma_device_init,
>      .class_init    = sparc32_dma_device_class_init,
>  };
>  
> +static void sparc32_espdma_device_init(Object *obj)
> +{
> +    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
> +
> +    memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
> +                          "espdma-mmio", DMA_SIZE);
> +    s->is_ledma = 0;
> +}
> +
> +static const TypeInfo sparc32_espdma_device_info = {
> +    .name          = TYPE_SPARC32_ESPDMA_DEVICE,
> +    .parent        = TYPE_SPARC32_DMA_DEVICE,
> +    .instance_size = sizeof(ESPDMADeviceState),
> +    .instance_init = sparc32_espdma_device_init,
> +};
> +
> +static void sparc32_ledma_device_init(Object *obj)
> +{
> +    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
> +
> +    memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
> +                          "ledma-mmio", DMA_ETH_SIZE);
> +    s->is_ledma = 1;
> +}
> +
> +static const TypeInfo sparc32_ledma_device_info = {
> +    .name          = TYPE_SPARC32_LEDMA_DEVICE,
> +    .parent        = TYPE_SPARC32_DMA_DEVICE,
> +    .instance_size = sizeof(LEDMADeviceState),
> +    .instance_init = sparc32_ledma_device_init,
> +};
> +
>  static void sparc32_dma_register_types(void)
>  {
>      type_register_static(&sparc32_dma_device_info);
> +    type_register_static(&sparc32_espdma_device_info);
> +    type_register_static(&sparc32_ledma_device_info);
>  }
>  
>  type_init(sparc32_dma_register_types)
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index 82c553c..88a9752 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -313,9 +313,8 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
>      DeviceState *dev;
>      SysBusDevice *s;
>  
> -    dev = qdev_create(NULL, "sparc32-dma-device");
> +    dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");

TYPE_SPARC32_LEDMA_DEVICE and TYPE_SPARC32_ESPDMA_DEVICE?

>      qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
> -    qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
>      qdev_init_nofail(dev);
>      s = SYS_BUS_DEVICE(dev);
>      sysbus_connect_irq(s, 0, parent_irq);
> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h Mark Cave-Ayland
@ 2017-10-19  4:37   ` Philippe Mathieu-Daudé
  2017-10-20 12:47     ` Mark Cave-Ayland
  0 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-19  4:37 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:
> This is in preparation to allow the type to be used elsewhere.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/dma/sun4m_iommu.c     |   14 --------------
>  include/hw/sparc/sun4m.h |   16 ++++++++++++++++
>  2 files changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/dma/sun4m_iommu.c b/hw/dma/sun4m_iommu.c
> index 335ef63..840064b 100644
> --- a/hw/dma/sun4m_iommu.c
> +++ b/hw/dma/sun4m_iommu.c
> @@ -36,7 +36,6 @@
>   * http://mediacast.sun.com/users/Barton808/media/Sun4M_SystemArchitecture_edited2.pdf
>   */
>  
> -#define IOMMU_NREGS         (4*4096/4)
>  #define IOMMU_CTRL          (0x0000 >> 2)
>  #define IOMMU_CTRL_IMPL     0xf0000000 /* Implementation */
>  #define IOMMU_CTRL_VERS     0x0f000000 /* Version */
> @@ -128,19 +127,6 @@
>  #define IOMMU_PAGE_SIZE     (1 << IOMMU_PAGE_SHIFT)
>  #define IOMMU_PAGE_MASK     ~(IOMMU_PAGE_SIZE - 1)
>  
> -#define TYPE_SUN4M_IOMMU "iommu"
> -#define SUN4M_IOMMU(obj) OBJECT_CHECK(IOMMUState, (obj), TYPE_SUN4M_IOMMU)
> -
> -typedef struct IOMMUState {
> -    SysBusDevice parent_obj;
> -
> -    MemoryRegion iomem;
> -    uint32_t regs[IOMMU_NREGS];
> -    hwaddr iostart;
> -    qemu_irq irq;
> -    uint32_t version;
> -} IOMMUState;
> -
>  static uint64_t iommu_mem_read(void *opaque, hwaddr addr,
>                                 unsigned size)
>  {
> diff --git a/include/hw/sparc/sun4m.h b/include/hw/sparc/sun4m.h
> index 580d87b..1f1cf91 100644
> --- a/include/hw/sparc/sun4m.h
> +++ b/include/hw/sparc/sun4m.h
> @@ -4,10 +4,26 @@
>  #include "qemu-common.h"
>  #include "exec/hwaddr.h"
>  #include "qapi/qmp/types.h"
> +#include "hw/sysbus.h"
>  
>  /* Devices used by sparc32 system.  */
>  
>  /* iommu.c */
> +#define TYPE_SUN4M_IOMMU "iommu"

Can this be "sun4m-iommu"?

> +#define SUN4M_IOMMU(obj) OBJECT_CHECK(IOMMUState, (obj), TYPE_SUN4M_IOMMU)
> +
> +#define IOMMU_NREGS         (4 * 4096 / 4)

4096?

> +
> +typedef struct IOMMUState {
> +    SysBusDevice parent_obj;
> +
> +    MemoryRegion iomem;
> +    uint32_t regs[IOMMU_NREGS];
> +    hwaddr iostart;
> +    qemu_irq irq;
> +    uint32_t version;
> +} IOMMUState;
> +
>  void sparc_iommu_memory_rw(void *opaque, hwaddr addr,
>                                   uint8_t *buf, int len, int is_write);
>  static inline void sparc_iommu_memory_read(void *opaque,

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 06/13] sparc32_dma: use object link instead of qdev property to pass IOMMU reference
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 06/13] sparc32_dma: use object link instead of qdev property to pass IOMMU reference Mark Cave-Ayland
@ 2017-10-19  4:38   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-19  4:38 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:
> This enables us to remove the last remaining (opaque) qdev property. Whilst we
> are here, also update iommu_init() to use TYPE_SUN4M_IOMMU instead of a
> hardcoded string.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  hw/dma/sparc32_dma.c |   13 +++++--------
>  hw/sparc/sun4m.c     |    4 ++--
>  2 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
> index ae8fa06..c56a2ba 100644
> --- a/hw/dma/sparc32_dma.c
> +++ b/hw/dma/sparc32_dma.c
> @@ -263,24 +263,21 @@ static void sparc32_dma_device_init(Object *obj)
>  
>      sysbus_init_mmio(sbd, &s->iomem);
>  
> +    object_property_add_link(OBJECT(dev), "iommu", TYPE_SUN4M_IOMMU,
> +                             (Object **) &s->iommu,
> +                             qdev_prop_allow_set_link_before_realize,
> +                             0, NULL);
> +
>      qdev_init_gpio_in(dev, dma_set_irq, 1);
>      qdev_init_gpio_out(dev, s->gpio, 2);
>  }
>  
> -static Property sparc32_dma_device_properties[] = {
> -    DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
> -    DEFINE_PROP_END_OF_LIST(),
> -};
> -
>  static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
>      dc->reset = sparc32_dma_device_reset;
>      dc->vmsd = &vmstate_sparc32_dma_device;
> -    dc->props = sparc32_dma_device_properties;
> -    /* Reason: pointer property "iommu_opaque" */
> -    dc->user_creatable = false;
>  }
>  
>  static const TypeInfo sparc32_dma_device_info = {
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index 4f2ed4b..12d36b5 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -297,7 +297,7 @@ static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
>      DeviceState *dev;
>      SysBusDevice *s;
>  
> -    dev = qdev_create(NULL, "iommu");
> +    dev = qdev_create(NULL, TYPE_SUN4M_IOMMU);
>      qdev_prop_set_uint32(dev, "version", version);
>      qdev_init_nofail(dev);
>      s = SYS_BUS_DEVICE(dev);
> @@ -313,7 +313,7 @@ static void *sparc32_dma_init(hwaddr daddr, void *iommu, int is_ledma)
>      SysBusDevice *s;
>  
>      dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");
> -    qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
> +    object_property_set_link(OBJECT(dev), OBJECT(iommu), "iommu", &error_abort);
>      qdev_init_nofail(dev);
>      s = SYS_BUS_DEVICE(dev);
>      sysbus_mmio_map(s, 0, daddr);
> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 13/13] sparc32_dma: add len to esp/le DMA memory tracing
  2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 13/13] sparc32_dma: add len to esp/le DMA memory tracing Mark Cave-Ayland
@ 2017-10-19  4:45   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-19  4:45 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

On 10/14/2017 03:39 PM, Mark Cave-Ayland wrote:
> This is surprisingly useful when trying to debug DMA issues.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  hw/dma/sparc32_dma.c |    8 ++++----
>  hw/dma/trace-events  |    8 ++++----
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
> index bb7d70a..fbb072a 100644
> --- a/hw/dma/sparc32_dma.c
> +++ b/hw/dma/sparc32_dma.c
> @@ -73,7 +73,7 @@ void ledma_memory_read(void *opaque, hwaddr addr,
>      int i;
>  
>      addr |= s->dmaregs[3];
> -    trace_ledma_memory_read(addr);
> +    trace_ledma_memory_read(addr, len);
>      if (do_bswap) {
>          sparc_iommu_memory_read(s->iommu, addr, buf, len);
>      } else {
> @@ -94,7 +94,7 @@ void ledma_memory_write(void *opaque, hwaddr addr,
>      uint16_t tmp_buf[32];
>  
>      addr |= s->dmaregs[3];
> -    trace_ledma_memory_write(addr);
> +    trace_ledma_memory_write(addr, len);
>      if (do_bswap) {
>          sparc_iommu_memory_write(s->iommu, addr, buf, len);
>      } else {
> @@ -139,7 +139,7 @@ void espdma_memory_read(void *opaque, uint8_t *buf, int len)
>  {
>      DMADeviceState *s = opaque;
>  
> -    trace_espdma_memory_read(s->dmaregs[1]);
> +    trace_espdma_memory_read(s->dmaregs[1], len);
>      sparc_iommu_memory_read(s->iommu, s->dmaregs[1], buf, len);
>      s->dmaregs[1] += len;
>  }
> @@ -148,7 +148,7 @@ void espdma_memory_write(void *opaque, uint8_t *buf, int len)
>  {
>      DMADeviceState *s = opaque;
>  
> -    trace_espdma_memory_write(s->dmaregs[1]);
> +    trace_espdma_memory_write(s->dmaregs[1], len);
>      sparc_iommu_memory_write(s->iommu, s->dmaregs[1], buf, len);
>      s->dmaregs[1] += len;
>  }
> diff --git a/hw/dma/trace-events b/hw/dma/trace-events
> index 428469a..6b367f0 100644
> --- a/hw/dma/trace-events
> +++ b/hw/dma/trace-events
> @@ -7,12 +7,12 @@ rc4030_read(uint64_t addr, uint32_t ret) "read reg[0x%"PRIx64"] = 0x%x"
>  rc4030_write(uint64_t addr, uint32_t val) "write reg[0x%"PRIx64"] = 0x%x"
>  
>  # hw/dma/sparc32_dma.c
> -ledma_memory_read(uint64_t addr) "DMA read addr 0x%"PRIx64
> -ledma_memory_write(uint64_t addr) "DMA write addr 0x%"PRIx64
> +ledma_memory_read(uint64_t addr, int len) "DMA read addr 0x%"PRIx64 " len %d"
> +ledma_memory_write(uint64_t addr, int len) "DMA write addr 0x%"PRIx64 " len %d"
>  sparc32_dma_set_irq_raise(void) "Raise IRQ"
>  sparc32_dma_set_irq_lower(void) "Lower IRQ"
> -espdma_memory_read(uint32_t addr) "DMA read addr 0x%08x"
> -espdma_memory_write(uint32_t addr) "DMA write addr 0x%08x"
> +espdma_memory_read(uint32_t addr, int len) "DMA read addr 0x%08x len %d"
> +espdma_memory_write(uint32_t addr, int len) "DMA write addr 0x%08x len %d"
>  sparc32_dma_mem_readl(uint64_t addr, uint32_t ret) "read dmareg 0x%"PRIx64": 0x%08x"
>  sparc32_dma_mem_writel(uint64_t addr, uint32_t old, uint32_t val) "write dmareg 0x%"PRIx64": 0x%08x -> 0x%08x"
>  sparc32_dma_enable_raise(void) "Raise DMA enable"
> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
  2017-10-19  4:26   ` Philippe Mathieu-Daudé
@ 2017-10-20 12:39     ` Mark Cave-Ayland
  2017-10-27 16:25       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-20 12:39 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, atar4qemu

On 19/10/17 05:26, Philippe Mathieu-Daudé wrote:

> Hi Mark,
> 
> On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:
>> Also update the function names to match as appropriate. While we're
>> here rename the type from sparc32_dma to sparc32-dma in order to
>> match the current QOM convention.
> 
> Where can I read on the QOM convention?

The relevant documentation is in include/qom/object.h on line 937: "In
general, you should use hyphens '-' instead of underscores '_' when
naming properties.". Note that while the type name isn't strictly a
property, I have been asked previously to change type names to use
hyphens on submitted patches.

>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>  hw/dma/sparc32_dma.c |   67 +++++++++++++++++++++++++-------------------------
>>  hw/sparc/sun4m.c     |    2 +-
>>  2 files changed, 35 insertions(+), 34 deletions(-)
>>
>> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
>> index eb491b5..a8d31c1 100644
>> --- a/hw/dma/sparc32_dma.c
>> +++ b/hw/dma/sparc32_dma.c
>> @@ -61,12 +61,13 @@
>>  /* XXX SCSI and ethernet should have different read-only bit masks */
>>  #define DMA_CSR_RO_MASK 0xfe000007
>>  
>> -#define TYPE_SPARC32_DMA "sparc32_dma"
>> -#define SPARC32_DMA(obj) OBJECT_CHECK(DMAState, (obj), TYPE_SPARC32_DMA)
>> +#define TYPE_SPARC32_DMA_DEVICE "sparc32-dma-device"
>> +#define SPARC32_DMA_DEVICE(obj) OBJECT_CHECK(DMADeviceState, (obj), \
> 
> not sure this is an improvement.

Can you clarify this further? The patchset introduces a common
SPARC32_DMA_DEVICE superclass which is intended to be the superclass for
the le/esp devices. Later on in the patchset, the previous SPARC32_DMA
object becomes a container effectively representing the memory region
holding the DMA registers for these devices.

>> +                                             TYPE_SPARC32_DMA_DEVICE)
>>  
>> -typedef struct DMAState DMAState;
>> +typedef struct DMADeviceState DMADeviceState;
>>  
>> -struct DMAState {
>> +struct DMADeviceState {
>>      SysBusDevice parent_obj;
>>  
>>      MemoryRegion iomem;
>> @@ -86,7 +87,7 @@ enum {
>>  void ledma_memory_read(void *opaque, hwaddr addr,
>>                         uint8_t *buf, int len, int do_bswap)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>      int i;
>>  
>>      addr |= s->dmaregs[3];
>> @@ -106,7 +107,7 @@ void ledma_memory_read(void *opaque, hwaddr addr,
>>  void ledma_memory_write(void *opaque, hwaddr addr,
>>                          uint8_t *buf, int len, int do_bswap)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>      int l, i;
>>      uint16_t tmp_buf[32];
>>  
>> @@ -134,7 +135,7 @@ void ledma_memory_write(void *opaque, hwaddr addr,
>>  
>>  static void dma_set_irq(void *opaque, int irq, int level)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>      if (level) {
>>          s->dmaregs[0] |= DMA_INTR;
>>          if (s->dmaregs[0] & DMA_INTREN) {
>> @@ -154,7 +155,7 @@ static void dma_set_irq(void *opaque, int irq, int level)
>>  
>>  void espdma_memory_read(void *opaque, uint8_t *buf, int len)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>  
>>      trace_espdma_memory_read(s->dmaregs[1]);
>>      sparc_iommu_memory_read(s->iommu, s->dmaregs[1], buf, len);
>> @@ -163,7 +164,7 @@ void espdma_memory_read(void *opaque, uint8_t *buf, int len)
>>  
>>  void espdma_memory_write(void *opaque, uint8_t *buf, int len)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>  
>>      trace_espdma_memory_write(s->dmaregs[1]);
>>      sparc_iommu_memory_write(s->iommu, s->dmaregs[1], buf, len);
>> @@ -173,7 +174,7 @@ void espdma_memory_write(void *opaque, uint8_t *buf, int len)
>>  static uint64_t dma_mem_read(void *opaque, hwaddr addr,
>>                               unsigned size)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>      uint32_t saddr;
>>  
>>      if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
>> @@ -190,7 +191,7 @@ static uint64_t dma_mem_read(void *opaque, hwaddr addr,
>>  static void dma_mem_write(void *opaque, hwaddr addr,
>>                            uint64_t val, unsigned size)
>>  {
>> -    DMAState *s = opaque;
>> +    DMADeviceState *s = opaque;
>>      uint32_t saddr;
>>  
>>      if (s->is_ledma && (addr > DMA_MAX_REG_OFFSET)) {
>> @@ -252,28 +253,28 @@ static const MemoryRegionOps dma_mem_ops = {
>>      },
>>  };
>>  
>> -static void dma_reset(DeviceState *d)
>> +static void sparc32_dma_device_reset(DeviceState *d)
>>  {
>> -    DMAState *s = SPARC32_DMA(d);
>> +    DMADeviceState *s = SPARC32_DMA_DEVICE(d);
>>  
>>      memset(s->dmaregs, 0, DMA_SIZE);
>>      s->dmaregs[0] = DMA_VER;
>>  }
>>  
>> -static const VMStateDescription vmstate_dma = {
>> +static const VMStateDescription vmstate_sparc32_dma_device = {
>>      .name ="sparc32_dma",
>>      .version_id = 2,
>>      .minimum_version_id = 2,
>>      .fields = (VMStateField[]) {
>> -        VMSTATE_UINT32_ARRAY(dmaregs, DMAState, DMA_REGS),
>> +        VMSTATE_UINT32_ARRAY(dmaregs, DMADeviceState, DMA_REGS),
>>          VMSTATE_END_OF_LIST()
>>      }
>>  };
>>  
>> -static void sparc32_dma_init(Object *obj)
>> +static void sparc32_dma_device_init(Object *obj)
>>  {
>>      DeviceState *dev = DEVICE(obj);
>> -    DMAState *s = SPARC32_DMA(obj);
>> +    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
>>      SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
>>  
>>      sysbus_init_irq(sbd, &s->irq);
>> @@ -284,9 +285,9 @@ static void sparc32_dma_init(Object *obj)
>>      qdev_init_gpio_out(dev, s->gpio, 2);
>>  }
>>  
>> -static void sparc32_dma_realize(DeviceState *dev, Error **errp)
>> +static void sparc32_dma_device_realize(DeviceState *dev, Error **errp)
>>  {
>> -    DMAState *s = SPARC32_DMA(dev);
>> +    DMADeviceState *s = SPARC32_DMA_DEVICE(dev);
>>      int reg_size;
>>  
>>      reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE;
>> @@ -294,35 +295,35 @@ static void sparc32_dma_realize(DeviceState *dev, Error **errp)
>>                            "dma", reg_size);
>>  }
>>  
>> -static Property sparc32_dma_properties[] = {
>> -    DEFINE_PROP_PTR("iommu_opaque", DMAState, iommu),
>> -    DEFINE_PROP_UINT32("is_ledma", DMAState, is_ledma, 0),
>> +static Property sparc32_dma_device_properties[] = {
>> +    DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
>> +    DEFINE_PROP_UINT32("is_ledma", DMADeviceState, is_ledma, 0),
>>      DEFINE_PROP_END_OF_LIST(),
>>  };
>>  
>> -static void sparc32_dma_class_init(ObjectClass *klass, void *data)
>> +static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>>  {
>>      DeviceClass *dc = DEVICE_CLASS(klass);
>>  
>> -    dc->reset = dma_reset;
>> -    dc->vmsd = &vmstate_dma;
>> -    dc->props = sparc32_dma_properties;
>> -    dc->realize = sparc32_dma_realize;
>> +    dc->reset = sparc32_dma_device_reset;
>> +    dc->vmsd = &vmstate_sparc32_dma_device;
>> +    dc->props = sparc32_dma_device_properties;
>> +    dc->realize = sparc32_dma_device_realize;
>>      /* Reason: pointer property "iommu_opaque" */
>>      dc->user_creatable = false;
>>  }
>>  
>> -static const TypeInfo sparc32_dma_info = {
>> -    .name          = TYPE_SPARC32_DMA,
>> +static const TypeInfo sparc32_dma_device_info = {
>> +    .name          = TYPE_SPARC32_DMA_DEVICE,
>>      .parent        = TYPE_SYS_BUS_DEVICE,
>> -    .instance_size = sizeof(DMAState),
>> -    .instance_init = sparc32_dma_init,
>> -    .class_init    = sparc32_dma_class_init,
>> +    .instance_size = sizeof(DMADeviceState),
>> +    .instance_init = sparc32_dma_device_init,
>> +    .class_init    = sparc32_dma_device_class_init,
>>  };
>>  
>>  static void sparc32_dma_register_types(void)
>>  {
>> -    type_register_static(&sparc32_dma_info);
>> +    type_register_static(&sparc32_dma_device_info);
>>  }
>>  
>>  type_init(sparc32_dma_register_types)
>> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
>> index e1bdd48..82c553c 100644
>> --- a/hw/sparc/sun4m.c
>> +++ b/hw/sparc/sun4m.c
>> @@ -313,7 +313,7 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
>>      DeviceState *dev;
>>      SysBusDevice *s;
>>  
>> -    dev = qdev_create(NULL, "sparc32_dma");
>> +    dev = qdev_create(NULL, "sparc32-dma-device");
> 
> Can you use TYPE_SPARC32_DMA_DEVICE instead here?

No not at this point (you'll see I change this later in the patchset)
because the type is still currently defined in sparc32_dma.c and hasn't
(yet) been moved to sparc32_dma.h.


ATB,

Mark.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices
  2017-10-19  4:33   ` Philippe Mathieu-Daudé
@ 2017-10-20 12:41     ` Mark Cave-Ayland
  2017-10-27 16:26       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-20 12:41 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, atar4qemu

On 19/10/17 05:33, Philippe Mathieu-Daudé wrote:

> On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:

>> Due to slight differences in behaviour accessing the registers for the
>> esp and le devices, create two separate SPARC32_DMA_DEVICE types and
>> update the sun4m machine to use.
>>
>> Note that by using different device types we already know the size of
>> the register block and the value of is_ledma at init time, allowing us to
>> drop the SPARC32_DMA_DEVICE realize function and the is_ledma device
>> property.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>  hw/dma/sparc32_dma.c |   63 ++++++++++++++++++++++++++++++++++++++++----------
>>  hw/sparc/sun4m.c     |    3 +--
>>  2 files changed, 52 insertions(+), 14 deletions(-)
>>
>> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
>> index a8d31c1..e4ff4a8 100644
>> --- a/hw/dma/sparc32_dma.c
>> +++ b/hw/dma/sparc32_dma.c
>> @@ -78,6 +78,22 @@ struct DMADeviceState {
>>      uint32_t is_ledma;
>>  };
>>  
>> +#define TYPE_SPARC32_ESPDMA_DEVICE "sparc32-espdma"
>> +#define SPARC32_ESPDMA_DEVICE(obj) OBJECT_CHECK(ESPDMADeviceState, (obj), \
>> +                                                TYPE_SPARC32_ESPDMA_DEVICE)
>> +
>> +typedef struct ESPDMADeviceState {
>> +    DMADeviceState parent_obj;
>> +} ESPDMADeviceState;
>> +
>> +#define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"
>> +#define SPARC32_LEDMA_DEVICE(obj) OBJECT_CHECK(LEDMADeviceState, (obj), \
>> +                                               TYPE_SPARC32_LEDMA_DEVICE)
>> +
>> +typedef struct LEDMADeviceState {
>> +    DMADeviceState parent_obj;
>> +} LEDMADeviceState;
>> +
>>  enum {
>>      GPIO_RESET = 0,
>>      GPIO_DMA,
>> @@ -285,19 +301,8 @@ static void sparc32_dma_device_init(Object *obj)
>>      qdev_init_gpio_out(dev, s->gpio, 2);
>>  }
>>  
>> -static void sparc32_dma_device_realize(DeviceState *dev, Error **errp)
>> -{
>> -    DMADeviceState *s = SPARC32_DMA_DEVICE(dev);
>> -    int reg_size;
>> -
>> -    reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE;
>> -    memory_region_init_io(&s->iomem, OBJECT(dev), &dma_mem_ops, s,
>> -                          "dma", reg_size);
>> -}
>> -
>>  static Property sparc32_dma_device_properties[] = {
>>      DEFINE_PROP_PTR("iommu_opaque", DMADeviceState, iommu),
>> -    DEFINE_PROP_UINT32("is_ledma", DMADeviceState, is_ledma, 0),
>>      DEFINE_PROP_END_OF_LIST(),
>>  };
>>  
>> @@ -308,7 +313,6 @@ static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>>      dc->reset = sparc32_dma_device_reset;
>>      dc->vmsd = &vmstate_sparc32_dma_device;
>>      dc->props = sparc32_dma_device_properties;
>> -    dc->realize = sparc32_dma_device_realize;
>>      /* Reason: pointer property "iommu_opaque" */
>>      dc->user_creatable = false;
>>  }
>> @@ -316,14 +320,49 @@ static void sparc32_dma_device_class_init(ObjectClass *klass, void *data)
>>  static const TypeInfo sparc32_dma_device_info = {
>>      .name          = TYPE_SPARC32_DMA_DEVICE,
>>      .parent        = TYPE_SYS_BUS_DEVICE,
>> +    .abstract      = true,
>>      .instance_size = sizeof(DMADeviceState),
>>      .instance_init = sparc32_dma_device_init,
>>      .class_init    = sparc32_dma_device_class_init,
>>  };
>>  
>> +static void sparc32_espdma_device_init(Object *obj)
>> +{
>> +    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
>> +
>> +    memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
>> +                          "espdma-mmio", DMA_SIZE);
>> +    s->is_ledma = 0;
>> +}
>> +
>> +static const TypeInfo sparc32_espdma_device_info = {
>> +    .name          = TYPE_SPARC32_ESPDMA_DEVICE,
>> +    .parent        = TYPE_SPARC32_DMA_DEVICE,
>> +    .instance_size = sizeof(ESPDMADeviceState),
>> +    .instance_init = sparc32_espdma_device_init,
>> +};
>> +
>> +static void sparc32_ledma_device_init(Object *obj)
>> +{
>> +    DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
>> +
>> +    memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
>> +                          "ledma-mmio", DMA_ETH_SIZE);
>> +    s->is_ledma = 1;
>> +}
>> +
>> +static const TypeInfo sparc32_ledma_device_info = {
>> +    .name          = TYPE_SPARC32_LEDMA_DEVICE,
>> +    .parent        = TYPE_SPARC32_DMA_DEVICE,
>> +    .instance_size = sizeof(LEDMADeviceState),
>> +    .instance_init = sparc32_ledma_device_init,
>> +};
>> +
>>  static void sparc32_dma_register_types(void)
>>  {
>>      type_register_static(&sparc32_dma_device_info);
>> +    type_register_static(&sparc32_espdma_device_info);
>> +    type_register_static(&sparc32_ledma_device_info);
>>  }
>>  
>>  type_init(sparc32_dma_register_types)
>> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
>> index 82c553c..88a9752 100644
>> --- a/hw/sparc/sun4m.c
>> +++ b/hw/sparc/sun4m.c
>> @@ -313,9 +313,8 @@ static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
>>      DeviceState *dev;
>>      SysBusDevice *s;
>>  
>> -    dev = qdev_create(NULL, "sparc32-dma-device");
>> +    dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");
> 
> TYPE_SPARC32_LEDMA_DEVICE and TYPE_SPARC32_ESPDMA_DEVICE?

Again please note that this patch is an intermediate step and the type
is switched over to use the macro later in the patchset when the type
macro is eventually moved over to sparc32_dma.h.


ATB,

Mark.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h
  2017-10-19  4:37   ` Philippe Mathieu-Daudé
@ 2017-10-20 12:47     ` Mark Cave-Ayland
  0 siblings, 0 replies; 29+ messages in thread
From: Mark Cave-Ayland @ 2017-10-20 12:47 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, atar4qemu

On 19/10/17 05:37, Philippe Mathieu-Daudé wrote:

> On 10/14/2017 03:38 PM, Mark Cave-Ayland wrote:
>> This is in preparation to allow the type to be used elsewhere.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>  hw/dma/sun4m_iommu.c     |   14 --------------
>>  include/hw/sparc/sun4m.h |   16 ++++++++++++++++
>>  2 files changed, 16 insertions(+), 14 deletions(-)
>>
>> diff --git a/hw/dma/sun4m_iommu.c b/hw/dma/sun4m_iommu.c
>> index 335ef63..840064b 100644
>> --- a/hw/dma/sun4m_iommu.c
>> +++ b/hw/dma/sun4m_iommu.c
>> @@ -36,7 +36,6 @@
>>   * http://mediacast.sun.com/users/Barton808/media/Sun4M_SystemArchitecture_edited2.pdf
>>   */
>>  
>> -#define IOMMU_NREGS         (4*4096/4)
>>  #define IOMMU_CTRL          (0x0000 >> 2)
>>  #define IOMMU_CTRL_IMPL     0xf0000000 /* Implementation */
>>  #define IOMMU_CTRL_VERS     0x0f000000 /* Version */
>> @@ -128,19 +127,6 @@
>>  #define IOMMU_PAGE_SIZE     (1 << IOMMU_PAGE_SHIFT)
>>  #define IOMMU_PAGE_MASK     ~(IOMMU_PAGE_SIZE - 1)
>>  
>> -#define TYPE_SUN4M_IOMMU "iommu"
>> -#define SUN4M_IOMMU(obj) OBJECT_CHECK(IOMMUState, (obj), TYPE_SUN4M_IOMMU)
>> -
>> -typedef struct IOMMUState {
>> -    SysBusDevice parent_obj;
>> -
>> -    MemoryRegion iomem;
>> -    uint32_t regs[IOMMU_NREGS];
>> -    hwaddr iostart;
>> -    qemu_irq irq;
>> -    uint32_t version;
>> -} IOMMUState;
>> -
>>  static uint64_t iommu_mem_read(void *opaque, hwaddr addr,
>>                                 unsigned size)
>>  {
>> diff --git a/include/hw/sparc/sun4m.h b/include/hw/sparc/sun4m.h
>> index 580d87b..1f1cf91 100644
>> --- a/include/hw/sparc/sun4m.h
>> +++ b/include/hw/sparc/sun4m.h
>> @@ -4,10 +4,26 @@
>>  #include "qemu-common.h"
>>  #include "exec/hwaddr.h"
>>  #include "qapi/qmp/types.h"
>> +#include "hw/sysbus.h"
>>  
>>  /* Devices used by sparc32 system.  */
>>  
>>  /* iommu.c */
>> +#define TYPE_SUN4M_IOMMU "iommu"
> 
> Can this be "sun4m-iommu"?

Possibly. This particular patch is concerned with moving the
declarations rather than changing them. As it's freeze coming up, I'd be
quite keen to get these changes in if possible because it nicely removes
some old sun4m hacks.

In fact, I suspect that the reason the type name is "iommu" is because
sun4m was the first IOMMU implementation within QEMU, and indeed it
predates the "official" IOMMU functionality implemented as a translating
memory region. Indeed the follow-up patchset to this switches over to
use the supported IOMMU memory region and removes another set of legacy
sun4m hacks.

>> +#define SUN4M_IOMMU(obj) OBJECT_CHECK(IOMMUState, (obj), TYPE_SUN4M_IOMMU)
>> +
>> +#define IOMMU_NREGS         (4 * 4096 / 4)
> 
> 4096?

Possibly again, same reasoning as before: this patch is just concerned
with moving the macros rather than altering them.

>> +
>> +typedef struct IOMMUState {
>> +    SysBusDevice parent_obj;
>> +
>> +    MemoryRegion iomem;
>> +    uint32_t regs[IOMMU_NREGS];
>> +    hwaddr iostart;
>> +    qemu_irq irq;
>> +    uint32_t version;
>> +} IOMMUState;
>> +
>>  void sparc_iommu_memory_rw(void *opaque, hwaddr addr,
>>                                   uint8_t *buf, int len, int is_write);
>>  static inline void sparc_iommu_memory_read(void *opaque,
> 
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


ATB,

Mark.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 07/13] esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 07/13] esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h Mark Cave-Ayland
@ 2017-10-25 10:42   ` Peter Maydell
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Maydell @ 2017-10-25 10:42 UTC (permalink / raw)
  To: Mark Cave-Ayland; +Cc: QEMU Developers, Artyom Tarasenko, Paolo Bonzini

On 14 October 2017 at 19:38, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
> This enables them to be used outside of esp.c.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> CC: Paolo Bonzini <pbonzini@redhat.com>


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 09/13] lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h
  2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 09/13] lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h Mark Cave-Ayland
@ 2017-10-25 10:44   ` Peter Maydell
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Maydell @ 2017-10-25 10:44 UTC (permalink / raw)
  To: Mark Cave-Ayland; +Cc: QEMU Developers, Artyom Tarasenko, Jason Wang

On 14 October 2017 at 19:38, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
> This enables them to be used outside of lance.c.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> CC: Jason Wang <jasowang@redhat.com>
> ---
>  hw/net/lance.c           |    9 ---------
>  include/hw/sparc/sun4m.h |   13 +++++++++++++
>  2 files changed, 13 insertions(+), 9 deletions(-)


I would suggest creating a new header file for this device,
include/hw/net/lance.h, rather than stuffing it into the sun4m.h header.
(That kind of header is a bit of a legacy from when we had
ad-hoc header organization, so in general we'd expect things to
go out of it rather than be added to it...)


thanks
-- PMM

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE
  2017-10-20 12:39     ` Mark Cave-Ayland
@ 2017-10-27 16:25       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-27 16:25 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

On 10/20/2017 09:39 AM, Mark Cave-Ayland wrote:
>>> Also update the function names to match as appropriate. While we're
>>> here rename the type from sparc32_dma to sparc32-dma in order to
>>> match the current QOM convention.
>>
>> Where can I read on the QOM convention?
> 
> The relevant documentation is in include/qom/object.h on line 937: "In
> general, you should use hyphens '-' instead of underscores '_' when
> naming properties.". Note that while the type name isn't strictly a
> property, I have been asked previously to change type names to use
> hyphens on submitted patches.

OK, thanks.

>>> -#define TYPE_SPARC32_DMA "sparc32_dma"
>>> -#define SPARC32_DMA(obj) OBJECT_CHECK(DMAState, (obj), TYPE_SPARC32_DMA)
>>> +#define TYPE_SPARC32_DMA_DEVICE "sparc32-dma-device"
>>> +#define SPARC32_DMA_DEVICE(obj) OBJECT_CHECK(DMADeviceState, (obj), \
>>
>> not sure this is an improvement.
> 
> Can you clarify this further? The patchset introduces a common
> SPARC32_DMA_DEVICE superclass which is intended to be the superclass for
> the le/esp devices. Later on in the patchset, the previous SPARC32_DMA
> object becomes a container effectively representing the memory region
> holding the DMA registers for these devices.

Fine :)

> 
>>> +                                             TYPE_SPARC32_DMA_DEVICE)
[...]
>>> -    dev = qdev_create(NULL, "sparc32_dma");
>>> +    dev = qdev_create(NULL, "sparc32-dma-device");
>>
>> Can you use TYPE_SPARC32_DMA_DEVICE instead here?
> 
> No not at this point (you'll see I change this later in the patchset)
> because the type is still currently defined in sparc32_dma.c and hasn't
> (yet) been moved to sparc32_dma.h.

OK!

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices
  2017-10-20 12:41     ` Mark Cave-Ayland
@ 2017-10-27 16:26       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-27 16:26 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, atar4qemu

On 10/20/2017 09:41 AM, Mark Cave-Ayland wrote:
>>> -    dev = qdev_create(NULL, "sparc32-dma-device");
>>> +    dev = qdev_create(NULL, is_ledma ? "sparc32-ledma" : "sparc32-espdma");
>>
>> TYPE_SPARC32_LEDMA_DEVICE and TYPE_SPARC32_ESPDMA_DEVICE?
> 
> Again please note that this patch is an intermediate step and the type
> is switched over to use the macro later in the patchset when the type
> macro is eventually moved over to sparc32_dma.h.

Oops sorry! I missed this mail while reviewing your v4.

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2017-10-27 16:27 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-14 18:38 [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups Mark Cave-Ayland
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 01/13] sparc32_dma: rename SPARC32_DMA type to SPARC32_DMA_DEVICE Mark Cave-Ayland
2017-10-19  4:26   ` Philippe Mathieu-Daudé
2017-10-20 12:39     ` Mark Cave-Ayland
2017-10-27 16:25       ` Philippe Mathieu-Daudé
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 02/13] sparc32_dma: split esp and le into separate DMA devices Mark Cave-Ayland
2017-10-19  4:33   ` Philippe Mathieu-Daudé
2017-10-20 12:41     ` Mark Cave-Ayland
2017-10-27 16:26       ` Philippe Mathieu-Daudé
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 03/13] sparc32_dma: move type declarations from sparc32_dma.c to sparc32_dma.h Mark Cave-Ayland
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 04/13] sun4m: move DMA device wiring from sparc32_dma_init() to sun4m_hw_init() Mark Cave-Ayland
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 05/13] sun4m_iommu: move TYPE_SUN4M_IOMMU declaration to sun4m.h Mark Cave-Ayland
2017-10-19  4:37   ` Philippe Mathieu-Daudé
2017-10-20 12:47     ` Mark Cave-Ayland
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 06/13] sparc32_dma: use object link instead of qdev property to pass IOMMU reference Mark Cave-Ayland
2017-10-19  4:38   ` Philippe Mathieu-Daudé
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 07/13] esp: move TYPE_ESP and SysBusESPState from esp.c to esp.h Mark Cave-Ayland
2017-10-25 10:42   ` Peter Maydell
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 08/13] sparc32_dma: make esp device child of espdma device Mark Cave-Ayland
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 09/13] lance: move TYPE_LANCE and SysBusPCNetState from lance.c to sun4m.h Mark Cave-Ayland
2017-10-25 10:44   ` Peter Maydell
2017-10-14 18:38 ` [Qemu-devel] [PATCHv3 10/13] sparc32_dma: make lance device child of ledma device Mark Cave-Ayland
2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 11/13] sparc32_dma: introduce new SPARC32_DMA type container object Mark Cave-Ayland
2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 12/13] sparc32_dma: remove is_ledma hack and replace with memory region alias Mark Cave-Ayland
2017-10-14 18:39 ` [Qemu-devel] [PATCHv3 13/13] sparc32_dma: add len to esp/le DMA memory tracing Mark Cave-Ayland
2017-10-19  4:45   ` Philippe Mathieu-Daudé
2017-10-14 19:23 ` [Qemu-devel] [PATCHv3 00/13] sun4m: sparc32_dma tidy-ups no-reply
2017-10-15  7:14   ` Mark Cave-Ayland
2017-10-18  9:12 ` Artyom Tarasenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.