From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
Jonathan Corbet <corbet@lwn.net>,
tiwai@suse.de, gregkh@linuxfoundation.org,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
linux-kernel@vger.kernel.org,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
vkoul@kernel.org, broonie@kernel.org,
srinivas.kandagatla@linaro.org, jank@cadence.com,
slawomir.blauciak@intel.com,
Sanyog Kale <sanyog.r.kale@intel.com>,
Bard liao <yung-chuan.liao@linux.intel.com>,
Rander Wang <rander.wang@linux.intel.com>
Subject: [alsa-devel] [PATCH v2 16/19] soundwire: stream: update state machine and add state checks
Date: Wed, 6 Nov 2019 13:22:20 -0600 [thread overview]
Message-ID: <20191106192223.6003-17-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20191106192223.6003-1-pierre-louis.bossart@linux.intel.com>
The state machine and notes don't accurately explain or allow
transitions from STREAM_DEPREPARED and STREAM_DISABLED.
Add more explanations and allow for more transitions as a result of a
trigger_stop(), trigger_suspend() and prepare(), depending on the
ALSA/ASoC layer behavior defined by the INFO_RESUME and INFO_PAUSE
flags.
Also add basic checks to help debug inconsistent states and illegal
state machine transitions.
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
Documentation/driver-api/soundwire/stream.rst | 63 +++++++++++++------
drivers/soundwire/stream.c | 38 +++++++++++
2 files changed, 83 insertions(+), 18 deletions(-)
diff --git a/Documentation/driver-api/soundwire/stream.rst b/Documentation/driver-api/soundwire/stream.rst
index 5351bd2f34a8..9b7418ff8d59 100644
--- a/Documentation/driver-api/soundwire/stream.rst
+++ b/Documentation/driver-api/soundwire/stream.rst
@@ -156,22 +156,27 @@ Below shows the SoundWire stream states and state transition diagram. ::
+-----------+ +------------+ +----------+ +----------+
| ALLOCATED +---->| CONFIGURED +---->| PREPARED +---->| ENABLED |
| STATE | | STATE | | STATE | | STATE |
- +-----------+ +------------+ +----------+ +----+-----+
- ^
- |
- |
- v
- +----------+ +------------+ +----+-----+
+ +-----------+ +------------+ +---+--+---+ +----+-----+
+ ^ ^ ^
+ | | |
+ __| |___________ |
+ | | |
+ v | v
+ +----------+ +-----+------+ +-+--+-----+
| RELEASED |<----------+ DEPREPARED |<-------+ DISABLED |
| STATE | | STATE | | STATE |
+----------+ +------------+ +----------+
-NOTE: State transition between prepare and deprepare is supported in Spec
-but not in the software (subsystem)
+NOTE: State transitions between ``SDW_STREAM_ENABLED`` and
+``SDW_STREAM_DISABLED`` are only relevant when then INFO_PAUSE flag is
+supported at the ALSA/ASoC level. Likewise the transition between
+``SDW_DISABLED_STATE`` and ``SDW_PREPARED_STATE`` depends on the
+INFO_RESUME flag.
-NOTE2: Stream state transition checks need to be handled by caller
-framework, for example ALSA/ASoC. No checks for stream transition exist in
-SoundWire subsystem.
+NOTE2: The framework implements basic state transition checks, but
+does not e.g. check if a transition from DISABLED to ENABLED is valid
+on a specific platform. Such tests need to be added at the ALSA/ASoC
+level.
Stream State Operations
-----------------------
@@ -246,6 +251,9 @@ SDW_STREAM_PREPARED
Prepare state of stream. Operations performed before entering in this state:
+ (0) Steps 1 and 2 are omitted in the case of a resume operation,
+ where the bus bandwidth is known.
+
(1) Bus parameters such as bandwidth, frame shape, clock frequency,
are computed based on current stream as well as already active
stream(s) on Bus. Re-computation is required to accommodate current
@@ -270,13 +278,15 @@ Prepare state of stream. Operations performed before entering in this state:
After all above operations are successful, stream state is set to
``SDW_STREAM_PREPARED``.
-Bus implements below API for PREPARE state which needs to be called once per
-stream. From ASoC DPCM framework, this stream state is linked to
-.prepare() operation.
+Bus implements below API for PREPARE state which needs to be called
+once per stream. From ASoC DPCM framework, this stream state is linked
+to .prepare() operation. Since the .trigger() operations may not
+follow the .prepare(), a direct transitions from
+``SDW_STREAM_PREPARED`` to ``SDW_STREAM_DEPREPARED`` is allowed.
.. code-block:: c
- int sdw_prepare_stream(struct sdw_stream_runtime * stream);
+ int sdw_prepare_stream(struct sdw_stream_runtime * stream, bool resume);
SDW_STREAM_ENABLED
@@ -332,6 +342,14 @@ Bus implements below API for DISABLED state which needs to be called once
per stream. From ASoC DPCM framework, this stream state is linked to
.trigger() stop operation.
+When the INFO_PAUSE flag is supported, a direct transition to
+``SDW_STREAM_ENABLED`` is allowed.
+
+For resume operations where ASoC will use the .prepare() callback, the
+stream can transition from ``SDW_STREAM_DISABLED`` to
+``SDW_STREAM_PREPARED``, with all required settings restored but
+without updating the bandwidth and bit allocation.
+
.. code-block:: c
int sdw_disable_stream(struct sdw_stream_runtime * stream);
@@ -353,9 +371,18 @@ state:
After all above operations are successful, stream state is set to
``SDW_STREAM_DEPREPARED``.
-Bus implements below API for DEPREPARED state which needs to be called once
-per stream. From ASoC DPCM framework, this stream state is linked to
-.trigger() stop operation.
+Bus implements below API for DEPREPARED state which needs to be called
+once per stream. ALSA/ASoC do not have a concept of 'deprepare', and
+the mapping from this stream state to ALSA/ASoC operation may be
+implementation specific.
+
+When the INFO_PAUSE flag is supported, the stream state is linked to
+the .hw_free() operation - the stream is not deprepared on a
+TRIGGER_STOP.
+
+Other implementations may transition to the ``SDW_STREAM_DEPREPARED``
+state on TRIGGER_STOP, should they require a transition through the
+``SDW_STREAM_PREPARED`` state.
.. code-block:: c
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index e69f94a8c3a8..0a074d445b8d 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1553,10 +1553,21 @@ int sdw_prepare_stream(struct sdw_stream_runtime *stream)
sdw_acquire_bus_lock(stream);
+ if (stream->state != SDW_STREAM_CONFIGURED &&
+ stream->state != SDW_STREAM_DEPREPARED &&
+ stream->state != SDW_STREAM_DISABLED) {
+ pr_err("%s: %s: inconsistent state state %d\n",
+ __func__, stream->name, stream->state);
+ ret = -EINVAL;
+ goto state_err;
+ }
+
ret = _sdw_prepare_stream(stream);
+
if (ret < 0)
pr_err("Prepare for stream:%s failed: %d\n", stream->name, ret);
+state_err:
sdw_release_bus_lock(stream);
return ret;
}
@@ -1621,10 +1632,19 @@ int sdw_enable_stream(struct sdw_stream_runtime *stream)
sdw_acquire_bus_lock(stream);
+ if (stream->state != SDW_STREAM_PREPARED &&
+ stream->state != SDW_STREAM_DISABLED) {
+ pr_err("%s: %s: inconsistent state state %d\n",
+ __func__, stream->name, stream->state);
+ ret = -EINVAL;
+ goto state_err;
+ }
+
ret = _sdw_enable_stream(stream);
if (ret < 0)
pr_err("Enable for stream:%s failed: %d\n", stream->name, ret);
+state_err:
sdw_release_bus_lock(stream);
return ret;
}
@@ -1697,10 +1717,18 @@ int sdw_disable_stream(struct sdw_stream_runtime *stream)
sdw_acquire_bus_lock(stream);
+ if (stream->state != SDW_STREAM_ENABLED) {
+ pr_err("%s: %s: inconsistent state state %d\n",
+ __func__, stream->name, stream->state);
+ ret = -EINVAL;
+ goto state_err;
+ }
+
ret = _sdw_disable_stream(stream);
if (ret < 0)
pr_err("Disable for stream:%s failed: %d\n", stream->name, ret);
+state_err:
sdw_release_bus_lock(stream);
return ret;
}
@@ -1755,10 +1783,20 @@ int sdw_deprepare_stream(struct sdw_stream_runtime *stream)
}
sdw_acquire_bus_lock(stream);
+
+ if (stream->state != SDW_STREAM_PREPARED &&
+ stream->state != SDW_STREAM_DISABLED) {
+ pr_err("%s: %s: inconsistent state state %d\n",
+ __func__, stream->name, stream->state);
+ ret = -EINVAL;
+ goto state_err;
+ }
+
ret = _sdw_deprepare_stream(stream);
if (ret < 0)
pr_err("De-prepare for stream:%d failed: %d\n", ret, ret);
+state_err:
sdw_release_bus_lock(stream);
return ret;
}
--
2.20.1
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
next prev parent reply other threads:[~2019-11-06 20:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-06 19:22 [alsa-devel] [PATCH v2 00/19] soundwire: code hardening and suspend-resume support Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 01/19] soundwire: intel/cadence: fix timeouts in MSI mode Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 02/19] soundwire: fix race between driver probe and update_status callback Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 03/19] soundwire: bus: add PM/no-PM versions of read/write functions Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 04/19] soundwire: bus: write Slave Device Number without runtime_pm Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 05/19] soundwire: intel: add helpers for link power down and shim wake Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 06/19] soundwire: intel: Add basic power management support Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 07/19] soundwire: intel: add pm_runtime support Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 08/19] soundwire: intel: reset pm_runtime status during system resume Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 09/19] soundwire: bus: add helper to reset Slave status to UNATTACHED Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 10/19] soundwire: intel: call helper to reset Slave states on resume Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 11/19] soundwire: bus: check first if Slaves become UNATTACHED Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 12/19] soundwire: add enumeration_complete signaling Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 13/19] soundwire: bus: add initialization_complete signaling Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 14/19] soundwire: intel: disable pm_runtime when removing a master Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 15/19] soundwire: bus: disable pm_runtime in sdw_slave_delete Pierre-Louis Bossart
2019-11-06 19:22 ` Pierre-Louis Bossart [this message]
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 17/19] soundwire: stream: only prepare stream when it is configured Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 18/19] soundwire: stream: do not update parameters during DISABLED-PREPARED transition Pierre-Louis Bossart
2019-11-06 19:22 ` [alsa-devel] [PATCH v2 19/19] soundwire: intel: reinitialize IP+DSP in .prepare() Pierre-Louis Bossart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191106192223.6003-17-pierre-louis.bossart@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=jank@cadence.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rander.wang@linux.intel.com \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sanyog.r.kale@intel.com \
--cc=slawomir.blauciak@intel.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=tiwai@suse.de \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).