1 From 653fc2595283df6deb92ca3058c8d5dc1e129e91 Mon Sep 17 00:00:00 2001
2 From: Diana Craciun <diana.craciun@nxp.com>
3 Date: Fri, 13 Sep 2019 17:17:30 +0300
4 Subject: [PATCH] bus/fsl-mc: Add a new parameter to dprc_scan_objects function
6 Prepare the dprc_scan_objects function to be used by
7 the VFIO mc driver code. The function is used to scan the mc
8 objects by the bus driver. The same functionality is
9 needed by the VFIO mc driver, but in this case the
10 interrupt configuration is delayed until the userspace
11 configures them. In order to use the same function in both
12 drivers add a new parameter.
14 Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
16 drivers/bus/fsl-mc/dprc-driver.c | 33 +++++++++++++++++++--------------
17 drivers/bus/fsl-mc/fsl-mc-bus.c | 2 +-
18 include/linux/fsl/mc.h | 1 +
19 3 files changed, 21 insertions(+), 15 deletions(-)
21 --- a/drivers/bus/fsl-mc/dprc-driver.c
22 +++ b/drivers/bus/fsl-mc/dprc-driver.c
24 * Freescale data path resource container (DPRC) driver
26 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
27 + * Copyright 2019 NXP
28 * Author: German Rivera <German.Rivera@freescale.com>
31 @@ -204,6 +205,8 @@ static void dprc_add_new_devices(struct
32 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
33 * @driver_override: driver override to apply to new objects found in the
34 * DPRC, or NULL, if none.
35 + * @alloc_interrupts: if true the function allocates the interrupt pool,
36 + * otherwise the interrupt allocation is delayed
37 * @total_irq_count: If argument is provided the function populates the
38 * total number of IRQs created by objects in the DPRC.
40 @@ -221,6 +224,7 @@ static void dprc_add_new_devices(struct
42 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
43 const char *driver_override,
44 + bool alloc_interrupts,
45 unsigned int *total_irq_count)
47 int num_child_objects;
48 @@ -302,19 +306,20 @@ int dprc_scan_objects(struct fsl_mc_devi
49 * Allocate IRQ's before binding the scanned devices with their
52 - if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
53 - if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
54 - dev_warn(&mc_bus_dev->dev,
55 - "IRQs needed (%u) exceed IRQs preallocated (%u)\n",
56 - irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
58 + if (alloc_interrupts) {
59 + if (dev_get_msi_domain(&mc_bus_dev->dev) && !mc_bus->irq_resources) {
60 + if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) {
61 + dev_warn(&mc_bus_dev->dev,
62 + "IRQs needed (%u) exceed IRQs preallocated (%u)\n",
63 + irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
66 - error = fsl_mc_populate_irq_pool(mc_bus,
67 - FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
70 + error = fsl_mc_populate_irq_pool(mc_bus,
71 + FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
78 *total_irq_count = irq_count;
80 @@ -350,7 +355,7 @@ static int dprc_scan_container(struct fs
81 * Discover objects in the DPRC:
83 mutex_lock(&mc_bus->scan_mutex);
84 - error = dprc_scan_objects(mc_bus_dev, NULL, NULL);
85 + error = dprc_scan_objects(mc_bus_dev, NULL, true, NULL);
86 mutex_unlock(&mc_bus->scan_mutex);
88 fsl_mc_cleanup_all_resource_pools(mc_bus_dev);
89 @@ -379,7 +384,7 @@ static ssize_t rescan_store(struct devic
92 mutex_lock(&root_mc_bus->scan_mutex);
93 - dprc_scan_objects(root_mc_dev, NULL, NULL);
94 + dprc_scan_objects(root_mc_dev, NULL, true, NULL);
95 mutex_unlock(&root_mc_bus->scan_mutex);
98 @@ -448,7 +453,7 @@ static irqreturn_t dprc_irq0_handler_thr
99 DPRC_IRQ_EVENT_OBJ_CREATED)) {
100 unsigned int irq_count;
102 - error = dprc_scan_objects(mc_dev, NULL, &irq_count);
103 + error = dprc_scan_objects(mc_dev, NULL, true, &irq_count);
106 * If the error is -ENXIO, we ignore it, as it indicates
107 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c
108 +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
109 @@ -215,7 +215,7 @@ static int scan_fsl_mc_bus(struct device
110 root_mc_dev = to_fsl_mc_device(dev);
111 root_mc_bus = to_fsl_mc_bus(root_mc_dev);
112 mutex_lock(&root_mc_bus->scan_mutex);
113 - dprc_scan_objects(root_mc_dev, NULL, NULL);
114 + dprc_scan_objects(root_mc_dev, NULL, true, NULL);
115 mutex_unlock(&root_mc_bus->scan_mutex);
118 --- a/include/linux/fsl/mc.h
119 +++ b/include/linux/fsl/mc.h
120 @@ -1010,6 +1010,7 @@ struct fsl_mc_bus {
122 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
123 const char *driver_override,
124 + bool alloc_interrupts,
125 unsigned int *total_irq_count);
127 int fsl_mc_find_msi_domain(struct device *mc_platform_dev,