Opened 15 years ago
Last modified 15 years ago
#57 new task
Rework device API: one device in many classes
| Reported by: | Nicolas Pouillon | Owned by: | Nicolas Pouillon |
|---|---|---|---|
| Priority: | blocker | Milestone: | Topology handling |
| Component: | drivers | Keywords: | |
| Cc: |
Description
We currently have a problem with devices that are in more than one driver class at the same time. We have to split them in subdevices, even if it is incorrect.
Some examples:
- CPU nodes are also ICUs
- soclib Xicu is timer and ICU
There once was a discussion about allowing devices to implement more than one class at the same time. How to do this ?
Attachments (1)
Change History (2)
Note:
See TracTickets
for help on using tickets.


Could we do something like:
API proposal
enum device_class_e { DEVICE_CLASS_FOO, #if defined(CONFIG_FEATURE_BAR) DEVICE_CLASS_BAR, #endif DEVICE_CLASS_COUNT, }; #define DEVICE_CLASS_UNAVAILABLE 0xff struct driver_funcs_s { union { struct { void (*op1)(struct device_s *dev, … ); void (*op2)(struct device_s *dev, … ); } foo; #if defined(CONFIG_FEATURE_BAR) struct { void (*op1)(struct device_s *dev, … ); void (*op2)(struct device_s *dev, … ); } bar; #endif }; } struct driver_s { error_t (*init)(struct device_s *dev, void *param); error_t (*cleanup)(struct device_s *dev); #if defined(CONFIG_DRIVER_MULTICLASS) uint8_t funcs_offset[DEVICE_CLASS_COUNT]; #endif struct driver_funcs_s funcs[0]; };Accessing functions of a given class
const struct driver_funcs_s *driver_class_funcs( const struct driver_s *drv, enum device_class_e class) { #if defined(CONFIG_DRIVER_MULTICLASS) const uint8_t offset = drv->funcs_offset[class]; assert(offset != DEVICE_CLASS_UNAVAILABLE); #else const uint8_t offset = 0; #endif return &drv->funcs[offset]; }Example for implementing a generic function of class BAR
void device_bar_op1(struct device_s *dev, …) { const struct driver_funcs_s *funcs = driver_class_funcs(dev->drv, DEVICE_CLASS_BAR); return funcs->bar.op1( dev, … ); }Rationale
Added from current code, there is a new indirection through
drv->funcs_offset.driver_class_funcsreturn&funcs[0]if there is no support for multiple drivers per device.Is this acceptable ?