[cdi-devel] [PATCH v2 5/9] cdi.h: Add cdi_handle_bus_device()
Max Reitz ·
On 16.04.2015 23:50, Kevin Wolf wrote: > On Thu, Apr 16, 2015 at 12:13:54AM +0200, Max Reitz wrote: >> + 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 at tyndur.org> > As you still haven't convinced me that you only speak Saxionian and no > German, bilingual documentation, please. ;-) Bah. Ähmal Dogumendazschioun zu schraim war mir ganz bersöhnlisch nu or schon fast ä bissel zu viel, da wäsch nu ni, obsch das ohch noch dobblt hinkriesche. ;-) >> 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); > Is this supposed to be called in drv->init_driver()? If so, could be > worth mentioning. I didn't intend any constraints for it, but limiting it to init_driver() seems reasonable. > Ideally it would just be part of the static driver declaration instead > of a separate function, but I imagine this is hard to achieve with both > the driver and device pattern being subclassed. Initially, I made it part of the static driver declaration, but then I didn't really want to go into having a variable-length array for multiple bus device patterns as part of the driver structure... Max