Skip to contentSkip to conversation

These patches add support for the Primcell PL330 DMA controller and add it to the Xilinx Zynq machine model. Patch 1 is the device model. Patch 2 is the machine model update.

PATCH Superseded Peter Crosthwaite 4 participants 10 messages Oct 29, 2012 – Oct 30, 2012 Arm/Zynq architecture

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover These patches add support for the Primcell PL330 DMA controller and add it to the Xilinx Zynq machine model. Patch 1 is the device model. Patch 2 is the machine model update.

The Device model was originally contributed by Kirill Batuzov / Samsung, as indicated by the (C) notice in hw/pl330.c.

changed since v4:
s/petalogix/xilinx in my email address.
addressed reviewer comments from Igor mitsyanko and Peter Maydell (1/2) changed since v3:
rebased against Makefile refactor
changed since v2:
addressed reviewer comments from Igor mitsyanko and Peter Maydell (1/2)

Peter Crosthwaite (2):
pl330: Initial version
xilinx_zynq: added pl330 to machine model

 default-configs/arm-softmmu.mak |    1 +
 hw/Makefile.objs                |    1 +
 hw/pl330.c                      | 1587 +++++++++++++++++++++++++++++++++++++++
 hw/xilinx_zynq.c                |   24 +
 4 files changed, 1613 insertions(+), 0 deletions(-)
 create mode 100644 hw/pl330.c
#1 lore raw

PATCH v5 1/2 pl330: Initial version

Device model for Primecell PL330 dma controller.

---
changed from v4:
Various cosmetic fixes
Some Makefile refactoring updates
refactored properties to match primecell options rather than be the config register values (PMM review)
s/chanel/channel (PMM review)
elaborated names of single letter fields of PL330FIFO (PMM review) remove use of target_phys_addr_t (PMM review)
"Put instruction to queue" - fixed comment style (PMM review)
changed dmago non-manager usage to throw PL330_FAULT_UNDEF (Igor Review) Added VMSD (PMM review)
Changed version to r01p01 (PMM Review)
const'ified TypeInfo (Igor review)
changed from v3:
rebased against Makefile refactor
changed from v2 (in order of diff appearance):
GPL version changed to v2 or later
Register and field names changed to match TRM
id field corrected
PL330ChanState enum corrected
target_phys_addr_t usages removed
identifier camel casing and underscoring fixed
data fifo reworked (uses head ptr and a occupancy count rather than head & tail ptrs) pl330_insn_from_queue->pl330_queue_remove_insn
Numerous typos in comments corrected as per review
g_malloc0(sizeof(a) * b) -> g_new
pl330_fifo_inc: changed to accept PL330Fifo struct as argument (rather than buf_size) pl330_fifo_push/get: rollback on overflow mechanism replaced with pre-check
pl330_queue_find_insn: fixed ugly if statement whitespace (PMM review)
pl330_dmaaddh: fixed arugment reversal
pl330_dmaaddh: asserted on !manager
"ns": change to be and behave like a boolean globally
pl330_dmald: force num=1 when PL330_SINGLE
pl330_dma_kill: put in correct alphabet order pl330_dmarmb/wmb:implemented
pl330_exec_insn: asserted insn->size not too big
pl330_exec_insn: enabled stall mechanism outside exec state (needed for rmb/wmb)
pl330_debug_exec: assert fault type on a fault
pl330_iomem_write: removed aligmnent assertion
pl330_iomem_write: corrected ev_status and irq_status logic
pl330_iomem_read_imp: fixed some incorrect bitfield positions (PMM review)
pl330_reset: stopped timer
pl330_init: removed redundant reset
changed from v1:
GPLv2 license
some code formatting fixes

 default-configs/arm-softmmu.mak |    1 +
 hw/Makefile.objs                |    1 +
 hw/pl330.c                      | 1587 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 1589 insertions(+), 0 deletions(-)
 create mode 100644 hw/pl330.c
default-configs/arm-softmmu.mak +1 -0
index 2f1a5c9..1775455 100644
@@ -41,6 +41,7 @@ CONFIG_PL110=y
 CONFIG_PL181=y
 CONFIG_PL190=y
 CONFIG_PL310=y
+CONFIG_PL330=y
 CONFIG_CADENCE=y
 CONFIG_XGMAC=y
 
hw/Makefile.objs +1 -0
index af4ab0c..584c688 100644
@@ -89,6 +89,7 @@ common-obj-$(CONFIG_PL110) += pl110.o
 common-obj-$(CONFIG_PL181) += pl181.o
 common-obj-$(CONFIG_PL190) += pl190.o
 common-obj-$(CONFIG_PL310) += arm_l2x0.o
