189634f99SSanyog Kale================= 289634f99SSanyog KaleSoundWire Locking 389634f99SSanyog Kale================= 489634f99SSanyog Kale 589634f99SSanyog KaleThis document explains locking mechanism of the SoundWire Bus. Bus uses 689634f99SSanyog Kalefollowing locks in order to avoid race conditions in Bus operations on 789634f99SSanyog Kaleshared resources. 889634f99SSanyog Kale 989634f99SSanyog Kale - Bus lock 1089634f99SSanyog Kale 1189634f99SSanyog Kale - Message lock 1289634f99SSanyog Kale 1389634f99SSanyog KaleBus lock 1489634f99SSanyog Kale======== 1589634f99SSanyog Kale 1689634f99SSanyog KaleSoundWire Bus lock is a mutex and is part of Bus data structure 1789634f99SSanyog Kale(sdw_bus) which is used for every Bus instance. This lock is used to 1889634f99SSanyog Kaleserialize each of the following operations(s) within SoundWire Bus instance. 1989634f99SSanyog Kale 2089634f99SSanyog Kale - Addition and removal of Slave(s), changing Slave status. 2189634f99SSanyog Kale 2289634f99SSanyog Kale - Prepare, Enable, Disable and De-prepare stream operations. 2389634f99SSanyog Kale 2489634f99SSanyog Kale - Access of Stream data structure. 2589634f99SSanyog Kale 2689634f99SSanyog KaleMessage lock 2789634f99SSanyog Kale============ 2889634f99SSanyog Kale 2989634f99SSanyog KaleSoundWire message transfer lock. This mutex is part of 3089634f99SSanyog KaleBus data structure (sdw_bus). This lock is used to serialize the message 3189634f99SSanyog Kaletransfers (read/write) within a SoundWire Bus instance. 3289634f99SSanyog Kale 3389634f99SSanyog KaleBelow examples show how locks are acquired. 3489634f99SSanyog Kale 3589634f99SSanyog KaleExample 1 3689634f99SSanyog Kale--------- 3789634f99SSanyog Kale 3889634f99SSanyog KaleMessage transfer. 3989634f99SSanyog Kale 4089634f99SSanyog Kale 1. For every message transfer 4189634f99SSanyog Kale 4289634f99SSanyog Kale a. Acquire Message lock. 4389634f99SSanyog Kale 4489634f99SSanyog Kale b. Transfer message (Read/Write) to Slave1 or broadcast message on 4589634f99SSanyog Kale Bus in case of bank switch. 4689634f99SSanyog Kale 47*be103884SMauro Carvalho Chehab c. Release Message lock 48*be103884SMauro Carvalho Chehab 49*be103884SMauro Carvalho Chehab :: 5089634f99SSanyog Kale 5189634f99SSanyog Kale +----------+ +---------+ 5289634f99SSanyog Kale | | | | 5389634f99SSanyog Kale | Bus | | Master | 5489634f99SSanyog Kale | | | Driver | 5589634f99SSanyog Kale | | | | 5689634f99SSanyog Kale +----+-----+ +----+----+ 5789634f99SSanyog Kale | | 5889634f99SSanyog Kale | bus->ops->xfer_msg() | 5989634f99SSanyog Kale <-------------------------------+ a. Acquire Message lock 6089634f99SSanyog Kale | | b. Transfer message 6189634f99SSanyog Kale | | 6289634f99SSanyog Kale +-------------------------------> c. Release Message lock 6389634f99SSanyog Kale | return success/error | d. Return success/error 6489634f99SSanyog Kale | | 6589634f99SSanyog Kale + + 6689634f99SSanyog Kale 6789634f99SSanyog KaleExample 2 6889634f99SSanyog Kale--------- 6989634f99SSanyog Kale 7089634f99SSanyog KalePrepare operation. 7189634f99SSanyog Kale 7289634f99SSanyog Kale 1. Acquire lock for Bus instance associated with Master 1. 7389634f99SSanyog Kale 7489634f99SSanyog Kale 2. For every message transfer in Prepare operation 7589634f99SSanyog Kale 7689634f99SSanyog Kale a. Acquire Message lock. 7789634f99SSanyog Kale 7889634f99SSanyog Kale b. Transfer message (Read/Write) to Slave1 or broadcast message on 7989634f99SSanyog Kale Bus in case of bank switch. 8089634f99SSanyog Kale 8189634f99SSanyog Kale c. Release Message lock. 8289634f99SSanyog Kale 8389634f99SSanyog Kale 3. Release lock for Bus instance associated with Master 1 :: 8489634f99SSanyog Kale 8589634f99SSanyog Kale +----------+ +---------+ 8689634f99SSanyog Kale | | | | 8789634f99SSanyog Kale | Bus | | Master | 8889634f99SSanyog Kale | | | Driver | 8989634f99SSanyog Kale | | | | 9089634f99SSanyog Kale +----+-----+ +----+----+ 9189634f99SSanyog Kale | | 9289634f99SSanyog Kale | sdw_prepare_stream() | 9389634f99SSanyog Kale <-------------------------------+ 1. Acquire bus lock 9489634f99SSanyog Kale | | 2. Perform stream prepare 9589634f99SSanyog Kale | | 9689634f99SSanyog Kale | | 9789634f99SSanyog Kale | bus->ops->xfer_msg() | 9889634f99SSanyog Kale <-------------------------------+ a. Acquire Message lock 9989634f99SSanyog Kale | | b. Transfer message 10089634f99SSanyog Kale | | 10189634f99SSanyog Kale +-------------------------------> c. Release Message lock 10289634f99SSanyog Kale | return success/error | d. Return success/error 10389634f99SSanyog Kale | | 10489634f99SSanyog Kale | | 10589634f99SSanyog Kale | return success/error | 3. Release bus lock 10689634f99SSanyog Kale +-------------------------------> 4. Return success/error 10789634f99SSanyog Kale | | 10889634f99SSanyog Kale + + 109