Skip to content

Commit

Permalink
soundwire: bus: add stream refcount
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
plbossart committed Dec 18, 2023
1 parent e1fe5a3 commit 9aa94e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/soundwire/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,8 @@ static struct sdw_master_runtime
m_rt->bus = bus;
m_rt->stream = stream;

bus->stream_refcount++;

return m_rt;
}

Expand Down Expand Up @@ -1216,6 +1218,7 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt,
struct sdw_stream_runtime *stream)
{
struct sdw_slave_runtime *s_rt, *_s_rt;
struct sdw_bus *bus = m_rt->bus;

list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) {
sdw_slave_port_free(s_rt->slave, stream);
Expand All @@ -1225,6 +1228,8 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt,
list_del(&m_rt->stream_node);
list_del(&m_rt->bus_node);
kfree(m_rt);

bus->stream_refcount--;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions include/linux/soundwire/sdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ struct sdw_master_ops {
* meaningful if multi_link is set. If set to 1, hardware-based
* synchronization will be used even if a stream only uses a single
* SoundWire segment.
* @stream_refcount: number of streams currently using this bus
*/
struct sdw_bus {
struct device *dev;
Expand Down Expand Up @@ -931,6 +932,7 @@ struct sdw_bus {
u32 bank_switch_timeout;
bool multi_link;
int hw_sync_min_links;
int stream_refcount;
};

int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,
Expand Down

0 comments on commit 9aa94e7

Please sign in to comment.