| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From ab5ad879bf30318213a717ab50944b5590bc09c1 Mon Sep 17 00:00:00 2001 |
| 2 | From: Laurentiu Tudor <laurentiu.tudor@nxp.com> |
| 3 | Date: Fri, 13 Apr 2018 11:52:44 +0300 |
| 4 | Subject: [PATCH] bus: fsl-mc: Propagate driver_override for a child DPRC's |
| 5 | children |
| 6 | |
| 7 | When a child DPRC is bound to the vfio_fsl_mc driver via |
| 8 | driver_override, its own children should not be bound to corresponding |
| 9 | host kernel drivers, but instead should be bound to the vfio_fsl_mc |
| 10 | driver as well. |
| 11 | |
| 12 | Currently, when a child container is scanned by the vfio_fsl_mc |
| 13 | driver, child devices found are automatically bound to corresponding |
| 14 | host kernel drivers (e.g., DPMCP and DPBP objects are bound to the |
| 15 | fsl_mc_allocator driver, DPNI objects are bound to the ldpaa_eth |
| 16 | driver, etc), Then, the user has to manually unbind these child |
| 17 | devices from their drivers, set the driver_override sysfs attribute |
| 18 | to vfio_fsl_mc driver, for each of them and rebind them. |
| 19 | |
| 20 | Signed-off-by: J. German Rivera <German.Rivera@freescale.com> |
| 21 | Signed-off-by: Stuart Yoder <stuart.yoder@nxp.com> |
| 22 | Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com> |
| 23 | Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com> |
| 24 | --- |
| 25 | drivers/bus/fsl-mc/dprc-driver.c | 16 +++++++++++----- |
| 26 | drivers/bus/fsl-mc/fsl-mc-bus.c | 19 +++++++++++++++++-- |
| 27 | drivers/bus/fsl-mc/fsl-mc-private.h | 2 ++ |
| 28 | include/linux/fsl/mc.h | 2 ++ |
| 29 | 4 files changed, 32 insertions(+), 7 deletions(-) |
| 30 | |
| 31 | --- a/drivers/bus/fsl-mc/dprc-driver.c |
| 32 | +++ b/drivers/bus/fsl-mc/dprc-driver.c |
| 33 | @@ -156,6 +156,8 @@ static void check_plugged_state_change(s |
| 34 | * dprc_add_new_devices - Adds devices to the logical bus for a DPRC |
| 35 | * |
| 36 | * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object |
| 37 | + * @driver_override: driver override to apply to new objects found in the |
| 38 | + * DPRC, or NULL, if none. |
| 39 | * @obj_desc_array: array of device descriptors for child devices currently |
| 40 | * present in the physical DPRC. |
| 41 | * @num_child_objects_in_mc: number of entries in obj_desc_array |
| 42 | @@ -165,6 +167,7 @@ static void check_plugged_state_change(s |
| 43 | * in the physical DPRC. |
| 44 | */ |
| 45 | static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev, |
| 46 | + const char *driver_override, |
| 47 | struct fsl_mc_obj_desc *obj_desc_array, |
| 48 | int num_child_objects_in_mc) |
| 49 | { |
| 50 | @@ -189,7 +192,7 @@ static void dprc_add_new_devices(struct |
| 51 | } |
| 52 | |
| 53 | error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev, |
| 54 | - &child_dev); |
| 55 | + driver_override, &child_dev); |
| 56 | if (error < 0) |
| 57 | continue; |
| 58 | } |
| 59 | @@ -199,6 +202,8 @@ static void dprc_add_new_devices(struct |
| 60 | * dprc_scan_objects - Discover objects in a DPRC |
| 61 | * |
| 62 | * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object |
| 63 | + * @driver_override: driver override to apply to new objects found in the |
| 64 | + * DPRC, or NULL, if none. |
| 65 | * @total_irq_count: If argument is provided the function populates the |
| 66 | * total number of IRQs created by objects in the DPRC. |
| 67 | * |
| 68 | @@ -215,6 +220,7 @@ static void dprc_add_new_devices(struct |
| 69 | * of the device drivers for the non-allocatable devices. |
| 70 | */ |
| 71 | int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, |
| 72 | + const char *driver_override, |
| 73 | unsigned int *total_irq_count) |
| 74 | { |
| 75 | int num_child_objects; |
| 76 | @@ -315,7 +321,7 @@ int dprc_scan_objects(struct fsl_mc_devi |
| 77 | dprc_remove_devices(mc_bus_dev, child_obj_desc_array, |
| 78 | num_child_objects); |
| 79 | |
| 80 | - dprc_add_new_devices(mc_bus_dev, child_obj_desc_array, |
| 81 | + dprc_add_new_devices(mc_bus_dev, driver_override, child_obj_desc_array, |
| 82 | num_child_objects); |
| 83 | |
| 84 | if (child_obj_desc_array) |
| 85 | @@ -344,7 +350,7 @@ static int dprc_scan_container(struct fs |
| 86 | * Discover objects in the DPRC: |
| 87 | */ |
| 88 | mutex_lock(&mc_bus->scan_mutex); |
| 89 | - error = dprc_scan_objects(mc_bus_dev, NULL); |
| 90 | + error = dprc_scan_objects(mc_bus_dev, NULL, NULL); |
| 91 | mutex_unlock(&mc_bus->scan_mutex); |
| 92 | if (error < 0) { |
| 93 | fsl_mc_cleanup_all_resource_pools(mc_bus_dev); |
| 94 | @@ -373,7 +379,7 @@ static ssize_t rescan_store(struct devic |
| 95 | |
| 96 | if (val) { |
| 97 | mutex_lock(&root_mc_bus->scan_mutex); |
| 98 | - dprc_scan_objects(root_mc_dev, NULL); |
| 99 | + dprc_scan_objects(root_mc_dev, NULL, NULL); |
| 100 | mutex_unlock(&root_mc_bus->scan_mutex); |
| 101 | } |
| 102 | |
| 103 | @@ -442,7 +448,7 @@ static irqreturn_t dprc_irq0_handler_thr |
| 104 | DPRC_IRQ_EVENT_OBJ_CREATED)) { |
| 105 | unsigned int irq_count; |
| 106 | |
| 107 | - error = dprc_scan_objects(mc_dev, &irq_count); |
| 108 | + error = dprc_scan_objects(mc_dev, NULL, &irq_count); |
| 109 | if (error < 0) { |
| 110 | /* |
| 111 | * If the error is -ENXIO, we ignore it, as it indicates |
| 112 | --- a/drivers/bus/fsl-mc/fsl-mc-bus.c |
| 113 | +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c |
| 114 | @@ -165,7 +165,7 @@ static int scan_fsl_mc_bus(struct device |
| 115 | root_mc_dev = to_fsl_mc_device(dev); |
| 116 | root_mc_bus = to_fsl_mc_bus(root_mc_dev); |
| 117 | mutex_lock(&root_mc_bus->scan_mutex); |
| 118 | - dprc_scan_objects(root_mc_dev, NULL); |
| 119 | + dprc_scan_objects(root_mc_dev, NULL, NULL); |
| 120 | mutex_unlock(&root_mc_bus->scan_mutex); |
| 121 | |
| 122 | exit: |
| 123 | @@ -597,6 +597,7 @@ static void fsl_mc_device_release(struct |
| 124 | int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, |
| 125 | struct fsl_mc_io *mc_io, |
| 126 | struct device *parent_dev, |
| 127 | + const char *driver_override, |
| 128 | struct fsl_mc_device **new_mc_dev) |
| 129 | { |
| 130 | int error; |
| 131 | @@ -629,6 +630,19 @@ int fsl_mc_device_add(struct fsl_mc_obj_ |
| 132 | |
| 133 | mc_dev->obj_desc = *obj_desc; |
| 134 | mc_dev->mc_io = mc_io; |
| 135 | + |
| 136 | + if (driver_override) { |
| 137 | + /* |
| 138 | + * We trust driver_override, so we don't need to use |
| 139 | + * kstrndup() here |
| 140 | + */ |
| 141 | + mc_dev->driver_override = kstrdup(driver_override, GFP_KERNEL); |
| 142 | + if (!mc_dev->driver_override) { |
| 143 | + error = -ENOMEM; |
| 144 | + goto error_cleanup_dev; |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | device_initialize(&mc_dev->dev); |
| 149 | mc_dev->dev.parent = parent_dev; |
| 150 | mc_dev->dev.bus = &fsl_mc_bus_type; |
| 151 | @@ -924,7 +938,8 @@ static int fsl_mc_bus_probe(struct platf |
| 152 | obj_desc.irq_count = 1; |
| 153 | obj_desc.region_count = 0; |
| 154 | |
| 155 | - error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev); |
| 156 | + error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, NULL, |
| 157 | + &mc_bus_dev); |
| 158 | if (error < 0) |
| 159 | goto error_cleanup_mc_io; |
| 160 | |
| 161 | --- a/drivers/bus/fsl-mc/fsl-mc-private.h |
| 162 | +++ b/drivers/bus/fsl-mc/fsl-mc-private.h |
| 163 | @@ -558,6 +558,7 @@ struct fsl_mc_bus { |
| 164 | int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, |
| 165 | struct fsl_mc_io *mc_io, |
| 166 | struct device *parent_dev, |
| 167 | + const char *driver_override, |
| 168 | struct fsl_mc_device **new_mc_dev); |
| 169 | |
| 170 | void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); |
| 171 | @@ -567,6 +568,7 @@ int __init dprc_driver_init(void); |
| 172 | void dprc_driver_exit(void); |
| 173 | |
| 174 | int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, |
| 175 | + const char *driver_override, |
| 176 | unsigned int *total_irq_count); |
| 177 | int __init fsl_mc_allocator_driver_init(void); |
| 178 | |
| 179 | --- a/include/linux/fsl/mc.h |
| 180 | +++ b/include/linux/fsl/mc.h |
| 181 | @@ -162,6 +162,7 @@ struct fsl_mc_obj_desc { |
| 182 | * @regions: pointer to array of MMIO region entries |
| 183 | * @irqs: pointer to array of pointers to interrupts allocated to this device |
| 184 | * @resource: generic resource associated with this MC object device, if any. |
| 185 | + * @driver_override: Driver name to force a match |
| 186 | * |
| 187 | * Generic device object for MC object devices that are "attached" to a |
| 188 | * MC bus. |
| 189 | @@ -195,6 +196,7 @@ struct fsl_mc_device { |
| 190 | struct fsl_mc_device_irq **irqs; |
| 191 | struct fsl_mc_resource *resource; |
| 192 | struct device_link *consumer_link; |
| 193 | + const char *driver_override; |
| 194 | }; |
| 195 | |
| 196 | #define to_fsl_mc_device(_dev) \ |