From patchwork Thu Dec 14 21:13:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Levinsky X-Patchwork-Id: 13493691 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 4F2E9C4167D for ; Thu, 14 Dec 2023 21:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=u/WfStJ4n4wMtLYfnsJ1+cWYEDA4kJIY74eu16wXU9E=; b=o5QRnWCL/1rjS9 jtqJxcTw+pcIfCv0AM4du3l6pwdv4YFLSD8dv7mZO3CDFz4wrghQhmmMDnbYfTRBnjsGRvkMQZ+cg 6qBehoW7HP9HKbqu5dIn9iD09t7N5kxzlabBWhG/PjfKgtVB5fV/XLCIIJxLsyFTVUAKNpMTi9Up1 c3zYYYpEyqXSjKsVttWfIPbblK77BfY6BKK2FmbYf7MAAH/3kdwwwWNsHUdce2PizWaEi/VUgVaTS kJXmP14OJ5DOhVEwM+OBOm+JYnYKk684wu9RTAYe6TPa4P7rjwqFNRww9YSe8gjJgiPGGoP3fBCus c1epTxzNgXlSq5mS17xA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDt2B-001JVq-17; Thu, 14 Dec 2023 21:14:19 +0000 Received: from mail-dm6nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:2409::601] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rDt1x-001JRP-23 for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2023 21:14:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T5UQUG2tMLeBUuOTEZXgo9JHKCPkEP46+bZWricWtwRwlvwvvahflodAyZMVCZLxjBssQ+GXLtzKTfKS7vMa8d4awoO0S0eJV7iCMIemSYGOmhLYCYAcpsPDlFEu7GkntxfK78kSOqiteHeosh6rAUSpd/zf3ri7JMSVZyp1HbiSDyqWPJBcIxipekPRZWdhyZIkotHhKa2P500NF45wZ8QIDFJDfAHCvFU+JGefQ8bDQwuZF1d2lKK1kmZjiXVkdhrpff4aite+/e641+fHski7MAvSnVVCdhXlqZbGtxhz32mXDrqhep5YUZedWDwDCb4S89lZvNEjbd0mau3bYg== 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=xsSAgkByxi1E/H41WVLR/a+MWiHNOG4RqH4g4/cMbPg=; b=WPY4J30UzvQuDQGoIRysDITIqkaH+Laaoz5qnp/L4mH/CSU8/gY7OB7eawdMFZ8C2e8fJ7X/S9vHNcfDWk9FIfyBWXgTY0GBOXRu3FRyvK8QmXXjP0LL2OLsgpDQ3y85EPYDVzYj5svk2kyvfCcMtILexgT2Q0FDc9qAUrzIvTMICcWe3NobBA9JAx8n97H/siB/+bs2KDD/uHF3fMqp7EV+RBt1HApUtiRPsJ+Jv9UnFx+Y6+uEL+gTQZG5w1F+qj8QaciiRf0SEXxFpWZI2svjT9A6PUS1xKppuevkKUdM+AI6rGqrSoH4rbHq14TnXx7hkeBO/DH6kJHRK8hVsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gmail.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xsSAgkByxi1E/H41WVLR/a+MWiHNOG4RqH4g4/cMbPg=; b=IdbdtTniUPcB/eW1MN02t3dtRuhaXwsyfAQj+kVOLLrMSPL5biKWsjASkMyZYAs9MVshe7648qa0fT2SlI4An+0YODQkl19AkxEW3FFxbDTZha7L1R7Fvds4r5cahAuUm3hWEFsl9+AZtyEyubwWzoEVmtdM/VlZ8mT5CGlmtuM= Received: from BL1PR13CA0163.namprd13.prod.outlook.com (2603:10b6:208:2bd::18) by IA0PR12MB8973.namprd12.prod.outlook.com (2603:10b6:208:48e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.38; Thu, 14 Dec 2023 21:13:57 +0000 Received: from MN1PEPF0000F0E3.namprd04.prod.outlook.com (2603:10b6:208:2bd:cafe::8a) by BL1PR13CA0163.outlook.office365.com (2603:10b6:208:2bd::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.8 via Frontend Transport; Thu, 14 Dec 2023 21:13:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by MN1PEPF0000F0E3.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7091.26 via Frontend Transport; Thu, 14 Dec 2023 21:13:57 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 14 Dec 2023 15:13:57 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 14 Dec 2023 15:13:57 -0600 Received: from xsjblevinsk50.xilinx.com (172.19.2.206) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.34 via Frontend Transport; Thu, 14 Dec 2023 15:13:56 -0600 From: Ben Levinsky To: , , CC: , , Subject: [PATCH 3/3] mailbox: zynqmp: Enable Bufferless IPI usage on Versal-based SOC's Date: Thu, 14 Dec 2023 13:13:54 -0800 Message-ID: <20231214211354.348294-4-ben.levinsky@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231214211354.348294-1-ben.levinsky@amd.com> References: <20231214211354.348294-1-ben.levinsky@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E3:EE_|IA0PR12MB8973:EE_ X-MS-Office365-Filtering-Correlation-Id: ca005360-5db6-43bb-7ebf-08dbfce9960a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zAWpzFKYQ9IPyt3HH0GF7pJIGvuGA99D3H9LNqbRtPs+RpdydEp0uBG3t/t0s0U8A3LA72LFTWJOl2TUvtz8ktpy06PEvV5WJHWH6zF3Tr3hmRS+W5bHygk5XMusmAyUqLJIkdlToTtBhk8ZlWEnFAUGscuhZ9cLKR6GGhQ8anxNM66Ayo0afoPoJitzWepzGvAqCrcisbGjOSoAbue1y20e1CWAkIy91saVGN6g5Wf4hFYefXkUvikWJZS1lvDpsSjKPwWDbdGqnzW5Z1UBZmfG8Rj3eXWL0GqrgxpoQRrtniNeP/W9v2peCUuDDSokmHE6kG7J6afOExbMsyz5qnHTExOE9Dgwj3Hohc/8fjmgEJu9uQe33RsupulL+KDB2GO0dKyL94kPiwlxLMdWdn9Sa1igC8T60eFtGoatbqiOMynb3JQSKCYb4KBKQR20U3MkpiZpwr5ahjfJy6wA4/5Ayr7EAEibR3IRCZWKQ0YVbfREsAy2kkf70cBuRBVe1uc/1JbW9fnpT+Ox/+2s37W3MG0Wm/2b8vsxIwGgOHTwta0qoKJGQTjWhCJIBxelR5m1PtoNdP2g7n8JB4ECZ8raihINFa+Cq/A4Y8G1i3Xz6kLuGpSeTUC6cfwmgX6fbmzQAWLNgV3HO447IqImIMYCjRjS83a7L3leAqvs6qoRrD7y/IVcdxDU2q4a5mW6WINUHTKa2A3sAdbnVn3MLQn/a8OAPTFNETg4PItdOfx5+x7O+lU8g5bS2JEL/Vjg3FgEo6w7A3N8EBeqCJCektfaNGAjsvpXqnqTc9sUGUo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(39860400002)(376002)(346002)(136003)(230922051799003)(186009)(82310400011)(451199024)(64100799003)(1800799012)(40470700004)(36840700001)(46966006)(41300700001)(15650500001)(2906002)(44832011)(5660300002)(40460700003)(36860700001)(82740400003)(81166007)(356005)(70206006)(70586007)(54906003)(6636002)(426003)(40480700001)(43170500006)(336012)(26005)(110136005)(83380400001)(316002)(2616005)(36756003)(1076003)(86362001)(966005)(478600001)(47076005)(8936002)(4326008)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2023 21:13:57.7438 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca005360-5db6-43bb-7ebf-08dbfce9960a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000F0E3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8973 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231214_131405_678190_889F2FB1 X-CRM114-Status: GOOD ( 23.80 ) 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 On Xilinx-AMD Versal and Versal-NET, there exist both inter-processor-interrupts with corresponding message buffers and without such buffers. Add a routine that, if the corresponding DT compatible string "xlnx,versal-ipi-mailbox" is used then a Versal-based SOC can use a mailbox Device Tree entry where both host and remote can use either of the buffered or bufferless interrupts. Signed-off-by: Ben Levinsky --- Note that the linked patch provides corresponding bindings. Depends on: https://lore.kernel.org/all/20231214054224.957336-3-tanmay.shah@amd.com/T/ --- drivers/mailbox/zynqmp-ipi-mailbox.c | 146 +++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 7 deletions(-) diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c index edefb80a6e47..316d9406064e 100644 --- a/drivers/mailbox/zynqmp-ipi-mailbox.c +++ b/drivers/mailbox/zynqmp-ipi-mailbox.c @@ -52,6 +52,13 @@ #define IPI_MB_CHNL_TX 0 /* IPI mailbox TX channel */ #define IPI_MB_CHNL_RX 1 /* IPI mailbox RX channel */ +/* IPI Message Buffer Information */ +#define RESP_OFFSET 0x20U +#define DEST_OFFSET 0x40U +#define IPI_BUF_SIZE 0x20U +#define DST_BIT_POS 9U +#define SRC_BITMASK GENMASK(11, 8) + /** * struct zynqmp_ipi_mchan - Description of a Xilinx ZynqMP IPI mailbox channel * @is_opened: indicate if the IPI channel is opened @@ -170,9 +177,11 @@ static irqreturn_t zynqmp_ipi_interrupt(int irq, void *data) if (ret > 0 && ret & IPI_MB_STATUS_RECV_PENDING) { if (mchan->is_opened) { msg = mchan->rx_buf; - msg->len = mchan->req_buf_size; - memcpy_fromio(msg->data, mchan->req_buf, - msg->len); + if (msg) { + msg->len = mchan->req_buf_size; + memcpy_fromio(msg->data, mchan->req_buf, + msg->len); + } mbox_chan_received_data(chan, (void *)msg); status = IRQ_HANDLED; } @@ -282,26 +291,26 @@ static int zynqmp_ipi_send_data(struct mbox_chan *chan, void *data) if (mchan->chan_type == IPI_MB_CHNL_TX) { /* Send request message */ - if (msg && msg->len > mchan->req_buf_size) { + if (msg && msg->len > mchan->req_buf_size && mchan->req_buf) { dev_err(dev, "channel %d message length %u > max %lu\n", mchan->chan_type, (unsigned int)msg->len, mchan->req_buf_size); return -EINVAL; } - if (msg && msg->len) + if (msg && msg->len && mchan->req_buf) memcpy_toio(mchan->req_buf, msg->data, msg->len); /* Kick IPI mailbox to send message */ arg0 = SMC_IPI_MAILBOX_NOTIFY; zynqmp_ipi_fw_call(ipi_mbox, arg0, 0, &res); } else { /* Send response message */ - if (msg && msg->len > mchan->resp_buf_size) { + if (msg && msg->len > mchan->resp_buf_size && mchan->resp_buf) { dev_err(dev, "channel %d message length %u > max %lu\n", mchan->chan_type, (unsigned int)msg->len, mchan->resp_buf_size); return -EINVAL; } - if (msg && msg->len) + if (msg && msg->len && mchan->resp_buf) memcpy_toio(mchan->resp_buf, msg->data, msg->len); arg0 = SMC_IPI_MAILBOX_ACK; zynqmp_ipi_fw_call(ipi_mbox, arg0, IPI_SMC_ACK_EIRQ_MASK, @@ -640,6 +649,126 @@ static int zynqmp_ipi_setup(struct zynqmp_ipi_mbox *ipi_mbox, return 0; } +/** + * versal_ipi_setup - Set up IPIs to support mixed usage of + * Buffered and Bufferless IPIs. + * + * @ipi_mbox: pointer to IPI mailbox private data structure + * @node: IPI mailbox device node + * + * Return: 0 for success, negative value for failure + */ +static int versal_ipi_setup(struct zynqmp_ipi_mbox *ipi_mbox, + struct device_node *node) +{ + struct zynqmp_ipi_mchan *tx_mchan, *rx_mchan; + struct resource host_res, remote_res; + struct device_node *parent_node; + int host_idx, remote_idx; + struct device *mdev, *dev; + + tx_mchan = &ipi_mbox->mchans[IPI_MB_CHNL_TX]; + rx_mchan = &ipi_mbox->mchans[IPI_MB_CHNL_RX]; + parent_node = of_get_parent(node); + dev = ipi_mbox->pdata->dev; + mdev = &ipi_mbox->dev; + + host_idx = zynqmp_ipi_mbox_get_buf_res(parent_node, "msg", &host_res); + remote_idx = zynqmp_ipi_mbox_get_buf_res(node, "msg", &remote_res); + + /* + * Only set up buffers if both sides claim to have msg buffers. + * This is because each buffered IPI's corresponding msg buffers + * are reserved for use by other buffered IPI's. + */ + if (!host_idx && !remote_idx) { + u32 host_src, host_dst, remote_src, remote_dst; + u32 buff_sz; + + buff_sz = resource_size(&host_res); + + host_src = host_res.start & SRC_BITMASK; + remote_src = remote_res.start & SRC_BITMASK; + + host_dst = (host_src >> DST_BIT_POS) * DEST_OFFSET; + remote_dst = (remote_src >> DST_BIT_POS) * DEST_OFFSET; + + /* Validate that IPI IDs is within IPI Message buffer space. */ + if (host_dst >= buff_sz || remote_dst >= buff_sz) { + dev_err(mdev, + "Invalid IPI Message buffer values: %x %x\n", + host_dst, remote_dst); + return -EINVAL; + } + + tx_mchan->req_buf = devm_ioremap(mdev, + host_res.start | remote_dst, + IPI_BUF_SIZE); + if (!tx_mchan->req_buf) { + dev_err(mdev, "Unable to map IPI buffer I/O memory\n"); + return -ENOMEM; + } + + tx_mchan->resp_buf = devm_ioremap(mdev, + (remote_res.start | host_dst) + + RESP_OFFSET, IPI_BUF_SIZE); + if (!tx_mchan->resp_buf) { + dev_err(mdev, "Unable to map IPI buffer I/O memory\n"); + return -ENOMEM; + } + + rx_mchan->req_buf = devm_ioremap(mdev, + remote_res.start | host_dst, + IPI_BUF_SIZE); + if (!rx_mchan->req_buf) { + dev_err(mdev, "Unable to map IPI buffer I/O memory\n"); + return -ENOMEM; + } + + rx_mchan->resp_buf = devm_ioremap(mdev, + (host_res.start | remote_dst) + + RESP_OFFSET, IPI_BUF_SIZE); + if (!rx_mchan->resp_buf) { + dev_err(mdev, "Unable to map IPI buffer I/O memory\n"); + return -ENOMEM; + } + + tx_mchan->resp_buf_size = IPI_BUF_SIZE; + tx_mchan->req_buf_size = IPI_BUF_SIZE; + tx_mchan->rx_buf = devm_kzalloc(mdev, IPI_BUF_SIZE + + sizeof(struct zynqmp_ipi_message), + GFP_KERNEL); + if (!tx_mchan->rx_buf) + return -ENOMEM; + + rx_mchan->resp_buf_size = IPI_BUF_SIZE; + rx_mchan->req_buf_size = IPI_BUF_SIZE; + rx_mchan->rx_buf = devm_kzalloc(mdev, IPI_BUF_SIZE + + sizeof(struct zynqmp_ipi_message), + GFP_KERNEL); + if (!rx_mchan->rx_buf) + return -ENOMEM; + } else { + /* + * If here, then set up Bufferless IPI Channel because + * one or both of the IPI's is bufferless. + */ + tx_mchan->req_buf = NULL; + tx_mchan->resp_buf = NULL; + tx_mchan->rx_buf = NULL; + tx_mchan->resp_buf_size = 0; + tx_mchan->req_buf_size = 0; + + rx_mchan->req_buf = NULL; + rx_mchan->resp_buf = NULL; + rx_mchan->rx_buf = NULL; + rx_mchan->resp_buf_size = 0; + rx_mchan->req_buf_size = 0; + } + + return 0; +} + /** * zynqmp_ipi_free_mboxes - Free IPI mailboxes devices * @@ -749,6 +878,9 @@ static const struct of_device_id zynqmp_ipi_of_match[] = { { .compatible = "xlnx,zynqmp-ipi-mailbox", .data = &zynqmp_ipi_setup, }, + { .compatible = "xlnx,versal-ipi-mailbox", + .data = &versal_ipi_setup, + }, {}, }; MODULE_DEVICE_TABLE(of, zynqmp_ipi_of_match);