From patchwork Thu Jan 4 23:51:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaying Liang X-Patchwork-Id: 10145799 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 5DB076020F for ; Thu, 4 Jan 2018 23:53:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1D8F284D2 for ; Thu, 4 Jan 2018 23:53:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 960D02868D; Thu, 4 Jan 2018 23:53:23 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, 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 6FF1B284D2 for ; Thu, 4 Jan 2018 23:53:22 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YjPQrZv7zqqhQXnzku+F1F74FgtySQux0TrZq8a5C6Y=; b=GgiMQwLQMjsPge n703EjFNeCqxCV6NSbREZQXGO44kmb5k6FOt6r91VhkbSO5DBPlcLoMXVdwumzUbzZIxvs9m3q3F6 Ww5pgQrz2Pw1ZFUNkzdKUZF03N5KDcvn1HOqjtM9pi6puG4SqTA3Cj7xNoP91eR+D5rKXkayLuqCE PM1nUdY6TEoD8NQ/AS7512AFE1YFs6Bi6RtUUhfbcsspUyt3LaM+SO4ho9rKFwJaWKylJsuMI9Da+ oRbOSgXCCWrwSw0J6rovl7ezQr+btiU8t/AyzslltajOHBRsKe6cEVK2M/3SvqG96GYGVse8cd9yQ /jnlbi515W4DkIpFyM3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eXFK0-0000iO-Se; Thu, 04 Jan 2018 23:53:16 +0000 Received: from mail-sn1nam01on0059.outbound.protection.outlook.com ([104.47.32.59] helo=NAM01-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eXFIv-0008CU-Ef for linux-arm-kernel@lists.infradead.org; Thu, 04 Jan 2018 23:52:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=w889zKB/aP2rDSBfsTQMZs2zEJjtiQ2AdjcEiBNtJiY=; b=ROitfRkHPYxvgNdcyGeYGq1BWJ6xDea1g645mvIzSqGd729wheWdKJ38bDfv6IfpPnb0UXg5DUSicABvnEUi701hOr38BYcgffqmRBL8KmSCIBQP/oOMhPaYV7N+38+S3Ex74iM6tVxM7iOJFP6u37QCgRmVyDeFaheEGT6+Ias= Received: from BLUPR0201CA0028.namprd02.prod.outlook.com (10.163.116.38) by CY4PR02MB3383.namprd02.prod.outlook.com (10.165.89.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.366.8; Thu, 4 Jan 2018 23:51:54 +0000 Received: from SN1NAM02FT023.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e44::202) by BLUPR0201CA0028.outlook.office365.com (2a01:111:e400:52e7::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.386.5 via Frontend Transport; Thu, 4 Jan 2018 23:51:54 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; lists.infradead.org; dkim=none (message not signed) header.d=none;lists.infradead.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by SN1NAM02FT023.mail.protection.outlook.com (10.152.72.156) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Thu, 4 Jan 2018 23:51:53 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:36810 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1eXFIe-0005yy-S9; Thu, 04 Jan 2018 15:51:52 -0800 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1eXFIe-0004sr-Q1; Thu, 04 Jan 2018 15:51:52 -0800 Received: from xsj-pvapsmtp01 (xsj-smtp.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id w04Nplcl028063; Thu, 4 Jan 2018 15:51:47 -0800 Received: from [172.19.2.167] (helo=xsjjliang50.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1eXFIZ-0004sF-1G; Thu, 04 Jan 2018 15:51:47 -0800 From: Wendy Liang To: , , , Subject: [PATCH v3 1/2] mailbox: ZynqMP IPI mailbox controller Date: Thu, 4 Jan 2018 15:51:30 -0800 Message-ID: <1515109891-17133-2-git-send-email-jliang@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515109891-17133-1-git-send-email-jliang@xilinx.com> References: <1515109891-17133-1-git-send-email-jliang@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23572.006 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(396003)(346002)(376002)(2980300002)(438002)(189003)(199004)(356003)(54906003)(106002)(316002)(39060400002)(76176011)(9786002)(2906002)(36756003)(8676002)(107886003)(47776003)(110136005)(36386004)(59450400001)(81156014)(106466001)(2950100002)(305945005)(50226002)(16586007)(15650500001)(63266004)(81166006)(51416003)(478600001)(50466002)(7696005)(4326008)(77096006)(48376002)(6666003)(5660300001)(8936002)(107986001)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR02MB3383; H:xsj-pvapsmtpgw02; FPR:; SPF:Pass; PTR:unknown-60-100.xilinx.com,xapps1.xilinx.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02FT023; 1:tT2OJ1wv9zcohONwn6yc8m4juEg3Ui8ZO7lgMXNXB6R8Usb58KMkurbLh1AvI1FK1rdw0tw4Qz+9/PH+oHrODS13HooXuXA5WuEmaGZvdjhI6/nWGBOG46Qm11qGivWs MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 011dd5fe-69ee-4de7-b6f5-08d553ce218c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:CY4PR02MB3383; X-Microsoft-Exchange-Diagnostics: 1; CY4PR02MB3383; 3:NI9QRCIlVOycEEoGh/1bGD2gKilIfayCripZkLvN4h04Q04wRP4XKa8UD0+9jnemeiuRnv8Cc2HfcETpaBnYvHN+0XF6VAzelEJjGnxtS12/MNrPLJPezmtRTkOx8bJQP8o0tyQIznx7sSDYd04V9hqzhG5zi5O+fgp6H4XU7l3KMnIgTPX20A/YMy4kJDzIldEefTKUhWRHsccBJBlQRhEmgiA1DtePYgcviK7TMv7ctwJhLnRQY9xxasnwNBdjDychhsETP4+6bO/iGPAGtr2UsZJa7ePNfs4ZyynaNWCPrvZDNlG32v3mxt1RtGfENJZwLpBe2P0pBo1x1GhSYuKzvJv3rwrfWUMfLGSQ0Ow=; 25:P2QFOcmR1AZWcWKScBcNLJMyj7Y1HcaKShCwNLZ9GksYT06nl2XsmOydYDdDZP6X1SypINk/ogvelmNXcR2Cqy4jOWRwVnGwDS8l+197xCjCWjtRcrayASnxzQCHOoj5fbKPHs83CuiKY3pOqvkCW8BDJ3J2tK9mSomlIGvhlL9LHWV9qF7ISKqIIIYMOtXO948pV8wL3KryTVoUY9p2gAFSJ8WqbAJCbDhYfR0htXlD07mVAK/D6vNd9OrHLSnpRS+/IkAK0pVG1C3bZQNI+hjZlfaD1YkuQdyf/meNJId7Gw31+Lh6+v/0Quro61CBXMl25/191Fwl40K0n2X8/Q== X-MS-TrafficTypeDiagnostic: CY4PR02MB3383: X-Microsoft-Exchange-Diagnostics: 1; CY4PR02MB3383; 31:SHrApaf1c3WJT2nkjZzScg1cx0vf6G7YAlVLIGzmQ+O25TYpi5V3GLjGf0RspDyOP5CCjK883TxyW8ELvogHPfLrA+NBxSoLxQVwfOnJNVZNgqwNl/ZrWThfC+zE36ivZT+4hcE8oIq8qa8M9YQT+HjEmndUctvxWNqIOIZ0fpuihnat+NvKl3icczWSvVpvgZMwrcpa0oFI8AAsffYaQT5bieW4XRddBR4qYyYRCzA=; 20:PJJdl3YrST70C5jzZXrmLOiKiQTXGDCwwJrRnwqXnX4zYiEyaN4dbIby+Cc2DhUZ63IIJpmQd/UFPKKNSAH1kp+LMOXQ9iniW6woZOuQUsfV6zr1Gekk0pckY16Rjm40bU4sdhxBWY+ijYpMSeAaYWpYBSduo6iyyZUzuxL2fCTNOJ5hGTd71G2EANMtAfeCIq5et9YQq7SGMn1wEt1xuf4apuNrVkPnVbHhN7kkB4F7SVnchxI5JWUFS1PjZosLTuLulAacJjH0elbQ0N1Zz2DY5h1hnyeKx40ZR5ukPmaa4Z1rCMG0yrZmceXU+GZbjcOGXph0PFBmXaWF7Z7UctPIV9NNB7mKsEVGd5y2X66LrPyTpgK1QZTv4DIN71nrmvAEzk5JlpBkXstP8N4q3vAdNuflFa2ogHgL08NptcIEG+/4RP4e6UpV/5SVD6ggzrl4AnZbpyaQ8ORft++MWUuXpYXLnpjGRZo0HqgNIpzlnBa/0uaXo8b2tbWw1Xsb X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93004095)(3231023)(944501075)(6055026)(6041268)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:CY4PR02MB3383; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR02MB3383; X-Microsoft-Exchange-Diagnostics: 1; CY4PR02MB3383; 4:QQAnoYH8LE/fInxemoXuP+moL+33V6tCGEod51N19zn+DYkXa9nuFkHo7BKUW+rRsX9UK1Im6PJOictAyh8t2B71u5dqIl3GijTwLFKSRCY/ha9sW6ZbJy87WJSTXoL/a5l39/D/eeOc+xoYMw3mBAY38ko/LhCpsRsUkqJ72fCGJAF6z8mS500TOhM9CnrujdQpbPwXhNT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XrmyN1OsVopt3+HJylFpzScCCxUNOwMS4zV95jgYm2EYp92AzOfq2yoq+7pprOk4gVZbtxtNbC1wbMmd6M0h+s=; 7:YSoGNLN+GxIhChktylP5buUVfwq5a/WUeuip6e3d1WTGcfiFEJPx9DeGFBT1hXfZAD74IahtfJPTxXpxObshwshjziV+9ZYIq6ctlsWUqn17dqidVp+kMNQGVni7PcR79AsKXIV0yzcPGz0orEsL60xsS5Dh+rQlCQD46L6vVbR5wjvCZwxe315/rMcgamzRienV38u4QmpgGVs9bubJyMeZISCHSIwuLOGRFi9PBGqkDY4w7cbYdYCvQHlbZAUX SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2018 23:51:53.1375 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 011dd5fe-69ee-4de7-b6f5-08d553ce218c X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.100]; Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR02MB3383 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180104_155209_662025_1366C223 X-CRM114-Status: GOOD ( 17.77 ) 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: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Wendy Liang 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 This patch is to introduce ZynqMP IPI mailbox controller driver to use the ZynqMP IPI block as mailboxes. Signed-off-by: Wendy Liang --- drivers/mailbox/Kconfig | 8 + drivers/mailbox/Makefile | 2 + drivers/mailbox/zynqmp-ipi-mailbox.c | 635 +++++++++++++++++++++++++++++ include/linux/mailbox/zynqmp-ipi-message.h | 24 ++ 4 files changed, 669 insertions(+) create mode 100644 drivers/mailbox/zynqmp-ipi-mailbox.c create mode 100644 include/linux/mailbox/zynqmp-ipi-message.h diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index ba2f152..876614a 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -171,4 +171,12 @@ config BCM_FLEXRM_MBOX Mailbox implementation of the Broadcom FlexRM ring manager, which provides access to various offload engines on Broadcom SoCs. Say Y here if you want to use the Broadcom FlexRM. + +config ZYNQMP_IPI_MBOX + tristate "Xilinx ZynqMP IPI Mailbox" + depends on ARCH_ZYNQMP && OF + help + Mailbox implementation for Xilinx ZynqMP IPI. It is used to send + notification or short message between processors with Xilinx + ZynqMP IPI. endif diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 4896f8d..155f72f 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -36,3 +36,5 @@ obj-$(CONFIG_BCM_FLEXRM_MBOX) += bcm-flexrm-mailbox.o obj-$(CONFIG_QCOM_APCS_IPC) += qcom-apcs-ipc-mailbox.o obj-$(CONFIG_TEGRA_HSP_MBOX) += tegra-hsp.o + +obj-$(CONFIG_ZYNQMP_IPI_MBOX) += zynqmp-ipi-mailbox.o diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c new file mode 100644 index 0000000..4258360d --- /dev/null +++ b/drivers/mailbox/zynqmp-ipi-mailbox.c @@ -0,0 +1,635 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Xilinx Inter Processor Interrupt(IPI) Mailbox Driver + * + * Copyright (C) 2017 Xilinx Inc. + * + */ + +#define pr_fmt(fmt) "%s: " fmt, __func__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* IPI agent ID any */ +#define IPI_ID_ANY 0xFFUL + +/* indicate if ZynqMP IPI mailbox driver uses SMC calls or HVC calls */ +#define USE_SMC 0 +#define USE_HVC 1 + +/* Default IPI SMC function IDs */ +#define SMC_IPI_MAILBOX_OPEN 0x82001000U +#define SMC_IPI_MAILBOX_RELEASE 0x82001001U +#define SMC_IPI_MAILBOX_STATUS_ENQUIRY 0x82001002U +#define SMC_IPI_MAILBOX_NOTIFY 0x82001003U +#define SMC_IPI_MAILBOX_ACK 0x82001004U +#define SMC_IPI_MAILBOX_ENABLE_IRQ 0x82001005U +#define SMC_IPI_MAILBOX_DISABLE_IRQ 0x82001006U + +/* IPI SMC Macros */ +#define IPI_SMC_OPEN_IRQ_MASK 0x00000001UL /* IRQ enable bit in IPI + * open SMC call + */ +#define IPI_SMC_NOTIFY_BLOCK_MASK 0x00000001UL /* Flag to indicate if + * IPI notification needs + * to be blocking. + */ +#define IPI_SMC_ENQUIRY_DIRQ_MASK 0x00000001UL /* Flag to indicate if + * notification interrupt + * to be disabled. + */ +#define IPI_SMC_ACK_EIRQ_MASK 0x00000001UL /* Flag to indicate if + * notification interrupt + * to be enabled. + */ + +/* IPI mailbox status */ +#define IPI_MB_STATUS_IDLE 0 +#define IPI_MB_STATUS_SEND_PENDING 1 +#define IPI_MB_STATUS_RECV_PENDING 2 + +#define IPI_MB_CHNL_TX 0 /* IPI mailbox TX channel */ +#define IPI_MB_CHNL_RX 1 /* IPI mailbox RX channel */ + +/** + * struct zynqmp_ipi_mchan - Description of a Xilinx ZynqMP IPI mailbox channel + * @is_opened: indicate if the IPI channel is opened + * @req_buf: local to remote request buffer start address + * @resp_buf: local to remote response buffer start address + * @req_buf_size: request buffer size + * @resp_buf_size: response buffer size + * @chan_type: channel type + */ +struct zynqmp_ipi_mchan { + int is_opened; + void __iomem *req_buf; + void __iomem *resp_buf; + size_t req_buf_size; + size_t resp_buf_size; + unsigned int chan_type; +}; + +/** + * struct zynqmp_ipi_mbox_pdata - Description of a ZynqMP IPI mailbox + * platform data. + * @dev: device pointer corresponding to the Xilinx ZynqMP + * IPI mailbox + * @local_id: local IPI agent ID + * @remote_id: remote IPI agent ID + * @method: IPI SMC or HVC is going to be used + * @mbox: mailbox Controller + * @mchans: array for channels, tx channel and rx channel. + * @irq: IPI agent interrupt ID + * @lock: IPI mailbox platform data lock + */ +struct zynqmp_ipi_mbox_pdata { + struct device *dev; + u32 local_id; + u32 remote_id; + unsigned int method; + struct mbox_controller mbox; + struct zynqmp_ipi_mchan mchans[2]; + int irq; + spinlock_t lock; /* spin lock for local data */ +}; + +static void zynqmp_ipi_fw_call(struct zynqmp_ipi_mbox_pdata *pdata, + unsigned long a0, unsigned long a3, + unsigned long a4, unsigned long a5, + unsigned long a6, unsigned long a7, + struct arm_smccc_res *res) +{ + unsigned long a1, a2; + + a1 = pdata->local_id; + a2 = pdata->remote_id; + if (pdata->method == USE_SMC) + arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res); + else + arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res); +} + +/** + * zynqmp_ipi_interrupt - Interrupt handler for IPI notification + * + * @irq: Interrupt number + * @data: ZynqMP IPI mailbox platform data. + * + * Return: -EINVAL if there is no instance + * IRQ_NONE if the interrupt is not ours. + * IRQ_HANDLED if the rx interrupt was successfully handled. + */ +static irqreturn_t zynqmp_ipi_interrupt(int irq, void *data) +{ + struct zynqmp_ipi_mbox_pdata *pdata = data; + struct mbox_chan *chan; + struct zynqmp_ipi_mchan *mchan; + struct zynqmp_ipi_message msg; + u64 arg0, arg3; + struct arm_smccc_res res; + int ret; + + arg0 = SMC_IPI_MAILBOX_STATUS_ENQUIRY; + arg3 = IPI_SMC_ENQUIRY_DIRQ_MASK; + zynqmp_ipi_fw_call(pdata, arg0, arg3, 0, 0, 0, 0, &res); + ret = (int)(res.a0 & 0xFFFFFFFF); + if (ret > 0 && ret & IPI_MB_STATUS_RECV_PENDING) { + chan = &pdata->mbox.chans[IPI_MB_CHNL_RX]; + mchan = chan->con_priv; + if (mchan->is_opened) { + msg.len = mchan->req_buf_size; + msg.data = mchan->req_buf; + /* Client will direclty copy data from + * IPI buffer to client data memory + */ + mbox_chan_received_data(chan, (void *)&msg); + return IRQ_HANDLED; + } + } + return IRQ_NONE; +} + +/** + * zynqmp_ipi_peek_data - Peek to see if there are any rx messages. + * + * @chan: Channel Pointer + * + * Return: 'true' if there is pending rx data, 'false' if there is none. + */ +static bool zynqmp_ipi_peek_data(struct mbox_chan *chan) +{ + struct device *dev = chan->mbox->dev; + struct zynqmp_ipi_mbox_pdata *pdata = dev_get_drvdata(dev); + struct zynqmp_ipi_mchan *mchan = chan->con_priv; + int ret; + u64 arg0; + struct arm_smccc_res res; + + if (WARN_ON(!pdata)) { + dev_err(dev, "no platform drv data??\n"); + return false; + } + + arg0 = SMC_IPI_MAILBOX_STATUS_ENQUIRY; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + ret = (int)(res.a0 & 0xFFFFFFFF); + + if (mchan->chan_type == IPI_MB_CHNL_TX) { + /* TX channel, check if the message has been acked + * by the remote, if yes, response is available. + */ + if (ret < 0 || ret & IPI_MB_STATUS_SEND_PENDING) + return false; + else + return true; + } else if (ret > 0 && ret & IPI_MB_STATUS_RECV_PENDING) { + /* RX channel, check if there is message arrived. */ + return true; + } + return false; +} + +/** + * zynqmp_ipi_last_tx_done - See if the last tx message is sent + * + * @chan: Channel pointer + * + * Return: 'true' is no pending tx data, 'false' if there are any. + */ +static bool zynqmp_ipi_last_tx_done(struct mbox_chan *chan) +{ + struct device *dev = chan->mbox->dev; + struct zynqmp_ipi_mbox_pdata *pdata = dev_get_drvdata(dev); + struct zynqmp_ipi_mchan *mchan = chan->con_priv; + int ret; + u64 arg0; + struct arm_smccc_res res; + struct zynqmp_ipi_message msg; + + if (WARN_ON(!pdata)) { + dev_err(dev, "no platform drv data??\n"); + return false; + } + + if (mchan->chan_type == IPI_MB_CHNL_TX) { + /* We only need to check if the message been taken + * by the remote in the TX channel + */ + arg0 = SMC_IPI_MAILBOX_STATUS_ENQUIRY; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + /* Check the SMC call status, a0 of the result */ + ret = (int)(res.a0 & 0xFFFFFFFF); + if (ret < 0 || ret & IPI_MB_STATUS_SEND_PENDING) + return false; + + msg.len = mchan->resp_buf_size; + msg.data = mchan->resp_buf; + /* Client will direclty copy data from + * IPI buffer to client data memory + */ + mbox_chan_received_data(chan, (void *)&msg); + return true; + } + /* Always true for the response message in RX channel */ + return true; +} + +/** + * zynqmp_ipi_send_data - Send data + * + * @chan: Channel Pointer + * @data: Message Pointer + * + * Return: 0 if all goes good, else appropriate error messages. + */ +static int zynqmp_ipi_send_data(struct mbox_chan *chan, void *data) +{ + struct device *dev = chan->mbox->dev; + struct zynqmp_ipi_mbox_pdata *pdata = dev_get_drvdata(dev); + struct zynqmp_ipi_mchan *mchan = chan->con_priv; + struct zynqmp_ipi_message *msg = data; + u64 arg0; + struct arm_smccc_res res; + u32 timeout; + int ret; + + if (WARN_ON(!pdata)) { + dev_err(dev, "no platform drv data??\n"); + return -EINVAL; + } + + if (mchan->chan_type == IPI_MB_CHNL_TX) { + /* Send request message */ + if (msg && msg->len > mchan->resp_buf_size) { + dev_err(dev, "channel %d message length %u > max %lu\n", + mchan->chan_type, (unsigned int)msg->len, + mchan->resp_buf_size); + return -EINVAL; + } + /* Enquire if the mailbox is free to send message */ + arg0 = SMC_IPI_MAILBOX_STATUS_ENQUIRY; + timeout = 10; + do { + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + ret = res.a0 & 0xFFFFFFFF; + if (ret >= 0 && !(ret & IPI_MB_STATUS_SEND_PENDING)) + break; + usleep_range(1, 2); + timeout--; + } while (timeout); + if (!timeout) { + dev_warn(dev, "channel %d sending msg timesout.\n", + pdata->remote_id); + return -ETIME; + } + /* Copy message to the request buffer */ + if (msg && msg->len) + memcpy_toio(mchan->req_buf, msg->data, msg->len); + /* Kick IPI mailbox to send message */ + arg0 = SMC_IPI_MAILBOX_NOTIFY; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + } else { + /* Send response message */ + if (msg && msg->len > mchan->resp_buf_size) { + 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) + memcpy(mchan->resp_buf, msg->data, msg->len); + arg0 = SMC_IPI_MAILBOX_NOTIFY; + arg0 = SMC_IPI_MAILBOX_ACK; + zynqmp_ipi_fw_call(pdata, arg0, IPI_SMC_ACK_EIRQ_MASK, + 0, 0, 0, 0, &res); + } + return 0; +} + +/** + * zynqmp_ipi_startup - Startup the IPI channel + * + * @chan: Channel pointer + * + * Return: 0 if all goes good, else return corresponding error message + */ +static int zynqmp_ipi_startup(struct mbox_chan *chan) +{ + struct device *dev = chan->mbox->dev; + struct zynqmp_ipi_mbox_pdata *pdata = dev_get_drvdata(dev); + struct zynqmp_ipi_mchan *mchan = chan->con_priv; + u64 arg0; + struct arm_smccc_res res; + int ret = 0; + unsigned long flags; + unsigned int nchan_type; + + spin_lock_irqsave(&pdata->lock, flags); + if (mchan->is_opened) { + /* IPI mailbox has been opened */ + spin_unlock_irqrestore(&pdata->lock, flags); + return -EBUSY; + } + + /* If no channel has been opened, open the IPI mailbox */ + nchan_type = (mchan->chan_type + 1) % 2; + if (!pdata->mchans[nchan_type].is_opened) { + arg0 = SMC_IPI_MAILBOX_OPEN; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + /* Check the SMC call status, a0 of the result */ + ret = (int)(res.a0 | 0xFFFFFFFF); + if (res.a0 < 0) { + dev_err(dev, "SMC to open the IPI channel failed.\n"); + ret = res.a0; + spin_unlock_irqrestore(&pdata->lock, flags); + return ret; + } + ret = 0; + } + + /* If it is RX channel, enable the IPI notification interrupt */ + if (mchan->chan_type == IPI_MB_CHNL_RX) { + arg0 = SMC_IPI_MAILBOX_ENABLE_IRQ; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + } + mchan->is_opened = 1; + spin_unlock_irqrestore(&pdata->lock, flags); + + return ret; +} + +/** + * zynqmp_ipi_shutdown - Shutdown the IPI channel + * + * @chan: Channel pointer + */ +static void zynqmp_ipi_shutdown(struct mbox_chan *chan) +{ + struct device *dev = chan->mbox->dev; + struct zynqmp_ipi_mbox_pdata *pdata = dev_get_drvdata(dev); + struct zynqmp_ipi_mchan *mchan = chan->con_priv; + u64 arg0; + struct arm_smccc_res res; + unsigned long flags; + unsigned int chan_type; + + spin_lock_irqsave(&pdata->lock, flags); + if (!mchan->is_opened) { + spin_unlock_irqrestore(&pdata->lock, flags); + return; + } + + /* If it is RX channel, disable notification interrupt */ + chan_type = mchan->chan_type; + if (chan_type == IPI_MB_CHNL_RX) { + arg0 = SMC_IPI_MAILBOX_DISABLE_IRQ; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + } + /* Release IPI mailbox if no other channel is opened */ + chan_type = (chan_type + 1) % 2; + if (!pdata->mchans[chan_type].is_opened) { + arg0 = SMC_IPI_MAILBOX_RELEASE; + zynqmp_ipi_fw_call(pdata, arg0, 0, 0, 0, 0, 0, &res); + } + + mchan->is_opened = 0; + spin_unlock_irqrestore(&pdata->lock, flags); +} + +/* ZynqMP IPI mailbox operations */ +static const struct mbox_chan_ops zynqmp_ipi_chan_ops = { + .startup = zynqmp_ipi_startup, + .shutdown = zynqmp_ipi_shutdown, + .peek_data = zynqmp_ipi_peek_data, + .last_tx_done = zynqmp_ipi_last_tx_done, + .send_data = zynqmp_ipi_send_data, +}; + +/** + * zynqmp_ipi_of_xlate - Translate of phandle to IPI mailbox channel + * + * @mbox: mailbox controller pointer + * @p: phandle pointer + * + * Return: Mailbox channel, else return error pointer. + */ +static struct mbox_chan *zynqmp_ipi_of_xlate(struct mbox_controller *mbox, + const struct of_phandle_args *p) +{ + struct zynqmp_ipi_mbox_pdata *pdata; + struct mbox_chan *chan; + struct device *dev = mbox->dev; + unsigned int chan_type; + + pdata = container_of(mbox, struct zynqmp_ipi_mbox_pdata, mbox); + + /* Only supports TX and RX channels */ + chan_type = p->args[0]; + if (chan_type != IPI_MB_CHNL_TX && chan_type != IPI_MB_CHNL_RX) { + dev_err(dev, "req chnl failure: invalid chnl type %u.\n", + chan_type); + return ERR_PTR(-EINVAL); + } + chan = &mbox->chans[chan_type]; + return chan; +} + +static const struct of_device_id zynqmp_ipi_of_match[] = { + {.compatible = "xlnx,zynqmp-ipi-mailbox"}, + {}, +}; +MODULE_DEVICE_TABLE(of, zynqmp_ipi_of_match); + +static int zynqmp_ipi_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = pdev->dev.of_node; + struct zynqmp_ipi_mbox_pdata *pdata; + struct zynqmp_ipi_mchan *mchan; + struct mbox_chan *chans; + struct mbox_controller *mbox; + const unsigned char *prop; + struct resource *res; + int ret = -EINVAL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + pdata->dev = dev; + + mchan = &pdata->mchans[IPI_MB_CHNL_TX]; + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "local_request_region"); + if (res) { + mchan->req_buf_size = resource_size(res); + mchan->req_buf = devm_ioremap(&pdev->dev, res->start, + mchan->req_buf_size); + if (IS_ERR(mchan->req_buf)) { + dev_err(dev, "Unable to map IPI buffer I/O memory\n"); + ret = PTR_ERR(mchan->req_buf); + return ret; + } + } + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "remote_response_region"); + if (res) { + mchan->resp_buf_size = resource_size(res); + mchan->resp_buf = devm_ioremap(&pdev->dev, res->start, + mchan->resp_buf_size); + if (IS_ERR(mchan->resp_buf)) { + dev_err(dev, "Unable to map IPI buffer I/O memory\n"); + ret = PTR_ERR(mchan->resp_buf); + return ret; + } + } + + mchan = &pdata->mchans[IPI_MB_CHNL_RX]; + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "remote_request_region"); + if (res) { + mchan->req_buf_size = resource_size(res); + mchan->req_buf = devm_ioremap(&pdev->dev, res->start, + mchan->req_buf_size); + if (IS_ERR(mchan->req_buf)) { + dev_err(dev, "Unable to map IPI buffer I/O memory\n"); + ret = PTR_ERR(mchan->req_buf); + return ret; + } + } + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "local_response_region"); + if (res) { + mchan->resp_buf_size = resource_size(res); + mchan->resp_buf = devm_ioremap(&pdev->dev, res->start, + mchan->resp_buf_size); + if (IS_ERR(mchan->resp_buf)) { + dev_err(dev, "Unable to map IPI buffer I/O memory\n"); + ret = PTR_ERR(mchan->resp_buf); + return ret; + } + } + + /* Get the IPI local and remote agents IDs */ + ret = of_property_read_u32_index(np, "xlnx,ipi-ids", 0, + &pdata->local_id); + if (ret < 0) { + dev_err(dev, "No IPI local ID is specified.\n"); + return ret; + } + ret = of_property_read_u32_index(np, "xlnx,ipi-ids", 1, + &pdata->remote_id); + if (ret < 0) { + dev_err(dev, "No IPI remote ID is specified.\n"); + return ret; + } + + /* Get how to access IPI agent method */ + prop = of_get_property(np, "method", NULL); + if (!prop) { + pdata->method = USE_SMC; + } else if (!strcmp(prop, "smc")) { + pdata->method = USE_SMC; + } else if (!strcmp(prop, "hvc")) { + pdata->method = USE_HVC; + } else { + dev_err(dev, "Invalid \"method\" %s.\n", prop); + return ret; + } + + /* IPI IRQ */ + ret = platform_get_irq(pdev, 0); + if (ret < 0) { + dev_err(dev, "unable to find IPI IRQ.\n"); + return ret; + } + pdata->irq = ret; + ret = devm_request_irq(dev, pdata->irq, zynqmp_ipi_interrupt, + IRQF_SHARED, dev_name(dev), pdata); + if (ret) { + dev_err(dev, "IRQ %d is not requested successfully.\n", + pdata->irq); + return ret; + } + + mbox = &pdata->mbox; + mbox->dev = dev; + mbox->ops = &zynqmp_ipi_chan_ops; + mbox->num_chans = 2; + mbox->txdone_irq = false; + mbox->txdone_poll = true; + mbox->txpoll_period = 5; + mbox->of_xlate = zynqmp_ipi_of_xlate; + chans = devm_kzalloc(dev, 2 * sizeof(*chans), GFP_KERNEL); + if (!chans) + return -ENOMEM; + mbox->chans = chans; + mbox->chans[IPI_MB_CHNL_TX].con_priv = &pdata->mchans[IPI_MB_CHNL_TX]; + mbox->chans[IPI_MB_CHNL_RX].con_priv = &pdata->mchans[IPI_MB_CHNL_RX]; + pdata->mchans[IPI_MB_CHNL_TX].chan_type = IPI_MB_CHNL_TX; + pdata->mchans[IPI_MB_CHNL_RX].chan_type = IPI_MB_CHNL_RX; + spin_lock_init(&pdata->lock); + platform_set_drvdata(pdev, pdata); + ret = mbox_controller_register(mbox); + if (ret) + dev_err(dev, "Failed to register mbox_controller(%d)\n", ret); + else + dev_info(dev, "Probed ZynqMP IPI Mailbox driver.\n"); + return ret; +} + +static int zynqmp_ipi_remove(struct platform_device *pdev) +{ + struct zynqmp_ipi_mbox_pdata *pdata; + + pdata = platform_get_drvdata(pdev); + mbox_controller_unregister(&pdata->mbox); + + return 0; +} + +static struct platform_driver zynqmp_ipi_driver = { + .probe = zynqmp_ipi_probe, + .remove = zynqmp_ipi_remove, + .driver = { + .name = "zynqmp-ipi", + .of_match_table = of_match_ptr(zynqmp_ipi_of_match), + }, +}; + +static struct class zynqmp_ipi_class = { .name = "zynqmp_ipi_mbox", }; + +static int __init zynqmp_ipi_init(void) +{ + int err; + + err = class_register(&zynqmp_ipi_class); + if (err) + return err; + + return platform_driver_register(&zynqmp_ipi_driver); +} +subsys_initcall(zynqmp_ipi_init); + +static void __exit zynqmp_ipi_exit(void) +{ + platform_driver_unregister(&zynqmp_ipi_driver); + class_unregister(&zynqmp_ipi_class); +} +module_exit(zynqmp_ipi_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Xilinx ZynqMP IPI Mailbox driver"); +MODULE_AUTHOR("Xilinx Inc."); diff --git a/include/linux/mailbox/zynqmp-ipi-message.h b/include/linux/mailbox/zynqmp-ipi-message.h new file mode 100644 index 0000000..173c41d --- /dev/null +++ b/include/linux/mailbox/zynqmp-ipi-message.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2017 Xilinx Inc. + * + */ + +#ifndef _LINUX_ZYNQMP_IPI_MESSAGE_H_ +#define _LINUX_ZYNQMP_IPI_MESSAGE_H_ + +/** + * struct zynqmp_ipi_message - ZynqMP IPI message structure + * @len: Length of the request message + * @data: Request message pointer + * + * This is the structure for data used in mbox_send_message + * the maximum length of data buffer is fixed to 12 bytes. + * Client is supposed to be aware of this. + */ +struct zynqmp_ipi_message { + size_t len; + u8 *data; +}; + +#endif /* _LINUX_ZYNQMP_IPI_MESSAGE_H_ */