From patchwork Mon Feb 1 17:20:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 8181541 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9C1F2BEEE5 for ; Mon, 1 Feb 2016 17:21:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05866203A1 for ; Mon, 1 Feb 2016 17:21:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50C3F20115 for ; Mon, 1 Feb 2016 17:21:11 +0000 (UTC) Received: from localhost ([::1]:53480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQIA2-0005pj-O9 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 01 Feb 2016 12:21:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQI95-0004f4-T3 for qemu-devel@nongnu.org; Mon, 01 Feb 2016 12:20:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQI92-0002nw-MF for qemu-devel@nongnu.org; Mon, 01 Feb 2016 12:20:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQI92-0002nj-HF; Mon, 01 Feb 2016 12:20:08 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 9E5F77AE88; Mon, 1 Feb 2016 17:20:07 +0000 (UTC) Received: from apm-mustang-ev3-33.khw.lab.eng.bos.redhat.com (apm-mustang-ev3-33.khw.lab.eng.bos.redhat.com [10.16.184.127]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u11HK6Q4013069; Mon, 1 Feb 2016 12:20:06 -0500 From: Wei Huang To: qemu-devel@nongnu.org Date: Mon, 1 Feb 2016 12:20:05 -0500 Message-Id: <1454347206-23717-1-git-send-email-wei@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-trivial@nongnu.org, peter.maydell@linaro.org, imammedo@redhat.com, shannon.zhao@linaro.org, zhaoshenglong@huawei.com Subject: [Qemu-devel] [PATCH 1/2] ARM: PL061: Clear PL061 device state after reset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current QEMU doesn't clear PL061 state after reset. This causes a weird issue with guest reboot via GPIO. Here is the device state description with two reboot requests: (PL061State fields) data old_in_data istate VM boot 0 0 0 After 1st ACPI reboot request 8 8 8 After VM PL061 driver ACK 8 8 0 After VM reboot 8 8 0 ------------------------------------------------------------ 2nd ACPI reboot request 8 In the second reboot request above, because old_in_data field is 8, QEMU decides that there is a pending edge IRQ already (see pl061_update()) in input; so it doesn't raise up IRQ again. As a result the second reboot request is lost. The correct way is to clear PL061 device state after reset. NOTE: The reset state is found from the following documentation: - PL061 Technical Reference Manual - Stellaris LM3S8962 Microcontroller Data Sheet - Stellaris LM3S5P31 Microcontroller Data Sheet Signed-off-by: Wei Huang --- hw/gpio/pl061.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c index e5a696e..342a70d 100644 --- a/hw/gpio/pl061.c +++ b/hw/gpio/pl061.c @@ -284,8 +284,35 @@ static void pl061_write(void *opaque, hwaddr offset, static void pl061_reset(PL061State *s) { - s->locked = 1; - s->cr = 0xff; + /* reset values from PL061 TRM, Stellaris LM3S5P31 & LM3S8962 Data Sheet */ + s->data = 0; + s->old_out_data = 0; + s->old_in_data = 0; + s->dir = 0; + s->isense = 0; + s->ibe = 0; + s->iev = 0; + s->im = 0; + s->istate = 0; + s->afsel = 0; + s->dr2r = 0xff; + s->dr4r = 0; + s->dr8r = 0; + s->odr = 0; + s->pur = 0; + s->pdr = 0; + s->slr = 0; + s->den = 0; + s->locked = 1; + s->cr = 0xff; + s->amsel = 0; +} + +static void pl061_state_reset(DeviceState *dev) +{ + PL061State *s = PL061(dev); + + pl061_reset(s); } static void pl061_set_irq(void * opaque, int irq, int level) @@ -343,6 +370,7 @@ static void pl061_class_init(ObjectClass *klass, void *data) k->init = pl061_initfn; dc->vmsd = &vmstate_pl061; + dc->reset = &pl061_state_reset; } static const TypeInfo pl061_info = {