RE: [Patch v3 5/8] firmware: qcom: scm: Convert to streaming DMA APIS
Hi, > This patch converts the Qualcomm SCM driver to use the streaming DMA > APIs for communication buffers. > > Signed-off-by: Andy Gross> --- Reviewed-by: sricha...@codeaurora.org Regards, Sricharan > 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 index 4388d13..3e71aec 100644 > --- a/drivers/firmware/qcom_scm-32.c > +++ b/drivers/firmware/qcom_scm-32.c > @@ -23,8 +23,7 @@ > #include > #include > #include > - > -#include > +#include > > #include "qcom_scm.h" > > @@ -97,44 +96,6 @@ struct qcom_scm_response { }; > > /** > - * alloc_qcom_scm_command() - Allocate an SCM command > - * @cmd_size: size of the command buffer > - * @resp_size: size of the response buffer > - * > - * Allocate an SCM command, including enough room for the command > - * and response headers as well as the command and response buffers. > - * > - * Returns a valid _scm_command on success or %NULL if the > allocation fails. > - */ > -static struct qcom_scm_command *alloc_qcom_scm_command(size_t > cmd_size, size_t resp_size) -{ > - struct qcom_scm_command *cmd; > - size_t len = sizeof(*cmd) + sizeof(struct qcom_scm_response) + > cmd_size + > - resp_size; > - u32 offset; > - > - cmd = kzalloc(PAGE_ALIGN(len), GFP_KERNEL); > - if (cmd) { > - cmd->len = cpu_to_le32(len); > - offset = offsetof(struct qcom_scm_command, buf); > - cmd->buf_offset = cpu_to_le32(offset); > - cmd->resp_hdr_offset = cpu_to_le32(offset + cmd_size); > - } > - return cmd; > -} > - > -/** > - * free_qcom_scm_command() - Free an SCM command > - * @cmd: command to free > - * > - * Free an SCM command. > - */ > -static inline void free_qcom_scm_command(struct qcom_scm_command > *cmd) -{ > - kfree(cmd); > -} > - > -/** > * qcom_scm_command_to_response() - Get a pointer to a > qcom_scm_response > * @cmd: command > * > @@ -168,7 +129,7 @@ static inline void > *qcom_scm_get_response_buffer(const struct qcom_scm_response > return (void *)rsp + le32_to_cpu(rsp->buf_offset); } > > -static u32 smc(u32 cmd_addr) > +static u32 smc(dma_addr_t cmd_addr) > { > int context_id; > register u32 r0 asm("r0") = 1; > @@ -192,51 +153,15 @@ static u32 smc(u32 cmd_addr) > return r0; > } > > -static int __qcom_scm_call(const struct qcom_scm_command *cmd) -{ > - int ret; > - u32 cmd_addr = virt_to_phys(cmd); > - > - /* > - * Flush the command buffer so that the secure world sees > - * the correct data. > - */ > - secure_flush_area(cmd, cmd->len); > - > - ret = smc(cmd_addr); > - if (ret < 0) > - ret = qcom_scm_remap_error(ret); > - > - return ret; > -} > - > -static void qcom_scm_inv_range(unsigned long start, unsigned long end) -{ > - u32 cacheline_size, ctr; > - > - asm volatile("mrc p15, 0, %0, c0, c0, 1" : "=r" (ctr)); > - cacheline_size = 4 << ((ctr >> 16) & 0xf); > - > - start = round_down(start, cacheline_size); > - end = round_up(end, cacheline_size); > - outer_inv_range(start, end); > - while (start < end) { > - asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start) > - : "memory"); > - start += cacheline_size; > - } > - dsb(); > - isb(); > -} > - > /** > * 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 > * > * 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 =
RE: [Patch v3 5/8] firmware: qcom: scm: Convert to streaming DMA APIS
Hi, > This patch converts the Qualcomm SCM driver to use the streaming DMA > APIs for communication buffers. > > Signed-off-by: Andy Gross > --- Reviewed-by: sricha...@codeaurora.org Regards, Sricharan > 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 index 4388d13..3e71aec 100644 > --- a/drivers/firmware/qcom_scm-32.c > +++ b/drivers/firmware/qcom_scm-32.c > @@ -23,8 +23,7 @@ > #include > #include > #include > - > -#include > +#include > > #include "qcom_scm.h" > > @@ -97,44 +96,6 @@ struct qcom_scm_response { }; > > /** > - * alloc_qcom_scm_command() - Allocate an SCM command > - * @cmd_size: size of the command buffer > - * @resp_size: size of the response buffer > - * > - * Allocate an SCM command, including enough room for the command > - * and response headers as well as the command and response buffers. > - * > - * Returns a valid _scm_command on success or %NULL if the > allocation fails. > - */ > -static struct qcom_scm_command *alloc_qcom_scm_command(size_t > cmd_size, size_t resp_size) -{ > - struct qcom_scm_command *cmd; > - size_t len = sizeof(*cmd) + sizeof(struct qcom_scm_response) + > cmd_size + > - resp_size; > - u32 offset; > - > - cmd = kzalloc(PAGE_ALIGN(len), GFP_KERNEL); > - if (cmd) { > - cmd->len = cpu_to_le32(len); > - offset = offsetof(struct qcom_scm_command, buf); > - cmd->buf_offset = cpu_to_le32(offset); > - cmd->resp_hdr_offset = cpu_to_le32(offset + cmd_size); > - } > - return cmd; > -} > - > -/** > - * free_qcom_scm_command() - Free an SCM command > - * @cmd: command to free > - * > - * Free an SCM command. > - */ > -static inline void free_qcom_scm_command(struct qcom_scm_command > *cmd) -{ > - kfree(cmd); > -} > - > -/** > * qcom_scm_command_to_response() - Get a pointer to a > qcom_scm_response > * @cmd: command > * > @@ -168,7 +129,7 @@ static inline void > *qcom_scm_get_response_buffer(const struct qcom_scm_response > return (void *)rsp + le32_to_cpu(rsp->buf_offset); } > > -static u32 smc(u32 cmd_addr) > +static u32 smc(dma_addr_t cmd_addr) > { > int context_id; > register u32 r0 asm("r0") = 1; > @@ -192,51 +153,15 @@ static u32 smc(u32 cmd_addr) > return r0; > } > > -static int __qcom_scm_call(const struct qcom_scm_command *cmd) -{ > - int ret; > - u32 cmd_addr = virt_to_phys(cmd); > - > - /* > - * Flush the command buffer so that the secure world sees > - * the correct data. > - */ > - secure_flush_area(cmd, cmd->len); > - > - ret = smc(cmd_addr); > - if (ret < 0) > - ret = qcom_scm_remap_error(ret); > - > - return ret; > -} > - > -static void qcom_scm_inv_range(unsigned long start, unsigned long end) -{ > - u32 cacheline_size, ctr; > - > - asm volatile("mrc p15, 0, %0, c0, c0, 1" : "=r" (ctr)); > - cacheline_size = 4 << ((ctr >> 16) & 0xf); > - > - start = round_down(start, cacheline_size); > - end = round_up(end, cacheline_size); > - outer_inv_range(start, end); > - while (start < end) { > - asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start) > - : "memory"); > - start += cacheline_size; > - } > - dsb(); > - isb(); > -} > - > /** > * 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 > * > * 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) +