mailbox.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #ifndef _MAILBOX_H
  7. #define _MAILBOX_H
  8. /**
  9. * A mailbox is a hardware mechanism for transferring small fixed-size messages
  10. * and/or notifications between the CPU on which U-Boot runs and some other
  11. * device such as an auxiliary CPU running firmware or a hardware module.
  12. *
  13. * Data transfer is optional; a mailbox may consist solely of a notification
  14. * mechanism. When data transfer is implemented, it is via HW registers or
  15. * FIFOs, rather than via RAM-based buffers. The mailbox API generally
  16. * implements any communication protocol enforced solely by hardware, and
  17. * leaves any higher-level protocols to other layers.
  18. *
  19. * A mailbox channel is a bi-directional mechanism that can send a message or
  20. * notification to a single specific remote entity, and receive messages or
  21. * notifications from that entity. The size, content, and format of such
  22. * messages is defined by the mailbox implementation, or the remote entity with
  23. * which it communicates; there is no general standard at this API level.
  24. *
  25. * A driver that implements UCLASS_MAILBOX is a mailbox provider. A provider
  26. * will often implement multiple separate mailbox channels, since the hardware
  27. * it manages often has this capability. mailbox-uclass.h describes the
  28. * interface which mailbox providers must implement.
  29. *
  30. * Mailbox consumers/clients generate and send, or receive and process,
  31. * messages. This header file describes the API used by clients.
  32. */
  33. struct udevice;
  34. /**
  35. * struct mbox_chan - A handle to a single mailbox channel.
  36. *
  37. * Clients provide storage for channels. The content of the channel structure
  38. * is managed solely by the mailbox API and mailbox drivers. A mailbox channel
  39. * is initialized by "get"ing the mailbox. The channel struct is passed to all
  40. * other mailbox APIs to identify which mailbox to operate upon.
  41. *
  42. * @dev: The device which implements the mailbox.
  43. * @id: The mailbox channel ID within the provider.
  44. *
  45. * Currently, the mailbox API assumes that a single integer ID is enough to
  46. * identify and configure any mailbox channel for any mailbox provider. If this
  47. * assumption becomes invalid in the future, the struct could be expanded to
  48. * either (a) add more fields to allow mailbox providers to store additional
  49. * information, or (b) replace the id field with an opaque pointer, which the
  50. * provider would dynamically allocated during its .of_xlate op, and process
  51. * during is .request op. This may require the addition of an extra op to clean
  52. * up the allocation.
  53. */
  54. struct mbox_chan {
  55. struct udevice *dev;
  56. /*
  57. * Written by of_xlate. We assume a single id is enough for now. In the
  58. * future, we might add more fields here.
  59. */
  60. unsigned long id;
  61. };
  62. /**
  63. * mbox_get_by_index - Get/request a mailbox by integer index
  64. *
  65. * This looks up and requests a mailbox channel. The index is relative to the
  66. * client device; each device is assumed to have n mailbox channels associated
  67. * with it somehow, and this function finds and requests one of them. The
  68. * mapping of client device channel indices to provider channels may be via
  69. * device-tree properties, board-provided mapping tables, or some other
  70. * mechanism.
  71. *
  72. * @dev: The client device.
  73. * @index: The index of the mailbox channel to request, within the
  74. * client's list of channels.
  75. * @chan A pointer to a channel object to initialize.
  76. * @return 0 if OK, or a negative error code.
  77. */
  78. int mbox_get_by_index(struct udevice *dev, int index, struct mbox_chan *chan);
  79. /**
  80. * mbox_get_by_name - Get/request a mailbox by name
  81. *
  82. * This looks up and requests a mailbox channel. The name is relative to the
  83. * client device; each device is assumed to have n mailbox channels associated
  84. * with it somehow, and this function finds and requests one of them. The
  85. * mapping of client device channel names to provider channels may be via
  86. * device-tree properties, board-provided mapping tables, or some other
  87. * mechanism.
  88. *
  89. * @dev: The client device.
  90. * @name: The name of the mailbox channel to request, within the client's
  91. * list of channels.
  92. * @chan A pointer to a channel object to initialize.
  93. * @return 0 if OK, or a negative error code.
  94. */
  95. int mbox_get_by_name(struct udevice *dev, const char *name,
  96. struct mbox_chan *chan);
  97. /**
  98. * mbox_free - Free a previously requested mailbox channel.
  99. *
  100. * @chan: A channel object that was previously successfully requested by
  101. * calling mbox_get_by_*().
  102. * @return 0 if OK, or a negative error code.
  103. */
  104. int mbox_free(struct mbox_chan *chan);
  105. /**
  106. * mbox_send - Send a message over a mailbox channel
  107. *
  108. * This function will send a message to the remote entity. It may return before
  109. * the remote entity has received and/or processed the message.
  110. *
  111. * @chan: A channel object that was previously successfully requested by
  112. * calling mbox_get_by_*().
  113. * @data: A pointer to the message to transfer. The format and size of
  114. * the memory region pointed at by @data is determined by the
  115. * mailbox provider. Providers that solely transfer notifications
  116. * will ignore this parameter.
  117. * @return 0 if OK, or a negative error code.
  118. */
  119. int mbox_send(struct mbox_chan *chan, const void *data);
  120. /**
  121. * mbox_recv - Receive any available message from a mailbox channel
  122. *
  123. * This function will wait (up to the specified @timeout_us) for a message to
  124. * be sent by the remote entity, and write the content of any such message
  125. * into a caller-provided buffer.
  126. *
  127. * @chan: A channel object that was previously successfully requested by
  128. * calling mbox_get_by_*().
  129. * @data: A pointer to the buffer to receive the message. The format and
  130. * size of the memory region pointed at by @data is determined by
  131. * the mailbox provider. Providers that solely transfer
  132. * notifications will ignore this parameter.
  133. * @timeout_us: The maximum time to wait for a message to be available, in
  134. * micro-seconds. A value of 0 does not wait at all.
  135. * @return 0 if OK, -ENODATA if no message was available, or a negative error
  136. * code.
  137. */
  138. int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us);
  139. #endif