[PATCH] xfree86: use udev to provide device enumeration for kms devices (v2)

2012-05-09 Thread Dave Airlie
From: Dave Airlie 

On Linux in order for future hotplug work, we are required to interface
to udev to detect device creation/removal. In order to try and get
some earlier testing on this, this patch adds the ability to use
udev for device enumeration on Linux.

At startup the list of drm/kms devices is probed and this info is
used to load drivers.

A new driver probing method is introduced that passes the udev
device info to the driver for probing.

The probing integrates with the pci probing code and will fallback
to the pci probe and old school probe functions in turn.

The flags parameter to the probe function will be used later
to provide hotplug and gpu screen flags for the driver to behave
in a different way.

This patch changes the driver ABI, all drivers should at least
be set with a NULL udev probe function after this commit.

v2: rename to platform bus, now with 100% less udev specific,

this version passes config_odev_attribs around which are an array
of id/string pairs, then the udev code can attach the set of attribs
it understands, the OS specific code can attach its attrib, and then
the core/drivers can lookup the required attribs.

also add MATCH_PCI_DEVICES macro.

This version is mainly to address concerns raised by ajax.

Signed-off-by: Dave Airlie 
---
 config/config-backends.h |1 +
 config/config.c  |8 +
 config/udev.c|   49 +
 configure.ac |   20 ++-
 hw/xfree86/common/Makefile.am|8 +-
 hw/xfree86/common/xf86.h |5 +
 hw/xfree86/common/xf86Bus.c  |   25 ++-
 hw/xfree86/common/xf86Bus.h  |1 +
 hw/xfree86/common/xf86fbBus.c|4 +
 hw/xfree86/common/xf86pciBus.c   |   17 ++-
 hw/xfree86/common/xf86pciBus.h   |5 +
 hw/xfree86/common/xf86platformBus.c  |  264 ++
 hw/xfree86/common/xf86platformBus.h  |   52 +
 hw/xfree86/common/xf86str.h  |   15 ++
 hw/xfree86/os-support/linux/Makefile.am  |2 +-
 hw/xfree86/os-support/linux/lnx_platform.c   |   87 +
 hw/xfree86/os-support/shared/platform_noop.c |   17 ++
 hw/xfree86/os-support/xf86_OSproc.h  |6 +
 include/dix-config.h.in  |3 +
 include/hotplug.h|   16 ++
 include/xorg-config.h.in |3 +
 include/xorg-server.h.in |3 +
 22 files changed, 599 insertions(+), 12 deletions(-)
 create mode 100644 hw/xfree86/common/xf86platformBus.c
 create mode 100644 hw/xfree86/common/xf86platformBus.h
 create mode 100644 hw/xfree86/os-support/linux/lnx_platform.c
 create mode 100644 hw/xfree86/os-support/shared/platform_noop.c

diff --git a/config/config-backends.h b/config/config-backends.h
index 62abc0a..6423701 100644
--- a/config/config-backends.h
+++ b/config/config-backends.h
@@ -36,6 +36,7 @@ BOOL device_is_duplicate(const char *config_info);
 int config_udev_pre_init(void);
 int config_udev_init(void);
 void config_udev_fini(void);
+void config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback);
 #else
 
 #ifdef CONFIG_NEED_DBUS
diff --git a/config/config.c b/config/config.c
index 24e7ba7..07e920e 100644
--- a/config/config.c
+++ b/config/config.c
@@ -85,6 +85,14 @@ config_fini(void)
 #endif
 }
 
+void
+config_odev_probe(config_odev_probe_proc_ptr probe_callback)
+{
+#if defined(CONFIG_UDEV_KMS)
+config_udev_odev_probe(probe_callback);
+#endif
+}
+
 static void
 remove_device(const char *backend, DeviceIntPtr dev)
 {
diff --git a/config/udev.c b/config/udev.c
index 1995184..a2d5aad 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -366,3 +366,52 @@ config_udev_fini(void)
 udev_monitor = NULL;
 udev_unref(udev);
 }
