resolv device by Flattened Device Tree alias name
v2 cover resolv device by Flattened Device Tree alias name
Hi,
This RFC series is intended to simplify Flattened Device Tree support, in particular the 'compatible' FDT entry, when Linux names mismatches QEMU ones, but this is the same device modelled.
So far this is only a 'proof of concept'.
To see how the qtests perform, I only modified the Xilinx ZynqMP machine.
This is only the 6th generic alias compatibility API in QEMU ¯\_(ツ)_/¯
Since v2:
- Follow Eduardo advice:
"If aliases exist only for compatibility, they should be restricted to the places where compatibility is really needed."
- Do not modify QOM/qobject, use a specific GHashTable for FDT alias resolv.
- The aliases aren't display in HMP / -device help
If a machine is expected to use FDT, it needs to explicitely resolv any device name with the type_resolve_fdt_alias() function.
Regards,
Phil.
Philippe Mathieu-Daudé (9):
hw/sysbus: add helpers to register FDT aliases hw/char/cadence_uart: add FDT aliases hw/net/cadence_gem: add FDT aliases hw/timer/cadence_ttc: add FDT aliases hw/dma/axidma: add 'xlnx,eth-dma' FDT alias hw/usb/hcd-ehci: add 'xlnx,ps7-usb' FDT aliases hw/ssi/xlnx-spips: add 'xlnx.zynq-qspi' FDT alias hw/dma/xlnx_dpdma: add 'xlnx,axi-dpdma-1.0' FDT alias hw/arm/xlnx-zynqmp: use Linux FDT names
include/hw/sysbus-fdt.h | 18 ++++++++++++++++++ hw/arm/xlnx-zynqmp.c | 14 ++++++++++---- hw/char/cadence_uart.c | 12 ++++++++++++ hw/core/sysbus-fdt.c | 30 ++++++++++++++++++++++++++++++ hw/dma/xilinx_axidma.c | 2 ++ hw/dma/xlnx_dpdma.c | 2 ++ hw/net/cadence_gem.c | 10 ++++++++++ hw/ssi/xilinx_spips.c | 2 ++ hw/timer/cadence_ttc.c | 8 ++++++++ hw/usb/hcd-ehci-sysbus.c | 8 ++++++++ hw/core/Makefile.objs | 1 + 11 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 include/hw/sysbus-fdt.h create mode 100644 hw/core/sysbus-fdt.c
Signature · 1 line
2.15.1
RFC PATCH v2 1/9 hw/sysbus: add helpers to register FDT aliases
--- include/hw/sysbus-fdt.h | 18 ++++++++++++++++++ hw/core/sysbus-fdt.c | 30 ++++++++++++++++++++++++++++++ hw/core/Makefile.objs | 1 + 3 files changed, 49 insertions(+) create mode 100644 include/hw/sysbus-fdt.h create mode 100644 hw/core/sysbus-fdt.c
include/hw/sysbus-fdt.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Flattened Device Tree alias helpers +* +* Copyright (C) 2018 Philippe Mathieu-Daudé <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* (at your option) any later version. See the COPYING file in the +* top-level directory. +*/ +#ifndef HW_SYSBUS_FDT_H +#define HW_SYSBUS_FDT_H + +void type_register_fdt_alias (const char *name,const char *alias); +void type_register_fdt_aliases (const char *name,const char **aliases); + +const char *type_resolve_fdt_alias (const char *alias); + +#endif /* HW_SYSBUS_FDT_H */
hw/core/sysbus-fdt.c new file +30 -0
@@ -0,0 +1,30 @@ +#include "qemu/osdep.h" +#include "hw/sysbus-fdt.h" + +static GHashTable *fdt_aliases (void ) +{ +static GHashTable *fdt_aliases_singleton; + +if (!fdt_aliases_singleton) { + fdt_aliases_singleton =g_hash_table_new (g_str_hash, g_str_equal); + } +return fdt_aliases_singleton; +} + +void type_register_fdt_alias (const char *name,const char *alias) +{ +g_hash_table_insert (fdt_aliases (), (gpointer )name, (gpointer )name); +g_hash_table_insert (fdt_aliases (), (gpointer )alias, (gpointer )name); +} + +void type_register_fdt_aliases (const char *name,const char **aliases) +{ +for (; *aliases; aliases++) { +type_register_fdt_alias (name, *aliases); + } +} + +const char *type_resolve_fdt_alias (const char *alias) +{ +return g_hash_table_lookup (fdt_aliases (), alias); +}
hw/core/Makefile.objs +1 -0
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o common-obj-$(CONFIG_XILINX_AXI) += stream.o common-obj-$(CONFIG_PTIMER) += ptimer.o common-obj-$(CONFIG_SOFTMMU) += sysbus.o +common-obj-$(CONFIG_SOFTMMU) += sysbus-fdt.o common-obj-$(CONFIG_SOFTMMU) += machine.o common-obj-$(CONFIG_SOFTMMU) += loader.o common-obj-$(CONFIG_FITLOADER) += loader-fit.o
Signature · 1 line
2.15.1
RFC PATCH v2 2/9 hw/char/cadence_uart: add FDT aliases
In reply to Philippe Mathieu-Daudé--- hw/char/cadence_uart.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/char/cadence_uart.c +12 -0
@@ -23,6 +23,7 @@#include "qemu/osdep.h" #include "hw/sysbus.h" +#include "hw/sysbus-fdt.h" #include "chardev/char-fe.h" #include "chardev/char-serial.h" #include "qemu/timer.h"
@@ -560,6 +561,17 @@ static const TypeInfo cadence_uart_info = {static void cadence_uart_register_types (void ) { +static const char *cadence_uart_fdt_aliases[] = { +"cdns.uart" , +"cdns,uart-r1p8" , +"xlnx,xuartps" ,/* Zynq-7xxx SoC */ +"xlnx.ps7-uart" , +"cdns,uart-r1p12" , +"xlnx,zynqmp-uart" ,/* Zynq Ultrascale+ MPSoC */ +NULL + }; + +type_register_fdt_aliases (TYPE_CADENCE_UART , cadence_uart_fdt_aliases);type_register_static (&cadence_uart_info); }
Signature · 1 line
2.15.1
RFC PATCH v2 3/9 hw/net/cadence_gem: add FDT aliases
In reply to Philippe Mathieu-Daudé--- hw/net/cadence_gem.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/net/cadence_gem.c +10 -0
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include <zlib.h> /* For crc32 */ +#include "hw/sysbus-fdt.h" #include "hw/net/cadence_gem.h" #include "qapi/error.h" #include "qemu/log.h"
@@ -1552,6 +1553,15 @@ static const TypeInfo gem_info = {static void gem_register_types (void ) { +static const char *gem_fdt_aliases[] = { +"cdns,gem" , +"cdns,zynq-gem" ,/* Zynq-7xxx SoC */ +"xlnx.ps7-ethernet" , +"cdns,zynqmp-gem" ,/* Zynq Ultrascale+ MPSoC */ +NULL + }; + +type_register_fdt_aliases (TYPE_CADENCE_GEM , gem_fdt_aliases);type_register_static (&gem_info); }
Signature · 1 line
2.15.1
RFC PATCH v2 4/9 hw/timer/cadence_ttc: add FDT aliases
In reply to Philippe Mathieu-Daudé--- hw/timer/cadence_ttc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/timer/cadence_ttc.c +8 -0
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include "hw/sysbus.h" +#include "hw/sysbus-fdt.h" #include "qemu/timer.h" #ifdef CADENCE_TTC_ERR_DEBUG
@@ -488,6 +489,13 @@ static const TypeInfo cadence_ttc_info = {static void cadence_ttc_register_types (void ) { +static const char *cadence_ttc_fdt_aliases[] = { +"cdns.ttc" ,/* Zynq */ +"xlnx.ps7-ttc" ,/* Zynq-7xxx SoC */ +NULL + }; + +type_register_fdt_aliases (TYPE_CADENCE_TTC , cadence_ttc_fdt_aliases);type_register_static (&cadence_ttc_info); }
Signature · 1 line
2.15.1
RFC PATCH v2 5/9 hw/dma/axidma: add 'xlnx, eth-dma' FDT alias
In reply to Philippe Mathieu-Daudé--- hw/dma/xilinx_axidma.c | 2 ++ 1 file changed, 2 insertions(+)
hw/dma/xilinx_axidma.c +2 -0
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "hw/sysbus.h" +#include "hw/sysbus-fdt.h" #include "qapi/error.h" #include "qemu/timer.h" #include "hw/ptimer.h"
@@ -648,6 +649,7 @@ static const TypeInfo xilinx_axidma_control_stream_info = {static void xilinx_axidma_register_types (void ) { +type_register_fdt_alias (TYPE_XILINX_AXI_DMA ,"xlnx,eth-dma" );type_register_static (&axidma_info);type_register_static (&xilinx_axidma_data_stream_info);type_register_static (&xilinx_axidma_control_stream_info);
Signature · 1 line
2.15.1
RFC PATCH v2 6/9 hw/usb/hcd-ehci: add 'xlnx, ps7-usb' FDT aliases
In reply to Philippe Mathieu-Daudé--- hw/usb/hcd-ehci-sysbus.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/usb/hcd-ehci-sysbus.c +8 -0
@@ -16,6 +16,7 @@*/ #include "qemu/osdep.h" +#include "hw/sysbus-fdt.h" #include "hw/usb/hcd-ehci.h" static const VMStateDescription vmstate_ehci_sysbus = {
@@ -244,6 +245,13 @@ static const TypeInfo ehci_fusbh200_type_info = {static void ehci_sysbus_register_types (void ) { +static const char *xlnx_ehci_fdt_aliases[] = { +"xlnx.zynq-usb" ,/* Zynq */ +"xlnx.ps7-usb" ,/* Zynq-7xxx SoC */ +NULL + }; + +type_register_fdt_aliases ("xlnx,ps7-usb" , xlnx_ehci_fdt_aliases);type_register_static (&ehci_type_info);type_register_static (&ehci_xlnx_type_info);type_register_static (&ehci_exynos4210_type_info);
Signature · 1 line
2.15.1
RFC PATCH v2 7/9 hw/ssi/xlnx-spips: add 'xlnx.zynq-qspi' FDT alias
In reply to Philippe Mathieu-Daudé--- hw/ssi/xilinx_spips.c | 2 ++ 1 file changed, 2 insertions(+)
hw/ssi/xilinx_spips.c +2 -0
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "hw/sysbus.h" +#include "hw/sysbus-fdt.h" #include "sysemu/sysemu.h" #include "hw/ptimer.h" #include "qemu/log.h"
@@ -1443,6 +1444,7 @@ static const TypeInfo xlnx_zynqmp_qspips_info = {static void xilinx_spips_register_types (void ) { +type_register_fdt_alias (TYPE_XILINX_QSPIPS ,"xlnx.zynq-qspi" );type_register_static (&xilinx_spips_info);type_register_static (&xilinx_qspips_info);type_register_static (&xlnx_zynqmp_qspips_info);
Signature · 1 line
2.15.1
RFC PATCH v2 8/9 hw/dma/xlnx_dpdma: add 'xlnx, axi-dpdma-1.0' FDT alias
In reply to Philippe Mathieu-Daudé--- hw/dma/xlnx_dpdma.c | 2 ++ 1 file changed, 2 insertions(+)
hw/dma/xlnx_dpdma.c +2 -0
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qemu/log.h" +#include "hw/sysbus-fdt.h" #include "hw/dma/xlnx_dpdma.h" #ifndef DEBUG_DPDMA
@@ -607,6 +608,7 @@ static const TypeInfo xlnx_dpdma_info = {static void xlnx_dpdma_register_types (void ) { +type_register_fdt_alias (TYPE_XLNX_DPDMA ,"xlnx,axi-dpdma-1.0" );/* ZynqMP */ type_register_static (&xlnx_dpdma_info); }
Signature · 1 line
2.15.1
RFC PATCH v2 9/9 hw/arm/xlnx-zynqmp: use Linux FDT names
In reply to Philippe Mathieu-Daudé--- hw/arm/xlnx-zynqmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/arm/xlnx-zynqmp.c +10 -4
@@ -24,6 +24,7 @@#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "kvm_arm.h" +#include "hw/sysbus-fdt.h" #define GIC_NUM_SPI_INTR 160
@@ -138,6 +139,7 @@ static void xlnx_zynqmp_init(Object *obj)XlnxZynqMPState *s =XLNX_ZYNQMP (obj);int i;int num_apus =MIN (smp_cpus,XLNX_ZYNQMP_NUM_APU_CPUS ); +const char *type_name;for (i =0 ; i < num_apus; i++) { object_initialize(&s->apu_cpu[i], sizeof(s->apu_cpu[i]),
@@ -150,12 +152,14 @@ static void xlnx_zynqmp_init(Object *obj)qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ());for (i =0 ; i <XLNX_ZYNQMP_NUM_GEMS ; i++) { -object_initialize (&s->gem[i],sizeof (s->gem[i]),TYPE_CADENCE_GEM ); + type_name =type_resolve_fdt_alias ("cdns,zynqmp-gem" ); +object_initialize (&s->gem[i],sizeof (s->gem[i]), type_name);qdev_set_parent_bus (DEVICE (&s->gem[i]),sysbus_get_default ()); }for (i =0 ; i <XLNX_ZYNQMP_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_CADENCE_UART ); + type_name =type_resolve_fdt_alias ("xlnx,zynqmp-uart" ); +object_initialize (&s->uart[i],sizeof (s->uart[i]), type_name);qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ()); }
@@ -175,13 +179,15 @@ static void xlnx_zynqmp_init(Object *obj)qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); } -object_initialize (&s->qspi,sizeof (s->qspi),TYPE_XLNX_ZYNQMP_QSPIPS ); + type_name =type_resolve_fdt_alias ("xlnx.zynq-qspi" ); +object_initialize (&s->qspi,sizeof (s->qspi), type_name);qdev_set_parent_bus (DEVICE (&s->qspi),sysbus_get_default ());object_initialize (&s->dp,sizeof (s->dp),TYPE_XLNX_DP );qdev_set_parent_bus (DEVICE (&s->dp),sysbus_get_default ()); -object_initialize (&s->dpdma,sizeof (s->dpdma),TYPE_XLNX_DPDMA ); + type_name =type_resolve_fdt_alias ("xlnx,axi-dpdma-1.0" ); +object_initialize (&s->dpdma,sizeof (s->dpdma), type_name);qdev_set_parent_bus (DEVICE (&s->dpdma),sysbus_get_default ()); }
Signature · 1 line
2.15.1
Re: [Qemu-arm] [RFC PATCH v2 9/9] hw/arm/xlnx-zynqmp: use Linux FDT names
Quoted 26 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/xlnx-zynqmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/arm/xlnx-zynqmp.c +2
-0@@ -24,6 +24,7 @@#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "kvm_arm.h" +#include "hw/sysbus-fdt.h" #define GIC_NUM_SPI_INTR 160@@ -138,6 +139,7 @@ static void xlnx_zynqmp_init(Object *obj)XlnxZynqMPState *s =XLNX_ZYNQMP (obj);int i;int num_apus =MIN (smp_cpus,XLNX_ZYNQMP_NUM_APU_CPUS ); +const char *type_name;for (i =0 ; i < num_apus; i++) { object_initialize(&s->apu_cpu[i], sizeof(s->apu_cpu[i]),
hw/arm/xlnx-zynqmp.c static void xlnx_zynqmp_init(Object *obj) · line 158
Quoted 8 lines
hw/arm/xlnx-zynqmp.c +2
-1@@ -150,12 +152,14 @@ static void xlnx_zynqmp_init(Object *obj)qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ());for (i =0 ; i <XLNX_ZYNQMP_NUM_GEMS ; i++) { -object_initialize (&s->gem[i],sizeof (s->gem[i]),TYPE_CADENCE_GEM ); + type_name =type_resolve_fdt_alias ("cdns,zynqmp-gem" ); +object_initialize (&s->gem[i],sizeof (s->gem[i]), type_name);qdev_set_parent_bus (DEVICE (&s->gem[i]),sysbus_get_default ()); }
I'm having difficulty seeing the benefits of this series. We spend patches 1-8 adding code to devices to add alias names to them, and this means that in patch 9 we can replace a single object_initialize() with ... two lines of code including a runtime lookup of an alias name. Can you explain why this is better than what we have currently?
thanks
-- PMM