QOMify AXI stream for Xilinx AXI ethernet/DMA
cover QOMify AXI stream for Xilinx AXI ethernet/DMA
Next revision of the series for AXI-stream, rebased on anthonys refactoring of the Interface system. Anthonys patch is already on the mailing list, but I have included it form completeness. There was an issue with combining links and interface that is resolved and discussed in the Blurb for P3. P2 is all the device-land stuff.
Anthony Liguori (1):
qom: reimplement Interfaces
Peter A. G. Crosthwaite (2):
xilinx_axi*: Re-implemented interconnect
qom: Converged dynamic cast for interfaces & objs
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 | 236 +++++++++++++++++++--------------------------- 10 files changed, 268 insertions(+), 260 deletions(-) create mode 100644 hw/stream.c create mode 100644 hw/stream.h delete mode 100644 hw/xilinx_axidma.h
Signature · 1 line
1.7.3.2
PATCH 1/3 qom: reimplement Interfaces
From: Anthony Liguori <[email protected]>
The current implementation of Interfaces is poorly designed. Each interface that an object implements end up being an object that's tracked by the implementing object. There's all sorts of gymnastics to deal with casting between these objects.
By 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.
--- include/qemu/object.h | 64 +++++++++++--- qom/object.c | 231 +++++++++++++++++++++++------------------------- 2 files changed, 160 insertions(+), 135 deletions(-)
include/qemu/object.h +49 -15
@@ -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;
@@ -381,6 +381,17 @@ 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 *
@@ -390,26 +401,31 @@ 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. +* INTERFACE_CLASS: +* @klass: class to cast from * -* The information associated with an interface. +* 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 *)interface_dynamic_cast_assert(OBJECT((obj)), (name)))/** * object_new:
@@ -548,6 +564,24 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass, const char *typename);/** +* interface_dynamic_cast_assert: +* @obj: the object to cast to an interface type +* @typename: the type name of the interface +* +* Returns: @obj if @obj implements @typename, otherwise raise an error +*/ +Object *interface_dynamic_cast_assert (Object *obj,const char *typename); + +/** +* interface_dynamic_cast_assert: +* @obj: the object to cast to an interface type +* @typename: the type name of the interface +* +* Returns: @obj if @obj implements @typename, otherwise %NULL +*/ +Object *interface_dynamic_cast (Object *obj,const char *typename); + +/** * object_class_get_name: * @klass: The class to obtain the QOM typename for. *
qom/object.c +111 -120
362 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 2/3 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.
---
changed since v0:
This patch is the combination of P2,P3,P7 & P8 of v0 renamed all axi_stream_foo to stream_foo (Edgar review)
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 +axi_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 axi_stream_slave_info = { + .name =TYPE_STREAM_SLAVE , + .parent =TYPE_INTERFACE , + .class_size =sizeof (StreamSlaveClass), +}; + + +static void axi_stream_slave_register_types (void ) +{ +type_register_static (&axi_stream_slave_info); +} + +type_init (axi_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" + +/* AXI 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 +axi_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;
@@ -773,7 +773,7 @@ static ssize_t eth_rx(VLANClientState *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); +axi_stream_push (s->tx_dev, (void *)s->rxmem, size, app); s->regs[R_IS ] |=IS_RX_COMPLETE ;enet_update_irq (s);
@@ -789,9 +789,9 @@ static void eth_cleanup(VLANClientState *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 )) {
@@ -845,12 +845,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);
@@ -870,11 +864,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,"tx_dev" ,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 (), };
@@ -883,9 +884,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 = {
@@ -893,6 +896,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.3.2
PATCH 3/3 qom: Converged dynamic cast for interfaces & objs
In reply to Peter A. G. CrosthwaiteInterfaces and Object for some reason have seperate code paths for dynamic casting. AFAICT, Anthonys new interface specific cast is a functional superset of the object cast, so this patch renames the interface cast to object cast and blows away the original object cast.
Anyone want to shed any light on why the casts need to be different?
The problem (and the reason for this patch) is its not always possible for user of interface to control how their object are going to be casted. Where this broke down big-time is with links. The link setter code path explictly uses object_dynamic_cast(), when link are set, which pretty much makes linking to interfaces impossible. So either:
1: This patch
2: Explictly test objects/classes for interfacage in the link setting code 3: Ban linking to interfaces
--- include/qemu/object.h | 20 +------------------- qom/object.c | 49 +++++++++---------------------------------------- 2 files changed, 10 insertions(+), 59 deletions(-)
include/qemu/object.h +1 -19
@@ -425,7 +425,7 @@ struct InterfaceClass* Returns: @obj casted to @interface if cast is valid, otherwise raise error. */ #define INTERFACE_CHECK (interface, obj, name) \ - ((interface *)interface_dynamic_cast_assert(OBJECT((obj)), (name))) + ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name)))/** * object_new:
@@ -564,24 +564,6 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass, const char *typename);/** -* interface_dynamic_cast_assert: -* @obj: the object to cast to an interface type -* @typename: the type name of the interface -* -* Returns: @obj if @obj implements @typename, otherwise raise an error -*/ -Object *interface_dynamic_cast_assert (Object *obj,const char *typename); - -/** -* interface_dynamic_cast_assert: -* @obj: the object to cast to an interface type -* @typename: the type name of the interface -* -* Returns: @obj if @obj implements @typename, otherwise %NULL -*/ -Object *interface_dynamic_cast (Object *obj,const char *typename); - -/** * object_class_get_name: * @klass: The class to obtain the QOM typename for. *
qom/object.c +9 -40
67 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [Qemu-devel] [PATCH v1 3/3] qom: Converged dynamic cast for interfaces & objs
Quoted 66 lines · Peter A. G. Crosthwaite
Interfaces and Object for some reason have seperate code paths for dynamic casting. AFAICT, Anthonys new interface specific cast is a functional superset of the object cast, so this patch renames the interface cast to object cast and blows away the original object cast.
Anyone want to shed any light on why the casts need to be different?
The problem (and the reason for this patch) is its not always possible for user of interface to control how their object are going to be casted. Where this broke down big-time is with links. The link setter code path explictly uses
object_dynamic_cast(), when link are set, which pretty much makes linking to interfaces impossible. So either:1: This patch
2: Explictly test objects/classes for interfacage in the link setting code 3: Ban linking to interfacesSigned-off-by Peter A. G. Crosthwaite <[email protected]>---
include/qemu/object.h | 20 +-------------------
qom/object.c | 49 +++++++++----------------------------------------2 files changed, 10 insertions(+), 59 deletions(-)include/qemu/object.h +1
-19@@ -425,7 +425,7 @@ struct InterfaceClass* Returns: @obj casted to @interface if cast is valid, otherwise raise error. */ #define INTERFACE_CHECK(interface, obj, name) \ - ((interface *)interface_dynamic_cast_assert(OBJECT((obj)), (name))) + ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name))) /*** object_new: @@ -564,24 +564,6 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass, const char *typename); /** -* interface_dynamic_cast_assert: -* @obj: the object to cast to an interface type -* @typename: the type name of the interface -* -* Returns: @obj if @obj implements @typename, otherwise raise an error -*/ -Object *interface_dynamic_cast_assert (Object *obj,const char *typename); - -/** -* interface_dynamic_cast_assert: -* @obj: the object to cast to an interface type -* @typename: the type name of the interface -* -* Returns: @obj if @obj implements @typename, otherwise %NULL -*/ -Object *interface_dynamic_cast (Object *obj,const char *typename); - -/** * object_class_get_name: * @klass: The class to obtain the QOM typename for. * qom/object.c +0
-0
qom/object.c static bool object_is_type(Object *obj, TypeImpl *target_type) · line 407
Quoted 3 lines
qom/object.c +0
-0@@ -405,24 +405,6 @@ static bool object_is_type(Object *obj, TypeImpl *target_type) return !target_type || type_is_ancestor(obj->class->type, target_type); }
@@ -400,29 +400,6 @@ void object_delete(Object *obj)
g_free(obj);
}
Missing a hunk (that I found in my dirty tree) that belongs in this commit:
-static bool object_is_type(Object *obj, TypeImpl *target_type) -{
- return !target_type || type_is_ancestor(obj->class->type, target_type);
-}
-
Will remake (after review).
Regards,
Peter
Quoted 69 lines
qom/object.c +9
-41-Object *object_dynamic_cast (Object *obj,const char *typename) -{ - TypeImpl *target_type = type_get_by_name(typename); - - /* Check if typename is a direct ancestor. Special-case TYPE_OBJECT, - * we want to go back from interfaces to the parent. - */ - if (target_type && object_is_type(obj, target_type)) { - return obj; - } - - if (!target_type) { - return obj; - } - - return NULL; -} - static void register_types(void) { static TypeInfo interface_info = {@@ -436,6 +418,15 @@ static void register_types(void) type_init(register_types) +Object *object_dynamic_cast(Object *obj, const char *typename) +{ + if (object_class_dynamic_cast(object_get_class(obj), typename)) { + return obj; + } + + return NULL; +} + Object *object_dynamic_cast_assert(Object *obj, const char *typename) { Object *inst;@@ -496,28 +487,6 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, return ret; } -Object *interface_dynamic_cast (Object *obj,const char *typename) -{ - if (object_class_dynamic_cast(object_get_class(obj), typename)) { - return obj; - } - - return NULL; -} - -Object *interface_dynamic_cast_assert (Object *obj,const char *typename) -{ - Object *ret = interface_dynamic_cast(obj, typename); - - if (!ret) { - fprintf(stderr, "Object %p is not an instance of type %s\n", - obj, typename); - abort(); - } - - return ret; -} - const char *object_get_typename(Object *obj) { return obj->class->type->name; --1.7.3.2