xref: /openbmc/qemu/include/hw/net/xlnx-zynqmp-can.h (revision 7d87775f)
1 /*
2  * QEMU model of the Xilinx ZynqMP CAN controller.
3  *
4  * Copyright (c) 2020 Xilinx Inc.
5  *
6  * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
7  *
8  * Based on QEMU CAN Device emulation implemented by Jin Yang, Deniz Eren and
9  * Pavel Pisa.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  */
29 
30 #ifndef XLNX_ZYNQMP_CAN_H
31 #define XLNX_ZYNQMP_CAN_H
32 
33 #include "hw/sysbus.h"
34 #include "hw/register.h"
35 #include "net/can_emu.h"
36 #include "net/can_host.h"
37 #include "qemu/fifo32.h"
38 #include "hw/ptimer.h"
39 #include "hw/qdev-clock.h"
40 
41 #define TYPE_XLNX_ZYNQMP_CAN "xlnx.zynqmp-can"
42 
43 #define XLNX_ZYNQMP_CAN(obj) \
44      OBJECT_CHECK(XlnxZynqMPCANState, (obj), TYPE_XLNX_ZYNQMP_CAN)
45 
46 #define MAX_CAN_CTRLS      2
47 #define XLNX_ZYNQMP_CAN_R_MAX     (0x84 / 4)
48 #define MAILBOX_CAPACITY   64
49 #define CAN_TIMER_MAX  0XFFFFUL
50 #define CAN_DEFAULT_CLOCK (24 * 1000 * 1000)
51 
52 /* Each CAN_FRAME will have 4 * 32bit size. */
53 #define CAN_FRAME_SIZE     4
54 #define RXFIFO_SIZE        (MAILBOX_CAPACITY * CAN_FRAME_SIZE)
55 
56 typedef struct XlnxZynqMPCANState {
57     SysBusDevice        parent_obj;
58     MemoryRegion        iomem;
59 
60     qemu_irq            irq;
61 
62     CanBusClientState   bus_client;
63     CanBusState         *canbus;
64 
65     struct {
66         uint32_t        ext_clk_freq;
67     } cfg;
68 
69     RegisterInfo        reg_info[XLNX_ZYNQMP_CAN_R_MAX];
70     uint32_t            regs[XLNX_ZYNQMP_CAN_R_MAX];
71 
72     Fifo32              rx_fifo;
73     Fifo32              tx_fifo;
74     Fifo32              txhpb_fifo;
75 
76     ptimer_state        *can_timer;
77 } XlnxZynqMPCANState;
78 
79 #endif
80