> -----Origin email-----
> From: Peter Maydell <peter.mayd...@linaro.org>
> Sent Time: Monday, November 10, 2014
> To: Kaiyuan <kaiyu...@tju.edu.cn>
> Cc: QEMU Developers <qemu-devel@nongnu.org>
> Subject: Re: Re: [Qemu-devel] What "opaque" stand for?
>
> On 10 November 2014 07:33, Kaiyuan <kaiyu...@tju.edu.cn> wrote:
> > Thanks for your explanation, Peter. In this case of
> > timer_read(void *opaque, hwaddr addr, unsigned int size), could
> > I think that opaque is a pointer to a register located in mmio
> > address? If I cast opaque pointer to corresponding structure,
> > the beginning address of structure == hwaddr addr and the size of
> > structure == parameter size?
>
> No, I think you're confused. The "opaque" parameter is simply
> whatever was passed as the fourth argument to memory_region_init_io()
> [see the documentation for that function in include/exec/memory.h].
> Typically in device models we pass the pointer to the device object
> itself, so that the callback can access any relevant internal state.
>
> This has no relation at all to the 'hwaddr' and 'size' arguments
> to the callback, which tell you what relative address within your
> MMIO region the guest was accessing and at what size.
>
> -- PMM
I think I get your point. In this case, opaque points to device after casting
in timer_read(), and hwaddr is relative address. It will read registers' value
or internal state inside device according hwaddr offset and size.