locking.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. =================
  2. SoundWire Locking
  3. =================
  4. This document explains locking mechanism of the SoundWire Bus. Bus uses
  5. following locks in order to avoid race conditions in Bus operations on
  6. shared resources.
  7. - Bus lock
  8. - Message lock
  9. Bus lock
  10. ========
  11. SoundWire Bus lock is a mutex and is part of Bus data structure
  12. (sdw_bus) which is used for every Bus instance. This lock is used to
  13. serialize each of the following operations(s) within SoundWire Bus instance.
  14. - Addition and removal of Slave(s), changing Slave status.
  15. - Prepare, Enable, Disable and De-prepare stream operations.
  16. - Access of Stream data structure.
  17. Message lock
  18. ============
  19. SoundWire message transfer lock. This mutex is part of
  20. Bus data structure (sdw_bus). This lock is used to serialize the message
  21. transfers (read/write) within a SoundWire Bus instance.
  22. Below examples show how locks are acquired.
  23. Example 1
  24. ---------
  25. Message transfer.
  26. 1. For every message transfer
  27. a. Acquire Message lock.
  28. b. Transfer message (Read/Write) to Slave1 or broadcast message on
  29. Bus in case of bank switch.
  30. c. Release Message lock ::
  31. +----------+ +---------+
  32. | | | |
  33. | Bus | | Master |
  34. | | | Driver |
  35. | | | |
  36. +----+-----+ +----+----+
  37. | |
  38. | bus->ops->xfer_msg() |
  39. <-------------------------------+ a. Acquire Message lock
  40. | | b. Transfer message
  41. | |
  42. +-------------------------------> c. Release Message lock
  43. | return success/error | d. Return success/error
  44. | |
  45. + +
  46. Example 2
  47. ---------
  48. Prepare operation.
  49. 1. Acquire lock for Bus instance associated with Master 1.
  50. 2. For every message transfer in Prepare operation
  51. a. Acquire Message lock.
  52. b. Transfer message (Read/Write) to Slave1 or broadcast message on
  53. Bus in case of bank switch.
  54. c. Release Message lock.
  55. 3. Release lock for Bus instance associated with Master 1 ::
  56. +----------+ +---------+
  57. | | | |
  58. | Bus | | Master |
  59. | | | Driver |
  60. | | | |
  61. +----+-----+ +----+----+
  62. | |
  63. | sdw_prepare_stream() |
  64. <-------------------------------+ 1. Acquire bus lock
  65. | | 2. Perform stream prepare
  66. | |
  67. | |
  68. | bus->ops->xfer_msg() |
  69. <-------------------------------+ a. Acquire Message lock
  70. | | b. Transfer message
  71. | |
  72. +-------------------------------> c. Release Message lock
  73. | return success/error | d. Return success/error
  74. | |
  75. | |
  76. | return success/error | 3. Release bus lock
  77. +-------------------------------> 4. Return success/error
  78. | |
  79. + +