MAINTAINERS: Include canfd tests under Xilinx CAN
PATCH v5 1/4 MAINTAINERS: Include canfd tests under Xilinx CAN
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -1813,7 +1813,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
PATCH v5 2/4 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.
--- hw/net/can/meson.build | 1 + hw/net/can/trace-events | 7 + hw/net/can/xlnx-versal-canfd.c | 2107 ++++++++++++++++++++++++++++ include/hw/net/xlnx-versal-canfd.h | 87 ++ 4 files changed, 2202 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 +2107 -0
2,107 lines not on this page · raw message
include/hw/net/xlnx-versal-canfd.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [QEMU][PATCH v5 2/4] hw/net/can: Introduce Xilinx Versal CANFD controller
Hi Vikram,
Quoted 44 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.
Signed-off-by Vikram Garhwal <[email protected]>--- hw/net/can/meson.build | 1 + hw/net/can/trace-events | 7 + hw/net/can/xlnx-versal-canfd.c | 2107 ++++++++++++++++++++++++++++ include/hw/net/xlnx-versal-canfd.h | 87 ++ 4 files changed, 2202 insertions(+) create mode 100644 hw/net/can/xlnx-versal-canfd.c create mode 100644 include/hw/net/xlnx-versal-canfd.hhw/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 +0
-0
hw/net/can/xlnx-versal-canfd.c line 7
Quoted 7 lines
hw/net/can/xlnx-versal-canfd.c new file +7
-0@@ -0,0 +1,2107 @@ +/* +* QEMU model of the Xilinx Versal CANFD device. +* +* This implementation is based on the following datasheet: +* https://docs.xilinx.com/v/u/2.0-English/pg223-canfd +* +* Copyright (c) 2022 AMD Inc.
s/2022 AMD Inc/2023 Advanced Micro Devices, Inc/
Quoted 15 lines
hw/net/can/xlnx-versal-canfd.c new file +15
-0+* +* Written-by: Vikram Garhwal <[email protected]> +* +* Based on QEMU CANFD Device emulation implemented by Jin Yang, Deniz Eren and +* Pavel Pisa +* +* 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 +* all copies or substantial portions of the Software.
hw/net/can/xlnx-versal-canfd.c line 32
Quoted 10 lines
hw/net/can/xlnx-versal-canfd.c new file +10
-0+* +* 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. +*/ +
.
.
.
Quoted 22 lines
hw/net/can/xlnx-versal-canfd.c new file +22
-0+REG32(STATUS_REGISTER, 0x18) + FIELD(STATUS_REGISTER, TDCV, 16, 7) + FIELD(STATUS_REGISTER, SNOOP, 12, 1) + FIELD(STATUS_REGISTER, BSFR_CONFIG, 10, 1) + FIELD(STATUS_REGISTER, PEE_CONFIG, 9, 1) + FIELD(STATUS_REGISTER, ESTAT, 7, 2) + FIELD(STATUS_REGISTER, ERRWRN, 6, 1) + FIELD(STATUS_REGISTER, BBSY, 5, 1) + FIELD(STATUS_REGISTER, BIDLE, 4, 1) + FIELD(STATUS_REGISTER, NORMAL, 3, 1) + FIELD(STATUS_REGISTER, SLEEP, 2, 1) + FIELD(STATUS_REGISTER, LBACK, 1, 1) + FIELD(STATUS_REGISTER, CONFIG, 0, 1) +REG32(INTERRUPT_STATUS_REGISTER, 0x1c) + FIELD(INTERRUPT_STATUS_REGISTER, TXEWMFLL, 31, 1) + FIELD(INTERRUPT_STATUS_REGISTER, TXEOFLW, 30, 1) + FIELD(INTERRUPT_STATUS_REGISTER, RXBOFLW_BI, 24, 6) + FIELD(INTERRUPT_STATUS_REGISTER, RXLRM_BI, 18, 6) + FIELD(INTERRUPT_STATUS_REGISTER, RXMNF, 17, 1) + FIELD(INTERRUPT_STATUS_REGISTER, RXFWMFLL_1, 16, 1) + FIELD(INTERRUPT_STATUS_REGISTER, RXFOFLW_1, 15, 1) +FIELD (INTERRUPT_STATUS_REGISTER ,TXCRS ,14 ,1 )
hw/net/can/xlnx-versal-canfd.c line 111
Quoted 10 lines
hw/net/can/xlnx-versal-canfd.c new file +10
-0+ FIELD(INTERRUPT_STATUS_REGISTER, TXRRS, 13, 1) + FIELD(INTERRUPT_STATUS_REGISTER, RXFWMFLL, 12, 1) + FIELD(INTERRUPT_STATUS_REGISTER, WKUP, 11, 1) + FIELD(INTERRUPT_STATUS_REGISTER, SLP, 10, 1) +FIELD (INTERRUPT_STATUS_REGISTER ,BSOFF ,9 ,1 ) +/* +* In original hw description below bit is named as ERROR but ERROR field +* name collides with a macro in Windows build. To avoid Windows build +* failure, renaming the bit to ERROR_BIT manually. +*/
Below sounds better to me but since I'm not english native this is just a suggestion (alternatively for my taste it is clear enough without the comment too).
"In the original HW description below bit is named as ERROR but an ERROR field name collides with a macro in the Windows build. To avoid Windows build failures, the bit is renamed to ERROR_BIT."
Quoted 18 lines
hw/net/can/xlnx-versal-canfd.c new file +18
-0+ FIELD(INTERRUPT_STATUS_REGISTER, ERROR_BIT, 8, 1) + FIELD(INTERRUPT_STATUS_REGISTER, RXFOFLW, 6, 1) + FIELD(INTERRUPT_STATUS_REGISTER, TSCNT_OFLW, 5, 1) + FIELD(INTERRUPT_STATUS_REGISTER, RXOK, 4, 1) + FIELD(INTERRUPT_STATUS_REGISTER, BSFRD, 3, 1) + FIELD(INTERRUPT_STATUS_REGISTER, PEE, 2, 1) + FIELD(INTERRUPT_STATUS_REGISTER, TXOK, 1, 1) + FIELD(INTERRUPT_STATUS_REGISTER, ARBLST, 0, 1) +REG32(INTERRUPT_ENABLE_REGISTER, 0x20) + FIELD(INTERRUPT_ENABLE_REGISTER, ETXEWMFLL, 31, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ETXEOFLW, 30, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ERXMNF, 17, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ERXFWMFLL_1, 16, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ERXFOFLW_1, 15, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ETXCRS, 14, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ETXRRS, 13, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ERXFWMFLL, 12, 1) +FIELD (INTERRUPT_ENABLE_REGISTER ,EWKUP ,11 ,1 )
hw/net/can/xlnx-versal-canfd.c line 139
Quoted 10 lines
hw/net/can/xlnx-versal-canfd.c new file +10
-0+ FIELD(INTERRUPT_ENABLE_REGISTER, ESLP, 10, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, EBSOFF, 9, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, EERROR, 8, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ERFXOFLW, 6, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ETSCNT_OFLW, 5, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ERXOK, 4, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, EBSFRD, 3, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, EPEE, 2, 1) + FIELD(INTERRUPT_ENABLE_REGISTER, ETXOK, 1, 1) +FIELD (INTERRUPT_ENABLE_REGISTER ,EARBLOST ,0 ,1 )
.
.
.
Quoted 12 lines
hw/net/can/xlnx-versal-canfd.c new file +6
-0+static void canfd_register_types (void ) +{ +type_register_static (&canfd_info); +} + +type_init (canfd_register_types)include/hw/net/xlnx-versal-canfd.h new file +0
-0
include/hw/net/xlnx-versal-canfd.h line 4
Quoted 4 lines
include/hw/net/xlnx-versal-canfd.h new file +4
-0@@ -0,0 +1,87 @@ +/* +* QEMU model of the Xilinx Versal CANFD Controller. +* +* Copyright (c) 2022 AMD Inc.
s/2022 AMD Inc/2023 Advanced Micro Devices, Inc/
Quoted 30 lines
include/hw/net/xlnx-versal-canfd.h new file +30
-0+* +* Written-by: Vikram Garhwal<[email protected]> +* Based on QEMU CANFD Device emulation implemented by Jin Yang, Deniz Eren and +* Pavel Pisa. +* 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 +* 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. +*/ + +#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"
include/hw/net/xlnx-versal-canfd.h line 44
Quoted 10 lines
include/hw/net/xlnx-versal-canfd.h new file +10
-0+ +#define TYPE_XILINX_CANFD "xlnx.versal-canfd" + +OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCANFDState, XILINX_CANFD) + +#define NUM_REGS_PER_MSG_SPACE 18/* 1 ID + 1 DLC + 16 Data(DW0 - DW15) regs. */ +#define MAX_NUM_RX 64 +#define OFFSET_RX1_DW15 (0x4144 / 4) +#define CANFD_TIMER_MAX 0xFFFFUL +#define CANFD_DEFAULT_CLOCK (24 * 1000 * 1000)
s/24/25/
With above changes:
Quoted 46 lines
include/hw/net/xlnx-versal-canfd.h new file +43
-0+ +#define XLNX_VERSAL_CANFD_R_MAX (OFFSET_RX1_DW15 + \ + ((MAX_NUM_RX - 1) * NUM_REGS_PER_MSG_SPACE) + 1) + +typedef struct XlnxVersalCANFDState { +SysBusDevice parent_obj; +MemoryRegion iomem; + +qemu_irq irq_canfd_int; +qemu_irq irq_addr_err; + +RegisterInfo reg_info[XLNX_VERSAL_CANFD_R_MAX ]; +RegisterAccessInfo *tx_regs; +RegisterAccessInfo *rx0_regs; +RegisterAccessInfo *rx1_regs; +RegisterAccessInfo *af_regs; +RegisterAccessInfo *txe_regs; +RegisterAccessInfo *rx_mailbox_regs; +RegisterAccessInfo *af_mask_regs_mailbox; + +uint32_t regs[XLNX_VERSAL_CANFD_R_MAX ]; + +ptimer_state *canfd_timer; + +CanBusClientState bus_client; +CanBusState *canfdbus; + +struct { +uint8_t rx0_fifo; +uint8_t rx1_fifo; +uint8_t tx_fifo; +bool enable_rx_fifo1; +uint32_t ext_clk_freq; + } cfg; + +}XlnxVersalCANFDState ; + +typedef struct tx_ready_reg_info { +uint32_t can_id; +uint32_t reg_num; +}tx_ready_reg_info ; + +#endif Signature · 1 line
2.17.1
PATCH v5 3/4 xlnx-versal: Connect Xilinx VERSAL CANFD controllers
In reply to Vikram GarhwalConnect CANFD0 and CANFD1 on the Versal-virt machine and update xlnx-versal-virt document with CANFD command line examples.
--- docs/system/arm/xlnx-versal-virt.rst | 31 ++++++++++++++++ hw/arm/xlnx-versal-virt.c | 53 ++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 37 +++++++++++++++++++ include/hw/arm/xlnx-versal.h | 12 +++++++ 4 files changed, 133 insertions(+)
docs/system/arm/xlnx-versal-virt.rst +31 -0
@@ -34,6 +34,7 @@ Implemented devices: - DDR memory - BBRAM (36 bytes of Battery-backed RAM) - eFUSE (3072 bytes of one-time field-programmable bit array) +- 2 CANFDs QEMU does not yet model any other devices, including the PL and the AI Engine.
@@ -224,3 +225,33 @@ To use a different index value, N, from default of 1, add: Better yet, do not use actual product data when running guest image on this Xilinx Versal Virt board. + +Using CANFDs for Versal Virt +"""""""""""""""""""""""""""" +Versal CANFD controller is developed based on SocketCAN and QEMU CAN bus +implementation. Bus connection and socketCAN connection for each CAN module +can be set through command lines. + +To connect both CANFD0 and CANFD1 on the same bus: + +.. code-block:: bash + + -object can-bus,id=canbus -machine canbus0=canbus -machine canbus1=canbus + +To connect CANFD0 and CANFD1 to separate buses: + +.. code-block:: bash + + -object can-bus,id=canbus0 -object can-bus,id=canbus1 \ + -machine canbus0=canbus0 -machine canbus1=canbus1 + +The SocketCAN interface can connect to a Physical or a Virtual CAN interfaces on +the host machine. Please check this document to learn about CAN interface on +Linux: docs/system/devices/can.rst + +To connect CANFD0 and CANFD1 to host machine's CAN interface can0: + +.. code-block:: bash + + -object can-bus,id=canbus -machine canbus0=canbus -machine canbus1=canbus + -object can-host-socketcan,id=canhost0,if=can0,canbus=canbus
hw/arm/xlnx-versal-virt.c +53 -0
86 lines not on this page · raw message
hw/arm/xlnx-versal.c +37 -0
@@ -184,6 +184,38 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic) } } +static void versal_create_canfds (Versal *s,qemu_irq *pic) +{ +int i; +uint32_t irqs[] = {VERSAL_CANFD0_IRQ_0 ,VERSAL_CANFD1_IRQ_0 }; +uint64_t addrs[] = {MM_CANFD0 ,MM_CANFD1 }; + +for (i =0 ; i <ARRAY_SIZE (s->lpd.iou.canfd); i++) { +char *name =g_strdup_printf ("canfd%d" , i); +SysBusDevice *sbd; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->lpd.iou.canfd[i], +TYPE_XILINX_CANFD ); + sbd =SYS_BUS_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 (&s->lpd.iou.canfd[i]),"canfdbus" , +OBJECT (s->lpd.iou.canbus[i]), + &error_abort); + +sysbus_realize (sbd, &error_fatal); + + mr =sysbus_mmio_get_region (sbd,0 ); +memory_region_add_subregion (&s->mr_ps, addrs[i], mr); + +sysbus_connect_irq (sbd,0 , pic[irqs[i]]); +g_free (name); + } +} +static void versal_create_usbs (Versal *s,qemu_irq *pic) {DeviceState *dev;
@@ -718,6 +750,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);
@@ -757,6 +790,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 0xff060000U +#define MM_CANFD0_SIZE 0x10000 +#define MM_CANFD1 0xff070000U +#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 v5 3/4] xlnx-versal: Connect Xilinx VERSAL CANFD controllers
Quoted 5 lines · Vikram Garhwal
Connect CANFD0 and CANFD1 on the Versal-virt machine and update xlnx-versal-virt document with CANFD command line examples.
Signed-off-by Vikram Garhwal <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Quoted 263 lines
--- docs/system/arm/xlnx-versal-virt.rst | 31 ++++++++++++++++ hw/arm/xlnx-versal-virt.c | 53 ++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 37 +++++++++++++++++++ include/hw/arm/xlnx-versal.h | 12 +++++++ 4 files changed, 133 insertions(+)docs/system/arm/xlnx-versal-virt.rst +31
-0@@ -34,6 +34,7 @@ Implemented devices: - DDR memory - BBRAM (36 bytes of Battery-backed RAM) - eFUSE (3072 bytes of one-time field-programmable bit array) +- 2 CANFDs QEMU does not yet model any other devices, including the PL and the AI Engine.@@ -224,3 +225,33 @@ To use a different index value, N, from default of 1, add: Better yet, do not use actual product data when running guest image on this Xilinx Versal Virt board. + +Using CANFDs for Versal Virt +"""""""""""""""""""""""""""" +Versal CANFD controller is developed based on SocketCAN and QEMU CAN bus +implementation. Bus connection and socketCAN connection for each CAN module +can be set through command lines. + +To connect both CANFD0 and CANFD1 on the same bus: + +.. code-block:: bash + + -object can-bus,id=canbus -machine canbus0=canbus -machine canbus1=canbus + +To connect CANFD0 and CANFD1 to separate buses: + +.. code-block:: bash + + -object can-bus,id=canbus0 -object can-bus,id=canbus1 \ + -machine canbus0=canbus0 -machine canbus1=canbus1 + +The SocketCAN interface can connect to a Physical or a Virtual CAN interfaces on +the host machine. Please check this document to learn about CAN interface on +Linux: docs/system/devices/can.rst + +To connect CANFD0 and CANFD1 to host machine's CAN interface can0: + +.. code-block:: bash + + -object can-bus,id=canbus -machine canbus0=canbus -machine canbus1=canbus + -object can-host-socketcan,id=canhost0,if=can0,canbus=canbushw/arm/xlnx-versal-virt.c +53
-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,38 @@ static void fdt_add_uart_nodes(VersalVirt *s) } } +static void fdt_add_canfd_nodes (VersalVirt *s) +{ +uint64_t addrs[] = {MM_CANFD1 ,MM_CANFD0 }; +uint32_t size[] = {MM_CANFD1_SIZE ,MM_CANFD0_SIZE }; +unsigned int irqs[] = {VERSAL_CANFD1_IRQ_0 ,VERSAL_CANFD0_IRQ_0 }; +const char clocknames[] ="can_clk\0s_axi_aclk" ; +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-fifo-depth" ,0x40 ); +qemu_fdt_setprop_cell (s->fdt, name,"tx-mailbox-count" ,0x20 ); + +qemu_fdt_setprop_cells (s->fdt, name,"clocks" , + s->phandle.clk_25Mhz, s->phandle.clk_25Mhz); +qemu_fdt_setprop (s->fdt, name,"clock-names" , + clocknames,sizeof (clocknames)); +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_string (s->fdt, name,"compatible" , +"xlnx,canfd-2.0" ); + +g_free (name); + } +} +static void fdt_add_fixed_link_nodes (VersalVirt *s,char *gemname,uint32_t phandle) {@@ -639,12 +673,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 +751,20 @@ static void versal_virt_init(MachineState *machine)static void versal_virt_machine_instance_init (Object *obj) { +VersalVirt *s =XLNX_VERSAL_VIRT_MACHINE (obj); + +/* +* User can set canbus0 and canbus1 properties to can-bus object and connect +* to socketcan(optional) interface via command line. +*/ +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@@ -184,6 +184,38 @@ static void versal_create_uarts(Versal *s, qemu_irq *pic) } } +static void versal_create_canfds (Versal *s,qemu_irq *pic) +{ +int i; +uint32_t irqs[] = {VERSAL_CANFD0_IRQ_0 ,VERSAL_CANFD1_IRQ_0 }; +uint64_t addrs[] = {MM_CANFD0 ,MM_CANFD1 }; + +for (i =0 ; i <ARRAY_SIZE (s->lpd.iou.canfd); i++) { +char *name =g_strdup_printf ("canfd%d" , i); +SysBusDevice *sbd; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s), name, &s->lpd.iou.canfd[i], +TYPE_XILINX_CANFD ); + sbd =SYS_BUS_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 (&s->lpd.iou.canfd[i]),"canfdbus" , +OBJECT (s->lpd.iou.canbus[i]), + &error_abort); + +sysbus_realize (sbd, &error_fatal); + + mr =sysbus_mmio_get_region (sbd,0 ); +memory_region_add_subregion (&s->mr_ps, addrs[i], mr); + +sysbus_connect_irq (sbd,0 , pic[irqs[i]]); +g_free (name); + } +} +static void versal_create_usbs (Versal *s,qemu_irq *pic) {DeviceState *dev;@@ -718,6 +750,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);@@ -757,6 +790,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 0xff060000U +#define MM_CANFD0_SIZE 0x10000 +#define MM_CANFD1 0xff070000U +#define MM_CANFD1_SIZE 0x10000 +#define MM_GEM0 0xff0c0000U#define MM_GEM0_SIZE 0x10000#define MM_GEM1 0xff0d0000USignature · 1 line
2.17.1
PATCH v5 4/4 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 | 423 ++++++++++++++++++++++++++++++++++ 2 files changed, 424 insertions(+) create mode 100644 tests/qtest/xlnx-canfd-test.c
tests/qtest/meson.build +1 -0
@@ -212,6 +212,7 @@ qtests_aarch64 = \ (config_all.has_key('CONFIG_TCG') and config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? \ ['tpm-tis-device-test', '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'] : []) + \ (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : []) + \ (config_all.has_key('CONFIG_TCG') and \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
tests/qtest/xlnx-canfd-test.c new file +423 -0
423 lines not on this page · raw message
Signature · 1 line
2.17.1