From patchwork Mon Mar 19 18:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 132075 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp3053076ljb; Mon, 19 Mar 2018 11:37:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELtNJrrX3RjJviMNYQD2tpwRUKSWiE4rMnJ32iyZ0kifY1YW+iZdZmAIywJIMfxTYYA95G0s X-Received: by 10.237.56.105 with SMTP id j96mr4295093qte.258.1521484671071; Mon, 19 Mar 2018 11:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484671; cv=none; d=google.com; s=arc-20160816; b=gH3TiuBIfzOLuSvdEDJIFUzBGPSPugwsTTvP63SaUH9LBcLKn3zwgkHcqtwuSqmb+M KAwgFApxD+UT0wS9eq3zT9L8+kxBd0dfIX2+sUkNB+DClYsIroz/bbS421h/G9t9j02A vgEUiV+T+EECNfrk+rEJ0pIZUOJNwbVXvNtX97ZPh7jY0wNJnTrEF3Po2nLQaC/3AzRu KkKrOy9ZNQ+RvH91H0KCCVAaiZ+70fKmgtdbYpsBZhCOWLATDuLH/lKvKIDGLnjBES5m FVukXUvMl+r+xLtYNrSGIyyP2iOpHxQ8ej8/h7YEIeQwvRTbPmIcl2DDSESozolASgbg 1eWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=/gozRclWi5v7Oy+56OKFXskFIkPWhSw4ojXmdRvQApA=; b=PuK/13oaT33FPTDJ6g7+WepJDpLtugSiA4R/1tQe71Eml7AaG4l1Mb3chG1j/3E65/ dx7cfVdok0xYodALYKzLn+GoVpMo4jeTiCpqEnMSPsrmmMyl/B2alwWquxobH1FyiHfl DU62OuS97yi5PxeQUICHxvpS1rVQXJgZpAxNyvqy5dXRxcIijYlyLsph3jO01DTBLZwk 5FqxMqjgL4/H9TqxFeubWnwU1JjeyGk3bcL1XindqVm/ZwMPOOo6oj9ubLoueS6Ogort kDUBt7jHwb5AgyDtNIrtxs8EZPvPjvNdiHzAaV1jdv+lSbmZw77b/ofld0sqvEXxyPfY rqrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j126si631453qkj.142.2018.03.19.11.37.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Mar 2018 11:37:51 -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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exzfK-0004su-Bl for patch@linaro.org; Mon, 19 Mar 2018 14:37:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exzbx-0002Jc-RK for qemu-devel@nongnu.org; Mon, 19 Mar 2018 14:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exzbw-0007dZ-RH for qemu-devel@nongnu.org; Mon, 19 Mar 2018 14:34:21 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:40456) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exzbw-0007dJ-K9 for qemu-devel@nongnu.org; Mon, 19 Mar 2018 14:34:20 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1exzbv-0002zt-Ka for qemu-devel@nongnu.org; Mon, 19 Mar 2018 18:34:19 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2018 18:34:05 +0000 Message-Id: <20180319183415.1976-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319183415.1976-1-peter.maydell@linaro.org> References: <20180319183415.1976-1-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 03/13] char: i.MX: Simplify imx_update() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" From: Andrey Smirnov Code of imx_update() is slightly confusing since the "flags" variable doesn't really corespond to anything in real hardware and server as a kitchensink accumulating events normally reported via USR1 and USR2 registers. Change the code to explicitly evaluate state of interrupts reported via USR1 and USR2 against corresponding masking bits and use the to detemine if IRQ line should be asserted or not. NOTE: Check for UTS1_TXEMPTY being set has been dropped for two reasons: 1. Emulation code implements a single character FIFO, so this flag will always be set since characters are trasmitted as a part of the code emulating "push" into the FIFO 2. imx_update() is really just a function doing ORing and maksing of reported events, so checking for UTS1_TXEMPTY should happen, if it's ever really needed should probably happen outside of it. Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Cc: Bill Paul Cc: Peter Maydell Signed-off-by: Andrey Smirnov Message-id: 20180315191141.6789-1-andrew.smirnov@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/char/imx_serial.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) -- 2.16.2 diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c index 70405ccf8b..d1e8586280 100644 --- a/hw/char/imx_serial.c +++ b/hw/char/imx_serial.c @@ -56,16 +56,24 @@ static const VMStateDescription vmstate_imx_serial = { static void imx_update(IMXSerialState *s) { - uint32_t flags; + uint32_t usr1; + uint32_t usr2; + uint32_t mask; - flags = (s->usr1 & s->ucr1) & (USR1_TRDY|USR1_RRDY); - if (s->ucr1 & UCR1_TXMPTYEN) { - flags |= (s->uts1 & UTS1_TXEMPTY); - } else { - flags &= ~USR1_TRDY; - } + /* + * Lucky for us TRDY and RRDY has the same offset in both USR1 and + * UCR1, so we can get away with something as simple as the + * following: + */ + usr1 = s->usr1 & s->ucr1 & (USR1_TRDY | USR1_RRDY); + /* + * Bits that we want in USR2 are not as conveniently laid out, + * unfortunately. + */ + mask = (s->ucr1 & UCR1_TXMPTYEN) ? USR2_TXFE : 0; + usr2 = s->usr2 & mask; - qemu_set_irq(s->irq, !!flags); + qemu_set_irq(s->irq, usr1 || usr2); } static void imx_serial_reset(IMXSerialState *s)