Skip to content

Commit

Permalink
firmware: arm_scmi: Use {get,put}_unaligned_le{32,64} accessors
Browse files Browse the repository at this point in the history
Instead of type-casting the {tx,rx}.buf all over the place while
accessing them to read/write __le{32,64} from/to the firmware, let's
use the existing {get,put}_unaligned_le{32,64} accessors to hide all
the type cast ugliness.

Suggested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
  • Loading branch information
Sudeep Holla committed Aug 12, 2019
1 parent 2bc06ff commit aa90ac4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion drivers/firmware/arm_scmi/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle,
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(id);
put_unaligned_le32(id, t->tx.buf);

ret = scmi_do_xfer(handle, t);
if (!ret)
Expand Down
12 changes: 4 additions & 8 deletions drivers/firmware/arm_scmi/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int scmi_clock_attributes_get(const struct scmi_handle *handle,
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(clk_id);
put_unaligned_le32(clk_id, t->tx.buf);
attr = t->rx.buf;

ret = scmi_do_xfer(handle, t);
Expand Down Expand Up @@ -204,15 +204,11 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value)
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(clk_id);
put_unaligned_le32(clk_id, t->tx.buf);

ret = scmi_do_xfer(handle, t);
if (!ret) {
__le32 *pval = t->rx.buf;

*value = le32_to_cpu(*pval);
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
}
if (!ret)
*value = get_unaligned_le64(t->rx.buf);

scmi_xfer_put(handle, t);
return ret;
Expand Down
2 changes: 2 additions & 0 deletions drivers/firmware/arm_scmi/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <linux/scmi_protocol.h>
#include <linux/types.h>

#include <asm/unaligned.h>

#define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0)
#define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16)
#define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
Expand Down
8 changes: 4 additions & 4 deletions drivers/firmware/arm_scmi/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(domain);
put_unaligned_le32(domain, t->tx.buf);
attr = t->rx.buf;

ret = scmi_do_xfer(handle, t);
Expand Down Expand Up @@ -284,7 +284,7 @@ static int scmi_perf_limits_get(const struct scmi_handle *handle, u32 domain,
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(domain);
put_unaligned_le32(domain, t->tx.buf);

ret = scmi_do_xfer(handle, t);
if (!ret) {
Expand Down Expand Up @@ -333,11 +333,11 @@ static int scmi_perf_level_get(const struct scmi_handle *handle, u32 domain,
return ret;

t->hdr.poll_completion = poll;
*(__le32 *)t->tx.buf = cpu_to_le32(domain);
put_unaligned_le32(domain, t->tx.buf);

ret = scmi_do_xfer(handle, t);
if (!ret)
*level = le32_to_cpu(*(__le32 *)t->rx.buf);
*level = get_unaligned_le32(t->rx.buf);

scmi_xfer_put(handle, t);
return ret;
Expand Down
6 changes: 3 additions & 3 deletions drivers/firmware/arm_scmi/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ scmi_power_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(domain);
put_unaligned_le32(domain, t->tx.buf);
attr = t->rx.buf;

ret = scmi_do_xfer(handle, t);
Expand Down Expand Up @@ -147,11 +147,11 @@ scmi_power_state_get(const struct scmi_handle *handle, u32 domain, u32 *state)
if (ret)
return ret;

*(__le32 *)t->tx.buf = cpu_to_le32(domain);
put_unaligned_le32(domain, t->tx.buf);

ret = scmi_do_xfer(handle, t);
if (!ret)
*state = le32_to_cpu(*(__le32 *)t->rx.buf);
*state = get_unaligned_le32(t->rx.buf);

scmi_xfer_put(handle, t);
return ret;
Expand Down
17 changes: 6 additions & 11 deletions drivers/firmware/arm_scmi/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,

do {
/* Set the number of sensors to be skipped/already read */
*(__le32 *)t->tx.buf = cpu_to_le32(desc_index);
put_unaligned_le32(desc_index, t->tx.buf);

ret = scmi_do_xfer(handle, t);
if (ret)
Expand Down Expand Up @@ -217,7 +217,6 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
u32 sensor_id, u64 *value)
{
int ret;
__le32 *pval;
struct scmi_xfer *t;
struct scmi_msg_sensor_reading_get *sensor;
struct sensors_info *si = handle->sensor_priv;
Expand All @@ -229,24 +228,20 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
if (ret)
return ret;

pval = t->rx.buf;
sensor = t->tx.buf;
sensor->id = cpu_to_le32(sensor_id);

if (s->async) {
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
ret = scmi_do_xfer_with_response(handle, t);
if (!ret) {
*value = le32_to_cpu(*(pval + 1));
*value |= (u64)le32_to_cpu(*(pval + 2)) << 32;
}
if (!ret)
*value = get_unaligned_le64((void *)
((__le32 *)t->rx.buf + 1));
} else {
sensor->flags = cpu_to_le32(0);
ret = scmi_do_xfer(handle, t);
if (!ret) {
*value = le32_to_cpu(*pval);
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
}
if (!ret)
*value = get_unaligned_le64(t->rx.buf);
}

scmi_xfer_put(handle, t);
Expand Down

0 comments on commit aa90ac4

Please sign in to comment.