+common-obj-$(CONFIG_PL330) += pl330.o
 common-obj-$(CONFIG_VERSATILE_PCI) += versatile_pci.o
 common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o
 common-obj-$(CONFIG_CADENCE) += cadence_uart.o
hw/pl330.c new file +1587 -0

1,587 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#9 lore raw

PATCH v5 2/2 xilinx_zynq: added pl330 to machine model

In reply to Peter Crosthwaite

---

 hw/xilinx_zynq.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
hw/xilinx_zynq.c +24 -0
index c55dafb..e985e26 100644
@@ -33,6 +33,10 @@
 
 #define IRQ_OFFSET 32 /* pic interrupts start from index 32 */
 
+int dma_irqs[8] = {
+    46, 47, 48, 49, 72, 73, 74, 75
+};
+
 static struct arm_boot_info zynq_binfo = {};
 
 static void gem_init(NICInfo *nd, uint32_t base, qemu_irq irq)
@@ -167,6 +171,26 @@ static void zynq_init(QEMUMachineInitArgs *args)
         }
     }
 
+    dev = qdev_create(NULL, "pl330");
+    qdev_prop_set_uint8(dev, "num_chnls",  8);
+    qdev_prop_set_uint8(dev, "num_periph_req",  4);
+    qdev_prop_set_uint8(dev, "num_events",  16);
+
+    qdev_prop_set_uint8(dev, "data_width",  64);
+    qdev_prop_set_uint8(dev, "wr_cap",  8);
+    qdev_prop_set_uint8(dev, "wr_q_dep",  16);
+    qdev_prop_set_uint8(dev, "rd_cap",  8);
+    qdev_prop_set_uint8(dev, "rd_q_dep",  16);
+    qdev_prop_set_uint16(dev, "data_buffer_dep",  256);
+
+    qdev_init_nofail(dev);
+    busdev = sysbus_from_qdev(dev);
+    sysbus_mmio_map(busdev, 0, 0xF8003000);
+    sysbus_connect_irq(busdev, 0, pic[45-IRQ_OFFSET]); /* abort irq line */
+    for (n = 0; n < 8; ++n) { /* event irqs */
+        sysbus_connect_irq(busdev, n + 1, pic[dma_irqs[n] - IRQ_OFFSET]);
+    }
+
     zynq_binfo.ram_size = ram_size;
     zynq_binfo.kernel_filename = kernel_filename;
     zynq_binfo.kernel_cmdline = kernel_cmdline;
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

In reply to Peter Crosthwaite
Quoted 1 line · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

A general question -- this is a DMA controller so should it be using the DMAContext APIs now? Avi?

hw/pl330.c line 477

Quoted 6 lines
hw/pl330.c new file +6 -0
+static void pl330_queue_init(PL330Queue *s, int size, int channum)
+{
+    s->queue = (PL330QueueEntry *)g_new0(PL330QueueEntry, size);
+    s->chan_num = channum;
+    s->lo_seqn = (uint8_t *)g_malloc0(channum);
+    s->hi_seqn = (uint8_t *)g_malloc0(channum);

You don't need to cast the return value from g_new0 or g_malloc0.

hw/pl330.c line 1323

Quoted 3 lines
hw/pl330.c new file +3 -0
+
+    default:
+        hw_error("pl330: bad read offset " TARGET_FMT_plx "\n", offset);

This hw_error() (and probably most of the others in this file) should be replaced by qemu_log_mask() with either LOG_GUEST_ERROR or LOG_UNIMP as appropriate.

hw/pl330.c line 1514

Quoted 3 lines
hw/pl330.c new file +3 -0
+    s->manager.parent = s;
+    s->manager.tag = s->num_chnls;
+    s->manager.is_manager = 1;

This is a bool, so 'true'.

thanks
-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

In reply to Peter Crosthwaite

Good day, Peter)

Quoted 4 lines · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

