qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] Modeling a device controlled by combination of GPIO and


From: Peter Maydell
Subject: Re: [Qemu-devel] Modeling a device controlled by combination of GPIO and UART
Date: Wed, 22 Aug 2018 12:56:09 +0100

On 22 August 2018 at 08:36, Martin Schroeder
<address@hidden> wrote:
> Thanks Peter.
>
> I have set it up such that master device has qemu_irq array which it
> initializes using qdev_init_gpio_out with number of gpio lines going
> out and slave device calls qdev_init_gpio_in with a callback that
> should be called when irq is raised. Then I connect them together at
> higher level using qdev_connect_gpio_out as you said. Then master
> calls qemu_set_irq with 1 or 0 depending on whether the gpio is high
> or low.
>
> This works, but not as I would expect. The handler that I supply to
> the init_gpio_in is only being called very infrequently - perhaps once
> every 50 toggles on the gpio pin. I need to make sure that it gets
> called every time master device calls qemu_set_irq.
>
> What's the mechanism behind this behavior and how can I deliver gpio
> change to the slave?

The mechanism is pretty simple -- a qemu_irq is really a
pointer to a small struct that has a function pointer in
it. Initializing a gpio in is just setting up the struct and
function pointer. Connecting them is passing the qemu_irq
pointer to the source. Calling qemu_set_irq() simply
calls the function pointer. (You can step through in a
debugger from the qemu_set_irq call through to the target
function call if you like -- it's not very much code.)

This can fail in the sense that if you don't wire it up
right then nothing happens when you call qemu_set_irq()
(because you didn't give the source device the right
qemu_irq or you didn't give it one at all), but it
shouldn't be able to fail unreliably and only call
the destination handler some of the time.

thanks
-- PMM



reply via email to

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