From patchwork Mon Jul 4 09:33:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 587127 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1ec:0:0:0:0 with SMTP id 12csp657119map; Mon, 4 Jul 2022 02:54:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t9dUWSD5+uylBBKyR5kCL6TxUKN/8TzxKauGlaFUDbL/Gl6vy74n+7sefOLxYjmlVrFCgj X-Received: by 2002:a25:1583:0:b0:668:e74a:995f with SMTP id 125-20020a251583000000b00668e74a995fmr31381516ybv.1.1656928481808; Mon, 04 Jul 2022 02:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656928481; cv=none; d=google.com; s=arc-20160816; b=ktELrTEuTa21AincE0O8EX4n8MD5G2i2XhvyLxOm/yg8eBqmDWDMAmnXmm/Hq4f6qZ pTSkFrOWE/btXWPTYEIhPvgbAdB6xgHN/xRzOGSX7yINbLQXzr3ITgwPKoktHmbqwkt6 mt8MWOFYkWCvGYK6Qp4PEX/NPjXrxNJk9QThDKqjqm1YkhxDdqyKIyCbWqoS6SWOSZ/l htOc35f9EVnbQWGZEB9GMLoBc4FdIczoEgIuhSR/iIygZHk3QRyIUkvoUPcBFwTDGX1d M7Ixq4TRSEq6WbIS5m1uKDLb9shVagiVC4zX4mcovzp3uC+WDifHe0mXArSLj8py7rCV xzTA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=osLJKyNmPqnc7lVA+B9CIUOXsndu+uo/6mM5gEQ/mGQ=; b=juse4rAWzobrLZKlgez4bf6llDFjMOkW+ehtgGfawet/YWuuy2OKUf5kL9TuR4H64W kUw5M5FUEDaMCBlVvDzx3+kha0RS9d07QaCUXbnEgomTGHcoSHqwQyQggM7sLZKl5Kvl 7C0yVw7SbsZGojaRjcGNfrx4LkiseGH6toXy4os1GkIugUqzx56FBQp4WSvHlIo4lTNA u1sdZmhHBgMEMPr7xnFSx5aG5uMFrQK8kMRe4c93s/6pkMhuUpMToTr56oiWmfeRK+lS TVDFIhz5RYfY3ocasXOeRbQemod93zsZoj5HY8Z1K+ETs2U4WfCYtU42fjrYOni4F/z7 DyHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MdlDS0+o; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 195-20020a8101cc000000b0031c9d6bb1c5si2030361ywb.324.2022.07.04.02.54.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jul 2022 02:54:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MdlDS0+o; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8Imv-00016Z-8Z for patch@linaro.org; Mon, 04 Jul 2022 05:54:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8ITp-0001Go-54 for qemu-devel@nongnu.org; Mon, 04 Jul 2022 05:34:57 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:40854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8ITn-0004xx-CG for qemu-devel@nongnu.org; Mon, 04 Jul 2022 05:34:56 -0400 Received: by mail-pj1-x1035.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so13079048pjl.5 for ; Mon, 04 Jul 2022 02:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=osLJKyNmPqnc7lVA+B9CIUOXsndu+uo/6mM5gEQ/mGQ=; b=MdlDS0+o4mb0+1uUOVR7Sl3ruOuGpMu1Gb/tvgcklsk9OL17JOOq9545SnJwNYANhC JBEWphkxflO4twyV0CzFcDxDgl2jwXBOa2rsx246NlNM4C7e/AWBy61xZwEiqMec193Z n7RUuTXmmY0TE7oNotgQBecR4xO3nJw2dy3u65BHS6NHrXzVH9zX7aRSUiEZ5X46Gtjy jsA5AfuF9NfM+8mYGN6Mvdg1o08g11eePvg3qufjn3FvPKsY60FNk1/T2lvB39gb5/aE f5aZnsQjVVSchI/CevJCC4/aKyTbdguOh3DPMgB2LN3jEKs7/0BDvssLuMJlR+0ToqGM Yu3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=osLJKyNmPqnc7lVA+B9CIUOXsndu+uo/6mM5gEQ/mGQ=; b=Jk/S0Axyw6RmXqpdhkORHiD+3eZ8ezSLVpnwuH2R0daH+1NhF+xG3bAAMCOH+3fvw3 FXVXNY2IDnMmUwzyTTnfR2yHYhT6GEDwXgLvZV4UFlCfnsuSJTKMEoCohPc0O3HRcxSA u4v7tq9Hx+Uj3qDrJqfUThKtDBjny3XrvZfIMzrw/VUmvjT+Z4ofc0ylW7kFGi4mEtWB FPzMuO8aR3j0tY6BAyzgXNj8qDcsNJXKJkn1yEzaGXDBP0u2jdrsDzcKZimneR4QZqaC 9nGYHm9fFRqtUVYzPN4eDu9s4YkkD5xjEHX3AT2+R6sYe4zF/s6eQWBxVMV4ptEheuGa SJqw== X-Gm-Message-State: AJIora9n9Pr9FpzawmCITf3KT07yJNleWvH9VZZ4g9P1MYjR2Sm/CK1y zbZCNRhC7MOT3zG7OR6yJsx0X7m6hJPfB5Mv X-Received: by 2002:a17:902:e5cd:b0:16a:6f96:eb9 with SMTP id u13-20020a170902e5cd00b0016a6f960eb9mr35392888plf.69.1656927294537; Mon, 04 Jul 2022 02:34:54 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id z5-20020aa79e45000000b00525b7f3e906sm15353355pfq.27.2022.07.04.02.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 02:34:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Xiaojuan Yang Subject: [PULL 19/23] hw/rtc/ls7a_rtc: Fix rtc enable and disable function Date: Mon, 4 Jul 2022 15:03:53 +0530 Message-Id: <20220704093357.983255-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220704093357.983255-1-richard.henderson@linaro.org> References: <20220704093357.983255-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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: Xiaojuan Yang Fix ls7a rtc enable and disable function. When rtc disabled, it do not support to read or write, but the real time is still continue, so we need not neither save the time nor update the rtc offset. Signed-off-by: Xiaojuan Yang Reviewed-by: Richard Henderson Message-Id: <20220701093407.2150607-6-yangxiaojuan@loongson.cn> Signed-off-by: Richard Henderson --- hw/rtc/ls7a_rtc.c | 60 ++++++----------------------------------------- 1 file changed, 7 insertions(+), 53 deletions(-) diff --git a/hw/rtc/ls7a_rtc.c b/hw/rtc/ls7a_rtc.c index eb10cdb451..a36aeea9dd 100644 --- a/hw/rtc/ls7a_rtc.c +++ b/hw/rtc/ls7a_rtc.c @@ -72,9 +72,6 @@ struct LS7ARtcState { */ int64_t offset_toy; int64_t offset_rtc; - uint64_t save_toy_mon; - uint64_t save_toy_year; - uint64_t save_rtc; int64_t data; int tidx; uint32_t toymatch[3]; @@ -140,14 +137,6 @@ static inline uint64_t toy_time_to_val_mon(struct tm tm) return val; } -static inline uint64_t toy_time_to_val_year(struct tm tm) -{ - uint64_t year; - - year = tm.tm_year; - return year; -} - static inline void toymatch_val_to_time(LS7ARtcState *s, uint64_t val, struct tm *tm) { qemu_get_timedate(tm, s->offset_toy); @@ -191,14 +180,6 @@ static void rtcmatch_write(LS7ARtcState *s, uint64_t val, int num) static void ls7a_toy_stop(LS7ARtcState *s) { int i; - struct tm tm; - /* - * save time when disabled toy, - * because toy time not add counters. - */ - qemu_get_timedate(&tm, s->offset_toy); - s->save_toy_mon = toy_time_to_val_mon(tm); - s->save_toy_year = toy_time_to_val_year(tm); /* delete timers, and when re-enabled, recaculate expire time */ for (i = 0; i < TIMER_NUMS; i++) { @@ -209,11 +190,6 @@ static void ls7a_toy_stop(LS7ARtcState *s) static void ls7a_rtc_stop(LS7ARtcState *s) { int i; - uint64_t time; - - /* save rtc time */ - time = ls7a_rtc_ticks() + s->offset_rtc; - s->save_rtc = time; /* delete timers, and when re-enabled, recaculate expire time */ for (i = 0; i < TIMER_NUMS; i++) { @@ -226,14 +202,7 @@ static void ls7a_toy_start(LS7ARtcState *s) int i; uint64_t expire_time, now; struct tm tm = {}; - /* - * need to recaculate toy offset - * and expire time when enable it. - */ - toy_val_to_time_mon(s->save_toy_mon, &tm); - toy_val_to_time_year(s->save_toy_year, &tm); - s->offset_toy = qemu_timedate_diff(&tm); now = qemu_clock_get_ms(rtc_clock); /* recaculate expire time and enable timer */ @@ -247,14 +216,7 @@ static void ls7a_toy_start(LS7ARtcState *s) static void ls7a_rtc_start(LS7ARtcState *s) { int i; - uint64_t expire_time, now; - - /* - * need to recaculate rtc offset - * and expire time when enable it. - */ - now = ls7a_rtc_ticks(); - s->offset_rtc = s->save_rtc - now; + uint64_t expire_time; /* recaculate expire time and enable timer */ for (i = 0; i < TIMER_NUMS; i++) { @@ -271,23 +233,21 @@ static uint64_t ls7a_rtc_read(void *opaque, hwaddr addr, unsigned size) switch (addr) { case SYS_TOYREAD0: - /* if toy disabled, read save toy time */ if (toy_enabled(s)) { qemu_get_timedate(&tm, s->offset_toy); val = toy_time_to_val_mon(tm); } else { - /* read save mon val */ - val = s->save_toy_mon; + /* return 0 when toy disabled */ + val = 0; } break; case SYS_TOYREAD1: - /* if toy disabled, read save toy time */ if (toy_enabled(s)) { qemu_get_timedate(&tm, s->offset_toy); val = tm.tm_year; } else { - /* read save year val */ - val = s->save_toy_year; + /* return 0 when toy disabled */ + val = 0; } break; case SYS_TOYMATCH0: @@ -303,11 +263,11 @@ static uint64_t ls7a_rtc_read(void *opaque, hwaddr addr, unsigned size) val = s->cntrctl; break; case SYS_RTCREAD0: - /* if rtc disabled, read save rtc time */ if (rtc_enabled(s)) { val = ls7a_rtc_ticks() + s->offset_rtc; } else { - val = s->save_rtc; + /* return 0 when rtc disabled */ + val = 0; } break; case SYS_RTCMATCH0: @@ -457,9 +417,6 @@ static void ls7a_rtc_realize(DeviceState *dev, Error **errp) } d->offset_toy = 0; d->offset_rtc = 0; - d->save_toy_mon = 0; - d->save_toy_year = 0; - d->save_rtc = 0; } @@ -515,9 +472,6 @@ static const VMStateDescription vmstate_ls7a_rtc = { .fields = (VMStateField[]) { VMSTATE_INT64(offset_toy, LS7ARtcState), VMSTATE_INT64(offset_rtc, LS7ARtcState), - VMSTATE_UINT64(save_toy_mon, LS7ARtcState), - VMSTATE_UINT64(save_toy_year, LS7ARtcState), - VMSTATE_UINT64(save_rtc, LS7ARtcState), VMSTATE_UINT32_ARRAY(toymatch, LS7ARtcState, TIMER_NUMS), VMSTATE_UINT32_ARRAY(rtcmatch, LS7ARtcState, TIMER_NUMS), VMSTATE_UINT32(cntrctl, LS7ARtcState),