drm/tegra: Convert to master/component framework
Subsystems (11)
v2 cover drm/tegra: Convert to master/component framework
From: Thierry Reding <[email protected]>
Hi,
This series converts the Tegra DRM driver to the master/component framework. The length of the series and the list of people in Cc is mostly due to the fact that Tegra has some special requirements as opposed to other drivers and therefore requires some changes outside of DRM.
Patch 1 introduces a helper function that can be used by new DRM drivers that don't rely on legacy userspace ABIs. It allows them to register DRM devices much more easily and without much of the midlayer that currently exists in the DRM subsystem.
Patches 2 and 3 make some changes to the master/component framework which are necessary to convert Tegra DRM to use it. All current users of the API have been converted as part of this patch. Note that at the same time the drivers are converted to no longer use drm_platform_init() in favour of the drm_set_unique() from patch 1 in conjunction with drm_dev_alloc() and drm_dev_register(). I would've liked to avoid such invasive changes in a single patch, but unfortunately I couldn't think of a way how to do that. I'm open to suggestions.
Patch 4 adds a new interface framework that supplements the master/ component framework and can be used in situations where there is no struct device * that a driver can bind to.
The Tegra DRM driver is converted to using the master/component framework in patch 5 using the above four patches.
Finally patches 6 and 7 add some documentation about the new way of registering DRM devices that don't need legacy support.
Each patch has a somewhat more elaborate description of why it is needed or what problem it solves. The patchset applies on top of linux-next.
I welcome any questions or comments you might have.
Thierry
Thierry Reding (7):
drm: Introduce drm_set_unique()
drivers/base: Allow driver-data to be attached to a master drivers/base: Allow multiple masters per device drivers/base: Add interface framework
drm/tegra: Convert to master/component framework
drm: Add device registration documentation
drm: Document how to register devices without struct drm_bus
Documentation/DocBook/drm.tmpl | 38 ++ drivers/base/Makefile | 2 +- drivers/base/component.c | 31 +- drivers/base/interface.c | 186 ++++++++++ drivers/gpu/drm/drm_ioctl.c | 23 +- drivers/gpu/drm/drm_pci.c | 80 ++--- drivers/gpu/drm/drm_platform.c | 15 +- drivers/gpu/drm/drm_stub.c | 43 ++- drivers/gpu/drm/drm_usb.c | 20 +- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 8 +- drivers/gpu/drm/msm/hdmi/hdmi.c | 8 +- drivers/gpu/drm/msm/msm_drv.c | 75 ++-- drivers/gpu/drm/msm/msm_drv.h | 1 + drivers/gpu/drm/tegra/Makefile | 1 - drivers/gpu/drm/tegra/bus.c | 64 ---- drivers/gpu/drm/tegra/dc.c | 58 ++- drivers/gpu/drm/tegra/drm.c | 171 ++++++--- drivers/gpu/drm/tegra/drm.h | 27 +- drivers/gpu/drm/tegra/dsi.c | 144 ++++---- drivers/gpu/drm/tegra/gr2d.c | 78 ++-- drivers/gpu/drm/tegra/gr3d.c | 77 ++-- drivers/gpu/drm/tegra/hdmi.c | 69 ++-- drivers/gpu/drm/tegra/sor.c | 71 ++-- drivers/gpu/host1x/Makefile | 1 - drivers/gpu/host1x/bus.c | 553 ----------------------------- drivers/gpu/host1x/bus.h | 29 -- drivers/gpu/host1x/dev.c | 21 +- drivers/gpu/host1x/dev.h | 7 +- drivers/staging/imx-drm/imx-drm-core.c | 58 +-- drivers/staging/imx-drm/imx-hdmi.c | 4 +- drivers/staging/imx-drm/imx-ldb.c | 4 +- drivers/staging/imx-drm/imx-tve.c | 4 +- drivers/staging/imx-drm/ipuv3-crtc.c | 4 +- drivers/staging/imx-drm/parallel-display.c | 4 +- include/drm/drmP.h | 3 + include/linux/component.h | 20 +- include/linux/host1x.h | 64 +--- include/linux/interface.h | 40 +++ 38 files changed, 849 insertions(+), 1257 deletions(-) create mode 100644 drivers/base/interface.c delete mode 100644 drivers/gpu/drm/tegra/bus.c delete mode 100644 drivers/gpu/host1x/bus.c delete mode 100644 drivers/gpu/host1x/bus.h create mode 100644 include/linux/interface.h
Signature · 1 line
1.9.2
PATCH v2 1/7 drm: Introduce drm_set_unique()
From: Thierry Reding <[email protected]>
Add a helper function that allows drivers to statically set the unique name of the device. This will allow platform and USB drivers to get rid of their DRM bus implementations and directly use drm_dev_alloc() and drm_dev_register().
---
Changes in v2:
- move drm_set_unique() to drivers/gpu/drm/drm_stub.c
- add kernel-doc
drivers/gpu/drm/drm_ioctl.c | 23 +++++++++++++++++------ drivers/gpu/drm/drm_stub.c | 24 ++++++++++++++++++++++++ include/drm/drmP.h | 3 +++ 3 files changed, 44 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +17 -6
@@ -131,13 +131,24 @@ static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)if (master->unique !=NULL )drm_unset_busid (dev, master); - ret = dev->driver->bus->set_busid (dev, master); -if (ret) - goto err; +if (dev->driver->bus && dev->driver->bus->set_busid) { + ret = dev->driver->bus->set_busid (dev, master); +if (ret) { +drm_unset_busid (dev, master); +return ret; + } + }else { +WARN (dev->unique ==NULL , +"No drm_bus.set_busid() implementation provided by %ps. " +"Set the unique name explicitly using drm_set_unique()." , + dev->driver); + + master->unique =kstrdup (dev->unique,GFP_KERNEL ); +if (master->unique) + master->unique_len =strlen (dev->unique); + } +return 0 ; -err: -drm_unset_busid (dev, master); -return ret; }/**
drivers/gpu/drm/drm_stub.c +24 -0
@@ -535,6 +535,29 @@ static void drm_fs_inode_free(struct inode *inode) }/** +* drm_set_unique - Set the unique name of a DRM device +* @dev: device of which to set the unique name +* @fmt: format string for unique name +* +* Sets the unique name of a DRM device using the specified format string and +* a variable list of arguments. Drivers can use this at driver probe time if +* the unique name of the devices they drive is static. +*/ +int drm_set_unique (struct drm_device *dev,const char *fmt, ...) +{ +va_list ap; + +kfree (dev->unique); + +va_start (ap, fmt); + dev->unique =kvasprintf (GFP_KERNEL , fmt, ap); +va_end (ap); + +return dev->unique ?0 : -ENOMEM ; +} +EXPORT_SYMBOL (drm_set_unique); + +/** * drm_dev_alloc - Allocate new drm device * @driver: DRM driver to allocate device for * @parent: Parent device object
@@ -649,6 +672,7 @@ static void drm_dev_release(struct kref *ref)drm_minor_free (dev,DRM_MINOR_CONTROL );mutex_destroy (&dev->master_mutex); +kfree (dev->unique);kfree (dev); }
include/drm/drmP.h +3 -0
@@ -1235,6 +1235,8 @@ struct drm_device {struct drm_vma_offset_manager *vma_offset_manager;/*@} */ int switch_power_state; + +char *unique; };#define DRM_SWITCH_POWER_ON 0
@@ -1680,6 +1682,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)#include <drm/drm_mem_util.h> +int drm_set_unique (struct drm_device *dev,const char *fmt, ...);struct drm_device *drm_dev_alloc (struct drm_driver *driver,struct device *parent);void drm_dev_ref (struct drm_device *dev);
Signature · 1 line
1.9.2
PATCH v2 2/7 drivers/base: Allow driver-data to be attached to a master
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Similarly to what can be done for device drivers, allow driver-specific data to be attached to a master. This is necessary for masters whose device is already bound to by a different driver and therefore cannot be used to store the driver-specific data.
---
Note that I'd like to merge this patch through the Tegra DRM tree so that the Tegra DRM changes later in this patch can be merged at the same time to avoid them being delayed for another release cycle.
In particular I'm looking for an Acked-by from Greg and Russell.
drivers/base/component.c | 13 +++++++++++++ include/linux/component.h | 3 +++ 2 files changed, 16 insertions(+)
drivers/base/component.c +13 -0
@@ -25,6 +25,8 @@ struct master {const struct component_master_ops *ops;struct device *dev; + +void *drvdata; };struct component {
@@ -53,6 +55,17 @@ static struct master *__master_find(struct device *dev,return NULL ; } +void master_set_drvdata (struct master *master,void *data) +{ +if (master) + master->drvdata = data; +} + +void *master_get_drvdata (struct master *master) +{ +return master ? master->drvdata :NULL ; +} +/* Attach an unattached component to a master. */ static void component_attach_master (struct master *master,struct component *c) {
include/linux/component.h +3 -0
@@ -26,6 +26,9 @@ int component_master_add(struct device *, const struct component_master_ops *);void component_master_del (struct device *,const struct component_master_ops *); +void master_set_drvdata (struct master *,void *); +void *master_get_drvdata (struct master *); +int component_master_add_child (struct master *master,int (*compare)(struct device *,void *),void *compare_data);
Signature · 1 line
1.9.2
PATCH v2 3/7 drivers/base: Allow multiple masters per device
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Currently the component/master framework allows only a single master to be registered against a struct device. A master is uniquely identified by the device and the master operations table, but the current API does not pass enough information along to allow a master to be uniquely identified when calling component_unbind_all().
To make it possible to register multiple masters on one device, instead of passing around the device associated with a master, pass around the master directly. That way it can always be uniquely identified.
The two existing users of the component/master framework need to be converted as part of this patch because the API is changed in an incompatible way. Since the master needs to be associated with the DRM devices at a precise point, this also drops the drm_platform_init() call and replaces it by direct drm_dev_alloc()/drm_dev_register() usage.
---
Changes in v2:
- convert existing users (staging/imx-drm, gpu/drm/msm)
Notes: I'd like to take this through the Tegra DRM tree if possible so that the Tegra DRM changes later in this series can be merged at the same time so as not to delay them for another release cycle.
In particular I'm looking for an Acked-by from Greg and Russell.
drivers/base/component.c | 18 +++---- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 8 ++-- drivers/gpu/drm/msm/hdmi/hdmi.c | 8 ++-- drivers/gpu/drm/msm/msm_drv.c | 75 ++++++++++++++++++++---------- drivers/gpu/drm/msm/msm_drv.h | 1 + drivers/staging/imx-drm/imx-drm-core.c | 58 ++++++++++++++--------- drivers/staging/imx-drm/imx-hdmi.c | 4 +- drivers/staging/imx-drm/imx-ldb.c | 4 +- drivers/staging/imx-drm/imx-tve.c | 4 +- drivers/staging/imx-drm/ipuv3-crtc.c | 4 +- drivers/staging/imx-drm/parallel-display.c | 4 +- include/linux/component.h | 17 ++++--- 12 files changed, 120 insertions(+), 85 deletions(-)
drivers/base/component.c +7 -11
@@ -133,7 +133,7 @@ static int try_to_bring_up_master(struct master *master,* Search the list of components, looking for components that * belong to this master, and attach them to the master. */ -if (master->ops->add_components (master->dev, master)) { +if (master->ops->add_components (master, master->dev)) {/* Failed to find all components */ master_remove_components (master); ret =0 ;
@@ -152,7 +152,7 @@ static int try_to_bring_up_master(struct master *master, }/* Found all components */ - ret = master->ops->bind (master->dev); + ret = master->ops->bind (master, master->dev);if (ret <0 ) {devres_release_group (master->dev,NULL );dev_info (master->dev,"master bind failed: %d\n" , ret);
@@ -185,7 +185,7 @@ static int try_to_bring_up_masters(struct component *component)static void take_down_master (struct master *master) {if (master->bound) { - master->ops->unbind (master->dev); + master->ops->unbind (master, master->dev);devres_release_group (master->dev,NULL ); master->bound = false; }
@@ -246,21 +246,19 @@ static void component_unbind(struct component *component, {WARN_ON (!component->bound); - component->ops->unbind (component->dev, master->dev, data); + component->ops->unbind (component->dev, master, data); component->bound = false;/* Release all resources claimed in the binding of this component */ devres_release_group (component->dev, component); } -void component_unbind_all (struct device *master_dev,void *data) +void component_unbind_all (struct master *master,void *data) { -struct master *master;struct component *c;WARN_ON (!mutex_is_locked (&component_mutex)); - master =__master_find (master_dev,NULL );if (!master)return ;
@@ -295,7 +293,7 @@ static int component_bind(struct component *component, struct master *master,dev_dbg (master->dev,"binding %s (ops %ps)\n" ,dev_name (component->dev), component->ops); - ret = component->ops->bind (component->dev, master->dev, data); + ret = component->ops->bind (component->dev, master, data);if (!ret) { component->bound = true;
@@ -321,15 +319,13 @@ static int component_bind(struct component *component, struct master *master,return ret; } -int component_bind_all (struct device *master_dev,void *data) +int component_bind_all (struct master *master,void *data) { -struct master *master;struct component *c;int ret =0 ;WARN_ON (!mutex_is_locked (&component_mutex)); - master =__master_find (master_dev,NULL );if (!master)return -EINVAL ;
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +4 -4
@@ -560,7 +560,7 @@ static void set_gpu_pdev(struct drm_device *dev, priv->gpu_pdev = pdev; } -static int a3xx_bind (struct device *dev,struct device *master,void *data) +static int a3xx_bind (struct device *dev,struct master *master,void *data) {static struct adreno_platform_config config = {};#ifdef CONFIG_OF
@@ -648,14 +648,14 @@ static int a3xx_bind(struct device *dev, struct device *master, void *data)# endif #endif dev->platform_data = &config; -set_gpu_pdev (dev_get_drvdata (master),to_platform_device (dev)); +set_gpu_pdev (master_get_drvdata (master),to_platform_device (dev));return 0 ; } -static void a3xx_unbind (struct device *dev,struct device *master, +static void a3xx_unbind (struct device *dev,struct master *master,void *data) { -set_gpu_pdev (dev_get_drvdata (master),NULL ); +set_gpu_pdev (master_get_drvdata (master),NULL ); }static const struct component_ops a3xx_ops = {
drivers/gpu/drm/msm/hdmi/hdmi.c +4 -4
@@ -256,7 +256,7 @@ static void set_hdmi_pdev(struct drm_device *dev, priv->hdmi_pdev = pdev; } -static int hdmi_bind (struct device *dev,struct device *master,void *data) +static int hdmi_bind (struct device *dev,struct master *master,void *data) {static struct hdmi_platform_config config = {};#ifdef CONFIG_OF
@@ -344,14 +344,14 @@ static int hdmi_bind(struct device *dev, struct device *master, void *data) }#endif dev->platform_data = &config; -set_hdmi_pdev (dev_get_drvdata (master),to_platform_device (dev)); +set_hdmi_pdev (master_get_drvdata (master),to_platform_device (dev));return 0 ; } -static void hdmi_unbind (struct device *dev,struct device *master, +static void hdmi_unbind (struct device *dev,struct master *master,void *data) { -set_hdmi_pdev (dev_get_drvdata (master),NULL ); +set_hdmi_pdev (master_get_drvdata (master),NULL ); } static const struct component_ops hdmi_ops = {
drivers/gpu/drm/msm/msm_drv.c +50 -25
137 lines not on this page · raw message
drivers/gpu/drm/msm/msm_drv.h +1 -0
@@ -68,6 +68,7 @@ struct msm_file_private { };struct msm_drm_private { +struct master *master;struct msm_kms *kms;
drivers/staging/imx-drm/imx-drm-core.c +36 -22
120 lines not on this page · raw message
drivers/staging/imx-drm/imx-hdmi.c +2 -2
@@ -1584,7 +1584,7 @@ static const struct of_device_id imx_hdmi_dt_ids[] = { };MODULE_DEVICE_TABLE (of, imx_hdmi_dt_ids); -static int imx_hdmi_bind (struct device *dev,struct device *master,void *data) +static int imx_hdmi_bind (struct device *dev,struct master *master,void *data) {struct platform_device *pdev =to_platform_device (dev); const struct of_device_id *of_id =
@@ -1717,7 +1717,7 @@ err_isfr:return ret; } -static void imx_hdmi_unbind (struct device *dev,struct device *master, +static void imx_hdmi_unbind (struct device *dev,struct master *master,void *data) {struct imx_hdmi *hdmi =dev_get_drvdata (dev);
drivers/staging/imx-drm/imx-ldb.c +2 -2
@@ -436,7 +436,7 @@ static const struct of_device_id imx_ldb_dt_ids[] = { };MODULE_DEVICE_TABLE (of, imx_ldb_dt_ids); -static int imx_ldb_bind (struct device *dev,struct device *master,void *data) +static int imx_ldb_bind (struct device *dev,struct master *master,void *data) {struct drm_device *drm = data;struct device_node *np = dev->of_node;
@@ -566,7 +566,7 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)return 0 ; } -static void imx_ldb_unbind (struct device *dev,struct device *master, +static void imx_ldb_unbind (struct device *dev,struct master *master,void *data) {struct imx_ldb *imx_ldb =dev_get_drvdata (dev);
drivers/staging/imx-drm/imx-tve.c +2 -2
@@ -562,7 +562,7 @@ static const int of_get_tve_mode(struct device_node *np)return -EINVAL ; } -static int imx_tve_bind (struct device *dev,struct device *master,void *data) +static int imx_tve_bind (struct device *dev,struct master *master,void *data) {struct platform_device *pdev =to_platform_device (dev);struct drm_device *drm = data;
@@ -689,7 +689,7 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data)return 0 ; } -static void imx_tve_unbind (struct device *dev,struct device *master, +static void imx_tve_unbind (struct device *dev,struct master *master,void *data) {struct imx_tve *tve =dev_get_drvdata (dev);
drivers/staging/imx-drm/ipuv3-crtc.c +2 -2
@@ -429,7 +429,7 @@ static struct device_node *ipu_drm_get_port_by_id(struct device_node *parent,return NULL ; } -static int ipu_drm_bind (struct device *dev,struct device *master,void *data) +static int ipu_drm_bind (struct device *dev,struct master *master,void *data) {struct ipu_client_platformdata *pdata = dev->platform_data;struct drm_device *drm = data;
@@ -451,7 +451,7 @@ static int ipu_drm_bind(struct device *dev, struct device *master, void *data)return 0 ; } -static void ipu_drm_unbind (struct device *dev,struct device *master, +static void ipu_drm_unbind (struct device *dev,struct master *master,void *data) {struct ipu_crtc *ipu_crtc =dev_get_drvdata (dev);
drivers/staging/imx-drm/parallel-display.c +2 -2
@@ -193,7 +193,7 @@ static int imx_pd_register(struct drm_device *drm,return 0 ; } -static int imx_pd_bind (struct device *dev,struct device *master,void *data) +static int imx_pd_bind (struct device *dev,struct master *master,void *data) {struct drm_device *drm = data;struct device_node *np = dev->of_node;
@@ -238,7 +238,7 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data)return 0 ; } -static void imx_pd_unbind (struct device *dev,struct device *master, +static void imx_pd_unbind (struct device *dev,struct master *master,void *data) {struct imx_parallel_display *imxpd =dev_get_drvdata (dev);
include/linux/component.h +8 -9
@@ -2,24 +2,23 @@#define COMPONENT_H struct device ; +struct master ;struct component_ops { -int (*bind)(struct device *,struct device *,void *); -void (*unbind)(struct device *,struct device *,void *); +int (*bind)(struct device *,struct master *,void *); +void (*unbind)(struct device *,struct master *,void *); };int component_add (struct device *,const struct component_ops *);void component_del (struct device *,const struct component_ops *); -int component_bind_all (struct device *,void *); -void component_unbind_all (struct device *,void *); - -struct master ; +int component_bind_all (struct master *,void *); +void component_unbind_all (struct master *,void *);struct component_master_ops { -int (*add_components)(struct device *,struct master *); -int (*bind)(struct device *); -void (*unbind)(struct device *); +int (*add_components)(struct master *,struct device *); +int (*bind)(struct master *,struct device *); +void (*unbind)(struct master *,struct device *); };int component_master_add (struct device *,const struct component_master_ops *);
Signature · 1 line
1.9.2
PATCH v2 4/7 drivers/base: Add interface framework
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x {
display-controller {
...
};
display-controller {
...
};
hdmi {
...
};
dsi {
...
};
csi {
...
};
video-input {
...
};
};Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.h
drivers/base/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-y := component.o core.o bus.o dd.o syscore.o \ driver.o class.o platform.o \ cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o \ - topology.o container.o + topology.o container.o interface.o obj-$(CONFIG_DEVTMPFS) += devtmpfs.o obj-$(CONFIG_DMA_CMA) += dma-contiguous.o obj-y += power/
drivers/base/interface.c new file +186 -0
186 lines not on this page · raw message
include/linux/interface.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2014 NVIDIA Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef INTERFACE_H +#define INTERFACE_H + +#include <linux/list.h> + +struct device ; +struct interface ; + +struct interface_driver { +const char *name; + +int (*bind)(struct interface *intf); +void (*unbind)(struct interface *intf); + +struct list_head list; +}; + +int interface_register_driver (struct interface_driver *driver); +void interface_unregister_driver (struct interface_driver *driver); + +struct interface { +const char *name; +struct device *dev; + +struct list_head drivers; +struct list_head list; +}; + +int interface_add (struct interface *intf); +void interface_remove (struct interface *intf); + +#endif
Signature · 1 line
1.9.2
PATCH v2 5/7 drm/tegra: Convert to master/component framework
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Instead of the current implementation, reuse the recently introduced master/component framework, which is equivalent in most regards. One issue is that there is no device to bind the DRM driver to. In order to still allow the driver to be probed, expose an interface from the host1x device and provide an interface driver to bind to that.
The interface driver then registers (or removes) the master that will be used to instantiate and bind the DRM driver. Since the drm_host1x bus implementation is now gone the dummy device instantiated by it can no longer be used as the parent for the DRM device. However since the parent device doesn't need to be modified, the host1x parent device that exposes the interface can be used instead.
--- drivers/gpu/drm/tegra/Makefile | 1 - drivers/gpu/drm/tegra/bus.c | 64 ----- drivers/gpu/drm/tegra/dc.c | 58 ++--- drivers/gpu/drm/tegra/drm.c | 171 +++++++++---- drivers/gpu/drm/tegra/drm.h | 27 +- drivers/gpu/drm/tegra/dsi.c | 144 +++++------ drivers/gpu/drm/tegra/gr2d.c | 78 +++--- drivers/gpu/drm/tegra/gr3d.c | 77 +++--- drivers/gpu/drm/tegra/hdmi.c | 69 ++--- drivers/gpu/drm/tegra/sor.c | 71 ++---- drivers/gpu/host1x/Makefile | 1 - drivers/gpu/host1x/bus.c | 553 ----------------------------------------- drivers/gpu/host1x/bus.h | 29 --- drivers/gpu/host1x/dev.c | 21 +- drivers/gpu/host1x/dev.h | 7 +- include/linux/host1x.h | 64 +---- 16 files changed, 332 insertions(+), 1103 deletions(-) delete mode 100644 drivers/gpu/drm/tegra/bus.c delete mode 100644 drivers/gpu/host1x/bus.c delete mode 100644 drivers/gpu/host1x/bus.h
drivers/gpu/drm/tegra/Makefile +0 -1
@@ -1,7 +1,6 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG tegra-drm-y := \ - bus.o \ drm.o \ gem.o \ fb.o \
drivers/gpu/drm/tegra/bus.c deleted +0 -64
64 lines not on this page · raw message
drivers/gpu/drm/tegra/dc.c +22 -36
126 lines not on this page · raw message
drivers/gpu/drm/tegra/drm.c +117 -54
288 lines not on this page · raw message
drivers/gpu/drm/tegra/drm.h +6 -21
@@ -36,6 +36,7 @@ struct tegra_fbdev {struct tegra_drm {struct drm_device *drm; +struct master *master;struct mutex clients_lock;struct list_head clients;
@@ -68,31 +69,25 @@ int tegra_drm_submit(struct tegra_drm_context *context, struct drm_file *file);struct tegra_drm_client { -struct host1x_client base;struct list_head list; +struct device *dev; + +enum host1x_class class; +struct host1x_syncpt **syncpts; +unsigned int num_syncpts;const struct tegra_drm_client_ops *ops; }; -static inline struct tegra_drm_client * -host1x_to_drm_client (struct host1x_client *client) -{ - return container_of(client, struct tegra_drm_client, base); -} -int tegra_drm_register_client (struct tegra_drm *tegra,struct tegra_drm_client *client);int tegra_drm_unregister_client (struct tegra_drm *tegra,struct tegra_drm_client *client); -int tegra_drm_init (struct tegra_drm *tegra,struct drm_device *drm); -int tegra_drm_exit (struct tegra_drm *tegra); -struct tegra_dc_soc_info ;struct tegra_output ;struct tegra_dc { -struct host1x_client client;struct device *dev;spinlock_t lock;
@@ -118,12 +113,6 @@ struct tegra_dc {const struct tegra_dc_soc_info *soc; }; -static inline struct tegra_dc * -host1x_client_to_dc (struct host1x_client *client) -{ - return container_of(client, struct tegra_dc, client); -} -static inline struct tegra_dc *to_tegra_dc (struct drm_crtc *crtc) { return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
@@ -249,10 +238,6 @@ static inline int tegra_output_check_mode(struct tegra_output *output,return output ? -ENOSYS : -EINVAL ; } -/* from bus.c */ -int drm_host1x_init (struct drm_driver *driver,struct host1x_device *device); -void drm_host1x_exit (struct drm_driver *driver,struct host1x_device *device); -/* from rgb.c */ int tegra_dc_rgb_probe (struct tegra_dc *dc);int tegra_dc_rgb_remove (struct tegra_dc *dc);
drivers/gpu/drm/tegra/dsi.c +60 -84
190 lines not on this page · raw message
drivers/gpu/drm/tegra/gr2d.c +35 -43
130 lines not on this page · raw message
drivers/gpu/drm/tegra/gr3d.c +35 -42
129 lines not on this page · raw message
drivers/gpu/drm/tegra/hdmi.c +22 -47
147 lines not on this page · raw message
drivers/gpu/drm/tegra/sor.c +22 -49
155 lines not on this page · raw message
drivers/gpu/host1x/Makefile +0 -1
@@ -1,5 +1,4 @@ host1x-y = \ - bus.o \ syncpt.o \ dev.o \ intr.o \
drivers/gpu/host1x/bus.c deleted +0 -553
553 lines not on this page · raw message
drivers/gpu/host1x/bus.h deleted +0 -29
@@ -1,29 +0,0 @@ -/* -* Copyright (C) 2012 Avionic Design GmbH -* Copyright (C) 2012-2013, NVIDIA Corporation -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef HOST1X_BUS_H -#define HOST1X_BUS_H - -struct host1x ; - -int host1x_bus_init (void ); -void host1x_bus_exit (void ); - -int host1x_register (struct host1x *host1x); -int host1x_unregister (struct host1x *host1x); - -#endif
drivers/gpu/host1x/dev.c +8 -13
@@ -27,7 +27,6 @@#define CREATE_TRACE_POINTS #include <trace/events/host1x.h> -#include "bus.h" #include "dev.h" #include "intr.h" #include "channel.h"
@@ -124,8 +123,8 @@ static int host1x_probe(struct platform_device *pdev)if (!host)return -ENOMEM ; -mutex_init (&host->devices_lock); -INIT_LIST_HEAD (&host->devices); +mutex_init (&host->masters_lock); +INIT_LIST_HEAD (&host->masters);INIT_LIST_HEAD (&host->list); host->dev = &pdev->dev; host->info = id->data;
@@ -176,7 +175,10 @@ static int host1x_probe(struct platform_device *pdev)host1x_debug_init (host); - err =host1x_register (host); + host->interface.name ="nvidia,tegra-host1x" ; + host->interface.dev = &pdev->dev; + + err =interface_add (&host->interface);if (err <0 ) goto fail_deinit_intr;
@@ -195,7 +197,7 @@ static int host1x_remove(struct platform_device *pdev) {struct host1x *host =platform_get_drvdata (pdev); -host1x_unregister (host); +interface_remove (&host->interface);host1x_intr_deinit (host);host1x_syncpt_deinit (host);clk_disable_unprepare (host->clk);
@@ -216,13 +218,9 @@ static int __init tegra_host1x_init(void) {int err; - err =host1x_bus_init (); -if (err <0 ) -return err; - err =platform_driver_register (&tegra_host1x_driver);if (err <0 ) - goto unregister_bus; +return err; err =platform_driver_register (&tegra_mipi_driver);if (err <0 )
@@ -232,8 +230,6 @@ static int __init tegra_host1x_init(void) unregister_host1x:platform_driver_unregister (&tegra_host1x_driver); -unregister_bus: -host1x_bus_exit ();return err; }module_init (tegra_host1x_init);
@@ -242,7 +238,6 @@ static void __exit tegra_host1x_exit(void) {platform_driver_unregister (&tegra_mipi_driver);platform_driver_unregister (&tegra_host1x_driver); -host1x_bus_exit (); }module_exit (tegra_host1x_exit);
drivers/gpu/host1x/dev.h +4 -3
@@ -17,6 +17,7 @@#ifndef HOST1X_DEV_H #define HOST1X_DEV_H +#include <linux/interface.h> #include <linux/platform_device.h> #include <linux/device.h>
@@ -127,9 +128,9 @@ struct host1x {struct dentry *debugfs; -struct mutex devices_lock; -struct list_head devices; - +struct interface interface; +struct mutex masters_lock; +struct list_head masters;struct list_head list; };
include/linux/host1x.h +1 -63
82 lines not on this page · raw message
Signature · 1 line
1.9.2
PATCH v2 6/7 drm: Add device registration documentation
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Describe how devices are registered using the drm_*_init() functions. Adding this to docbook requires a largish set of changes to the comments in drm_{pci,usb,platform}.c since they are doxygen-style rather than proper kernel-doc and therefore mess with the docbook generation.
--- Documentation/DocBook/drm.tmpl | 9 +++++ drivers/gpu/drm/drm_pci.c | 80 ++++++++++++++++++++---------------------- drivers/gpu/drm/drm_platform.c | 15 ++++---- drivers/gpu/drm/drm_stub.c | 19 +++++----- drivers/gpu/drm/drm_usb.c | 20 ++++++++++- 5 files changed, 81 insertions(+), 62 deletions(-)
Documentation/DocBook/drm.tmpl +9 -0
@@ -282,6 +282,15 @@ char *date;</synopsis> </sect3> </sect2> <sect2> + <title>Device Registration</title> + <para> + A number of functions are provided to help with device registration. + The functions deal with PCI, USB and platform devices, respectively. + </para> +!Fdrivers/gpu/drm/drm_pci.c drm_pci_init drm_pci_exit +!Fdrivers/gpu/drm/drm_usb.c drm_usb_init drm_usb_exit +!Fdrivers/gpu/drm/drm_platform.c drm_platform_init + <sect2> <title>Driver Load</title> <para> The <methodname>load</methodname> method is the driver and device
drivers/gpu/drm/drm_pci.c +38 -42
136 lines not on this page · raw message
drivers/gpu/drm/drm_platform.c +7 -8
@@ -106,17 +106,16 @@ static struct drm_bus drm_platform_bus = { };/** -* Platform device initialization. Called direct from modules. +* drm_platform_init - Register a platform device with the DRM subsystem +* @driver: DRM device driver +* @platform_device: platform device to register * -* \return zero on success or a negative number on failure. -* -* Initializes a drm_device structures,registering the -* stubs +* Registers the specified DRM device driver and platform device with the DRM +* subsystem, initializing a drm_device structure and calling the driver's +* .load() function. * -* Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and -* after the initialization for driver customization. +* Return: 0 on success or a negative error code on failure. */ -int drm_platform_init (struct drm_driver *driver,struct platform_device *platform_device) {DRM_DEBUG ("\n" );
drivers/gpu/drm/drm_stub.c +8 -11
@@ -1,16 +1,11 @@ -/** -* \file drm_stub.h -* Stub support -* -* \author Rickard E. (Rik) Faith <[email protected]> -*/ -/* * Created: Fri Jan 19 10:48:35 2001 by [email protected] * * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California. * All Rights Reserved. * +* Author Rickard E. (Rik) Faith <[email protected]> +* * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation
@@ -424,11 +419,12 @@ void drm_minor_release(struct drm_minor *minor) }/** -* Called via drm_exit() at module unload time or when pci device is -* unplugged. +* drm_put_dev - Unregister and release a DRM device +* @dev: DRM device * -* Cleans up all DRM device, calling drm_lastclose(). +* Called at module unload time or when a PCI device is unplugged. * +* Cleans up all DRM device, calling drm_lastclose(). */ void drm_put_dev (struct drm_device *dev) {
@@ -558,7 +554,7 @@ int drm_set_unique(struct drm_device *dev, const char *fmt, ...)EXPORT_SYMBOL (drm_set_unique);/** -* drm_dev_alloc - Allocate new drm device +* drm_dev_alloc - Allocate new DRM device * @driver: DRM driver to allocate device for * @parent: Parent device object *
@@ -712,6 +708,7 @@ EXPORT_SYMBOL(drm_dev_unref);/** * drm_dev_register - Register DRM device * @dev: Device to register +* @flags: Flags passed to the driver's .load() function * * Register the DRM device @dev with the system, advertise device to user-space * and start normal device operation. @dev must be allocated via drm_dev_alloc()
drivers/gpu/drm/drm_usb.c +19 -1
@@ -45,7 +45,17 @@ static int drm_usb_set_busid(struct drm_device *dev,static struct drm_bus drm_usb_bus = { .set_busid = drm_usb_set_busid, }; - + +/** +* drm_usb_init - Register matching USB devices with the DRM subsystem +* @driver: DRM device driver +* @udriver: USB device driver +* +* Registers one or more devices matched by a USB driver with the DRM +* subsystem. +* +* Return: 0 on success or a negative error code on failure. +*/ int drm_usb_init (struct drm_driver *driver,struct usb_driver *udriver) {int res;
@@ -58,6 +68,14 @@ int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver) }EXPORT_SYMBOL (drm_usb_init); +/** +* drm_usb_exit - Unregister matching USB devices from the DRM subsystem +* @driver: DRM device driver +* @udriver: USB device driver +* +* Unregisters one or more devices matched by a USB driver from the DRM +* subsystem. +*/ void drm_usb_exit (struct drm_driver *driver,struct usb_driver *udriver) {
Signature · 6 lines
1.9.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 7/7 drm: Document how to register devices without struct drm_bus
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
With the recent addition of the drm_set_unique() function, devices can now be registered without requiring a drm_bus. Add a brief description to the DRM docbook to show how that can be achieved.
--- Documentation/DocBook/drm.tmpl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
Documentation/DocBook/drm.tmpl +29 -0
@@ -142,6 +142,12 @@ to register it with the DRM subsystem. </para> <para> + Newer drivers that no longer require a <structname>drm_bus</structname> + structure can alternatively use the low-level device initialization and + registration functions such as <function>drm_dev_alloc()</function> and + <function>drm_dev_register()</function> directly. + </para> + <para> The <structname>drm_driver</structname> structure contains static information that describes the driver and features it supports, and pointers to methods that the DRM core will call to implement the DRM API.
@@ -290,6 +296,29 @@ char *date;</synopsis> !Fdrivers/gpu/drm/drm_pci.c drm_pci_init drm_pci_exit !Fdrivers/gpu/drm/drm_usb.c drm_usb_init drm_usb_exit !Fdrivers/gpu/drm/drm_platform.c drm_platform_init + <para> + New drivers that no longer rely on the services provided by the + <structname>drm_bus</structname> structure can call the low-level + device registration functions directly. The + <function>drm_dev_alloc()</function> function can be used to allocate + and initialize a new <structname>drm_device</structname> structure. + Drivers will typically want to perform some additional setup on this + structure, such as allocating driver-specific data and storing a + pointer to it in the DRM device's <structfield>dev_private</structfield> + field. Drivers should also set the device's unique name using the + <function>drm_set_unique()</function> function. After it has been set up + a device can be registered with the DRM subsystem by calling + <function>drm_dev_register()</function>. This will cause the device to + be exposed to userspace and will call the driver's + <structfield>.load()</structfield> implementation. When a device is + removed, the DRM device can safely be unregistered and freed using a + call to <function>drm_put_dev()</function>. + </para> +!Fdrivers/gpu/drm/drm_stub.c drm_dev_alloc +!Fdrivers/gpu/drm/drm_stub.c drm_set_unique +!Fdrivers/gpu/drm/drm_stub.c drm_dev_register +!Fdrivers/gpu/drm/drm_stub.c drm_put_dev + </sect2> <sect2> <title>Driver Load</title> <para>
Signature · 1 line
1.9.2
Re: [PATCH v2 1/7] drm: Introduce drm_set_unique()
In reply to Thierry RedingHi
Some minor nitpicks below:
Quoted 31 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Add a helper function that allows drivers to statically set the unique name of the device. This will allow platform and USB drivers to get rid of their DRM bus implementations and directly use
drm_dev_alloc()anddrm_dev_register().Reviewed-by Daniel Vetter <[email protected]>Signed-off-by Thierry Reding <[email protected]>---
Changes in v2:
- movedrm_set_unique()todrivers/gpu/drm/drm_stub.c
- add kernel-docdrivers/gpu/drm/drm_ioctl.c | 23 +++++++++++++++++------ drivers/gpu/drm/drm_stub.c | 24 ++++++++++++++++++++++++ include/drm/drmP.h | 3 +++ 3 files changed, 44 insertions(+), 6 deletions(-)drivers/gpu/drm/drm_ioctl.c +1
-3@@ -131,13 +131,24 @@ static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)if (master->unique !=NULL )drm_unset_busid (dev, master); - ret = dev->driver->bus->set_busid (dev, master); -if (ret) - goto err; +if (dev->driver->bus && dev->driver->bus->set_busid) {
drivers/gpu/drm/drm_ioctl.c static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv) · line 144
Quoted 10 lines
drivers/gpu/drm/drm_ioctl.c +10
-0+ ret = dev->driver->bus->set_busid (dev, master); +if (ret) { +drm_unset_busid (dev, master); +return ret; + } + }else { +WARN (dev->unique ==NULL , +"No drm_bus.set_busid() implementation provided by %ps. " +"Set the unique name explicitly using drm_set_unique()." , + dev->driver);
return -EINVAL?
If you don't bail out here, the kstrdup() below will cause a kernel-oops. There's no reason to WARN() if you purposely cause an oops below.
Quoted 20 lines
drivers/gpu/drm/drm_ioctl.c +6
-3+ + master->unique =kstrdup (dev->unique,GFP_KERNEL ); +if (master->unique) + master->unique_len =strlen (dev->unique); + } +return 0 ; -err: -drm_unset_busid (dev, master); -return ret; }/** drivers/gpu/drm/drm_stub.c +0
-0@@ -535,6 +535,29 @@ static void drm_fs_inode_free(struct inode *inode) }
drivers/gpu/drm/drm_stub.c static void drm_fs_inode_free(struct inode *inode) · line 546
Quoted 10 lines
drivers/gpu/drm/drm_stub.c +9
-0/** +* drm_set_unique - Set the unique name of a DRM device +* @dev: device of which to set the unique name +* @fmt: format string for unique name +* +* Sets the unique name of a DRM device using the specified format string and +* a variable list of arguments. Drivers can use this at driver probe time if +* the unique name of the devices they drive is static. +*/ +int drm_set_unique (struct drm_device *dev,const char *fmt, ...)
I tried renaming all the device-management APIs to "drm_dev_*", so how about moving this below drm_dev_unregister() and renaming it to drm_dev_set_unique()? I prefer prefixes which describe the object the function works on. set_unique() works on drm_device, so lets use the known drm_dev_* prefix.
Just my opinion, others might disagree..
Quoted 30 lines
drivers/gpu/drm/drm_stub.c +15
-0+{ +va_list ap; + +kfree (dev->unique); + +va_start (ap, fmt); + dev->unique =kvasprintf (GFP_KERNEL , fmt, ap); +va_end (ap); + +return dev->unique ?0 : -ENOMEM ; +} +EXPORT_SYMBOL (drm_set_unique); + +/** * drm_dev_alloc - Allocate new drm device * @driver: DRM driver to allocate device for * @parent: Parent device object @@ -649,6 +672,7 @@ static void drm_dev_release(struct kref *ref)drm_minor_free (dev,DRM_MINOR_CONTROL );mutex_destroy (&dev->master_mutex); +kfree (dev->unique);kfree (dev); }include/drm/drmP.h +0
-0
include/drm/drmP.h struct drm_device { · line 1239
Quoted 5 lines
include/drm/drmP.h +2
-0@@ -1235,6 +1235,8 @@ struct drm_device {struct drm_vma_offset_manager *vma_offset_manager;/*@} */ int switch_power_state; + +char *unique;
Can you add this to the group at the top of the object? This somehow belongs to
/** \name Lifetime Management */
as it is part of device initialization and API.
include/drm/drmP.h static __inline__ void drm_core_dropmap(struct drm_local_map *map) · line 1685
Quoted 8 lines
include/drm/drmP.h +1
-0};#define DRM_SWITCH_POWER_ON 0@@ -1680,6 +1682,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)#include <drm/drm_mem_util.h> +int drm_set_unique (struct drm_device *dev,const char *fmt, ...);
Again just a minor style-nitpick: Move that below the drm_dev_*() declarations, not above. Usual kernel-style is to have allocators/lifetime-management first, followed by runtime management.
Otherwise looks good:
Thanks
David
Quoted 6 lines
include/drm/drmP.h +0
-1struct drm_device *drm_dev_alloc (struct drm_driver *driver,struct device *parent);void drm_dev_ref (struct drm_device *dev); --1.9.2
Re: [PATCH v2 7/7] drm: Document how to register devices without struct drm_bus
In reply to Thierry RedingHi
Quoted 38 lines · Thierry Reding
From: Thierry Reding <[email protected]>
With the recent addition of the
drm_set_unique()function, devices can now be registered without requiring adrm_bus. Add a brief description to the DRM docbook to show how that can be achieved.Signed-off-by Thierry Reding <[email protected]>--- Documentation/DocBook/drm.tmpl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)Documentation/DocBook/drm.tmpl +12
-0@@ -142,6 +142,12 @@ to register it with the DRM subsystem. </para> <para> + Newer drivers that no longer require a <structname>drm_bus</structname> + structure can alternatively use the low-level device initialization and + registration functions such as <function>drm_dev_alloc()</function> and + <function>drm_dev_register()</function> directly. + </para> + <para> The <structname>drm_driver</structname> structure contains static information that describes the driver and features it supports, and pointers to methods that the DRM core will call to implement the DRM API.@@ -290,6 +296,29 @@ char *date;</synopsis> !Fdrivers/gpu/drm/drm_pci.c drm_pci_init drm_pci_exit !Fdrivers/gpu/drm/drm_usb.c drm_usb_init drm_usb_exit !Fdrivers/gpu/drm/drm_platform.c drm_platform_init + <para> + New drivers that no longer rely on the services provided by the + <structname>drm_bus</structname> structure can call the low-level + device registration functions directly. The + <function>drm_dev_alloc()</function> function can be used to allocate + and initialize a new <structname>drm_device</structname> structure.
Documentation/DocBook/drm.tmpl char *date;</synopsis> · line 314
Quoted 10 lines
Documentation/DocBook/drm.tmpl +10
-0+ Drivers will typically want to perform some additional setup on this + structure, such as allocating driver-specific data and storing a + pointer to it in the DRM device's <structfield>dev_private</structfield> + field. Drivers should also set the device's unique name using the + <function>drm_set_unique()</function> function. After it has been set up + a device can be registered with the DRM subsystem by calling + <function>drm_dev_register()</function>. This will cause the device to + be exposed to userspace and will call the driver's + <structfield>.load()</structfield> implementation. When a device is + removed, the DRM device can safely be unregistered and freed using a
That's not true. drm_put_dev() is anything but safe.. but that's an implementation bug and I'm working on it. Not that easy, though. Furthermore, please use drm_dev_unregister() and drm_dev_unref() directly. No reason to use drm_put_dev() in new drivers. Once I fixed the runtime issues, a call to drm_dev_unregister() will _immediately_ remove a device and detach all active user-space connections.
Documentation/DocBook/drm.tmpl char *date;</synopsis> · line 317
Quoted 3 lines
Documentation/DocBook/drm.tmpl +3
-0+ call to <function>drm_put_dev()</function>. + </para> +!Fdrivers/gpu/drm/drm_stub.c drm_dev_alloc
Please change this to:
+!Fdrivers/gpu/drm/drm_stub.c drm_dev_alloc
+!Fdrivers/gpu/drm/drm_stub.c drm_dev_ref
+!Fdrivers/gpu/drm/drm_stub.c drm_dev_unref
+!Fdrivers/gpu/drm/drm_stub.c drm_dev_register
+!Fdrivers/gpu/drm/drm_stub.c drm_dev_unregister
+!Fdrivers/gpu/drm/drm_stub.c drm_dev_set_unique
All these helpers are needed and exported to drivers.
Otherwise, looks all good! Thanks!
David
Quoted 7 lines
Documentation/DocBook/drm.tmpl +1
-1+ </sect2> <sect2> <title>Driver Load</title> <para> --1.9.2
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Thierry RedingQuoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.
Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.h
Hm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
-Daniel
Quoted 255 lines
drivers/base/Makefile +1
-1@@ -4,7 +4,7 @@ obj-y := component.o core.o bus.o dd.o syscore.o \ driver.o class.o platform.o \ cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o \ - topology.o container.o + topology.o container.o interface.o obj-$(CONFIG_DEVTMPFS) += devtmpfs.o obj-$(CONFIG_DMA_CMA) += dma-contiguous.o obj-y += power/drivers/base/interface.c new file +186
-0@@ -0,0 +1,186 @@ +/* +* Copyright (C) 2014 NVIDIA Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#define pr_fmt (fmt) "interface: " fmt + +#include <linux/device.h> +#include <linux/interface.h> +#include <linux/mutex.h> +#include <linux/slab.h> + +static DEFINE_MUTEX (interfaces_lock); +static LIST_HEAD (interfaces); +static LIST_HEAD (drivers); + +struct interface_attachment { +struct interface_driver *driver; +struct list_head list; +}; + +static bool interface_match (struct interface *intf, +struct interface_driver *driver) +{ +return strcmp (intf->name, driver->name) ==0 ; +} + +static bool interface_attached (struct interface *intf, +struct interface_driver *driver) +{ +struct interface_attachment *attach; + +list_for_each_entry (attach, &intf->drivers, list) +if (attach->driver == driver) +return true; + +return false; +} + +static int interface_attach (struct interface *intf, +struct interface_driver *driver) +{ +struct interface_attachment *attach; + + attach =kzalloc (sizeof (*attach),GFP_KERNEL ); +if (!attach) +return -ENOMEM ; + +INIT_LIST_HEAD (&attach->list); + attach->driver = driver; + +list_add_tail (&attach->list, &intf->drivers); + +return 0 ; +} + +static void interface_detach (struct interface *intf, +struct interface_driver *driver) +{ +struct interface_attachment *attach; + +list_for_each_entry (attach, &intf->drivers, list) { +if (attach->driver == driver) { +list_del (&attach->list); +kfree (attach); +return ; + } + } +} + +static void interface_bind (struct interface *intf, +struct interface_driver *driver) +{ +int err; + +if (interface_attached (intf, driver)) +return ; + +if (!interface_match (intf, driver)) +return ; + + err =interface_attach (intf, driver); +if (err <0 ) { +pr_err ("failed to attach driver %ps to interface %s: %d\n" , + driver, intf->name, err); +return ; + } + + err = driver->bind (intf); +if (err <0 ) { +pr_err ("failed to bind driver %ps to interface %s: %d\n" , + driver, intf->name, err); +interface_detach (intf, driver); +return ; + } + +pr_debug ("driver %ps bound to interface %s\n" , driver, intf->name); +} + +static void interface_unbind (struct interface *intf, +struct interface_driver *driver) +{ +if (!interface_attached (intf, driver)) +return ; + +interface_detach (intf, driver); + driver->unbind (intf); + +pr_debug ("driver %ps unbound from interface %s\n" , driver, intf->name); +} + +int interface_add (struct interface *intf) +{ +struct interface_driver *driver; + +INIT_LIST_HEAD (&intf->drivers); +INIT_LIST_HEAD (&intf->list); + +mutex_lock (&interfaces_lock); + +list_add_tail (&intf->list, &interfaces); + +pr_debug ("interface %s added for device %s\n" , intf->name, +dev_name (intf->dev)); + +list_for_each_entry (driver, &drivers, list) +interface_bind (intf, driver); + +mutex_unlock (&interfaces_lock); + +return 0 ; +} + +void interface_remove (struct interface *intf) +{ +struct interface_driver *driver; + +mutex_lock (&interfaces_lock); + +list_for_each_entry (driver, &drivers, list) +interface_unbind (intf, driver); + +list_del_init (&intf->list); + +pr_debug ("interface %s removed for device %s\n" , intf->name, +dev_name (intf->dev)); + +mutex_unlock (&interfaces_lock); +} + +int interface_register_driver (struct interface_driver *driver) +{ +struct interface *intf; + +mutex_lock (&interfaces_lock); + +list_add_tail (&driver->list, &drivers); + +pr_debug ("driver %ps added\n" , driver); + +list_for_each_entry (intf, &interfaces, list) +interface_bind (intf, driver); + +mutex_unlock (&interfaces_lock); + +return 0 ; +} + +void interface_unregister_driver (struct interface_driver *driver) +{ +struct interface *intf; + +mutex_lock (&interfaces_lock); + +list_for_each_entry (intf, &interfaces, list) +interface_unbind (intf, driver); + +list_del_init (&driver->list); + +pr_debug ("driver %ps removed\n" , driver); + +mutex_unlock (&interfaces_lock); +}include/linux/interface.h new file +40
-0@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2014 NVIDIA Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef INTERFACE_H +#define INTERFACE_H + +#include <linux/list.h> + +struct device ; +struct interface ; + +struct interface_driver { +const char *name; + +int (*bind)(struct interface *intf); +void (*unbind)(struct interface *intf); + +struct list_head list; +}; + +int interface_register_driver (struct interface_driver *driver); +void interface_unregister_driver (struct interface_driver *driver); + +struct interface { +const char *name; +struct device *dev; + +struct list_head drivers; +struct list_head list; +}; + +int interface_add (struct interface *intf); +void interface_remove (struct interface *intf); + +#endif Signature · 1 line
1.9.2
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH v2 6/7] drm: Add device registration documentation
In reply to Thierry RedingQuoted 22 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Describe how devices are registered using the drm_*_init() functions. Adding this to docbook requires a largish set of changes to the comments in drm_{pci,usb,platform}.c since they are doxygen-style rather than proper kernel-doc and therefore mess with the docbook generation.
Signed-off-by Thierry Reding <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 +++++ drivers/gpu/drm/drm_pci.c | 80 ++++++++++++++++++++---------------------- drivers/gpu/drm/drm_platform.c | 15 ++++---- drivers/gpu/drm/drm_stub.c | 19 +++++----- drivers/gpu/drm/drm_usb.c | 20 ++++++++++- 5 files changed, 81 insertions(+), 62 deletions(-)Documentation/DocBook/drm.tmpl +0
-0@@ -282,6 +282,15 @@ char *date;</synopsis> </sect3>
Documentation/DocBook/drm.tmpl char *date;</synopsis> · line 292
Quoted 10 lines
Documentation/DocBook/drm.tmpl +8
-0</sect2> <sect2> + <title>Device Registration</title> + <para> + A number of functions are provided to help with device registration. + The functions deal with PCI, USB and platform devices, respectively. + </para> +!Fdrivers/gpu/drm/drm_pci.c drm_pci_init drm_pci_exit +!Fdrivers/gpu/drm/drm_usb.c drm_usb_init drm_usb_exit +!Fdrivers/gpu/drm/drm_platform.c drm_platform_init
Generally I prefer to use !E to pull in all exported functions - those are the ones driver authors care about. And using this has the upside that if anyone renames them or adds/removes some it will be kept in sync automatically. Same for the next patch.
-Daniel
Quoted 278 lines
Documentation/DocBook/drm.tmpl +1
-0+ <sect2> <title>Driver Load</title> <para> The <methodname>load</methodname> method is the driver and devicedrivers/gpu/drm/drm_pci.c +38
-42@@ -1,17 +1,3 @@ -/* drm_pci.h -- PCI DMA memory management wrappers for DRM -*- linux-c -*- */ -/** -* \file drm_pci.c -* \brief Functions and ioctls to manage PCI memory -* -* \warning These interfaces aren't stable yet. -* -* \todo Implement the remaining ioctl's for the PCI pools. -* \todo The wrappers here are so thin that they would be better off inlined.. -* -* \author José Fonseca <[email protected]> -* \author Leif Delgass <[email protected]> -*/ -/* * Copyright 2003 José Fonseca. * Copyright 2003 Leif Delgass. @@ -42,12 +28,14 @@#include <linux/export.h> #include <drm/drmP.h> -/**********************************************************************/ -/** \name PCI memory */ -/*@{*/ -/** -* \brief Allocate a PCI consistent memory block, for DMA. +* drm_pci_alloc - Allocate a PCI consistent memory block, for DMA. +* @dev: DRM device +* @size: size of block to allocate +* @align: alignment of block +* +* Return: A handle to the allocated memory block on success or NULL on +* failure. */ drm_dma_handle_t *drm_pci_alloc (struct drm_device * dev,size_t size,size_t align) {@@ -88,8 +76,8 @@ drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t aliEXPORT_SYMBOL (drm_pci_alloc); -/** -* \brief Free a PCI consistent memory block without freeing its descriptor. +/* +* Free a PCI consistent memory block without freeing its descriptor. * * This function is for internal use in the Linux-specific DRM core code. */ @@ -111,7 +99,9 @@ void __drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah) }/** -* \brief Free a PCI consistent memory block +* drm_pci_free - Free a PCI consistent memory block +* @dev: DRM device +* @dmah: handle to memory block */ void drm_pci_free (struct drm_device * dev,drm_dma_handle_t * dmah) {@@ -226,17 +216,16 @@ static int drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *p) }/** -* Get interrupt from bus id. -* -* \param inode device inode. -* \param file_priv DRM file private. -* \param cmd command. -* \param arg user argument, pointing to a drm_irq_busid structure. -* \return zero on success or a negative number on failure. +* drm_irq_by_busid - Get interrupt from bus ID +* @dev: DRM device +* @data: IOCTL parameter pointing to a drm_irq_busid structure +* @file_priv: DRM file private. * * Finds the PCI device with the specified bus id and gets its IRQ number. * This IOCTL is deprecated, and will now return EINVAL for any busid not equal * to that of the device that this DRM instance attached to. +* +* Return: 0 on success or a negative error code on failure. */ int drm_irq_by_busid (struct drm_device *dev,void *data,struct drm_file *file_priv)@@ -285,15 +274,16 @@ static struct drm_bus drm_pci_bus = { };/** -* Register. -* -* \param pdev - PCI device structure -* \param ent entry from the PCI ID table with device type flags -* \return zero on success or a negative number on failure. +* drm_get_pci_dev - Register a PCI device with the DRM subsystem +* @pdev: PCI device +* @ent: entry from the PCI ID table that matches @pdev +* @driver: DRM device driver * * Attempt to gets inter module "drm" information. If we are first * then register the character device and inter module information. * Try and register, if we fail to register, backout previous work. +* +* Return: 0 on success or a negative error code on failure. */ int drm_get_pci_dev (struct pci_dev *pdev,const struct pci_device_id *ent,struct drm_driver *driver)@@ -346,15 +336,14 @@ err_free:EXPORT_SYMBOL (drm_get_pci_dev);/** -* PCI device initialization. Called direct from modules at load time. +* drm_pci_init - Register matching PCI devices with the DRM subsystem +* @driver: DRM device driver +* @pdriver: PCI device driver * -* \return zero on success or a negative number on failure. +* Initializes a drm_device structures, registering the stubs and initializing +* the AGP device. * -* Initializes a drm_device structures,registering the -* stubs and initializing the AGP device. -* -* Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and -* after the initialization for driver customization. +* Return: 0 on success or a negative error code on failure. */ int drm_pci_init (struct drm_driver *driver,struct pci_driver *pdriver) {@@ -458,7 +447,14 @@ int drm_pci_set_unique(struct drm_device *dev,EXPORT_SYMBOL (drm_pci_init); -/*@}*/ +/** +* drm_pci_exit - Unregister matching PCI devices from the DRM subsystem +* @driver: DRM device driver +* @pdriver: PCI device driver +* +* Unregisters one or more devices matched by a PCI driver from the DRM +* subsystem. +*/ void drm_pci_exit (struct drm_driver *driver,struct pci_driver *pdriver) {struct drm_device *dev, *tmp;drivers/gpu/drm/drm_platform.c +7
-8@@ -106,17 +106,16 @@ static struct drm_bus drm_platform_bus = { };/** -* Platform device initialization. Called direct from modules. +* drm_platform_init - Register a platform device with the DRM subsystem +* @driver: DRM device driver +* @platform_device: platform device to register * -* \return zero on success or a negative number on failure. -* -* Initializes a drm_device structures,registering the -* stubs +* Registers the specified DRM device driver and platform device with the DRM +* subsystem, initializing a drm_device structure and calling the driver's +* .load() function. * -* Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and -* after the initialization for driver customization. +* Return: 0 on success or a negative error code on failure. */ -int drm_platform_init (struct drm_driver *driver,struct platform_device *platform_device) {DRM_DEBUG ("\n" );drivers/gpu/drm/drm_stub.c +8
-11@@ -1,16 +1,11 @@ -/** -* \file drm_stub.h -* Stub support -* -* \author Rickard E. (Rik) Faith <[email protected]> -*/ -/* * Created: Fri Jan 19 10:48:35 2001 by [email protected] * * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California. * All Rights Reserved. * +* Author Rickard E. (Rik) Faith <[email protected]> +* * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -424,11 +419,12 @@ void drm_minor_release(struct drm_minor *minor) }/** -* Called via drm_exit() at module unload time or when pci device is -* unplugged. +* drm_put_dev - Unregister and release a DRM device +* @dev: DRM device * -* Cleans up all DRM device, calling drm_lastclose(). +* Called at module unload time or when a PCI device is unplugged. * +* Cleans up all DRM device, calling drm_lastclose(). */ void drm_put_dev (struct drm_device *dev) {@@ -558,7 +554,7 @@ int drm_set_unique(struct drm_device *dev, const char *fmt, ...)EXPORT_SYMBOL (drm_set_unique);/** -* drm_dev_alloc - Allocate new drm device +* drm_dev_alloc - Allocate new DRM device * @driver: DRM driver to allocate device for * @parent: Parent device object * @@ -712,6 +708,7 @@ EXPORT_SYMBOL(drm_dev_unref);/** * drm_dev_register - Register DRM device * @dev: Device to register +* @flags: Flags passed to the driver's .load() function * * Register the DRM device @dev with the system, advertise device to user-space * and start normal device operation. @dev must be allocated via drm_dev_alloc() drivers/gpu/drm/drm_usb.c +19
-1@@ -45,7 +45,17 @@ static int drm_usb_set_busid(struct drm_device *dev,static struct drm_bus drm_usb_bus = { .set_busid = drm_usb_set_busid, }; - + +/** +* drm_usb_init - Register matching USB devices with the DRM subsystem +* @driver: DRM device driver +* @udriver: USB device driver +* +* Registers one or more devices matched by a USB driver with the DRM +* subsystem. +* +* Return: 0 on success or a negative error code on failure. +*/ int drm_usb_init (struct drm_driver *driver,struct usb_driver *udriver) {int res;@@ -58,6 +68,14 @@ int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver) }EXPORT_SYMBOL (drm_usb_init); +/** +* drm_usb_exit - Unregister matching USB devices from the DRM subsystem +* @driver: DRM device driver +* @udriver: USB device driver +* +* Unregisters one or more devices matched by a USB driver from the DRM +* subsystem. +*/ void drm_usb_exit (struct drm_driver *driver,struct usb_driver *udriver) {Signature · 1 line
1.9.2
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Daniel VetterQuoted 84 lines · Daniel Vetter
Quoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.h
Quoted 5 lines
Hm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
The problem that this is trying to solve is slightly different. The host1x children do already sit on a kind of bus, only that there's currently (and likely never) a real need to turn it into a custom bus implementation, so we reuse platform_bus instead (host1x is the parent of the child devices).
What this interface framework tries to solve is that host1x itself is a device with a proper driver. Child devices in turn are implemented as separate drivers as well. The result is that there is no device that can be used to register the DRM driver against. DRM doesn't specifically require this since it doesn't take ownership of a device, but with the driver model every driver needs a device to bind against, otherwise no .probe() function is called.
Two solutions have previously been proposed, and Tegra DRM has used each of them at one point, but it never really seemed like the right solution. Also at each point I was told to look into fixing it.
The first solution is to have everything in one driver. That way the DRM device could be instantiated from the host1x driver. Similarily a future V4L2 driver could be instantiated from the same host1x driver. That has the obvious disadvantage that the driver becomes really big and monolithic.
A different solution, which seems to be fairly common for DRM drivers for SoCs, is to instantiate a dummy device so that the DRM driver can bind to it. This can happen in two forms: add the dummy device directly in device tree (which goes against pretty much everything that's been preached about device tree in the past) or the dummy device can be instantiated in code, which is what the current Tegra DRM/host1x driver does.
The interface framework solution is a way to combine both of the above, while dropping the ugly parts at the same time. What it tries to achieve is to allow a specific device (the host1x parent device in this case) to expose an interface (which is essentially just a name of a set of functions that the device implements). For host1x this interface would be "tegra-host1x". An interface can be bound to by more than one driver, which is probably the most fundamental difference between an interface and a device (as in the driver model).
So for host1x, there could be two drivers that bind to the tegra-host1x
interface: DRM and V4L2 (there could potentially be others). None of the drivers would need to take ownership of a device, since they are meta- drivers that would typically use the component/master framework. The only reason why it's needed is so that the drivers get an entry point so that they can register the master of a componentized device.
I guess that reduces the number of use-cases compared to what you had in mind, so perhaps moving this from the driver core into host1x would be a better option. Still perhaps it's useful for other scenarios that I just haven't thought about and having it in the core would make it easier to find.
Thierry
Greg Kroah-Hartman
maintainerRe: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Daniel VetterQuoted 84 lines · Daniel Vetter
Quoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.h
Quoted 5 lines
Hm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
I have no problem adding such "bus-light" functions, to make it easier to create and implement a bus in the driver core, as I know it's really heavy. That's been on my "todo" list for over a decade now...
thanks,
greg k-h
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Thierry RedingQuoted 7 lines · Thierry Reding
A different solution, which seems to be fairly common for DRM drivers for SoCs, is to instantiate a dummy device so that the DRM driver can bind to it. This can happen in two forms: add the dummy device directly in device tree (which goes against pretty much everything that's been preached about device tree in the past) or the dummy device can be instantiated in code, which is what the current Tegra DRM/host1x driver does.
Actually the dummy device seems to be an acceptable solution and iirc was even acked by DT maintainers in the last KS. I'm not on top of things, but iirc the thinking was that a dummy device which just pulls in all the relevant real bits with phandles is justified in the board file since it tells you how the board is intended to be used. The justification was that on SoCs where assigning stuff between v4l and drm is really flexible (e.g. on omap or so where you can assign the display pipes essentially freely) the use-case of the board is what matters, and that's a somewhat physical property of it (i.e. in what kind of device it's sitting.)
So in your case you'd have a fake display and a fake video device which pulls everything the drm/v4l driver need together. So if the issue is how to get at a master device I think that's simple to solve.
If the issue otoh is how the various drivers can get at the bus-like services host1x exposes, then I think a real bus driver makes a lot more sense. And Greg seems to have ideas about that already. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Greg Kroah-HartmanQuoted 91 lines · Greg Kroah-Hartman
Quoted 84 lines · Daniel Vetter
Quoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.hQuoted 5 lines
Hm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
Quoted 3 lines
I have no problem adding such "bus-light" functions, to make it easier to create and implement a bus in the driver core, as I know it's really heavy. That's been on my "todo" list for over a decade now...
Hm, I've victimized^Wvolunteered a few internal people to look into a hdmi/dp sink bus type of thing so that we can move away from all those ad-hoc hacks currently used to coordinate between drm display drivers and the audio side of things. So I'm interested.
Do you have some ideas somewhere already about how you think this should look like? Or is this more a "hey, this would be really cool, eventually" kind of thing?
Thanks, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Daniel VetterQuoted 9 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding
A different solution, which seems to be fairly common for DRM drivers for SoCs, is to instantiate a dummy device so that the DRM driver can bind to it. This can happen in two forms: add the dummy device directly in device tree (which goes against pretty much everything that's been preached about device tree in the past) or the dummy device can be instantiated in code, which is what the current Tegra DRM/host1x driver does.
Quoted 9 lines
Actually the dummy device seems to be an acceptable solution and iirc was even acked by DT maintainers in the last KS. I'm not on top of things, but iirc the thinking was that a dummy device which just pulls in all the relevant real bits with phandles is justified in the board file since it tells you how the board is intended to be used. The justification was that on SoCs where assigning stuff between v4l and drm is really flexible (e.g. on omap or so where you can assign the display pipes essentially freely) the use-case of the board is what matters, and that's a somewhat physical property of it (i.e. in what kind of device it's sitting.)
I disagree. If there's a way to derive all that information within the driver (like we do for Tegra) then there should be no need to add redundant content to the device tree. Also note that Tegra DRM and its device tree binding predate the last KS, and prior to that the gospel was to *not* add this kind of data to the device tree. Hence I was forced to spend a *lot* of time working out a solution in the driver. Therefore I hope it's understandable that I don't take well to being told to just go use a bloody dummy device.
Quoted 3 lines
So in your case you'd have a fake display and a fake video device which pulls everything the drm/v4l driver need together. So if the issue is how to get at a master device I think that's simple to solve.
But that's completely redundant. The driver is perfectly capable of determining what devices belong to a DRM device and which should be part of a V4L2 device.
Fake devices are only workarounds for a problem that we currently have no better solution for in the kernel. And as a matter of fact we already do create a dummy device (albeit in the kernel rather than in device tree) on Tegra. But I consider that suboptimal, hence why I want to find a better way to do this. This interface framework is the result.
If people don't see a need to fix this then I'll just stick with what I currently have, since it isn't any worse than what everybody else is doing.
Quoted 3 lines
If the issue otoh is how the various drivers can get at the bus-like services host1x exposes, then I think a real bus driver makes a lot more sense. And Greg seems to have ideas about that already.
There aren't really any bus-like services exposed by host1x. It really just exposes resources such as DMA channels or syncpoints. But that's not even a problem because we know that host1x children are always, well, children of host1x and therefore we can simply get access to host1x via the parent device.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Greg Kroah-Hartman
maintainerRe: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Daniel VetterQuoted 96 lines · Daniel Vetter
Quoted 91 lines · Greg Kroah-Hartman
Quoted 84 lines · Daniel Vetter
Quoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.hQuoted 5 lines
Hm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
Quoted 3 lines
I have no problem adding such "bus-light" functions, to make it easier to create and implement a bus in the driver core, as I know it's really heavy. That's been on my "todo" list for over a decade now...
Quoted 8 lines
Hm, I've victimized^Wvolunteered a few internal people to look into a hdmi/dp sink bus type of thing so that we can move away from all those ad-hoc hacks currently used to coordinate between drm display drivers and the audio side of things. So I'm interested.
Do you have some ideas somewhere already about how you think this should look like? Or is this more a "hey, this would be really cool, eventually" kind of thing?
It was very much a "hey, this would be really cool" type of thing, nothing specific at all, sorry.
greg k-h
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Greg Kroah-HartmanQuoted 91 lines · Greg Kroah-Hartman
Quoted 84 lines · Daniel Vetter
Quoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.hQuoted 5 lines
Hm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
Quoted 3 lines
I have no problem adding such "bus-light" functions, to make it easier to create and implement a bus in the driver core, as I know it's really heavy. That's been on my "todo" list for over a decade now...
Greg,
Do you think you could find the time to look at this patch in a little more detail? This isn't about creating a light alternative to busses at all. It is an attempt to solve a different problem.
Consider the following: you have a collection of hardware devices that together can implement functionality in a given subsystem such as DRM or V4L2. In many cases all these devices have their own driver and they are glued together using the component helpers. This results in a situation where people are instantiating dummy devices for the sole purpose of getting a driver probed, since all of the existing devices have already had a driver bind to them.
Another downside of using dummy devices is that they mess up the device hierarchy. All of a sudden you have a situation where the dummy device is the logical parent for its aunts and uncles (or siblings).
The solution proposed here is to allow any device to expose an interface that interface drivers can bind to. This removes the need for dummy devices. As opposed to device drivers, an interface can be bound to by multiple drivers. That's a feature that is needed specifically by host1x on Tegra since two drivers need to hang off of the host1x device (DRM and V4L2), but I can easily imagine this to be useful in other cases. Interfaces are exposed explicitly at probe time by the device drivers for the devices they drive.
Even though this was designed with the above use-case in mind I can imagine this to be useful for other things as well. For example a set of generic interfaces could be created and devices (or even whole classes of devices) could be made to expose these interfaces. This would cause interfaces to be created for each of these devices. That's functionality similar to what can be done with notifiers, albeit somewhat more structured. That could for example be useful to apply policy to a class of devices or collect statistics, etc.
If you think that I'm on a wild-goose chase, please let me know so that I don't waste any more time on this.
Thierry
2014-05-13 17:30 GMT+02:00 Thierry Reding <[email protected]>:
Quoted 8 lines
From: Thierry Reding <[email protected]>
Instead of the current implementation, reuse the recently introduced master/component framework, which is equivalent in most regards. One issue is that there is no device to bind the DRM driver to. In order to still allow the driver to be probed, expose an interface from the host1x device and provide an interface driver to bind to that.
Quoted 8 lines
The interface driver then registers (or removes) the master that will be used to instantiate and bind the DRM driver. Since the
drm_host1xbus implementation is now gone the dummy device instantiated by it can no longer be used as the parent for the DRM device. However since the parent device doesn't need to be modified, the host1x parent device that exposes the interface can be used instead.Signed-off-by Thierry Reding <[email protected]>
Is there a git tree somewhere to have a look at? I am interested in the usage of the master/component framework.
thanks
--
Christian Gmeiner, MSc
Quoted 16 lines · Christian Gmeiner
2014-05-13 17:30 GMT+02:00 Thierry Reding <[email protected]>:
Quoted 15 lines
From: Thierry Reding <[email protected]>
Instead of the current implementation, reuse the recently introduced master/component framework, which is equivalent in most regards. One issue is that there is no device to bind the DRM driver to. In order to still allow the driver to be probed, expose an interface from the host1x device and provide an interface driver to bind to that.
The interface driver then registers (or removes) the master that will be used to instantiate and bind the DRM driver. Since the
drm_host1xbus implementation is now gone the dummy device instantiated by it can no longer be used as the parent for the DRM device. However since the parent device doesn't need to be modified, the host1x parent device that exposes the interface can be used instead.
Quoted 4 lines
Quoted 1 line
Signed-off-by Thierry Reding <[email protected]>Is there a git tree somewhere to have a look at? I am interested in the usage of the master/component framework.
I've pushed my latest working branches to gitorious[0]. staging/work is the branch that has everything.
Thierry
[0]: https://gitorious.org/thierryreding/linux
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 4/7] drivers/base: Add interface framework
In reply to Thierry RedingHi Thierry, Greg,
Quoted 92 lines · Thierry Reding
Quoted 91 lines · Greg Kroah-Hartman
Quoted 89 lines · Daniel Vetter
Quoted 74 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Some drivers, such as graphics drivers in the DRM subsystem, do not have a real device that they can bind to. They are often composed of several devices, each having their own driver. The master/component framework can be used in these situations to collect the devices pertaining to one logical device, wait until all of them have registered and then bind them all at once.
For some situations this is only a partial solution. An implementation of a master still needs to be registered with the system somehow. Many drivers currently resort to creating a dummy device that a driver can bind to and register the master against. This is problematic since it requires (and presumes) knowledge about the system within drivers.
Furthermore there are setups where a suitable device already exists, but is already bound to a driver. For example, on Tegra the following device tree extract (simplified) represents the host1x device along with child devices:
host1x { display-controller { ... }; display-controller { ... }; hdmi { ... }; dsi { ... }; csi { ... }; video-input { ... }; };Each of the child devices is in turn a client of host1x, in that it can request resources (command stream DMA channels and syncpoints) from it. To implement the DMA channel and syncpoint infrastructure, host1x comes with its own driver. Children are implemented in separate drivers. In Linux this set of devices would be exposed by DRM and V4L2 drivers.
However, neither the DRM nor the V4L2 drivers have a single device that they can bind to. The DRM device is composed of the display controllers and the various output devices, whereas the V4L2 device is composed of one or more video input devices.
This patch introduces the concept of an interface and drivers that can bind to a given interface. An interface can be exposed by any device, and interface drivers can bind to these interfaces. Multiple drivers can bind against a single interface. When a device is removed, interfaces exposed by it will be removed as well, thereby removing the drivers that were bound to those interfaces.
In the example above, the host1x device would expose the "tegra-host1x" interface. DRM and V4L2 drivers can then bind to that interface and instantiate the respective subsystem objects from there.
Signed-off-by Thierry Reding <[email protected]>---
Note that I'd like to merge this through the Tegra DRM tree so that the changes to the Tegra DRM driver later in this series can be merged at the same time and are not delayed for another release cycle.Quoted 8 lines
In particular that means that I'm looking for an Acked-by from Greg.
drivers/base/Makefile | 2 +- drivers/base/interface.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/interface.h | 40 ++++++++++ 3 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/base/interface.c create mode 100644 include/linux/interface.hHm, this interface stuff smells like bus drivers light. Should we instead have a pile of helpers to make creating new buses with match methods more trivial? There's a fairly big pile of small use-cases where this might be useful. In your case here all the host1x children would sit on a host1x bus. Admittedly I didn't look into the details.
Quoted 3 lines
Quoted 3 lines
I have no problem adding such "bus-light" functions, to make it easier to create and implement a bus in the driver core, as I know it's really heavy. That's been on my "todo" list for over a decade now...
I have posted some times ago RFC for interface_tracker framework [1]. It seems with interface_tracker you can achieve similar functionality and it seems to be more generic.
[1]: https://lkml.org/lkml/2014/4/30/345
Two small things should be added to interface_tracker framework:
- matching objects using string comparison,
- before notifier unregistration call notifier to inform that observed interface will disappear for him.
Greg, this is another use case for interface_tracker framework.
To show how it could be achieved I present pseudo patch which converts tegra drivers to interface_tracker. Obviously I have not tested it.
drivers/gpu/drm/tegra/drm.c +0 -0
@@ -728,27 +728,27 @@ static const struct component_master_ops
tegra_drm_master_ops = {
.unbind = tegra_drm_unbind,
};
-static int host1x_interface_bind(struct interface *intf)
-{
- return component_master_add(intf->dev, &tegra_drm_master_ops);
-}
-
-static void host1x_interface_unbind(struct interface *intf)
-{
- component_master_del(intf->dev, &tegra_drm_master_ops);
-}
-
-static struct interface_driver host1x_interface_driver = {
- .name = "nvidia,tegra-host1x",
- .bind = host1x_interface_bind,
- .unbind = host1x_interface_unbind,
-};
+void itb_callback(struct interface_tracker_block *itb, const void *object,
+ unsigned long type, bool on, void *data)
+{
+ struct device *dev = data;
+
+ if (on)
+ component_master_add(dev, &tegra_drm_master_ops);
+ else
+ component_master_del(dev, &tegra_drm_master_ops);
+}
+static struct interface_tracker_block itb = {
+ .callback = itb_callback
+};
static int __init tegra_drm_init(void)
{
int err;
- err = interface_register_driver(&host1x_interface_driver);
+ err = interface_tracker_register("nvidia,tegra-host1x",
+ INTERFACE_TRACKER_TYPE_PARENT_DEV, &itb);
if (err < 0)
return err;
@@ -795,7 +795,8 @@ unregister_dsi:
unregister_dc:
platform_driver_unregister(&tegra_dc_driver);
unregister_host1x:
- interface_unregister_driver(&host1x_interface_driver);
+ interface_tracker_unregister("nvidia,tegra-host1x",
+ INTERFACE_TRACKER_TYPE_PARENT_DEV, &itb);
return err;
}
module_init(tegra_drm_init);
@@ -809,7 +810,8 @@ static void __exit tegra_drm_exit(void)
platform_driver_unregister(&tegra_sor_driver); platform_driver_unregister(&tegra_dsi_driver); platform_driver_unregister(&tegra_dc_driver);
- interface_unregister_driver(&host1x_interface_driver);
+ interface_tracker_unregister("nvidia,tegra-host1x",
+ INTERFACE_TRACKER_TYPE_PARENT_DEV, &itb);
}
module_exit(tegra_drm_exit);
drivers/gpu/host1x/dev.c +4 -5
@@ -175,10 +175,9 @@ static int host1x_probe(struct platform_device *pdev)host1x_debug_init (host); - host->interface.name ="nvidia,tegra-host1x" ; - host->interface.dev = &pdev->dev; - - err =interface_add (&host->interface); + err =interface_tracker_ifup ("nvidia,tegra-host1x" , +INTERFACE_TRACKER_TYPE_PARENT_DEV , &pdev->dev);if (err <0 ) goto fail_deinit_intr;
@@ -197,7 +196,9 @@ static int host1x_remove(struct platform_device *pdev) {struct host1x *host =platform_get_drvdata (pdev); -interface_remove (&host->interface); + err =interface_tracker_ifdown ("nvidia,tegra-host1x" , +INTERFACE_TRACKER_TYPE_PARENT_DEV , &pdev->dev);host1x_intr_deinit (host);host1x_syncpt_deinit (host);clk_disable_unprepare (host->clk);
Regards
Andrzej
Quoted 42 lines
Greg,
Do you think you could find the time to look at this patch in a little more detail? This isn't about creating a light alternative to busses at all. It is an attempt to solve a different problem.
Consider the following: you have a collection of hardware devices that together can implement functionality in a given subsystem such as DRM or V4L2. In many cases all these devices have their own driver and they are glued together using the component helpers. This results in a situation where people are instantiating dummy devices for the sole purpose of getting a driver probed, since all of the existing devices have already had a driver bind to them.
Another downside of using dummy devices is that they mess up the device hierarchy. All of a sudden you have a situation where the dummy device is the logical parent for its aunts and uncles (or siblings).
The solution proposed here is to allow any device to expose an interface that interface drivers can bind to. This removes the need for dummy devices. As opposed to device drivers, an interface can be bound to by multiple drivers. That's a feature that is needed specifically by host1x on Tegra since two drivers need to hang off of the host1x device (DRM and V4L2), but I can easily imagine this to be useful in other cases. Interfaces are exposed explicitly at probe time by the device drivers for the devices they drive.
Even though this was designed with the above use-case in mind I can imagine this to be useful for other things as well. For example a set of generic interfaces could be created and devices (or even whole classes of devices) could be made to expose these interfaces. This would cause interfaces to be created for each of these devices. That's functionality similar to what can be done with notifiers, albeit somewhat more structured. That could for example be useful to apply policy to a class of devices or collect statistics, etc.
If you think that I'm on a wild-goose chase, please let me know so that I don't waste any more time on this.
Thierry
Quoted 41 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Hi,
This series converts the Tegra DRM driver to the master/component framework. The length of the series and the list of people in Cc is mostly due to the fact that Tegra has some special requirements as opposed to other drivers and therefore requires some changes outside of DRM.
Patch 1 introduces a helper function that can be used by new DRM drivers that don't rely on legacy userspace ABIs. It allows them to register DRM devices much more easily and without much of the midlayer that currently exists in the DRM subsystem.
Patches 2 and 3 make some changes to the master/component framework which are necessary to convert Tegra DRM to use it. All current users of the API have been converted as part of this patch. Note that at the same time the drivers are converted to no longer use
drm_platform_init()in favour of thedrm_set_unique()from patch 1 in conjunction withdrm_dev_alloc()anddrm_dev_register(). I would've liked to avoid such invasive changes in a single patch, but unfortunately I couldn't think of a way how to do that. I'm open to suggestions.Patch 4 adds a new interface framework that supplements the master/ component framework and can be used in situations where there is no struct device * that a driver can bind to.
The Tegra DRM driver is converted to using the master/component framework in patch 5 using the above four patches.
Finally patches 6 and 7 add some documentation about the new way of registering DRM devices that don't need legacy support.
Each patch has a somewhat more elaborate description of why it is needed or what problem it solves. The patchset applies on top of linux-next.
I welcome any questions or comments you might have.
Thierry
Quoted 8 lines
Thierry Reding (7):
drm: Introducedrm_set_unique()
drivers/base: Allow driver-data to be attached to a masterdrivers/base: Allow multiple masters per devicedrivers/base: Add interface framework
drm/tegra: Convert to master/component framework
drm: Add device registration documentation
drm: Document how to register devices without structdrm_bus
Greg, Russell,
Any comments on this? I've been blocking a bunch of patches in the hopes of getting this merged since it allows the Tegra DRM driver to be cleaned up a great deal, but if nobody's going to look at or comment on this I'll abandon this series and keep using the custom solution we've had for a while now.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Greg Kroah-Hartman
maintainerQuoted 51 lines · Thierry Reding
Quoted 41 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Hi,
This series converts the Tegra DRM driver to the master/component framework. The length of the series and the list of people in Cc is mostly due to the fact that Tegra has some special requirements as opposed to other drivers and therefore requires some changes outside of DRM.
Patch 1 introduces a helper function that can be used by new DRM drivers that don't rely on legacy userspace ABIs. It allows them to register DRM devices much more easily and without much of the midlayer that currently exists in the DRM subsystem.
Patches 2 and 3 make some changes to the master/component framework which are necessary to convert Tegra DRM to use it. All current users of the API have been converted as part of this patch. Note that at the same time the drivers are converted to no longer use
drm_platform_init()in favour of thedrm_set_unique()from patch 1 in conjunction withdrm_dev_alloc()anddrm_dev_register(). I would've liked to avoid such invasive changes in a single patch, but unfortunately I couldn't think of a way how to do that. I'm open to suggestions.Patch 4 adds a new interface framework that supplements the master/ component framework and can be used in situations where there is no struct device * that a driver can bind to.
The Tegra DRM driver is converted to using the master/component framework in patch 5 using the above four patches.
Finally patches 6 and 7 add some documentation about the new way of registering DRM devices that don't need legacy support.
Each patch has a somewhat more elaborate description of why it is needed or what problem it solves. The patchset applies on top of linux-next.
I welcome any questions or comments you might have.
Thierry
Quoted 8 lines
Thierry Reding (7):
drm: Introducedrm_set_unique()
drivers/base: Allow driver-data to be attached to a masterdrivers/base: Allow multiple masters per devicedrivers/base: Add interface framework
drm/tegra: Convert to master/component framework
drm: Add device registration documentation
drm: Document how to register devices without structdrm_bus
Quoted 7 lines
Greg, Russell,
Any comments on this? I've been blocking a bunch of patches in the hopes of getting this merged since it allows the Tegra DRM driver to be cleaned up a great deal, but if nobody's going to look at or comment on this I'll abandon this series and keep using the custom solution we've had for a while now.
I'd like Russell to comment on this, as he just added some driver core work to do drm device work that seems to me to be much the same here.
There's also the work that the media developers are working on to handle power management issues that seem to also be hitting the same area. Due to all of that, I really don't want to add yet-another-driver-core addition for just one drm driver, all of them should be able to use it.
thanks,
greg k-h
Quoted 54 lines · Greg Kroah-Hartman
Quoted 53 lines · Thierry Reding
Quoted 41 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Hi,
This series converts the Tegra DRM driver to the master/component framework. The length of the series and the list of people in Cc is mostly due to the fact that Tegra has some special requirements as opposed to other drivers and therefore requires some changes outside of DRM.
Patch 1 introduces a helper function that can be used by new DRM drivers that don't rely on legacy userspace ABIs. It allows them to register DRM devices much more easily and without much of the midlayer that currently exists in the DRM subsystem.
Patches 2 and 3 make some changes to the master/component framework which are necessary to convert Tegra DRM to use it. All current users of the API have been converted as part of this patch. Note that at the same time the drivers are converted to no longer use
drm_platform_init()in favour of thedrm_set_unique()from patch 1 in conjunction withdrm_dev_alloc()anddrm_dev_register(). I would've liked to avoid such invasive changes in a single patch, but unfortunately I couldn't think of a way how to do that. I'm open to suggestions.Patch 4 adds a new interface framework that supplements the master/ component framework and can be used in situations where there is no struct device * that a driver can bind to.
The Tegra DRM driver is converted to using the master/component framework in patch 5 using the above four patches.
Finally patches 6 and 7 add some documentation about the new way of registering DRM devices that don't need legacy support.
Each patch has a somewhat more elaborate description of why it is needed or what problem it solves. The patchset applies on top of linux-next.
I welcome any questions or comments you might have.
Thierry
Quoted 8 lines
Thierry Reding (7):
drm: Introducedrm_set_unique()
drivers/base: Allow driver-data to be attached to a masterdrivers/base: Allow multiple masters per devicedrivers/base: Add interface framework
drm/tegra: Convert to master/component framework
drm: Add device registration documentation
drm: Document how to register devices without structdrm_busGreg, Russell,
Quoted 8 lines
Quoted 5 lines
Any comments on this? I've been blocking a bunch of patches in the hopes of getting this merged since it allows the Tegra DRM driver to be cleaned up a great deal, but if nobody's going to look at or comment on this I'll abandon this series and keep using the custom solution we've had for a while now.
I'd like Russell to comment on this, as he just added some driver core work to do drm device work that seems to me to be much the same here.
Yes. In fact that's what this series is all about. It converts the Tegra DRM driver to use Russell's master/component helpers. But there are also special requirements on Tegra DRM that require some enhancements to the helpers, which this series does. Furthermore the interface framework introduced here is supposed to complement the master/components helpers. It is not a duplicate implementation but attempts to solves a completely different problem.
Quoted 4 lines
There's also the work that the media developers are working on to handle power management issues that seem to also be hitting the same area. Due to all of that, I really don't want to add yet-another-driver-core addition for just one drm driver, all of them should be able to use it.
Like I said, this "interface" framework is meant to address something different and was specifically designed to be useful for more than just one DRM driver. However, people seem to prefer to make assumptions about this code rather than actually go look (or even read the description) what it really is about.
Besides I already have a working solution for the "one DRM driver". And replacing it with the component/master helpers as-is will make it worse than it is. Hence in order to avoid wasting more of everyone's time I have now dropped patches 2-4 and changed patch 5 to only convert to the drm_dev_set_unique() function, which is the more important piece of the series anyway.
Thierry
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel