122c30607SScott Branden /* SPDX-License-Identifier: GPL-2.0 */ 222c30607SScott Branden /* 322c30607SScott Branden * Copyright 2018-2020 Broadcom. 422c30607SScott Branden */ 522c30607SScott Branden 622c30607SScott Branden #ifndef BCM_VK_MSG_H 722c30607SScott Branden #define BCM_VK_MSG_H 822c30607SScott Branden 9111d746bSScott Branden #include <uapi/linux/misc/bcm_vk.h> 10111d746bSScott Branden #include "bcm_vk_sg.h" 11111d746bSScott Branden 12111d746bSScott Branden /* Single message queue control structure */ 13111d746bSScott Branden struct bcm_vk_msgq { 14111d746bSScott Branden u16 type; /* queue type */ 15111d746bSScott Branden u16 num; /* queue number */ 16111d746bSScott Branden u32 start; /* offset in BAR1 where the queue memory starts */ 17111d746bSScott Branden 18111d746bSScott Branden u32 rd_idx; /* read idx */ 19111d746bSScott Branden u32 wr_idx; /* write idx */ 20111d746bSScott Branden 21111d746bSScott Branden u32 size; /* 22111d746bSScott Branden * size, which is in number of 16byte blocks, 23111d746bSScott Branden * to align with the message data structure. 24111d746bSScott Branden */ 25111d746bSScott Branden u32 nxt; /* 26111d746bSScott Branden * nxt offset to the next msg queue struct. 27111d746bSScott Branden * This is to provide flexibity for alignment purposes. 28111d746bSScott Branden */ 29111d746bSScott Branden 30111d746bSScott Branden /* Least significant 16 bits in below field hold doorbell register offset */ 31111d746bSScott Branden #define DB_SHIFT 16 32111d746bSScott Branden 33111d746bSScott Branden u32 db_offset; /* queue doorbell register offset in BAR0 */ 34111d746bSScott Branden 35111d746bSScott Branden u32 rsvd; 36111d746bSScott Branden }; 37111d746bSScott Branden 38111d746bSScott Branden /* 39111d746bSScott Branden * Structure to record static info from the msgq sync. We keep local copy 40111d746bSScott Branden * for some of these variables for both performance + checking purpose. 41111d746bSScott Branden */ 42111d746bSScott Branden struct bcm_vk_sync_qinfo { 43111d746bSScott Branden void __iomem *q_start; 44111d746bSScott Branden u32 q_size; 45111d746bSScott Branden u32 q_mask; 46111d746bSScott Branden u32 q_low; 47111d746bSScott Branden u32 q_db_offset; 48111d746bSScott Branden }; 49111d746bSScott Branden 50111d746bSScott Branden #define VK_MSGQ_MAX_NR 4 /* Maximum number of message queues */ 51111d746bSScott Branden 52111d746bSScott Branden /* 53111d746bSScott Branden * message block - basic unit in the message where a message's size is always 54111d746bSScott Branden * N x sizeof(basic_block) 55111d746bSScott Branden */ 56111d746bSScott Branden struct vk_msg_blk { 57111d746bSScott Branden u8 function_id; 58111d746bSScott Branden #define VK_FID_TRANS_BUF 5 59111d746bSScott Branden #define VK_FID_SHUTDOWN 8 60111d746bSScott Branden #define VK_FID_INIT 9 61111d746bSScott Branden u8 size; /* size of the message in number of vk_msg_blk's */ 62111d746bSScott Branden u16 trans_id; /* transport id, queue & msg_id */ 63111d746bSScott Branden u32 context_id; 64111d746bSScott Branden #define VK_NEW_CTX 0 65111d746bSScott Branden u32 cmd; 66111d746bSScott Branden #define VK_CMD_PLANES_MASK 0x000f /* number of planes to up/download */ 67111d746bSScott Branden #define VK_CMD_UPLOAD 0x0400 /* memory transfer to vk */ 68111d746bSScott Branden #define VK_CMD_DOWNLOAD 0x0500 /* memory transfer from vk */ 69111d746bSScott Branden #define VK_CMD_MASK 0x0f00 /* command mask */ 70111d746bSScott Branden u32 arg; 71111d746bSScott Branden }; 72111d746bSScott Branden 73111d746bSScott Branden /* vk_msg_blk is 16 bytes fixed */ 74111d746bSScott Branden #define VK_MSGQ_BLK_SIZE (sizeof(struct vk_msg_blk)) 75111d746bSScott Branden /* shift for fast division of basic msg blk size */ 76111d746bSScott Branden #define VK_MSGQ_BLK_SZ_SHIFT 4 77111d746bSScott Branden 78111d746bSScott Branden /* use msg_id 0 for any simplex host2vk communication */ 79111d746bSScott Branden #define VK_SIMPLEX_MSG_ID 0 80111d746bSScott Branden 8122c30607SScott Branden /* context per session opening of sysfs */ 8222c30607SScott Branden struct bcm_vk_ctx { 8322c30607SScott Branden struct list_head node; /* use for linkage in Hash Table */ 8422c30607SScott Branden unsigned int idx; 8522c30607SScott Branden bool in_use; 8622c30607SScott Branden pid_t pid; 8722c30607SScott Branden u32 hash_idx; 88111d746bSScott Branden u32 q_num; /* queue number used by the stream */ 8922c30607SScott Branden struct miscdevice *miscdev; 90111d746bSScott Branden atomic_t pend_cnt; /* number of items pending to be read from host */ 91111d746bSScott Branden atomic_t dma_cnt; /* any dma transaction outstanding */ 92111d746bSScott Branden wait_queue_head_t rd_wq; 9322c30607SScott Branden }; 9422c30607SScott Branden 9522c30607SScott Branden /* pid hash table entry */ 9622c30607SScott Branden struct bcm_vk_ht_entry { 9722c30607SScott Branden struct list_head head; 9822c30607SScott Branden }; 9922c30607SScott Branden 100111d746bSScott Branden #define VK_DMA_MAX_ADDRS 4 /* Max 4 DMA Addresses */ 101111d746bSScott Branden /* structure for house keeping a single work entry */ 102111d746bSScott Branden struct bcm_vk_wkent { 103111d746bSScott Branden struct list_head node; /* for linking purpose */ 104111d746bSScott Branden struct bcm_vk_ctx *ctx; 105111d746bSScott Branden 106111d746bSScott Branden /* Store up to 4 dma pointers */ 107111d746bSScott Branden struct bcm_vk_dma dma[VK_DMA_MAX_ADDRS]; 108111d746bSScott Branden 109111d746bSScott Branden u32 to_h_blks; /* response */ 110111d746bSScott Branden struct vk_msg_blk *to_h_msg; 111111d746bSScott Branden 112111d746bSScott Branden /* 113111d746bSScott Branden * put the to_v_msg at the end so that we could simply append to_v msg 114111d746bSScott Branden * to the end of the allocated block 115111d746bSScott Branden */ 116111d746bSScott Branden u32 usr_msg_id; 117111d746bSScott Branden u32 to_v_blks; 118111d746bSScott Branden u32 seq_num; 119*208012f0SGustavo A. R. Silva struct vk_msg_blk to_v_msg[]; 120111d746bSScott Branden }; 121111d746bSScott Branden 122111d746bSScott Branden /* queue stats counters */ 123111d746bSScott Branden struct bcm_vk_qs_cnts { 124111d746bSScott Branden u32 cnt; /* general counter, used to limit output */ 125111d746bSScott Branden u32 acc_sum; 126111d746bSScott Branden u32 max_occ; /* max during a sampling period */ 127111d746bSScott Branden u32 max_abs; /* the abs max since reset */ 128111d746bSScott Branden }; 129111d746bSScott Branden 130111d746bSScott Branden /* control channel structure for either to_v or to_h communication */ 131111d746bSScott Branden struct bcm_vk_msg_chan { 132111d746bSScott Branden u32 q_nr; 133111d746bSScott Branden /* Mutex to access msgq */ 134111d746bSScott Branden struct mutex msgq_mutex; 135111d746bSScott Branden /* pointing to BAR locations */ 136111d746bSScott Branden struct bcm_vk_msgq __iomem *msgq[VK_MSGQ_MAX_NR]; 137111d746bSScott Branden /* Spinlock to access pending queue */ 138111d746bSScott Branden spinlock_t pendq_lock; 139111d746bSScott Branden /* for temporary storing pending items, one for each queue */ 140111d746bSScott Branden struct list_head pendq[VK_MSGQ_MAX_NR]; 141111d746bSScott Branden /* static queue info from the sync */ 142111d746bSScott Branden struct bcm_vk_sync_qinfo sync_qinfo[VK_MSGQ_MAX_NR]; 143111d746bSScott Branden }; 144111d746bSScott Branden 145111d746bSScott Branden /* totol number of message q allowed by the driver */ 146111d746bSScott Branden #define VK_MSGQ_PER_CHAN_MAX 3 147111d746bSScott Branden #define VK_MSGQ_NUM_DEFAULT (VK_MSGQ_PER_CHAN_MAX - 1) 148111d746bSScott Branden 14922c30607SScott Branden /* total number of supported ctx, 32 ctx each for 5 components */ 15022c30607SScott Branden #define VK_CMPT_CTX_MAX (32 * 5) 15122c30607SScott Branden 15222c30607SScott Branden /* hash table defines to store the opened FDs */ 15322c30607SScott Branden #define VK_PID_HT_SHIFT_BIT 7 /* 128 */ 15422c30607SScott Branden #define VK_PID_HT_SZ BIT(VK_PID_HT_SHIFT_BIT) 15522c30607SScott Branden 156111d746bSScott Branden /* The following are offsets of DDR info provided by the vk card */ 157111d746bSScott Branden #define VK_BAR0_SEG_SIZE (4 * SZ_1K) /* segment size for BAR0 */ 158111d746bSScott Branden 159111d746bSScott Branden /* shutdown types supported */ 160111d746bSScott Branden #define VK_SHUTDOWN_PID 1 161111d746bSScott Branden #define VK_SHUTDOWN_GRACEFUL 2 162111d746bSScott Branden 16322c30607SScott Branden #endif 164