Microblaze generic FDT framework
cover Microblaze generic FDT framework
In response to Chris Wulff series which add FDT driver machine generation for microblaze, heres the current version of the system maintained out of tree at Xilinx.
Looking to collaborate with Chris (or anyone else out there) on how we can converge our implementations.
Major outstanding issues:
-The Flash and Serial stuff is a bit of a hack as they arent there yet with QOM. I think Anthony has some stuff in a series to fix up serial which clear this series up a little bit. Ditto for PFlash, with outstanding QOM issues. -Need to rework the API to handle nodepaths a little cleaner.
Peter A. G. Crosthwaite (10):
device_tree: allow offsets for cell properties
device_tree: return Error* from prop getters
device_tree: allow property getters to inherit
device_tree: get_prop(): memdup returned properties
qemu-coroutine: Add simple work queue support
device_tree: Extended interface for fdt_generic
fdt_generic: First revision
pflash_cfi01: Added fdt generic platform support
microblaze_generic_fdt: first revision
serial: added fdt generic platform support
default-configs/microblaze-softmmu.mak | 1 + default-configs/microblazeel-softmmu.mak | 1 + device_tree.c | 199 +++++++++++++- device_tree.h | 38 +++- hw/arm_boot.c | 10 +- hw/fdt_generic.c | 215 +++++++++++++++ hw/fdt_generic.h | 92 +++++++ hw/fdt_generic_devices.c | 80 ++++++ hw/fdt_generic_devices.h | 8 + hw/fdt_generic_util.c | 438 ++++++++++++++++++++++++++++++ hw/fdt_generic_util.h | 36 +++ hw/microblaze/Makefile.objs | 5 + hw/microblaze_generic_fdt.c | 378 ++++++++++++++++++++++++++ qemu-coroutine-lock.c | 13 + qemu-coroutine.h | 9 + 15 files changed, 1507 insertions(+), 16 deletions(-) create mode 100644 hw/fdt_generic.c create mode 100644 hw/fdt_generic.h create mode 100644 hw/fdt_generic_devices.c create mode 100644 hw/fdt_generic_devices.h create mode 100644 hw/fdt_generic_util.c create mode 100644 hw/fdt_generic_util.h create mode 100644 hw/microblaze_generic_fdt.c
RFC 1/10 device_tree: allow offsets for cell properties
--- device_tree.c | 10 +++++----- device_tree.h | 2 +- hw/arm_boot.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
device_tree.c +5 -5
@@ -196,16 +196,16 @@ const void *qemu_devtree_getprop(void *fdt, const char *node_path, }uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path, -const char *property) +const char *property,int offset) {int len;const uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len); -if (len !=4 ) { -fprintf (stderr,"%s: %s/%s not 4 bytes long (not a cell?)\n" , - __func__, node_path, property); +if (len < (offset+1 )*4 ) { +fprintf (stderr,"%s: %s/%s not long enough to hold %d properties\n" , + __func__, node_path, property, offset+1 );exit (1 ); } -return be32_to_cpu (*p); +return be32_to_cpu (p[offset]); }uint32_t qemu_devtree_get_phandle (void *fdt,const char *path)
device_tree.h +1 -1
@@ -31,7 +31,7 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,const void *qemu_devtree_getprop (void *fdt,const char *node_path,const char *property,int *lenp);uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path, -const char *property); +const char *property,int offset);uint32_t qemu_devtree_get_phandle (void *fdt,const char *path);uint32_t qemu_devtree_alloc_phandle (void *fdt);int qemu_devtree_nop_node (void *fdt,const char *node_path);
hw/arm_boot.c +2 -2
@@ -237,8 +237,8 @@ static int load_dtb(target_phys_addr_t addr, const struct arm_boot_info *binfo) }g_free (filename); - acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ); - scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ); + acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ,0 ); + scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ,0 );if (acells ==0 || scells ==0 ) {fprintf (stderr,"dtb file invalid (#address-cells or #size-cells 0)\n" );return -1 ;
Signature · 1 line
1.7.0.4
RFC 2/10 device_tree: return Error* from prop getters
In reply to Peter A. G. CrosthwaiteRather than exit(1) on fail return an Error*. Clients can then handle errors as they wish.
--- device_tree.c | 25 ++++++++++++++++++------- device_tree.h | 9 +++++++-- hw/arm_boot.c | 8 ++++++-- 3 files changed, 31 insertions(+), 11 deletions(-)
device_tree.c +18 -7
@@ -179,7 +179,8 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path, }const void *qemu_devtree_getprop (void *fdt,const char *node_path, -const char *property,int *lenp) +const char *property,int *lenp, +Error **errp) {int len;const void *r;
@@ -190,20 +191,30 @@ const void *qemu_devtree_getprop(void *fdt, const char *node_path,if (!r) {fprintf (stderr,"%s: Couldn't get %s/%s: %s\n" , __func__, node_path, property,fdt_strerror (*lenp)); -exit (1 ); +/* FIXME: Be smarter */ +error_set (errp,QERR_UNDEFINED_ERROR ); +return NULL ; }return r; }uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path, -const char *property,int offset) +const char *property,int offset, +Error **errp) {int len; -const uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len); +const uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len, + errp); +if (errp && *errp) { +return 0 ; + }if (len < (offset+1 )*4 ) { -fprintf (stderr,"%s: %s/%s not long enough to hold %d properties\n" , - __func__, node_path, property, offset+1 ); -exit (1 ); +fprintf (stderr,"%s: %s/%s not long enough to hold %d properties " +"(length = %d)\n" , __func__, node_path, property, + offset+1 , len); +/* FIXME: Be smarter */ +error_set (errp,QERR_UNDEFINED_ERROR ); +return 0 ; }return be32_to_cpu (p[offset]); }
device_tree.h +7 -2
@@ -14,6 +14,9 @@#ifndef __DEVICE_TREE_H__#define __DEVICE_TREE_H__ +#include "qemu-common.h" +#include "qerror.h" +void *create_device_tree (int *sizep);void *load_device_tree (const char *filename_path,int *sizep);
@@ -29,9 +32,11 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,const char *property, const char *target_node_path);const void *qemu_devtree_getprop (void *fdt,const char *node_path, -const char *property,int *lenp); +const char *property,int *lenp, +Error **errp);uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path, -const char *property,int offset); +const char *property,int offset, +Error **errp);uint32_t qemu_devtree_get_phandle (void *fdt,const char *path);uint32_t qemu_devtree_alloc_phandle (void *fdt);int qemu_devtree_nop_node (void *fdt,const char *node_path);
hw/arm_boot.c +6 -2
@@ -221,6 +221,8 @@ static int load_dtb(target_phys_addr_t addr, const struct arm_boot_info *binfo)void *fdt =NULL ;char *filename;int size, rc; +Error *errp =NULL ; +uint32_t acells, scells, hival; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , binfo->dtb_filename);
@@ -237,8 +239,10 @@ static int load_dtb(target_phys_addr_t addr, const struct arm_boot_info *binfo) }g_free (filename); - acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ,0 ); - scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ,0 ); + acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ,0 , &errp); + scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ,0 , &errp); +assert_no_error (errp); +if (acells ==0 || scells ==0 ) {fprintf (stderr,"dtb file invalid (#address-cells or #size-cells 0)\n" );return -1 ;
Signature · 1 line
1.7.0.4
RFC 3/10 device_tree: allow property getters to inherit
In reply to Peter A. G. CrosthwaiteIf the inherit flag is set, and the specified property is not found, then search the parents for it as well.
--- device_tree.c | 11 ++++++++--- device_tree.h | 4 ++-- hw/arm_boot.c | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-)
device_tree.c +8 -3
@@ -180,7 +180,7 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,const void *qemu_devtree_getprop (void *fdt,const char *node_path,const char *property,int *lenp, -Error **errp) +bool inherit,Error **errp) {int len;const void *r;
@@ -189,6 +189,11 @@ const void *qemu_devtree_getprop(void *fdt, const char *node_path, } r =fdt_getprop (fdt,findnode_nofail (fdt, node_path), property, lenp);if (!r) { +char parent[DT_PATH_LENGTH ]; +if (inherit && !qemu_devtree_getparent (fdt, parent, node_path)) { +return qemu_devtree_getprop (fdt, parent, property, lenp, true, + errp); + }fprintf (stderr,"%s: Couldn't get %s/%s: %s\n" , __func__, node_path, property,fdt_strerror (*lenp));/* FIXME: Be smarter */
@@ -200,11 +205,11 @@ const void *qemu_devtree_getprop(void *fdt, const char *node_path,uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path,const char *property,int offset, -Error **errp) +bool inherit,Error **errp) {int len;const uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len, - errp); + inherit, errp);if (errp && *errp) {return 0 ; }
device_tree.h +2 -2
@@ -33,10 +33,10 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path, const char *target_node_path);const void *qemu_devtree_getprop (void *fdt,const char *node_path,const char *property,int *lenp, -Error **errp); +bool inherit,Error **errp);uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path,const char *property,int offset, -Error **errp); +bool inherit,Error **errp);uint32_t qemu_devtree_get_phandle (void *fdt,const char *path);uint32_t qemu_devtree_alloc_phandle (void *fdt);int qemu_devtree_nop_node (void *fdt,const char *node_path);
hw/arm_boot.c +4 -2
@@ -239,8 +239,10 @@ static int load_dtb(target_phys_addr_t addr, const struct arm_boot_info *binfo) }g_free (filename); - acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ,0 , &errp); - scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ,0 , &errp); + acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ,0 , + false, &errp); + scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ,0 , + false, &errp);assert_no_error (errp);if (acells ==0 || scells ==0 ) {
Signature · 1 line
1.7.0.4
RFC 4/10 device_tree: get_prop(): memdup returned properties
In reply to Peter A. G. Crosthwaitegetprop currently return a pointer into the device tree itself. These pointers will be corrupted if the device tree is written to in anyway. To make getprop() safe, duplicate the property so that the value doesnt change over the lifetime of the returned pointer.
--- device_tree.c | 11 +++++++---- device_tree.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-)
device_tree.c +7 -4
@@ -178,7 +178,7 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,return r; } -const void *qemu_devtree_getprop (void *fdt,const char *node_path, +void *qemu_devtree_getprop (void *fdt,const char *node_path,const char *property,int *lenp,bool inherit,Error **errp) {
@@ -200,7 +200,7 @@ const void *qemu_devtree_getprop(void *fdt, const char *node_path,error_set (errp,QERR_UNDEFINED_ERROR );return NULL ; } -return r; +return g_memdup (r, *lenp); } uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path,
@@ -208,7 +208,8 @@ uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path, bool inherit, Error **errp) { int len; -const uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len, +uint32_t ret; +uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len, inherit, errp);if (errp && *errp) {return 0 ;
@@ -221,7 +222,9 @@ uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path,error_set (errp,QERR_UNDEFINED_ERROR );return 0 ; } -return be32_to_cpu (p[offset]); + ret =be32_to_cpu (p[offset]); +g_free (p); +return ret; }uint32_t qemu_devtree_get_phandle (void *fdt,const char *path)
device_tree.h +1 -1
@@ -31,7 +31,7 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,int qemu_devtree_setprop_phandle (void *fdt,const char *node_path,const char *property,const char *target_node_path); -const void *qemu_devtree_getprop (void *fdt,const char *node_path, +void *qemu_devtree_getprop (void *fdt,const char *node_path,const char *property,int *lenp,bool inherit,Error **errp); uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path,
Signature · 1 line
1.7.0.4
RFC 5/10 qemu-coroutine: Add simple work queue support
In reply to Peter A. G. CrosthwaiteAdd a function co_queue_enter_next() which will immediately transfer control to the coroutine at the head of a co queue. This can be used for implementing simple work queues where the manager of a co-queue only needs to enter queued routines one at a time.
--- qemu-coroutine-lock.c | 13 +++++++++++++ qemu-coroutine.h | 9 +++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
qemu-coroutine-lock.c +13 -0
@@ -91,6 +91,19 @@ void qemu_co_queue_restart_all(CoQueue *queue) } } +bool qemu_co_queue_enter_next (CoQueue *queue) +{ +Coroutine *next; + + next =QTAILQ_FIRST (&queue->entries); +if (next) { +QTAILQ_REMOVE (&queue->entries, next, co_queue_next); +qemu_coroutine_enter (next,NULL ); + } + +return (next !=NULL ); +} +bool qemu_co_queue_empty (CoQueue *queue) {return (QTAILQ_FIRST (&queue->entries) ==NULL );
qemu-coroutine.h +9 -0
@@ -137,6 +137,15 @@ bool qemu_co_queue_next(CoQueue *queue);void qemu_co_queue_restart_all (CoQueue *queue);/** +* Transfers control to the next coroutine in the CoQueue and removes it from +* the queue. +* +* Returns true once after control transfers back to caller, or false +* immediately if the queue is empty. +*/ +bool qemu_co_queue_enter_next (CoQueue *queue); + +/** * Checks if the CoQueue is empty. */ bool qemu_co_queue_empty (CoQueue *queue);
Signature · 1 line
1.7.0.4
RFC 6/10 device_tree: Extended interface for fdt_generic
In reply to Peter A. G. CrosthwaiteExtended the wrapper interface (around libfdt) for device tree. Node Property getters have been added (qemu_devtree_getprop*) as well as helpers to search/ navigate the nodes of a FDT blob.
--- device_tree.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ device_tree.h | 27 ++++++++++ 2 files changed, 185 insertions(+), 0 deletions(-)
device_tree.c +158 -0
@@ -323,3 +323,161 @@ int qemu_devtree_add_subnode(void *fdt, const char *name)g_free (dupname);return retval; } + +char *qemu_devtree_get_node_name (void *fdt,const char *node_path) +{ +const char *ret =fdt_get_name (fdt,fdt_path_offset (fdt, node_path),NULL ); +return ret ?strdup (ret) :NULL ; +} + +int qemu_devtree_get_node_depth (void *fdt,const char *node_path) +{ +return fdt_node_depth (fdt,fdt_path_offset (fdt, node_path)); +} + +static void qemu_devtree_children_info (void *fdt,const char *node_path, +int depth,int *num,char **returned_paths) { +int offset =fdt_path_offset (fdt, node_path); +int root_depth =fdt_node_depth (fdt, offset); +int cur_depth = root_depth; + + *num =0 ; +for (;;) { + offset =fdt_next_node (fdt, offset, &cur_depth); +if (cur_depth <= root_depth) { +break ; + } +if (cur_depth <= root_depth + depth || depth ==0 ) { +if (returned_paths) { + returned_paths[*num] =g_malloc0 (DT_PATH_LENGTH ); +fdt_get_path (fdt, offset, returned_paths[*num],DT_PATH_LENGTH ); + } + (*num)++; + } + } +} + +char **qemu_devtree_get_children (void *fdt,const char *node_path,int depth) +{ +int num_children =qemu_devtree_get_num_children (fdt, node_path, depth); +char **ret =g_malloc0 (sizeof (*ret) * num_children); + +qemu_devtree_children_info (fdt, node_path, depth, &num_children, ret); +return ret; +} + +int qemu_devtree_get_num_children (void *fdt,const char *node_path,int depth) +{ +int ret; + +qemu_devtree_children_info (fdt, node_path, depth, &ret,NULL ); +return ret; +} + +int qemu_devtree_node_by_compatible (void *fdt,char *node_path, +const char *compats) +{ +int offset =fdt_node_offset_by_compatible (fdt,0 , compats); +return offset >0 ? +fdt_get_path (fdt, offset, node_path,DT_PATH_LENGTH ) :1 ; +} + +int qemu_devtree_get_node_by_name (void *fdt,char *node_path, +const char *cmpname) { +int offset =0 ; +char *name =NULL ; + +do { + offset =fdt_next_node (fdt, offset,NULL ); + name = (void *)fdt_get_name (fdt, offset,NULL ); +if (!name) { +continue ; + } +if (!strncmp (name, cmpname,strlen (cmpname))) { +break ; + } + }while (offset >0 ); +return offset >0 ? +fdt_get_path (fdt, offset, node_path,DT_PATH_LENGTH ) :1 ; +} + +int qemu_devtree_get_node_by_phandle (void *fdt,char *node_path,int phandle) +{ +return fdt_get_path (fdt,fdt_node_offset_by_phandle (fdt, phandle), + node_path,DT_PATH_LENGTH ); +} + +int qemu_devtree_getparent (void *fdt,char *node_path,const char *current) +{ +int offset =fdt_path_offset (fdt, current); +int parent_offset =fdt_supernode_atdepth_offset (fdt, offset, +fdt_node_depth (fdt, offset) -1 ,NULL ); + +return parent_offset >0 ? +fdt_get_path (fdt, parent_offset, node_path,DT_PATH_LENGTH ) :1 ; +} + +int qemu_devtree_get_root_node (void *fdt,char *node_path) +{ +return fdt_get_path (fdt,0 , node_path,DT_PATH_LENGTH ); +} + +static void devtree_scan (void *fdt,int *num_nodes,int info_dump) +{ +int depth =0 , offset =0 ; + +if (num_nodes) { + *num_nodes =0 ; + } +for (;;) { + offset =fdt_next_node (fdt, offset, &depth); +if (num_nodes) { + (*num_nodes)++; + } +if (offset <=0 || depth <=0 ) { +break ; + } + +if (info_dump) { +char node_path[DT_PATH_LENGTH ]; +char *all_compats =NULL ; +int compat_len; +Error *errp =NULL ; + +if (fdt_get_path (fdt, offset, node_path,DT_PATH_LENGTH )) { +sprintf (node_path,"(none)" ); + }else { + all_compats =qemu_devtree_getprop (fdt, node_path,"compatible" , + &compat_len, false, &errp); + } +if (!errp) { +char *i = all_compats; +for (;;) { +char *j =rawmemchr (i,'\0' ); + compat_len -= ((j+1 )-i); +if (!compat_len) { +break ; + } + *j =' ' ; + i = j+1 ; + } + } +printf ("OFFSET: %d, DEPTH: %d, PATH: %s, COMPATS: %s\n" , + offset, depth, node_path, + all_compats ? all_compats :"(none)" ); + } + } +} + +void devtree_info_dump (void *fdt) +{ +devtree_scan (fdt,NULL ,1 ); +} + +int devtree_get_num_nodes (void *fdt) +{ +int ret; + +devtree_scan (fdt, &ret,0 ); +return ret; +}
device_tree.h +27 -0
@@ -20,6 +20,8 @@void *create_device_tree (int *sizep);void *load_device_tree (const char *filename_path,int *sizep); +/* property setters */ +int qemu_devtree_setprop (void *fdt,const char *node_path,const char *property,const void *val_array,int size); int qemu_devtree_setprop_cell(void *fdt, const char *node_path,
@@ -54,4 +56,29 @@ int qemu_devtree_add_subnode(void *fdt, const char *name); sizeof(qdt_tmp)); \ } while (0) +/* node queries */ + +char *qemu_devtree_get_node_name(void *fdt, const char *node_path); +int qemu_devtree_get_node_depth (void *fdt,const char *node_path); +int qemu_devtree_get_num_children (void *fdt,const char *node_path,int depth); +char **qemu_devtree_get_children (void *fdt,const char *node_path,int depth); + +/* node getters */ + +int qemu_devtree_node_by_compatible (void *fdt,char *node_path, +const char *compats); +int qemu_devtree_get_node_by_name (void *fdt,char *node_path, +const char *cmpname); +int qemu_devtree_get_node_by_phandle (void *fdt,char *node_path,int phandle); +int qemu_devtree_getparent (void *fdt,char *node_path, +const char *current); +int qemu_devtree_get_root_node (void *fdt,char *node_path); + +/* misc */ + +int devtree_get_num_nodes (void *fdt); +void devtree_info_dump (void *fdt); + +#define DT_PATH_LENGTH 1024 +#endif /* __DEVICE_TREE_H__ */
Signature · 1 line
1.7.0.4
RFC 7/10 fdt_generic: First revision
In reply to Peter A. G. CrosthwaiteFirst revision of fdt generic infrastructure. These modules allow for fdt generic machine models, which create machines to match a device tree specification.
--- default-configs/microblaze-softmmu.mak | 1 + default-configs/microblazeel-softmmu.mak | 1 + hw/fdt_generic.c | 215 +++++++++++++++ hw/fdt_generic.h | 92 +++++++ hw/fdt_generic_util.c | 438 ++++++++++++++++++++++++++++++ hw/fdt_generic_util.h | 36 +++ hw/microblaze/Makefile.objs | 3 + 7 files changed, 786 insertions(+), 0 deletions(-) create mode 100644 hw/fdt_generic.c create mode 100644 hw/fdt_generic.h create mode 100644 hw/fdt_generic_util.c create mode 100644 hw/fdt_generic_util.h
default-configs/microblaze-softmmu.mak +1 -0
@@ -5,3 +5,4 @@ CONFIG_PFLASH_CFI01=y CONFIG_SERIAL=y CONFIG_XILINX=y CONFIG_XILINX_AXI=y +CONFIG_FDT_GENERIC=y
default-configs/microblazeel-softmmu.mak +1 -0
@@ -5,3 +5,4 @@ CONFIG_PFLASH_CFI01=y CONFIG_SERIAL=y CONFIG_XILINX=y CONFIG_XILINX_AXI=y +CONFIG_FDT_GENERIC=y
hw/fdt_generic.c new file +215 -0
215 lines not on this page · raw message
hw/fdt_generic.h new file +92 -0
92 lines not on this page · raw message
hw/fdt_generic_util.c new file +438 -0
438 lines not on this page · raw message
hw/fdt_generic_util.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef FDT_GENERIC_UTIL_H +#define FDT_GENERIC_UTIL_H + +#include "qemu-common.h" +#include "fdt_generic.h" + +/* create a fdt_generic machine. the top level cpu irqs are required for +* systems instantiating interrupt devices. The client is responsible for +* destroying the returned FDTMachineInfo (using fdt_init_destroy_fdti) +*/ + +FDTMachineInfo *fdt_generic_create_machine (void *fdt,qemu_irq *cpu_irq); + +/* fdt init a simple bus. Search the bus for child nodes and instantiate or +* invalidate devices as appropriate. Conformant to FDTInitFn prototype, i.e. +* a bus may fdt_register_compatibilty this as its instantiator. +*/ + +int simple_bus_fdt_init (char *node_path,FDTMachineInfo *fdti,void *priv); + +/* get an irq for a device. The interrupt parent of a device is idenitified +* and the specified irq (by the interrupts device-tree property) is retrieved +*/ + +qemu_irq fdt_get_irq (FDTMachineInfo *fdti,char *node_path,int irq_idx); + +/* same as above, but poulates err with non-zero if something goes wrong, and +* populates info with a human readable string giving some basic information +* about the interrupt connection found (or not found). Both arguments are +* optional (i.e. can be NULL) +*/ + +qemu_irq fdt_get_irq_info (FDTMachineInfo *fdti,char *node_path,int irq_idx, +int *err,char * info); + +#endif /* FDT_GENERIC_UTIL_H */
hw/microblaze/Makefile.objs +3 -0
@@ -6,4 +6,7 @@ obj-y += microblaze_pic_cpu.o obj-y += xilinx_ethlite.o obj-$(CONFIG_FDT) += ../device_tree.o +obj-$(CONFIG_FDT_GENERIC) += fdt_generic.o +obj-$(CONFIG_FDT_GENERIC) += fdt_generic_util.o + obj-y := $(addprefix ../,$(obj-y))
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [RFC v0 07/10] fdt_generic: First revision
Il 17/09/2012 11:02, Peter A. G. Crosthwaite ha scritto:
Quoted 3 lines
First revision of fdt generic infrastructure. These modules allow for fdt generic machine models, which create machines to match a device tree specification.
Ok, so here is the famous coroutine-based FDT generation. :)
It does look pretty, to be fair.
However, as things stand there is nothing (I think) that really requires coroutines. A simple 2-pass initialization would do, with links and irqs connected on the second pass. I'm wondering how your patch fares in terms of error handling for example; can you end up with partially-uninitialized devices or infinite loops? If so, why not?
It would be nice if you included some simple qtest test cases. They would generate a few machines with different device trees and check that the output of "info qtree" matches somewhat the device tree. Rough checks should not be hard to implement, and would provide some guidance to people who want to hack the code.
Paolo
Re: [Qemu-devel] [RFC v0 07/10] fdt_generic: First revision
Quoted 9 lines · Paolo Bonzini
Il 17/09/2012 11:02, Peter A. G. Crosthwaite ha scritto:
Quoted 3 lines
First revision of fdt generic infrastructure. These modules allow for fdt generic machine models, which create machines to match a device tree specification.
Ok, so here is the famous coroutine-based FDT generation. :)
It does look pretty, to be fair.
Thanks :)
Quoted 3 lines
However, as things stand there is nothing (I think) that really requires coroutines. A simple 2-pass initialization would do, with links and irqs connected on the second pass.
I'm just trying to be a little more general. For more complex setups we may in the future want to resolve dependencies at different phases of the machine init process. The ability to yield arbitrarily solves that problem universally rather than have to manage a discrete number of passes. That and two pass is brutally ugly in code (and in-efficient) as you need to tag passes.
I'm wondering how your patch fares
Quoted 3 lines
in terms of error handling for example; can you end up with partially-uninitialized devices or infinite loops? If so, why not?
Deadlock looping shouldnt happen if thats what your worried about. Each device is instantiated before its able to yield (waiting on another) and all devices are inited before you reach that all-threads-are-yielded point. Essentially your "first-pass" as you suggested above is complete before before every thread is yielded, which makes deadlock impossible with current usages.
Paritally initied shouldnt happen - as that can only happen if coroutines are left yielded. The machine init does not return until all coros have exited.
Regards,
Peter
Quoted 7 lines
It would be nice if you included some simple qtest test cases. They would generate a few machines with different device trees and check that the output of "info qtree" matches somewhat the device tree. Rough checks should not be hard to implement, and would provide some guidance to people who want to hack the code.
Paolo
Re: [Qemu-devel] [RFC v0 07/10] fdt_generic: First revision
Quoted 7 lines
Quoted 3 lines
However, as things stand there is nothing (I think) that really requires coroutines. A simple 2-pass initialization would do, with links and irqs connected on the second pass.
I'm just trying to be a little more general. For more complex setups we may in the future want to resolve dependencies at different phases of the machine init process.
Do you have any examples of things that are more complicated than "build everything" followed by "resolve everything"?
Quoted 2 lines
That and two pass is brutally ugly in code (and
in-efficient) as you need to tag passes.
Not sure I follow, but I can't of course promise aesthetics without having written any code.
Quoted 10 lines
I'm wondering how your patch fares
Quoted 2 lines
in terms of error handling for example; can you end up with partially-uninitialized devices or infinite loops? If so, why not?
Deadlock looping shouldnt happen if thats what your worried about. Each device is instantiated before its able to yield (waiting on another) and all devices are inited before you reach that all-threads-are-yielded point. Essentially your "first-pass" as you suggested above is complete before before every thread is yielded, which makes deadlock impossible with current usages.
Ok, so something checks the syntax before initialization runs.
Pao
RFC 8/10 pflash_cfi01: Added fdt generic platform support
In reply to Peter A. G. CrosthwaiteAdded fdt generic platform support. Note that this does not add the fdt init handler to the table of registered models as this needs to be handled in a platform dependent way (due to target endianness issues). Fdt generic machine models are required to register this device should it be supported.
--- hw/fdt_generic_devices.c | 45 +++++++++++++++++++++++++++++++++++++++++++ hw/fdt_generic_devices.h | 8 +++++++ hw/microblaze/Makefile.objs | 1 + 3 files changed, 54 insertions(+), 0 deletions(-) create mode 100644 hw/fdt_generic_devices.c create mode 100644 hw/fdt_generic_devices.h
hw/fdt_generic_devices.c new file +45 -0
@@ -0,0 +1,45 @@ + +#include "blockdev.h" + +#include "fdt_generic_util.h" +#include "fdt_generic_devices.h" + +#define FLASH_SECTOR_SIZE (64 * 1024) + +/* FIXME: This file should go away. When these devices are properly QOMified +* then these FDT creations should happen automatically without need for these +* explict shim functions +*/ + +int pflash_cfi01_fdt_init (char *node_path,FDTMachineInfo *fdti,void *opaque) +{ + +int flash_base =0 ; +int flash_size =0 ; +Error *errp =NULL ; + +int be = *((int *)opaque); + +DriveInfo *dinfo; +int bank_width; + + flash_base =qemu_devtree_getprop_cell (fdti->fdt, node_path,"reg" ,0 , + false, &errp); + flash_size =qemu_devtree_getprop_cell (fdti->fdt, node_path,"reg" ,1 , + false, &errp); + bank_width =qemu_devtree_getprop_cell (fdti->fdt, node_path,"bank-width" , +0 , false, &errp); +assert_no_error (errp); + +printf ("FDT: FLASH: baseaddr: 0x%x, size: 0x%x\n" , + flash_base, flash_size); + + dinfo =drive_get_next (IF_PFLASH ); +pflash_cfi01_register (flash_base,NULL , node_path, flash_size, + dinfo ? dinfo->bdrv :NULL ,FLASH_SECTOR_SIZE , + flash_size/FLASH_SECTOR_SIZE , + bank_width,0x89 ,0x18 ,0x0000 ,0x0 , be); +return 0 ; +} + +#endif /* CONFIG_FDT */
hw/fdt_generic_devices.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef FDT_GENERIC_DEVICES_H +#define FDT_GENERIC_DEVICES_H + +#include "fdt_generic.h" + +int pflash_cfi01_fdt_init (char *node_path,FDTMachineInfo *fdti,void *opaque); + +#endif /* FDT_GENERIC_DEVICES_H */
hw/microblaze/Makefile.objs +1 -0
@@ -8,5 +8,6 @@ obj-$(CONFIG_FDT) += ../device_tree.o obj-$(CONFIG_FDT_GENERIC) += fdt_generic.o obj-$(CONFIG_FDT_GENERIC) += fdt_generic_util.o +obj-$(CONFIG_FDT_GENERIC) += fdt_generic_devices.o obj-y := $(addprefix ../,$(obj-y))
Signature · 1 line
1.7.0.4
RFC 9/10 microblaze_generic_fdt: first revision
In reply to Peter A. G. CrosthwaiteFirst revision of fdt generic platform for xilinx microblaze platforms. Adds machine model "microblaze-fdt" which can be used along with the --hw-dtb option to lauch dts driven machine models for microblaze platforms.
--- hw/microblaze/Makefile.objs | 1 + hw/microblaze_generic_fdt.c | 378 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 379 insertions(+), 0 deletions(-) create mode 100644 hw/microblaze_generic_fdt.c
hw/microblaze/Makefile.objs +1 -0
@@ -1,5 +1,6 @@ obj-y = petalogix_s3adsp1800_mmu.o obj-y += petalogix_ml605_mmu.o +obj-y += microblaze_generic_fdt.o obj-y += microblaze_boot.o obj-y += microblaze_pic_cpu.o
hw/microblaze_generic_fdt.c new file +378 -0
378 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [RFC v0 09/10] microblaze_generic_fdt: first revision
Am 17.09.2012 11:03, schrieb Peter A. G. Crosthwaite:
Quoted 16 lines
First revision of fdt generic platform for xilinx microblaze platforms. Adds machine model "microblaze-fdt" which can be used along with the --hw-dtb option to lauch dts driven machine models for microblaze platforms.
Signed-off-by Peter A. G. Crosthwaite <[email protected]>--- hw/microblaze/Makefile.objs | 1 + hw/microblaze_generic_fdt.c | 378 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 379 insertions(+), 0 deletions(-) create mode 100644 hw/microblaze_generic_fdt.chw/microblaze/Makefile.objs +0
-0
hw/microblaze/Makefile.objs line 6
Quoted 6 lines
hw/microblaze/Makefile.objs +1
-0@@ -1,5 +1,6 @@ obj-y = petalogix_s3adsp1800_mmu.o obj-y += petalogix_ml605_mmu.o +obj-y += microblaze_generic_fdt.o obj-y += microblaze_boot.o obj-y += microblaze_pic_cpu.o
[snip]
Since this file clearly is MicroBlaze-specific, I suggest to place it in hw/microblaze/generic_fdt.c instead. (CC'ing Mr. Makefile)
Cheers,
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
Re: [Qemu-devel] [RFC v0 09/10] microblaze_generic_fdt: first revision
Il 17/09/2012 17:20, Andreas Färber ha scritto:
Quoted 2 lines
Since this file clearly is MicroBlaze-specific, I suggest to place it in
hw/microblaze/generic_fdt.cinstead. (CC'ing Mr.Makefile)
Seconded, we have to start somewhere...
Paolo
RFC 10/10 serial: added fdt generic platform support
In reply to Peter A. G. Crosthwaitefdt generic platform support for 16550 uarts.
--- hw/fdt_generic_devices.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-)
hw/fdt_generic_devices.c +37 -2
@@ -1,4 +1,3 @@ -#include "blockdev.h" #include "fdt_generic_util.h"
@@ -42,4 +41,40 @@ int pflash_cfi01_fdt_init(char *node_path, FDTMachineInfo *fdti, void *opaque)return 0 ; } -#endif /* CONFIG_FDT */ +static int uart16550_fdt_init (char *node_path,FDTMachineInfo *fdti, +void *priv) +{ +/* FIXME: Pass in dynamically */ +MemoryRegion *address_space_mem =get_system_memory (); +target_phys_addr_t base; +int baudrate; +qemu_irq irqline; +char irq_info[1024 ]; +void *serial =NULL ; +Error *errp =NULL ; + + base =qemu_devtree_getprop_cell (fdti->fdt, node_path,"reg" ,0 , + false, &errp); + base +=qemu_devtree_getprop_cell (fdti->fdt, node_path,"reg-offset" ,0 , + false, &errp); +assert_no_error (errp); + base &= ~3ULL ;/* qemu uart16550 model starts with 3* 8bit offset */ + + baudrate =qemu_devtree_getprop_cell (fdti->fdt, node_path,"current-speed" , +0 , false, &errp); +if (errp) { + baudrate =115200 ; + } + + irqline =fdt_get_irq_info (fdti, node_path,0 ,NULL , irq_info); +printf ("FDT: UART16550a: baseaddr: 0x" + TARGET_FMT_plx", irq: %s, baud %d\n" , base, irq_info, baudrate); + +/* it_shift = 2, reg-shift in DTS - for Xilnx IP is hardcoded */ + serial =serial_mm_init (address_space_mem, base,2 , irqline, baudrate, +qemu_char_get_next_serial (),DEVICE_LITTLE_ENDIAN ); +return 0 ; +} + +fdt_register_compatibility_n (uart16550_fdt_init,"ns16550" ,0 ); +fdt_register_compatibility_n (uart16550_fdt_init,"ns16550a" ,1 );
Signature · 1 line
1.7.0.4