hw/pl330.c new file +2 -0
+
+static Property pl330_properties[] = {

hw/pl330.c line 1547

Quoted 10 lines
hw/pl330.c new file +10 -0
+    /* CR0 */
+    DEFINE_PROP_UINT8("num_chnls", PL330, num_chnls, 8),
+    DEFINE_PROP_UINT8("num_periph_req", PL330, num_periph_req, 8),
+    DEFINE_PROP_UINT8("num_events", PL330, num_events, 8),
+    DEFINE_PROP_UINT8("mgr_ns_at_rst", PL330, mgr_ns_at_rst, 0),
+    /* CR1 */
+    DEFINE_PROP_UINT8("i-cache_len", PL330, i_cache_len, 4),
+    DEFINE_PROP_UINT8("num_i-cache_lines", PL330, num_i_cache_lines, 8),
+
+    DEFINE_PROP_UINT8("mgr_ns_at_rst", PL330, mgr_ns_at_rst, 0),

That's a duplicate, you had the same property three rows before.

hw/pl330.c line 1554

Quoted 7 lines
hw/pl330.c new file +7 -0
+
+    /* CR2-4 */
+    DEFINE_PROP_UINT32("boot_addr", PL330, cfg[CFG_BOOT_ADDR], 0),
+    DEFINE_PROP_UINT32("INS", PL330, cfg[CFG_INS], 0),
+    DEFINE_PROP_UINT32("PNS", PL330, cfg[CFG_PNS], 0),
+    /* CRD */
+    DEFINE_PROP_UINT8("data_width", PL330, data_width, 0),

You do not decode this value in pl330_init() like you do for, for example, i_cache_len property. I think default value here should be 32, which corresponds to 0b010 in LSB of CRD register. And you should also check for reserved values of this property and, perhaps, hw_error() on them.

Quoted 33 lines
hw/pl330.c new file +33 -0
+    DEFINE_PROP_UINT8("wr_cap", PL330, wr_cap, 0),
+    DEFINE_PROP_UINT8("wr_q_dep", PL330, wr_q_dep, 0),
+    DEFINE_PROP_UINT8("rd_cap", PL330, rd_cap, 0),
+    DEFINE_PROP_UINT8("rd_q_dep", PL330, rd_q_dep, 0),
+    DEFINE_PROP_UINT16("data_buffer_dep", PL330, data_buffer_dep, 0),
+
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pl330_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = pl330_init;
+    dc->reset = pl330_reset;
+    dc->props = pl330_properties;
+    dc->vmsd = &vmstate_pl330;
+}
+
+static const TypeInfo pl330_type_info = {
+    .name           = "pl330",
+    .parent         = TYPE_SYS_BUS_DEVICE,
+    .instance_size  = sizeof(PL330),
+    .class_init      = pl330_class_init,
+};
+
+static void pl330_register_types(void)
+{
+    type_register_static(&pl330_type_info);
+}
+
+type_init(pl330_register_types)
Signature · 3 lines
Mitsyanko Igor
ASWG, Moscow R&D center, Samsung Electronics
email: [email protected]
#3 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

In reply to Peter Maydell

All changed made

Thanks,
Peter

Quoted 33 lines · Peter Maydell
Quoted 1 line · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

A general question -- this is a DMA controller so should it be using the DMAContext APIs now? Avi?

hw/pl330.c line 477

Quoted 6 lines
hw/pl330.c new file +6 -0
+static void pl330_queue_init(PL330Queue *s, int size, int channum)
+{
+    s->queue = (PL330QueueEntry *)g_new0(PL330QueueEntry, size);
+    s->chan_num = channum;
+    s->lo_seqn = (uint8_t *)g_malloc0(channum);
+    s->hi_seqn = (uint8_t *)g_malloc0(channum);

You don't need to cast the return value from g_new0 or g_malloc0.

hw/pl330.c line 1323

Quoted 3 lines
hw/pl330.c new file +3 -0
+
+    default:
+        hw_error("pl330: bad read offset " TARGET_FMT_plx "\n", offset);

This hw_error() (and probably most of the others in this file) should be replaced by qemu_log_mask() with either LOG_GUEST_ERROR or LOG_UNIMP as appropriate.

hw/pl330.c line 1514

Quoted 3 lines
hw/pl330.c new file +3 -0
+    s->manager.parent = s;
+    s->manager.tag = s->num_chnls;
+    s->manager.is_manager = 1;

This is a bool, so 'true'.

thanks
-- PMM

#8 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

In reply to Igor Mitsyanko

All changed made,

Thanks,
Peter

Quoted 81 lines · Igor Mitsyanko

Good day, Peter)

Quoted 5 lines · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

