Commit 354b2e36 authored by Sudeep Holla's avatar Sudeep Holla

firmware: arm_scmi: improve code readability using bitfield accessor macros

By using FIELD_{FIT,GET,PREP} and GENMASK macro accessors we can avoid
some clumpsy custom shifting and masking macros and also improve the
code better readability.
Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
parent 60cc43fc
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Copyright (C) 2018 ARM Ltd. * Copyright (C) 2018 ARM Ltd.
*/ */
#include <linux/bitfield.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -14,10 +15,10 @@ ...@@ -14,10 +15,10 @@
#include <linux/scmi_protocol.h> #include <linux/scmi_protocol.h>
#include <linux/types.h> #include <linux/types.h>
#define PROTOCOL_REV_MINOR_BITS 16 #define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0)
#define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1) #define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16)
#define PROTOCOL_REV_MAJOR(x) ((x) >> PROTOCOL_REV_MINOR_BITS) #define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
#define PROTOCOL_REV_MINOR(x) ((x) & PROTOCOL_REV_MINOR_MASK) #define PROTOCOL_REV_MINOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x)))
#define MAX_PROTOCOLS_IMP 16 #define MAX_PROTOCOLS_IMP 16
#define MAX_OPPS 16 #define MAX_OPPS 16
......
...@@ -29,16 +29,12 @@ ...@@ -29,16 +29,12 @@
#include "common.h" #include "common.h"
#define MSG_ID_SHIFT 0 #define MSG_ID_MASK GENMASK(7, 0)
#define MSG_ID_MASK 0xff #define MSG_TYPE_MASK GENMASK(9, 8)
#define MSG_TYPE_SHIFT 8 #define MSG_PROTOCOL_ID_MASK GENMASK(17, 10)
#define MSG_TYPE_MASK 0x3 #define MSG_TOKEN_ID_MASK GENMASK(27, 18)
#define MSG_PROTOCOL_ID_SHIFT 10 #define MSG_XTRACT_TOKEN(hdr) FIELD_GET(MSG_TOKEN_ID_MASK, (hdr))
#define MSG_PROTOCOL_ID_MASK 0xff #define MSG_TOKEN_MAX (MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1)
#define MSG_TOKEN_ID_SHIFT 18
#define MSG_TOKEN_ID_MASK 0x3ff
#define MSG_XTRACT_TOKEN(header) \
(((header) >> MSG_TOKEN_ID_SHIFT) & MSG_TOKEN_ID_MASK)
enum scmi_error_codes { enum scmi_error_codes {
SCMI_SUCCESS = 0, /* Success */ SCMI_SUCCESS = 0, /* Success */
...@@ -255,9 +251,9 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m) ...@@ -255,9 +251,9 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)
*/ */
static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr) static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
{ {
return ((hdr->id & MSG_ID_MASK) << MSG_ID_SHIFT) | return FIELD_PREP(MSG_ID_MASK, hdr->id) |
((hdr->seq & MSG_TOKEN_ID_MASK) << MSG_TOKEN_ID_SHIFT) | FIELD_PREP(MSG_TOKEN_ID_MASK, hdr->seq) |
((hdr->protocol_id & MSG_PROTOCOL_ID_MASK) << MSG_PROTOCOL_ID_SHIFT); FIELD_PREP(MSG_PROTOCOL_ID_MASK, hdr->protocol_id);
} }
/** /**
...@@ -621,9 +617,9 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo) ...@@ -621,9 +617,9 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)
struct scmi_xfers_info *info = &sinfo->minfo; struct scmi_xfers_info *info = &sinfo->minfo;
/* Pre-allocated messages, no more than what hdr.seq can support */ /* Pre-allocated messages, no more than what hdr.seq can support */
if (WARN_ON(desc->max_msg >= (MSG_TOKEN_ID_MASK + 1))) { if (WARN_ON(desc->max_msg >= MSG_TOKEN_MAX)) {
dev_err(dev, "Maximum message of %d exceeds supported %d\n", dev_err(dev, "Maximum message of %d exceeds supported %ld\n",
desc->max_msg, MSG_TOKEN_ID_MASK + 1); desc->max_msg, MSG_TOKEN_MAX);
return -EINVAL; return -EINVAL;
} }
...@@ -840,7 +836,8 @@ static int scmi_probe(struct platform_device *pdev) ...@@ -840,7 +836,8 @@ static int scmi_probe(struct platform_device *pdev)
if (of_property_read_u32(child, "reg", &prot_id)) if (of_property_read_u32(child, "reg", &prot_id))
continue; continue;
prot_id &= MSG_PROTOCOL_ID_MASK; if (!FIELD_FIT(MSG_PROTOCOL_ID_MASK, prot_id))
dev_err(dev, "Out of range protocol %d\n", prot_id);
if (!scmi_is_protocol_implemented(handle, prot_id)) { if (!scmi_is_protocol_implemented(handle, prot_id)) {
dev_err(dev, "SCMI protocol %d not implemented\n", dev_err(dev, "SCMI protocol %d not implemented\n",
......
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