From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwPLM-00006J-Mo for qemu-devel@nongnu.org; Wed, 11 Nov 2015 01:57:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwPLJ-0006VF-E0 for qemu-devel@nongnu.org; Wed, 11 Nov 2015 01:57:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54486) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwPLJ-0006VB-7x for qemu-devel@nongnu.org; Wed, 11 Nov 2015 01:57:17 -0500 References: <1446128855-26637-1-git-send-email-shannon.zhao@linaro.org> <1446128855-26637-8-git-send-email-shannon.zhao@linaro.org> From: Wei Huang Message-ID: <5642E6C8.9000200@redhat.com> Date: Wed, 11 Nov 2015 00:57:12 -0600 MIME-Version: 1.0 In-Reply-To: <1446128855-26637-8-git-send-email-shannon.zhao@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 7/8] hw/arm/virt: Add QEMU powerdown notifier and hook it to GPIO Pin 3 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Shannon Zhao , qemu-devel@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, imammedo@redhat.com Cc: peter.huangpeng@huawei.com, zhaoshenglong@huawei.com On 10/29/2015 09:27 AM, Shannon Zhao wrote: > Currently mach-virt model doesn't support powerdown request. Guest VM > doesn't react to system_powerdown from monitor console (or QMP) because > there is no communication mechanism for such requests. This patch registers > GPIO Pin 3 with powerdown notification. So guest VM can receive notification > when such powerdown request is triggered. > > Signed-off-by: Wei Huang > Signed-off-by: Shannon Zhao > Signed-off-by: Shannon Zhao > --- > hw/arm/virt.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > index 5c505a4..6f1b9d6 100644 > --- a/hw/arm/virt.c > +++ b/hw/arm/virt.c > @@ -540,6 +540,18 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic) > g_free(nodename); > } > > +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), 0); > + qemu_set_irq(qdev_get_gpio_in(pl061_dev, 3), 1); This pull-down and then pull-up is for extra safety, right? It actually also works with only pull-up call. But I am OK with your design here; please add additional comments to explain the design. > +} > + > +static Notifier virt_system_powerdown_notifier = { > + .notify = virt_powerdown_req > +}; > + > static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic) > { > char *nodename; > @@ -548,7 +560,7 @@ static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic) > int irq = vbi->irqmap[VIRT_GPIO]; > const char compat[] = "arm,pl061\0arm,primecell"; > > - sysbus_create_simple("pl061", base, pic[irq]); > + pl061_dev = sysbus_create_simple("pl061", base, pic[irq]); > > nodename = g_strdup_printf("/pl061@%" PRIx64, base); > qemu_fdt_add_subnode(vbi->fdt, nodename); > @@ -563,6 +575,9 @@ static void create_gpio(const VirtBoardInfo *vbi, qemu_irq *pic) > qemu_fdt_setprop_cell(vbi->fdt, nodename, "clocks", vbi->clock_phandle); > qemu_fdt_setprop_string(vbi->fdt, nodename, "clock-names", "apb_pclk"); > > + /* connect powerdown request */ > + qemu_register_powerdown_notifier(&virt_system_powerdown_notifier); > + > g_free(nodename); > } > > Reviewed-by: Wei Huang