From: Bjorn Andersson <bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Andy Gross <andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Stephen Boyd <sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
jilai wang <jilaiw-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Subject: Re: [Patch v4 5/8] firmware: qcom: scm: Convert to streaming DMA APIS
Date: Wed, 11 May 2016 13:34:44 -0700 [thread overview]
Message-ID: <20160511203444.GX1256@tuxbot> (raw)
In-Reply-To: <1462976158-26016-6-git-send-email-andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
On Wed 11 May 07:15 PDT 2016, Andy Gross wrote:
> This patch converts the Qualcomm SCM driver to use the streaming DMA APIs
> for communication buffers.
>
Some style issues in qcom_scm_call(), but functionality wise I think
this looks good (with the open question on packing of rsp and rps->buf).
> Signed-off-by: Andy Gross <andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> drivers/firmware/qcom_scm-32.c | 152 +++++++++++++----------------------------
> drivers/firmware/qcom_scm.c | 6 +-
> drivers/firmware/qcom_scm.h | 10 +--
> 3 files changed, 58 insertions(+), 110 deletions(-)
>
> diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c
[..]
> /**
> * qcom_scm_call() - Send an SCM command
> - * @svc_id: service identifier
> - * @cmd_id: command identifier
> - * @cmd_buf: command buffer
> - * @cmd_len: length of the command buffer
> - * @resp_buf: response buffer
> - * @resp_len: length of the response buffer
> + * @dev: struct device
> + * @svc_id: service identifier
> + * @cmd_id: command identifier
> + * @cmd_buf: command buffer
> + * @cmd_len: length of the command buffer
> + * @resp_buf: response buffer
> + * @resp_len: length of the response buffer
Leaving the indentation alone clarifies that your changes is just the
addition of "dev".
> *
> * Sends a command to the SCM and waits for the command to finish processing.
> *
> @@ -247,42 +172,60 @@ static void qcom_scm_inv_range(unsigned long start, unsigned long end)
> * and response buffers is taken care of by qcom_scm_call; however, callers are
> * responsible for any other cached buffers passed over to the secure world.
> */
> -static int qcom_scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf,
> - size_t cmd_len, void *resp_buf, size_t resp_len)
> +static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,
> + const void *cmd_buf, size_t cmd_len, void *resp_buf,
> + size_t resp_len)
> {
> int ret;
> struct qcom_scm_command *cmd;
> struct qcom_scm_response *rsp;
> - unsigned long start, end;
> + size_t alloc_len = sizeof(*cmd) + sizeof(struct qcom_scm_response) +
> + cmd_len + resp_len;
This would be cleaner if written:
size_t alloc_len = sizeof(*cmd) + cmd_len + sizeof(*rsp) + resp_len;
> + dma_addr_t cmd_phys;
> + u32 offset;
>
> - cmd = alloc_qcom_scm_command(cmd_len, resp_len);
> + cmd = kzalloc(PAGE_ALIGN(alloc_len), GFP_KERNEL);
> if (!cmd)
> return -ENOMEM;
>
> + cmd->len = cpu_to_le32(alloc_len);
> + offset = offsetof(struct qcom_scm_command, buf);
> + cmd->buf_offset = cpu_to_le32(offset);
Sure this is the offset of the buf in *cmd, but based on the rest of my
comments below I would have dropped the offset variable and just used
sizeof(*cmd).
> + cmd->resp_hdr_offset = cpu_to_le32(offset + cmd_len);
But this would be more intuitive as sizeof(*cmd) + cmd_len;
> +
> cmd->id = cpu_to_le32((svc_id << 10) | cmd_id);
> if (cmd_buf)
> memcpy(qcom_scm_get_command_buffer(cmd), cmd_buf, cmd_len);
Somewhat unrelated, but we should probably just inline this helper in
favour of writing "cmd->buf".
>
> + cmd_phys = dma_map_single(dev, cmd, alloc_len, DMA_TO_DEVICE);
Unless there's a guarantee that the resp buffer is packed onto the
response we should probably map the entire page(s).
> + if (dma_mapping_error(dev, cmd_phys)) {
> + kfree(cmd);
> + return -ENOMEM;
> + }
> +
> mutex_lock(&qcom_scm_lock);
> - ret = __qcom_scm_call(cmd);
> + ret = smc(cmd_phys);
> + if (ret < 0)
> + ret = qcom_scm_remap_error(ret);
> mutex_unlock(&qcom_scm_lock);
> if (ret)
> goto out;
>
> rsp = qcom_scm_command_to_response(cmd);
> - start = (unsigned long)rsp;
>
> do {
> - qcom_scm_inv_range(start, start + sizeof(*rsp));
> + dma_sync_single_for_cpu(dev, cmd_phys + cmd_len + offset,
Same here, would be easier to read if it was
cmd_phys + sizeof(*cmd) + cmd_len;
Or even:
cmd_phys + le32_to_cpu(cmd->resp_hdr_offset);
> + sizeof(*rsp), DMA_FROM_DEVICE);
> } while (!rsp->is_complete);
>
> - end = (unsigned long)qcom_scm_get_response_buffer(rsp) + resp_len;
> - qcom_scm_inv_range(start, end);
> -
> - if (resp_buf)
> + if (resp_buf) {
> + dma_sync_single_for_cpu(dev, cmd_phys + alloc_len - resp_len,
Do we know that the firmware always set
rsp->buf_offset = sizeof(*rsp)
Would be clearer (and safe from this assumption) if you have it as:
cmd_phys + le32_to_cpu(cmd->resp_hdr_offset) + le32_to_cpu(rsp->buf_offset);
> + resp_len, DMA_FROM_DEVICE);
> memcpy(resp_buf, qcom_scm_get_response_buffer(rsp), resp_len);
And as we just calculated that offset, we can drop the
qcom_scm_get_response_buffer() single use helper.
> + }
> out:
> - free_qcom_scm_command(cmd);
> + dma_unmap_single(dev, cmd_phys, alloc_len, DMA_TO_DEVICE);
> + kfree(cmd);
> return ret;
> }
>
The rest looks good.
Regards,
Bjorn
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-05-11 20:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 14:15 [Patch v4 0/8] Qualcomm SCM Rework Andy Gross
2016-05-11 14:15 ` [Patch v4 1/8] dt/bindings: firmware: Add Qualcomm SCM binding Andy Gross
2016-05-11 19:49 ` Bjorn Andersson
2016-05-12 7:00 ` Stanimir Varbanov
2016-05-11 14:15 ` [Patch v4 2/8] firmware: qcom: scm: Convert SCM to platform driver Andy Gross
2016-05-11 19:53 ` Bjorn Andersson
2016-05-11 14:15 ` [Patch v4 3/8] firmware: qcom: scm: Use atomic SCM for cold boot Andy Gross
2016-05-11 19:56 ` Bjorn Andersson
2016-05-11 14:15 ` [Patch v4 5/8] firmware: qcom: scm: Convert to streaming DMA APIS Andy Gross
[not found] ` <1462976158-26016-6-git-send-email-andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-05-11 20:34 ` Bjorn Andersson [this message]
[not found] ` <1462976158-26016-1-git-send-email-andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-05-11 14:15 ` [Patch v4 4/8] firmware: qcom: scm: Generalize shared error map Andy Gross
2016-05-11 14:15 ` [Patch v4 6/8] firmware: qcom: scm: Add support for ARM64 SoCs Andy Gross
[not found] ` <1462976158-26016-7-git-send-email-andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-05-11 21:21 ` Bjorn Andersson
2016-05-11 14:15 ` [Patch v4 7/8] dts: qcom: apq8084: Add SCM firmware node Andy Gross
2016-05-11 14:15 ` [Patch v4 8/8] arm64: dts: msm8916: " Andy Gross
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=20160511203444.GX1256@tuxbot \
--to=bjorn.andersson-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
--cc=andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=jilaiw-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
/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).