Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752968AbbLKS21 (ORCPT ); Fri, 11 Dec 2015 13:28:27 -0500 Received: from mail-by2on0148.outbound.protection.outlook.com ([207.46.100.148]:9888 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751733AbbLKS1O (ORCPT ); Fri, 11 Dec 2015 13:27:14 -0500 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; From: "J. German Rivera" To: , , , CC: , , , , , , , , , , , , , , "J. German Rivera" Subject: [PATCH v4 05/11] staging: fsl-mc: Extended MC bus allocator to include IRQs Date: Fri, 11 Dec 2015 12:09:43 -0600 Message-ID: <1449857389-2506-6-git-send-email-German.Rivera@freescale.com> X-Mailer: git-send-email 2.3.3 In-Reply-To: <1449857389-2506-1-git-send-email-German.Rivera@freescale.com> References: <1449857389-2506-1-git-send-email-German.Rivera@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC008;1:7ET9WVipQ68ZkBHMw6dgTh3tqT5X0k4p+Du3L/+RNa0BW0lA9ggs8Ta4qK1vln194BNiomnZaUssMlGmFvVJRNlL+wI/8sHvXKt4MCRs+YNeFKTAm8HndHid0kwczXnNRxljOLa2NOz4ApY5NfcFEuA0+oka6wHoeGYKBpLrQlckTWOn/oFH3aQwxTOU2G8ddqpWrzya7sHbZynhr0LAThQ7v1seaUrtNVnRsYQrkjbiozlY0B0VBRNCmeLCiBocBXSGPtY6e3rDKxHvCx+ORrcOHnsoTQ2+Cf3VAZ3D3qhrVCIe6SHLlvNZ5ROB7DtgenJSDp9+lD0sujUAeta7x4OBs+eWnrSktIdNJplL35uv7RE3eIyMk2FWhbNtpovWE8EkXTZG1M8UlDC5EUxU4u9/5N6o2E46Q9S5+BebtC/9TW+7/QjDvhNwYtlH2f2c X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(448002)(189002)(199003)(1096002)(92566002)(229853001)(1220700001)(106466001)(4001430100002)(586003)(5003940100001)(5008740100001)(19580395003)(19580405001)(2201001)(104016004)(81156007)(5001770100001)(6806005)(189998001)(97736004)(36756003)(5001960100002)(107886002)(50986999)(85326001)(47776003)(5890100001)(76176999)(77096005)(2950100001)(86362001)(50466002)(87936001)(50226001)(48376002);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB506;H:tx30smr01.am.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB506;2:JVzv01Sh3CB8djRkOt10Hcj9C7etAvCIGpBZZhdLNJZdKx/xHg8iOm3TI1iPnTOWVsdK0tp9UbD/AfmV/649T+8BVt3fpILrENzM3hkHMJrhCZYfPSzI/qb5gTTNqWCmNBNcQZK2gILuIyvAdAyDpA==;3:O2XRUq7woVswku/j9AwNI5R+n9GkVoSa6BnbxhxUQV0Eajri+0P+Q72KsB/P+QIlcSN6zt4vJZ3Vehqes5/CYNJDvhE6ZwduDyqFWpZGlLaqTPQrKYn7HjOl2hWTuCraXIjaUKqBOhEHpKDIkfawKK9Q7iNCHp691visDh5Ee+0EkKf8DcZHTeE4NgY2Ndc6zYyoajdkcZOMnRsb6IPrfjGsZqOaery+xDcgW8VsogQ=;25:w80S+eK/NZioQrYQ/epvb2lMK0miP6sNlDaotjb1wLb1i8I/dFo28l7xdXf1v2NvQuHyXv43jsx2J33BBZuYYYpGRK+vjwIzzXfZyVp3gB/Fe6CGhbCvZNPKi2cPZ73NoUL7sTq3IeeFrM1fK8DcRz2j2exLS5ZPB7kz7ADPkinAb/ReGGlPrZ9pXZOOSNSeDLBoduMVCms+h2oKm1Yr4CttMFURQfn/+oFHema9pkx4jrCyJpZP0ljFqyrbWUp5N0t0CUNADf9Kc8m5vUJruA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB506; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB506;20:CabnI6yxWoFmTuu6GkiSX+iN/T1WZMeG5wKNWO93dWl4X2Mr4FlXOwLb+zxze9TEXsgcL2MtRztYDPjfj8+fKVaISpqa0neBOp3fXePtW+OQ6e2qShYnYI6nZ+Qps34zYu1ByDIfK2hRYbBeVbJ8QqGsYvvMY9cL7EhmZgV/s1TKramsh7WPsGcVgde1BY3HLyqNCJvmYkCMf8rkzEFKEbIjHDqRu4H8esExkiK6A9dp7rnwnN8r5nKHvB/eowUBPQWSwjjuqBe46hJqpjxMFgNc48h2SgZUgfqyfRzIhiWCHojFltKXuLaHK1ItWh0vAkf6o3IdDlzxu3h40nTcYp4SRdTry6E3b54kCoSmvfg=;4:yayx73SfgXmG/n9SzsGOJVMngwcP6kMFeFA5wFtWtg2XbtD2DerEzANB/S80fdhQ3MaFS+iiy1S0RiFEpwRt9Zurx/TkScYV3lvkQpNJ61ln0s+WWy0gcmzeGoP9i+S+DqNSBFSN1lwRmYSs0aE9lu4Msz+xKN594P6jUh3ZpzdWJx86rX7ywD9jnwHfCl+BX+ObslscYBGJwzFuTnspeBr4/gBYSjjMVe0E50gH8segr+2+cyqExH9Qgk4ngvktaLtUCO7ZvNb5spB4GWDAYGznlf60+cb+CPETpkIxlBynkL6wNj8xqZCZqEnOIa1qhOktYg2UpXvfHtNQ+upNbXYgQKpjBHyieLJRbNSyBTlcRbIlxRSODvRaSSLSsCjkVKe7Q0HQDWNvIRWJQHYeq4LcVNWHnOGQ59o7uWXOz0d7xXjPuLysqjxJURHxx3H2 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001);SRVR:BY2PR03MB506;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB506; X-Forefront-PRVS: 0787459938 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR03MB506;23:NnGSvJ/iZoXMegx1nsXkXosG5XbJRMATVTUtB0zJ2E?= =?us-ascii?Q?Wcvw7TpRkaS+jEYC0x5aGegUrY0vptmWpNUJSVRQdVpUlz2NhhqXY1GfHyGY?= =?us-ascii?Q?8M8oFF7Vfq+N6/8SYZyJVe0TSep+3aFBHeJFBQLasSU2gIPw6xWeGau09kY3?= =?us-ascii?Q?QDjdMDvZU+SyDO3k5nl2lN/afb137cyy0cNo5cwU2VqP3Ym2iRr21se50QMW?= =?us-ascii?Q?2iUld5Qlfknk8p75wl+DCz/Df1vX4OdhyUn462lbHlOHlc3UHyyWoZbIhX2M?= =?us-ascii?Q?5lmDGhjMzqweB7YFG6lkJWZLAnFgXagvR3gDj33Rz+q6weZKt4PN+hj/goNM?= =?us-ascii?Q?Jxyi3JmWkhMbIWaOAZSOxDboQAW/S9H7wFsSVsujwTZm0Kezg4qt/I2qnUbF?= =?us-ascii?Q?5mYZzUVzrm0kbkFzUdygLvSNUa6ANgdf0OqTytylHFq4E6i3tTBsMLgNGncH?= =?us-ascii?Q?bb9xGcsuSWEhSPFbygYmFKP+ANxUtdAkDpCAeu5YmTAEatINwcbwkzBnmdhR?= =?us-ascii?Q?AD+ver0CX21IAXmz4ws787Ew9H+B25+V09I4Hp7vHh/lDAdyOwtAhezu7iV7?= =?us-ascii?Q?lDSiSF20F9U2ADQnE9YOy4+cR3aZBvsdT+RiyHlEwZkspI4LTvJ8UDGqlUpj?= =?us-ascii?Q?AGHWQ2U779V2eFnXWyyGG5Gbl4HSLvYroeiHwJzYrEnov77ZZSpZHbxyPLZe?= =?us-ascii?Q?oVdGslt4fmppH/GbGADwNFJKdu1ASxcf/rOdjicAfc5Az8g3ylovqVxBvM5j?= =?us-ascii?Q?FqFSzM7KuV5Rj+zH8N058uIwB09SOwTQCyQi1m/kTm0GAQWxuhPyW+Y802BR?= =?us-ascii?Q?So9jQzjlvyzMi6IlCyZp2he4uSG/9CAJHrSnxN/XFHQwwlI0ii6BSWFoXLf7?= =?us-ascii?Q?NMKaMmdsqX7Od8VCo/eQBxHP+8mHgwCSYmuqm6QpAeQcjXmkqEzpAMigWGVW?= =?us-ascii?Q?TZSRzSajLNaWplghfenqUwrDKrSxHeg+TsynBCldJZ2UFj6R3PoKoD7e3/TV?= =?us-ascii?Q?A9Bz3DrrvToQM5hFIjMpM9rdbL3pblqmGOle3wGotXcw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB506;5:YiG3UvnAGtcWWvReGtDzH6j88xwOw52PnHpTRpSJXDl79vfEhW6n2JWQpz2Z0rP0TbTm4xbWtwqLrISdWSgam5x6QKOzcoQ3uKPkPsmdNP4JuIbWlv9CVN3NOE1LKgqbWEedChE8JfR14PYLdDrFHA==;24:loqUw/TnU8S8Lo0Ik5HgSwE1MCzSmdny2zOWKf/9L9AuEncnImSKTpxdpJr0VS5Rv61GjEp206g8KIMK2dhoKfY8FmckcGRxUQvIQiI2XeI= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2015 18:27:08.8835 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB506 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10110 Lines: 341 All the IRQs for DPAA2 objects in the same DPRC must use the ICID of that DPRC, as their device Id in the GIC-ITS. Thus, all these IRQs must share the same ITT table in the GIC. As a result, a pool of IRQs with the same device Id must be preallocated per DPRC (fsl-mc bus instance). So, the fsl-mc bus object allocator is extended to also provide services to allocate IRQs to DPAA2 devices, from their parent fsl-mc bus IRQ pool. Signed-off-by: J. German Rivera --- CHANGE HISTORY Changes in v4: none Changes in v3: none Changes in v2: none drivers/staging/fsl-mc/bus/mc-allocator.c | 199 ++++++++++++++++++++++++++++ drivers/staging/fsl-mc/include/mc-private.h | 15 +++ drivers/staging/fsl-mc/include/mc.h | 9 ++ 3 files changed, 223 insertions(+) diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fsl-mc/bus/mc-allocator.c index 88d1857..c5fa628 100644 --- a/drivers/staging/fsl-mc/bus/mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/mc-allocator.c @@ -15,6 +15,7 @@ #include "../include/dpcon-cmd.h" #include "dpmcp-cmd.h" #include "dpmcp.h" +#include /** * fsl_mc_resource_pool_add_device - add allocatable device to a resource @@ -160,6 +161,7 @@ static const char *const fsl_mc_pool_type_strings[] = { [FSL_MC_POOL_DPMCP] = "dpmcp", [FSL_MC_POOL_DPBP] = "dpbp", [FSL_MC_POOL_DPCON] = "dpcon", + [FSL_MC_POOL_IRQ] = "irq", }; static int __must_check object_type_to_pool_type(const char *object_type, @@ -465,6 +467,203 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev) } EXPORT_SYMBOL_GPL(fsl_mc_object_free); +/* + * Initialize the interrupt pool associated with a MC bus. + * It allocates a block of IRQs from the GIC-ITS + */ +int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, + unsigned int irq_count) +{ + unsigned int i; + struct msi_desc *msi_desc; + struct fsl_mc_device_irq *irq_resources; + struct fsl_mc_device_irq *mc_dev_irq; + int error; + struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; + struct fsl_mc_resource_pool *res_pool = + &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; + + if (WARN_ON(irq_count == 0 || + irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS)) + return -EINVAL; + + error = fsl_mc_msi_domain_alloc_irqs(&mc_bus_dev->dev, irq_count); + if (error < 0) + return error; + + irq_resources = devm_kzalloc(&mc_bus_dev->dev, + sizeof(*irq_resources) * irq_count, + GFP_KERNEL); + if (!irq_resources) { + error = -ENOMEM; + goto cleanup_msi_irqs; + } + + for (i = 0; i < irq_count; i++) { + mc_dev_irq = &irq_resources[i]; + + /* + * NOTE: This mc_dev_irq's MSI addr/value pair will be set + * by the fsl_mc_msi_write_msg() callback + */ + mc_dev_irq->resource.type = res_pool->type; + mc_dev_irq->resource.data = mc_dev_irq; + mc_dev_irq->resource.parent_pool = res_pool; + INIT_LIST_HEAD(&mc_dev_irq->resource.node); + list_add_tail(&mc_dev_irq->resource.node, &res_pool->free_list); + } + + for_each_msi_entry(msi_desc, &mc_bus_dev->dev) { + mc_dev_irq = &irq_resources[msi_desc->fsl_mc.msi_index]; + mc_dev_irq->msi_desc = msi_desc; + mc_dev_irq->resource.id = msi_desc->irq; + } + + res_pool->max_count = irq_count; + res_pool->free_count = irq_count; + mc_bus->irq_resources = irq_resources; + return 0; + +cleanup_msi_irqs: + fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool); + +/** + * Teardown the interrupt pool associated with an MC bus. + * It frees the IRQs that were allocated to the pool, back to the GIC-ITS. + */ +void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus) +{ + struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; + struct fsl_mc_resource_pool *res_pool = + &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; + + if (WARN_ON(!mc_bus->irq_resources)) + return; + + if (WARN_ON(res_pool->max_count == 0)) + return; + + if (WARN_ON(res_pool->free_count != res_pool->max_count)) + return; + + INIT_LIST_HEAD(&res_pool->free_list); + res_pool->max_count = 0; + res_pool->free_count = 0; + mc_bus->irq_resources = NULL; + fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); +} +EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool); + +/** + * It allocates the IRQs required by a given MC object device. The + * IRQs are allocated from the interrupt pool associated with the + * MC bus that contains the device, if the device is not a DPRC device. + * Otherwise, the IRQs are allocated from the interrupt pool associated + * with the MC bus that represents the DPRC device itself. + */ +int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev) +{ + int i; + int irq_count; + int res_allocated_count = 0; + int error = -EINVAL; + struct fsl_mc_device_irq **irqs = NULL; + struct fsl_mc_bus *mc_bus; + struct fsl_mc_resource_pool *res_pool; + + if (WARN_ON(mc_dev->irqs)) + return -EINVAL; + + irq_count = mc_dev->obj_desc.irq_count; + if (WARN_ON(irq_count == 0)) + return -EINVAL; + + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) + mc_bus = to_fsl_mc_bus(mc_dev); + else + mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); + + if (WARN_ON(!mc_bus->irq_resources)) + return -EINVAL; + + res_pool = &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; + if (res_pool->free_count < irq_count) { + dev_err(&mc_dev->dev, + "Not able to allocate %u irqs for device\n", irq_count); + return -ENOSPC; + } + + irqs = devm_kzalloc(&mc_dev->dev, irq_count * sizeof(irqs[0]), + GFP_KERNEL); + if (!irqs) + return -ENOMEM; + + for (i = 0; i < irq_count; i++) { + struct fsl_mc_resource *resource; + + error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_IRQ, + &resource); + if (error < 0) + goto error_resource_alloc; + + irqs[i] = to_fsl_mc_irq(resource); + res_allocated_count++; + + WARN_ON(irqs[i]->mc_dev); + irqs[i]->mc_dev = mc_dev; + irqs[i]->dev_irq_index = i; + } + + mc_dev->irqs = irqs; + return 0; + +error_resource_alloc: + for (i = 0; i < res_allocated_count; i++) { + irqs[i]->mc_dev = NULL; + fsl_mc_resource_free(&irqs[i]->resource); + } + + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs); + +/* + * It frees the IRQs that were allocated for a MC object device, by + * returning them to the corresponding interrupt pool. + */ +void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev) +{ + int i; + int irq_count; + struct fsl_mc_bus *mc_bus; + struct fsl_mc_device_irq **irqs = mc_dev->irqs; + + if (WARN_ON(!irqs)) + return; + + irq_count = mc_dev->obj_desc.irq_count; + + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) + mc_bus = to_fsl_mc_bus(mc_dev); + else + mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); + + if (WARN_ON(!mc_bus->irq_resources)) + return; + + for (i = 0; i < irq_count; i++) { + WARN_ON(!irqs[i]->mc_dev); + irqs[i]->mc_dev = NULL; + fsl_mc_resource_free(&irqs[i]->resource); + } + + mc_dev->irqs = NULL; +} +EXPORT_SYMBOL_GPL(fsl_mc_free_irqs); + /** * fsl_mc_allocator_probe - callback invoked when an allocatable device is * being added to the system diff --git a/drivers/staging/fsl-mc/include/mc-private.h b/drivers/staging/fsl-mc/include/mc-private.h index 28c8d32..3babe92 100644 --- a/drivers/staging/fsl-mc/include/mc-private.h +++ b/drivers/staging/fsl-mc/include/mc-private.h @@ -30,6 +30,16 @@ struct irq_domain; struct msi_domain_info; /** + * Maximum number of total IRQs that can be pre-allocated for an MC bus' + * IRQ pool + */ +#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 + +struct device_node; +struct irq_domain; +struct msi_domain_info; + +/** * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device * @root_mc_bus_dev: MC object device representing the root DPRC * @num_translation_ranges: number of entries in addr_translation_ranges @@ -137,4 +147,9 @@ int __init its_fsl_mc_msi_init(void); void its_fsl_mc_msi_cleanup(void); +int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, + unsigned int irq_count); + +void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus); + #endif /* _FSL_MC_PRIVATE_H_ */ diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index 1c1d6ae..ac7c1ce 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -14,12 +14,14 @@ #include #include #include +#include #include "../include/dprc.h" #define FSL_MC_VENDOR_FREESCALE 0x1957 struct fsl_mc_device; struct fsl_mc_io; +struct fsl_mc_bus; /** * struct fsl_mc_driver - MC object device driver object @@ -75,6 +77,7 @@ enum fsl_mc_pool_type { FSL_MC_POOL_DPMCP = 0x0, /* corresponds to "dpmcp" in the MC */ FSL_MC_POOL_DPBP, /* corresponds to "dpbp" in the MC */ FSL_MC_POOL_DPCON, /* corresponds to "dpcon" in the MC */ + FSL_MC_POOL_IRQ, /* * NOTE: New resource pool types must be added before this entry @@ -141,6 +144,7 @@ struct fsl_mc_device_irq { * NULL if none. * @obj_desc: MC description of the DPAA device * @regions: pointer to array of MMIO region entries + * @irqs: pointer to array of pointers to interrupts allocated to this device * @resource: generic resource associated with this MC object device, if any. * * Generic device object for MC object devices that are "attached" to a @@ -172,6 +176,7 @@ struct fsl_mc_device { struct fsl_mc_io *mc_io; struct dprc_obj_desc obj_desc; struct resource *regions; + struct fsl_mc_device_irq **irqs; struct fsl_mc_resource *resource; }; @@ -215,6 +220,10 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev, void fsl_mc_object_free(struct fsl_mc_device *mc_adev); +int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev); + +void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev); + extern struct bus_type fsl_mc_bus_type; #endif /* _FSL_MC_H_ */ -- 2.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/