Received: by 10.223.164.202 with SMTP id h10csp19547wrb; Wed, 29 Nov 2017 16:10:32 -0800 (PST) X-Google-Smtp-Source: AGs4zMY6pJPWf75ERCqbgjsa/uDUdXdPkHhbNywXK9sZNteSVtcnLlXYsk1fXGaFWeMDs4fSQtEF X-Received: by 10.84.171.193 with SMTP id l59mr637959plb.33.1512000632364; Wed, 29 Nov 2017 16:10:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512000632; cv=none; d=google.com; s=arc-20160816; b=uxv7+0E0QmViswXVhD/H/AMbE4H3/yTMc33+2o5VWKHLkOyJJde88Sm61ZwSYeAK5t eSGreJVHFSTY3eW1FEXgC7aJOLYh0CL35WuOuMQJvXqn/hJ4CPLux8evH7UO72ImKqbp 8IBkvJEvdZgJxALRYpDU7xvG9VVn3zqScCA3h0wv5V3yvnyQT/qqGk4wH6x0jS57nUJ3 yZQsGMCqof9pGZkJ4NM3jY2jouyK9hFx6MRpJeUBQEkRTsfyXRATEP8iCfifp1+FHBww L7376RWSpB3wYdrZyuZH9FJs5XhtiL5XlxWilI126LQwOxD2celPq/KFI3gqpin/0V2f D/xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=UK4bWEuzv2iReyLner0hiaBf5RrnWhZHsCPKhtP3O98=; b=ietm8LR5gZki0iW2dbOVGKyg4+xbTmD/7EKY0jhf5kPv1nhaorkazJnbsVdzMiRt4u AzAH3j8dqUV0p05TUH+kIEcBrQOtVRRk7H1oLTim0cjXLMwcIP7Dr3CG15hyzY9dmljW cDWxiZuNOq4usZaxY4+QP7DMhUXqwrk1JFALcQT7TWDad8uE8E0IBcek+BSPrhRDjAWl 4O5tcAunyRdEQSScAKjFmM6pHFPdY5bgfFUCJf5pzxyNZfllJaufQ0LXyhXGC7xHgNn+ 8EgLeAoOuU9w6kMSH9D4Qf96DC+oUj5bFvV9Iwuny0ccl2WGrL/q0ojN8rFlsSAoarj+ 18oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector1-xilinx-com header.b=G+NPz5Uh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 r7si2072784ple.415.2017.11.29.16.10.16; Wed, 29 Nov 2017 16:10:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector1-xilinx-com header.b=G+NPz5Uh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753501AbdK3AJ7 (ORCPT + 99 others); Wed, 29 Nov 2017 19:09:59 -0500 Received: from mail-by2nam01on0048.outbound.protection.outlook.com ([104.47.34.48]:22428 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753060AbdK3AJw (ORCPT ); Wed, 29 Nov 2017 19:09:52 -0500 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=UK4bWEuzv2iReyLner0hiaBf5RrnWhZHsCPKhtP3O98=; b=G+NPz5UhZ9KqzkNxtz/BgDDA7H8hkQasoyT2aKzLccpADEo52Zn7OAEyzLjulrX2sxHIwEhXI0rBYuv2KHaIKKUHXEonNRW8IfnSUtTMc4NJqc3eXEF1rXtzWROqwqSuzecwPit+xO55rxF56AnRRGKO1Mg+B+0+STgvRO/D3hc= Received: from MWHPR0201CA0007.namprd02.prod.outlook.com (2603:10b6:301:74::20) by DM2PR02MB1338.namprd02.prod.outlook.com (2a01:111:e400:50c8::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Thu, 30 Nov 2017 00:09:50 +0000 Received: from BL2NAM02FT025.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::202) by MWHPR0201CA0007.outlook.office365.com (2603:10b6:301:74::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.282.5 via Frontend Transport; Thu, 30 Nov 2017 00:09:49 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Received: from xsj-pvapsmtpgw01 (149.199.60.83) by BL2NAM02FT025.mail.protection.outlook.com (10.152.77.151) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.239.4 via Frontend Transport; Thu, 30 Nov 2017 00:09:49 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1eKCQG-0000Su-Eg; Wed, 29 Nov 2017 16:09:48 -0800 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1eKCQG-0003us-AH; Wed, 29 Nov 2017 16:09:48 -0800 Received: from xsj-pvapsmtp01 (xsj-pvapsmtp01.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id vAU09g1R004248; Wed, 29 Nov 2017 16:09:42 -0800 Received: from [172.19.2.167] (helo=xsjjliang50.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1eKCQ9-0003sy-UC; Wed, 29 Nov 2017 16:09:41 -0800 From: Wendy Liang To: , , , CC: , , , Wendy Liang Subject: [RFC 1/2] mailbox: ZynqMP IPI mailbox controller Date: Wed, 29 Nov 2017 15:59:06 -0800 Message-ID: <1511999947-8274-2-git-send-email-jliang@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511999947-8274-1-git-send-email-jliang@xilinx.com> References: <1511999947-8274-1-git-send-email-jliang@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.1.0.1062-23498.005 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.83;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(346002)(376002)(39860400002)(2980300002)(438002)(199003)(189002)(189998001)(39060400002)(107886003)(478600001)(110136005)(4326008)(305945005)(50986010)(76176010)(2906002)(6666003)(16586007)(63266004)(2950100002)(54906003)(5660300001)(81166006)(36756003)(356003)(47776003)(81156014)(316002)(8676002)(106466001)(77096006)(50466002)(8936002)(48376002)(33646002)(106002)(15650500001)(9786002)(50226002)(51416003)(7696005)(36386004)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR02MB1338;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;PTR:unknown-60-83.xilinx.com;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2NAM02FT025;1:TPLQ65Wj/bdAvoAaVgI7UflWkF3YykS3Q+QrQkDfot30hnyyKwPnYu/BG9+ijQ29TA2t8hbaaBT917QDb2eumitjkSVnZUJK4HFUOEJjXPspa6za2EjFGM0qCJc7HGzO MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 457326c0-269c-42e5-698b-08d53786ac14 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603277);SRVR:DM2PR02MB1338; X-Microsoft-Exchange-Diagnostics: 1;DM2PR02MB1338;3:ygRmsZdG5se1/H8cz1LDsAqsKxpZZKA2GKJRrmwyMSuudidS1oqM0nlc0XoJAspGhgCd7jyLKbtemKbmqiaNigI8wqf7aWbiqZ532eHBI23ukSxWW0G02xD4f8JtPOaKuRC7/Tn6IPn3e0FFLTc+DIrDlwerjbTc84aT+iApNmtEKQclHaKkbA5weMMvW/65Q6xzQysvwwOAeK4Qwz+ANI64z0zMolPyDSN8JEG6H1ph9YdmdYslUaKsAmvEKBVIkAOm5Bw5k4lcNxMG1J9PkNfS2j9Kp0FakUjR3EqL1WVrLyGKCUHNnr56225Lqh/ZOi13SEJSaSfNutquX65Fin2tubxU5FK0yaP1hlw7JvI=;25:1W2ja/HgaMzl0hJiuzdpfq05Y23+12FyX9MSXuaxUdR+K1H6RiubBS9h2e7/Qbu9gWwql413WGSRGVT1SyOGznzFw6Bf4ufxtvH+V+N6Dwwv/JGVaTFlWGmYwgVw6+4as4MiiOyhyeOCvDagbiz2kp+zt8cJbjMSM7Kzc23wH8wnQYd+tNtpuf+nA/K3a8rdl8me51m97tXmppmc5u/SVeMdJOt5mp1nAiVVyUBt1KklTbQ5sMKq7v+VdX4JTUmBSfJQFwIi5j/Pvw0jRlFmUHPPGkydgWc0lUui7T9asIz58T7MOWeeVj30btMHcUDpmRuUu057hWBT7uC/fVLAGu4glrHKJnw/oQX+qlTn+O8= X-MS-TrafficTypeDiagnostic: DM2PR02MB1338: X-Microsoft-Exchange-Diagnostics: 1;DM2PR02MB1338;31:o7/NkGVI0tjNGuSYtrJmU7S32Tbp3wV2HCcYVKniRwnuiWC8aZmU6HiwbKYePx/5Fb0rjtqtM84KmEzgV+VvS9xloJ2h3Zea/3vdTmR5OutfMzSCIOdLmYq9xWusxeG5of2cBlojCy4IGJSmldrGyKvpyOuXUV2rLjA2FtFq06prSF2qXwk4FDvh1tdxABjxKGUaOwzrf5GzXayYbrk2z6V7EZkz8lvGaobWmlLu0y0=;20:ekyedDelDoEc18c8TugptYmFNZIc3INGnujFSliIQEL0ZHlieVyAYN9RVvlz7A/wZkdXahCQQ5p3Q4Tx4VDSoNcH2LWeGg9Dzz2aIk1hFFkxVBldRPLt7kngN+BpvcSYfqW6ygIqrXuixG1h4AAGO/TYgKE+zzsWjklQdgpeADmyFhtkd5Cr9xrBiuSpVqIwJsD3lpk777Ks7U1gnC3fPEVa7hXeOHHXslMlV10bFYrOX3GsE5ZP+DXqy/NnisyW1POshNiTrDirO/h42mJzOGROCxq9c7Jzfl3XTDF1IAMayMmR0r1fHe/ZeBWZuxrwgDW+YpyjW7c2EWcIYdMKTET4NGDf542KpfTrvRC7Cju0UbRYL10PAjoX/rq979fVQv2Ds1AnbMmjXUDKRKyCrvvV6rPSGAJhvXlfTvEGDe1nrq3VkZ/7BrhNS8Yq6mlI0wsxyv3ol8kr/kF/p7IE5qRrCnrTf0/xjCLcDNpCcU0selrWdt+yGw6WZ35oXhrQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(93006095)(93004095)(3002001)(10201501046)(6055026)(6041248)(20161123564025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(6072148)(201708071742011);SRVR:DM2PR02MB1338;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM2PR02MB1338; X-Microsoft-Exchange-Diagnostics: 1;DM2PR02MB1338;4:I85HLGvXOAW6epl2lUnij/cT7QtlEvduKhU4xLEHyokw4tSF8kM/uLnt+zH+key5wOjuwxHNaYFfvNAm4QUqglMgLye7UIrJiGUWn0fNtk0ct1Z1YPkRlNIbg/OW/DhS42SDdDJzYzsfO/VWAl1SJjKISKIcqCfPJ+hzfcjAH25oIbiBgr/L5IlcrMoMueToalzCUFtNffRbMqY0E0htsm7WFX8xd95MrhddW4B5IfdApREDFE+8idWqbDI5CTPr8Euf+zpPRuhZsTAAWp3y3HlQ3u7Dvc2TF2EIsdSieqlllUxZbnlN3j4mFwwLQqdS X-Forefront-PRVS: 05079D8470 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR02MB1338;23:VpyhzzOwu90xFTvPIykD38hm2+ZhW0RgE606+aX1k?= =?us-ascii?Q?gB0GJugNntbQRsHyJFlIMmH+jHAEnSQS5rAW4cHTeep5ZWI8ZmmFUKXAgo3c?= =?us-ascii?Q?8c3wlkMp/CKvNXEgJ7C9fBTBAmPDco1Zn6JrJjPU5GPs74e4OSmyYe8XebSC?= =?us-ascii?Q?1VoCJ66YkzFLeXNmPYCumNyVBCIoIoq8wPQE+C4akJHnCK+KlrSpDOqeoSqm?= =?us-ascii?Q?5UTXBddHX1XWcjf+7Kavyrt7m4KdsDM+Ar6Z8uDvbE9tpGWIR+yA89c/nZkb?= =?us-ascii?Q?RAIUfX5uT6eIWxWcY5ofGG4EXPwA6elHoxbpwJS3NSDNHz4gL5DmB2vOvanK?= =?us-ascii?Q?gBz5YTJTKLw3TJ/mZHOlxOyzSAowTdp/Oej7r0JygEkKnYDgnEJNDRL0+HiB?= =?us-ascii?Q?VlFYCjfzYGWw/SJ42WXDvoZP1YQMQvuXjLlKEF4/a3qL207UIvG3z+KoHJMS?= =?us-ascii?Q?hOPyFc5/S9bMOkg2N09xCpxAjT9IK3DzWDwizraAJmwFejHCpxvA63kYfyFj?= =?us-ascii?Q?bR1+rflODplHPsuJwtoyFOyKJ/alH0kxUwOoN2ulhf9MqjOhfFGvDK5Zcg+B?= =?us-ascii?Q?l0qioNG+QdoforXXL4F3h17jmlnIQdYYIfU0VkMbNq5UAxfcVwdl5trYukC1?= =?us-ascii?Q?HikDn78QQP6btX9OJ+0MglYiA09lYzmWlxWpQip68lAvgPl71CaurQsbYKjg?= =?us-ascii?Q?bns+Svp7XkiJhGbS+b8d9T5f+KZBt1y7UEYhRpVPLxHILDBCpZR6igdvFPx5?= =?us-ascii?Q?hIkbG8GJVWlN2qDtcaAbveaHJLD2edl7PfGwEe7fETBHiEbz5Lv2CPnO2K5g?= =?us-ascii?Q?8DDzJ7xOaY2SStQZw6rUScxkBr6MkLpxEdwRATC0gdpHEh8Hrpeyw+XXkqnM?= =?us-ascii?Q?Rb8x5LyCLZwmyCwltHrsVYPpTItL5lXBPJdo13ZnAZvD4ZYuXk44iojMAy5L?= =?us-ascii?Q?YfTjWwZUazqy4KBm5KIb16VIZFett+r1lTHffsh0Ep0/bAvBPZRFZQePp/ax?= =?us-ascii?Q?Rz3yxqdlYIpFZ2QeCkatdz7MjVgSj4fXiMiqBFM1AR2vgWWZ8UpsyeHZiAxu?= =?us-ascii?Q?BrUNvZnzzl+cn0GS/2fAsT1NpuY?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR02MB1338;6:WngKBbZZnj+9JMKFDY4VsdYfoeo3aVGMgfTbX6kQyqSz+kgJN2uEYIqE7g5gkSUua+BCzRB1rZzUt7EMxp52j/WSsY/u5Ps/QvVzgjyX6UVRoexjVOrJUVbCFhl8VRGXML6D90VxkIEJBrTqrcm82nRQlqhOZuJoRRAnF0twez6hDxcUkshyO2yH5/+9Juc1TShuCBliP4nZxX0/mcZdRMftY7g2S0vrJNBtyTuS+sLSzMzqAjvX2/ZiUp12fiKXWL79XrublTyh9RAJ/bMiPGQrvALkydCWCmRsxYfs/lQmCzd6/5he6rbd8bvEfF2NDGdy4wt4tnkYIxuvXszk+Q53Q2SJTuDsIST50h1onKI=;5:7rCs2fFrCYvpZS27T8MLtkklQ/TVDqhSS0eAL85R9IzazEh4eJ4In5nOydtC7F2Xy9+MVjdQ6v4ci+JjPubPsDrBn7SiI4YcYK/biamN3jW4t17FwJmb3ci7iCNx7e/SjYGKiIC20O2XT07Efn+7yl/m3gwxzvftuAZ9ZlZTK88=;24:2VECo5O0nu1wQlD75IxhQzc8CuMg4cCPcVw28+4Qa9/ifb31PKXGXPcEmFbTMS6n2a5+PV512A9NUbSndB9lLJYupL/j2meL0peiSYpES8A=;7:1wGj0xUnAXxc8wMy3vObblgVPRXzjiAeeApSvUYNNQ3JQa9dwFpI82TUTrjWHuLLb/vR37SLL/SLQC+7oaqj+76g9mEkJtb/xuVwTHaUsLg+IN4t8jbZJlopR3IDIFbGUUOKll2qM7aM8x5qWuEAvjK53YazuEabUX5B64nXNpUS7PRDKHoLmwA/3VPO+lK7YnddyNHtBc6CUwLjoSs6bAFRlPyxWGWm5un1r6FgluKy5Vi6muhrR7l8AoWqYReF SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2017 00:09:49.0894 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 457326c0-269c-42e5-698b-08d53786ac14 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.83];Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR02MB1338 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 633 +++++++++++++++++++++++++++++ include/linux/mailbox/zynqmp-ipi-message.h | 24 ++ 4 files changed, 667 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..229f26c --- /dev/null +++ b/drivers/mailbox/zynqmp-ipi-mailbox.c @@ -0,0 +1,633 @@ +/* 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) { + spin_unlock_irqrestore(&pdata->lock, flags); + return 0; + } + + /* 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_ */ -- 2.7.4 From 1585482840350735972@xxx Thu Nov 30 09:31:03 +0000 2017 X-GM-THRID: 1585313375333417645 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread