qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 1/2] memory: Fix old portio word accesses


From: Avi Kivity
Subject: Re: [Qemu-devel] [PATCH v2 1/2] memory: Fix old portio word accesses
Date: Mon, 19 Sep 2011 16:09:24 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]