Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757200AbcLAXEB (ORCPT ); Thu, 1 Dec 2016 18:04:01 -0500 Received: from mail-cys01nam02on0046.outbound.protection.outlook.com ([104.47.37.46]:31055 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752954AbcLAXD7 (ORCPT ); Thu, 1 Dec 2016 18:03:59 -0500 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; X-IncomingTopHeaderMarker: OriginalChecksum:;UpperCasedChecksum:;SizeAsReceived:990;Count:10 From: Stuart Yoder To: CC: , , , , , , , , , Roy Pledge , Haiying Wang , Stuart Yoder Subject: [PATCH v3 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Thu, 1 Dec 2016 16:41:33 -0600 Message-ID: <1480632094-3621-9-git-send-email-stuart.yoder@nxp.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1480632094-3621-1-git-send-email-stuart.yoder@nxp.com> References: <1480632094-3621-1-git-send-email-stuart.yoder@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131251061365632748;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(336004)(339900001)(189002)(199003)(76176999)(81156014)(7416002)(81166006)(189998001)(50986999)(48376002)(97736004)(106466001)(2351001)(50466002)(33646002)(68736007)(92566002)(86362001)(104016004)(50226002)(8936002)(105606002)(2950100002)(305945005)(6666003)(39450400002)(356003)(47776003)(38730400001)(4326007)(36756003)(5660300001)(2906002)(7846002)(8676002)(6916009)(39410400001)(77096006)(39400400001)(85426001)(39380400001)(8666005)(626004)(5003940100001)(110136003)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB0745;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11OLC006;1:vCPZdw6cBWOUsh2P8vSVjRvrJfucOTDiapaj/vXz2JLVS3EUjASs2c6Grhmka/h2dm5w6CCakpjkJotXWig5qcE/IhidTs6qkmNwWT64dLaKhrEjdO/9Ov3uLCSSIBzz9VhraLIJX9P8wv3UnI2+den+ekeWLswskUvIBb0qS5hqeFAsprrxTV/tl2VmUYxIKfakb77QEUqXV3YPjONkrtuQQI8S1d5N+M3ZYk4ZBfrcFKNjt6c6GX0ypGyb2KFce4/RvR0khBkvKZzkdzJ8pDf8xEDCpProGs8sdOlINDEOy9IXbFWSWbdR0P+aox7y9antjXyjk9IJc2RndT8eutl1J8ePLI25SH71BM8KSY6eCfIq9mRblszuy0R0ouYDiiWCRrPK2CMc2DQpzy0BYkoz9iEEnykTbiaFNVre/WoVgf9cAg54St8hPoKHCondR6D0xGQVQcoG6KkZk2sB4IBdalkN3JsETM70UDz52P0pD5AeqlmGZXjIcdjIPzCJYA1tdCJ0RkH+2OVapZzOsytJiMoBU4Z9yjrsc9u6St5kOfQhjfqZOhkyiYi+NnWuPGR8tcGA9aAhaUYs+SJjINoyYDjYI72o01zeYxC0XlxYmzN4U0BlCeCgRA19YOeCWl7K/0r2lNLBT+hXNnUIYdqSObETIAxPY4+fQJSlMjElCymgjzXibOVBe2v6/PQBGq96UHpPFL0NMi5ogjGEkKNblIGlvy6Wq4PMvaI8/jc= MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0745;2:vrBTBJ9f6ByJPx4IZwPyZrJeAuSMteS/hQpX1xSqLHkHzMT6N0/epo6IMDZ10L7AjaMuypAc2Nn6HiZl58saHioaepmCBOJawz++KffID8V8+xZyf3dVGKErWJ+qqLTqtn5kNk5o5ts/E6XB2wSmuGAN9Glw7AmGpTwuCrYMxqs=;3:Tmsav+WM1IKiqt5X+Ig6qbqHAMneSylTybt/3IRkn4+pIXaf9+VvX4Ao30tatBCDP/Yg6vlORY49GxaXXQwu8ysQnj2zXB19EUxY44GVjuWr+vmoVA8vTzIMoyeFhpdvYf90u3SQWVaVNywjnhVS0XuIQwVyQ/4eqk1jpKRBWS9tn09bkHW7LPL9EpNfQUwFZzWK61bPCfPw6iWuAWthLXOjFcoAcsU0IestOBE6uyoPCDCpZ2PAYAPejDjzM4KbY4XVDlINAI+/m3D1oC3T8g==;25:ZZCofi3ivLBLnzf+JpP9gQvBl3rQijDSXM0ZvEF2Klzxq1mV9qtQ3Em5e2mXeLlxiArgSO6AOh+p5+H1jiXy7nf3PPPLrrm4k3a94KCqglaGm3+UF93zKWLuyMW5Qu4po2GNKSrdHQiKVxXrad/dV2OkegWFoDXvw8d1A54+kKsQ744sN5P3VmTq2XbuMCOvSzqMCgZrlqFBFKMuVLaxXLMYPd+PkANu7ph3YlA2GjGtE8DNNbAL4Jb2P/VD1iBv9Kh7IpkSLMz2TdT3n0KTHly55L8N91WxgoISVSyLZzW8oafdHDS5bn7vra22gRl/1EuhqNJDrOCsMZlVgRqiXSnA5AY0DkNOp/19uXvp6vz8maXfKXjsdSGNdvE8Y0HU8Fy+7oyvpNlgHU5BWKVn3JhRYywWplo88FbVmxYnak8umMfxbox/QsBNUI6ogxyCavWe0i5WnIgxRoBmmtF8Bg== X-MS-Office365-Filtering-Correlation-Id: 6d58f80e-8300-490d-6eec-08d41a3c3b8e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY1PR0301MB0745; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0745;31:P9ycL90k1qoXog2nlf6xdY4N9SjY5ougD7K3HZjoGdiMtzWO2WcqnFH0N1dWYSk0NZEfl1kO6/761Cmw21/nZEyNPY6FonnhqNOneGKg3WUBQo5xqicxCgW1nteE6kDYaFb7t9RDit1BzuENCEMfEF2r/um0agE2BvEQQcsdLMJm/+yS34LIRoNAwg+qlLusY4kSagj12g8vYSF7PCjOH50p/GDW46hxPpJpCIWBobzDSqStudwvCwTIK8JR0+ySiA2ZJVPiCDbgMTX+sekqRw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095060)(601004)(2401047)(13017025)(13023025)(13015025)(13024025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6096035)(20161123563025)(20161123565025)(20161123559025)(20161123556025)(20161123561025);SRVR:CY1PR0301MB0745;BCL:0;PCL:0;RULEID:(400006);SRVR:CY1PR0301MB0745; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0745;4:KwndA0uacfs968KG6wS0DRwid4XAZJJETbImHkAZDTm4nkvBVrOtN2ey9rqADRptoKL9ol8GwJPkSU33MXJEajlrAnlNCukHOfkLoNMhY7zMhzbci2PLBxQtJr04O8N7fKez9ZrG/waDOIDYO5M0z8Ey85MZdmla51cMNLxqa9YyVcushPCqVxW2Tl0VpA/A6cnKea7hjLs5Pm0YF2e5iSazFsIZ5ecThXEnWCEn5Q7zHGzPvEGzC78FPCNqoIFbGkDkp45emDoReA4gQR6RKlvDCGfs/s5JoF8pi4Ptv7RFgOSJXchjy2G/DulKI6tc9Z5Zm9vkcJUo+ljrgakT7sS+XxcTyCqXFSCllgV3AuTACxFs7P5ZiTNPToa3Vn4oY38hhkZlxYogfI6GHmg99lHOuHQKBesg08PkCGpGyVUuXHTgnJpJjb8lT4tTSKLe87BTZaTQ5M0O+CEmn4nN9aG9Mc2XCiGIR9RcTnRNBGX9Sa+mW12YcwKvwmJbjNuK0ADsAMV/AwSgz46AeEyPI03DAxvYIkns0sNuAfyAerkoKOhzZZcn8Ay2FmDyh02UTef+K/0mnXAr2oHwixz4jKaIu2WIdoMIFq5gf3l46Naa9GfPpJcNqrcUe1St/btJ/Pjq7HUc+g3pui6k51xEYAkE1Frds+7QGPLcW5j8XSoQWr0XNUM0s4rrYJYgjx1i+OwgaPgz9kJr1aX7wkgg4RuDeZ1T5sPJnahSa9bhMn8cjR+6rYGmaG4jn5MGez5DiLCHm0ucEtLwoNuhEcq0zA== X-Forefront-PRVS: 014304E855 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB0745;23:CKXSv1Bn5NHKsvqwPSVBVyIbm5p3Djj+tcIuimH?= =?us-ascii?Q?tyw06A8I1lIcfPyHXQgOdt80fCnndv7DiRiE5xKehCBnw2C2pqng51l4ch7E?= =?us-ascii?Q?Zer+fcZLZKPk56yBB9uhlzH0TwDeE+JP+xV0Ww3IkwRhGCp5JvjJh53bxiwp?= =?us-ascii?Q?Lf/A+Wio2hhLfLNz+WFAoeD3+ADvVvSQCg+UeP2geo6SDi5uEPbTv0dGrZU8?= =?us-ascii?Q?W6WABJwZtUW1Uazu8U2LRfVJREDmh3K7mTQiaRpxnh4c/A71OmrDfgPMvlvf?= =?us-ascii?Q?WlcdboETaRDZPEEk9Ro0PmPX/Hb2SUPxt5CJ31XcUKNFWN0s+lj55TAfz305?= =?us-ascii?Q?BIIqYERffscvaxTRfVvraDrnaFdbUGbeaP+y/W60mfLg6mQuWhuu6qawzkZy?= =?us-ascii?Q?CyoAx5WAHh75WQu0DDJqixkypi8F1pLLDTr9TvmJhnBwxD/S9OlgskWWtj4V?= =?us-ascii?Q?pVM1rBZ7PhOKadDGXmVTMXpO4fNmPcezlAtWAer5t6QBwxa+UEnbOYgHmDEG?= =?us-ascii?Q?e0+GVAZojg3LPyShI3fbEVvSgyVEFs4RA2wfw9yMNE5QbzLXhcsJzZ+y5dmu?= =?us-ascii?Q?lojwypD//DUKfBhDYW3OCsKPf/ODdAhwzEMdRXbVdO2RiKkvTT8eTOcl4ufe?= =?us-ascii?Q?hhIQLqIhqPEB/AXA54O2lWpdRiovFkZ+iITX9ZjzcQPKU8Q624mAaNOhBdAD?= =?us-ascii?Q?Gi11sYHwYAQISxn565EoJpypfdq3189O5nSNojuCXjbia2xW7UNxiaOtt+Lm?= =?us-ascii?Q?oNwxyHDdTSjETtMOg8+5ocXGeeQXqlqRR0E/99leOOtMmtd1yt14hSULPdJv?= =?us-ascii?Q?FPXXuKsUmXtYvSJ5CdZ6zQBEBeGTTVzBkmFzf8hs+tMRaHuukG0W6PHG3Ln/?= =?us-ascii?Q?viI6QzkTIJPCrfEnxa5v+bW7fEi4oDB0dGaOlWWDHNq0gksZOrb++v75bKoC?= =?us-ascii?Q?EHHS0lemM8yrz3T5H4Fg8CWVws8JfOctd66b60U2RZ3PXxveNLEtfGux++qb?= =?us-ascii?Q?HFw26bEJaFzbY3fOq7XAl0EyjV/gqMphDrUP4OwYItgR0LT0N0eJS5Bd2lIM?= =?us-ascii?Q?CAzgy2akimpwpX1XcKKgGjWuk2k75vLX/xN6pagkYzfwuSbrSbs6IoFacKbl?= =?us-ascii?Q?1poBQVqube9Dt89F2nsJ6yWb2moctGlU7DrPMiSWRYtcEFNggKXN/JS5LnDf?= =?us-ascii?Q?tsUevwxI2y3d+AJlR4ky6ogCSsNkVdJu/DjwYi+BGxV1+fdYhLZPaod3pBvF?= =?us-ascii?Q?lKi+1XShUiyqG3YKjtfTt6n9AARKg6zSZ48NDTVZI?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0745;6:10Q5DpQq9g+Lxtq14KcN0fz2lPq4F7R1MIHngB6PvBkzoY0e51773fYDh0s34WVTdvOemOQdhDo+jGzZ7GJQ5Mn+lF1MiThBrVNEs3jooGXP1bUB/kUchDpIpZp+fzuBAo4BljOp6aY2s5CBgD3dW8wzY7lPruLwDECb2iET8GJxeld17JmGPXIgb8xRnwJvAaC7hYP4clxD8E+TLgHRwx9mlwq4/1ci1anx808htGhwHtCidZMPLAg6CVodO6bhpj/0jsl0Bqdnr89amU/x6U0NGHZDZXogokdsQCpfKBtgokjqafDjC5KEm9fOM6YrOOBJOtEdME+Wy0avdaCauA==;5:ZfDAenx4XNjXVT+Gx7j+KLL6YbO6PYGKNmFueV0YT2W/6YFBRDABsN9JD5jRC9uqy+tzIUE/2FtAliIAowS4J3jMJPydHt23kKnfqRS5enrZJEOi+J9WBLos0U+GdB8uIBoCZ+hqebHmA23cpULB23PWnzUai5MFbZomMG0bl4fxj9zO8ym/HZlb3kB0RWzr;24:JW14kQxA2gKgLvlOyiIPHkFt/oclFdzfkUvm3pHX89zTmJ8T30mbqOrIub9G8yEvEQTn3J+MdKvAQQ3BFy3/Bg1RBXib7gkEBHQCwl1mLyE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0745;7:xeeUtlSJylkJ6JyRhwJ3rR2ctbHsF1ss0bhSqAwqrvZkJ3GMADF+PVDZgsh4nFI2I5ZPT87KfnH47ZDW73GlskoxqHAjqm0PqpB3fzqDVtn1GWPjq8uSYGUZjJ4/v1Bow7ulE88u2Tn36na0Imin2AOql9JvI6uMZPmMmKybTw0DiPLAgLCEIVGp7BgZcnYLMuACTip3E3Ugjj8H0rjYoI2DoWx6iZPsuVlzAgJfPShYAFAY5zL8nKeoREfnaBKX3iz9eyB01fQ+VgtS4W7eKBukhEcSZo1iaW7fhOp+MUaT9SACTdE69vdm135dNLvUt7TitWHo4VvY7eM8YZ+vCFq4VDhZAC9kf2lfIYTVwOE= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2016 22:48:56.3916 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB0745 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9672 Lines: 336 From: Roy Pledge The DPIO driver registers with the fsl-mc bus to handle bus-related events for DPIO objects. Key responsibility is mapping I/O regions, setting up interrupt handlers, and calling the DPIO service initialization during probe. Signed-off-by: Roy Pledge Signed-off-by: Haiying Wang Signed-off-by: Stuart Yoder --- Notes: -v3 -no changes -v2 -handle error case where number of DPIOs > NR_CPUs drivers/bus/fsl-mc/dpio/Makefile | 2 +- drivers/bus/fsl-mc/dpio/dpio-driver.c | 295 ++++++++++++++++++++++++++++++++++ 2 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 drivers/bus/fsl-mc/dpio/dpio-driver.c diff --git a/drivers/bus/fsl-mc/dpio/Makefile b/drivers/bus/fsl-mc/dpio/Makefile index 0778da7..837d330 100644 --- a/drivers/bus/fsl-mc/dpio/Makefile +++ b/drivers/bus/fsl-mc/dpio/Makefile @@ -6,4 +6,4 @@ subdir-ccflags-y := -Werror obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o -fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o diff --git a/drivers/bus/fsl-mc/dpio/dpio-driver.c b/drivers/bus/fsl-mc/dpio/dpio-driver.c new file mode 100644 index 0000000..76261d2 --- /dev/null +++ b/drivers/bus/fsl-mc/dpio/dpio-driver.c @@ -0,0 +1,295 @@ +/* + * Copyright 2014-2016 Freescale Semiconductor Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "qbman-portal.h" +#include "dpio.h" +#include "dpio-cmd.h" + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_AUTHOR("Freescale Semiconductor, Inc"); +MODULE_DESCRIPTION("DPIO Driver"); + +struct dpio_priv { + struct dpaa2_io *io; +}; + +static irqreturn_t dpio_irq_handler(int irq_num, void *arg) +{ + struct device *dev = (struct device *)arg; + struct dpio_priv *priv = dev_get_drvdata(dev); + + return dpaa2_io_irq(priv->io); +} + +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev) +{ + struct fsl_mc_device_irq *irq; + + irq = dpio_dev->irqs[0]; + + /* clear the affinity hint */ + irq_set_affinity_hint(irq->msi_desc->irq, NULL); +} + +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu) +{ + struct dpio_priv *priv; + int error; + struct fsl_mc_device_irq *irq; + cpumask_t mask; + + priv = dev_get_drvdata(&dpio_dev->dev); + + irq = dpio_dev->irqs[0]; + error = devm_request_irq(&dpio_dev->dev, + irq->msi_desc->irq, + dpio_irq_handler, + 0, + dev_name(&dpio_dev->dev), + &dpio_dev->dev); + if (error < 0) { + dev_err(&dpio_dev->dev, + "devm_request_irq() failed: %d\n", + error); + return error; + } + + /* set the affinity hint */ + cpumask_clear(&mask); + cpumask_set_cpu(cpu, &mask); + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask)) + dev_err(&dpio_dev->dev, + "irq_set_affinity failed irq %d cpu %d\n", + irq->msi_desc->irq, cpu); + + return 0; +} + +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) +{ + struct dpio_attr dpio_attrs; + struct dpaa2_io_desc desc; + struct dpio_priv *priv; + int err = -ENOMEM; + struct device *dev = &dpio_dev->dev; + static int next_cpu = -1; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + goto err_priv_alloc; + + dev_set_drvdata(dev, priv); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_dbg(dev, "MC portal allocation failed\n"); + err = -EPROBE_DEFER; + goto err_mcportal; + } + + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, + &dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_open() failed\n"); + goto err_open; + } + + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle, + &dpio_attrs); + if (err) { + dev_err(dev, "dpio_get_attributes() failed %d\n", err); + goto err_get_attr; + } + desc.qman_version = dpio_attrs.qbman_version; + + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_enable() failed %d\n", err); + goto err_get_attr; + } + + /* initialize DPIO descriptor */ + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0; + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0; + desc.dpio_id = dpio_dev->obj_desc.id; + + /* get the cpu to use for the affinity hint */ + if (next_cpu == -1) + next_cpu = cpumask_first(cpu_online_mask); + else + next_cpu = cpumask_next(next_cpu, cpu_online_mask); + + if (!cpu_possible(next_cpu)) { + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n"); + err = -ERANGE; + goto err_allocate_irqs; + } + desc.cpu = next_cpu; + + /* + * Set the CENA regs to be the cache inhibited area of the portal to + * avoid coherency issues if a user migrates to another core. + */ + desc.regs_cena = ioremap_wc(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + desc.regs_cinh = ioremap(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + + err = fsl_mc_allocate_irqs(dpio_dev); + if (err) { + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err); + goto err_allocate_irqs; + } + + err = register_dpio_irq_handlers(dpio_dev, desc.cpu); + if (err) + goto err_register_dpio_irq; + + priv->io = dpaa2_io_create(&desc); + if (!priv->io) { + dev_err(dev, "dpaa2_io_create failed\n"); + goto err_dpaa2_io_create; + } + + dev_info(dev, "probed\n"); + dev_dbg(dev, " receives_notifications = %d\n", + desc.receives_notifications); + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + fsl_mc_portal_free(dpio_dev->mc_io); + + return 0; + +err_dpaa2_io_create: + unregister_dpio_irq_handlers(dpio_dev); +err_register_dpio_irq: + fsl_mc_free_irqs(dpio_dev); +err_allocate_irqs: + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_get_attr: + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + dev_set_drvdata(dev, NULL); +err_priv_alloc: + return err; +} + +/* Tear down interrupts for a given DPIO object */ +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev) +{ + unregister_dpio_irq_handlers(dpio_dev); + fsl_mc_free_irqs(dpio_dev); +} + +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev) +{ + struct device *dev; + struct dpio_priv *priv; + int err; + + dev = &dpio_dev->dev; + priv = dev_get_drvdata(dev); + + dpaa2_io_down(priv->io); + + dpio_teardown_irqs(dpio_dev); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_err(dev, "MC portal allocation failed\n"); + goto err_mcportal; + } + + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, + &dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_open() failed\n"); + goto err_open; + } + + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + fsl_mc_portal_free(dpio_dev->mc_io); + + dev_set_drvdata(dev, NULL); + + return 0; + +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + return err; +} + +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = { + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpio", + }, + { .vendor = 0x0 } +}; + +static struct fsl_mc_driver dpaa2_dpio_driver = { + .driver = { + .name = KBUILD_MODNAME, + .owner = THIS_MODULE, + }, + .probe = dpaa2_dpio_probe, + .remove = dpaa2_dpio_remove, + .match_id_table = dpaa2_dpio_match_id_table +}; + +static int dpio_driver_init(void) +{ + return fsl_mc_driver_register(&dpaa2_dpio_driver); +} + +static void dpio_driver_exit(void) +{ + fsl_mc_driver_unregister(&dpaa2_dpio_driver); +} +module_init(dpio_driver_init); +module_exit(dpio_driver_exit); -- 1.9.0