hw/pl330.c new file +2 -0
+
+static Property pl330_properties[] = {

hw/pl330.c line 1547

Quoted 10 lines
hw/pl330.c new file +10 -0
+    /* CR0 */
+    DEFINE_PROP_UINT8("num_chnls", PL330, num_chnls, 8),
+    DEFINE_PROP_UINT8("num_periph_req", PL330, num_periph_req, 8),
+    DEFINE_PROP_UINT8("num_events", PL330, num_events, 8),
+    DEFINE_PROP_UINT8("mgr_ns_at_rst", PL330, mgr_ns_at_rst, 0),
+    /* CR1 */
+    DEFINE_PROP_UINT8("i-cache_len", PL330, i_cache_len, 4),
+    DEFINE_PROP_UINT8("num_i-cache_lines", PL330, num_i_cache_lines, 8),
+
+    DEFINE_PROP_UINT8("mgr_ns_at_rst", PL330, mgr_ns_at_rst, 0),

That's a duplicate, you had the same property three rows before.

hw/pl330.c line 1554

Quoted 7 lines
hw/pl330.c new file +7 -0
+
+    /* CR2-4 */
+    DEFINE_PROP_UINT32("boot_addr", PL330, cfg[CFG_BOOT_ADDR], 0),
+    DEFINE_PROP_UINT32("INS", PL330, cfg[CFG_INS], 0),
+    DEFINE_PROP_UINT32("PNS", PL330, cfg[CFG_PNS], 0),
+    /* CRD */
+    DEFINE_PROP_UINT8("data_width", PL330, data_width, 0),

You do not decode this value in pl330_init() like you do for, for example, i_cache_len property. I think default value
here should be 32, which corresponds to 0b010 in LSB of CRD register. And you should also check for reserved
values of this property and, perhaps, hw_error() on them.

Quoted 23 lines
hw/pl330.c new file +23 -0
+    DEFINE_PROP_UINT8("wr_cap", PL330, wr_cap, 0),
+    DEFINE_PROP_UINT8("wr_q_dep", PL330, wr_q_dep, 0),
+    DEFINE_PROP_UINT8("rd_cap", PL330, rd_cap, 0),
+    DEFINE_PROP_UINT8("rd_q_dep", PL330, rd_q_dep, 0),
+    DEFINE_PROP_UINT16("data_buffer_dep", PL330, data_buffer_dep, 0),
+
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pl330_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = pl330_init;
+    dc->reset = pl330_reset;
+    dc->props = pl330_properties;
+    dc->vmsd = &vmstate_pl330;
+}
+
+static const TypeInfo pl330_type_info = {
+    .name           = "pl330",
+    .parent         = TYPE_SYS_BUS_DEVICE,

hw/pl330.c line 1587

Quoted 10 lines
hw/pl330.c new file +10 -0
+    .instance_size  = sizeof(PL330),
+    .class_init      = pl330_class_init,
+};
+
+static void pl330_register_types(void)
+{
+    type_register_static(&pl330_type_info);
+}
+
+type_init(pl330_register_types)

--
Mitsyanko Igor
ASWG, Moscow R&D center, Samsung Electronics
email: [email protected]

#4 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

In reply to Peter Maydell
Quoted 6 lines · Peter Maydell
Quoted 1 line · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

A general question -- this is a DMA controller so should it be using the DMAContext APIs now? Avi?

IOMMU functionality will be folded into the memory core, so address_space_rw() and family.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

Quoted 12 lines · Avi Kivity
Quoted 6 lines · Peter Maydell
Quoted 1 line · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

A general question -- this is a DMA controller so should it be using the DMAContext APIs now? Avi?

IOMMU functionality will be folded into the memory core, so address_space_rw() and family.

Hi Avi,

So does this mean no more dma_contexts and dma_memory_foo? I have remade the series (and others) using dma_memory_*. Can you point to a sysbus attached DMA controller currently in tree that does it properly so we can use it for a basis as there are several (four in total think) series I have pending all containing DMA which will be effected by this.

Regards,
Peter

P.S. Sorry for dropping off the IRC, connection probs.

Quoted 5 lines

--
error compiling committee.c: too many arguments to function

#6 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] pl330: Initial version

Quoted 9 lines · Peter Crosthwaite
Quoted 8 lines · Avi Kivity
Quoted 6 lines · Peter Maydell
Quoted 1 line · Peter Crosthwaite

Device model for Primecell PL330 dma controller.

A general question -- this is a DMA controller so should it be using the DMAContext APIs now? Avi?

Quoted 8 lines
Quoted 4 lines

IOMMU functionality will be folded into the memory core, so address_space_rw() and family.

Hi Avi,

So does this mean no more dma_contexts and dma_memory_foo?

Correct.

Quoted 6 lines

I have
remade the series (and others) using dma_memory_*. Can you point to a sysbus attached DMA controller currently in tree that does it properly so we can use it for a basis as there are several (four in total think) series I have pending all containing DMA which will be effected by this.

I don't think there are any.

If your dma controller does not have an IOMMU, all you need to do is replace cpu_physical_memory_*(...) with address_space_*(&address_space_memory, ...). If it does have an IOMMU, then you need to wait until my IOMMU patchset hits mainline (or use DMAContext).

Signature · 1 line
error compiling committee.c: too many arguments to function