Skip to content

Commit a5b7365

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: bus: add stream refcount
The notion of stream is by construction based on a multi-bus capability, to allow for aggregation of Peripheral devices or functions located on different segments. We currently count how many master_rt contexts are used by a stream, but we don't have the dual refcount of how many streams are allocated on a given bus. This refcount will be useful to check if BTP/BRA streams can be allocated. Note that the stream_refcount is modified in sdw_master_rt_alloc() and sdw_master_rt_free() which are both called with the bus_lock mutex held, so there's no need for refcount_ primitives for additional protection. Signed-off-by: Pierre-Louis Bossart <[email protected]> Reviewed-by: Rander Wang <[email protected]> Signed-off-by: Bard Liao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent fe46d2a commit a5b7365

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

drivers/soundwire/stream.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,8 @@ static struct sdw_master_runtime
11811181
m_rt->bus = bus;
11821182
m_rt->stream = stream;
11831183

1184+
bus->stream_refcount++;
1185+
11841186
return m_rt;
11851187
}
11861188

@@ -1217,6 +1219,7 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt,
12171219
struct sdw_stream_runtime *stream)
12181220
{
12191221
struct sdw_slave_runtime *s_rt, *_s_rt;
1222+
struct sdw_bus *bus = m_rt->bus;
12201223

12211224
list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) {
12221225
sdw_slave_port_free(s_rt->slave, stream);
@@ -1226,6 +1229,8 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt,
12261229
list_del(&m_rt->stream_node);
12271230
list_del(&m_rt->bus_node);
12281231
kfree(m_rt);
1232+
1233+
bus->stream_refcount--;
12291234
}
12301235

12311236
/**

include/linux/soundwire/sdw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ struct sdw_master_ops {
903903
* meaningful if multi_link is set. If set to 1, hardware-based
904904
* synchronization will be used even if a stream only uses a single
905905
* SoundWire segment.
906+
* @stream_refcount: number of streams currently using this bus
906907
*/
907908
struct sdw_bus {
908909
struct device *dev;
@@ -933,6 +934,7 @@ struct sdw_bus {
933934
u32 bank_switch_timeout;
934935
bool multi_link;
935936
int hw_sync_min_links;
937+
int stream_refcount;
936938
};
937939

938940
int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,

0 commit comments

Comments
 (0)