tech-kern archive

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

Re: General device properties API



> On Sep 12, 2021, at 8:17 AM, Jason Thorpe <thorpej%me.com@localhost> wrote:
> 
> Doing this with symbols is a mess.

Here’s a way to basically get most of what you want without referencing symbols:

struct device_call_generic {
        const char *name; 
        void *args; 
};
 
int     device_call_generic(device_t, const struct device_call_generic *); 
 
struct i2c_enumerate_devices_args {
        ...
};

union i2c_enumerate_devices_binding { 
        struct device_call_generic generic;
        struct {
                const char *name;
                struct i2c_enumerate_devices_args *args;
        } binding;
};

#define I2C_ENUMERATE_DEVICES(_args_)                                   \
        &((const union i2c_enumerate_devices_binding){                  \
                .binding.name = "i2c-enumerate-devices",                \
                .binding.args = (_args_),                               \
        })      
        
#define device_call(dev, call)                                          \
        device_call_generic((dev), (call)->generic) 
 
 
        
        struct i2c_attach_args ia = {
                .ia_tag = ic,
        };
        struct i2c_enumerate_devices_args enumargs = {
                .ia = &ia,
                .callback = iic_enumerate_devices_callback,
        };
 
        rv = device_call(dev, I2C_ENUMERATE_DEVICES(&enumargs));

-- thorpej



Home | Main Index | Thread Index | Old Index