From patchwork Wed May 9 17:07:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 135315 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5223lji; Wed, 9 May 2018 10:12:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrttQ2YMwPmePG7S07tYJOP6W2ykwSu2jZzCAozAte4cdf3ktVNgr+wx09CrF1G6X1mm6qm X-Received: by 2002:a65:6182:: with SMTP id c2-v6mr2273674pgv.219.1525885966756; Wed, 09 May 2018 10:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525885966; cv=none; d=google.com; s=arc-20160816; b=MCit/2H0RU2jtNlgSm9wcngkd96kpOxZmCHP2SP4rEhN1uk5KH4xF8P9JQNJqtW38c qRYm4nApqCbxlIcSKbjzvlMhchoZYXtF5Tv1Qjegs9vzIbGWx7c1Qaddv2r+OW2hW2ZJ QpqkXKMFwdoYvyNf0btkIc+D5Kbw1PVk0RzaKTWY/SIUT7rRO/46rJhCbIpvQyutN3/K X2zm4HUQ/4YoEgzhwPobDB70lgZAxe4e5Xwue995ETULkRnPz9iprIjiFecSNcRT8Q2h 21ncrrMXMtQ1Wum1zcF4Myya6Onojvym5htDEVSaZ4CsD9IsMAt9rYziTiFPPD14cN1j /rGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=oFcLmpB358l0WHExLhDAI32xSRPa0eEgmaVppMxr+5M=; b=UL0wP61Us2I7GEv5o9K5SplCbta6ZqmO+30NHwvUcXwI8MEVJUgLjgNrmW+iJRTWEK F74fxvMmOHBgiwpSJadiwrRIUtNSXRINQI/KWlWQAfb99CC2TgaxYQZpIbUG005WJ6s/ ZXW+9zA/1LEpcZUIQLLsmnD6V0y2Subd4XtrYXz7AGztaS+qokTeBoydqTIB6dbDMTy1 2zSNGVUz/Nl9XIE3FCRdYqLryK5MmgLi9kuzjH2WV/cJQm9sfkHS/4aP1y7Do4Rv1dBO 5ZUDALOZDmB1pjwEuzmvi3jPxnljpfBj7RXAED6Vv4RT2TKE2/a5CqoGHwb2QweDNp+6 KOBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j33-v6si16858745pld.151.2018.05.09.10.12.46; Wed, 09 May 2018 10:12:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965690AbeEIRMp (ORCPT + 10 others); Wed, 9 May 2018 13:12:45 -0400 Received: from foss.arm.com ([217.140.101.70]:47264 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965594AbeEIRMp (ORCPT ); Wed, 9 May 2018 13:12:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 04E9515B2; Wed, 9 May 2018 10:12:45 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A99D3F592; Wed, 9 May 2018 10:12:43 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, Jonathan Cameron Cc: Sudeep Holla , linux-pm@vger.kernel.org Subject: [PATCH 1/8] firmware: arm_scmi: improve code readability using bitfield accessor macros Date: Wed, 9 May 2018 18:07:07 +0100 Message-Id: <1525885634-22348-2-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525885634-22348-1-git-send-email-sudeep.holla@arm.com> References: <1525885634-22348-1-git-send-email-sudeep.holla@arm.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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: Sudeep Holla --- drivers/firmware/arm_scmi/common.h | 9 +++++---- drivers/firmware/arm_scmi/driver.c | 31 ++++++++++++++----------------- 2 files changed, 19 insertions(+), 21 deletions(-) -- 2.7.4 diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 0c30234f9098..e8f332c9c469 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -7,6 +7,7 @@ * Copyright (C) 2018 ARM Ltd. */ +#include #include #include #include @@ -14,10 +15,10 @@ #include #include -#define PROTOCOL_REV_MINOR_BITS 16 -#define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1) -#define PROTOCOL_REV_MAJOR(x) ((x) >> PROTOCOL_REV_MINOR_BITS) -#define PROTOCOL_REV_MINOR(x) ((x) & PROTOCOL_REV_MINOR_MASK) +#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))) +#define PROTOCOL_REV_MINOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x))) #define MAX_PROTOCOLS_IMP 16 #define MAX_OPPS 16 diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 14b147135a0c..917786d91f55 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -29,16 +29,12 @@ #include "common.h" -#define MSG_ID_SHIFT 0 -#define MSG_ID_MASK 0xff -#define MSG_TYPE_SHIFT 8 -#define MSG_TYPE_MASK 0x3 -#define MSG_PROTOCOL_ID_SHIFT 10 -#define MSG_PROTOCOL_ID_MASK 0xff -#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) +#define MSG_ID_MASK GENMASK(7, 0) +#define MSG_TYPE_MASK GENMASK(9, 8) +#define MSG_PROTOCOL_ID_MASK GENMASK(17, 10) +#define MSG_TOKEN_ID_MASK GENMASK(27, 18) +#define MSG_XTRACT_TOKEN(hdr) FIELD_GET(MSG_TOKEN_ID_MASK, (hdr)) +#define MSG_TOKEN_MAX (MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1) enum scmi_error_codes { SCMI_SUCCESS = 0, /* Success */ @@ -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) { - return ((hdr->id & MSG_ID_MASK) << MSG_ID_SHIFT) | - ((hdr->seq & MSG_TOKEN_ID_MASK) << MSG_TOKEN_ID_SHIFT) | - ((hdr->protocol_id & MSG_PROTOCOL_ID_MASK) << MSG_PROTOCOL_ID_SHIFT); + return FIELD_PREP(MSG_ID_MASK, hdr->id) | + FIELD_PREP(MSG_TOKEN_ID_MASK, hdr->seq) | + FIELD_PREP(MSG_PROTOCOL_ID_MASK, hdr->protocol_id); } /** @@ -621,9 +617,9 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo) struct scmi_xfers_info *info = &sinfo->minfo; /* Pre-allocated messages, no more than what hdr.seq can support */ - if (WARN_ON(desc->max_msg >= (MSG_TOKEN_ID_MASK + 1))) { - dev_err(dev, "Maximum message of %d exceeds supported %d\n", - 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 %ld\n", + desc->max_msg, MSG_TOKEN_MAX); return -EINVAL; } @@ -840,7 +836,8 @@ static int scmi_probe(struct platform_device *pdev) if (of_property_read_u32(child, "reg", &prot_id)) 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)) { dev_err(dev, "SCMI protocol %d not implemented\n",