From patchwork Mon Jul 1 03:01:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13717531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59D99C3064D for ; Mon, 1 Jul 2024 03:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=dJEFLQQvxWlzIB0A6HSFpQP6jALKEd9skWZSjZwdlOc=; b=BOrS/eRXuosHboZj/t1gla8Bhu 6gmAQ7FA5ZEHh+R/vcmkAsjt9BuemKmB7QxulqHMSOOLfltv9QCeWyna9KUy2IeBXv9k4IciYS8zz +sVQVVniehz6q+gdOhH+dZlHGyjA3EHO8U4D/PFN8PMxjN4ajY/utoUqr8d9a2naHxpK1TLz5HSmu reO85DTtYmmosHc4tbpxSrcPgYEbTqExYODc/hBRJcJ/xlM6gpvGw0iQ0R+U4ZDiBiTBgEndqhHOl T4/mBHi+rntoAsNJVWn4ITlSmt8QGgHl417GDVX2foquEVnBwO8+okxC7aCD34y7p3jR93xAMeOFl XwZhEK/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sO7Oy-00000001XsW-3xV0; Mon, 01 Jul 2024 03:08:24 +0000 Received: from mail-db8eur05on20616.outbound.protection.outlook.com ([2a01:111:f400:7e1a::616] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sO7Oo-00000001Xrc-22IC for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 03:08:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cY2dB40le6D6ovtjDX2PYOWrlMgtaJ75Dl0OrviDPaoWPnR6VPNaTTojnQQ5hUKXsHcQjpPbNvhH7pcycscfpCuMxXt1HSDr4b8j8W66YMq5Ze726/I8s//oa8zirhRPRfsxxht33SQudj9zx+coCkZhXM3TC4aNsJyj9nQrCwYWQYUBnHTJuBD6bgT5RsIWe/BjxcVJUnF5ZOPEfpkZyOJIW0Tjzc0OEyMJTRpU/ANoWg+yfgz6zjGI0nPGSB0PSDScLDMtHjTIYxLwkFg3zHIjughyJrWlUvhcZjO6tm3rlSH9vQzvoKK2ijUY+5cYo55/03w1nirrwO0Bzxufig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dJEFLQQvxWlzIB0A6HSFpQP6jALKEd9skWZSjZwdlOc=; b=VLR7aDX/34lmsiRQo64gGz/mTCfdOGctyL/8TlpVqMwFVZKLat7S3MevnHFgby6RiWb5HlWvjuMlnawuOfv8CU2hblL1slavuv4Z37hDSHkHOlx7X2xZTdpAnIUxuk8OZzBmJ4O4k84QlEk8UwWLGVoNWiN84hy8zeG98SrXtZRylGooUdFIMEvXwx9YGeyQiuJL0Zp0Tpqv4mhyWcovfGfNvx72CylBW9wV9c0zRXyhLiStIk7a+H/y1Q6GN9+l2XQrpOSLI2DqOPIyTM7zEs6vAg8CEkyy5HPqTTFNMpALCUPJnhqXp/IGNrKimiFr8LhM6reDcHcmP9nFhO3e3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dJEFLQQvxWlzIB0A6HSFpQP6jALKEd9skWZSjZwdlOc=; b=Nym6iSu7OVP4hQxa6STkHMDQcbubQ2Gc+PW6bWzjnz93j3AzCBFM2P+HNt4QDS0vYEcU4TP1sySPEFcHTTIl2yLdQGxDeL2fHuFeHShTJKrXyDugDEW1Ncmun78fJdiCVcNjTsIhCnL2urIfDyhe86gLzk5WwCzyO4XJx19OF/4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) by PAWPR04MB9765.eurprd04.prod.outlook.com (2603:10a6:102:389::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.29; Mon, 1 Jul 2024 02:52:45 +0000 Received: from AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256]) by AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256%4]) with mapi id 15.20.7719.028; Mon, 1 Jul 2024 02:52:45 +0000 From: "Peng Fan (OSS)" To: sudeep.holla@arm.com, cristian.marussi@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, arm-scmi@vger.kernel.org, Peng Fan Subject: [PATCH] firmware: arm_scmi: introduce setup_shmem_iomap Date: Mon, 1 Jul 2024 11:01:43 +0800 Message-Id: <20240701030143.2327844-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.37.1 X-ClientProxiedBy: SGBP274CA0024.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b0::36) To AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5941:EE_|PAWPR04MB9765:EE_ X-MS-Office365-Filtering-Correlation-Id: b379d0fc-67f7-4d6d-51a6-08dc9978e227 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: 4Pq30S+aXftCd5vTgFjWQ5U11vTa2Cb3kDVwWTWLHcqXDPAHceTIS9IFeB5OVTYQLs0eFVwUN/MoP8S2tm8OUyA51xBLeZDbm6RMxjW4or6tcDROdcfRgeBPei13q6v00AeDzbE1G6evYzAj2fbjqxRHDc6lSVKW2C9q1egiH7qXnt8r9CUTT3LdRCNvMMYkj5BNZx2bfBm8rjsR7q6jhVgE12OCctngi1UGHU45V5ZkuLKcpOiIi0dPXMyMPJh02V2PVdywPJeB4CajrDj+vttljMu1QZm4Ib9tcDo8DCf6r3rTmsO7eTikQxXvPbEm3/+bqJuBQMwaBX5p+gGzh5IvhT836SHnGKpTm3V4bioM8XT8iPY14L7CoHkXTy3Dstp9JvaYizmzsEs1Zpzg2Rrw5881kDQEkof6jR/cIso618q0LD8/HUfM0AfsWdt6rNOzQryuyPkWdtQswoRFB1/CY9ggdYzC6PNzhMWggtnEuZhBoZl5WZzVX05EKdNSKlCDPQlwHBWViHmK1ra8ubQ7YBOZ0CS/3AZRa/SCLJDR8ryes36sf4xPYYLb6GtG24GG6AsKUfV0+DYx8uxjeLrD5cB3bz0eFzzhSaFZeJwLabpz6I+12oyRIMkQnnia3yTGyJi64nqV+5Zc/q3lKgTuM18UMQqcYoyCs8+YUo2Ja5mfDWb5KcmAcf5MnZv9USQqlfvjYn2tfY+JKP8ZO3w4dE1awGXvygLLlv4/vlxEqkuy5bc6YFOAzuyvcwvXsd+fEXCOTRiVQJPHf++0p9dqQVJA/qx+3hz9abaOP80ZQJJxAgqNb+3Kgnqmkv9wsLkEtNyPeH8YMvyFlFUR+8mBICIbwlNvfA1Iqyq4WPsuKnV3hyZbk28GLZM4r0CGVSWlnjiSVR5cGeNEGT0jRcIy5DFxzdYFr6ZM7qBWNIT/80B6iKUDQFtJTGc8RYT81oGjb1atJOKANo+mo6SeHi8AZcvR4VLMNppLtXT7ae6ZeKYZKpTFdUuWR/bfQeXdthi45h8BzS4mEziwqxinbIBPGuTYn0MC/QkFc8ormWN5TThUij0SBTnTrEirpAT2eu/Xx2nLOJa1xWgiFIZYb8zvPkb40YztFLQpQ0f12II9pc0kLbOOpPBjgtudUpmmTDkMbH/OKEW51P2SDjQwKk2vft1AKK3KUG5tPRR1DuaxX4OR0cY2TPgVH0Px9CDm9SX2tJc/7xcyAs0jCYMJ8J5acLf+Ynnf/JA+37Hj1NHshgwP2y453XKMJz27BkE8zgm2gdKHlvYu2M71QEMwWExZoS8MwoVz7B56NIkTjSO4m5QSOw/d11dYgm/XolmkbiKHEhIqaIRLpHIiwgQCNL1iZflLR6Kz0TeCPA51GH+QNemdTumWRg+egs7Ybt8IIjsPo/E3CsRw82RJUIke3g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5941.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-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yhjNBZx3dZ98aJ6EMsEEjP0ewVXLmxbqRf3QesIBSACvwBBckvHj258B+3KmTFG5a9cPKS4KCL+9AwnreaVmmbYiK4ctmSYgwkHWk8dTReV2wivxHGCEDwKePcxocv2UuDh+nNO3B6GRuFZiRzjVA4opzI6yeXHsVZdvmEU0Qr8KghOYwzPWL1dtUIlcbBGZk++e/VaPUb8k1nQnUFzbDA9L0OExqYdGqGmR6FtXwZE6m3pf3sYyAco7IT8tLp/p5uAXZFWSgYArvLVf2KwbvtY26IzsL1mu4/joLBHMQaZY7z2f6AKvVix2X5H0LVPqd117bPxncLVToRTvXXXX6IPn3QL71utxAQJwxm+XV5RfDld5uqDDikyOuWL+XjG1G1YLhANOkesmfeWFs/wg+aDzNXZa7c4yjaI7xnSSr58bG5t+ncQYyEcd/sYQDBz1ozwToYRb3p66UQoCMqhVmf/5GQzgE/Fdh7CjIb7sh3pvLX24OpXcO5xIXzHMHwHzMwTEg5aH10MpZeCTG662/qbjeg/SDqE7l/7ev8 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b379d0fc-67f7-4d6d-51a6-08dc9978e227 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5941.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2024 02:52:45.2346 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SS7m36xxwJ9AcQAUdv1g0mjFkIEuDlcWbQARVERtd2ZN0RZCe5vGpW0Lwp/iZ7NsMXggYA8VYiSE5P4vG4smKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB9765 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240630_200814_543234_CE66E9F8 X-CRM114-Status: GOOD ( 14.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan To get the address of shmem could be generalized by introducing setup_shmem_iomap. Then the duplicated code in mailbox.c and optee.c could be dropped. Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/common.h | 2 ++ drivers/firmware/arm_scmi/mailbox.c | 27 ++++------------------ drivers/firmware/arm_scmi/optee.c | 35 ++++------------------------ drivers/firmware/arm_scmi/shmem.c | 36 +++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 4b8c5250cdb5..b4c217641e3a 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -327,6 +327,8 @@ bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem, struct scmi_xfer *xfer); bool shmem_channel_free(struct scmi_shared_mem __iomem *shmem); bool shmem_channel_intr_enabled(struct scmi_shared_mem __iomem *shmem); +void __iomem *setup_shmem_iomap(struct scmi_chan_info *cinfo, struct device *dev, + bool tx); /* declarations for message passing transports */ struct scmi_msg_payld; diff --git a/drivers/firmware/arm_scmi/mailbox.c b/drivers/firmware/arm_scmi/mailbox.c index 0219a12e3209..b0a579f31905 100644 --- a/drivers/firmware/arm_scmi/mailbox.c +++ b/drivers/firmware/arm_scmi/mailbox.c @@ -178,11 +178,8 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, const char *desc = tx ? "Tx" : "Rx"; struct device *cdev = cinfo->dev; struct scmi_mailbox *smbox; - struct device_node *shmem; - int ret, a2p_rx_chan, p2a_chan, p2a_rx_chan, idx = tx ? 0 : 1; + int ret, a2p_rx_chan, p2a_chan, p2a_rx_chan; struct mbox_client *cl; - resource_size_t size; - struct resource res; ret = mailbox_chan_validate(cdev, &a2p_rx_chan, &p2a_chan, &p2a_rx_chan); if (ret) @@ -195,25 +192,9 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, if (!smbox) return -ENOMEM; - shmem = of_parse_phandle(cdev->of_node, "shmem", idx); - if (!of_device_is_compatible(shmem, "arm,scmi-shmem")) { - of_node_put(shmem); - return -ENXIO; - } - - ret = of_address_to_resource(shmem, 0, &res); - of_node_put(shmem); - if (ret) { - dev_err(cdev, "failed to get SCMI %s shared memory\n", desc); - return ret; - } - - size = resource_size(&res); - smbox->shmem = devm_ioremap(dev, res.start, size); - if (!smbox->shmem) { - dev_err(dev, "failed to ioremap SCMI %s shared memory\n", desc); - return -EADDRNOTAVAIL; - } + smbox->shmem = setup_shmem_iomap(cinfo, dev, tx); + if (IS_ERR(smbox->shmem)) + return PTR_ERR(smbox->shmem); cl = &smbox->cl; cl->dev = cdev; diff --git a/drivers/firmware/arm_scmi/optee.c b/drivers/firmware/arm_scmi/optee.c index 4e7944b91e38..8abcd668108c 100644 --- a/drivers/firmware/arm_scmi/optee.c +++ b/drivers/firmware/arm_scmi/optee.c @@ -368,38 +368,11 @@ static int setup_dynamic_shmem(struct device *dev, struct scmi_optee_channel *ch static int setup_static_shmem(struct device *dev, struct scmi_chan_info *cinfo, struct scmi_optee_channel *channel) { - struct device_node *np; - resource_size_t size; - struct resource res; - int ret; - - np = of_parse_phandle(cinfo->dev->of_node, "shmem", 0); - if (!of_device_is_compatible(np, "arm,scmi-shmem")) { - ret = -ENXIO; - goto out; - } - - ret = of_address_to_resource(np, 0, &res); - if (ret) { - dev_err(dev, "Failed to get SCMI Tx shared memory\n"); - goto out; - } - - size = resource_size(&res); + channel->req.shmem = setup_shmem_iomap(cinfo, dev, true); + if (IS_ERR(channel->req.shmem)) + return PTR_ERR(channel->req.shmem); - channel->req.shmem = devm_ioremap(dev, res.start, size); - if (!channel->req.shmem) { - dev_err(dev, "Failed to ioremap SCMI Tx shared memory\n"); - ret = -EADDRNOTAVAIL; - goto out; - } - - ret = 0; - -out: - of_node_put(np); - - return ret; + return 0; } static int setup_shmem(struct device *dev, struct scmi_chan_info *cinfo, diff --git a/drivers/firmware/arm_scmi/shmem.c b/drivers/firmware/arm_scmi/shmem.c index b74e5a740f2c..c31f188d74ef 100644 --- a/drivers/firmware/arm_scmi/shmem.c +++ b/drivers/firmware/arm_scmi/shmem.c @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include @@ -133,3 +135,37 @@ bool shmem_channel_intr_enabled(struct scmi_shared_mem __iomem *shmem) { return ioread32(&shmem->flags) & SCMI_SHMEM_FLAG_INTR_ENABLED; } + +void *__iomem +setup_shmem_iomap(struct scmi_chan_info *cinfo, struct device *dev, bool tx) +{ + const char *desc = tx ? "Tx" : "Rx"; + int ret, idx = tx ? 0 : 1; + struct device *cdev = cinfo->dev; + struct device_node *shmem; + resource_size_t size; + struct resource res; + void __iomem *addr; + + shmem = of_parse_phandle(cdev->of_node, "shmem", idx); + if (!of_device_is_compatible(shmem, "arm,scmi-shmem")) { + of_node_put(shmem); + return ERR_PTR(-ENXIO); + } + + ret = of_address_to_resource(shmem, 0, &res); + of_node_put(shmem); + if (ret) { + dev_err(cdev, "failed to get SCMI %s shared memory\n", desc); + return ERR_PTR(ret); + } + + size = resource_size(&res); + addr = devm_ioremap(dev, res.start, size); + if (!addr) { + dev_err(dev, "failed to ioremap SCMI %s shared memory\n", desc); + return ERR_PTR(-EADDRNOTAVAIL); + } + + return addr; +}