bcm_vk_msg.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2018-2020 Broadcom.
  4. */
  5. #ifndef BCM_VK_MSG_H
  6. #define BCM_VK_MSG_H
  7. #include <uapi/linux/misc/bcm_vk.h>
  8. #include "bcm_vk_sg.h"
  9. /* Single message queue control structure */
  10. struct bcm_vk_msgq {
  11. u16 type; /* queue type */
  12. u16 num; /* queue number */
  13. u32 start; /* offset in BAR1 where the queue memory starts */
  14. u32 rd_idx; /* read idx */
  15. u32 wr_idx; /* write idx */
  16. u32 size; /*
  17. * size, which is in number of 16byte blocks,
  18. * to align with the message data structure.
  19. */
  20. u32 nxt; /*
  21. * nxt offset to the next msg queue struct.
  22. * This is to provide flexibity for alignment purposes.
  23. */
  24. /* Least significant 16 bits in below field hold doorbell register offset */
  25. #define DB_SHIFT 16
  26. u32 db_offset; /* queue doorbell register offset in BAR0 */
  27. u32 rsvd;
  28. };
  29. /*
  30. * Structure to record static info from the msgq sync. We keep local copy
  31. * for some of these variables for both performance + checking purpose.
  32. */
  33. struct bcm_vk_sync_qinfo {
  34. void __iomem *q_start;
  35. u32 q_size;
  36. u32 q_mask;
  37. u32 q_low;
  38. u32 q_db_offset;
  39. };
  40. #define VK_MSGQ_MAX_NR 4 /* Maximum number of message queues */
  41. /*
  42. * message block - basic unit in the message where a message's size is always
  43. * N x sizeof(basic_block)
  44. */
  45. struct vk_msg_blk {
  46. u8 function_id;
  47. #define VK_FID_TRANS_BUF 5
  48. #define VK_FID_SHUTDOWN 8
  49. #define VK_FID_INIT 9
  50. u8 size; /* size of the message in number of vk_msg_blk's */
  51. u16 trans_id; /* transport id, queue & msg_id */
  52. u32 context_id;
  53. #define VK_NEW_CTX 0
  54. u32 cmd;
  55. #define VK_CMD_PLANES_MASK 0x000f /* number of planes to up/download */
  56. #define VK_CMD_UPLOAD 0x0400 /* memory transfer to vk */
  57. #define VK_CMD_DOWNLOAD 0x0500 /* memory transfer from vk */
  58. #define VK_CMD_MASK 0x0f00 /* command mask */
  59. u32 arg;
  60. };
  61. /* vk_msg_blk is 16 bytes fixed */
  62. #define VK_MSGQ_BLK_SIZE (sizeof(struct vk_msg_blk))
  63. /* shift for fast division of basic msg blk size */
  64. #define VK_MSGQ_BLK_SZ_SHIFT 4
  65. /* use msg_id 0 for any simplex host2vk communication */
  66. #define VK_SIMPLEX_MSG_ID 0
  67. /* context per session opening of sysfs */
  68. struct bcm_vk_ctx {
  69. struct list_head node; /* use for linkage in Hash Table */
  70. unsigned int idx;
  71. bool in_use;
  72. pid_t pid;
  73. u32 hash_idx;
  74. u32 q_num; /* queue number used by the stream */
  75. struct miscdevice *miscdev;
  76. atomic_t pend_cnt; /* number of items pending to be read from host */
  77. atomic_t dma_cnt; /* any dma transaction outstanding */
  78. wait_queue_head_t rd_wq;
  79. };
  80. /* pid hash table entry */
  81. struct bcm_vk_ht_entry {
  82. struct list_head head;
  83. };
  84. #define VK_DMA_MAX_ADDRS 4 /* Max 4 DMA Addresses */
  85. /* structure for house keeping a single work entry */
  86. struct bcm_vk_wkent {
  87. struct list_head node; /* for linking purpose */
  88. struct bcm_vk_ctx *ctx;
  89. /* Store up to 4 dma pointers */
  90. struct bcm_vk_dma dma[VK_DMA_MAX_ADDRS];
  91. u32 to_h_blks; /* response */
  92. struct vk_msg_blk *to_h_msg;
  93. /*
  94. * put the to_v_msg at the end so that we could simply append to_v msg
  95. * to the end of the allocated block
  96. */
  97. u32 usr_msg_id;
  98. u32 to_v_blks;
  99. u32 seq_num;
  100. struct vk_msg_blk to_v_msg[];
  101. };
  102. /* queue stats counters */
  103. struct bcm_vk_qs_cnts {
  104. u32 cnt; /* general counter, used to limit output */
  105. u32 acc_sum;
  106. u32 max_occ; /* max during a sampling period */
  107. u32 max_abs; /* the abs max since reset */
  108. };
  109. /* control channel structure for either to_v or to_h communication */
  110. struct bcm_vk_msg_chan {
  111. u32 q_nr;
  112. /* Mutex to access msgq */
  113. struct mutex msgq_mutex;
  114. /* pointing to BAR locations */
  115. struct bcm_vk_msgq __iomem *msgq[VK_MSGQ_MAX_NR];
  116. /* Spinlock to access pending queue */
  117. spinlock_t pendq_lock;
  118. /* for temporary storing pending items, one for each queue */
  119. struct list_head pendq[VK_MSGQ_MAX_NR];
  120. /* static queue info from the sync */
  121. struct bcm_vk_sync_qinfo sync_qinfo[VK_MSGQ_MAX_NR];
  122. };
  123. /* totol number of message q allowed by the driver */
  124. #define VK_MSGQ_PER_CHAN_MAX 3
  125. #define VK_MSGQ_NUM_DEFAULT (VK_MSGQ_PER_CHAN_MAX - 1)
  126. /* total number of supported ctx, 32 ctx each for 5 components */
  127. #define VK_CMPT_CTX_MAX (32 * 5)
  128. /* hash table defines to store the opened FDs */
  129. #define VK_PID_HT_SHIFT_BIT 7 /* 128 */
  130. #define VK_PID_HT_SZ BIT(VK_PID_HT_SHIFT_BIT)
  131. /* The following are offsets of DDR info provided by the vk card */
  132. #define VK_BAR0_SEG_SIZE (4 * SZ_1K) /* segment size for BAR0 */
  133. /* shutdown types supported */
  134. #define VK_SHUTDOWN_PID 1
  135. #define VK_SHUTDOWN_GRACEFUL 2
  136. #endif