Commit 7279db92 authored by Stephen Boyd's avatar Stephen Boyd Committed by Kumar Gala

ARM: qcom: Fix SCM interface for big-endian kernels

The secure environment only runs in little-endian mode, so any
buffers shared with the secure environment should have their
contents converted to little-endian. We also mark such elements
with __le32 to allow sparse to catch such problems.
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarKumar Gala <galak@codeaurora.org>
parent 65b4ab65
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
int scm_set_boot_addr(u32 addr, int flags) int scm_set_boot_addr(u32 addr, int flags)
{ {
struct { struct {
unsigned int flags; __le32 flags;
u32 addr; __le32 addr;
} cmd; } cmd;
cmd.addr = addr; cmd.addr = cpu_to_le32(addr);
cmd.flags = flags; cmd.flags = cpu_to_le32(flags);
return scm_call(SCM_SVC_BOOT, SCM_BOOT_ADDR, return scm_call(SCM_SVC_BOOT, SCM_BOOT_ADDR,
&cmd, sizeof(cmd), NULL, 0); &cmd, sizeof(cmd), NULL, 0);
} }
......
...@@ -61,11 +61,11 @@ static DEFINE_MUTEX(scm_lock); ...@@ -61,11 +61,11 @@ static DEFINE_MUTEX(scm_lock);
* to access the buffers in a safe manner. * to access the buffers in a safe manner.
*/ */
struct scm_command { struct scm_command {
u32 len; __le32 len;
u32 buf_offset; __le32 buf_offset;
u32 resp_hdr_offset; __le32 resp_hdr_offset;
u32 id; __le32 id;
u32 buf[0]; __le32 buf[0];
}; };
/** /**
...@@ -75,9 +75,9 @@ struct scm_command { ...@@ -75,9 +75,9 @@ struct scm_command {
* @is_complete: indicates if the command has finished processing * @is_complete: indicates if the command has finished processing
*/ */
struct scm_response { struct scm_response {
u32 len; __le32 len;
u32 buf_offset; __le32 buf_offset;
u32 is_complete; __le32 is_complete;
}; };
/** /**
...@@ -95,12 +95,14 @@ static struct scm_command *alloc_scm_command(size_t cmd_size, size_t resp_size) ...@@ -95,12 +95,14 @@ static struct scm_command *alloc_scm_command(size_t cmd_size, size_t resp_size)
struct scm_command *cmd; struct scm_command *cmd;
size_t len = sizeof(*cmd) + sizeof(struct scm_response) + cmd_size + size_t len = sizeof(*cmd) + sizeof(struct scm_response) + cmd_size +
resp_size; resp_size;
u32 offset;
cmd = kzalloc(PAGE_ALIGN(len), GFP_KERNEL); cmd = kzalloc(PAGE_ALIGN(len), GFP_KERNEL);
if (cmd) { if (cmd) {
cmd->len = len; cmd->len = cpu_to_le32(len);
cmd->buf_offset = offsetof(struct scm_command, buf); offset = offsetof(struct scm_command, buf);
cmd->resp_hdr_offset = cmd->buf_offset + cmd_size; cmd->buf_offset = cpu_to_le32(offset);
cmd->resp_hdr_offset = cpu_to_le32(offset + cmd_size);
} }
return cmd; return cmd;
} }
...@@ -125,7 +127,7 @@ static inline void free_scm_command(struct scm_command *cmd) ...@@ -125,7 +127,7 @@ static inline void free_scm_command(struct scm_command *cmd)
static inline struct scm_response *scm_command_to_response( static inline struct scm_response *scm_command_to_response(
const struct scm_command *cmd) const struct scm_command *cmd)
{ {
return (void *)cmd + cmd->resp_hdr_offset; return (void *)cmd + le32_to_cpu(cmd->resp_hdr_offset);
} }
/** /**
...@@ -147,7 +149,7 @@ static inline void *scm_get_command_buffer(const struct scm_command *cmd) ...@@ -147,7 +149,7 @@ static inline void *scm_get_command_buffer(const struct scm_command *cmd)
*/ */
static inline void *scm_get_response_buffer(const struct scm_response *rsp) static inline void *scm_get_response_buffer(const struct scm_response *rsp)
{ {
return (void *)rsp + rsp->buf_offset; return (void *)rsp + le32_to_cpu(rsp->buf_offset);
} }
static int scm_remap_error(int err) static int scm_remap_error(int err)
...@@ -259,7 +261,7 @@ int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len, ...@@ -259,7 +261,7 @@ int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len,
if (!cmd) if (!cmd)
return -ENOMEM; return -ENOMEM;
cmd->id = (svc_id << 10) | cmd_id; cmd->id = cpu_to_le32((svc_id << 10) | cmd_id);
if (cmd_buf) if (cmd_buf)
memcpy(scm_get_command_buffer(cmd), cmd_buf, cmd_len); memcpy(scm_get_command_buffer(cmd), cmd_buf, cmd_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment