QOMify AXI stream for Xilinx AXI ethernet/DMA
The following changes since commit 3d1d9652978ac5a32a0beb4bdf6065ca39440d89:
Bruce Rogers (1):
handle device help before accelerator set up
are available in the git repository at:
git://developer.petalogix.com/public/qemu.git for-upstream/axi-stream.next
Anthony Liguori (1):
qom: Reimplement Interfaces
Peter A. G. Crosthwaite (1):
xilinx_axi*: Re-implemented interconnect
hw/Makefile.objs | 1 + hw/petalogix_ml605_mmu.c | 24 +++-- hw/stream.c | 23 +++++ hw/stream.h | 31 +++++++ hw/xilinx.h | 22 ++--- hw/xilinx_axidma.c | 74 +++++++++------- hw/xilinx_axidma.h | 39 -------- hw/xilinx_axienet.c | 32 ++++--- include/qemu/object.h | 46 ++++++---- qom/object.c | 220 ++++++++++++++++++---------------------------- 10 files changed, 255 insertions(+), 257 deletions(-) create mode 100644 hw/stream.c create mode 100644 hw/stream.h delete mode 100644 hw/xilinx_axidma.h
PATCH 1/2 qom: Reimplement Interfaces
From: Anthony Liguori <[email protected]>
The current implementation of Interfaces is poorly designed. Each interface that an object implements ends up being an object that's tracked by the implementing object. There's all sorts of gymnastics to deal with casting between these objects.
But an interface shouldn't be associated with an Object. Interfaces are global to a class. This patch moves all Interface knowledge to ObjectClass eliminating the relationship between Object and Interfaces.
Interfaces are now abstract (as they should be) but this is okay. Interfaces essentially act as additional parents for the classes and are treated as such.
With this new implementation, we should fully support derived interfaces including reimplementing an inherited interface.
PC: Rebased against qom-next merge Jun-2012.
PC: Removed replication of cast logic for interfaces, i.e. there is only one cast function - object_dynamic_cast() (and object_dynamic_cast_assert())
--- include/qemu/object.h | 46 +++++++---- qom/object.c | 220 +++++++++++++++++++------------------------------ 2 files changed, 116 insertions(+), 150 deletions(-)
include/qemu/object.h +30 -16
@@ -239,6 +239,7 @@ struct ObjectClass {/*< private >*/ Type type; +GSList *interfaces; };/**
@@ -260,7 +261,6 @@ struct Object {/*< private >*/ ObjectClass *class; -GSList *interfaces; QTAILQ_HEAD(, ObjectProperty) properties;uint32_t ref;Object *parent;
@@ -387,6 +387,16 @@ struct TypeInfoOBJECT_CLASS_CHECK (class,object_get_class (OBJECT (obj)), name)/** +* InterfaceInfo: +* @type: The name of the interface. +* +* The information associated with an interface. + */ +struct InterfaceInfo { +const char *type; +}; + +/** * InterfaceClass: * @parent_class: the base class *
@@ -396,26 +406,30 @@ struct TypeInfostruct InterfaceClass {ObjectClass parent_class; +/*< private >*/ +ObjectClass *concrete_class; }; +#define TYPE_INTERFACE "interface" +/** -* InterfaceInfo: -* @type: The name of the interface. -* @interface_initfn: This method is called during class initialization and is -* used to initialize an interface associated with a class. This function -* should initialize any default virtual functions for a class and/or override -* virtual functions in a parent class. -* -* The information associated with an interface. +* INTERFACE_CLASS: +* @klass: class to cast from +* Returns: An #InterfaceClass or raise an error if cast is invalid */ -struct InterfaceInfo -{ -const char *type; +#define INTERFACE_CLASS (klass) \ + OBJECT_CLASS_CHECK(InterfaceClass, klass, TYPE_INTERFACE) -void (*interface_initfn)(ObjectClass *class,void *data); -}; - -#define TYPE_INTERFACE "interface" +/** +* INTERFACE_CHECK: +* @interface: the type to return +* @obj: the object to convert to an interface +* @name: the interface type name +* +* Returns: @obj casted to @interface if cast is valid, otherwise raise error. +*/ +#define INTERFACE_CHECK (interface, obj, name) \ + ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name)))/** * object_new:
qom/object.c +86 -134
334 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [PATCH 1/2] qom: Reimplement Interfaces
Am 10.08.2012 05:16, schrieb Peter A. G. Crosthwaite:
Quoted 17 lines
From: Anthony Liguori <[email protected]>
The current implementation of Interfaces is poorly designed. Each interface that an object implements ends up being an object that's tracked by the implementing object. There's all sorts of gymnastics to deal with casting between these objects.
But an interface shouldn't be associated with an Object. Interfaces are global to a class. This patch moves all Interface knowledge to ObjectClass eliminating the relationship between Object and Interfaces.
Interfaces are now abstract (as they should be) but this is okay. Interfaces essentially act as additional parents for the classes and are treated as such.
With this new implementation, we should fully support derived interfaces including reimplementing an inherited interface.
Quoted 8 lines
PC: Rebased against qom-next merge Jun-2012.
PC: Removed replication of cast logic for interfaces, i.e. there is only one cast function -
object_dynamic_cast()(andobject_dynamic_cast_assert())Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Peter A. G. Crosthwaite <[email protected]>Acked-by Paolo Bonzini <[email protected]>
Anthony, didn't you have a whole series to refactor interfaces and add test cases?
/-F
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 1/2] qom: Reimplement Interfaces
Quoted 23 lines · Andreas Färber
Am 10.08.2012 05:16, schrieb Peter A. G. Crosthwaite:
Quoted 22 lines
From: Anthony Liguori <[email protected]>
The current implementation of Interfaces is poorly designed. Each interface that an object implements ends up being an object that's tracked by the implementing object. There's all sorts of gymnastics to deal with casting between these objects.
But an interface shouldn't be associated with an Object. Interfaces are global to a class. This patch moves all Interface knowledge to ObjectClass eliminating the relationship between Object and Interfaces.
Interfaces are now abstract (as they should be) but this is okay. Interfaces essentially act as additional parents for the classes and are treated as such.
With this new implementation, we should fully support derived interfaces including reimplementing an inherited interface.
PC: Rebased against qom-next merge Jun-2012.
PC: Removed replication of cast logic for interfaces, i.e. there is only one cast function -
object_dynamic_cast()(andobject_dynamic_cast_assert())
Quoted 7 lines
Quoted 3 lines
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Peter A. G. Crosthwaite <[email protected]>Acked-by Paolo Bonzini <[email protected]>Anthony, didn't you have a whole series to refactor interfaces and add test cases?
This is patch 1 from that series. I have refactored it a little (as indicated in the comments). Unless theres been another series since I missed?
Quoted 5 lines
/-F
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 2/2 xilinx_axi*: Re-implemented interconnect
In reply to Peter A. G. CrosthwaiteRe-implemented the interconnect between the Xilinx AXI ethernet and DMA controllers. A QOM interface "stream" is created, for the two stream interfaces.
As per Edgars request, this is designed to be more generic than AXI-stream, so in the future we may see more clients of this interface beyond AXI stream.
This is based primarily on Paolos original refactoring of the interconnect.
--- hw/Makefile.objs | 1 + hw/petalogix_ml605_mmu.c | 24 +++++++++------ hw/stream.c | 23 ++++++++++++++ hw/stream.h | 31 +++++++++++++++++++ hw/xilinx.h | 22 +++++-------- hw/xilinx_axidma.c | 74 +++++++++++++++++++++++++-------------------- hw/xilinx_axidma.h | 39 ------------------------ hw/xilinx_axienet.c | 32 ++++++++++++------- 8 files changed, 139 insertions(+), 107 deletions(-) create mode 100644 hw/stream.c create mode 100644 hw/stream.h delete mode 100644 hw/xilinx_axidma.h
hw/Makefile.objs +1 -0
@@ -65,6 +65,7 @@ hw-obj-$(CONFIG_XILINX) += xilinx_timer.o hw-obj-$(CONFIG_XILINX) += xilinx_uartlite.o hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o +hw-obj-$(CONFIG_XILINX_AXI) += stream.o # PCI watchdog devices hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
hw/petalogix_ml605_mmu.c +14 -10
@@ -39,7 +39,8 @@#include "microblaze_boot.h" #include "microblaze_pic_cpu.h" -#include "xilinx_axidma.h" + +#include "stream.h" #define LMB_BRAM_SIZE (128 * 1024)#define FLASH_SIZE (32 * 1024 * 1024)
@@ -76,7 +77,7 @@ petalogix_ml605_init(ram_addr_t ram_size, const char *initrd_filename, const char *cpu_model) { MemoryRegion *address_space_mem = get_system_memory(); -DeviceState *dev; +DeviceState *dev, *dma, *eth0;MicroBlazeCPU *cpu;CPUMBState *env;DriveInfo *dinfo;
@@ -125,15 +126,18 @@ petalogix_ml605_init(ram_addr_t ram_size,/* 2 timers at irq 2 @ 100 Mhz. */ xilinx_timer_create (TIMER_BASEADDR , irq[2 ],0 ,100 *1000000 ); -/* axi ethernet and dma initialization. TODO: Dynamically connect them. */ - { -static struct XilinxDMAConnection dmach; +/* axi ethernet and dma initialization. */ + dma =qdev_create (NULL ,"xlnx.axi-dma" ); -xilinx_axiethernet_create (&dmach, &nd_table[0 ],0x82780000 , - irq[3 ],0x1000 ,0x1000 ); -xilinx_axiethernetdma_create (&dmach,0x84600000 , - irq[1 ], irq[0 ],100 *1000000 ); - } +/* FIXME: attach to the sysbus instead */ +object_property_add_child (container_get (qdev_get_machine (),"/unattached" ), +"xilinx-dma" ,OBJECT (dma),NULL ); + + eth0 =xilinx_axiethernet_create (&nd_table[0 ],STREAM_SLAVE (dma), +0x82780000 , irq[3 ],0x1000 ,0x1000 ); + +xilinx_axiethernetdma_init (dma,STREAM_SLAVE (eth0), +0x84600000 , irq[1 ], irq[0 ],100 *1000000 );microblaze_load_kernel (cpu, ddr_base, ram_size,BINARY_DEVICE_TREE_FILE , machine_cpu_reset);
hw/stream.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "stream.h" + +void +stream_push (StreamSlave *sink,uint8_t *buf,size_t len,uint32_t *app) +{ +StreamSlaveClass *k =STREAM_SLAVE_GET_CLASS (sink); + + k->push (sink, buf, len, app); +} + +static TypeInfo stream_slave_info = { + .name =TYPE_STREAM_SLAVE , + .parent =TYPE_INTERFACE , + .class_size =sizeof (StreamSlaveClass), +}; + + +static void stream_slave_register_types (void ) +{ +type_register_static (&stream_slave_info); +} + +type_init (stream_slave_register_types)
hw/stream.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef STREAM_H +#define STREAM_H 1 + +#include "qemu-common.h" +#include "qemu/object.h" + +/* stream slave. Used until qdev provides a generic way. */ +#define TYPE_STREAM_SLAVE "stream-slave" + +#define STREAM_SLAVE_CLASS (klass) \ + OBJECT_CLASS_CHECK(StreamSlaveClass, (klass), TYPE_STREAM_SLAVE) +#define STREAM_SLAVE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(StreamSlaveClass, (obj), TYPE_STREAM_SLAVE) +#define STREAM_SLAVE (obj) \ + INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE) + +typedef struct StreamSlave { +Object Parent; +}StreamSlave ; + +typedef struct StreamSlaveClass { +InterfaceClass parent; + +void (*push)(StreamSlave *obj,unsigned char *buf,size_t len, +uint32_t *app); +}StreamSlaveClass ; + +void +stream_push (StreamSlave *sink,uint8_t *buf,size_t len,uint32_t *app); + +#endif /* STREAM_H */
hw/xilinx.h +9 -13
@@ -1,3 +1,4 @@ +#include "stream.h" #include "qemu-common.h" #include "net.h"
@@ -49,8 +50,8 @@ xilinx_ethlite_create(NICInfo *nd, target_phys_addr_t base, qemu_irq irq, }static inline DeviceState * -xilinx_axiethernet_create (void *dmach, -NICInfo *nd,target_phys_addr_t base,qemu_irq irq, +xilinx_axiethernet_create (NICInfo *nd,StreamSlave *peer, +target_phys_addr_t base,qemu_irq irq,int txmem,int rxmem) {DeviceState *dev;
@@ -60,7 +61,7 @@ xilinx_axiethernet_create(void *dmach,qdev_set_nic_properties (dev, nd);qdev_prop_set_uint32 (dev,"rxmem" , rxmem);qdev_prop_set_uint32 (dev,"txmem" , txmem); -qdev_prop_set_ptr (dev,"dmach" , dmach); +object_property_set_link (OBJECT (dev),OBJECT (peer),"tx_dev" ,NULL );qdev_init_nofail (dev);sysbus_mmio_map (sysbus_from_qdev (dev),0 , base);sysbus_connect_irq (sysbus_from_qdev (dev),0 , irq);
@@ -68,21 +69,16 @@ xilinx_axiethernet_create(void *dmach,return dev; } -static inline DeviceState * -xilinx_axiethernetdma_create (void *dmach, -target_phys_addr_t base,qemu_irq irq, -qemu_irq irq2,int freqhz) +static inline void +xilinx_axiethernetdma_init (DeviceState *dev,StreamSlave *peer, +target_phys_addr_t base,qemu_irq irq, +qemu_irq irq2,int freqhz) { -DeviceState *dev =NULL ; - - dev =qdev_create (NULL ,"xlnx.axi-dma" );qdev_prop_set_uint32 (dev,"freqhz" , freqhz); -qdev_prop_set_ptr (dev,"dmach" , dmach); +object_property_set_link (OBJECT (dev),OBJECT (peer),"tx_dev" ,NULL );qdev_init_nofail (dev);sysbus_mmio_map (sysbus_from_qdev (dev),0 , base);sysbus_connect_irq (sysbus_from_qdev (dev),0 , irq);sysbus_connect_irq (sysbus_from_qdev (dev),1 , irq2); - -return dev; }
hw/xilinx_axidma.c +41 -33
223 lines not on this page · raw message
hw/xilinx_axidma.h deleted +0 -39
@@ -1,39 +0,0 @@ -/* AXI DMA connection. Used until qdev provides a generic way. */ -typedef void (*DMAPushFn )(void *opaque, -unsigned char *buf,size_t len,uint32_t *app); - -struct XilinxDMAConnection { -void *dma; -void *client; - -DMAPushFn to_dma; -DMAPushFn to_client; -}; - -static inline void xlx_dma_connect_client (struct XilinxDMAConnection *dmach, -void *c,DMAPushFn f) -{ - dmach->client = c; - dmach->to_client = f; -} - -static inline void xlx_dma_connect_dma (struct XilinxDMAConnection *dmach, -void *d,DMAPushFn f) -{ - dmach->dma = d; - dmach->to_dma = f; -} - -static inline -void xlx_dma_push_to_dma (struct XilinxDMAConnection *dmach, -uint8_t *buf,size_t len,uint32_t *app) -{ - dmach->to_dma (dmach->dma, buf, len, app); -} -static inline -void xlx_dma_push_to_client (struct XilinxDMAConnection *dmach, -uint8_t *buf,size_t len,uint32_t *app) -{ - dmach->to_client (dmach->client, buf, len, app); -} -
hw/xilinx_axienet.c +20 -12
@@ -28,7 +28,7 @@#include "net.h" #include "net/checksum.h" -#include "xilinx_axidma.h" +#include "stream.h" #define DPHY (x)
@@ -310,7 +310,7 @@ struct XilinxAXIEnet {SysBusDevice busdev;MemoryRegion iomem;qemu_irq irq; -void *dmach; +StreamSlave *tx_dev;NICState *nic;NICConf conf;
@@ -772,7 +772,7 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)/* Good frame. */ app[2 ] |=1 <<6 ; -xlx_dma_push_to_dma (s->dmach, (void *)s->rxmem, size, app); +stream_push (s->tx_dev, (void *)s->rxmem, size, app); s->regs[R_IS ] |=IS_RX_COMPLETE ;enet_update_irq (s);
@@ -788,9 +788,9 @@ static void eth_cleanup(NetClientState *nc) }static void -axienet_stream_push (void *opaque,uint8_t *buf,size_t size,uint32_t *hdr) +axienet_stream_push (StreamSlave *obj,uint8_t *buf,size_t size,uint32_t *hdr) { -struct XilinxAXIEnet *s = opaque; +struct XilinxAXIEnet *s =FROM_SYSBUS (typeof (*s),SYS_BUS_DEVICE (obj));/* TX enable ? */ if (!(s->tc &TC_TX )) {
@@ -844,12 +844,6 @@ static int xilinx_enet_init(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq); -if (!s->dmach) { -hw_error ("Unconnected Xilinx Ethernet MAC.\n" ); - } - -xlx_dma_connect_client (s->dmach, s, axienet_stream_push); -memory_region_init_io (&s->iomem, &enet_ops, s,"enet" ,0x40000 );sysbus_init_mmio (dev, &s->iomem);
@@ -869,11 +863,18 @@ static int xilinx_enet_init(SysBusDevice *dev)return 0 ; } +static void xilinx_enet_initfn (Object *obj) +{ +struct XilinxAXIEnet *s =FROM_SYSBUS (typeof (*s),SYS_BUS_DEVICE (obj)); + +object_property_add_link (obj,"axistream-connected" ,TYPE_STREAM_SLAVE , + (Object **) &s->tx_dev,NULL ); +} +static Property xilinx_enet_properties[] = { DEFINE_PROP_UINT32("phyaddr", struct XilinxAXIEnet, c_phyaddr, 7), DEFINE_PROP_UINT32("rxmem", struct XilinxAXIEnet, c_rxmem, 0x1000), DEFINE_PROP_UINT32("txmem", struct XilinxAXIEnet, c_txmem, 0x1000), - DEFINE_PROP_PTR("dmach", struct XilinxAXIEnet, dmach), DEFINE_NIC_PROPERTIES(struct XilinxAXIEnet, conf),DEFINE_PROP_END_OF_LIST (), };
@@ -882,9 +883,11 @@ static void xilinx_enet_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass);SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +StreamSlaveClass *ssc =STREAM_SLAVE_CLASS (klass); k->init = xilinx_enet_init; dc->props = xilinx_enet_properties; + ssc->push = axienet_stream_push; }static TypeInfo xilinx_enet_info = {
@@ -892,6 +895,11 @@ static TypeInfo xilinx_enet_info = { .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(struct XilinxAXIEnet), .class_init = xilinx_enet_class_init, + .instance_init = xilinx_enet_initfn, + .interfaces = (InterfaceInfo []) { + {TYPE_STREAM_SLAVE }, + { } + } };static void xilinx_enet_register_types (void )
Signature · 1 line
1.7.0.4
Edgar E. Iglesias
AppliedQuoted 6 lines · Peter A. G. Crosthwaite
The following changes since commit
3d1d9652978ac5a32a0beb4bdf6065ca39440d89:
Bruce Rogers (1):
handle device help before accelerator set upare available in the git repository at:
Quoted 7 lines
git://developer.petalogix.com/public/qemu.gitfor-upstream/axi-stream.nextAnthony Liguori (1):
qom: Reimplement InterfacesPeter A. G. Crosthwaite (1):
xilinx_axi*: Re-implemented interconnect
Applied, thanks Peter.
Cheers,
Edgar
Quoted 15 lines
hw/Makefile.objs | 1 + hw/petalogix_ml605_mmu.c | 24 +++-- hw/stream.c | 23 +++++ hw/stream.h | 31 +++++++ hw/xilinx.h | 22 ++--- hw/xilinx_axidma.c | 74 +++++++++------- hw/xilinx_axidma.h | 39 -------- hw/xilinx_axienet.c | 32 ++++--- include/qemu/object.h | 46 ++++++---- qom/object.c | 220 ++++++++++++++++++---------------------------- 10 files changed, 255 insertions(+), 257 deletions(-) create mode 100644 hw/stream.c create mode 100644 hw/stream.h delete mode 100644 hw/xilinx_axidma.h
Hej Edgar,
Am 13.08.2012 11:41, schrieb Edgar E. Iglesias:
Quoted 9 lines · Peter A. G. Crosthwaite
Quoted 8 lines
The following changes since commit
3d1d9652978ac5a32a0beb4bdf6065ca39440d89:
Bruce Rogers (1):
handle device help before accelerator set upare available in the git repository at:
git://developer.petalogix.com/public/qemu.gitfor-upstream/axi-stream.next
Quoted 7 lines
Quoted 5 lines
Anthony Liguori (1):
qom: Reimplement InterfacesPeter A. G. Crosthwaite (1):
xilinx_axi*: Re-implemented interconnectApplied, thanks Peter.
Sorry to bug you again, but I notice that in qemu.git HEAD these patches have changed order. I have no clue if the introduction of a first interface user before the infrastructure changes causes any bisectability problems in practice, but since the above branch matches this pull request it suggests that you are not using git-merge and may want to check the script you are using in its place (git-rev-list?).
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 18 lines · Andreas Färber
Hej Edgar,
Am 13.08.2012 11:41, schrieb Edgar E. Iglesias:
Quoted 15 lines · Peter A. G. Crosthwaite
Quoted 13 lines
The following changes since commit
3d1d9652978ac5a32a0beb4bdf6065ca39440d89:
Bruce Rogers (1):
handle device help before accelerator set upare available in the git repository at:
git://developer.petalogix.com/public/qemu.gitfor-upstream/axi-stream.nextAnthony Liguori (1):
qom: Reimplement InterfacesPeter A. G. Crosthwaite (1):
xilinx_axi*: Re-implemented interconnect
Quoted 8 lines
Quoted 1 line
Applied, thanks Peter.
Sorry to bug you again, but I notice that in qemu.git HEAD these patches have changed order. I have no clue if the introduction of a first interface user before the infrastructure changes causes any bisectability problems in practice, but since the above branch matches this pull request it suggests that you are not using git-merge and may want to check the script you are using in its place (git-rev-list?).
Hi,
Yeah, I had problems reaching the host so applied manually with git am. I must have reversed the order between these, sorry. I guess the bisectability harm is already done...
Cheers,
Edgar