0001 =================
0002 SoundWire Locking
0003 =================
0004
0005 This document explains locking mechanism of the SoundWire Bus. Bus uses
0006 following locks in order to avoid race conditions in Bus operations on
0007 shared resources.
0008
0009 - Bus lock
0010
0011 - Message lock
0012
0013 Bus lock
0014 ========
0015
0016 SoundWire Bus lock is a mutex and is part of Bus data structure
0017 (sdw_bus) which is used for every Bus instance. This lock is used to
0018 serialize each of the following operations(s) within SoundWire Bus instance.
0019
0020 - Addition and removal of Slave(s), changing Slave status.
0021
0022 - Prepare, Enable, Disable and De-prepare stream operations.
0023
0024 - Access of Stream data structure.
0025
0026 Message lock
0027 ============
0028
0029 SoundWire message transfer lock. This mutex is part of
0030 Bus data structure (sdw_bus). This lock is used to serialize the message
0031 transfers (read/write) within a SoundWire Bus instance.
0032
0033 Below examples show how locks are acquired.
0034
0035 Example 1
0036 ---------
0037
0038 Message transfer.
0039
0040 1. For every message transfer
0041
0042 a. Acquire Message lock.
0043
0044 b. Transfer message (Read/Write) to Slave1 or broadcast message on
0045 Bus in case of bank switch.
0046
0047 c. Release Message lock
0048
0049 ::
0050
0051 +----------+ +---------+
0052 | | | |
0053 | Bus | | Master |
0054 | | | Driver |
0055 | | | |
0056 +----+-----+ +----+----+
0057 | |
0058 | bus->ops->xfer_msg() |
0059 <-------------------------------+ a. Acquire Message lock
0060 | | b. Transfer message
0061 | |
0062 +-------------------------------> c. Release Message lock
0063 | return success/error | d. Return success/error
0064 | |
0065 + +
0066
0067 Example 2
0068 ---------
0069
0070 Prepare operation.
0071
0072 1. Acquire lock for Bus instance associated with Master 1.
0073
0074 2. For every message transfer in Prepare operation
0075
0076 a. Acquire Message lock.
0077
0078 b. Transfer message (Read/Write) to Slave1 or broadcast message on
0079 Bus in case of bank switch.
0080
0081 c. Release Message lock.
0082
0083 3. Release lock for Bus instance associated with Master 1 ::
0084
0085 +----------+ +---------+
0086 | | | |
0087 | Bus | | Master |
0088 | | | Driver |
0089 | | | |
0090 +----+-----+ +----+----+
0091 | |
0092 | sdw_prepare_stream() |
0093 <-------------------------------+ 1. Acquire bus lock
0094 | | 2. Perform stream prepare
0095 | |
0096 | |
0097 | bus->ops->xfer_msg() |
0098 <-------------------------------+ a. Acquire Message lock
0099 | | b. Transfer message
0100 | |
0101 +-------------------------------> c. Release Message lock
0102 | return success/error | d. Return success/error
0103 | |
0104 | |
0105 | return success/error | 3. Release bus lock
0106 +-------------------------------> 4. Return success/error
0107 | |
0108 + +