MAINTAINERS: Update maintainer's email for Xilinx CAN
PATCH 1/5 MAINTAINERS: Update maintainer's email for Xilinx CAN
--- MAINTAINERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
MAINTAINERS +2 -2
@@ -1751,8 +1751,8 @@ F: tests/qtest/intel-hda-test.c F: tests/qtest/fuzz-sb16-test.c Xilinx CAN -M: Vikram Garhwal <[email protected]> -M: Francisco Iglesias <[email protected]> +M: Vikram Garhwal <[email protected]> +M: Francisco Iglesias <[email protected]> S: Maintained F: hw/net/can/xlnx-* F: include/hw/net/xlnx-*
Signature · 1 line
2.17.1
PATCH 2/5 hw/net/can: Introduce Xilinx Versal CANFD controller
The Xilinx Versal CANFD controller is developed based on SocketCAN, QEMU CAN bus implementation. Bus connection and socketCAN connection for each CAN module can be set through command lines.
Example for using connecting CANFD0 and CANFD1 to same bus:
-machine xlnx-versal-virt
-object can-bus,id=canbus
-machine canbus0=canbus
-machine canbus1=canbus
To create virtual CAN on the host machine, please check the QEMU CAN docs:
https://github.com/qemu/qemu/blob/master/docs/can.txt
--- hw/net/can/meson.build | 1 + hw/net/can/trace-events | 7 + hw/net/can/xlnx-versal-canfd.c | 2157 ++++++++++++++++++++++++++++ include/hw/net/xlnx-versal-canfd.h | 92 ++ 4 files changed, 2257 insertions(+) create mode 100644 hw/net/can/xlnx-versal-canfd.c create mode 100644 include/hw/net/xlnx-versal-canfd.h
hw/net/can/meson.build +1 -0
@@ -5,3 +5,4 @@ softmmu_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_mioe3680_pci.c')) softmmu_ss.add(when: 'CONFIG_CAN_CTUCANFD', if_true: files('ctucan_core.c')) softmmu_ss.add(when: 'CONFIG_CAN_CTUCANFD_PCI', if_true: files('ctucan_pci.c')) softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-can.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-canfd.c'))
hw/net/can/trace-events +7 -0
@@ -7,3 +7,10 @@ xlnx_can_filter_mask_pre_write(uint8_t filter_num, uint32_t value) "Filter%d MAS xlnx_can_tx_data(uint32_t id, uint8_t dlc, uint8_t db0, uint8_t db1, uint8_t db2, uint8_t db3, uint8_t db4, uint8_t db5, uint8_t db6, uint8_t db7) "Frame: ID: 0x%08x DLC: 0x%02x DATA: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x" xlnx_can_rx_data(uint32_t id, uint32_t dlc, uint8_t db0, uint8_t db1, uint8_t db2, uint8_t db3, uint8_t db4, uint8_t db5, uint8_t db6, uint8_t db7) "Frame: ID: 0x%08x DLC: 0x%02x DATA: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x" xlnx_can_rx_discard(uint32_t status) "Controller is not enabled for bus communication. Status Register: 0x%08x" + +# xlnx-versal-canfd.c +xlnx_canfd_update_irq(char *path, uint32_t isr, uint32_t ier, uint32_t irq) "%s: ISR: 0x%08x IER: 0x%08x IRQ: 0x%08x" +xlnx_canfd_rx_fifo_filter_reject(char *path, uint32_t id, uint8_t dlc) "%s: Frame: ID: 0x%08x DLC: 0x%02x" +xlnx_canfd_rx_data(char *path, uint32_t id, uint8_t dlc, uint8_t flags) "%s: Frame: ID: 0x%08x DLC: 0x%02x CANFD Flag: 0x%02x" +xlnx_canfd_tx_data(char *path, uint32_t id, uint8_t dlc, uint8_t flgas) "%s: Frame: ID: 0x%08x DLC: 0x%02x CANFD Flag: 0x%02x" +xlnx_canfd_reset(char *path, uint32_t val) "%s: Resetting controller with value = 0x%08x"
hw/net/can/xlnx-versal-canfd.c new file +2157 -0
2,157 lines not on this page · raw message
include/hw/net/xlnx-versal-canfd.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [QEMU][PATCH 2/5] hw/net/can: Introduce Xilinx Versal CANFD controller
Quoted 5 lines · Vikram Garhwal
The Xilinx Versal CANFD controller is developed based on SocketCAN, QEMU CAN bus implementation. Bus connection and socketCAN connection for each CAN module can be set through command lines.
Quoted 8 lines
Example for using connecting CANFD0 and CANFD1 to same bus:
-machine xlnx-versal-virt
-object can-bus,id=canbus
-machine canbus0=canbus
-machine canbus1=canbusTo create virtual CAN on the host machine, please check the QEMU CAN docs:
https://github.com/qemu/qemu/blob/master/docs/can.txt
That link is a 404. You could just give the relative path to the docs in the repo, which is docs/system/devices/can.rst
For the machine specifics, you should include (either in the patch 4 where you add this to the xlnx-versal-virt board, or in a separate patch if it seems too big) updates to docs/system/arm/xlnx-versal-virt.rst which document the new functionality, including, if it's useful to users, some documentation of how to use it.
hw/net/can/xlnx-versal-canfd.c line 49
Quoted 2 lines
hw/net/can/xlnx-versal-canfd.c new file +2
-0+/* To avoid the build issues on Windows machines. */ +#undef ERROR
What ?
Quoted 16 lines
hw/net/can/xlnx-versal-canfd.c new file +16
-0+static void canfd_config_mode (XlnxVersalCANFDState *s) +{ +register_reset (&s->reg_info[R_ERROR_COUNTER_REGISTER ]); +register_reset (&s->reg_info[R_ERROR_STATUS_REGISTER ]); +register_reset (&s->reg_info[R_STATUS_REGISTER ]); + +/* Put XlnxVersalCANFDState in configuration mode. */ +ARRAY_FIELD_DP32 (s->regs,STATUS_REGISTER ,CONFIG ,1 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,WKUP ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,SLP ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,BSOFF ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,ERROR ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,RXFOFLW ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,RXFOFLW_1 ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,RXOK ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,TXOK ,0 );
hw/net/can/xlnx-versal-canfd.c line 776
Quoted 10 lines
hw/net/can/xlnx-versal-canfd.c new file +10
-0+ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,ARBLST ,0 ); + +/* Clear the time stamp. */ +ptimer_transaction_begin (s->canfd_timer); +ptimer_set_count (s->canfd_timer,0 ); +ptimer_transaction_commit (s->canfd_timer); + +canfd_update_irq (s); +} +
A lot of this looks like it's just copy-and-pasted code from the existing hw/net/can/xlnx-zynqmp-can.c. Is this just an updated/extra-features version of that device? Is there some way we can share the code rather than duplicating 2000-odd lines ?
include/hw/net/xlnx-versal-canfd.h line 36
Quoted 9 lines
include/hw/net/xlnx-versal-canfd.h new file +9
-0+#ifndef HW_CANFD_XILINX_H +#define HW_CANFD_XILINX_H + +#include "hw/register.h" +#include "hw/ptimer.h" +#include "net/can_emu.h" +#include "hw/qdev-clock.h" + +#define TYPE_XILINX_CANFD "xlnx.versal-canfd"
Should this be a dot or a comma? The codebase has examples of both for xlnx devices :-(
include/hw/net/xlnx-versal-canfd.h line 39
Quoted 3 lines
include/hw/net/xlnx-versal-canfd.h new file +3
-0+ +#define XILINX_CANFD (obj) \ + OBJECT_CHECK(XlnxVersalCANFDState, (obj), TYPE_XILINX_CANFD)
Please use OBJECT_DECLARE_SIMPLE_TYPE() rather than defining the cast macro by hand.
include/hw/net/xlnx-versal-canfd.h line 43
Quoted 4 lines
include/hw/net/xlnx-versal-canfd.h new file +4
-0+ +#define NUM_REGS_PER_MSG_SPACE 18 +#define MAX_NUM_RX 64 +#define CANFD_TIMER_MAX 0XFFFFUL
Don't use capital X in the 0x hex prefix, please.
include/hw/net/xlnx-versal-canfd.h line 46
Quoted 3 lines
include/hw/net/xlnx-versal-canfd.h new file +3
-0+#define CANFD_DEFAULT_CLOCK (24 * 1000 * 1000) + +/* 0x4144/4 + 1 + (64 - 1) * 18 + 1. */
This comment isn't very informative. The #define itself is much better because it uses symbolic constants.
What is the magic number 0x4144. It should either be defined via some kind of symbolic constant, or if that's not possible at least explained in a comment.
include/hw/net/xlnx-versal-canfd.h line 48
Quoted 2 lines
include/hw/net/xlnx-versal-canfd.h new file +2
-0+#define XLNX_VERSAL_CANFD_R_MAX (0x4144 / 4 + \ + ((MAX_NUM_RX - 1) * NUM_REGS_PER_MSG_SPACE) + 1)
thanks
-- PMM
Re: [QEMU][PATCH 2/5] hw/net/can: Introduce Xilinx Versal CANFD controller
Hello Peter,
thanks for the review and Vikram for his work, I do not know much about Xilinx emulation nor Xilixn CAN controllers so I cannot comment much on this part.
Quoted 5 lines · On Thursday 22 of September 2022 16:46:48 Peter Maydell wrote:
On Sat, 10 Sept 2022 at 07:13, Vikram Garhwal <[email protected]> > > To create virtual CAN on the host machine, please check the QEMU CAN
Quoted 1 line
That link is a 404. You could just give the relative path to the docs in the repo, which is
docs/system/devices/can.rst
The actual generated documentation is located at
https://www.qemu.org/docs/master/system/devices/can.html
I think that that URL is stable for some time... Could it be used directly in source to provide path to formated version?
Quoted 5 lines
For the machine specifics, you should include (either in the patch 4 where you add this to the xlnx-versal-virt board, or in a separate patch if it seems too big) updates to
docs/system/arm/xlnx-versal-virt.rstwhich document the new functionality, including, if it's useful to users, some documentation of how to use it.
Some short example how to use emulation even with Xilinx Zynq and Ultra Scale would be nice if added into the document. If the document length expands too much, then probably division into individual documents per controllers would be nice.
By the way, CAN in Automation publishes our overview article about our CAN activities including some short netion of QEMU integration
https://can-newsletter.org/uploads/media/raw/a9abe317ae034be55d99fee4410ad70e.pdf
I hope I wind some time for CAN in QEMU, RTEMS and Linux ongoing projects, but I need to finish some promissed project for ESA the first.
Best wishes,
Pavel
Signature · 12 lines
Pavel Pisa
phone: +420 603531357
e-mail: [email protected]
Department of Control Engineering FEE CVUT
Karlovo namesti 13, 121 35, Prague 2
university: http://control.fel.cvut.cz/
personal: http://cmp.felk.cvut.cz/~pisa
projects: https://www.openhub.net/accounts/ppisa
CAN related:http://canbus.pages.fel.cvut.cz/
RISC-V education: https://comparch.edu.cvut.cz/
Open Technologies Research Education and Exchange Services
https://gitlab.fel.cvut.cz/otrees/org/-/wikis/homeRe: [QEMU][PATCH 2/5] hw/net/can: Introduce Xilinx Versal CANFD controller
In reply to Peter MaydellHi Peter,
Quoted 13 lines · Peter Maydell
Quoted 4 lines · Vikram Garhwal
The Xilinx Versal CANFD controller is developed based on SocketCAN, QEMU CAN bus implementation. Bus connection and socketCAN connection for each CAN module can be set through command lines.
Quoted 8 lines
Example for using connecting CANFD0 and CANFD1 to same bus:
-machine xlnx-versal-virt
-object can-bus,id=canbus
-machine canbus0=canbus
-machine canbus1=canbusTo create virtual CAN on the host machine, please check the QEMU CAN docs:
https://github.com/qemu/qemu/blob/master/docs/can.txt
Quoted 8 lines
That link is a 404. You could just give the relative path to the docs in the repo, which is
docs/system/devices/can.rstFor the machine specifics, you should include (either in the patch 4 where you add this to the xlnx-versal-virt board, or in a separate patch if it seems too big) updates to
docs/system/arm/xlnx-versal-virt.rstwhich document the new functionality, including, if it's useful to users, some documentation of how to use it.
Sorry for delay in reply. I was waiting for other to review before sending v2. But it's been a few weeks so I will send v2 today EoD or tomorrow.
I will move the documentation part in xlnx-versal-virt.rst file.
Quoted 5 lines
hw/net/can/xlnx-versal-canfd.c line 49
Quoted 4 lines
hw/net/can/xlnx-versal-canfd.c new file +2
-0+/* To avoid the build issues on Windows machines. */ +#undef ERRORWhat ?
The ERROR field of the INTERRUPT_STATUS_REGISTER colides with a macro in the Windows build enviorment. Build fails due to incorrect size of ERROR on Windows systems.
Quoted 23 lines
Quoted 23 lines
hw/net/can/xlnx-versal-canfd.c new file +22
-0+static void canfd_config_mode (XlnxVersalCANFDState *s) +{ +register_reset (&s->reg_info[R_ERROR_COUNTER_REGISTER ]); +register_reset (&s->reg_info[R_ERROR_STATUS_REGISTER ]); +register_reset (&s->reg_info[R_STATUS_REGISTER ]); + +/* Put XlnxVersalCANFDState in configuration mode. */ +ARRAY_FIELD_DP32 (s->regs,STATUS_REGISTER ,CONFIG ,1 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,WKUP ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,SLP ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,BSOFF ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,ERROR ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,RXFOFLW ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,RXFOFLW_1 ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,RXOK ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,TXOK ,0 ); +ARRAY_FIELD_DP32 (s->regs,INTERRUPT_STATUS_REGISTER ,ARBLST ,0 ); + +/* Clear the time stamp. */ +ptimer_transaction_begin (s->canfd_timer); +ptimer_set_count (s->canfd_timer,0 ); +ptimer_transaction_commit (s->canfd_timer);
Quoted 8 lines
hw/net/can/xlnx-versal-canfd.c line 717
Quoted 4 lines
hw/net/can/xlnx-versal-canfd.c new file +4
-0+ +canfd_update_irq (s); +} +A lot of this looks like it's just copy-and-pasted code from the existing
hw/net/can/xlnx-zynqmp-can.c. Is this just an updated/extra-features version of that device? Is there some way we can share the code rather than duplicating 2000-odd lines ?
No, both are very different controllers. Versal SoCs CANFD has lot more registers, RX/TX FIFOs compare to ZynqMP CAN device. Interrupt handling, overflow conditions are also different. I will recheck if can find some common function and can use for both with making the code more complex.
Quoted 12 lines
include/hw/net/xlnx-versal-canfd.h line 36
Quoted 10 lines
include/hw/net/xlnx-versal-canfd.h new file +9
-0+#ifndef HW_CANFD_XILINX_H +#define HW_CANFD_XILINX_H + +#include "hw/register.h" +#include "hw/ptimer.h" +#include "net/can_emu.h" +#include "hw/qdev-clock.h" + +#define TYPE_XILINX_CANFD "xlnx.versal-canfd"Should this be a dot or a comma? The codebase has examples of both for xlnx devices :-(
You are right about dot or comma comment. We need to harmonize these across all Xilinx devices. For Versal board, recently introduced machine has all dots, so I am following that. Let me check with team here and perhaps we can send another series to address the dot/comma variations.
Quoted 19 lines
include/hw/net/xlnx-versal-canfd.h line 39
Quoted 4 lines
include/hw/net/xlnx-versal-canfd.h new file +3
-0+ +#define XILINX_CANFD (obj) \ + OBJECT_CHECK(XlnxVersalCANFDState, (obj), TYPE_XILINX_CANFD)Please use
OBJECT_DECLARE_SIMPLE_TYPE()rather than defining the cast macro by hand.include/hw/net/xlnx-versal-canfd.h line 43
Quoted 4 lines
include/hw/net/xlnx-versal-canfd.h new file +4
-0+ +#define NUM_REGS_PER_MSG_SPACE 18 +#define MAX_NUM_RX 64 +#define CANFD_TIMER_MAX 0XFFFFULDon't use capital X in the 0x hex prefix, please.
include/hw/net/xlnx-versal-canfd.h line 46
Quoted 3 lines
include/hw/net/xlnx-versal-canfd.h new file +3
-0+#define CANFD_DEFAULT_CLOCK (24 * 1000 * 1000) + +/* 0x4144/4 + 1 + (64 - 1) * 18 + 1. */ This comment isn't very informative. The #define itself is much better because it uses symbolic constants.
Quoted 3 lines
What is the magic number
0x4144. It should either be defined via some kind of symbolic constant, or if that's not possible at least explained in a comment.
Rest of the comments will be resolved in v2.
Quoted 4 lines
include/hw/net/xlnx-versal-canfd.h line 48
Quoted 2 lines
include/hw/net/xlnx-versal-canfd.h new file +2
-0+#define XLNX_VERSAL_CANFD_R_MAX (0x4144 / 4 + \ + ((MAX_NUM_RX - 1) * NUM_REGS_PER_MSG_SPACE) + 1)thanks
-- PMM
PATCH 3/5 xlnx-zynqmp: Connect Xilinx VERSAL CANFD controllers
In reply to Vikram GarhwalConnect CANFD0 and CANFD1 on the Versal-virt machine.
--- hw/arm/xlnx-versal-virt.c | 45 ++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 37 +++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 12 ++++++++++ 3 files changed, 94 insertions(+)
hw/arm/xlnx-versal-virt.c +45 -0
@@ -40,9 +40,11 @@ struct VersalVirt {uint32_t clk_25Mhz;uint32_t usb;uint32_t dwc; +uint32_t canfd[2 ]; } phandle;struct arm_boot_info binfo; +CanBusState *canbus[XLNX_VERSAL_NR_CANFD ];struct {bool secure; } cfg;
@@ -235,6 +237,34 @@ static void fdt_add_uart_nodes(VersalVirt *s) } } +static void fdt_add_canfd_nodes (VersalVirt *s) +{ +uint64_t addrs[] = {MM_CANFD0 ,MM_CANFD1 }; +uint32_t size[] = {MM_CANFD0_SIZE ,MM_CANFD1_SIZE }; +unsigned int irqs[] = {VERSAL_CANFD0_IRQ_0 ,VERSAL_CANFD1_IRQ_0 }; +const char compat[] ="xlnx,versal-canfd" ; +int i; + +/* Create and connect CANFD0 and CANFD1 nodes to canbus0. */ +for (i =0 ; i <ARRAY_SIZE (addrs); i++) { +char *name =g_strdup_printf ("/canfd@%" PRIx64, addrs[i]); +qemu_fdt_add_subnode (s->fdt, name); +qemu_fdt_setprop_cell (s->fdt, name,"rx-fifo0" ,0x40 ); +qemu_fdt_setprop_cell (s->fdt, name,"enable-rx-fifo1" ,0x1 ); +qemu_fdt_setprop_cell (s->fdt, name,"rx-fifo1" ,0x40 ); + +qemu_fdt_setprop_cells (s->fdt, name,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irqs[i], +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); +qemu_fdt_setprop_sized_cells (s->fdt, name,"reg" , +2 , addrs[i],2 , size[i]); +qemu_fdt_setprop (s->fdt, name,"compatible" , + compat,sizeof (compat)); + +g_free (name); + } +} +static void fdt_add_fixed_link_nodes (VersalVirt *s,char *gemname,uint32_t phandle) {
@@ -639,12 +669,17 @@ static void versal_virt_init(MachineState *machine) TYPE_XLNX_VERSAL);object_property_set_link (OBJECT (&s->soc),"ddr" ,OBJECT (machine->ram), &error_abort); +object_property_set_link (OBJECT (&s->soc),"canbus0" ,OBJECT (s->canbus[0 ]), + &error_abort); +object_property_set_link (OBJECT (&s->soc),"canbus1" ,OBJECT (s->canbus[1 ]), + &error_abort);sysbus_realize (SYS_BUS_DEVICE (&s->soc), &error_fatal);fdt_create (s);create_virtio_regions (s);fdt_add_gem_nodes (s);fdt_add_uart_nodes (s); +fdt_add_canfd_nodes (s);fdt_add_gic_nodes (s);fdt_add_timer_nodes (s);fdt_add_zdma_nodes (s);
@@ -712,6 +747,16 @@ static void versal_virt_init(MachineState *machine)static void versal_virt_machine_instance_init (Object *obj) { +VersalVirt *s =XLNX_VERSAL_VIRT_MACHINE (obj); + +object_property_add_link (obj,"canbus0" ,TYPE_CAN_BUS , + (Object **)&s->canbus[0 ], + object_property_allow_set_link, +0 ); +object_property_add_link (obj,"canbus1" ,TYPE_CAN_BUS , + (Object **)&s->canbus[1 ], + object_property_allow_set_link, +0 ); }static void versal_virt_machine_class_init (ObjectClass *oc,void *data)
hw/arm/xlnx-versal.c +37 -0
@@ -185,6 +185,38 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic) } } +static void versal_create_canfds (Versal *s,qemu_irq *pic) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (s->lpd.iou.canfd); i++) { +static const int irqs[] = {VERSAL_CANFD0_IRQ_0 ,VERSAL_CANFD1_IRQ_0 }; +static const uint64_t addrs[] = {MM_CANFD0 ,MM_CANFD1 }; +char *name =g_strdup_printf ("canfd%d" , i); +DeviceState *dev; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->lpd.iou.canfd[i], +TYPE_XILINX_CANFD ); + dev =DEVICE (&s->lpd.iou.canfd[i]); + +object_property_set_int (OBJECT (&s->lpd.iou.canfd[i]),"ext_clk_freq" , +XLNX_VERSAL_CANFD_REF_CLK , &error_abort); + +object_property_set_link (OBJECT (dev),"canfdbus" , +OBJECT (s->lpd.iou.canbus[i]), + &error_abort); + +sysbus_realize (SYS_BUS_DEVICE (dev), &error_fatal); + + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ); +memory_region_add_subregion (&s->mr_ps, addrs[i], mr); + +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , pic[irqs[i]]); +g_free (name); + } +} +static void versal_create_usbs (Versal *s,qemu_irq *pic) {DeviceState *dev;
@@ -719,6 +751,7 @@ static void versal_realize(DeviceState *dev, Error **errp)versal_create_apu_gic (s, pic);versal_create_rpu_cpus (s);versal_create_uarts (s, pic); +versal_create_canfds (s, pic);versal_create_usbs (s, pic);versal_create_gems (s, pic);versal_create_admas (s, pic);
@@ -758,6 +791,10 @@ static void versal_init(Object *obj)static Property versal_properties[] = {DEFINE_PROP_LINK ("ddr" , Versal, cfg.mr_ddr,TYPE_MEMORY_REGION , MemoryRegion *), +DEFINE_PROP_LINK ("canbus0" , Versal, lpd.iou.canbus[0 ], + TYPE_CAN_BUS, CanBusState *), +DEFINE_PROP_LINK ("canbus1" , Versal, lpd.iou.canbus[1 ], + TYPE_CAN_BUS, CanBusState *),DEFINE_PROP_END_OF_LIST () };
include/hw/arm/xlnx-versal.h +12 -0
@@ -31,6 +31,7 @@#include "hw/dma/xlnx_csu_dma.h" #include "hw/misc/xlnx-versal-crl.h" #include "hw/misc/xlnx-versal-pmc-iou-slcr.h" +#include "hw/net/xlnx-versal-canfd.h" #define TYPE_XLNX_VERSAL "xlnx-versal"OBJECT_DECLARE_SIMPLE_TYPE (Versal,XLNX_VERSAL )
@@ -43,6 +44,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(Versal, XLNX_VERSAL)#define XLNX_VERSAL_NR_SDS 2#define XLNX_VERSAL_NR_XRAM 4#define XLNX_VERSAL_NR_IRQS 192 +#define XLNX_VERSAL_NR_CANFD 2 +#define XLNX_VERSAL_CANFD_REF_CLK (24 * 1000 * 1000)struct Versal {/*< private >*/
@@ -73,6 +76,8 @@ struct Versal {CadenceGEMState gem[XLNX_VERSAL_NR_GEMS ];XlnxZDMA adma[XLNX_VERSAL_NR_ADMAS ];VersalUsb2 usb; +CanBusState *canbus[XLNX_VERSAL_NR_CANFD ]; +XlnxVersalCANFDState canfd[XLNX_VERSAL_NR_CANFD ]; } iou;/* Real-time Processing Unit. */
@@ -133,6 +138,8 @@ struct Versal {#define VERSAL_CRL_IRQ 10#define VERSAL_UART0_IRQ_0 18#define VERSAL_UART1_IRQ_0 19 +#define VERSAL_CANFD0_IRQ_0 20 +#define VERSAL_CANFD1_IRQ_0 21#define VERSAL_USB0_IRQ_0 22#define VERSAL_GEM0_IRQ_0 56#define VERSAL_GEM0_WAKE_IRQ_0 57
@@ -163,6 +170,11 @@ struct Versal {#define MM_UART1 0xff010000U#define MM_UART1_SIZE 0x10000 +#define MM_CANFD0 0xff060000 +#define MM_CANFD0_SIZE 0x10000 +#define MM_CANFD1 0xff070000 +#define MM_CANFD1_SIZE 0x10000 +#define MM_GEM0 0xff0c0000U#define MM_GEM0_SIZE 0x10000#define MM_GEM1 0xff0d0000U
Signature · 1 line
2.17.1
Re: [QEMU][PATCH 3/5] xlnx-zynqmp: Connect Xilinx VERSAL CANFD controllers
Quoted 27 lines · Vikram Garhwal
Connect CANFD0 and CANFD1 on the Versal-virt machine.
Signed-off-by Vikram Garhwal <[email protected]>--- hw/arm/xlnx-versal-virt.c | 45 ++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 37 +++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 12 ++++++++++ 3 files changed, 94 insertions(+)hw/arm/xlnx-versal-virt.c +2
-0@@ -40,9 +40,11 @@ struct VersalVirt {uint32_t clk_25Mhz;uint32_t usb;uint32_t dwc; +uint32_t canfd[2 ]; } phandle;struct arm_boot_info binfo; +CanBusState *canbus[XLNX_VERSAL_NR_CANFD ];struct {bool secure; } cfg;
hw/arm/xlnx-versal-virt.c static void fdt_add_uart_nodes(VersalVirt *s) · line 243
Quoted 7 lines
hw/arm/xlnx-versal-virt.c +4
-0@@ -235,6 +237,34 @@ static void fdt_add_uart_nodes(VersalVirt *s) } } +static void fdt_add_canfd_nodes (VersalVirt *s) +{ +uint64_t addrs[] = {MM_CANFD0 ,MM_CANFD1 }; +uint32_t size[] = {MM_CANFD0_SIZE ,MM_CANFD1_SIZE };
Can you be consistent about how you format the spacing on this kind of thing, please?
Quoted 9 lines
hw/arm/xlnx-versal-virt.c +9
-0+unsigned int irqs[] = {VERSAL_CANFD0_IRQ_0 ,VERSAL_CANFD1_IRQ_0 }; +const char compat[] ="xlnx,versal-canfd" ; +int i; + +/* Create and connect CANFD0 and CANFD1 nodes to canbus0. */ +for (i =0 ; i <ARRAY_SIZE (addrs); i++) { +char *name =g_strdup_printf ("/canfd@%" PRIx64, addrs[i]); +qemu_fdt_add_subnode (s->fdt, name); +qemu_fdt_setprop_cell (s->fdt, name,"rx-fifo0" ,0x40 );
hw/arm/xlnx-versal-virt.c static void fdt_add_uart_nodes(VersalVirt *s) · line 262
Quoted 10 lines
hw/arm/xlnx-versal-virt.c +10
-0+qemu_fdt_setprop_cell (s->fdt, name,"enable-rx-fifo1" ,0x1 ); +qemu_fdt_setprop_cell (s->fdt, name,"rx-fifo1" ,0x40 ); + +qemu_fdt_setprop_cells (s->fdt, name,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irqs[i], +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); +qemu_fdt_setprop_sized_cells (s->fdt, name,"reg" , +2 , addrs[i],2 , size[i]); +qemu_fdt_setprop (s->fdt, name,"compatible" , + compat,sizeof (compat));
Where there is no embedded NUL byte in the compat string, you can use qemu_fdt_setprop_string():
qemu_fdt_setprop_string(s->fdt, name, "compatible", "xlnx,versal-canfd");
Quoted 30 lines
hw/arm/xlnx-versal-virt.c +10
-0+ +g_free (name); + } +} +static void fdt_add_fixed_link_nodes (VersalVirt *s,char *gemname,uint32_t phandle) {@@ -639,12 +669,17 @@ static void versal_virt_init(MachineState *machine) TYPE_XLNX_VERSAL);object_property_set_link (OBJECT (&s->soc),"ddr" ,OBJECT (machine->ram), &error_abort); +object_property_set_link (OBJECT (&s->soc),"canbus0" ,OBJECT (s->canbus[0 ]), + &error_abort); +object_property_set_link (OBJECT (&s->soc),"canbus1" ,OBJECT (s->canbus[1 ]), + &error_abort);sysbus_realize (SYS_BUS_DEVICE (&s->soc), &error_fatal);fdt_create (s);create_virtio_regions (s);fdt_add_gem_nodes (s);fdt_add_uart_nodes (s); +fdt_add_canfd_nodes (s);fdt_add_gic_nodes (s);fdt_add_timer_nodes (s);fdt_add_zdma_nodes (s);@@ -712,6 +747,16 @@ static void versal_virt_init(MachineState *machine)static void versal_virt_machine_instance_init (Object *obj) {
hw/arm/xlnx-versal-virt.c static void versal_virt_init(MachineState *machine) · line 759
Quoted 10 lines
hw/arm/xlnx-versal-virt.c +10
-0+VersalVirt *s =XLNX_VERSAL_VIRT_MACHINE (obj); + +object_property_add_link (obj,"canbus0" ,TYPE_CAN_BUS , + (Object **)&s->canbus[0 ], + object_property_allow_set_link, +0 ); +object_property_add_link (obj,"canbus1" ,TYPE_CAN_BUS , + (Object **)&s->canbus[1 ], + object_property_allow_set_link, +0 );
What are these for ?
Quoted 15 lines
hw/arm/xlnx-versal-virt.c +0
-0}static void versal_virt_machine_class_init (ObjectClass *oc,void *data)hw/arm/xlnx-versal.c +4
-0@@ -185,6 +185,38 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic) } } +static void versal_create_canfds (Versal *s,qemu_irq *pic) +{ +int i; +
hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 201
Quoted 10 lines
hw/arm/xlnx-versal.c +10
-0+for (i =0 ; i <ARRAY_SIZE (s->lpd.iou.canfd); i++) { +static const int irqs[] = {VERSAL_CANFD0_IRQ_0 ,VERSAL_CANFD1_IRQ_0 }; +static const uint64_t addrs[] = {MM_CANFD0 ,MM_CANFD1 }; +char *name =g_strdup_printf ("canfd%d" , i); +DeviceState *dev; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->lpd.iou.canfd[i], +TYPE_XILINX_CANFD ); + dev =DEVICE (&s->lpd.iou.canfd[i]);
You never use dev directly as a DeviceState, so you might as well make it a SysBusDevice and save some of the cast macros below.
Quoted 7 lines
hw/arm/xlnx-versal.c +7
-0+ +object_property_set_int (OBJECT (&s->lpd.iou.canfd[i]),"ext_clk_freq" , +XLNX_VERSAL_CANFD_REF_CLK , &error_abort); + +object_property_set_link (OBJECT (dev),"canfdbus" , +OBJECT (s->lpd.iou.canbus[i]), + &error_abort);
hw/arm/xlnx-versal.c static void versal_create_uarts(Versal *s, qemu_irq *pic) · line 218
Quoted 10 lines
hw/arm/xlnx-versal.c +10
-0+ +sysbus_realize (SYS_BUS_DEVICE (dev), &error_fatal); + + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ); +memory_region_add_subregion (&s->mr_ps, addrs[i], mr); + +sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , pic[irqs[i]]); +g_free (name); + } +}
thanks
-- PMM
PATCH 4/5 tests/qtest: Introduce tests for Xilinx VERSAL CANFD controller
In reply to Vikram GarhwalThe QTests perform three tests on the Xilinx VERSAL CANFD controller:
Tests the CANFD controllers in loopback.
Tests the CANFD controllers in normal mode with CAN frame. Tests the CANFD controllers in normal mode with CANFD frame.
--- tests/qtest/meson.build | 1 + tests/qtest/xlnx-canfd-test.c | 421 ++++++++++++++++++++++++++++++++++ 2 files changed, 422 insertions(+) create mode 100644 tests/qtest/xlnx-canfd-test.c
tests/qtest/meson.build +1 -0
@@ -217,6 +217,7 @@ qtests_aarch64 = \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ + (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test'] : []) + \ ['arm-cpu-features', 'numa-test', 'boot-serial-test',
tests/qtest/xlnx-canfd-test.c new file +421 -0
421 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [QEMU][PATCH 4/5] tests/qtest: Introduce tests for Xilinx VERSAL CANFD controller
Quoted 45 lines · Vikram Garhwal
The QTests perform three tests on the Xilinx VERSAL CANFD controller:
Tests the CANFD controllers in loopback.
Tests the CANFD controllers in normal mode with CAN frame. Tests the CANFD controllers in normal mode with CANFD frame.Signed-off-by Vikram Garhwal <[email protected]>--- tests/qtest/meson.build | 1 + tests/qtest/xlnx-canfd-test.c | 421 ++++++++++++++++++++++++++++++++++ 2 files changed, 422 insertions(+)create mode 100644
tests/qtest/xlnx-canfd-test.ctests/qtest/meson.build +1
-0@@ -217,6 +217,7 @@ qtests_aarch64 = \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ + (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test'] : []) + \ ['arm-cpu-features', 'numa-test', 'boot-serial-test',tests/qtest/xlnx-canfd-test.c new file +15
-0@@ -0,0 +1,421 @@ +/* +* QTests for the Xilinx Versal CANFD controller. +* +* Copyright (c) 2022 AMD Inc. +* +* Written-by: Vikram Garhwal<[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in
tests/qtest/xlnx-canfd-test.c line 25
Quoted 10 lines
tests/qtest/xlnx-canfd-test.c new file +10
-0+* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/
It's just my personal taste, but could you maybe add a SPDX license identifier in front of the license code? ... that would make it easier to identify the kind of license instead of reading through the whole text to understand which license it is.
Apart from that, patch looks fine to me at a quick glance.
PATCH 5/5 MAINTAINERS: Include canfd tests under Xilinx CAN
In reply to Vikram Garhwal--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -1756,7 +1756,7 @@ M: Francisco Iglesias <[email protected]> S: Maintained F: hw/net/can/xlnx-* F: include/hw/net/xlnx-* -F: tests/qtest/xlnx-can-test* +F: tests/qtest/xlnx-can*-test* EDU M: Jiri Slaby <[email protected]>
Signature · 1 line
2.17.1
Re: [QEMU][PATCH 5/5] MAINTAINERS: Include canfd tests under Xilinx CAN
Quoted 2 lines · Vikram Garhwal
Signed-off-by Vikram Garhwal <[email protected]>
thanks
-- PMM
Quoted 1 line · Vikram Garhwal
Signed-off-by Vikram Garhwal <[email protected]>
Quoted 23 lines
--- MAINTAINERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)MAINTAINERS +2
-2@@ -1751,8 +1751,8 @@ F: tests/qtest/intel-hda-test.c F: tests/qtest/fuzz-sb16-test.c Xilinx CAN -M: Vikram Garhwal <[email protected]> -M: Francisco Iglesias <[email protected]> +M: Vikram Garhwal <[email protected]> +M: Francisco Iglesias <[email protected]> S: Maintained F: hw/net/can/xlnx-* F: include/hw/net/xlnx-*Signature · 1 line
2.17.1