The vfio-mc bus driver needs some additional services to be exported by the
mc-bus driver like:
- a way to reset the DPRC container
- driver_override support
- functions to setup/tear down a DPRC
- functions for allocating the pool of interrupts. In case of VFIO the
interrupts are not configured at probe time, but later by userspace
request
v1 -> v2
- Remove driver_override propagation through various functions
- Cache the DPRC API version
The patches are related with "vfio/fsl-mc: VFIO support for FSL-MC
devices" patches, but the series were split because they are targeting
different subsystems. However, the mc-bus patches may suffer changes
when addressing the VFIO review comments.
Bharat Bhushan (3):
bus/fsl-mc: add support for 'driver_override' in the mc-bus
bus/fsl-mc: Add dprc-reset-container support
bus/fsl-mc: Extend ICID size from 16bit to 32bit
Diana Craciun (9):
bus/fsl-mc: Do no longer export the total number of irqs outside
dprc_scan_objects
bus/fsl-mc: Add a new parameter to dprc_scan_objects function
bus/fsl-mc: Set the QMAN/BMAN region flags
bus/fsl-mc: Cache the DPRC API version
bus/fsl-mc: Export a dprc scan function to be used by multiple
entities
bus/fsl-mc: Export a cleanup function for DPRC
bus/fsl-mc: Add a container setup function
bus/fsl_mc: Do not rely on caller to provide non NULL mc_io
bus/fsl-mc: Export IRQ pool handling functions to be used by VFIO
drivers/bus/fsl-mc/dprc-driver.c | 181 ++++++++++++++++----------
drivers/bus/fsl-mc/dprc.c | 103 +++++++++++++--
drivers/bus/fsl-mc/fsl-mc-allocator.c | 12 +-
drivers/bus/fsl-mc/fsl-mc-bus.c | 64 ++++++++-
drivers/bus/fsl-mc/fsl-mc-private.h | 28 ++--
drivers/bus/fsl-mc/mc-io.c | 7 +-
include/linux/fsl/mc.h | 29 ++++-
7 files changed, 313 insertions(+), 111 deletions(-)
--
2.17.1
Before destroying the mc_io, check first that it was
allocated.
Signed-off-by: Diana Craciun <[email protected]>
---
drivers/bus/fsl-mc/mc-io.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/bus/fsl-mc/mc-io.c b/drivers/bus/fsl-mc/mc-io.c
index 6ae48ad80409..e1dfe4a76519 100644
--- a/drivers/bus/fsl-mc/mc-io.c
+++ b/drivers/bus/fsl-mc/mc-io.c
@@ -129,7 +129,12 @@ int __must_check fsl_create_mc_io(struct device *dev,
*/
void fsl_destroy_mc_io(struct fsl_mc_io *mc_io)
{
- struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
+ struct fsl_mc_device *dpmcp_dev;
+
+ if (!mc_io)
+ return;
+
+ dpmcp_dev = mc_io->dpmcp_dev;
if (dpmcp_dev)
fsl_mc_io_unset_dpmcp(mc_io);
--
2.17.1
Prepare the dprc_scan_objects function to be used by
the VFIO mc driver code. The function is used to scan the mc
objects by the bus driver. The same functionality is
needed by the VFIO mc driver, but in this case the
interrupt configuration is delayed until the userspace
configures the interrupts. In order to use the same function
in both drivers add a new parameter.
Signed-off-by: Diana Craciun <[email protected]>
---
drivers/bus/fsl-mc/dprc-driver.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
index 035b220779d0..7a8061224df8 100644
--- a/drivers/bus/fsl-mc/dprc-driver.c
+++ b/drivers/bus/fsl-mc/dprc-driver.c
@@ -198,6 +198,8 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
* dprc_scan_objects - Discover objects in a DPRC
*
* @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
+ * @alloc_interrupts: if true the function allocates the interrupt pool,
+ * otherwise the interrupt allocation is delayed
*
* Detects objects added and removed from a DPRC and synchronizes the
* state of the Linux bus driver, MC by adding and removing
@@ -211,7 +213,8 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
* populated before they can get allocation requests from probe callbacks
* of the device drivers for the non-allocatable devices.
*/
-static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev)
+static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
+ bool alloc_interrupts)
{
int num_child_objects;
int dprc_get_obj_failures;
@@ -299,7 +302,7 @@ static int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev)
irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
}
- if (!mc_bus->irq_resources) {
+ if (alloc_interrupts && !mc_bus->irq_resources) {
error = fsl_mc_populate_irq_pool(mc_bus,
FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS);
if (error < 0)
@@ -339,7 +342,7 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
* Discover objects in the DPRC:
*/
mutex_lock(&mc_bus->scan_mutex);
- error = dprc_scan_objects(mc_bus_dev);
+ error = dprc_scan_objects(mc_bus_dev, true);
mutex_unlock(&mc_bus->scan_mutex);
if (error < 0) {
fsl_mc_cleanup_all_resource_pools(mc_bus_dev);
@@ -409,7 +412,7 @@ static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg)
DPRC_IRQ_EVENT_OBJ_DESTROYED |
DPRC_IRQ_EVENT_OBJ_CREATED)) {
- error = dprc_scan_objects(mc_dev);
+ error = dprc_scan_objects(mc_dev, true);
if (error < 0) {
/*
* If the error is -ENXIO, we ignore it, as it indicates
--
2.17.1
From: Bharat Bhushan <[email protected]>
This patch is required for vfio-fsl-mc meta driver to successfully bind
layerscape container devices for device passthrough. This patch adds
a mechanism to allow a layerscape device to specify a driver rather than
a layerscape driver provide a device match.
Example to allow a device (dprc.1) to specifically bind
with driver (vfio-fsl-mc):
- echo vfio-fsl-mc > /sys/bus/fsl-mc/devices/dprc.1/driver_override
- echo dprc.1 > /sys/bus/fsl-mc/drivers/fsl_mc_dprc/unbind
- echo dprc.1 > /sys/bus/fsl-mc/drivers/vfio-fsl-mc/bind
Signed-off-by: Bharat Bhushan <[email protected]>
Signed-off-by: Laurentiu Tudor <[email protected]>
Signed-off-by: Diana Craciun <[email protected]>
---
drivers/bus/fsl-mc/fsl-mc-bus.c | 54 +++++++++++++++++++++++++++++++++
include/linux/fsl/mc.h | 2 ++
2 files changed, 56 insertions(+)
diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 40526da5c6a6..3a86f5087717 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -3,6 +3,7 @@
* Freescale Management Complex (MC) bus driver
*
* Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
+ * Copyright 2019-2020 NXP
* Author: German Rivera <[email protected]>
*
*/
@@ -71,6 +72,12 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
bool found = false;
+ /* When driver_override is set, only bind to the matching driver */
+ if (mc_dev->driver_override) {
+ found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
+ goto out;
+ }
+
if (!mc_drv->match_id_table)
goto out;
@@ -135,8 +142,52 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(modalias);
+static ssize_t driver_override_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+ char *driver_override, *old = mc_dev->driver_override;
+ char *cp;
+
+ if (WARN_ON(dev->bus != &fsl_mc_bus_type))
+ return -EINVAL;
+
+ if (count >= (PAGE_SIZE - 1))
+ return -EINVAL;
+
+ driver_override = kstrndup(buf, count, GFP_KERNEL);
+ if (!driver_override)
+ return -ENOMEM;
+
+ cp = strchr(driver_override, '\n');
+ if (cp)
+ *cp = '\0';
+
+ if (strlen(driver_override)) {
+ mc_dev->driver_override = driver_override;
+ } else {
+ kfree(driver_override);
+ mc_dev->driver_override = NULL;
+ }
+
+ kfree(old);
+
+ return count;
+}
+
+static ssize_t driver_override_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+
+ return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override);
+}
+static DEVICE_ATTR_RW(driver_override);
+
static struct attribute *fsl_mc_dev_attrs[] = {
&dev_attr_modalias.attr,
+ &dev_attr_driver_override.attr,
NULL,
};
@@ -706,6 +757,9 @@ EXPORT_SYMBOL_GPL(fsl_mc_device_add);
*/
void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
{
+ kfree(mc_dev->driver_override);
+ mc_dev->driver_override = NULL;
+
/*
* The device-specific remove callback will get invoked by device_del()
*/
diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h
index 2b5f8366dbe1..4e9b570a1845 100644
--- a/include/linux/fsl/mc.h
+++ b/include/linux/fsl/mc.h
@@ -161,6 +161,7 @@ struct fsl_mc_obj_desc {
* @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.
+ * @driver_override: driver name to force a match
*
* Generic device object for MC object devices that are "attached" to a
* MC bus.
@@ -194,6 +195,7 @@ struct fsl_mc_device {
struct fsl_mc_device_irq **irqs;
struct fsl_mc_resource *resource;
struct device_link *consumer_link;
+ char *driver_override;
};
#define to_fsl_mc_device(_dev) \
--
2.17.1
On Thu, May 07, 2020 at 10:34:22AM +0300, Diana Craciun wrote:
> From: Bharat Bhushan <[email protected]>
>
> This patch is required for vfio-fsl-mc meta driver to successfully bind
> layerscape container devices for device passthrough. This patch adds
> a mechanism to allow a layerscape device to specify a driver rather than
> a layerscape driver provide a device match.
>
> Example to allow a device (dprc.1) to specifically bind
> with driver (vfio-fsl-mc):
> - echo vfio-fsl-mc > /sys/bus/fsl-mc/devices/dprc.1/driver_override
> - echo dprc.1 > /sys/bus/fsl-mc/drivers/fsl_mc_dprc/unbind
> - echo dprc.1 > /sys/bus/fsl-mc/drivers/vfio-fsl-mc/bind
Hi Bharat, Diana
grep -r "/driver_override" Documentation
Documentation/ABI/testing/sysfs-bus-rpmsg:What: /sys/bus/rpmsg/devices/.../driver_override
Documentation/ABI/testing/sysfs-bus-pci:What: /sys/bus/pci/devices/.../driver_override
Documentation/ABI/testing/sysfs-bus-platform:What: /sys/bus/platform/devices/.../driver_override
Documentation/ABI/testing/sysfs-bus-css:What: /sys/bus/css/devices/.../driver_override
Documentation/ABI/testing/sysfs-bus-vmbus:What: /sys/bus/vmbus/devices/.../driver_override
Documentation/ABI/testing/sysfs-bus-amba:What: /sys/bus/amba/devices/.../driver_override
Maybe it is time to move this into the core, and avoid yet another
implementation of driver_override_store() and driver_override_show()
functions etc.
Andrew
On 5/7/2020 10:34 AM, Diana Craciun wrote:
> The vfio-mc bus driver needs some additional services to be exported by the
> mc-bus driver like:
> - a way to reset the DPRC container
> - driver_override support
> - functions to setup/tear down a DPRC
> - functions for allocating the pool of interrupts. In case of VFIO the
> interrupts are not configured at probe time, but later by userspace
> request
>
> v1 -> v2
> - Remove driver_override propagation through various functions
> - Cache the DPRC API version
>
> The patches are related with "vfio/fsl-mc: VFIO support for FSL-MC
> devices" patches, but the series were split because they are targeting
> different subsystems. However, the mc-bus patches may suffer changes
> when addressing the VFIO review comments.
>
> Bharat Bhushan (3):
> bus/fsl-mc: add support for 'driver_override' in the mc-bus
> bus/fsl-mc: Add dprc-reset-container support
> bus/fsl-mc: Extend ICID size from 16bit to 32bit
>
> Diana Craciun (9):
> bus/fsl-mc: Do no longer export the total number of irqs outside
> dprc_scan_objects
> bus/fsl-mc: Add a new parameter to dprc_scan_objects function
> bus/fsl-mc: Set the QMAN/BMAN region flags
> bus/fsl-mc: Cache the DPRC API version
> bus/fsl-mc: Export a dprc scan function to be used by multiple
> entities
> bus/fsl-mc: Export a cleanup function for DPRC
> bus/fsl-mc: Add a container setup function
> bus/fsl_mc: Do not rely on caller to provide non NULL mc_io
> bus/fsl-mc: Export IRQ pool handling functions to be used by VFIO
>
> drivers/bus/fsl-mc/dprc-driver.c | 181 ++++++++++++++++----------
> drivers/bus/fsl-mc/dprc.c | 103 +++++++++++++--
> drivers/bus/fsl-mc/fsl-mc-allocator.c | 12 +-
> drivers/bus/fsl-mc/fsl-mc-bus.c | 64 ++++++++-
> drivers/bus/fsl-mc/fsl-mc-private.h | 28 ++--
> drivers/bus/fsl-mc/mc-io.c | 7 +-
> include/linux/fsl/mc.h | 29 ++++-
> 7 files changed, 313 insertions(+), 111 deletions(-)
>
For the whole series:
Reviewed-by: Laurentiu Tudor <[email protected]>
---
Best Regards, Laurentiu