amdxdna_mailbox.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2022-2024, Advanced Micro Devices, Inc.
  4. */
  5. #ifndef _AIE2_MAILBOX_H_
  6. #define _AIE2_MAILBOX_H_
  7. struct mailbox;
  8. struct mailbox_channel;
  9. /*
  10. * xdna_mailbox_msg - message struct
  11. *
  12. * @opcode: opcode for firmware
  13. * @handle: handle used for the notify callback
  14. * @notify_cb: callback function to notify the sender when there is response
  15. * @send_data: pointing to sending data
  16. * @send_size: size of the sending data
  17. *
  18. * The mailbox will split the sending data in to multiple firmware message if
  19. * the size of the data is too big. This is transparent to the sender. The
  20. * sender will receive one notification.
  21. */
  22. struct xdna_mailbox_msg {
  23. u32 opcode;
  24. void *handle;
  25. int (*notify_cb)(void *handle, void __iomem *data, size_t size);
  26. u8 *send_data;
  27. size_t send_size;
  28. };
  29. /*
  30. * xdna_mailbox_res - mailbox hardware resource
  31. *
  32. * @ringbuf_base: ring buffer base address
  33. * @ringbuf_size: ring buffer size
  34. * @mbox_base: mailbox base address
  35. * @mbox_size: mailbox size
  36. */
  37. struct xdna_mailbox_res {
  38. void __iomem *ringbuf_base;
  39. size_t ringbuf_size;
  40. void __iomem *mbox_base;
  41. size_t mbox_size;
  42. const char *name;
  43. };
  44. /*
  45. * xdna_mailbox_chann_res - resources
  46. *
  47. * @rb_start_addr: ring buffer start address
  48. * @rb_size: ring buffer size
  49. * @mb_head_ptr_reg: mailbox head pointer register
  50. * @mb_tail_ptr_reg: mailbox tail pointer register
  51. */
  52. struct xdna_mailbox_chann_res {
  53. u32 rb_start_addr;
  54. u32 rb_size;
  55. u32 mb_head_ptr_reg;
  56. u32 mb_tail_ptr_reg;
  57. };
  58. /*
  59. * xdna_mailbox_create() -- create mailbox subsystem and initialize
  60. *
  61. * @ddev: device pointer
  62. * @res: SRAM and mailbox resources
  63. *
  64. * Return: If success, return a handle of mailbox subsystem.
  65. * Otherwise, return NULL pointer.
  66. */
  67. struct mailbox *xdnam_mailbox_create(struct drm_device *ddev,
  68. const struct xdna_mailbox_res *res);
  69. /*
  70. * xdna_mailbox_alloc_channel() -- alloc a mailbox channel
  71. *
  72. * @mb: mailbox handle
  73. */
  74. struct mailbox_channel *xdna_mailbox_alloc_channel(struct mailbox *mb);
  75. /*
  76. * xdna_mailbox_start_channel() -- start a mailbox channel instance
  77. *
  78. * @mb_chann: the handle return from xdna_mailbox_alloc_channel()
  79. * @x2i: host to firmware mailbox resources
  80. * @i2x: firmware to host mailbox resources
  81. * @xdna_mailbox_intr_reg: register addr of MSI-X interrupt
  82. * @mb_irq: Linux IRQ number associated with mailbox MSI-X interrupt vector index
  83. *
  84. * Return: If success, return a handle of mailbox channel. Otherwise, return NULL.
  85. */
  86. int
  87. xdna_mailbox_start_channel(struct mailbox_channel *mb_chann,
  88. const struct xdna_mailbox_chann_res *x2i,
  89. const struct xdna_mailbox_chann_res *i2x,
  90. u32 xdna_mailbox_intr_reg,
  91. int mb_irq);
  92. /*
  93. * xdna_mailbox_free_channel() -- free mailbox channel
  94. *
  95. * @mailbox_chann: the handle return from xdna_mailbox_create_channel()
  96. */
  97. void xdna_mailbox_free_channel(struct mailbox_channel *mailbox_chann);
  98. /*
  99. * xdna_mailbox_stop_channel() -- stop mailbox channel
  100. *
  101. * @mailbox_chann: the handle return from xdna_mailbox_create_channel()
  102. */
  103. void xdna_mailbox_stop_channel(struct mailbox_channel *mailbox_chann);
  104. /*
  105. * xdna_mailbox_send_msg() -- Send a message
  106. *
  107. * @mailbox_chann: Mailbox channel handle
  108. * @msg: message struct for message information
  109. * @tx_timeout: the timeout value for sending the message in ms.
  110. *
  111. * Return: If success return 0, otherwise, return error code
  112. */
  113. int xdna_mailbox_send_msg(struct mailbox_channel *mailbox_chann,
  114. const struct xdna_mailbox_msg *msg, u64 tx_timeout);
  115. #endif /* _AIE2_MAILBOX_ */