From patchwork Mon Jul 6 09:59:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 50710 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C8ECE218EA for ; Mon, 6 Jul 2015 10:05:16 +0000 (UTC) Received: by widjy10 with SMTP id jy10sf50174492wid.3 for ; Mon, 06 Jul 2015 03:05:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=LnnoFJBT2+xb39r2EdbHQU/Fqa0/hiYg+8nkRAsP6jg=; b=SMhVKzFa/hkaElEEb3woDuwmEoEN/aevKRDl1qafrPF5XjZiul180xjU7EVMEN7fde iE2M9tf0RdkraYSMa/F9rWRHxtwqDyZmFUAHhcLLvbjgsYL+10tobDHxHk8jCnNf9ZX8 ZXCwkVnyt9SM+VBXooOcQWyFULGVoJxRHcAfz4FlIBHB7mTV0vb6NiVxGctK0FSwUgIu qj9NafsbnbWyxy1rGeSR36akrnsZ7bgC5/6G5PA/5vhiH6af4hHwhbvc6ii2hedkeBGe FFPyAvVbHzppBtV/l40UZ9tb0/KS4iVeIdpNWwpX2nmeGRon6DQdFtCpiXfTf7ZD88wb AKbg== X-Gm-Message-State: ALoCoQmHF6LnGwcu3fddyU57lwazP4dAgO68213rOl1rYkCYROwbK2hhNbHod9FSTtc70WlB+rLs X-Received: by 10.112.160.39 with SMTP id xh7mr3020663lbb.22.1436177115990; Mon, 06 Jul 2015 03:05:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.235 with SMTP id r11ls104325lal.108.gmail; Mon, 06 Jul 2015 03:05:15 -0700 (PDT) X-Received: by 10.112.40.99 with SMTP id w3mr36359503lbk.55.1436177115576; Mon, 06 Jul 2015 03:05:15 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id lr11si14866318lbb.37.2015.07.06.03.05.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 03:05:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lagc2 with SMTP id c2so148252193lag.3 for ; Mon, 06 Jul 2015 03:05:15 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr22572211lbc.112.1436177115256; Mon, 06 Jul 2015 03:05:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1615531lbb; Mon, 6 Jul 2015 03:05:14 -0700 (PDT) X-Received: by 10.70.32.164 with SMTP id k4mr104807302pdi.138.1436177113532; Mon, 06 Jul 2015 03:05:13 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id an7si28276665pad.131.2015.07.06.03.05.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 06 Jul 2015 03:05:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:49848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC3Gx-0005JX-OJ for patch@linaro.org; Mon, 06 Jul 2015 06:05:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC3Bj-0005Xk-Nj for qemu-devel@nongnu.org; Mon, 06 Jul 2015 05:59:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZC3Bh-0003Pv-Go for qemu-devel@nongnu.org; Mon, 06 Jul 2015 05:59:47 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC3Bh-0003HN-8y for qemu-devel@nongnu.org; Mon, 06 Jul 2015 05:59:45 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZC3BX-0007hO-Vw for qemu-devel@nongnu.org; Mon, 06 Jul 2015 10:59:36 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 6 Jul 2015 10:59:34 +0100 Message-Id: <1436176775-29545-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1436176775-29545-1-git-send-email-peter.maydell@linaro.org> References: <1436176775-29545-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 6/7] arm_mptimer: Fix timer shutdown and mode change 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Dmitry Osipenko The running timer can't be stopped because timer control code just doesn't handle disabling the timer. Fix it by deleting the timer if the enable bit is cleared. The timer won't start periodic ticking if a ONE-SHOT -> PERIODIC mode change happens after a one-shot tick was completed. Fix it by re-starting ticking if the timer isn't ticking right now. To avoid code churning, these two fixes are squashed in one commit. Signed-off-by: Dmitry Osipenko Reviewed-by: Peter Crosthwaite Signed-off-by: Peter Maydell --- hw/timer/arm_mptimer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c index 8b93b3c..0e132b1 100644 --- a/hw/timer/arm_mptimer.c +++ b/hw/timer/arm_mptimer.c @@ -122,11 +122,18 @@ static void timerblock_write(void *opaque, hwaddr addr, case 8: /* Control. */ old = tb->control; tb->control = value; - if (((old & 1) == 0) && (value & 1)) { - if (tb->count == 0 && (tb->control & 2)) { + if (value & 1) { + if ((old & 1) && (tb->count != 0)) { + /* Do nothing if timer is ticking right now. */ + break; + } + if (tb->control & 2) { tb->count = tb->load; } timerblock_reload(tb, 1); + } else if (old & 1) { + /* Shutdown the timer. */ + timer_del(tb->timer); } break; case 12: /* Interrupt status. */