* [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type
2023-09-13 19:53 [PATCH v11 0/5] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
@ 2023-09-13 19:53 ` Umang Jain
2023-09-13 20:58 ` Stefan Wahren
` (2 more replies)
2023-09-13 19:53 ` [PATCH v11 2/5] staging: vc04_services: vchiq_arm: Register vchiq_bus_type Umang Jain
` (3 subsequent siblings)
4 siblings, 3 replies; 14+ messages in thread
From: Umang Jain @ 2023-09-13 19:53 UTC (permalink / raw)
To: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart, Umang Jain
The devices that the vchiq interface registers (bcm2835-audio,
bcm2835-camera) are implemented and exposed by the VC04 firmware.
The device tree describes the VC04 itself with the resources required
to communicate with it through a mailbox interface. However, the
vchiq interface registers these devices as platform devices. This
also means the specific drivers for these devices are getting
registered as platform drivers. This is not correct and a blatant
abuse of platform device/driver.
Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
which will be used to migrate child devices that the vchiq interfaces
creates/registers from the platform device/driver.
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
drivers/staging/vc04_services/Makefile | 1 +
.../interface/vchiq_arm/vchiq_device.c | 111 ++++++++++++++++++
.../interface/vchiq_arm/vchiq_device.h | 54 +++++++++
3 files changed, 166 insertions(+)
create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
index 44794bdf6173..2d071e55e175 100644
--- a/drivers/staging/vc04_services/Makefile
+++ b/drivers/staging/vc04_services/Makefile
@@ -5,6 +5,7 @@ vchiq-objs := \
interface/vchiq_arm/vchiq_core.o \
interface/vchiq_arm/vchiq_arm.o \
interface/vchiq_arm/vchiq_debugfs.o \
+ interface/vchiq_arm/vchiq_device.o \
interface/vchiq_arm/vchiq_connected.o \
ifdef CONFIG_VCHIQ_CDEV
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
new file mode 100644
index 000000000000..aad55c461905
--- /dev/null
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * vchiq_device.c - VCHIQ generic device and bus-type
+ *
+ * Copyright (c) 2023 Ideas On Board Oy
+ */
+
+#include <linux/device/bus.h>
+#include <linux/dma-mapping.h>
+#include <linux/of_device.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "vchiq_device.h"
+
+static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
+{
+ if (dev->bus == &vchiq_bus_type &&
+ strcmp(dev_name(dev), drv->name) == 0)
+ return 1;
+
+ return 0;
+}
+
+static int vchiq_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)
+{
+ const struct vchiq_device *device = container_of_const(dev, struct vchiq_device, dev);
+
+ return add_uevent_var(env, "MODALIAS=%s", dev_name(&device->dev));
+}
+
+static int vchiq_bus_probe(struct device *dev)
+{
+ struct vchiq_device *device = to_vchiq_device(dev);
+ struct vchiq_driver *driver = to_vchiq_driver(dev->driver);
+ int ret;
+
+ ret = driver->probe(device);
+ if (ret == 0)
+ return 0;
+
+ return ret;
+}
+
+struct bus_type vchiq_bus_type = {
+ .name = "vchiq-bus",
+ .match = vchiq_bus_type_match,
+ .uevent = vchiq_bus_uevent,
+ .probe = vchiq_bus_probe,
+};
+
+static void vchiq_device_release(struct device *dev)
+{
+ struct vchiq_device *device = to_vchiq_device(dev);
+
+ kfree(device);
+}
+
+struct vchiq_device *
+vchiq_device_register(struct device *parent, const char *name)
+{
+ struct vchiq_device *device;
+ int ret;
+
+ device = kzalloc(sizeof(*device), GFP_KERNEL);
+ if (!device) {
+ dev_err(parent, "Cannot register %s: Insufficient memory\n",
+ name);
+ return NULL;
+ }
+
+ device->dev.init_name = name;
+ device->dev.parent = parent;
+ device->dev.bus = &vchiq_bus_type;
+ device->dev.release = vchiq_device_release;
+
+ of_dma_configure(&device->dev, parent->of_node, true);
+ ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
+ if (ret) {
+ dev_err(&device->dev, "32-bit DMA enable failed\n");
+ return NULL;
+ }
+
+ ret = device_register(&device->dev);
+ if (ret) {
+ dev_err(parent, "Cannot register %s: %d\n", name, ret);
+ put_device(&device->dev);
+ return NULL;
+ }
+
+ return device;
+}
+
+void vchiq_device_unregister(struct vchiq_device *vchiq_dev)
+{
+ device_unregister(&vchiq_dev->dev);
+}
+
+int vchiq_driver_register(struct vchiq_driver *vchiq_drv)
+{
+ vchiq_drv->driver.bus = &vchiq_bus_type;
+
+ return driver_register(&vchiq_drv->driver);
+}
+EXPORT_SYMBOL_GPL(vchiq_driver_register);
+
+void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv)
+{
+ driver_unregister(&vchiq_drv->driver);
+}
+EXPORT_SYMBOL_GPL(vchiq_driver_unregister);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
new file mode 100644
index 000000000000..7eaaf9a91cda
--- /dev/null
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 Ideas On Board Oy
+ */
+
+#ifndef _VCHIQ_DEVICE_H
+#define _VCHIQ_DEVICE_H
+
+#include <linux/device.h>
+
+struct vchiq_device {
+ struct device dev;
+};
+
+struct vchiq_driver {
+ int (*probe)(struct vchiq_device *device);
+ void (*remove)(struct vchiq_device *device);
+ int (*resume)(struct vchiq_device *device);
+ int (*suspend)(struct vchiq_device *device,
+ pm_message_t state);
+ struct device_driver driver;
+};
+
+static inline struct vchiq_device *to_vchiq_device(struct device *d)
+{
+ return container_of(d, struct vchiq_device, dev);
+}
+
+static inline struct vchiq_driver *to_vchiq_driver(struct device_driver *d)
+{
+ return container_of(d, struct vchiq_driver, driver);
+}
+
+extern struct bus_type vchiq_bus_type;
+
+struct vchiq_device *
+vchiq_device_register(struct device *parent, const char *name);
+void vchiq_device_unregister(struct vchiq_device *dev);
+
+int vchiq_driver_register(struct vchiq_driver *vchiq_drv);
+void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv);
+
+/**
+ * module_vchiq_driver() - Helper macro for registering a vchiq driver
+ * @__vchiq_driver: vchiq driver struct
+ *
+ * Helper macro for vchiq drivers which do not do anything special in
+ * module init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_vchiq_driver(__vchiq_driver) \
+ module_driver(__vchiq_driver, vchiq_driver_register, vchiq_driver_unregister)
+
+#endif /* _VCHIQ_DEVICE_H */
--
2.40.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type
2023-09-13 19:53 ` [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type Umang Jain
@ 2023-09-13 20:58 ` Stefan Wahren
2023-09-14 22:15 ` Robin Murphy
2023-09-14 6:55 ` Dan Carpenter
2023-09-17 8:40 ` Stefan Wahren
2 siblings, 1 reply; 14+ messages in thread
From: Stefan Wahren @ 2023-09-13 20:58 UTC (permalink / raw)
To: Umang Jain, linux-staging, linux-arm-kernel, linux-rpi-kernel,
linux-media, linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
Hi Umang,
Am 13.09.23 um 21:53 schrieb Umang Jain:
> The devices that the vchiq interface registers (bcm2835-audio,
> bcm2835-camera) are implemented and exposed by the VC04 firmware.
> The device tree describes the VC04 itself with the resources required
> to communicate with it through a mailbox interface. However, the
> vchiq interface registers these devices as platform devices. This
> also means the specific drivers for these devices are getting
> registered as platform drivers. This is not correct and a blatant
> abuse of platform device/driver.
>
> Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
> which will be used to migrate child devices that the vchiq interfaces
> creates/registers from the platform device/driver.
>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
> drivers/staging/vc04_services/Makefile | 1 +
> .../interface/vchiq_arm/vchiq_device.c | 111 ++++++++++++++++++
> .../interface/vchiq_arm/vchiq_device.h | 54 +++++++++
> 3 files changed, 166 insertions(+)
> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>
> diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
> index 44794bdf6173..2d071e55e175 100644
> --- a/drivers/staging/vc04_services/Makefile
> +++ b/drivers/staging/vc04_services/Makefile
> @@ -5,6 +5,7 @@ vchiq-objs := \
> interface/vchiq_arm/vchiq_core.o \
> interface/vchiq_arm/vchiq_arm.o \
> interface/vchiq_arm/vchiq_debugfs.o \
> + interface/vchiq_arm/vchiq_device.o \
> interface/vchiq_arm/vchiq_connected.o \
>
> ifdef CONFIG_VCHIQ_CDEV
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> new file mode 100644
> index 000000000000..aad55c461905
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -0,0 +1,111 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * vchiq_device.c - VCHIQ generic device and bus-type
> + *
> + * Copyright (c) 2023 Ideas On Board Oy
> + */
> +
> +#include <linux/device/bus.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/of_device.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +
> +#include "vchiq_device.h"
> +
> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
> +{
> + if (dev->bus == &vchiq_bus_type &&
> + strcmp(dev_name(dev), drv->name) == 0)
> + return 1;
> +
> + return 0;
> +}
> +
> +static int vchiq_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)
> +{
> + const struct vchiq_device *device = container_of_const(dev, struct vchiq_device, dev);
> +
> + return add_uevent_var(env, "MODALIAS=%s", dev_name(&device->dev));
> +}
> +
> +static int vchiq_bus_probe(struct device *dev)
> +{
> + struct vchiq_device *device = to_vchiq_device(dev);
> + struct vchiq_driver *driver = to_vchiq_driver(dev->driver);
> + int ret;
> +
> + ret = driver->probe(device);
> + if (ret == 0)
> + return 0;
> +
> + return ret;
> +}
> +
> +struct bus_type vchiq_bus_type = {
> + .name = "vchiq-bus",
> + .match = vchiq_bus_type_match,
> + .uevent = vchiq_bus_uevent,
> + .probe = vchiq_bus_probe,
> +};
> +
> +static void vchiq_device_release(struct device *dev)
> +{
> + struct vchiq_device *device = to_vchiq_device(dev);
> +
> + kfree(device);
> +}
> +
> +struct vchiq_device *
> +vchiq_device_register(struct device *parent, const char *name)
> +{
> + struct vchiq_device *device;
> + int ret;
> +
> + device = kzalloc(sizeof(*device), GFP_KERNEL);
> + if (!device) {
> + dev_err(parent, "Cannot register %s: Insufficient memory\n",
> + name);
AFAIK kzalloc already logs an error in case of insufficient memory, so
there is no need for this.
> + return NULL;
> + }
> +
> + device->dev.init_name = name;
> + device->dev.parent = parent;
> + device->dev.bus = &vchiq_bus_type;
> + device->dev.release = vchiq_device_release;
> +
> + of_dma_configure(&device->dev, parent->of_node, true);
> + ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
From my understand Robin suggested to drop dma_set_mask_and_coherent()
here, too. In case this cause a regression until patch 3 & 4 are
applied. The DMA mask parts should be applied separately before this patch.
> + if (ret) {
> + dev_err(&device->dev, "32-bit DMA enable failed\n");
> + return NULL;
> + }
> +
> + ret = device_register(&device->dev);
> + if (ret) {
> + dev_err(parent, "Cannot register %s: %d\n", name, ret);
> + put_device(&device->dev);
Also Robin pointed out that there is a memory leak in the error path,
because the "device" get lost.
Thanks Stefan
> + return NULL;
> + }
> +
> + return device;
> +}
> +
> +void vchiq_device_unregister(struct vchiq_device *vchiq_dev)
> +{
> + device_unregister(&vchiq_dev->dev);
> +}
> +
> +int vchiq_driver_register(struct vchiq_driver *vchiq_drv)
> +{
> + vchiq_drv->driver.bus = &vchiq_bus_type;
> +
> + return driver_register(&vchiq_drv->driver);
> +}
> +EXPORT_SYMBOL_GPL(vchiq_driver_register);
> +
> +void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv)
> +{
> + driver_unregister(&vchiq_drv->driver);
> +}
> +EXPORT_SYMBOL_GPL(vchiq_driver_unregister);
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
> new file mode 100644
> index 000000000000..7eaaf9a91cda
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
> @@ -0,0 +1,54 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2023 Ideas On Board Oy
> + */
> +
> +#ifndef _VCHIQ_DEVICE_H
> +#define _VCHIQ_DEVICE_H
> +
> +#include <linux/device.h>
> +
> +struct vchiq_device {
> + struct device dev;
> +};
> +
> +struct vchiq_driver {
> + int (*probe)(struct vchiq_device *device);
> + void (*remove)(struct vchiq_device *device);
> + int (*resume)(struct vchiq_device *device);
> + int (*suspend)(struct vchiq_device *device,
> + pm_message_t state);
> + struct device_driver driver;
> +};
> +
> +static inline struct vchiq_device *to_vchiq_device(struct device *d)
> +{
> + return container_of(d, struct vchiq_device, dev);
> +}
> +
> +static inline struct vchiq_driver *to_vchiq_driver(struct device_driver *d)
> +{
> + return container_of(d, struct vchiq_driver, driver);
> +}
> +
> +extern struct bus_type vchiq_bus_type;
> +
> +struct vchiq_device *
> +vchiq_device_register(struct device *parent, const char *name);
> +void vchiq_device_unregister(struct vchiq_device *dev);
> +
> +int vchiq_driver_register(struct vchiq_driver *vchiq_drv);
> +void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv);
> +
> +/**
> + * module_vchiq_driver() - Helper macro for registering a vchiq driver
> + * @__vchiq_driver: vchiq driver struct
> + *
> + * Helper macro for vchiq drivers which do not do anything special in
> + * module init/exit. This eliminates a lot of boilerplate. Each module may only
> + * use this macro once, and calling it replaces module_init() and module_exit()
> + */
> +#define module_vchiq_driver(__vchiq_driver) \
> + module_driver(__vchiq_driver, vchiq_driver_register, vchiq_driver_unregister)
> +
> +#endif /* _VCHIQ_DEVICE_H */
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type
2023-09-13 20:58 ` Stefan Wahren
@ 2023-09-14 22:15 ` Robin Murphy
0 siblings, 0 replies; 14+ messages in thread
From: Robin Murphy @ 2023-09-14 22:15 UTC (permalink / raw)
To: Stefan Wahren, Umang Jain, linux-staging, linux-arm-kernel,
linux-rpi-kernel, linux-media, linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
On 2023-09-13 21:58, Stefan Wahren wrote:
> Hi Umang,
>
> Am 13.09.23 um 21:53 schrieb Umang Jain:
>> The devices that the vchiq interface registers (bcm2835-audio,
>> bcm2835-camera) are implemented and exposed by the VC04 firmware.
>> The device tree describes the VC04 itself with the resources required
>> to communicate with it through a mailbox interface. However, the
>> vchiq interface registers these devices as platform devices. This
>> also means the specific drivers for these devices are getting
>> registered as platform drivers. This is not correct and a blatant
>> abuse of platform device/driver.
>>
>> Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
>> which will be used to migrate child devices that the vchiq interfaces
>> creates/registers from the platform device/driver.
>>
>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
>> ---
>> drivers/staging/vc04_services/Makefile | 1 +
>> .../interface/vchiq_arm/vchiq_device.c | 111 ++++++++++++++++++
>> .../interface/vchiq_arm/vchiq_device.h | 54 +++++++++
>> 3 files changed, 166 insertions(+)
>> create mode 100644
>> drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> create mode 100644
>> drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>>
>> diff --git a/drivers/staging/vc04_services/Makefile
>> b/drivers/staging/vc04_services/Makefile
>> index 44794bdf6173..2d071e55e175 100644
>> --- a/drivers/staging/vc04_services/Makefile
>> +++ b/drivers/staging/vc04_services/Makefile
>> @@ -5,6 +5,7 @@ vchiq-objs := \
>> interface/vchiq_arm/vchiq_core.o \
>> interface/vchiq_arm/vchiq_arm.o \
>> interface/vchiq_arm/vchiq_debugfs.o \
>> + interface/vchiq_arm/vchiq_device.o \
>> interface/vchiq_arm/vchiq_connected.o \
>>
>> ifdef CONFIG_VCHIQ_CDEV
>> diff --git
>> a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> new file mode 100644
>> index 000000000000..aad55c461905
>> --- /dev/null
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> @@ -0,0 +1,111 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * vchiq_device.c - VCHIQ generic device and bus-type
>> + *
>> + * Copyright (c) 2023 Ideas On Board Oy
>> + */
>> +
>> +#include <linux/device/bus.h>
>> +#include <linux/dma-mapping.h>
>> +#include <linux/of_device.h>
>> +#include <linux/slab.h>
>> +#include <linux/string.h>
>> +
>> +#include "vchiq_device.h"
>> +
>> +static int vchiq_bus_type_match(struct device *dev, struct
>> device_driver *drv)
>> +{
>> + if (dev->bus == &vchiq_bus_type &&
>> + strcmp(dev_name(dev), drv->name) == 0)
>> + return 1;
>> +
>> + return 0;
>> +}
>> +
>> +static int vchiq_bus_uevent(const struct device *dev, struct
>> kobj_uevent_env *env)
>> +{
>> + const struct vchiq_device *device = container_of_const(dev,
>> struct vchiq_device, dev);
>> +
>> + return add_uevent_var(env, "MODALIAS=%s", dev_name(&device->dev));
>> +}
>> +
>> +static int vchiq_bus_probe(struct device *dev)
>> +{
>> + struct vchiq_device *device = to_vchiq_device(dev);
>> + struct vchiq_driver *driver = to_vchiq_driver(dev->driver);
>> + int ret;
>> +
>> + ret = driver->probe(device);
>> + if (ret == 0)
>> + return 0;
>> +
>> + return ret;
>> +}
>> +
>> +struct bus_type vchiq_bus_type = {
>> + .name = "vchiq-bus",
>> + .match = vchiq_bus_type_match,
>> + .uevent = vchiq_bus_uevent,
>> + .probe = vchiq_bus_probe,
>> +};
>> +
>> +static void vchiq_device_release(struct device *dev)
>> +{
>> + struct vchiq_device *device = to_vchiq_device(dev);
>> +
>> + kfree(device);
>> +}
>> +
>> +struct vchiq_device *
>> +vchiq_device_register(struct device *parent, const char *name)
>> +{
>> + struct vchiq_device *device;
>> + int ret;
>> +
>> + device = kzalloc(sizeof(*device), GFP_KERNEL);
>> + if (!device) {
>> + dev_err(parent, "Cannot register %s: Insufficient memory\n",
>> + name);
> AFAIK kzalloc already logs an error in case of insufficient memory, so
> there is no need for this.
>> + return NULL;
>> + }
>> +
>> + device->dev.init_name = name;
>> + device->dev.parent = parent;
>> + device->dev.bus = &vchiq_bus_type;
>> + device->dev.release = vchiq_device_release;
>> +
>> + of_dma_configure(&device->dev, parent->of_node, true);
>> + ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
> From my understand Robin suggested to drop dma_set_mask_and_coherent()
> here, too. In case this cause a regression until patch 3 & 4 are
> applied. The DMA mask parts should be applied separately before this patch.
Indeed, here we should have "device->dev.dma_mask =
&device->dev.dma_coherent_mask;", unconditionally, before
of_dma_configure() is called, and we should *not* be calling
dma_set_mask_and_coherent() at all. That will then be equivalent to what
the platform bus code was previously doing for these devices.
The vchiq_device drivers can then call dma_set_mask_and_coherent() if
they need to (AFAICS I'm not sure if they're actually using DMA at the
moment?) and should not touch dev->dma_mask directly. That does not need
to be done in any particular order relative to this patch, since the
truth is that of_dma_configure() will still initialise the masks to 32
bits by default anyway (as it currently does for the platform devices),
however it is still correct to add explicit calls (and handle their
potential failure if DMA is entirely unusable), and not simply assume
that the default masks are OK.
Hope that's clear.
Thanks,
Robin.
>> + if (ret) {
>> + dev_err(&device->dev, "32-bit DMA enable failed\n");
>> + return NULL;
>> + }
>> +
>> + ret = device_register(&device->dev);
>> + if (ret) {
>> + dev_err(parent, "Cannot register %s: %d\n", name, ret);
>> + put_device(&device->dev);
> Also Robin pointed out that there is a memory leak in the error path,
> because the "device" get lost.
>
> Thanks Stefan
>> + return NULL;
>> + }
>> +
>> + return device;
>> +}
>> +
>> +void vchiq_device_unregister(struct vchiq_device *vchiq_dev)
>> +{
>> + device_unregister(&vchiq_dev->dev);
>> +}
>> +
>> +int vchiq_driver_register(struct vchiq_driver *vchiq_drv)
>> +{
>> + vchiq_drv->driver.bus = &vchiq_bus_type;
>> +
>> + return driver_register(&vchiq_drv->driver);
>> +}
>> +EXPORT_SYMBOL_GPL(vchiq_driver_register);
>> +
>> +void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv)
>> +{
>> + driver_unregister(&vchiq_drv->driver);
>> +}
>> +EXPORT_SYMBOL_GPL(vchiq_driver_unregister);
>> diff --git
>> a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>> b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>> new file mode 100644
>> index 000000000000..7eaaf9a91cda
>> --- /dev/null
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>> @@ -0,0 +1,54 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Copyright (c) 2023 Ideas On Board Oy
>> + */
>> +
>> +#ifndef _VCHIQ_DEVICE_H
>> +#define _VCHIQ_DEVICE_H
>> +
>> +#include <linux/device.h>
>> +
>> +struct vchiq_device {
>> + struct device dev;
>> +};
>> +
>> +struct vchiq_driver {
>> + int (*probe)(struct vchiq_device *device);
>> + void (*remove)(struct vchiq_device *device);
>> + int (*resume)(struct vchiq_device *device);
>> + int (*suspend)(struct vchiq_device *device,
>> + pm_message_t state);
>> + struct device_driver driver;
>> +};
>> +
>> +static inline struct vchiq_device *to_vchiq_device(struct device *d)
>> +{
>> + return container_of(d, struct vchiq_device, dev);
>> +}
>> +
>> +static inline struct vchiq_driver *to_vchiq_driver(struct
>> device_driver *d)
>> +{
>> + return container_of(d, struct vchiq_driver, driver);
>> +}
>> +
>> +extern struct bus_type vchiq_bus_type;
>> +
>> +struct vchiq_device *
>> +vchiq_device_register(struct device *parent, const char *name);
>> +void vchiq_device_unregister(struct vchiq_device *dev);
>> +
>> +int vchiq_driver_register(struct vchiq_driver *vchiq_drv);
>> +void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv);
>> +
>> +/**
>> + * module_vchiq_driver() - Helper macro for registering a vchiq driver
>> + * @__vchiq_driver: vchiq driver struct
>> + *
>> + * Helper macro for vchiq drivers which do not do anything special in
>> + * module init/exit. This eliminates a lot of boilerplate. Each
>> module may only
>> + * use this macro once, and calling it replaces module_init() and
>> module_exit()
>> + */
>> +#define module_vchiq_driver(__vchiq_driver) \
>> + module_driver(__vchiq_driver, vchiq_driver_register,
>> vchiq_driver_unregister)
>> +
>> +#endif /* _VCHIQ_DEVICE_H */
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type
2023-09-13 19:53 ` [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type Umang Jain
2023-09-13 20:58 ` Stefan Wahren
@ 2023-09-14 6:55 ` Dan Carpenter
[not found] ` <700e11e4-057d-78ed-8b52-dd2df97198bf@ideasonboard.com>
2023-09-17 8:40 ` Stefan Wahren
2 siblings, 1 reply; 14+ messages in thread
From: Dan Carpenter @ 2023-09-14 6:55 UTC (permalink / raw)
To: Umang Jain
Cc: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel, Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
On Thu, Sep 14, 2023 at 01:23:50AM +0530, Umang Jain wrote:
> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
> +{
> + if (dev->bus == &vchiq_bus_type &&
> + strcmp(dev_name(dev), drv->name) == 0)
> + return 1;
> +
> + return 0;
> +}
I was not going to comment on this, because it's unfair to nitpick a
v11 patch... But since you're going to have to redo it anyway, could
you make this function bool and change it to return true/false.
static bool vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
{
if (dev->bus == &vchiq_bus_type &&
strcmp(dev_name(dev), drv->name) == 0)
return true;
return false;
}
> +static int vchiq_bus_probe(struct device *dev)
> +{
> + struct vchiq_device *device = to_vchiq_device(dev);
> + struct vchiq_driver *driver = to_vchiq_driver(dev->driver);
> + int ret;
> +
> + ret = driver->probe(device);
> + if (ret == 0)
> + return 0;
> +
> + return ret;
Ugh... I was going to ignore this as well, but later there is a
checkpatch warning so then I decided nitpicking was ok. Always do
error handling. if (ret). Never do success handling. if (!ret). But
here it can be done on one line.
return driver->probe(device);
> +}
> +
> +struct bus_type vchiq_bus_type = {
> + .name = "vchiq-bus",
> + .match = vchiq_bus_type_match,
> + .uevent = vchiq_bus_uevent,
> + .probe = vchiq_bus_probe,
> +};
> +
> +static void vchiq_device_release(struct device *dev)
> +{
> + struct vchiq_device *device = to_vchiq_device(dev);
> +
> + kfree(device);
> +}
> +
> +struct vchiq_device *
> +vchiq_device_register(struct device *parent, const char *name)
> +{
> + struct vchiq_device *device;
> + int ret;
> +
> + device = kzalloc(sizeof(*device), GFP_KERNEL);
> + if (!device) {
> + dev_err(parent, "Cannot register %s: Insufficient memory\n",
> + name);
Run checkpatch.pl -f on your files.
> + return NULL;
> + }
Stefan already commented on the other stuff I was going to say.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type
2023-09-13 19:53 ` [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type Umang Jain
2023-09-13 20:58 ` Stefan Wahren
2023-09-14 6:55 ` Dan Carpenter
@ 2023-09-17 8:40 ` Stefan Wahren
2 siblings, 0 replies; 14+ messages in thread
From: Stefan Wahren @ 2023-09-17 8:40 UTC (permalink / raw)
To: Umang Jain, linux-staging, linux-arm-kernel, linux-rpi-kernel,
linux-media, linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
Hi Umang,
Am 13.09.23 um 21:53 schrieb Umang Jain:
> The devices that the vchiq interface registers (bcm2835-audio,
> bcm2835-camera) are implemented and exposed by the VC04 firmware.
> The device tree describes the VC04 itself with the resources required
> to communicate with it through a mailbox interface. However, the
> vchiq interface registers these devices as platform devices. This
> also means the specific drivers for these devices are getting
> registered as platform drivers. This is not correct and a blatant
> abuse of platform device/driver.
>
> Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
> which will be used to migrate child devices that the vchiq interfaces
> creates/registers from the platform device/driver.
>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
> drivers/staging/vc04_services/Makefile | 1 +
> .../interface/vchiq_arm/vchiq_device.c | 111 ++++++++++++++++++
> .../interface/vchiq_arm/vchiq_device.h | 54 +++++++++
> 3 files changed, 166 insertions(+)
> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
sorry for not noticing this before, but there is already a vchiq_dev.c
file which represent the character device.
In order to avoid confusion how about renaming vchiq_device.c to
vchiq_bus.c ? This also matches the function names better.
> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>
> diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
> index 44794bdf6173..2d071e55e175 100644
> --- a/drivers/staging/vc04_services/Makefile
> +++ b/drivers/staging/vc04_services/Makefile
> @@ -5,6 +5,7 @@ vchiq-objs := \
> interface/vchiq_arm/vchiq_core.o \
> interface/vchiq_arm/vchiq_arm.o \
> interface/vchiq_arm/vchiq_debugfs.o \
> + interface/vchiq_arm/vchiq_device.o \
> interface/vchiq_arm/vchiq_connected.o \
>
> ifdef CONFIG_VCHIQ_CDEV
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> new file mode 100644
> index 000000000000..aad55c461905
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -0,0 +1,111 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * vchiq_device.c - VCHIQ generic device and bus-type
> + *
> + * Copyright (c) 2023 Ideas On Board Oy
> + */
> +
> +#include <linux/device/bus.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/of_device.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +
> +#include "vchiq_device.h"
> +
> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
> +{
> + if (dev->bus == &vchiq_bus_type &&
> + strcmp(dev_name(dev), drv->name) == 0)
> + return 1;
> +
> + return 0;
> +}
> +
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v11 2/5] staging: vc04_services: vchiq_arm: Register vchiq_bus_type
2023-09-13 19:53 [PATCH v11 0/5] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
2023-09-13 19:53 ` [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type Umang Jain
@ 2023-09-13 19:53 ` Umang Jain
2023-09-13 21:01 ` Stefan Wahren
2023-09-13 19:53 ` [PATCH v11 3/5] staging: bcm2835-camera: Register bcm2835-camera with vchiq_bus_type Umang Jain
` (2 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Umang Jain @ 2023-09-13 19:53 UTC (permalink / raw)
To: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart, Umang Jain
Register the vchiq_bus_type bus with the vchiq interface.
The bcm2835-camera and bcm2835_audio will be registered to this bus type
going ahead.
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
.../vc04_services/interface/vchiq_arm/vchiq_arm.c | 13 ++++++++++++-
.../interface/vchiq_arm/vchiq_device.c | 7 -------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index aa2313f3bcab..d993a91de237 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -12,6 +12,7 @@
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/device.h>
+#include <linux/device/bus.h>
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
@@ -34,6 +35,7 @@
#include "vchiq_ioctl.h"
#include "vchiq_arm.h"
#include "vchiq_debugfs.h"
+#include "vchiq_device.h"
#include "vchiq_connected.h"
#include "vchiq_pagelist.h"
@@ -1870,9 +1872,17 @@ static int __init vchiq_driver_init(void)
{
int ret;
+ ret = bus_register(&vchiq_bus_type);
+ if (ret) {
+ pr_err("Failed to register %s\n", vchiq_bus_type.name);
+ return ret;
+ }
+
ret = platform_driver_register(&vchiq_driver);
- if (ret)
+ if (ret) {
pr_err("Failed to register vchiq driver\n");
+ bus_unregister(&vchiq_bus_type);
+ }
return ret;
}
@@ -1880,6 +1890,7 @@ module_init(vchiq_driver_init);
static void __exit vchiq_driver_exit(void)
{
+ bus_unregister(&vchiq_bus_type);
platform_driver_unregister(&vchiq_driver);
}
module_exit(vchiq_driver_exit);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
index aad55c461905..b8c46f39e74a 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
@@ -74,13 +74,6 @@ vchiq_device_register(struct device *parent, const char *name)
device->dev.bus = &vchiq_bus_type;
device->dev.release = vchiq_device_release;
- of_dma_configure(&device->dev, parent->of_node, true);
- ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
- if (ret) {
- dev_err(&device->dev, "32-bit DMA enable failed\n");
- return NULL;
- }
-
ret = device_register(&device->dev);
if (ret) {
dev_err(parent, "Cannot register %s: %d\n", name, ret);
--
2.40.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v11 2/5] staging: vc04_services: vchiq_arm: Register vchiq_bus_type
2023-09-13 19:53 ` [PATCH v11 2/5] staging: vc04_services: vchiq_arm: Register vchiq_bus_type Umang Jain
@ 2023-09-13 21:01 ` Stefan Wahren
2023-09-14 8:22 ` Umang Jain
0 siblings, 1 reply; 14+ messages in thread
From: Stefan Wahren @ 2023-09-13 21:01 UTC (permalink / raw)
To: Umang Jain, linux-staging, linux-arm-kernel, linux-rpi-kernel,
linux-media, linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
Hi Umang,
Am 13.09.23 um 21:53 schrieb Umang Jain:
> Register the vchiq_bus_type bus with the vchiq interface.
> The bcm2835-camera and bcm2835_audio will be registered to this bus type
> going ahead.
>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
> .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 13 ++++++++++++-
> .../interface/vchiq_arm/vchiq_device.c | 7 -------
> 2 files changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index aa2313f3bcab..d993a91de237 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -12,6 +12,7 @@
> #include <linux/cdev.h>
> #include <linux/fs.h>
> #include <linux/device.h>
> +#include <linux/device/bus.h>
> #include <linux/mm.h>
> #include <linux/highmem.h>
> #include <linux/pagemap.h>
> @@ -34,6 +35,7 @@
> #include "vchiq_ioctl.h"
> #include "vchiq_arm.h"
> #include "vchiq_debugfs.h"
> +#include "vchiq_device.h"
> #include "vchiq_connected.h"
> #include "vchiq_pagelist.h"
>
> @@ -1870,9 +1872,17 @@ static int __init vchiq_driver_init(void)
> {
> int ret;
>
> + ret = bus_register(&vchiq_bus_type);
> + if (ret) {
> + pr_err("Failed to register %s\n", vchiq_bus_type.name);
> + return ret;
> + }
> +
> ret = platform_driver_register(&vchiq_driver);
> - if (ret)
> + if (ret) {
> pr_err("Failed to register vchiq driver\n");
> + bus_unregister(&vchiq_bus_type);
> + }
>
> return ret;
> }
> @@ -1880,6 +1890,7 @@ module_init(vchiq_driver_init);
>
> static void __exit vchiq_driver_exit(void)
> {
> + bus_unregister(&vchiq_bus_type);
> platform_driver_unregister(&vchiq_driver);
> }
> module_exit(vchiq_driver_exit);
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> index aad55c461905..b8c46f39e74a 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -74,13 +74,6 @@ vchiq_device_register(struct device *parent, const char *name)
> device->dev.bus = &vchiq_bus_type;
> device->dev.release = vchiq_device_release;
>
> - of_dma_configure(&device->dev, parent->of_node, true);
> - ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
> - if (ret) {
> - dev_err(&device->dev, "32-bit DMA enable failed\n");
> - return NULL;
> - }
> -
this code was added in the patch before and now it's removed again.
Please avoid this.
> ret = device_register(&device->dev);
> if (ret) {
> dev_err(parent, "Cannot register %s: %d\n", name, ret);
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v11 2/5] staging: vc04_services: vchiq_arm: Register vchiq_bus_type
2023-09-13 21:01 ` Stefan Wahren
@ 2023-09-14 8:22 ` Umang Jain
0 siblings, 0 replies; 14+ messages in thread
From: Umang Jain @ 2023-09-14 8:22 UTC (permalink / raw)
To: Stefan Wahren, linux-staging, linux-arm-kernel, linux-rpi-kernel,
linux-media, linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
Hi Stefan
On 9/14/23 2:31 AM, Stefan Wahren wrote:
> Hi Umang,
>
> Am 13.09.23 um 21:53 schrieb Umang Jain:
>> Register the vchiq_bus_type bus with the vchiq interface.
>> The bcm2835-camera and bcm2835_audio will be registered to this bus type
>> going ahead.
>>
>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>> .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 13 ++++++++++++-
>> .../interface/vchiq_arm/vchiq_device.c | 7 -------
>> 2 files changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git
>> a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> index aa2313f3bcab..d993a91de237 100644
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> @@ -12,6 +12,7 @@
>> #include <linux/cdev.h>
>> #include <linux/fs.h>
>> #include <linux/device.h>
>> +#include <linux/device/bus.h>
>> #include <linux/mm.h>
>> #include <linux/highmem.h>
>> #include <linux/pagemap.h>
>> @@ -34,6 +35,7 @@
>> #include "vchiq_ioctl.h"
>> #include "vchiq_arm.h"
>> #include "vchiq_debugfs.h"
>> +#include "vchiq_device.h"
>> #include "vchiq_connected.h"
>> #include "vchiq_pagelist.h"
>>
>> @@ -1870,9 +1872,17 @@ static int __init vchiq_driver_init(void)
>> {
>> int ret;
>>
>> + ret = bus_register(&vchiq_bus_type);
>> + if (ret) {
>> + pr_err("Failed to register %s\n", vchiq_bus_type.name);
>> + return ret;
>> + }
>> +
>> ret = platform_driver_register(&vchiq_driver);
>> - if (ret)
>> + if (ret) {
>> pr_err("Failed to register vchiq driver\n");
>> + bus_unregister(&vchiq_bus_type);
>> + }
>>
>> return ret;
>> }
>> @@ -1880,6 +1890,7 @@ module_init(vchiq_driver_init);
>>
>> static void __exit vchiq_driver_exit(void)
>> {
>> + bus_unregister(&vchiq_bus_type);
>> platform_driver_unregister(&vchiq_driver);
>> }
>> module_exit(vchiq_driver_exit);
>> diff --git
>> a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> index aad55c461905..b8c46f39e74a 100644
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> @@ -74,13 +74,6 @@ vchiq_device_register(struct device *parent, const
>> char *name)
>> device->dev.bus = &vchiq_bus_type;
>> device->dev.release = vchiq_device_release;
>>
>> - of_dma_configure(&device->dev, parent->of_node, true);
>> - ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
>> - if (ret) {
>> - dev_err(&device->dev, "32-bit DMA enable failed\n");
>> - return NULL;
>> - }
>> -
>
> this code was added in the patch before and now it's removed again.
> Please avoid this.
Ouch, fixup! got incorrectly squashed in this patch, should have been
squashed in earlier patch, apologies.
>
>> ret = device_register(&device->dev);
>> if (ret) {
>> dev_err(parent, "Cannot register %s: %d\n", name, ret);
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v11 3/5] staging: bcm2835-camera: Register bcm2835-camera with vchiq_bus_type
2023-09-13 19:53 [PATCH v11 0/5] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
2023-09-13 19:53 ` [PATCH v11 1/5] staging: vc04_services: vchiq_arm: Add new bus type and device type Umang Jain
2023-09-13 19:53 ` [PATCH v11 2/5] staging: vc04_services: vchiq_arm: Register vchiq_bus_type Umang Jain
@ 2023-09-13 19:53 ` Umang Jain
2023-09-13 19:53 ` [PATCH v11 4/5] staging: bcm2835-audio: Register bcm2835-audio " Umang Jain
2023-09-13 19:53 ` [PATCH v11 5/5] staging: vc04_services: vchiq_arm: Remove vchiq_register_child() Umang Jain
4 siblings, 0 replies; 14+ messages in thread
From: Umang Jain @ 2023-09-13 19:53 UTC (permalink / raw)
To: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart, Umang Jain
Register the bcm2835-camera with the vchiq_bus_type instead of using
platform driver/device.
Since we moved away bcm2835-camera from platform driver/device,
we have to set the DMA mask explicitly. Set the DMA mask at probe
time.
Also the VCHIQ firmware doesn't support device enumeration, hence
one has to maintain a list of devices to be registered in the interface.
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
.../bcm2835-camera/bcm2835-camera.c | 26 +++++++++++++------
.../interface/vchiq_arm/vchiq_arm.c | 11 +++++---
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 346d00df815a..52431b834232 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -11,6 +11,7 @@
* Luke Diamand @ Broadcom
*/
+#include <linux/dma-mapping.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -24,8 +25,9 @@
#include <media/v4l2-event.h>
#include <media/v4l2-common.h>
#include <linux/delay.h>
-#include <linux/platform_device.h>
+#include "../interface/vchiq_arm/vchiq_arm.h"
+#include "../interface/vchiq_arm/vchiq_device.h"
#include "../vchiq-mmal/mmal-common.h"
#include "../vchiq-mmal/mmal-encodings.h"
#include "../vchiq-mmal/mmal-vchiq.h"
@@ -1841,7 +1843,7 @@ static struct v4l2_format default_v4l2_format = {
.fmt.pix.sizeimage = 1024 * 768,
};
-static int bcm2835_mmal_probe(struct platform_device *pdev)
+static int bcm2835_mmal_probe(struct vchiq_device *device)
{
int ret;
struct bcm2835_mmal_dev *dev;
@@ -1852,6 +1854,14 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
unsigned int resolutions[MAX_BCM2835_CAMERAS][2];
int i;
+ if (!device->dev.dma_mask)
+ device->dev.dma_mask = &device->dev.coherent_dma_mask;
+ ret = dma_set_coherent_mask(&device->dev, DMA_BIT_MASK(32));
+ if (ret) {
+ dev_err(&device->dev, "can't set coherent DMA mask: %d\n", ret);
+ return ret;
+ }
+
ret = vchiq_mmal_init(&instance);
if (ret < 0)
return ret;
@@ -1896,7 +1906,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
&camera_instance);
ret = v4l2_device_register(NULL, &dev->v4l2_dev);
if (ret) {
- dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
+ dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
__func__, ret);
goto free_dev;
}
@@ -1976,7 +1986,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
return ret;
}
-static void bcm2835_mmal_remove(struct platform_device *pdev)
+static void bcm2835_mmal_remove(struct vchiq_device *device)
{
int camera;
struct vchiq_mmal_instance *instance = gdev[0]->instance;
@@ -1988,17 +1998,17 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
vchiq_mmal_finalise(instance);
}
-static struct platform_driver bcm2835_camera_driver = {
+static struct vchiq_driver bcm2835_camera_driver = {
.probe = bcm2835_mmal_probe,
- .remove_new = bcm2835_mmal_remove,
+ .remove = bcm2835_mmal_remove,
.driver = {
.name = "bcm2835-camera",
},
};
-module_platform_driver(bcm2835_camera_driver)
+module_vchiq_driver(bcm2835_camera_driver)
MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
MODULE_AUTHOR("Vincent Sanders");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:bcm2835-camera");
+MODULE_ALIAS("bcm2835-camera");
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index d993a91de237..14bdde610f3a 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -67,8 +67,13 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
DEFINE_SPINLOCK(msg_queue_spinlock);
struct vchiq_state g_state;
-static struct platform_device *bcm2835_camera;
static struct platform_device *bcm2835_audio;
+/*
+ * The devices implemented in the VCHIQ firmware are not discoverable,
+ * so we need to maintain a list of them in order to register them with
+ * the interface.
+ */
+static struct vchiq_device *bcm2835_camera;
struct vchiq_drvdata {
const unsigned int cache_line_size;
@@ -1840,8 +1845,8 @@ static int vchiq_probe(struct platform_device *pdev)
goto error_exit;
}
- bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera");
bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
+ bcm2835_camera = vchiq_device_register(&pdev->dev, "bcm2835-camera");
return 0;
@@ -1854,7 +1859,7 @@ static int vchiq_probe(struct platform_device *pdev)
static void vchiq_remove(struct platform_device *pdev)
{
platform_device_unregister(bcm2835_audio);
- platform_device_unregister(bcm2835_camera);
+ vchiq_device_unregister(bcm2835_camera);
vchiq_debugfs_deinit();
vchiq_deregister_chrdev();
}
--
2.40.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v11 4/5] staging: bcm2835-audio: Register bcm2835-audio with vchiq_bus_type
2023-09-13 19:53 [PATCH v11 0/5] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
` (2 preceding siblings ...)
2023-09-13 19:53 ` [PATCH v11 3/5] staging: bcm2835-camera: Register bcm2835-camera with vchiq_bus_type Umang Jain
@ 2023-09-13 19:53 ` Umang Jain
2023-09-13 19:53 ` [PATCH v11 5/5] staging: vc04_services: vchiq_arm: Remove vchiq_register_child() Umang Jain
4 siblings, 0 replies; 14+ messages in thread
From: Umang Jain @ 2023-09-13 19:53 UTC (permalink / raw)
To: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart, Umang Jain
Similar to how bcm2385-camera device is registered, register the
bcm2835-audio with vchiq_bus_type as well.
Since we moved away bcm2835-audio from platform driver/device,
we have to set the DMA mask explicitly. Set the DMA mask at probe
time.
Meanwhile at it, change the name and module alias from "bcm2835_audio"
to "bcm2835-audio" to be consistent with bcm2835-camera device. This
does not brings any functional change as '-' and '_' are
interchangeable as per modprobe man pages.
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
.../vc04_services/bcm2835-audio/bcm2835.c | 29 ++++++++++++-------
.../interface/vchiq_arm/vchiq_arm.c | 6 ++--
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 00bc898b0189..7d945703d97f 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2011 Broadcom Corporation. All rights reserved. */
-#include <linux/platform_device.h>
-
+#include <linux/dma-mapping.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include "../interface/vchiq_arm/vchiq_arm.h"
+#include "../interface/vchiq_arm/vchiq_device.h"
#include "bcm2835.h"
static bool enable_hdmi;
@@ -268,11 +269,19 @@ static int snd_add_child_devices(struct device *device, u32 numchans)
return 0;
}
-static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
+static int snd_bcm2835_alsa_probe(struct vchiq_device *device)
{
- struct device *dev = &pdev->dev;
+ struct device *dev = &device->dev;
int err;
+ if (!dev->dma_mask)
+ dev->dma_mask = &dev->coherent_dma_mask;
+ err = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
+ if (err) {
+ dev_err(dev, "can't set coherent DMA mask: %d\n", err);
+ return err;
+ }
+
if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
num_channels = MAX_SUBSTREAMS;
dev_warn(dev, "Illegal num_channels value, will use %u\n",
@@ -292,32 +301,32 @@ static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
#ifdef CONFIG_PM
-static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
+static int snd_bcm2835_alsa_suspend(struct vchiq_device *device,
pm_message_t state)
{
return 0;
}
-static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
+static int snd_bcm2835_alsa_resume(struct vchiq_device *device)
{
return 0;
}
#endif
-static struct platform_driver bcm2835_alsa_driver = {
+static struct vchiq_driver bcm2835_alsa_driver = {
.probe = snd_bcm2835_alsa_probe,
#ifdef CONFIG_PM
.suspend = snd_bcm2835_alsa_suspend,
.resume = snd_bcm2835_alsa_resume,
#endif
.driver = {
- .name = "bcm2835_audio",
+ .name = "bcm2835-audio",
},
};
-module_platform_driver(bcm2835_alsa_driver);
+module_vchiq_driver(bcm2835_alsa_driver);
MODULE_AUTHOR("Dom Cobley");
MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:bcm2835_audio");
+MODULE_ALIAS("bcm2835-audio");
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 14bdde610f3a..2da470740cda 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -67,12 +67,12 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
DEFINE_SPINLOCK(msg_queue_spinlock);
struct vchiq_state g_state;
-static struct platform_device *bcm2835_audio;
/*
* The devices implemented in the VCHIQ firmware are not discoverable,
* so we need to maintain a list of them in order to register them with
* the interface.
*/
+static struct vchiq_device *bcm2835_audio;
static struct vchiq_device *bcm2835_camera;
struct vchiq_drvdata {
@@ -1845,7 +1845,7 @@ static int vchiq_probe(struct platform_device *pdev)
goto error_exit;
}
- bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
+ bcm2835_audio = vchiq_device_register(&pdev->dev, "bcm2835-audio");
bcm2835_camera = vchiq_device_register(&pdev->dev, "bcm2835-camera");
return 0;
@@ -1858,7 +1858,7 @@ static int vchiq_probe(struct platform_device *pdev)
static void vchiq_remove(struct platform_device *pdev)
{
- platform_device_unregister(bcm2835_audio);
+ vchiq_device_unregister(bcm2835_audio);
vchiq_device_unregister(bcm2835_camera);
vchiq_debugfs_deinit();
vchiq_deregister_chrdev();
--
2.40.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v11 5/5] staging: vc04_services: vchiq_arm: Remove vchiq_register_child()
2023-09-13 19:53 [PATCH v11 0/5] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
` (3 preceding siblings ...)
2023-09-13 19:53 ` [PATCH v11 4/5] staging: bcm2835-audio: Register bcm2835-audio " Umang Jain
@ 2023-09-13 19:53 ` Umang Jain
2023-09-14 6:45 ` Dan Carpenter
4 siblings, 1 reply; 14+ messages in thread
From: Umang Jain @ 2023-09-13 19:53 UTC (permalink / raw)
To: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel
Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart, Umang Jain
vchiq_register_child() is used to registered child devices as platform
devices. Now that the child devices are migrated to use the
vchiq_bus_type instead, they will be registered to that. Hence, drop
vchiq_register_child() as it is no more required.
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
.../interface/vchiq_arm/vchiq_arm.c | 22 -------------------
1 file changed, 22 deletions(-)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 2da470740cda..5eccf5b277e5 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1776,28 +1776,6 @@ static const struct of_device_id vchiq_of_match[] = {
};
MODULE_DEVICE_TABLE(of, vchiq_of_match);
-static struct platform_device *
-vchiq_register_child(struct platform_device *pdev, const char *name)
-{
- struct platform_device_info pdevinfo;
- struct platform_device *child;
-
- memset(&pdevinfo, 0, sizeof(pdevinfo));
-
- pdevinfo.parent = &pdev->dev;
- pdevinfo.name = name;
- pdevinfo.id = PLATFORM_DEVID_NONE;
- pdevinfo.dma_mask = DMA_BIT_MASK(32);
-
- child = platform_device_register_full(&pdevinfo);
- if (IS_ERR(child)) {
- dev_warn(&pdev->dev, "%s not registered\n", name);
- child = NULL;
- }
-
- return child;
-}
-
static int vchiq_probe(struct platform_device *pdev)
{
struct device_node *fw_node;
--
2.40.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v11 5/5] staging: vc04_services: vchiq_arm: Remove vchiq_register_child()
2023-09-13 19:53 ` [PATCH v11 5/5] staging: vc04_services: vchiq_arm: Remove vchiq_register_child() Umang Jain
@ 2023-09-14 6:45 ` Dan Carpenter
0 siblings, 0 replies; 14+ messages in thread
From: Dan Carpenter @ 2023-09-14 6:45 UTC (permalink / raw)
To: Umang Jain
Cc: linux-staging, linux-arm-kernel, linux-rpi-kernel, linux-media,
linux-kernel, Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
Laurent Pinchart
On Thu, Sep 14, 2023 at 01:23:54AM +0530, Umang Jain wrote:
> vchiq_register_child() is used to registered child devices as platform
> devices. Now that the child devices are migrated to use the
> vchiq_bus_type instead, they will be registered to that. Hence, drop
> vchiq_register_child() as it is no more required.
This needs to be folded together with patch 4. Otherwise it introduces
a compile warning which breaks git bisect. (I haven't tested this so
I'm going to be so embarrassed if I'm wrong).
regards,
dan carpenter
^ permalink raw reply [flat|nested] 14+ messages in thread