+
+#ifdef CONFIG_UDEV_KMS
+void
+config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback)
+{
+struct udev *udev;
+struct udev_enumerate *enumerate;
+struct udev_list_entry *devices, *device;
+struct config_odev_attribute attribs[3];
+
+udev = udev_monitor_get_udev(udev_monitor);
+enumerate = udev_enumerate_new(udev);
+if (!enumerate)
+return;
+
+udev_enumerate_add_match_subsystem(enumerate, "drm");
+udev_enumerate_add_match_sysname(enumerate, "card[0-9]*");
+udev_enumerate_scan_devices(enumerate);
+devices = udev_enumerate_get_list_entry(enumerate);
+udev_list_entry_foreach(device, devices) {
+const char *syspath = udev_list_entry_get_name(device);
+struct udev_device *udev_device = udev_device_new_from_syspath(udev, 
syspath);
+const char *path = udev_device_get_devnode(udev_device);
+const char *sysname = udev_device_get_sysname(udev_device);
+int probe = TRUE;
+
+if (!path || !syspath)
+probe = FALSE;
+   if (strcmp(udev_device_get_subsystem(udev_device), "drm"))
+   

Re: [PATCH] xfree86: use udev to provide device enumeration for kms devices (v2)

2012-05-09 Thread Peter Hutterer
On Wed, May 09, 2012 at 12:10:11PM +0100, Dave Airlie wrote:
> From: Dave Airlie 
> 
> On Linux in order for future hotplug work, we are required to interface
> to udev to detect device creation/removal. In order to try and get
> some earlier testing on this, this patch adds the ability to use
> udev for device enumeration on Linux.
> 
> At startup the list of drm/kms devices is probed and this info is
> used to load drivers.
> 
> A new driver probing method is introduced that passes the udev
> device info to the driver for probing.
> 
> The probing integrates with the pci probing code and will fallback
> to the pci probe and old school probe functions in turn.
> 
> The flags parameter to the probe function will be used later
> to provide hotplug and gpu screen flags for the driver to behave
> in a different way.
> 
> This patch changes the driver ABI, all drivers should at least
> be set with a NULL udev probe function after this commit.
> 
> v2: rename to platform bus, now with 100% less udev specific,
> 
> this version passes config_odev_attribs around which are an array
> of id/string pairs, then the udev code can attach the set of attribs
> it understands, the OS specific code can attach its attrib, and then
> the core/drivers can lookup the required attribs.
> 
> also add MATCH_PCI_DEVICES macro.
> 
> This version is mainly to address concerns raised by ajax.
> 
> Signed-off-by: Dave Airlie 
> ---
>  config/config-backends.h |1 +
>  config/config.c  |8 +
>  config/udev.c|   49 +
>  configure.ac |   20 ++-
>  hw/xfree86/common/Makefile.am|8 +-
>  hw/xfree86/common/xf86.h |5 +
>  hw/xfree86/common/xf86Bus.c  |   25 ++-
>  hw/xfree86/common/xf86Bus.h  |1 +
>  hw/xfree86/common/xf86fbBus.c|4 +
>  hw/xfree86/common/xf86pciBus.c   |   17 ++-
>  hw/xfree86/common/xf86pciBus.h   |5 +
>  hw/xfree86/common/xf86platformBus.c  |  264 
> ++
>  hw/xfree86/common/xf86platformBus.h  |   52 +
>  hw/xfree86/common/xf86str.h  |   15 ++
>  hw/xfree86/os-support/linux/Makefile.am  |2 +-
>  hw/xfree86/os-support/linux/lnx_platform.c   |   87 +
>  hw/xfree86/os-support/shared/platform_noop.c |   17 ++
>  hw/xfree86/os-support/xf86_OSproc.h  |6 +
>  include/dix-config.h.in  |3 +
>  include/hotplug.h|   16 ++
>  include/xorg-config.h.in |3 +
>  include/xorg-server.h.in |3 +
>  22 files changed, 599 insertions(+), 12 deletions(-)
>  create mode 100644 hw/xfree86/common/xf86platformBus.c
>  create mode 100644 hw/xfree86/common/xf86platformBus.h
>  create mode 100644 hw/xfree86/os-support/linux/lnx_platform.c
>  create mode 100644 hw/xfree86/os-support/shared/platform_noop.c
> 
> diff --git a/config/config-backends.h b/config/config-backends.h
> index 62abc0a..6423701 100644
> --- a/config/config-backends.h
> +++ b/config/config-backends.h
> @@ -36,6 +36,7 @@ BOOL device_is_duplicate(const char *config_info);
>  int config_udev_pre_init(void);
>  int config_udev_init(void);
>  void config_udev_fini(void);
> +void config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback);
>  #else
>  
>  #ifdef CONFIG_NEED_DBUS
> diff --git a/config/config.c b/config/config.c
> index 24e7ba7..07e920e 100644
> --- a/config/config.c
> +++ b/config/config.c
> @@ -85,6 +85,14 @@ config_fini(void)
>  #endif
>  }
>  
> +void
> +config_odev_probe(config_odev_probe_proc_ptr probe_callback)
> +{
> +#if defined(CONFIG_UDEV_KMS)
> +config_udev_odev_probe(probe_callback);
> +#endif
> +}
> +
>  static void
>  remove_device(const char *backend, DeviceIntPtr dev)
>  {
> diff --git a/config/udev.c b/config/udev.c
> index 1995184..a2d5aad 100644
> --- a/config/udev.c
> +++ b/config/udev.c
> @@ -366,3 +366,52 @@ config_udev_fini(void)
>  udev_monitor = NULL;
>  udev_unref(udev);
>  }
> +
> +#ifdef CONFIG_UDEV_KMS
> +void
> +config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback)
> +{
> +struct udev *udev;
> +struct udev_enumerate *enumerate;
> +struct udev_list_entry *devices, *device;
> +struct config_odev_attribute attribs[3];



> +
> +udev = udev_monitor_get_udev(udev_monitor);
> +enumerate = udev_enumerate_new(udev);
> +if (!enumerate)
> +return;
> +
> +udev_enumerate_add_match_subsystem(enumerate, "drm");
> +udev_enumerate_add_match_sysname(enumerate, "card[0-9]*");
> +udev_enumerate_scan_devices(enumerate);
> +devices = udev_enumerate_get_list_entry(enumerate);
> +udev_list_entry_foreach(device, devices) {
> +const char *syspath = udev_list_entry_get_name(device);
> +struct udev_device *udev_device = udev_device_new_from_sys