message-queue.rst 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .. SPDX-License-Identifier: GPL-2.0
  2. Message Queues
  3. ==============
  4. Message queue is a simple low-capacity IPC channel between two VMs. It is
  5. intended for sending small control and configuration messages. Each message
  6. queue is unidirectional, so a full-duplex IPC channel requires a pair of queues.
  7. Messages can be up to 240 bytes in length. Longer messages require a further
  8. protocol on top of the message queue messages themselves. For instance, communication
  9. with the resource manager adds a header field for sending longer messages via multiple
  10. message fragments.
  11. The diagram below shows how message queue works. A typical configuration involves
  12. 2 message queues. Message queue 1 allows VM_A to send messages to VM_B. Message
  13. queue 2 allows VM_B to send messages to VM_A.
  14. 1. VM_A sends a message of up to 240 bytes in length. It raises a hypercall
  15. with the message to inform the hypervisor to add the message to
  16. message queue 1's queue. The hypervisor copies memory into the internal
  17. message queue representation; the memory doesn't need to be shared between
  18. VM_A and VM_B.
  19. 2. Gunyah raises the corresponding interrupt for VM_B (Rx vIRQ) when any of
  20. these happens:
  21. a. gh_msgq_send() has PUSH flag. Queue is immediately flushed. This is the typical case.
  22. b. Explicility with gh_msgq_push command from VM_A.
  23. c. Message queue has reached a threshold depth.
  24. 3. VM_B calls gh_msgq_recv() and Gunyah copies message to requested buffer.
  25. 4. Gunyah buffers messages in the queue. If the queue became full when VM_A added a message,
  26. the return values for gh_msgq_send() include a flag that indicates the queue is full.
  27. Once VM_B receives the message and, thus, there is space in the queue, Gunyah
  28. will raise the Tx vIRQ on VM_A to indicate it can continue sending messages.
  29. For VM_B to send a message to VM_A, the process is identical, except that hypercalls
  30. reference message queue 2's capability ID. Each message queue has its own independent
  31. vIRQ: two TX message queues will have two vIRQs (and two capability IDs).
  32. ::
  33. +---------------+ +-----------------+ +---------------+
  34. | VM_A | |Gunyah hypervisor| | VM_B |
  35. | | | | | |
  36. | | | | | |
  37. | | Tx | | | |
  38. | |-------->| | Rx vIRQ | |
  39. |gh_msgq_send() | Tx vIRQ |Message queue 1 |-------->|gh_msgq_recv() |
  40. | |<------- | | | |
  41. | | | | | |
  42. | Message Queue | | | | Message Queue |
  43. | driver | | | | driver |
  44. | | | | | |
  45. | | | | | |
  46. | | | | Tx | |
  47. | | Rx vIRQ | |<--------| |
  48. |gh_msgq_recv() |<--------|Message queue 2 | Tx vIRQ |gh_msgq_send() |
  49. | | | |-------->| |
  50. | | | | | |
  51. | | | | | |
  52. +---------------+ +-----------------+ +---------------+
  53. Gunyah message queues are exposed as mailboxes. To create the mailbox, create
  54. a mbox_client and call `gh_msgq_init()`. On receipt of the RX_READY interrupt,
  55. all messages in the RX message queue are read and pushed via the `rx_callback`
  56. of the registered mbox_client.
  57. .. kernel-doc:: drivers/mailbox/gunyah-msgq.c
  58. :identifiers: gh_msgq_init