qemu/include/hw/net/xlnx-versal-canfd.h
<<
>>
Prefs
   1/*
   2 * QEMU model of the Xilinx Versal CANFD device.
   3 *
   4 * Copyright (c) 2020 Xilinx Inc.
   5 *
   6 * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
   7 * Based on QEMU CANFD Device emulation implemented by Jin Yang, Deniz Eren and
   8 * Pavel Pisa.
   9 * Permission is hereby granted, free of charge, to any person obtaining a copy
  10 * of this software and associated documentation files (the "Software"), to deal
  11 * in the Software without restriction, including without limitation the rights
  12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13 * copies of the Software, and to permit persons to whom the Software is
  14 * furnished to do so, subject to the following conditions:
  15 *
  16 * The above copyright notice and this permission notice shall be included in
  17 * all copies or substantial portions of the Software.
  18 *
  19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25 * THE SOFTWARE.
  26 */
  27
  28#ifndef HW_CANFD_XILINX_H
  29#define HW_CANFD_XILINX_H
  30
  31#include "hw/register.h"
  32#include "hw/ptimer.h"
  33#include "net/can_emu.h"
  34#include "hw/qdev-clock.h"
  35
  36#define TYPE_XILINX_CANFD "xlnx.versal-canfd"
  37
  38#define XILINX_CANFD(obj) \
  39     OBJECT_CHECK(XlnxVersalCANFDState, (obj), TYPE_XILINX_CANFD)
  40
  41#define NUM_REGS_PER_MSG_SPACE 18
  42#define MAX_NUM_RX             64
  43#define CANFD_TIMER_MAX        0XFFFFUL
  44#define CANFD_DEFAULT_CLOCK    (24 * 1000 * 1000)
  45
  46/* 0x4144/4 + 1 + (64 - 1) * 18 + 1. */
  47#define XLNX_VERSAL_CANFD_R_MAX (0x4144 / 4  + \
  48                    ((MAX_NUM_RX - 1) * NUM_REGS_PER_MSG_SPACE) + 1)
  49
  50typedef struct XlnxVersalCANFDState {
  51    SysBusDevice            parent_obj;
  52    MemoryRegion            iomem;
  53
  54    qemu_irq                irq_canfd_int;
  55    qemu_irq                irq_addr_err;
  56
  57    RegisterInfo            reg_info[XLNX_VERSAL_CANFD_R_MAX];
  58    RegisterAccessInfo      *tx_regs;
  59    RegisterAccessInfo      *rx0_regs;
  60    RegisterAccessInfo      *rx1_regs;
  61    RegisterAccessInfo      *af_regs;
  62    RegisterAccessInfo      *txe_regs;
  63    RegisterAccessInfo      *rx_mailbox_regs;
  64    RegisterAccessInfo      *af_mask_regs_mailbox;
  65
  66    uint32_t                regs[XLNX_VERSAL_CANFD_R_MAX];
  67    uint8_t                 tx_busy_bit;
  68    uint8_t                 modes;
  69
  70    ptimer_state            *canfd_timer;
  71
  72    CanBusClientState       bus_client;
  73    CanBusState             *canfdbus;
  74
  75    struct {
  76        uint8_t             ctrl_idx;
  77        uint8_t             rx0_fifo;
  78        uint8_t             rx1_fifo;
  79        uint8_t             tx_fifo;
  80        bool                enable_rx_fifo1;
  81        uint32_t            ext_clk_freq;
  82   } cfg;
  83
  84} XlnxVersalCANFDState;
  85
  86typedef struct txid_list {
  87    uint32_t can_id;
  88    uint32_t reg_num;
  89    struct txid_list   *next;
  90} txid_list;
  91
  92#endif
  93