1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2018-2020 Broadcom.
9 #include <uapi/linux/misc/bcm_vk.h>
10 #include "bcm_vk_sg.h"
12 /* Single message queue control structure */
14 u16 type; /* queue type */
15 u16 num; /* queue number */
16 u32 start; /* offset in BAR1 where the queue memory starts */
18 u32 rd_idx; /* read idx */
19 u32 wr_idx; /* write idx */
22 * size, which is in number of 16byte blocks,
23 * to align with the message data structure.
26 * nxt offset to the next msg queue struct.
27 * This is to provide flexibity for alignment purposes.
30 /* Least significant 16 bits in below field hold doorbell register offset */
33 u32 db_offset; /* queue doorbell register offset in BAR0 */
39 * Structure to record static info from the msgq sync. We keep local copy
40 * for some of these variables for both performance + checking purpose.
42 struct bcm_vk_sync_qinfo {
43 void __iomem *q_start;
50 #define VK_MSGQ_MAX_NR 4 /* Maximum number of message queues */
53 * message block - basic unit in the message where a message's size is always
54 * N x sizeof(basic_block)
58 #define VK_FID_TRANS_BUF 5
59 #define VK_FID_SHUTDOWN 8
61 u8 size; /* size of the message in number of vk_msg_blk's */
62 u16 trans_id; /* transport id, queue & msg_id */
66 #define VK_CMD_PLANES_MASK 0x000f /* number of planes to up/download */
67 #define VK_CMD_UPLOAD 0x0400 /* memory transfer to vk */
68 #define VK_CMD_DOWNLOAD 0x0500 /* memory transfer from vk */
69 #define VK_CMD_MASK 0x0f00 /* command mask */
73 /* vk_msg_blk is 16 bytes fixed */
74 #define VK_MSGQ_BLK_SIZE (sizeof(struct vk_msg_blk))
75 /* shift for fast division of basic msg blk size */
76 #define VK_MSGQ_BLK_SZ_SHIFT 4
78 /* use msg_id 0 for any simplex host2vk communication */
79 #define VK_SIMPLEX_MSG_ID 0
81 /* context per session opening of sysfs */
83 struct list_head node; /* use for linkage in Hash Table */
88 u32 q_num; /* queue number used by the stream */
89 struct miscdevice *miscdev;
90 atomic_t pend_cnt; /* number of items pending to be read from host */
91 atomic_t dma_cnt; /* any dma transaction outstanding */
92 wait_queue_head_t rd_wq;
95 /* pid hash table entry */
96 struct bcm_vk_ht_entry {
97 struct list_head head;
100 #define VK_DMA_MAX_ADDRS 4 /* Max 4 DMA Addresses */
101 /* structure for house keeping a single work entry */
102 struct bcm_vk_wkent {
103 struct list_head node; /* for linking purpose */
104 struct bcm_vk_ctx *ctx;
106 /* Store up to 4 dma pointers */
107 struct bcm_vk_dma dma[VK_DMA_MAX_ADDRS];
109 u32 to_h_blks; /* response */
110 struct vk_msg_blk *to_h_msg;
113 * put the to_v_msg at the end so that we could simply append to_v msg
114 * to the end of the allocated block
119 struct vk_msg_blk to_v_msg[];
122 /* queue stats counters */
123 struct bcm_vk_qs_cnts {
124 u32 cnt; /* general counter, used to limit output */
126 u32 max_occ; /* max during a sampling period */
127 u32 max_abs; /* the abs max since reset */
130 /* control channel structure for either to_v or to_h communication */
131 struct bcm_vk_msg_chan {
133 /* Mutex to access msgq */
134 struct mutex msgq_mutex;
135 /* pointing to BAR locations */
136 struct bcm_vk_msgq __iomem *msgq[VK_MSGQ_MAX_NR];
137 /* Spinlock to access pending queue */
138 spinlock_t pendq_lock;
139 /* for temporary storing pending items, one for each queue */
140 struct list_head pendq[VK_MSGQ_MAX_NR];
141 /* static queue info from the sync */
142 struct bcm_vk_sync_qinfo sync_qinfo[VK_MSGQ_MAX_NR];
145 /* totol number of message q allowed by the driver */
146 #define VK_MSGQ_PER_CHAN_MAX 3
147 #define VK_MSGQ_NUM_DEFAULT (VK_MSGQ_PER_CHAN_MAX - 1)
149 /* total number of supported ctx, 32 ctx each for 5 components */
150 #define VK_CMPT_CTX_MAX (32 * 5)
152 /* hash table defines to store the opened FDs */
153 #define VK_PID_HT_SHIFT_BIT 7 /* 128 */
154 #define VK_PID_HT_SZ BIT(VK_PID_HT_SHIFT_BIT)
156 /* The following are offsets of DDR info provided by the vk card */
157 #define VK_BAR0_SEG_SIZE (4 * SZ_1K) /* segment size for BAR0 */
159 /* shutdown types supported */
160 #define VK_SHUTDOWN_PID 1
161 #define VK_SHUTDOWN_GRACEFUL 2