arm: virt: change GPIO trigger interrupt to pulse
PATCH 1/1 arm: virt: change GPIO trigger interrupt to pulse
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/virt.c +1 -1
@@ -546,7 +546,7 @@ static DeviceState *pl061_dev;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_irq_pulse (qdev_get_gpio_in (pl061_dev,3 )); }static Notifier virt_system_powerdown_notifier = {
Signature · 1 line
1.8.3.1
Hi,
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open /dev/input/event0 failed. So the interrupt could be injected and could see under /proc/interrupts but guest doesn't have any action. I'll investigate why it opens failed later.
Quoted 30 lines · 2016年1月29日星期五,Wei Huang <[email protected]> 写道:
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
Signed-off-by Wei Huang <[email protected] <javascript:;>>--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/virt.c +1
-2@@ -546,7 +546,7 @@ static DeviceState *pl061_dev;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_irq_pulse (qdev_get_gpio_in (pl061_dev,3 )); }static Notifier virt_system_powerdown_notifier = { --1.8.3.1
Quoted 6 lines · Shannon Zhao
Hi,
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed. So the interrupt could be injected and could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.
That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);
Thanks,
-Wei
Quoted 34 lines
Quoted 30 lines · 2016年1月29日星期五,Wei Huang <[email protected]> 写道:
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
Signed-off-by Wei Huang <[email protected] <javascript:;>>--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/virt.c +1
-2@@ -546,7 +546,7 @@ static DeviceState *pl061_dev;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_irq_pulse (qdev_get_gpio_in (pl061_dev,3 )); }static Notifier virt_system_powerdown_notifier = { --1.8.3.1
Quoted 5 lines · Wei Huang
Quoted 2 lines · Shannon Zhao
Hi,
Quoted 8 lines
Quoted 4 lines
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed. So the interrupt could be injected and could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Yeah, that's very weird.
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);
I'll try this tomorrow. But even if this works, it's still weird.
Quoted 37 lines
Thanks,
-WeiQuoted 34 lines
Quoted 30 lines · 2016年1月29日星期五,Wei Huang <[email protected]> 写道:
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
Signed-off-by Wei Huang <[email protected] <javascript:;>>--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/virt.c +1
-2@@ -546,7 +546,7 @@ static DeviceState *pl061_dev;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_irq_pulse (qdev_get_gpio_in (pl061_dev,3 )); }static Notifier virt_system_powerdown_notifier = { --1.8.3.1
Signature · 1 line
Shannon
Quoted 18 lines · Shannon Zhao
Quoted 12 lines · Wei Huang
Quoted 8 lines · Shannon Zhao
Hi,
This makes ACPI work well but makes DT not work. The reason is systemd or
acpid open/dev/input/event0failed. So the interrupt could be injected and
could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.Quoted 3 lines
That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Quoted 6 lines
Yeah, that's very weird.
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);I'll try this tomorrow. But even if this works, it's still weird.
To reproduce this case, do the following steps using current upstream
qemu: create vm => reboot vm (succeed) => reboot or shutdown vm (fail). Apparently the last interrupt wasn't received correctly.
-Wei
Quoted 39 lines
Quoted 38 lines
Thanks,
-WeiQuoted 34 lines
Quoted 30 lines · 2016年1月29日星期五,Wei Huang <[email protected]> 写道:
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
Signed-off-by Wei Huang <[email protected] <javascript:;>>--- hw/arm/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/virt.c +1
-1@@ -546,7 +546,7 @@ static DeviceState *pl061_dev;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_irq_pulse (qdev_get_gpio_in (pl061_dev,3 )); }static Notifier virt_system_powerdown_notifier = {Signature · 1 line
1.8.3.1
Quoted 12 lines · Shannon Zhao
Quoted 11 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed. So the interrupt could be injected and
could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Quoted 6 lines
Yeah, that's very weird.
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);I'll try this tomorrow. But even if this works, it's still weird.
I wonder if we should be asserting the GPIO pin in the powerdown-request hook and then deasserting it on system reset somewhere...
thanks
-- PMM
Quoted 15 lines · Peter Maydell
Quoted 14 lines · Shannon Zhao
Quoted 11 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed. So the interrupt could be injected and
could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Yeah, that's very weird.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);I'll try this tomorrow. But even if this works, it's still weird.
I wonder if we should be asserting the GPIO pin in the powerdown-request hook and then deasserting it on system reset somewhere...
This is another possibility. We can try to reset the pl061 state by hooking up with dc->reset and see what happens.
Quoted 4 lines
thanks
-- PMM
Quoted 22 lines · Wei Huang
Quoted 20 lines · Shannon Zhao
Quoted 20 lines · Wei Huang
Quoted 12 lines
Quoted 12 lines · Shannon Zhao
Quoted 8 lines
Quoted 8 lines
Hi,
This makes ACPI work well but makes DT not work. The reason is systemd or
acpid open/dev/input/event0failed. So the interrupt could be injected and
could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.Quoted 3 lines
Quoted 3 lines
That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Yeah, that's very weird.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);I'll try this tomorrow. But even if this works, it's still weird.
To reproduce this case, do the following steps using current upstream
qemu: create vm => reboot vm (succeed) => reboot or shutdown vm (fail). Apparently the last interrupt wasn't received correctly.
Yes, I reproduce this today. Let's clarify current state.
Firstly, for ACPI it should use qemu_irq_pulse since we make the GPIO pin edge-triggered. And for DT, it uses gpio-key which is also edge-triggered that we could get from output of guest /proc/interrupts.
Secondly, current upstream qemu with your patch makes second reboot works when using ACPI. But first shutdown/reboot doesn't works when using DT since the systemd or acpid open /dev/input/event0 failed. This is what I'm surprised.
Wei, what userspace program your guest uses? systemd or acpid? Could you please try to use DT to test your patch? And see if there is a same result with me.(I know Redhat kernel uses ACPI by default, so you could append acpi=off to switch to DT)
Thanks,
Signature · 1 line
Shannon
Quoted 8 lines · Wei Huang
Quoted 2 lines · Peter Maydell
I wonder if we should be asserting the GPIO pin in the powerdown-request hook and then deasserting it on system reset somewhere...
This is another possibility. We can try to reset the pl061 state by hooking up with
dc->resetand see what happens.
Ah, yes, PL061 hasn't been updated to implement reset. That is almost certainly your problem.
thanks
-- PMM
Quoted 6 lines · Wei Huang
Quoted 4 lines · Shannon Zhao
Quoted 4 lines
Hi,
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed.
To correct, systemd or acpid open /dev/input/event0 successfully but it waits for events and when we input "system_powerdown", it doesn't get the event.
Quoted 8 lines
So the interrupt could be injected and
Quoted 2 lines
Quoted 2 lines
could see under
/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);
If we don't input "system_powerdown" during guest booting(before device driver load), current QEMU with above codes could work for DT. But if we input "system_powerdown" during guest booting, guest has no action when we input "system_powerdown" again after guest booting completely. I add dc->reset for pl061 but get the same result.
Below is the output of acpid:
./acpid -l -n -d
input layer /dev/input/event0 (gpio-keys) opened successfully, fd 4 inotify fd: 5
inotify wd: 1
RTNETLINK1 answers: No such file or directory
acpid: error talking to the kernel via netlink
netlink opened successfully
acpid: starting up with netlink and the input layer parsing conf file /etc/acpi/events/powerbtn
acpid: 1 rule loaded
acpid: waiting for events: event logging is on
It will stuck here even if we input "system_powerdown".
Below is the right output when we input "system_powerdown".
./acpid -l -n -d
input layer /dev/input/event0 (gpio-keys) opened successfully, fd 4 inotify fd: 5
inotify wd: 1
RTNETLINK1 answers: No such file or directory
acpid: error talking to the kernel via netlink
netlink opened successfully
acpid: starting up with netlink and the input layer
parsing conf file /etc/acpi/events/powerbtn
acpid: 1 rule loaded
acpid: waiting for events: event logging is on
acpid: received input layer event "button/power PBTN 00000080 00000000"
acpid: rule from /etc/acpi/events/powerbtn matched
acpid: executing action "/etc/acpi/powerbtn.sh"
Thanks,
Signature · 1 line
Shannon
Quoted 19 lines · On Fri, 29 Jan 2016 09:13:15 -0600 Wei Huang <[email protected]> wrote:
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Shannon Zhao
Quoted 11 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed. So the interrupt could be injected and
could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Yeah, that's very weird.
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I'll try this tomorrow. But even if this works, it's still weird.
I wonder if we should be asserting the GPIO pin in the powerdown-request hook and then deasserting it on system reset somewhere...
This is another possibility. We can try to reset the pl061 state by hooking up with
dc->resetand see what happens.
I think that's what we do on x86.
Quoted 6 lines
Quoted 5 lines
thanks
-- PMM
Quoted 22 lines · Igor Mammedov
Quoted 19 lines · On Fri, 29 Jan 2016 09:13:15 -0600 Wei Huang <[email protected]> wrote:
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Shannon Zhao
Quoted 11 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
This makes ACPI work well but makes DT not work. The reason is systemd or acpid open
/dev/input/event0failed. So the interrupt could be injected and
could see under/proc/interruptsbut guest doesn't have any action. I'll investigate why it opens failed later.That is interesting. Could you try it with the following? This reverses the order to down-up and worked on ACPI case.
Yeah, that's very weird.
Quoted 3 lines
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I'll try this tomorrow. But even if this works, it's still weird.
I wonder if we should be asserting the GPIO pin in the powerdown-request hook and then deasserting it on system reset somewhere...
This is another possibility. We can try to reset the pl061 state by hooking up with
dc->resetand see what happens.I think that's what we do on x86.
So the device state is wrong after reset. I just sent out a fix for it, which was verified on ACPI code path. Basically the old_in_data is stale after reboot, causing QEMU to believe that it isn't necessary to raise up IRQ again for the second reboot/shutdown (see s->old_in_data ^ s->data in pl061.c file).
Shannon: could you double check from your side with my patch?
-Wei
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
thanks
-- PMM
Quoted 7 lines · Wei Huang
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
So, what's the outcome of this? :)
Thanks,
/mjt
Quoted 14 lines
hw/arm/virt.c +1
-1@@ -546,7 +546,7 @@ static DeviceState *pl061_dev;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_irq_pulse (qdev_get_gpio_in (pl061_dev,3 )); }static Notifier virt_system_powerdown_notifier = {
Quoted 10 lines · Michael Tokarev
Quoted 7 lines · Wei Huang
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
So, what's the outcome of this? :)
This patch is definitely wrong. The patch to fix up the gpio reset stuff is definitely the right idea. Whether it fixes the reported failure or some further change is also needed is currently unclear.
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Michael Tokarev
Quoted 7 lines · Wei Huang
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
Quoted 6 lines
Quoted 1 line
So, what's the outcome of this? :)
This patch is definitely wrong. The patch to fix up the gpio reset stuff is definitely the right idea. Whether it fixes the reported failure or some further change is also needed is currently unclear.
I will NAK this one for now. Please see V2 patch, which is necessary. In the meanwhile, I think there is a problem with pulling-up only in current implementation. Let me debug Shannon's DT problem first.
Quoted 4 lines
thanks
-- PMM
Quoted 14 lines · Wei Huang
Quoted 12 lines · Peter Maydell
Quoted 12 lines · Michael Tokarev
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines · Wei Huang
Quoted 7 lines
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
So, what's the outcome of this? :)
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
This patch is definitely wrong. The patch to fix up the gpio reset stuff is definitely the right idea. Whether it fixes the reported failure or some further change is also needed is currently unclear.
I will NAK this one for now. Please see V2 patch, which is necessary. In the meanwhile, I think there is a problem with pulling-up only in current implementation. Let me debug Shannon's DT problem first.
Hi Wei,
The reason of DT problem is that when we use qemu_irq_pulse(i.e qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1); qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);), it will inject the GPIO interrupt until it executes qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0) because the qemu main thread is serialized and then guest will get the button value as zero, so it's failed to report the input event.
See gpio_keys_gpio_report_event
in drivers/input/keyboard/gpio_keys.c
int state = gpio_get_value_cansleep(button->gpio);
The state is always zero.
The solution I think would be making the each qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1 or 0) cloud inject an interrupt to guest.
Thanks,
Signature · 1 line
Shannon
Quoted 35 lines · Shannon Zhao
Quoted 14 lines · Wei Huang
Quoted 12 lines · Peter Maydell
Quoted 12 lines · Michael Tokarev
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines · Wei Huang
Quoted 7 lines
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot request will succeed; but the following shutdown/reboot requests fail to trigger VMs to react. Notice that in mach-virt machine model GPIO is defined as edge-triggered and active-high in ACPI. This patch changes the behavior of powerdown notifier from PULLUP to PULSE. It solves the problem described above (i.e. reboot continues to work).
So, what's the outcome of this? :)
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
This patch is definitely wrong. The patch to fix up the gpio reset stuff is definitely the right idea. Whether it fixes the reported failure or some further change is also needed is currently unclear.
I will NAK this one for now. Please see V2 patch, which is necessary. In the meanwhile, I think there is a problem with pulling-up only in current implementation. Let me debug Shannon's DT problem first.
Hi Wei,
The reason of DT problem is that when we use qemu_irq_pulse(i.e
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);), it will inject the GPIO interrupt until it executesqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0)because the qemu main thread is serialized and then guest will get the button value as zero, so it's failed to report the input event.
Quoted 5 lines
See
gpio_keys_gpio_report_event
indrivers/input/keyboard/gpio_keys.c
int state =gpio_get_value_cansleep(button->gpio);The state is always zero.
I reversed the order of edge pulling. The state is 1 according to printk inside gpio_keys driver. However the reboot still failed with two reboots (1 very early, 1 later).
Quoted 7 lines
The solution I think would be making the each
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1 or 0)cloud inject an interrupt to guest.Thanks,
Quoted 37 lines · Wei Huang
Quoted 35 lines · Shannon Zhao
Quoted 35 lines · Wei Huang
Quoted 14 lines
Quoted 14 lines · Peter Maydell
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines · Michael Tokarev
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
28.01.2016 21:22, Wei Huang wrote:
When QEMU is hook'ed up with libvirt/virsh, the first ACPI reboot
request will succeed; but the following shutdown/reboot requests
fail to trigger VMs to react. Notice that in mach-virt machine
model GPIO is defined as edge-triggered and active-high in ACPI.
This patch changes the behavior of powerdown notifier from PULLUP
to PULSE. It solves the problem described above (i.e. reboot
continues to work).So, what's the outcome of this? :)
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This patch is definitely wrong. The patch to fix up the gpio reset stuff is definitely the right idea. Whether it fixes the reported failure or some further change is also needed is currently unclear.
I will NAK this one for now. Please see V2 patch, which is necessary. In the meanwhile, I think there is a problem with pulling-up only in current implementation. Let me debug Shannon's DT problem first.
Hi Wei,
The reason of DT problem is that when we use qemu_irq_pulse(i.e
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);), it will inject the GPIO interrupt until it executesqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0)because the qemu main thread is serialized and then guest will get the button value as zero, so it's failed to report the input event.
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
See
gpio_keys_gpio_report_event
indrivers/input/keyboard/gpio_keys.c
int state =gpio_get_value_cansleep(button->gpio);The state is always zero.
I reversed the order of edge pulling. The state is 1 according to printk inside
gpio_keysdriver. However the reboot still failed with two reboots (1 very early, 1 later).
Because to make the input work, it should call input_event twice I think.
input_event(input, type, button->code, 1) means the button pressed input_event(input, type, button->code, 0) means the button released
But We only see guest entering gpio_keys_gpio_report_event once.
My original purpose is like below:
call qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1) to make guest execute input_event(input, type, button->code, 1)
call qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0) to make guest execute input_event(input, type, button->code, 0).
But even though it calls qemu_set_irq twice, it only calls pl061_update once in qemu.
Signature · 1 line
Shannon
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Wei Huang
On 02/03/2016 07:44 PM, Shannon Zhao wrote:
<snip>
Quoted 13 lines
Quoted 4 lines
I reversed the order of edge pulling. The state is 1 according to printk inside
gpio_keysdriver. However the reboot still failed with two reboots (1 very early, 1 later).Because to make the input work, it should call
input_eventtwice I think.
input_event(input, type, button->code, 1)means the button pressedinput_event(input, type, button->code, 0)means the button releasedBut We only see guest entering
gpio_keys_gpio_report_eventonce.My original purpose is like below:
Quoted 7 lines
call
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1)to make guest executeinput_event(input, type, button->code, 1)
callqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0)to make guest executeinput_event(input, type, button->code, 0).But even though it calls
qemu_set_irqtwice, it only callspl061_updateonce in qemu.
Hi Shannon,
Assuming that we are talking about the special case you found (i.e. send reboot very early and then send another one after guest VM fully booted). Dug into the code further, here are my findings:
=== Why ACPI case failed? ===
QEMU pl061.c checks the current request against the new request (see s->old_in_data ^ s->data in pl061.c file). If no change, nothing will happen.
So two consecutive reboots will cause the following state change; apparently the second request won't trigger VM reboot because pl01_update() decides _not_ to inject IRQ into guest VM.
(PL061State fields) data old_in_data istate VM boot 0 0 0 1st ACPI reboot request 8 0 0 After VM PL061 driver ACK 8 8 0 2nd ACPI reboot request 8 no-change, no IRQ <==
To solve this problem, we have to invert PL061State->data at least once to trigger IRQ inside VM. Two solutions:
S1: "Pulse"
static void virt_powerdown_req(Notifier *n, void *opaque)
{
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);
}S2: "Invert"
static int old_gpio_level = 0;
static void virt_powerdown_req(Notifier *n, void *opaque)
{
/* use gpio Pin 3 for power button event */
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), !old_gpio_level);
old_gpio_level = !old_gpio_level;
}Both S1 and S2 works for ACPI. But S1 has problem with DT, which is explained below.
=== Why DT fails with S1 ===
DT approach requires both PL061 and gpio-keys to work together. Looking into guest kernel gpio-keys/input code, you will find that it only reacts to both LEVEL-HI and input changes. Here is the code snip from drivers/input/input.c file:
/* auto-repeat bypasses state updates */
if (value == 2) {
disposition = INPUT_PASS_TO_HANDLERS;
break;
}
if (!!test_bit(code, dev->key) != !!value) {
__change_bit(code, dev->key);
disposition = INPUT_PASS_TO_HANDLERS;
}Unless we adds gpio-keys DT property to "autorepeat", the "!!test_bit(code, dev->key) != !!value" is always FALSE with S1. Thus systemd won't receive any input event; and no power-switch will be triggered.
In comparison S2 will work because value is changed very time.
=== Summary ===
1. Cleaning PL061 state is required. That means "[PATCH V2 1/2] ARM:
PL061: Clear PL061 device state after reset" is necessary.
2. S2 is better. To support S2, we needs to change GPIO IRQ polarity to AML_ACTIVE_BOTH in ACPI description.
I attach a small patch in this email. It should work for your DT case. Please test it and let me know your comments.
Thanks,
-Wei
Quoted 1 line
hw/arm/virt-acpi-build.c +1 -1
@@ -326,7 +326,7 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,Aml *aei =aml_resource_template ();/* Pin 3 for power button */ const uint32_t pin_list[1 ] = {3 }; -aml_append (aei,aml_gpio_int (AML_CONSUMER ,AML_EDGE ,AML_ACTIVE_HIGH , +aml_append (aei,aml_gpio_int (AML_CONSUMER ,AML_EDGE ,3 ,AML_EXCLUSIVE ,AML_PULL_UP ,0 , pin_list,1 ,"GPO0" ,NULL ,0 ));aml_append (dev,aml_name_decl ("_AEI" , aei));
hw/arm/virt.c +3 -1
@@ -547,10 +547,12 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic) }static DeviceState *pl061_dev; +static int old_gpio_level =0 ;static void virt_powerdown_req (Notifier *n,void *opaque) {/* use gpio Pin 3 for power button event */ -qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ),1 ); +qemu_set_irq (qdev_get_gpio_in (pl061_dev,3 ), !old_gpio_level); + old_gpio_level = !old_gpio_level; }static Notifier virt_system_powerdown_notifier = {
Hi Wei,
Quoted 62 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Wei Huang
On 02/03/2016 07:44 PM, Shannon Zhao wrote:
<snip>
Quoted 13 lines
Quoted 4 lines
I reversed the order of edge pulling. The state is 1 according to printk inside
gpio_keysdriver. However the reboot still failed with two reboots (1 very early, 1 later).Because to make the input work, it should call
input_eventtwice I think.
input_event(input, type, button->code, 1)means the button pressedinput_event(input, type, button->code, 0)means the button releasedBut We only see guest entering
gpio_keys_gpio_report_eventonce.My original purpose is like below:
Quoted 7 lines
call
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1)to make guest executeinput_event(input, type, button->code, 1)
callqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0)to make guest executeinput_event(input, type, button->code, 0).But even though it calls
qemu_set_irqtwice, it only callspl061_updateonce in qemu.Hi Shannon,
Assuming that we are talking about the special case you found (i.e. send reboot very early and then send another one after guest VM fully booted). Dug into the code further, here are my findings:
=== Why ACPI case failed? ===
QEMUpl061.cchecks the current request against the new request (sees->old_in_data^s->datainpl061.cfile). If no change, nothing will happen.So two consecutive reboots will cause the following state change; apparently the second request won't trigger VM reboot because
pl01_update()decides _not_ to inject IRQ into guest VM.(PL061State fields) data old_in_data istate VM boot 0 0 0 1st ACPI reboot request 8 0 0 After VM PL061 driver ACK 8 8 0 2nd ACPI reboot request 8 no-change, no IRQ <==To solve this problem, we have to invert
PL061State->dataat least once to trigger IRQ inside VM. Two solutions:S1: "Pulse"
static voidvirt_powerdown_req(Notifier *n, void *opaque){ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0); qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1); }
Quoted 9 lines
S2: "Invert"
static intold_gpio_level= 0;
static voidvirt_powerdown_req(Notifier *n, void *opaque){ /* use gpio Pin 3 for power button event */ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), !old_gpio_level); old_gpio_level = !old_gpio_level; }
The S2 still doesn't work. After sending the early first reboot, whne guest boots well, it doesn't react to the second reboot while it reacts to the third one.
Quoted 25 lines
Both S1 and S2 works for ACPI. But S1 has problem with DT, which is explained below.
=== Why DT fails with S1 ===
DT approach requires both PL061 and gpio-keys to work together. Looking into guest kernel gpio-keys/input code, you will find that it only reacts to both LEVEL-HI and input changes. Here is the code snip fromdrivers/input/input.cfile:/* auto-repeat bypasses state updates */ if (value == 2) { disposition = INPUT_PASS_TO_HANDLERS; break; } if (!!test_bit(code, dev->key) != !!value) { __change_bit(code, dev->key); disposition = INPUT_PASS_TO_HANDLERS; }Unless we adds gpio-keys DT property to "autorepeat", the "!!test_bit(code,
dev->key) != !!value" is always FALSE with S1. Thus systemd won't receive any input event; and no power-switch will be triggered.
Quoted 8 lines
In comparison S2 will work because value is changed very time.
=== Summary ===
1. Cleaning PL061 state is required. That means "[PATCH V2 1/2] ARM:
PL061: Clear PL061 device state after reset" is necessary.
2. S2 is better. To support S2, we needs to change GPIO IRQ polarity toAML_ACTIVE_BOTHin ACPI description.
Thanks. But we don't have the AML_ACTIVE_BOTH since there is only one bit for "Interrupt Polarity" in ACPI table.
See ACPI SPEC 6.0 "Table 6-216 Extended Interrupt Descriptor Definition" Bit [2] Interrupt Polarity, _LL
0 Active-High: This interrupt is sampled when the signal is high, or true.
1 Active-Low: This interrupt is sampled when the signal is low, or false.
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap, · line 329
Quoted 8 lines
hw/arm/virt-acpi-build.c +1
-1@@ -326,7 +326,7 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,Aml *aei =aml_resource_template ();/* Pin 3 for power button */ const uint32_t pin_list[1 ] = {3 }; - aml_append(aei, aml_gpio_int(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH, + aml_append(aei, aml_gpio_int(AML_CONSUMER, AML_EDGE, 3,
What's the meaning of 3 here?
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap, · line 332
Quoted 3 lines
hw/arm/virt-acpi-build.c +0
-0AML_EXCLUSIVE ,AML_PULL_UP ,0 , pin_list,1 , "GPO0", NULL, 0));aml_append (dev,aml_name_decl ("_AEI" , aei));
Thanks,
Signature · 1 line
Shannon
Quoted 74 lines · Shannon Zhao
Hi Wei,
Quoted 62 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Wei Huang
On 02/03/2016 07:44 PM, Shannon Zhao wrote:
<snip>
Quoted 13 lines
Quoted 4 lines
I reversed the order of edge pulling. The state is 1 according to printk inside
gpio_keysdriver. However the reboot still failed with two reboots (1 very early, 1 later).Because to make the input work, it should call
input_eventtwice I think.
input_event(input, type, button->code, 1)means the button pressedinput_event(input, type, button->code, 0)means the button releasedBut We only see guest entering
gpio_keys_gpio_report_eventonce.My original purpose is like below:
Quoted 7 lines
call
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1)to make guest executeinput_event(input, type, button->code, 1)
callqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0)to make guest executeinput_event(input, type, button->code, 0).But even though it calls
qemu_set_irqtwice, it only callspl061_updateonce in qemu.Hi Shannon,
Assuming that we are talking about the special case you found (i.e. send reboot very early and then send another one after guest VM fully booted). Dug into the code further, here are my findings:
=== Why ACPI case failed? ===
QEMUpl061.cchecks the current request against the new request (sees->old_in_data^s->datainpl061.cfile). If no change, nothing will happen.So two consecutive reboots will cause the following state change; apparently the second request won't trigger VM reboot because
pl01_update()decides _not_ to inject IRQ into guest VM.(PL061State fields) data old_in_data istate VM boot 0 0 0 1st ACPI reboot request 8 0 0 After VM PL061 driver ACK 8 8 0 2nd ACPI reboot request 8 no-change, no IRQ <==To solve this problem, we have to invert
PL061State->dataat least once to trigger IRQ inside VM. Two solutions:S1: "Pulse"
static voidvirt_powerdown_req(Notifier *n, void *opaque){ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0); qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1); }Quoted 9 lines
S2: "Invert"
static intold_gpio_level= 0;
static voidvirt_powerdown_req(Notifier *n, void *opaque){ /* use gpio Pin 3 for power button event */ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), !old_gpio_level); old_gpio_level = !old_gpio_level; }
Quoted 3 lines
The S2 still doesn't work. After sending the early first reboot, whne guest boots well, it doesn't react to the second reboot while it reacts to the third one.
I can reproduce it. The problem is that gpio-keys only handles GPIO_ACTIVE_LOW or GPIO_ACTIVE_HIGH. It can't react to ACTIVE_BOTH. That explains why it reacts to the 3rd request: HIGH (ingored, too early, keyboard driver not loaded) ==> LOW (ignored, ACTIVE_HIGH only) ==> HIGH (received).
This problem is full of dilemma, across different components in QEMU or guest VM:
* For qemu/pl011.c to generate IRQ, we need to have level transition. That means qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1) in virt_powerdown_req() isn't enough.
* If we do "invert" (i.e. S2 above), gpio-keys inside VM isn't happy with it.
* If we do pulse (i.e. S1 above), DT fails because of the reason explained below. Plus the GPIO seems to receive the same state due to non-preemptive (you mentioned it long time ago).
Not sure what to do next. Some wild ideas can be:
1) set up a worker thread to pull down GPIO after a fix time. This emulates real world scenario.
2) enable PL061 to support auto-ACK after receiving ACK from guest VM.
Thanks,
-Wei
Quoted 62 lines
Quoted 26 lines
Both S1 and S2 works for ACPI. But S1 has problem with DT, which is explained below.
=== Why DT fails with S1 ===
DT approach requires both PL061 and gpio-keys to work together. Looking into guest kernel gpio-keys/input code, you will find that it only reacts to both LEVEL-HI and input changes. Here is the code snip fromdrivers/input/input.cfile:/* auto-repeat bypasses state updates */ if (value == 2) { disposition = INPUT_PASS_TO_HANDLERS; break; } if (!!test_bit(code, dev->key) != !!value) { __change_bit(code, dev->key); disposition = INPUT_PASS_TO_HANDLERS; }Unless we adds gpio-keys DT property to "autorepeat", the "!!test_bit(code,
dev->key) != !!value" is always FALSE with S1. Thus systemd won't receive any input event; and no power-switch will be triggered.Quoted 8 lines
In comparison S2 will work because value is changed very time.
=== Summary ===
1. Cleaning PL061 state is required. That means "[PATCH V2 1/2] ARM:
PL061: Clear PL061 device state after reset" is necessary.
2. S2 is better. To support S2, we needs to change GPIO IRQ polarity toAML_ACTIVE_BOTHin ACPI description.Thanks. But we don't have the
AML_ACTIVE_BOTHsince there is only one bit for "Interrupt Polarity" in ACPI table.
See ACPI SPEC 6.0 "Table 6-216 Extended Interrupt Descriptor Definition" Bit [2] Interrupt Polarity,_LL
0 Active-High: This interrupt is sampled when the signal is high, or true.
1 Active-Low: This interrupt is sampled when the signal is low, or false.hw/arm/virt-acpi-build.c static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap, · line 329
Quoted 8 lines
hw/arm/virt-acpi-build.c +1
-1@@ -326,7 +326,7 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,Aml *aei =aml_resource_template ();/* Pin 3 for power button */ const uint32_t pin_list[1 ] = {3 }; - aml_append(aei, aml_gpio_int(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH, + aml_append(aei, aml_gpio_int(AML_CONSUMER, AML_EDGE, 3,What's the meaning of 3 here?
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap, · line 332
Quoted 3 lines
hw/arm/virt-acpi-build.c +0
-0AML_EXCLUSIVE ,AML_PULL_UP ,0 , pin_list,1 , "GPO0", NULL, 0));aml_append (dev,aml_name_decl ("_AEI" , aei));Thanks,
Quoted 99 lines · Wei Huang
Quoted 74 lines · Shannon Zhao
Hi Wei,
Quoted 62 lines · Wei Huang
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Wei Huang
On 02/03/2016 07:44 PM, Shannon Zhao wrote:
<snip>
Quoted 13 lines
Quoted 4 lines
I reversed the order of edge pulling. The state is 1 according to printk inside
gpio_keysdriver. However the reboot still failed with two reboots (1 very early, 1 later).Because to make the input work, it should call
input_eventtwice I think.
input_event(input, type, button->code, 1)means the button pressedinput_event(input, type, button->code, 0)means the button releasedBut We only see guest entering
gpio_keys_gpio_report_eventonce.My original purpose is like below:
Quoted 7 lines
call
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1)to make guest executeinput_event(input, type, button->code, 1)
callqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0)to make guest executeinput_event(input, type, button->code, 0).But even though it calls
qemu_set_irqtwice, it only callspl061_updateonce in qemu.Hi Shannon,
Assuming that we are talking about the special case you found (i.e. send reboot very early and then send another one after guest VM fully booted). Dug into the code further, here are my findings:
=== Why ACPI case failed? ===
QEMUpl061.cchecks the current request against the new request (sees->old_in_data^s->datainpl061.cfile). If no change, nothing will happen.So two consecutive reboots will cause the following state change; apparently the second request won't trigger VM reboot because
pl01_update()decides _not_ to inject IRQ into guest VM.(PL061State fields) data old_in_data istate VM boot 0 0 0 1st ACPI reboot request 8 0 0 After VM PL061 driver ACK 8 8 0 2nd ACPI reboot request 8 no-change, no IRQ <==To solve this problem, we have to invert
PL061State->dataat least once to trigger IRQ inside VM. Two solutions:S1: "Pulse"
static voidvirt_powerdown_req(Notifier *n, void *opaque){ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0); qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1); }Quoted 9 lines
S2: "Invert"
static intold_gpio_level= 0;
static voidvirt_powerdown_req(Notifier *n, void *opaque){ /* use gpio Pin 3 for power button event */ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), !old_gpio_level); old_gpio_level = !old_gpio_level; }Quoted 3 lines
The S2 still doesn't work. After sending the early first reboot, whne guest boots well, it doesn't react to the second reboot while it reacts to the third one.
I can reproduce it. The problem is that gpio-keys only handles
GPIO_ACTIVE_LOWorGPIO_ACTIVE_HIGH. It can't react toACTIVE_BOTH. That explains why it reacts to the 3rd request: HIGH (ingored, too early, keyboard driver not loaded) ==> LOW (ignored,ACTIVE_HIGHonly) ==> HIGH (received).This problem is full of dilemma, across different components in QEMU or guest VM:
* For
qemu/pl011.cto generate IRQ, we need to have level transition. That meansqemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1)invirt_powerdown_req()isn't enough.
* If we do "invert" (i.e. S2 above), gpio-keys inside VM isn't happy with it.
* If we do pulse (i.e. S1 above), DT fails because of the reason explained below. Plus the GPIO seems to receive the same state due to non-preemptive (you mentioned it long time ago).
Quoted 3 lines
Not sure what to do next. Some wild ideas can be:
1) set up a worker thread to pull down GPIO after a fix time. This emulates real world scenario.
Yeah, right! But other than a worker thread, I'd like to use a timer. Then set a latency between pull up and down like we press a button in real world.
So how about below patch? I've tested it and it works both for ACPI and DT. Could you help verify if it works for you? Thanks.
hw/arm/virt.c +0 -0
@@ -558,11 +558,20 @@ static void create_rtc(const VirtBoardInfo *vbi,
qemu_irq *pic)
g_free(nodename);
}
+#define GPIO_KEY_LATENCY 500 /* 500ms */
static DeviceState *pl061_dev;
+static QEMUTimer *gpio_key_timer;
+static void gpio_key_timer_expired(void *vp)
+{
+ qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 0);
+}
+
static void virt_powerdown_req(Notifier *n, void *opaque)
{
/* use gpio Pin 3 for power button event */
qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1);+ timer_mod(gpio_key_timer,
+ qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + GPIO_KEY_LATENCY);
}
static Notifier virt_system_powerdown_notifier = {
@@ -609,6 +618,8 @@ static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic)
/* connect powerdown request */
qemu_register_powerdown_notifier(&virt_system_powerdown_notifier);+ gpio_key_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,gpio_key_timer_expired,
+ NULL);
g_free(nodename);
}
Thanks,
Signature · 1 line
Shannon
hw/arm/virt.c static void create_rtc(const VirtBoardInfo *vbi, · line 562
Quoted 13 lines · Shannon Zhao
So how about below patch? I've tested it and it works both for ACPI and DT. Could you help verify if it works for you? Thanks.
hw/arm/virt.c +1
-0@@ -558,11 +558,20 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic)g_free (nodename ); } +#define GPIO_KEY_LATENCY 500/* 500ms */
I don't understand why a 500ms pulse is better than a short one.
hw/arm/virt.c static void create_rtc(const VirtBoardInfo *vbi, · line 563
Quoted 1 line
hw/arm/virt.c +1
-0+static QEMUTimer *gpio_key_timer;
This is state, and must be migrated somehow.
thanks
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Shannon Zhao
So how about below patch? I've tested it and it works both for ACPI and DT. Could you help verify if it works for you? Thanks.
hw/arm/virt.c +0
-0@@ -558,11 +558,20 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic)g_free (nodename ); }
Quoted 4 lines
hw/arm/virt.c static void create_rtc(const VirtBoardInfo *vbi, · line 562
Quoted 1 line
hw/arm/virt.c +1
-0+#define GPIO_KEY_LATENCY 500/* 500ms */ I don't understand why a 500ms pulse is better than a short one.
Oh, I just pick a value which seems like a real latency for pressing a button. What's your suggestion?
Quoted 4 lines
hw/arm/virt.c static void create_rtc(const VirtBoardInfo *vbi, · line 563
Quoted 1 line
hw/arm/virt.c +1
-0+static QEMUTimer *gpio_key_timer;This is state, and must be migrated somehow.
Ah, yes. So is it fine if we move this timer and the notifier virt_system_powerdown_notifier to VirtMachineState?
Thanks,
Signature · 1 line
Shannon
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Peter Maydell
I don't understand why a 500ms pulse is better than a short one.
Oh, I just pick a value which seems like a real latency for pressing a button. What's your suggestion?
I would prefer to avoid the pain of having a timer whose state needs to be migrated. It's unclear to me why a 500ms pulse will solve anything that an instantaneous pulse does not, so I'd like to better understand the problem first.
thanks
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Peter Maydell
I don't understand why a 500ms pulse is better than a short one.
Oh, I just pick a value which seems like a real latency for pressing a button. What's your suggestion?
I would prefer to avoid the pain of having a timer whose state needs to be migrated. It's unclear to me why a 500ms pulse will solve anything that an instantaneous pulse does not, so I'd like to better understand the problem first.
The problem we found with pulse was: only the last state change in GPIO is received by guest VM. In other words, with 0(L)->1(H)->0(L) or 1(H)->0(L)->1(0), PL061 only sees the last state (0 and 1). I guess this is because QEMU is non-preemptive. The solution is to have the following steps:
* qemu_set_irq(gpio_in, 1)
* yeild to guest VM
* qemu_set_irq(gpio_in, 0)
Is there any way to do so in QEMU without using timer?
Quoted 4 lines
thanks
-- PMM
Quoted 24 lines · Wei Huang
Quoted 11 lines · Peter Maydell
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Peter Maydell
I don't understand why a 500ms pulse is better than a short one.
Oh, I just pick a value which seems like a real latency for pressing a button. What's your suggestion?
I would prefer to avoid the pain of having a timer whose state needs to be migrated. It's unclear to me why a 500ms pulse will solve anything that an instantaneous pulse does not, so I'd like to better understand the problem first.
The problem we found with pulse was: only the last state change in GPIO is received by guest VM. In other words, with 0(L)->1(H)->0(L) or 1(H)->0(L)->1(0), PL061 only sees the last state (0 and 1). I guess this is because QEMU is non-preemptive. The solution is to have the following steps:
*qemu_set_irq(gpio_in, 1)
* yeild to guest VM
*qemu_set_irq(gpio_in, 0)
Quoted 1 line
Is there any way to do so in QEMU without using timer?
You have no guarantee that the guest VM will necessarily make any progress even with a 500ms pulse length, so I don't think increasing the length of the pulse is going to solidly fix this.
As usual with any kind of interrupt you either need to trigger on an edge (and latch the trigger in the interrupt controller until the guest picks it up), or trigger on a level, and keep the level high until the guest acknowledges by writing back to the original device to tell it to drop the level.
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Wei Huang
Quoted 11 lines · Peter Maydell
Quoted 5 lines · Shannon Zhao
Quoted 2 lines · Peter Maydell
I don't understand why a 500ms pulse is better than a short one.
Oh, I just pick a value which seems like a real latency for pressing a button. What's your suggestion?
I would prefer to avoid the pain of having a timer whose state needs to be migrated. It's unclear to me why a 500ms pulse will solve anything that an instantaneous pulse does not, so I'd like to better understand the problem first.
The problem we found with pulse was: only the last state change in GPIO is received by guest VM. In other words, with 0(L)->1(H)->0(L) or 1(H)->0(L)->1(0), PL061 only sees the last state (0 and 1). I guess this is because QEMU is non-preemptive. The solution is to have the following steps:
*qemu_set_irq(gpio_in, 1)
* yeild to guest VM
*qemu_set_irq(gpio_in, 0)
Quoted 4 lines
Quoted 1 line
Is there any way to do so in QEMU without using timer?
You have no guarantee that the guest VM will necessarily make any progress even with a 500ms pulse length,
Yeah, if the guest is very busy! But it's true in the real world like that we press a GPIO_KEY button, but guest is too busy that it can't react to this then the guest can't shutdown.
Quoted 4 lines
so I don't
think increasing the length of the pulse is going to solidly fix this.
This is not simply increasing the length. It just makes the guest not blocked after the first qemu_set_irq so that the guest can detect the button is pressed(i.e. get the value 1). Then after any time, call the second qemu_set_irq then guest can detect the button is released.
You must be aware that here the purpose of qemu_set_irq is only to set the value of gpio pin not directly set the interrupt controller. As for injecting the interrupt, it's what the PL061 device does which detects the pin value changed.
And for GPIO_KEY, it must detect 1 and 0 then it realizes it as a valid input.
Have a look at the below function in drivers/input/keyboard/gpio_keys.c.
static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
{
const struct gpio_keys_button *button = bdata->button;
struct input_dev *input = bdata->input;
unsigned int type = button->type ?: EV_KEY;
int state = (gpio_get_value_cansleep(button->gpio) ? 1 : 0) ^button->active_low;
if (type == EV_ABS) {
if (state)
input_event(input, type, button->code, button->value);
} else {
input_event(input, type, button->code, !!state);
}
input_sync(input);
}Quoted 7 lines
As usual with any kind of interrupt you either need to trigger on an edge (and latch the trigger in the interrupt controller until the guest picks it up), or trigger on a level, and keep the level high until the guest acknowledges by writing back to the original device to tell it to drop the level.
As said, here we only want change the some pin value and want guest to get the value. The interrupt is triggered by PL061 device which just notifies the guest that pin value is changed, please read.
Thanks,
Signature · 1 line
Shannon