From patchwork Tue Dec 5 22:17:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 10093917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6AC296056E for ; Tue, 5 Dec 2017 22:21:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CF7C24B5B for ; Tue, 5 Dec 2017 22:21:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51A3E296AA; Tue, 5 Dec 2017 22:21:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0EB9029585 for ; Tue, 5 Dec 2017 22:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:References:To:Subject:From:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=31VGAhX5YETuST/alHfNfUSDCYS1sLx/cE6VRT8lguU=; b=seJwmnAa/xznDv CsafWNgc9aTIjaectd6TD8CUWz3v+cJDB6mLuYqxmXeEWk/YmxhGfM9QXBS9DHD0xbwcuKEhqOz3W +gDeTXBDaXgmvt1qE1wWeJfSOz7kJ5O3Z9lTtEp1uCA00DEVnNvLwgqX+W7v/FL+qFxQw36IDNDJ1 xs7gfnX2myBCkkiGzvyKwB0tnma9yLVPreHjme3w/STDUmmj7JiNparX9EV5vLqkYUR3QCsVJcIuq jnr2qkXQxy+APpmujJywyGfSHYXnRpNm9H9fFJfL8W8Sn4jxlVw4oCUdu6TQcyED7QBKttUrHqH/X ON53oxBAkFg4hyVQAIKg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMLaK-0002hN-UE; Tue, 05 Dec 2017 22:21:05 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMLXL-0006zu-59; Tue, 05 Dec 2017 22:18:09 +0000 Received: by mail-wr0-x244.google.com with SMTP id h1so1889972wre.12; Tue, 05 Dec 2017 14:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=PT2ggXX6FFUOVpoFckwqVCtBD6H/U4WarKteQZ3wIUY=; b=M50Tnk2/ouuhNaUrfOZI0OcEidI44l0zScifl6VqeHeYQOYTAr3NHhCo9l3XhCDdKp 7A8O9YxujhhO6tW/+o0Viepg8rmHAujZrB/hko3wTed1VpwGoBCn+NqAhIOs4pS5PyGj sFxaWaZA59XjlQfNt9Px5qjILKutefzEZn8wGA2DgtfbVScVNJGVc8pROFK2RAdcOHc/ 4UU/7iPQSUukID0lYdUdIUvBd9fT4NaHeQ/RwCRtaKh3bJnCgAbwPHBkI1164AuCjy/r YxWXMpb+jJ0lePcIKk+w8jEtzeqBTXWYYNudyI099WsZSU9O58nJ6rJdFRzlLGFY3eZR /Liw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=PT2ggXX6FFUOVpoFckwqVCtBD6H/U4WarKteQZ3wIUY=; b=R/hvAbV0Cyw0QS1rA8Unh0rBy2KgUDl6tYNhmbuOqJtwSS6jtF2lcVnpQi6H4GAcBr inD3SuI1jyXfE4eOXEz2UCw34aEIj0jwK1sHFYh5psNovHF9yLoIYjqlPeF0I5QFjBt6 ykp5GsLLKMlambcttMfDh2TMPQIlZHheFJ8jNxzdXnjpSV+WnuN9CHUlbZwc7/ZA2ad5 eNTdAqLuU7XFvPUD/PLaT0qpqoiFCyPFSwGyDflapvteuHjJxnko7jmnqI/QuKFMh5At WOHr6Nt1FjCOx6STofVhxApBy1Xx3bGBHBWwmq2zjT0Ogu48PaxDiMBTn32OmnrECtAt s78Q== X-Gm-Message-State: AJaThX5DjkY70++WMWDBeoUmazaNjoWmVKjZ86KCv/VzcejKeAeh8iMy Gkp+BWXvsnsSNDdKOeo3sOQ= X-Google-Smtp-Source: AGs4zMZFSqnuWsq06spPvY8vsbNPRulobSvrluFty8nmt1EBZDqZ67VrGl3Y4Vz2/OA7y13GX7lsdQ== X-Received: by 10.223.171.177 with SMTP id s46mr17422842wrc.194.1512512259989; Tue, 05 Dec 2017 14:17:39 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:b595:9d9d:56de:88e3? (p200300EA8BC0E400B5959D9D56DE88E3.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:b595:9d9d:56de:88e3]) by smtp.googlemail.com with ESMTPSA id f19sm1400937wmf.5.2017.12.05.14.17.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 14:17:39 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 11/12] firmware: arm_scpi: use FIELD_GET/_PREP to simplify macro definitions To: Sudeep Holla References: <99220c79-8b35-2978-11d1-6d101ccb6772@gmail.com> Message-ID: Date: Tue, 5 Dec 2017 23:17:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <99220c79-8b35-2978-11d1-6d101ccb6772@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171205_141800_075294_5EE8B13F X-CRM114-Status: UNSURE ( 7.99 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:ARM/Amlogic Meson..." , "linux-arm-kernel@lists.infradead.org" , Kevin Hilman Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Macro definitions can be simplified by making use of the FIELD_GET/_PREP bitfield macros. Signed-off-by: Heiner Kallweit --- drivers/firmware/arm_scpi.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 5695b1f4..bc7055a6 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -46,27 +46,19 @@ #include #include -#define CMD_ID_SHIFT 0 -#define CMD_ID_MASK 0x7f -#define CMD_TOKEN_ID_SHIFT 8 -#define CMD_TOKEN_ID_MASK 0xff -#define CMD_DATA_SIZE_SHIFT 16 -#define CMD_DATA_SIZE_MASK 0x1ff -#define CMD_LEGACY_DATA_SIZE_SHIFT 20 -#define CMD_LEGACY_DATA_SIZE_MASK 0x1ff -#define PACK_SCPI_CMD(cmd_id, tx_sz) \ - ((((cmd_id) & CMD_ID_MASK) << CMD_ID_SHIFT) | \ - (((tx_sz) & CMD_DATA_SIZE_MASK) << CMD_DATA_SIZE_SHIFT)) -#define ADD_SCPI_TOKEN(cmd, token) \ - ((cmd) |= (((token) & CMD_TOKEN_ID_MASK) << CMD_TOKEN_ID_SHIFT)) -#define PACK_LEGACY_SCPI_CMD(cmd_id, tx_sz) \ - ((((cmd_id) & CMD_ID_MASK) << CMD_ID_SHIFT) | \ - (((tx_sz) & CMD_LEGACY_DATA_SIZE_MASK) << CMD_LEGACY_DATA_SIZE_SHIFT)) - -#define CMD_SIZE(cmd) (((cmd) >> CMD_DATA_SIZE_SHIFT) & CMD_DATA_SIZE_MASK) -#define CMD_LEGACY_SIZE(cmd) (((cmd) >> CMD_LEGACY_DATA_SIZE_SHIFT) & \ - CMD_LEGACY_DATA_SIZE_MASK) -#define CMD_UNIQ_MASK (CMD_TOKEN_ID_MASK << CMD_TOKEN_ID_SHIFT | CMD_ID_MASK) +#define CMD_ID_MASK GENMASK(6, 0) +#define CMD_TOKEN_ID_MASK GENMASK(15, 8) +#define CMD_DATA_SIZE_MASK GENMASK(24, 16) +#define CMD_LEGACY_DATA_SIZE_MASK GENMASK(28, 20) +#define PACK_SCPI_CMD(cmd_id, tx_sz) \ + (FIELD_PREP(CMD_ID_MASK, cmd_id) | \ + FIELD_PREP(CMD_DATA_SIZE_MASK, tx_sz)) +#define PACK_LEGACY_SCPI_CMD(cmd_id, tx_sz) \ + (FIELD_PREP(CMD_ID_MASK, cmd_id) | \ + FIELD_PREP(CMD_LEGACY_DATA_SIZE_MASK, tx_sz)) + +#define CMD_SIZE(cmd) FIELD_GET(CMD_DATA_SIZE_MASK, cmd) +#define CMD_UNIQ_MASK (CMD_TOKEN_ID_MASK | CMD_ID_MASK) #define CMD_XTRACT_UNIQ(cmd) ((cmd) & CMD_UNIQ_MASK) #define SCPI_SLOT 0 @@ -412,7 +404,7 @@ static void scpi_process_cmd(struct scpi_chan *ch, u32 cmd) } else { struct scpi_shared_mem __iomem *mem = ch->rx_payload; - len = min(match->rx_len, CMD_SIZE(cmd)); + len = min_t(unsigned int, match->rx_len, CMD_SIZE(cmd)); match->status = ioread32(&mem->status); memcpy_fromio(match->rx_buf, mem->payload, len); @@ -454,7 +446,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) if (t->rx_buf) { if (!(++ch->token)) ++ch->token; - ADD_SCPI_TOKEN(t->cmd, ch->token); + t->cmd |= FIELD_PREP(CMD_TOKEN_ID_MASK, ch->token); spin_lock_irqsave(&ch->rx_lock, flags); list_add_tail(&t->node, &ch->rx_pending); spin_unlock_irqrestore(&ch->rx_lock, flags);