[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cdi-devel] [PATCH v2 5/9] cdi.h: Add cdi_handle_bus_device()



+ Currently, all devices provided on a bus have to be passed to the
  init_device() function of all drivers handling any device type on that
  bus. cdi_handle_bus_device() can be used by the driver to specify a
  pattern (struct cdi_bus_device_pattern) which allows the CDI
  implementation to speed up the selection of the correct driver for a
  new device.

Signed-off-by: Max Reitz <max@xxxxxxxxxx>
---
 include/cdi.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/include/cdi.h b/include/cdi.h
index 998e080..9c1c1b1 100644
--- a/include/cdi.h
+++ b/include/cdi.h
@@ -141,6 +141,17 @@ struct cdi_bus_data {
 };
 
 /**
+ * This structure, which is extended by any bus type supporting it, contains
+ * information about which devices can be handled by a certain driver.
+ * Typically, it will contain some of the fields provided by the appropriate
+ * cdi_bus_data structure (the ones which are used to identify a device like
+ * device/vendor ID) where negative values signify a "don't care".
+ */
+struct cdi_bus_device_pattern {
+    cdi_device_type_t bus_type;
+};
+
+/**
  * \german
  * Beschreibt ein Gerät
  * \endgerman
@@ -406,6 +417,19 @@ int cdi_provide_device(struct cdi_bus_data* device);
 int cdi_provide_device_internal_drv(struct cdi_bus_data* device,
                                     struct cdi_driver* driver);
 
+/**
+ * Tells the CDI implementation that the driver @drv is able to handle devices
+ * with the pattern @pattern (appearing on the bus @pattern->bus_type). This
+ * function can be called multiple times. Any device appearing on the bus not
+ * fitting the pattern will not be passed to the @drv->init_device() function.
+ * That function may however return NULL even after the driver has used this
+ * function, that is, it is valid to call this function with a @pattern that
+ * does not only fit devices handled by @drv but others as well (which can then
+ * be rejected by letting @drv->init_device() return NULL).
+ */
+void cdi_handle_bus_device(struct cdi_driver* drv,
+                           struct cdi_bus_device_pattern* pattern);
+
 #endif
 
 /*\@}*/
-- 
2.3.5