From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Andy Gross <andy.gross@linaro.org>,
Mark Brown <broonie@kernel.org>,
linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org,
David Brown <david.brown@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Patrick Lai <plai@codeaurora.org>,
Banajit Goswami <bgoswami@codeaurora.org>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-soc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, sboyd@codeaurora.org
Subject: Re: [RESEND PATCH v2 09/15] ASoC: qcom: qdsp6: Add support to Q6CORE
Date: Wed, 3 Jan 2018 16:27:03 +0000 [thread overview]
Message-ID: <e624aa61-7fe1-51f7-bec3-c7ccfe9d0bc5@linaro.org> (raw)
In-Reply-To: <20180102221520.GQ478@tuxbook>
Thanks for the review.
On 02/01/18 22:15, Bjorn Andersson wrote:
> On Thu 14 Dec 09:33 PST 2017, srinivas.kandagatla@linaro.org wrote:
>
>> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>>
>> This patch adds support to core apr service, which is used to query
>> status of other static and dynamic services on the dsp.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>> ---
>> sound/soc/qcom/Kconfig | 5 +
>> sound/soc/qcom/qdsp6/Makefile | 1 +
>> sound/soc/qcom/qdsp6/q6core.c | 227 ++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 233 insertions(+)
>> create mode 100644 sound/soc/qcom/qdsp6/q6core.c
>>
>> +obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
>> diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
>> new file mode 100644
>> index 000000000000..d4e2dbc62489
>> +struct q6core {
>> + struct apr_device *adev;
>> + wait_queue_head_t wait;
>> + uint32_t avcs_state;
>> + int resp_received;
>
> bool
yep.
>
>> + uint32_t num_services;
>> + struct avcs_svc_info *svcs_info;
>> +};
>> +static int core_callback(struct apr_device *adev, struct apr_client_data *data)
>> +{
>> + struct q6core *core = dev_get_drvdata(&adev->dev);
>> + uint32_t *payload;
>> +
>> + switch (data->opcode) {
>> + case AVCS_GET_VERSIONS_RSP:
>> + payload = data->payload;
>> + core->num_services = payload[1];
>
> Describe the payload in a struct (with flexible array member for the
> svcs_info list).
sure!
>
>> +
>> + if (!core->svcs_info)
>> + core->svcs_info = kcalloc(core->num_services,
>> + sizeof(*core->svcs_info),
>> + GFP_ATOMIC);
>> + if (!core->svcs_info)
>> + return -ENOMEM;
>> +
>
> If we receive this twice with different num_services for some reason the
> memcpy might trash the heap.
>
> But as this is the get_version response and we're only going to issue
> that once you should remove the check for !core->svcs_info above.
>
yes, I agree
> And don't forget to free svcs_info once you have added your services.
yep.
>
>> + /* svc info is after 8 bytes */
>> + memcpy(core->svcs_info, payload + 2,
>> + core->num_services * sizeof(*core->svcs_info));
>> +
>> + core->resp_received = 1;
>> + wake_up(&core->wait);
>> +
>> + break;
>> + case AVCS_CMDRSP_ADSP_EVENT_GET_STATE:
>> + payload = data->payload;
>> + core->avcs_state = payload[0];
>> +
>> + core->resp_received = 1;
>> + wake_up(&core->wait);
>> + break;
>> + default:
>> + dev_err(&adev->dev, "Message id from adsp core svc: 0x%x\n",
>> + data->opcode);
>> + break;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +void q6core_add_service(struct device *dev, uint32_t svc_id, uint32_t version)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < ARRAY_SIZE(static_services); i++) {
>> + if (static_services[i].svc_id == svc_id) {
>> + static_services[i].svc_version = version;
>> + apr_add_device(dev->parent, &static_services[i]);
>> + dev_info(dev,
>
> Please don't spam the logs, dev_dbg() should be enough. And as
> apr_add_device() returns you can find the devices registered in /sys
sure!
>
>> + "Adding SVC: %s: id 0x%x API Ver 0x%x:0x%x\n",
>> + static_services[i].name, svc_id,
>> + APR_SVC_MAJOR_VERSION(version),
>> + APR_SVC_MINOR_VERSION(version));
>> + }
>> + }
>> +}
>> +
>> +static void q6core_add_static_services(struct q6core *core)
>
> The name of this function is deceiving, it doesn't really add the static
> services. It adds devices for the services that we've been informed
> exists, by the other side - using the static list of services.
>
> Per the comment on a previous patch I don't think the "name" in
> apr_device_id provides any real value and in this case if forces you to
> perform a lookup using this table.
>
> If you drop the name, you can loop over the list of service ids returned
> from the remote and just register them with a hard coded domain id
> (based on apr instance?) and client_id. You don't need the lookup table.
>
yes, correct.
>> +{
>> + int i;
>> + struct apr_device *adev = core->adev;
>> + struct avcs_svc_info *svcs_info = core->svcs_info;
>> +
>> + for (i = 0; i < core->num_services; i++)
>> + q6core_add_service(&adev->dev, svcs_info[i].service_id,
>> + svcs_info[i].version);
>> +}
>> +
>> +static int q6core_get_svc_versions(struct q6core *core)
>> +{
>> + struct apr_device *adev = core->adev;
>> + struct apr_hdr hdr = {0};
>> + int rc;
>> +
>> + hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
>> + APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
>> + hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, 0);
>> + hdr.opcode = AVCS_GET_VERSIONS;
>> +
>> + rc = apr_send_pkt(adev, (uint32_t *)&hdr);
>> + if (rc < 0)
>> + return rc;
>> +
>> + rc = wait_event_timeout(core->wait, (core->resp_received == 1),
>> + msecs_to_jiffies(Q6_READY_TIMEOUT_MS));
>
> The wait and resp_received could favourably be expressed as a completion
> instead, as all we care about is that this happened once.
will give that a try.
>
>> + if (rc > 0 && core->resp_received) {
>> + core->resp_received = 0;
>> + return 0;
>> + }
>
> It wasn't obvious at first sight that this is the success case and the
> return rc below was the error case...
>
okay, I can add some comments here to help.
>> +
>> + return rc;
>
> And this will actually be 0 if core->resp_received has not become 1 at
> the timeout.
>
yep, will return an error value here.
>> +}
>> +
>> +static bool q6core_is_adsp_ready(struct q6core *core)
>> +{
>> + struct apr_device *adev = core->adev;
>> + struct apr_hdr hdr = {0};
>> + int rc;
>> +
>> + hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
>> + APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
>> + hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE, 0);
>> + hdr.opcode = AVCS_CMD_ADSP_EVENT_GET_STATE;
>> +
>> + rc = apr_send_pkt(adev, (uint32_t *)&hdr);
>> + if (rc < 0)
>> + return false;
>> +
>> + rc = wait_event_timeout(core->wait, (core->resp_received == 1),
>> + msecs_to_jiffies(Q6_READY_TIMEOUT_MS));
>
> I think this too would be nicer to describe with a completion.
>
> Currently it's possible to ask is the dsp is ready, time out and ask
> again, just to receive the first ack and continue. The service request
> sleep might then wake up on this previous ack.
>
> If you describe this by two different completions for the two waits you
> avoid any such race conditions occurring.
>
sure i will make a note of it when I try completions.
>> + if (rc > 0 && core->resp_received) {
>> + core->resp_received = 0;
>> + if (core->avcs_state == 0x1)
>> + return true;
>> + }
>> +
>> + return false;
>> +}
>> +
>> +static int q6core_probe(struct apr_device *adev)
>> +{
>> + struct q6core *core;
>> + unsigned long timeout = jiffies +
>> + msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
>> + int ret = 0;
>> +
>> + core = devm_kzalloc(&adev->dev, sizeof(*core), GFP_KERNEL);
>> + if (!core)
>> + return -ENOMEM;
>> +
>> + dev_set_drvdata(&adev->dev, core);
>> +
>> + core->adev = adev;
>> + init_waitqueue_head(&core->wait);
>> +
>> + do {
>> + if (!q6core_is_adsp_ready(core)) {
>> + dev_info(&adev->dev, "ADSP Audio isn't ready\n");
>> + } else {
>> + dev_info(&adev->dev, "ADSP Audio is ready\n");
>> +
>> + ret = q6core_get_svc_versions(core);
>> + if (!ret)
>> + q6core_add_static_services(core);
>> +
>> + break;
>> + }
>> + } while (time_after(timeout, jiffies));
>
> This would be much better rewritten as:
>
> for (;;) {
> if (q6core_is_adsp_ready(core))
> break;
>
> if (time_after(timeout, jiffies))
> return -ETIMEDOUT;
> }
>
> ret = q6core_get_svc_versions(core);
> if (ret)
> return ret;
>
> q6core_add_static_services(core);
>
Sure.
>> +
>> + return ret;
>> +}
>> +
>> +
>> +static struct apr_driver qcom_q6core_driver = {
>> + .probe = q6core_probe,
>> + .remove = q6core_exit,
>> + .callback = core_callback,
>> + .id_table = core_id,
>> + .driver = {
>> + .name = "qcom-q6core",
>> + },
>
> Indentation.
Sure.
next prev parent reply other threads:[~2018-01-03 16:27 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-14 17:33 [RESEND PATCH v2 00/15] ASoC: qcom: Add support to QDSP6 based audio srinivas.kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 01/15] dt-bindings: soc: qcom: Add bindings for APR bus srinivas.kandagatla
[not found] ` <20171214173402.19074-2-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-12-16 17:27 ` Rob Herring
2017-12-18 9:50 ` Srinivas Kandagatla
2018-01-03 0:35 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 02/15] soc: qcom: add support to APR bus driver srinivas.kandagatla
[not found] ` <20171214173402.19074-3-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-01 23:29 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 03/15] ASoC: qcom: qdsp6: Add common qdsp6 helper functions srinivas.kandagatla
2018-01-02 0:19 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 04/15] ASoC: qcom: qdsp6: Add support to Q6AFE srinivas.kandagatla
2018-01-02 0:45 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 05/15] ASoC: qcom: qdsp6: Add support to Q6ADM srinivas.kandagatla
[not found] ` <20171214173402.19074-6-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-02 1:50 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 06/15] ASoC: qcom: qdsp6: Add support to Q6ASM srinivas.kandagatla
[not found] ` <20171214173402.19074-7-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-02 4:43 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 08/15] ASoC: qcom: q6asm: add support to audio stream apis srinivas.kandagatla
2018-01-02 20:08 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
2018-01-13 8:42 ` Rohit Kumar
2017-12-14 17:33 ` [RESEND PATCH v2 09/15] ASoC: qcom: qdsp6: Add support to Q6CORE srinivas.kandagatla
2018-01-02 22:15 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla [this message]
2018-02-07 12:15 ` [alsa-devel] " Rohit Kumar
2017-12-14 17:33 ` [RESEND PATCH v2 10/15] ASoC: qcom: qdsp6: Add support to q6routing driver srinivas.kandagatla
2018-01-02 23:00 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 11/15] ASoC: qcom: qdsp6: Add support to q6afe dai driver srinivas.kandagatla
[not found] ` <20171214173402.19074-12-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-02 23:28 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla
2018-02-07 11:34 ` Rohit Kumar
2018-02-07 11:40 ` [alsa-devel] " Srinivas Kandagatla
2017-12-14 17:33 ` [RESEND PATCH v2 12/15] ASoC: qcom: qdsp6: Add support to q6asm " srinivas.kandagatla
2018-01-03 0:03 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla
2018-01-13 8:45 ` [alsa-devel] " Rohit Kumar
[not found] ` <20171214173402.19074-1-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-12-14 17:33 ` [RESEND PATCH v2 07/15] ASoC: qcom: q6asm: Add support to memory map and unmap srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2018-01-02 5:48 ` Bjorn Andersson
2018-01-03 16:26 ` Srinivas Kandagatla
[not found] ` <4d1d17df-71a4-2896-29c1-9d033a2f3711-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03 19:39 ` Bjorn Andersson
2017-12-14 17:34 ` [RESEND PATCH v2 13/15] dt-bindings: sound: qcom: Add devicetree bindings for apq8096 srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2017-12-16 17:44 ` Rob Herring
2017-12-18 9:49 ` Srinivas Kandagatla
2018-01-03 0:28 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla
[not found] ` <787ecdc5-66d8-23ee-7136-2a8759c86536-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03 19:49 ` Bjorn Andersson
2017-12-14 17:34 ` [RESEND PATCH v2 14/15] ASoC: qcom: apq8096: Add db820c machine driver srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2018-01-03 0:16 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla
2018-01-03 20:04 ` Bjorn Andersson
2018-01-03 17:20 ` Stephen Boyd
2018-01-03 18:36 ` Srinivas Kandagatla
2018-01-03 19:41 ` Stephen Boyd
2018-01-04 9:25 ` Srinivas Kandagatla
2018-01-04 12:02 ` Mark Brown
2018-01-04 13:44 ` Srinivas Kandagatla
2018-01-04 14:03 ` Mark Brown
2017-12-14 17:34 ` [RESEND PATCH v2 15/15] arm64: dts: msm8996: db820c: Add sound card support srinivas.kandagatla
[not found] ` <20171214173402.19074-16-srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2018-01-03 0:22 ` Bjorn Andersson
2018-01-03 16:27 ` Srinivas Kandagatla
2018-01-03 20:01 ` Bjorn Andersson
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=e624aa61-7fe1-51f7-bec3-c7ccfe9d0bc5@linaro.org \
--to=srinivas.kandagatla@linaro.org \
--cc=alsa-devel@alsa-project.org \
--cc=andy.gross@linaro.org \
--cc=bgoswami@codeaurora.org \
--cc=bjorn.andersson@linaro.org \
--cc=broonie@kernel.org \
--cc=david.brown@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-soc@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=perex@perex.cz \
--cc=plai@codeaurora.org \
--cc=robh+dt@kernel.org \
--cc=sboyd@codeaurora.org \
--cc=tiwai@suse.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).