* [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button
@ 2016-03-17 13:25 Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 1/2] hw/gpio: Add the emulation of gpio_key Shannon Zhao
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Shannon Zhao @ 2016-03-17 13:25 UTC (permalink / raw)
To: qemu-arm, peter.maydell, wei
Cc: peter.huangpeng, zhaoshenglong, qemu-devel, shannon.zhao
From: Shannon Zhao <shannon.zhao@linaro.org>
There is a problem for power button that it will not work if an early
system_powerdown request happens before guest gpio driver loads.
Here we add the emulation of gpio_key and use it for ARM virt power
button.
Shannon Zhao (2):
hw/gpio: Add the emulation of gpio_key
ARM: Virt: Use gpio_key for power button
default-configs/arm-softmmu.mak | 1 +
hw/arm/virt.c | 7 ++-
hw/gpio/Makefile.objs | 1 +
hw/gpio/gpio_key.c | 100 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 107 insertions(+), 2 deletions(-)
create mode 100644 hw/gpio/gpio_key.c
--
2.0.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 1/2] hw/gpio: Add the emulation of gpio_key
2016-03-17 13:25 [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button Shannon Zhao
@ 2016-03-17 13:25 ` Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 2/2] ARM: Virt: Use gpio_key for power button Shannon Zhao
2016-03-23 16:12 ` [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt " Peter Maydell
2 siblings, 0 replies; 8+ messages in thread
From: Shannon Zhao @ 2016-03-17 13:25 UTC (permalink / raw)
To: qemu-arm, peter.maydell, wei
Cc: peter.huangpeng, zhaoshenglong, qemu-devel, shannon.zhao
From: Shannon Zhao <shannon.zhao@linaro.org>
This will be used by ARM virt machine as a power button.
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
default-configs/arm-softmmu.mak | 1 +
hw/gpio/Makefile.objs | 1 +
hw/gpio/gpio_key.c | 100 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 102 insertions(+)
create mode 100644 hw/gpio/gpio_key.c
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 2bcd236..c63cdd0 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -111,3 +111,4 @@ CONFIG_I82801B11=y
CONFIG_ACPI=y
CONFIG_SMBIOS=y
CONFIG_ASPEED_SOC=y
+CONFIG_GPIO_KEY=y
diff --git a/hw/gpio/Makefile.objs b/hw/gpio/Makefile.objs
index 52233f7..a43c7cf 100644
--- a/hw/gpio/Makefile.objs
+++ b/hw/gpio/Makefile.objs
@@ -3,6 +3,7 @@ common-obj-$(CONFIG_PL061) += pl061.o
common-obj-$(CONFIG_PUV3) += puv3_gpio.o
common-obj-$(CONFIG_ZAURUS) += zaurus.o
common-obj-$(CONFIG_E500) += mpc8xxx.o
+common-obj-$(CONFIG_GPIO_KEY) += gpio_key.o
obj-$(CONFIG_OMAP) += omap_gpio.o
obj-$(CONFIG_IMX) += imx_gpio.o
diff --git a/hw/gpio/gpio_key.c b/hw/gpio/gpio_key.c
new file mode 100644
index 0000000..41639fa
--- /dev/null
+++ b/hw/gpio/gpio_key.c
@@ -0,0 +1,100 @@
+/*
+ * GPIO key
+ *
+ * Copyright (c) 2016 Linaro Limited
+ *
+ * Author: Shannon Zhao <shannon.zhao@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+
+#define TYPE_GPIOKEY "gpio_key"
+#define GPIOKEY(obj) OBJECT_CHECK(GPIOKEYState, (obj), TYPE_GPIOKEY)
+#define GPIO_KEY_LATENCY 100 /* 100ms */
+
+typedef struct GPIOKEYState {
+ SysBusDevice parent_obj;
+
+ QEMUTimer *timer;
+ qemu_irq irq;
+} GPIOKEYState;
+
+static const VMStateDescription vmstate_gpio_key = {
+ .name = "gpio_key",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_TIMER_PTR(timer, GPIOKEYState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static void gpio_key_reset(DeviceState *dev)
+{
+ GPIOKEYState *s = GPIOKEY(dev);
+
+ timer_del(s->timer);
+}
+
+static void gpio_key_timer_expired(void *opaque)
+{
+ GPIOKEYState *s = (GPIOKEYState *)opaque;
+
+ qemu_set_irq(s->irq, 0);
+ timer_del(s->timer);
+}
+
+static void gpio_key_set_irq(void *opaque, int irq, int level)
+{
+ GPIOKEYState *s = (GPIOKEYState *)opaque;
+
+ qemu_set_irq(s->irq, 1);
+ timer_mod(s->timer,
+ qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + GPIO_KEY_LATENCY);
+}
+
+static void gpio_key_realize(DeviceState *dev, Error **errp)
+{
+ GPIOKEYState *s = GPIOKEY(dev);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+
+ sysbus_init_irq(sbd, &s->irq);
+ qdev_init_gpio_in(dev, gpio_key_set_irq, 1);
+ s->timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, gpio_key_timer_expired, s);
+}
+
+static void gpio_key_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->realize = gpio_key_realize;
+ dc->vmsd = &vmstate_gpio_key;
+ dc->reset = &gpio_key_reset;
+}
+
+static const TypeInfo gpio_key_info = {
+ .name = TYPE_GPIOKEY,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(GPIOKEYState),
+ .class_init = gpio_key_class_init,
+};
+
+static void gpio_key_register_types(void)
+{
+ type_register_static(&gpio_key_info);
+}
+
+type_init(gpio_key_register_types)
--
2.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 2/2] ARM: Virt: Use gpio_key for power button
2016-03-17 13:25 [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 1/2] hw/gpio: Add the emulation of gpio_key Shannon Zhao
@ 2016-03-17 13:25 ` Shannon Zhao
2016-03-23 16:12 ` [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt " Peter Maydell
2 siblings, 0 replies; 8+ messages in thread
From: Shannon Zhao @ 2016-03-17 13:25 UTC (permalink / raw)
To: qemu-arm, peter.maydell, wei
Cc: peter.huangpeng, zhaoshenglong, qemu-devel, shannon.zhao
From: Shannon Zhao <shannon.zhao@linaro.org>
There is a problem for power button that it will not work if an early
system_powerdown request happens before guest gpio driver loads.
Fix this problem by using gpio_key.
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
hw/arm/virt.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 95331a5..10e385d 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -581,11 +581,11 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic)
g_free(nodename);
}
-static DeviceState *pl061_dev;
+static DeviceState *gpio_key_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_set_irq(qdev_get_gpio_in(gpio_key_dev, 0), 1);
}
static Notifier virt_system_powerdown_notifier = {
@@ -595,6 +595,7 @@ static Notifier virt_system_powerdown_notifier = {
static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic)
{
char *nodename;
+ DeviceState *pl061_dev;
hwaddr base = vbi->memmap[VIRT_GPIO].base;
hwaddr size = vbi->memmap[VIRT_GPIO].size;
int irq = vbi->irqmap[VIRT_GPIO];
@@ -617,6 +618,8 @@ static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic)
qemu_fdt_setprop_string(vbi->fdt, nodename, "clock-names", "apb_pclk");
qemu_fdt_setprop_cell(vbi->fdt, nodename, "phandle", phandle);
+ gpio_key_dev = sysbus_create_simple("gpio_key", -1,
+ qdev_get_gpio_in(pl061_dev, 3));
qemu_fdt_add_subnode(vbi->fdt, "/gpio-keys");
qemu_fdt_setprop_string(vbi->fdt, "/gpio-keys", "compatible", "gpio-keys");
qemu_fdt_setprop_cell(vbi->fdt, "/gpio-keys", "#size-cells", 0);
--
2.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button
2016-03-17 13:25 [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 1/2] hw/gpio: Add the emulation of gpio_key Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 2/2] ARM: Virt: Use gpio_key for power button Shannon Zhao
@ 2016-03-23 16:12 ` Peter Maydell
2016-03-23 17:14 ` Wei Huang
2016-04-06 17:50 ` Emilio G. Cota
2 siblings, 2 replies; 8+ messages in thread
From: Peter Maydell @ 2016-03-23 16:12 UTC (permalink / raw)
To: Shannon Zhao
Cc: Wei Huang, Huangpeng (Peter), qemu-arm, QEMU Developers, Shannon Zhao
On 17 March 2016 at 13:25, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
>
> There is a problem for power button that it will not work if an early
> system_powerdown request happens before guest gpio driver loads.
>
> Here we add the emulation of gpio_key and use it for ARM virt power
> button.
I tweaked the type names to be 'gpio-key' rather than 'gpio_key',
and added a comment to briefly describe what the device does:
+ * Emulate a (human) keypress -- when the key is triggered by
+ * setting the incoming gpio line, the outbound irq line is
+ * raised for 100ms before being dropped again.
Applied to target-arm.next, thanks.
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button
2016-03-23 16:12 ` [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt " Peter Maydell
@ 2016-03-23 17:14 ` Wei Huang
2016-03-24 0:58 ` Shannon Zhao
2016-04-06 17:50 ` Emilio G. Cota
1 sibling, 1 reply; 8+ messages in thread
From: Wei Huang @ 2016-03-23 17:14 UTC (permalink / raw)
To: Peter Maydell, Shannon Zhao
Cc: Huangpeng (Peter), qemu-arm, QEMU Developers, Shannon Zhao
On 03/23/2016 11:12 AM, Peter Maydell wrote:
> On 17 March 2016 at 13:25, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>
>> There is a problem for power button that it will not work if an early
>> system_powerdown request happens before guest gpio driver loads.
>>
>> Here we add the emulation of gpio_key and use it for ARM virt power
>> button.
>
> I tweaked the type names to be 'gpio-key' rather than 'gpio_key',
> and added a comment to briefly describe what the device does:
>
> + * Emulate a (human) keypress -- when the key is triggered by
> + * setting the incoming gpio line, the outbound irq line is
> + * raised for 100ms before being dropped again.
>
> Applied to target-arm.next, thanks.
I didn't see the patch series until yesterday. So just to make it
complete, I did test it with both DT and ACPI modes. The patch seemed to
work as intended.
Tested-by: Wei Huang <wei@redhat.com>
Thanks,
-Wei
>
> -- PMM
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button
2016-03-23 17:14 ` Wei Huang
@ 2016-03-24 0:58 ` Shannon Zhao
0 siblings, 0 replies; 8+ messages in thread
From: Shannon Zhao @ 2016-03-24 0:58 UTC (permalink / raw)
To: Wei Huang, Peter Maydell
Cc: Huangpeng (Peter), qemu-arm, QEMU Developers, Shannon Zhao
On 2016/3/24 1:14, Wei Huang wrote:
>
> On 03/23/2016 11:12 AM, Peter Maydell wrote:
>> > On 17 March 2016 at 13:25, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
>>> >> From: Shannon Zhao <shannon.zhao@linaro.org>
>>> >>
>>> >> There is a problem for power button that it will not work if an early
>>> >> system_powerdown request happens before guest gpio driver loads.
>>> >>
>>> >> Here we add the emulation of gpio_key and use it for ARM virt power
>>> >> button.
>> >
>> > I tweaked the type names to be 'gpio-key' rather than 'gpio_key',
>> > and added a comment to briefly describe what the device does:
>> >
>> > + * Emulate a (human) keypress -- when the key is triggered by
>> > + * setting the incoming gpio line, the outbound irq line is
>> > + * raised for 100ms before being dropped again.
>> >
Great. Thanks a lot!
>> > Applied to target-arm.next, thanks.
> I didn't see the patch series until yesterday. So just to make it
> complete, I did test it with both DT and ACPI modes. The patch seemed to
> work as intended.
>
> Tested-by: Wei Huang <wei@redhat.com>
Thanks, Wei!
--
Shannon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button
2016-03-23 16:12 ` [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt " Peter Maydell
2016-03-23 17:14 ` Wei Huang
@ 2016-04-06 17:50 ` Emilio G. Cota
2016-04-06 19:27 ` Peter Maydell
1 sibling, 1 reply; 8+ messages in thread
From: Emilio G. Cota @ 2016-04-06 17:50 UTC (permalink / raw)
To: Peter Maydell
Cc: Wei Huang, QEMU Developers, Huangpeng (Peter),
qemu-arm, Shannon Zhao, Shannon Zhao
On Wed, Mar 23, 2016 at 16:12:46 +0000, Peter Maydell wrote:
> On 17 March 2016 at 13:25, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
> > From: Shannon Zhao <shannon.zhao@linaro.org>
> >
> > There is a problem for power button that it will not work if an early
> > system_powerdown request happens before guest gpio driver loads.
> >
> > Here we add the emulation of gpio_key and use it for ARM virt power
> > button.
>
> I tweaked the type names to be 'gpio-key' rather than 'gpio_key',
> and added a comment to briefly describe what the device does:
>
> + * Emulate a (human) keypress -- when the key is triggered by
> + * setting the incoming gpio line, the outbound irq line is
> + * raised for 100ms before being dropped again.
>
> Applied to target-arm.next, thanks.
I might be doing something wrong, but aarch64-softmmu @ master only works for me
after reverting 94f02c5ea94 "ARM: Virt: Use gpio_key for power button". Bisect log
appended.
This is what I get when booting aarch64 as per [1]:
$ aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt \
-nographic -smp 1 -m 2048 -kernel img/aarch64/aarch64-linux-3.15rc2-buildroot.img \
--append "console=ttyAMA0"
qemu-system-aarch64: Unknown device 'gpio-key' for default sysbus
Aborted (core dumped)
Thanks,
Emilio
[1] http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/
git bisect start
# good: [4829e0378dfb91d55af9dfd741bd09e8f2c4f91a] Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-03-18' into staging
git bisect good 4829e0378dfb91d55af9dfd741bd09e8f2c4f91a
# bad: [7acbff99c6c285b3070bf0e768d56f511e2bf346] Update version for v2.6.0-rc1 release
git bisect bad 7acbff99c6c285b3070bf0e768d56f511e2bf346
# good: [9fd3c5d556b21e0020d98d4695c84a655aa056f0] tests/test-filter-redirector: Add unit test for filter-redirector
git bisect good 9fd3c5d556b21e0020d98d4695c84a655aa056f0
# bad: [e8710c2293c0f4652090b1434603715f2d9a410f] block: m25p80: Removed unused variable
git bisect bad e8710c2293c0f4652090b1434603715f2d9a410f
# good: [5481531154cf08ed53623a0184f7677a9b98d083] raw: Support BDRV_REQ_FUA
git bisect good 5481531154cf08ed53623a0184f7677a9b98d083
# good: [c98d3d79ee387ea6e8fb091299f8562b20022f10] target-mips: use CP0_CHECK for gen_m{f|t}hc0
git bisect good c98d3d79ee387ea6e8fb091299f8562b20022f10
# good: [f4e732a0a773c4e44c2c183a5d63cd850ffb57d1] iotests: Test qemu-img convert -S 0 behavior
git bisect good f4e732a0a773c4e44c2c183a5d63cd850ffb57d1
# good: [69bc7f5029db5ea55359f7905e9829777ae5a34f] Merge remote-tracking branch 'remotes/berrange/tags/pull-qcrypto-2016-03-30-1' into staging
git bisect good 69bc7f5029db5ea55359f7905e9829777ae5a34f
# good: [489ef4c810033e63af570c8a430af8b9858bfa5f] Merge remote-tracking branch 'remotes/lalrae/tags/mips-20160329-2' into staging
git bisect good 489ef4c810033e63af570c8a430af8b9858bfa5f
# bad: [94f02c5ea9430be935088b2574f72f2dcf902997] ARM: Virt: Use gpio_key for power button
git bisect bad 94f02c5ea9430be935088b2574f72f2dcf902997
# good: [e5a8152c9bfd3d40c37711ba5b704f277cbc0c54] hw/gpio: Add the emulation of gpio_key
git bisect good e5a8152c9bfd3d40c37711ba5b704f277cbc0c54
# first bad commit: [94f02c5ea9430be935088b2574f72f2dcf902997] ARM: Virt: Use gpio_key for power button
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button
2016-04-06 17:50 ` Emilio G. Cota
@ 2016-04-06 19:27 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2016-04-06 19:27 UTC (permalink / raw)
To: Emilio G. Cota
Cc: Wei Huang, QEMU Developers, Huangpeng (Peter),
qemu-arm, Shannon Zhao, Shannon Zhao
On 6 April 2016 at 18:50, Emilio G. Cota <cota@braap.org> wrote:
> I might be doing something wrong, but aarch64-softmmu @ master only works for me
> after reverting 94f02c5ea94 "ARM: Virt: Use gpio_key for power button". Bisect log
> appended.
>
> This is what I get when booting aarch64 as per [1]:
> $ aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt \
> -nographic -smp 1 -m 2048 -kernel img/aarch64/aarch64-linux-3.15rc2-buildroot.img \
> --append "console=ttyAMA0"
>
> qemu-system-aarch64: Unknown device 'gpio-key' for default sysbus
> Aborted (core dumped)
Your tree isn't building right (this is a dependency bug in our
makefiles somewhere) -- it hasn't built the new object file
with the gpio-key device in it, which means a runtime failure
when the device can't be found. You should be able to fix this
by deleting the aarch64-softmmu/config-devices.mak file from
your build tree and then doing a rebuild.
(One day I may get round to figuring out what happens here.
The oddity is that it doesn't cause problems for an
incremental rebuild, only for a build after a 'make clean'.)
thanks
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-04-06 19:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-17 13:25 [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt power button Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 1/2] hw/gpio: Add the emulation of gpio_key Shannon Zhao
2016-03-17 13:25 ` [Qemu-devel] [PATCH 2/2] ARM: Virt: Use gpio_key for power button Shannon Zhao
2016-03-23 16:12 ` [Qemu-devel] [PATCH 0/2] Add gpio_key and use it for ARM virt " Peter Maydell
2016-03-23 17:14 ` Wei Huang
2016-03-24 0:58 ` Shannon Zhao
2016-04-06 17:50 ` Emilio G. Cota
2016-04-06 19:27 ` Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.