On 09/19/2011 03:55 PM, Jan Kiszka wrote:
>
> The trick of having a way to register N callbacks with one shot is worth
> growing. Ideally each register in a BAR would have a callback and we'd
> do something like
>
> MemoryRegionOps mydev_ops = {
> .registers = {
> { MYDEV_REG_x, 4, 4, mydev_reg_x_read, mydev_reg_x_write, },
> ...
> },
> }
>
> with hints to the core like "this register sits at this offset, use it
> for reads instead of a callback", or, "this is a read-only register".
This has pros and cons. If you have n registers to dispatch, you then
have to write n function prologues and maybe epilogues instead of just
one. Specifically if the register access is trivial, that could case
quite some LoC blowup on the device side.
What may have a better ratio are generic register get/set handlers.
With C++ pointers-to-members and pointers-to-member-functions, you
actually get some nice representation:
class MyDev {
void reg_1_read(...) { return some_computation(); }
void reg_1_write(...) { do_something(); }
uint32_t reg_2;
void reg_2_write(...) { reg_2 = value; do_something(); }
uint64_t reg_3;
static const Register registers[] = {
Register(REG_1, &MyDev::reg_1_read, &MyDev::reg_1_write),
Register(REG_2, &MyDev::reg_2, &MyDev::reg_2_write),
Register(REG_1, &MyDev::reg_3),
};
};
... and the Register class generates the appropriate accessors. We can
emulate some of this with macros, but the conversion from opaque to the
actual type will always be ugly.
--
error compiling committee.c: too many arguments to function