From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869127; cv=none; d=zohomail.com; s=zohoarc; b=FqpU212aAD+TRvIxc+FPQ0qr1gaE/z8byoJI+yAq+goAXyVcsGzmaTr21RuCuupW7PjzJ9FYDtRCUFMBJk4+bweNlDitl9CzMnFT4OplJta/ghN4IH9bdj8dXGvebQu31E7CKBlx0glRC4myhRtZRCBXp4Zj0gsKO/gRxot+f8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869127; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=/7vqyfsfQSXKfw69CwuMNDomx2TM2p1e+fdBs9WDTis=; b=CYDkzQSy8FUG/Dzvzz0+wlmTkOsleDsohnaikLH9AOwEqg4GJF56bugUADpsV65kPQTGW9wFr81kLZXMwGDq9bL/31bFcmf8KkKVAs3hIlFnPWR9EDDTArHmoF6GmCXRcIB0RZrLcutUdaNlEiS0wnPOkuIwqiiwvhrNAPqYAcQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869127900518.4678824310225; Thu, 5 Nov 2026 00:58:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtHI-0003E3-CJ; Thu, 05 Nov 2026 03:57:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtHG-0003DU-Sj for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:56:58 -0500 Received: from mail-dy1-f182.google.com ([74.125.82.182]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHF-0003bz-3f for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:56:58 -0500 Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-33fb4680717so2930040eec.1 for ; Thu, 05 Nov 2026 00:56:56 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca3785430sm20796681eec.3.2026.11.05.00.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:56:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869015; x=1794473815; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/7vqyfsfQSXKfw69CwuMNDomx2TM2p1e+fdBs9WDTis=; b=Q5qQyFgrg2CYDeKTvwtBRbBHsc+fKbHwLGJ7gZ6M2G1bI0GqcKL2JEkZJWLFt2JUG3 1WU95Wu20EGOu3SfEm1YMCGSVTEDuhfjEJ5dEe/AqQuBayo8tr33iWLKKbmrU9AMVM28 mgvQuIWAIW+E8a5PCVc4rCjwWFlzK3oSREGSRsysoq4d0KMt2zbhWDACqXHLywLn8MlS GvCAdhUGSwks214faZTmyAErldEBqBl/Xgjg44T5VXAoHFWJsYIq2JfmPezM5Aw5yjTY K78JyNMxfahZqf0WWrL/A3uTmhYmPxe1LK1whKVYhwjsrooYTnqTgCOkuiC8Z+CUGAGf 8r8Q== X-Gm-Message-State: APuU4Z+clZKwMxHTfb2LQB9FQIdCW2WGNvJR7gobC6teue7nMx/3ZucM d+W9dMIFiigvQfacfkqm6jFCXUpTR6oykBHbwhWDCPZHmZ4/AfkpLSTjxQQIEe8Qkq8= X-Gm-Gg: AYBFou1zUQ24rYSPTinTbjtYMOs68f7X87exECsaxQMOo4SnfgKjysxHWHB60RcvlLk d/zAU0DOD7/OjpHw9Ia+OiZmF33YlvbTTAcUwKGBswlF+IRjbfpXOhkb5rdsdfKV90Cn4ZxUDJA GTneVczQBLcJvNvgXmtsYYF6nt2vztA0j5f+REQHpLB8IfyicB2VFlps1xN5WXNwklrspXqHKaT a7s8UIrQFnGxsjI7rwKxjJFoEwjU5K7kbJRhzLqa2lvlCh+L0bSpno1RrPTiMj3cS1AdwlHEsuU r9b9rQDS3DfE9flHnLaZoD/TpV9h3Nx/MQPUs+/FAZrk/4UJNBf75yadvlFk20z4s4nVCTpQHEd mqLYuVrjNNvGlu22MbA0i8xETVU/2LGHlbd+8ts8oifje+/DvpvRCN1/2WQMfw8NDfp+/p9Bio+ BOylNS1seoz2MrBN7MUXiZ7ozmNqdgtvHTAsObg6zGxoQslKAfA+YbkZYU+8htKqlh0VBaFQjEL Tp4lWFORtFrwq7C9Oa/KQNFC7C2qUWtvKROJrR10IpfjbovxjbHnfhbL4UcMfH3PPtS6ekpa3si r+vMRWRvUvp/gzElZ1B7pzqbMmcuU9vqF8m9BX7CKLxpx+WiDjLpBgCzVWgKcvsZh+RK2+9VmlK g3UE2yQ== X-Received: by 2002:a05:7300:cc9e:b0:36e:c01b:2e7c with SMTP id 5a478bee46e88-36ec01b30d3mr356272eec.6.1793869014982; Thu, 05 Nov 2026 00:56:54 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:37 +0800 Subject: [PATCH 01/19] hw/rtc: ds1338: program the clock from the time registers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-1-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868639; l=6068; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=uej/UOj+V/lpxWjtnR1AN5iwpDxP7F3nxb3Qip3BUmg=; b=W3ycztXUaDdqSbDXU5XN5lZGQGuKCp0ZqX9qS3X16uF2dScitCQNn4rHBhK+CVUBnpHOEBidT vCurS/8l4SVBAZM90Lpp96MPvFKcOlmPjE4U1bAp0udOL4FArQcO996 X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=74.125.82.182; envelope-from=eblot.ml@gmail.com; helo=mail-dy1-f182.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869129435158500 A write to a time register rebuilt a struct tm from the current date, substituted the field being written and folded the result back into the offset. Every byte of a multi-byte transfer was therefore normalised against the fields the guest had not written yet: a date of 31 programmed while the month register still held a 30-day month moved the clock into the following month. Keep the written value in the register file and derive the offset from the file as a whole. This needs the registers refreshed on a START_SEND, as the hardware does on any START. Signed-off-by: Emmanuel Blot --- hw/rtc/ds1338.c | 116 ++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/hw/rtc/ds1338.c b/hw/rtc/ds1338.c index 7eaa663113..862e03bd32 100644 --- a/hw/rtc/ds1338.c +++ b/hw/rtc/ds1338.c @@ -8,6 +8,12 @@ * * Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. + * + * Limitations: + * - Writing the seconds register does not reset the internal countdown ch= ain, + * so the sub-second phase of the clock is not modelled. + * - Leap years follow the Gregorian rule, where the parts stop at 2100: t= hey + * derive the leap year from the two-digit year alone. */ =20 #include "qemu/osdep.h" @@ -75,6 +81,41 @@ static const VMStateDescription vmstate_ds1338 =3D { } }; =20 +/* Reconstruct a struct tm from the BCD time registers in nvram. */ +static void ds1338_time_from_regs(DS1338State *s, struct tm *now) +{ + qemu_get_timedate(now, s->offset); + now->tm_sec =3D from_bcd(s->nvram[0] & 0x7f); + now->tm_min =3D from_bcd(s->nvram[1] & 0x7f); + if (s->nvram[2] & HOURS_12) { + int tmp =3D from_bcd(s->nvram[2] & (HOURS_PM - 1)); + if (s->nvram[2] & HOURS_PM) { + tmp +=3D 12; + } + if (tmp % 12 =3D=3D 0) { + tmp -=3D 12; + } + now->tm_hour =3D tmp; + } else { + now->tm_hour =3D from_bcd(s->nvram[2] & (HOURS_12 - 1)); + } + now->tm_mday =3D from_bcd(s->nvram[4] & 0x3f); + now->tm_mon =3D from_bcd(s->nvram[5] & 0x1f) - 1; + now->tm_year =3D from_bcd(s->nvram[6]) + 100; +} + +static void ds1338_resync_from_regs(DS1338State *s) +{ + struct tm now; + int user_wday; + + ds1338_time_from_regs(s, &now); + s->offset =3D qemu_timedate_diff(&now); + qemu_get_timedate(&now, s->offset); + user_wday =3D (s->nvram[3] & 7) - 1; + s->wday_offset =3D (user_wday - now.tm_wday + 7) % 7; +} + static void ds1338_capture_current_time(DS1338State *s) { /* Capture the current time into the secondary registers @@ -123,16 +164,16 @@ static int ds1338_event(I2CSlave *i2c, enum i2c_event= event) DS1338State *s =3D DS1338(i2c); =20 switch (event) { - case I2C_START_RECV: - /* In h/w, capture happens on any START condition, not just a - * START_RECV, but there is no need to actually capture on - * START_SEND, because the guest can't get at that data - * without going through a START_RECV which would overwrite it. - */ - ds1338_capture_current_time(s); - break; case I2C_START_SEND: s->addr_byte =3D true; + /* fall through */ + case I2C_START_RECV: + /* + * In h/w the time is transferred to the user registers on any STA= RT + * condition, so a write modifies the running time rather than + * whatever the last read left behind. + */ + ds1338_capture_current_time(s); break; default: break; @@ -167,51 +208,20 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) return 0; } if (s->ptr < 7) { - /* Time register. */ - struct tm now; - qemu_get_timedate(&now, s->offset); - switch(s->ptr) { - case 0: - /* TODO: Implement CH (stop) bit. */ - now.tm_sec =3D from_bcd(data & 0x7f); - break; - case 1: - now.tm_min =3D from_bcd(data & 0x7f); - break; - case 2: - if (data & HOURS_12) { - int tmp =3D from_bcd(data & (HOURS_PM - 1)); - if (data & HOURS_PM) { - tmp +=3D 12; - } - if (tmp % 12 =3D=3D 0) { - tmp -=3D 12; - } - now.tm_hour =3D tmp; - } else { - now.tm_hour =3D from_bcd(data & (HOURS_12 - 1)); - } - break; - case 3: - { - /* The day field is supposed to contain a value in - the range 1-7. Otherwise behavior is undefined. - */ - int user_wday =3D (data & 7) - 1; - s->wday_offset =3D (user_wday - now.tm_wday + 7) % 7; - } - break; - case 4: - now.tm_mday =3D from_bcd(data & 0x3f); - break; - case 5: - now.tm_mon =3D from_bcd(data & 0x1f) - 1; - break; - case 6: - now.tm_year =3D from_bcd(data) + 100; - break; - } - s->offset =3D qemu_timedate_diff(&now); + /* + * Time register. The write lands in the register file and the clo= ck + * is then rebuilt from it as a whole: a transfer that programs the + * date before the month it belongs to must not be normalised away + * against the month still held from the previous date. + * + * TODO: Implement CH (stop) bit. + */ + static const uint8_t valid[7] =3D { + 0x7f, 0x7f, 0x7f, 0x07, 0x3f, 0x1f, 0xff + }; + + s->nvram[s->ptr] =3D data & valid[s->ptr]; + ds1338_resync_from_regs(s); } else { if (s->ptr =3D=3D k->ctrl_addr) { /* Control register: reserved bits read back as zero. */ --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869047; cv=none; d=zohomail.com; s=zohoarc; b=VB1FYjwRxxCuUXy4MoMWTG6wnOUwafMoGx2pn8pBUgJm3hp6LQT2EeyaxvtlQyl9jt3iOQBt1+ZwU1+R87aLvlnZUHrzsmgkK80MQEV294AdfXKwo7fdg6q3RgKFvCpvRDQMoCY4BqK0hMZJMlqYgqwL5VOvXkm2ooKlnojvs5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869047; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=W5PhRPYjPeVIiLmDaG68Pb9QynlP1yOMDtzh8f0rn+Q=; b=hWkFwbaddV6IxoEO8l6mZC0oxzTdlAbpxatKWeRYpv1qa8i7DuVz8nZoCloV3h2Yp6lwGl2Y7A8CwfChFFKZJRAy2/7qUxmaSenp1tv/PlymPEel2fzGvqEgKCQzythy0yOGM2Es/4efOMkDw6Ta5HS0H7t7Y4rTCmALFuNLP4w= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869046930403.2760432511501; Thu, 5 Nov 2026 00:57:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtHS-0003Et-Bt; Thu, 05 Nov 2026 03:57:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtHP-0003Ed-RC for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:08 -0500 Received: from mail-dl1-f51.google.com ([74.125.82.51]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHM-0003ct-Vs for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:07 -0500 Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-1adbf62dd31so2256757c88.0 for ; Thu, 05 Nov 2026 00:57:04 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b245c69c3fsm14372246c88.20.2026.11.05.00.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869023; x=1794473823; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=W5PhRPYjPeVIiLmDaG68Pb9QynlP1yOMDtzh8f0rn+Q=; b=F8upNVt6goXfFXABenLOv99jC7ko6geev8EMYyU8gVHay9ZGEOTc9iTVXL0XkD1A0v MCrvlRQtjAa7yfE9CP4jIPH3cuZM9YuA5EpCjwLIsezIm5p2ZMd80oI6gpWapMv2wnVY BgDXoQNr6vhHl+Rg8Te7yewRkoWXgsKUAgAAJuFKLQXN8vInewzvb1HdsnhKxdMwruly YK9Ca6sr63AJq10KUwzvXoLUaslcFnnlhdWo5HrRFZLx1pkurtkAwqD1dcnfOAQY950O mqfwf4Y/zRwBY0OjzsLe4UKdrjED+fEqZ/Q+ye6q3LeNie/Q0xuAbA6N1YTkPSdAayEl +lpQ== X-Gm-Message-State: APuU4Z+IvE6m7vdWRjH4BXU/k5+A9w23TzCLEe642joHYn7o4NolZUrv nK+Uy/fg2ijbf2D+NB53clbAshT2IjCy6EFSKVSWcwPDISXA9AHXNWWeMX0mqJFpzdE= X-Gm-Gg: AYBFou3xGrXxpNGg/pC2qhtGsH8404Bfg7ZtP5T+ZrZpQfbWQ6MRP/QxCxTEmPNeZmD MFFX5BPT691nQXdNdmadGYCaB6B4ptL8Ru6ardE8HPseO+KwLR6qHaxwwTTZiBnwcvCUb4949P0 vsYslZl6FhjUQIR7iay8PhjxVAB5+wez8AKglYOji7o68VSkdAGH7Ft/sBoDrS2IwKy0tKAGm13 gvqfVfEQgo3s+TgN7Vg4Sd7fQCdjcYtr4pOuDE21mb1Dmo9gqU4HQK0CEOixcVKDHI8D6HIibRq qnur4BGlcS2T+nS4M+FL8Ec+wVakRpJknmhrhjbBbRYAfgs1fB9VJUb0WZiWeqKfKcQcJStofOf 9MDp+eGUB9xPdJqWIw7+roWIfeA7djCKvVnE0fwzI932obc2I3jXOVGSLCcEXw9lylTvuQxfkRZ 4aDoHb+ZGcSkXZ8R6WOUpHgtiJ5cgjLnEyGd9JzNK6sO25nJxc2v0Dl2KzyWg24u6OLj8vqGtdp HoQ3DPkAMv3TZXVqqcFh1F77CfQhBIRYf5dXGFJt5DXbTpi82WriyfhY2J9EiE8wCVERSn0mfa7 FZiYQgWEmu6KIw+4fYapk9Zgwu8aWC9NuovmOzPCKUe5uDkZ6pFKaXMTj4rowhLYWwkhp2NPznx uHvl0Cg== X-Received: by 2002:a05:701b:464d:b0:1b2:3497:5998 with SMTP id a92af1059eb24-1b2349759cfmr14192551c88.36.1793869022715; Thu, 05 Nov 2026 00:57:02 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:38 +0800 Subject: [PATCH 02/19] hw/rtc: ds1338: implement the DS1338 clock-halt bit MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-2-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868639; l=4398; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=Kzt6qfQ8xw5u2qhWKCAbs8upbxPA4Z4PtksNYulDrzo=; b=D6bt+csvS76ioaeBh+q8lcfldQbu0J2Z4fQPbP4aMkA6pxXARfKRsyxtq11Kb71lfxMqQNUvt /39SvxXYuD9CL9WgKjjY5rFuxN9gDU2XLDcUpViU740q4u4lYThsBAi X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=74.125.82.51; envelope-from=eblot.ml@gmail.com; helo=mail-dl1-f51.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869048252158500 Bit 7 of the seconds register disables the oscillator, and the guest is expected to clear it before trusting the time. The bit was masked away on every write, so it always read back zero and the clock never stopped. The reset value stays clear rather than set as on real hardware, keeping the model's convention that the clock comes up running and synchronised with the host. Signed-off-by: Emmanuel Blot --- hw/rtc/ds1338.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/hw/rtc/ds1338.c b/hw/rtc/ds1338.c index 862e03bd32..79bcff4599 100644 --- a/hw/rtc/ds1338.c +++ b/hw/rtc/ds1338.c @@ -14,6 +14,7 @@ * so the sub-second phase of the clock is not modelled. * - Leap years follow the Gregorian rule, where the parts stop at 2100: t= hey * derive the leap year from the two-digit year alone. + * - The model comes up with the clock running; real hardware comes up hal= ted. */ =20 #include "qemu/osdep.h" @@ -53,6 +54,7 @@ struct DS1338State { uint8_t nvram[NVRAM_SIZE]; int32_t ptr; bool addr_byte; + bool osc_stopped; /* oscillator halted: time is frozen */ }; =20 struct DS1338Class { @@ -64,11 +66,12 @@ struct DS1338Class { uint8_t osf_addr; /* register holding the OSF flag */ uint8_t osf_mask; /* OSF bit within osf_addr */ uint8_t ctrl_reset; /* control-register power-on value */ + uint8_t ch_mask; /* Clock-halt bit in the seconds reg */ }; =20 static const VMStateDescription vmstate_ds1338 =3D { .name =3D "ds1338", - .version_id =3D 2, + .version_id =3D 3, .minimum_version_id =3D 1, .fields =3D (const VMStateField[]) { VMSTATE_I2C_SLAVE(parent_obj, DS1338State), @@ -77,6 +80,7 @@ static const VMStateDescription vmstate_ds1338 =3D { VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE), VMSTATE_INT32(ptr, DS1338State), VMSTATE_BOOL(addr_byte, DS1338State), + VMSTATE_BOOL_V(osc_stopped, DS1338State, 3), VMSTATE_END_OF_LIST() } }; @@ -122,6 +126,11 @@ static void ds1338_capture_current_time(DS1338State *s) * which will be actually read by the data transfer operation. */ struct tm now; + + if (s->osc_stopped) { + return; + } + qemu_get_timedate(&now, s->offset); s->nvram[0] =3D to_bcd(now.tm_sec); s->nvram[1] =3D to_bcd(now.tm_min); @@ -213,15 +222,30 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) * is then rebuilt from it as a whole: a transfer that programs the * date before the month it belongs to must not be normalised away * against the month still held from the previous date. - * - * TODO: Implement CH (stop) bit. */ static const uint8_t valid[7] =3D { 0x7f, 0x7f, 0x7f, 0x07, 0x3f, 0x1f, 0xff }; + uint8_t mask =3D valid[s->ptr]; + bool halt =3D s->osc_stopped; =20 - s->nvram[s->ptr] =3D data & valid[s->ptr]; - ds1338_resync_from_regs(s); + if (s->ptr =3D=3D 0) { + mask |=3D k->ch_mask; + if (k->ch_mask) { + halt =3D data & k->ch_mask; + } + } + + if (halt && !s->osc_stopped) { + /* CH set: freeze the counters before the register is stored. = */ + ds1338_capture_current_time(s); + s->nvram[k->osf_addr] |=3D k->osf_mask; + } + s->nvram[s->ptr] =3D data & mask; + s->osc_stopped =3D halt; + if (!halt) { + ds1338_resync_from_regs(s); + } } else { if (s->ptr =3D=3D k->ctrl_addr) { /* Control register: reserved bits read back as zero. */ @@ -253,6 +277,7 @@ static void ds1338_reset_hold(Object *obj, ResetType ty= pe) s->nvram[k->ctrl_addr] =3D k->ctrl_reset; s->ptr =3D 0; s->addr_byte =3D false; + s->osc_stopped =3D false; } =20 static void ds1338_class_init(ObjectClass *klass, const void *data) @@ -275,6 +300,7 @@ static void ds1338_class_init(ObjectClass *klass, const= void *data) dsc->osf_addr =3D DS1338_CONTROL; dsc->osf_mask =3D CTRL_OSF; dsc->ctrl_reset =3D DS1338_CTRL_RESET; + dsc->ch_mask =3D SECONDS_CH; } =20 static const TypeInfo ds1338_types[] =3D { --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869066; cv=none; d=zohomail.com; s=zohoarc; b=ZvUcaprb57MyXM6qNVmSu3RA3JdgXnC0yB8FG9XMImUFnp4oGXMdVOf6zQKCdQkgSfXrx+NqIkrQO18gdX8QKSxK3Oc0srBJjcJmf0wPdXElvzbhbtChcL0Bn98ceYD8GhTY9AtalyQhWq9/l+GKFB939cSbgO/h8NWwNmJ1uOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869066; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=4c8supkKneQ6KSPUU96myXPMZvz+cStDQRdD8Fg6fTw=; b=IqGVEiPJz0f+B7C0qYYqU8bpWo5QGFjaXpUHplDdl56jK65COIRykFH/l49RK17o5h+1rxVtR262BGXMsI+F9xiZf2ds1h41+Kb5JlAkpkZBfMRv6G2rrXM528y7+YbX37TA+9f4j5TQztAUBl6radePFpoVnnQn7T5dNroCBGw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869066404668.1164610997884; Thu, 5 Nov 2026 00:57:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtHY-0003G1-DR; Thu, 05 Nov 2026 03:57:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtHW-0003FU-Aa for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:14 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHU-0003dR-CN for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:13 -0500 Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-cc4aa0246b7so790806a12.3 for ; Thu, 05 Nov 2026 00:57:12 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ed08bd5ab2sm15236955ad.5.2026.11.05.00.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869031; x=1794473831; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4c8supkKneQ6KSPUU96myXPMZvz+cStDQRdD8Fg6fTw=; b=K6lVmD13AcuDV4tzOsg5yiDxt1Z+j3dsKGTyIAkWX6w1bA0Asd8lrT3Nnesldl3Q3V cTx3JDPpvlIRpClH+U5MAx9AI75B10E+lE3SyeiZlB13+ZM84IFfl6EEdfiBRfMho1ms b3pOx4+FGIqiVcjT+saHIgDh4umlEH5oXuqOa/gWg2gPOqiXdacg58B22E07RkVqbJL+ XXEfKfATwH2YlmLiW1Cbs1HPp+XRrGSNflGKRpIS+6qumSaP4WeowxjoRokst4dV/97+ LCZyuCGUIhJzGYowLu2xj3qALMhk9cS0mWHr9BeYv6tKWpc2P4f6YA5A20+mm2JxHOEl gaMA== X-Gm-Message-State: APuU4Z93SisZE3SDPMBJCAkYqd2aSufqrwjqgIOt/VoC+D+JtDT2RtIe hDR1OjMudsd+btvs2VyjOIRgcHRIjTgZLcRWwMJY1hujUQcIv5rk/1U6t1wVmxl6NCs= X-Gm-Gg: AYBFou319eLc3edzX3V1OMFQ7YL48z5+6gqh6+MEZF39GPWxANCMdHtZ9eyrIUcqJTY JERUkyKEl0TrJfB3zOSAczXmYAhVpguPDalqNULbaaeiMrszjAnx/QKwEVn1HglUpD3hDOIkN+P H2NKzqwnmEUKWOJqaN3w3ECvInt5W8xSTJFbRRvpz3GEzueRY7MA2e3YcPFNtsM9AcBQAAjX128 ZeOZ+eC6o0+wvo4rqcHarrDQ1QcIxMtS0+k+2iC2mPb5zRfB/rQJoLUb4nSN4KB5BjsSAt4S4Vi dqX0VShHyZgzb/fLLNRTdI2wlDzlIbpVwhasjU5lsroRvMDHIjIr/dDuRnlneDyPEwO0Czz+EtT nrwjmiss9+70sCYwgZMz73mUb3uYcexP9vRLQ9fyDmcivaAI0b+bZ0gppsoMj2A+z9Cgi3zp9dh falG1ej7VSKRT9u4unhdlGf1wbWPeyKbp/Q9jdF9yeLw3wXWgmn5djZqFOFlwTLyWgAlHMDPqL0 i58vIT8KKSVI7km0VCq+0w3XaJZWagbbIe14JOvSmuYtDDWT0KKn+ZcqJ5fvst3MTeiL7a8RBTh pwVkclkUD/Y8tzxUbG8iBvtAwF/wV9zcsgjRO8o6IXuqmwXPkVIfrA3wsellYV9CC/hEgPB34jn NmQxxEw== X-Received: by 2002:a17:903:3904:b0:2e3:1d30:8658 with SMTP id d9443c01a7336-2eb36396775mr166669095ad.10.1793869030724; Thu, 05 Nov 2026 00:57:10 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:39 +0800 Subject: [PATCH 03/19] hw/rtc: ds1338: refresh the user registers on a read rollover only MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-3-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868639; l=1985; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=Mt2M8RCp3ALFgPQLrMqox8ji8iLmVD233jOdYO4LkMo=; b=lN13VPE6DX0epbA3j4KxbegyhKY6dMenqIR1VTwgrFGRXnx9wvo+/WCn4Bnrd+/GlxRupOIrh qw3edfLAWaBDbSvwwGPxwab0U8D9qIPgO9aX+h7AXEmpua0f16aLAVf X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.215.178; envelope-from=eblot.ml@gmail.com; helo=mail-pg1-f178.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869068289158500 Synchronising the user buffers when the register pointer rolls over to zero is a property of reading them; hardware routes a write to the counters themselves. Doing it from the shared pointer increment meant a write transfer long enough to wrap overwrote the bytes the guest had just sent with the current time. Move the refresh to the read path. Signed-off-by: Emmanuel Blot --- hw/rtc/ds1338.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/rtc/ds1338.c b/hw/rtc/ds1338.c index 79bcff4599..c5fc74e6ca 100644 --- a/hw/rtc/ds1338.c +++ b/hw/rtc/ds1338.c @@ -12,6 +12,8 @@ * Limitations: * - Writing the seconds register does not reset the internal countdown ch= ain, * so the sub-second phase of the clock is not modelled. + * - The user registers are refreshed on a START and on a read that wraps = the + * register pointer, but not on a STOP. * - Leap years follow the Gregorian rule, where the parts stop at 2100: t= hey * derive the leap year from the two-digit year alone. * - The model comes up with the clock running; real hardware comes up hal= ted. @@ -157,15 +159,7 @@ static void ds1338_inc_regptr(DS1338State *s) { DS1338Class *k =3D DS1338_GET_CLASS(s); =20 - /* - * The register pointer wraps around after the last register; wraparou= nd - * causes the current time/date to be retransferred into the secondary - * registers. - */ s->ptr =3D (s->ptr + 1) % k->num_regs; - if (!s->ptr) { - ds1338_capture_current_time(s); - } } =20 static int ds1338_event(I2CSlave *i2c, enum i2c_event event) @@ -201,6 +195,10 @@ static uint8_t ds1338_recv(I2CSlave *i2c) trace_ds1338_recv(s->ptr, res); =20 ds1338_inc_regptr(s); + if (!s->ptr) { + /* Read-only: a wrapping write must keep the bytes it just sent. */ + ds1338_capture_current_time(s); + } return res; } =20 --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869062; cv=none; d=zohomail.com; s=zohoarc; b=T9tFSbocQY26j8oaZ1KjJFBagLfvzvxxaqx4D6XJtIRHRg94/wO1y9rkTtfWcbOD7kqHuLCMd7hFWQA8Sy2EHjDUA9TvoSE2pQVqjxOxhv7/IrtMDwfP66lz5XjkvM1/w6Mr+o411Bn59HQVHbh1uCsX3eR6X+nZSUwFG6e8Vj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869062; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=9jZpvK/2JIYvTgChmDwtU9W+dxG3f61FuvNfLFka24M=; b=namfhxuLy+ILXBv4DrOyDdU+V2FpakyYQcvU5XiUTWBGJG8HnZr7scZOV8dN8wnYkNQrdS1RwnOOI5OiCXbTMbgyi9XSgM+7M9R+pbF+p+bdlVv5M4rgmxsWZ4KDrVGD/XFdzu+Dd48IJP2iLMtem5zJRWm+QBgJVlAnW0VaVPk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869062587712.8276045752975; Thu, 5 Nov 2026 00:57:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtHh-0003HE-8M; Thu, 05 Nov 2026 03:57:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtHe-0003Gi-MZ for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:22 -0500 Received: from mail-pg1-f172.google.com ([209.85.215.172]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHc-0003gU-Jo for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:22 -0500 Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-cc4aa0246b7so790856a12.3 for ; Thu, 05 Nov 2026 00:57:20 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b2cf31acsm2819893a91.0.2026.11.05.00.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869038; x=1794473838; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9jZpvK/2JIYvTgChmDwtU9W+dxG3f61FuvNfLFka24M=; b=tgkjhy5Bsb2Vd9KwqUL7IQrf0RVVKap30IPR7FZqOESgFz1vJmUpPsi6VVzw3iDRBv hSSupCqkv/X2mlVEVGDqH3xJlSCvIsCdz5PKZFY7wnzkGbhxlNTuW68EVVnXkzbi7o0b 8KCI5jwsBJc87Q6pIOKMSAF95/xr0uWct7zwXAY9D7LNQ5BpCc9aQg7sT22MAK88YHC8 CNUYAgWUQXiypRzW//gRYBdBJpfNlvO9cwWWCSxfOtOMRjUeDt1wDjlFP/7etR9IZhNt AA6xK7Ha+4fDoM5DluTbWlKD4hTi3SqbKPKLaSOYM0aNhMzoV2fl/j7zF9FLIfAf/plE +l+g== X-Gm-Message-State: APuU4Z/bbs8AOpN3nFleK2t6Mac2CqJZkQ2f6gUi/Loe9LrpklUuT2fo LrA/nozAvTr2PvCNQbhhGkLhAfl2gNANhlvYgdMIPvrp1Kj84q2HGcOSQoU69g== X-Gm-Gg: AYBFou1BzGJGi1rw+74XKcYJ7rv8UUp1EbQFIftW1TBLBUsffu26XSE4251j2fcQ92U z8ne1ld/vd5m3/TbuYV41kYyTFneGVmqHDTs+OMRyeY96Pqfg3dmaCbpgSONAUKKriVF6YiVkxr bD0/8NMskJOLv/xwG4zYAnX0ZmFuHbLN8qzn5eACuUoa/BMPS8z0t6GI6+DmJcdBdM8+xUNI/bm tsEKnV2ZmqjzijwZWx7d24E4vxnsvxEaiSCLZ9s49+U8bBaZqOuIfPmm1y5ZOlI3Qq8bfvrfAur EaXUUGTEHoNgI86zxZgbEI/KvtDO5IKOMX827IUEUufLUQ5Kwgov1TkdqzEiY6BGw5ys3bhpPDh aqi6nD+V2OEvhfxc31HvwKV+OLV2Bb0ukcUiQ65lrpBsf5Sg3GX4keL9ijSeGau7sScgb1j0XUq 0flkGy/z9LEkB1SpwCJ+b7xsELQNOooJ5i3jDlL7SW65dost7pat7QPwBfpPG8D0RLAvlbhGsom dEI2sCVHzsuKHxjojiBIu7OQ+UHRf1pXviixP3/NkvFDMZD1QCUpVodCbCUiV4nTrxNMC7K7bVv v+dY6Oo7T+AQcTYNh7OTiiSohQjMtbhH2xiw5R3ZuXKUftTs8jWz+kz9z8mCXCKyZGgPrzGbeB1 fNyNRlw== X-Received: by 2002:a17:90b:4c52:b0:3b0:a4d1:6d7a with SMTP id 98e67ed59e1d1-3b0a4d1700dmr2715390a91.31.1793869038514; Thu, 05 Nov 2026 00:57:18 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:40 +0800 Subject: [PATCH 04/19] hw/rtc: ds1338: add a persist-on-reset property MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-4-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=2773; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=qmvk0g/rmD++ZnSC5okHJqYVp2DjqufV612HoOi6RBE=; b=NQSJsxRYfHyZJVlxOFC0ObgfDRhQRJ+qIor2L0kbQWc2aeexcOBdllhrxwWVfdBVSxv3zlWra ghpOc/sYj+iC81Jx6RHrIGaXrBDJOSYflumCYsCSJQeWNC7KCqVkWvz X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.215.172; envelope-from=eblot.ml@gmail.com; helo=mail-pg1-f172.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869064364158500 A real RTC keeps counting across a reboot of the machine it sits in, and its register file comes back with it. The model instead wiped the registers on every reset and resynchronised the clock with the host. Add a property selecting between the two. It defaults off, leaving every board as it was. Signed-off-by: Emmanuel Blot --- hw/rtc/ds1338.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hw/rtc/ds1338.c b/hw/rtc/ds1338.c index c5fc74e6ca..21deb94689 100644 --- a/hw/rtc/ds1338.c +++ b/hw/rtc/ds1338.c @@ -22,6 +22,7 @@ #include "qemu/osdep.h" #include "hw/i2c/i2c.h" #include "hw/rtc/ds1338.h" +#include "hw/core/qdev-properties.h" #include "migration/vmstate.h" #include "qemu/bcd.h" #include "qom/object.h" @@ -56,7 +57,8 @@ struct DS1338State { uint8_t nvram[NVRAM_SIZE]; int32_t ptr; bool addr_byte; - bool osc_stopped; /* oscillator halted: time is frozen */ + bool osc_stopped; /* oscillator halted: time is frozen */ + bool persist_on_reset; /* keep the registers across a reset */ }; =20 struct DS1338Class { @@ -263,9 +265,8 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) return 0; } =20 -static void ds1338_reset_hold(Object *obj, ResetType type) +static void ds1338_power_on(DS1338State *s) { - DS1338State *s =3D DS1338(obj); DS1338Class *k =3D DS1338_GET_CLASS(s); =20 /* The clock is running and synchronized with the host */ @@ -273,11 +274,29 @@ static void ds1338_reset_hold(Object *obj, ResetType = type) s->wday_offset =3D 0; memset(s->nvram, 0, NVRAM_SIZE); s->nvram[k->ctrl_addr] =3D k->ctrl_reset; + s->osc_stopped =3D false; +} + +static void ds1338_realize(DeviceState *dev, Error **errp) +{ + ds1338_power_on(DS1338(dev)); +} + +static void ds1338_reset_hold(Object *obj, ResetType type) +{ + DS1338State *s =3D DS1338(obj); + + if (!s->persist_on_reset) { + ds1338_power_on(s); + } s->ptr =3D 0; s->addr_byte =3D false; - s->osc_stopped =3D false; } =20 +static const Property ds1338_properties[] =3D { + DEFINE_PROP_BOOL("persist-on-reset", DS1338State, persist_on_reset, fa= lse), +}; + static void ds1338_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -289,6 +308,8 @@ static void ds1338_class_init(ObjectClass *klass, const= void *data) k->recv =3D ds1338_recv; k->send =3D ds1338_send; rc->phases.hold =3D ds1338_reset_hold; + dc->realize =3D ds1338_realize; + device_class_set_props(dc, ds1338_properties); dc->desc =3D "DS1338 I2C RTC with 56-byte NV RAM"; dc->vmsd =3D &vmstate_ds1338; =20 --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869092; cv=none; d=zohomail.com; s=zohoarc; b=eORbrw/PMtdLLloVFT5xIeWgs01A790aUayI8rd9wahXxOttAwtrsN/uF8S3Rqrgm7ydK5sVJ/uohygzz3iZiV0+LstJoPZS6ko9NL2M/nQFF7dy/1nu0wL83Bg9jIt0co5L6wWS3Ll9RhFJ75MQCMBmlJK4N4zFzAMiHcWcBl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869092; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=xmNroMpGWl2lemJA5PX/kG1o2rPRZcL22w1qYRUbH5U=; b=T8u9/nFdmuJmU53ySysr51KhQiJFIwuACtisPDmXC6yQFbRfHoYaZLnb/ynPJYBSsxDCCu6Sn7v45R2xKeFr/Mo/nKRywcRMDXFP5UhwqJPATfKyh0heCUUGIU71uNRxSMXU5LzJD8rNHNazm5jE+NV4ddhZtbm5XRMvQOiZts0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869092829406.69567551843136; Thu, 5 Nov 2026 00:58:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtHm-0003NF-Ad; Thu, 05 Nov 2026 03:57:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtHl-0003Mj-9u for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:29 -0500 Received: from mail-pg1-f182.google.com ([209.85.215.182]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHj-0003iB-JQ for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:29 -0500 Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cd60c5da24cso1029750a12.0 for ; Thu, 05 Nov 2026 00:57:27 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b3265a52sm2711139a91.10.2026.11.05.00.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869046; x=1794473846; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xmNroMpGWl2lemJA5PX/kG1o2rPRZcL22w1qYRUbH5U=; b=z1vN2rQtDI6j8WlNpYi0yDKahmLRTLMiuQEuKOJtO7dOOX8hIFB61HZLcSdWgrPZTr Ek2+IwRYYv3+jEkaQgLA83pYMouwTq+rPPVgQyfDEtxt2u30B8P3kvi08G87iwUap4ex 0FZDwwMDoqCMVmcXcc5XBY8ePSOo1JCeh/eiS4PukCPJtepYKXezmxhTZVXnREyPAi3/ LZ62lYfOHfYCsogaQFEA9OZTW3SCkJ/ALOlMaVZ88oLpka6+XeoHbVskZud7OP+IhTpE x7FqeOi2eSTrQCUg6VOMiDH24x0VbcK0RcC97MAraqTG9B3yJcv8XWhD2JkgQ3U64U/V MveA== X-Gm-Message-State: APuU4Z+XukAGdC7ykQKE9uHqhnNLiMbJ9oyKUrisaMtyecbXy5cTQaW3 HZPhN9Wl64d9hEimZyOGHbSN8LulvH6a7bwhTYW8vQHuylcrfyVdY2JqNiTBbjYwXLs= X-Gm-Gg: AYBFou03ynJYjGL1/zFaUiIiU7NTGPZkMavoZm4pn3XSMWGON/kQ4xIIegxGxgoRzAi u6f6AoPYdbrtiCodkQO9U0iPAt4i+QSgMMMhg+7IFuaVCBMszLRkhSPVT07TDf4kaTs5WhcpS+5 bO2umi1scz82BMaUpR54jx6kyzRhGQF17sCtF5iCSmNYRcoOebpWX1NYz6HwDfKHaAs4GeNR0FV wrsObj02huJPEgejEazNtsUJbHrYE8HFdJle351NpFgUsiSEWb8DgugaxF/yTgsaFASf+1P2uzL 9AB4W1bKkmUUyeFDZiqBsOusHGj5lq9M3U8hZurkUgjlf0NftjTEfligkebTrOoJ47kzqRp0kxH 9nowguOvixbY/u1QN9+wAHd8Vb0FOnK9TbrxSi2TFVMvWNhVYgoG46/mBbY/rkMJ9XX7UlBWrru 4FRkHNEJ+yLYx/5CS/UpJMIIw0sdCn5BONNTUkqQEbU2MZgERWPuxbJ/uGTTTCDb/03ih57VTe/ WCFouGrDpRHE7Ma3XrAxhx89ao7EvAhSuqJgWH7VUeRan0aCKNw8yT3ga1TLk6/ZmuCllPcYDqx wThsPAUM6eNdWoGecrtP5dWa/Nk/hZBVdlIkbZTklLTfJyXvE5dWGfW1KqBxAEzlm2M5XPgcfkP uiczeag== X-Received: by 2002:a17:90b:4cd2:b0:3a7:3474:b1ee with SMTP id 98e67ed59e1d1-3ae897f8a0dmr16693420a91.60.1793869045936; Thu, 05 Nov 2026 00:57:25 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:41 +0800 Subject: [PATCH 05/19] tests/qtest: ds1338: cover the DS1338-specific register map MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-5-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=4130; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=rUA8d+d6nAk/JSdhMcKg9/bMZjbXLM8xkCDgafupUKA=; b=nTMmZs6Crxs8ZDQv8VLlrJVHmH0Kj+LaeCaWAudgJBseGIZMLQOsdy+KN/Xxgp4qabm4YB8bX lja3LeP5iT5DOb46nZ1awNaenhBfgr0PB6AkVeb/mN81E8h5eIay1ap X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.215.182; envelope-from=eblot.ml@gmail.com; helo=mail-pg1-f182.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869094630158500 The register map is a set of per-model class properties. Pin the values it holds for this part, so a later change cannot alter them unnoticed. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1338-test.c | 67 +++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index b8d0e65ec4..6066a34846 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -24,6 +24,15 @@ =20 #define DS1338_ADDR 0x68 =20 +/* DS1338 register map */ +#define DS1338_SECONDS 0x00 +#define DS1338_CONTROL 0x07 +#define DS1338_NVRAM 0x08 +#define DS1338_NUM_REGS 0x40 + +#define DS1338_CTRL_OSF 0x20 + +/* The clock and calendar come up on the host time. */ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) { QI2CDevice *i2cdev =3D (QI2CDevice *)obj; @@ -32,7 +41,7 @@ static void send_and_receive(void *obj, void *data, QGues= tAllocator *alloc) time_t now =3D time(NULL); struct tm *tm_ptr =3D gmtime(&now); =20 - i2c_read_block(i2cdev, 0, resp, sizeof(resp)); + i2c_read_block(i2cdev, DS1338_SECONDS, resp, sizeof(resp)); =20 /* check retrieved time against local time */ g_assert_cmpuint(from_bcd(resp[4]), =3D=3D , tm_ptr->tm_mday); @@ -40,6 +49,56 @@ static void send_and_receive(void *obj, void *data, QGue= stAllocator *alloc) g_assert_cmpuint(2000 + from_bcd(resp[6]), =3D=3D , 1900 + tm_ptr->tm_= year); } =20 +/* Writable control bits round-trip; the reserved ones read back zero. */ +static void test_control_register(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1338_CONTROL, 0x93); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL), =3D=3D, 0x93); + + i2c_set8(i2cdev, DS1338_CONTROL, 0x4c); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL), =3D=3D, 0x00); +} + +/* The oscillator-stop flag can only be cleared by a write, never set. */ +static void test_osf_write_protect(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, + =3D=3D, DS1338_CTRL_OSF); + i2c_set8(i2cdev, DS1338_CONTROL, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, = =3D=3D, 0); + i2c_set8(i2cdev, DS1338_CONTROL, DS1338_CTRL_OSF); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, = =3D=3D, 0); +} + +/* The user RAM returns what the guest wrote to it. */ +static void test_nvram(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, 0x08, 0xaa); + i2c_set8(i2cdev, 0x20, 0x55); + i2c_set8(i2cdev, 0x3f, 0xc3); + + g_assert_cmphex(i2c_get8(i2cdev, 0x08), =3D=3D, 0xaa); + g_assert_cmphex(i2c_get8(i2cdev, 0x20), =3D=3D, 0x55); + g_assert_cmphex(i2c_get8(i2cdev, 0x3f), =3D=3D, 0xc3); +} + +/* The register pointer wraps at the end of the map. */ +static void test_address_wrap(void *obj, void *data, QGuestAllocator *allo= c) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1338_NVRAM, 0x5a); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_NVRAM + DS1338_NUM_REGS), =3D= =3D, 0x5a); +} + static void ds1338_register_nodes(void) { QOSGraphEdgeOptions opts =3D { @@ -49,6 +108,12 @@ static void ds1338_register_nodes(void) =20 qos_node_create_driver("ds1338", i2c_device_create); qos_node_consumes("ds1338", "i2c-bus", &opts); + qos_add_test("tx-rx", "ds1338", send_and_receive, NULL); + qos_add_test("control-register", "ds1338", test_control_register, NULL= ); + qos_add_test("osf-write-protect", "ds1338", test_osf_write_protect, NU= LL); + qos_add_test("nvram", "ds1338", test_nvram, NULL); + qos_add_test("address-wrap", "ds1338", test_address_wrap, NULL); } + libqos_init(ds1338_register_nodes); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869113; cv=none; d=zohomail.com; s=zohoarc; b=SLDFwp+t2h648XUrPh+ZcaXA5oXAP/e5P5Ee80kkZxvc5ERAedEVy6AFbFXf9NpmowzJysBVLbro88AnBX13hlf3A7UFNrgMFtetj3qPuKF78EHFXlqFG7G8OYmxeqnZnhxfC0yxYXc4jM1jdbiHUVy+xRdUyLAaWwS5N1cN81w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869113; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=i2TFQ/K2+n3LqcTPLQTKo2+VbMDYp1DEdeJ43Ldv0iQ=; b=XYmx9+0Rsk5mOhjRYT/IwEfFexVue1ixrByFlEoUBK8wFVPKRMLNMRKkDVXsHzGqbbE5QDULRjbcOO5wZJ3Q+R0DVleJjLq5PUx+Sc4Av+Wuk65gKqCDpwKtSmk8/DnTYiE95HMkT0zJcEABwMNHQXLkye6RRDXGIZKYhU3fIPI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179386911306580.29534307689323; Thu, 5 Nov 2026 00:58:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtHv-0003OO-E6; Thu, 05 Nov 2026 03:57:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtHt-0003Nq-8x for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:37 -0500 Received: from mail-pf1-f179.google.com ([209.85.210.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHr-0003io-87 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:36 -0500 Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8a089dfee18so252190b3a.1 for ; Thu, 05 Nov 2026 00:57:34 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8b09b089601sm1837217b3a.30.2026.11.05.00.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869054; x=1794473854; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=i2TFQ/K2+n3LqcTPLQTKo2+VbMDYp1DEdeJ43Ldv0iQ=; b=Q5X+xKkV62DruwabrYZbVBGPNEluyZ06ntPpiCYN3aEzjMjPkmgXF+voMpxNXexUK0 OdEsWzRUD7meRn8lZ1S0my4h8AA8/YuOdq+6otE+cnuz3cwTZj2YLIlPOmbm3vmEKBun XXMthCyIGuyQjK57oKh7jdRuTFMYNl0KJv+gkgbvTqtcvFxP7oGRJc+ydv+VbmUm8Zte sU/dJi1AgPm/oNuw9bu7S1eD7bTNeeXG3+F980UMFhBKsHWsO1f0yJMkicUzC8ntQS5w bYK7OugqrcOdzjovWvFNYKXo4ldmS+3SJICIsLuZCThYnhbexzwz6q5Dql2EJRC4aSf2 3WQw== X-Gm-Message-State: APuU4Z/ybOI38vBAQv5l3BLygATUHZZW2i295fY8wCFy0KK7Tl7sylAe KS7OnOPkamMHNADfTxakRBWkwQE1eFCi/td3ISGvJ4lc5GIphy+CmNLpnRcMDLT7hq8= X-Gm-Gg: AYBFou2VrziQoWz1DdNyAgs1Wh7K2xI9wKHyiFiJLhXKkq68HStlVYly/p8r1WxV4vR 8Ke4bVbXdKjL5lk/gB5NH3ohqTOeqbo2OXGq/cwaNUylGoFRE5xAJCyBOhT+dmfcZFxr9LwaiSV eIs+mxfu8kgnPFgQhtrJsEFmqFccQsUt7Yuyt8Rf+8PdU33MQemGgAEO3Er+ZIYfPE+kYnx+aAl fLJDd8nm5AwF256arBs8rAKuzq1jaeZy7aw8TG2uUZhhoLh+pBgrJico5WACZJrKSUGmAEEwtsb X/Y2r5at1wUtnrdtoga6bLxTIjbairZp2Fg+7bzPP2k4kWyk94pNMfshuOtIhmIBqM5expyudjH gAS2ObU2bMJR0heiEB7tiuSwC9C+ntoe7n8Gl/epXarLf49hzqUvGQeBDuVpxKYNSp4WlE4UToT uTI7F5vFcUTup3EUJxZcYsNDjTe2fC9vhzBoT3hIwJnWJUUsKRFkQJYU+A9/u+Q9n/9Kq5y4L1/ EGGog6UMlmlycnJGRxQ659mwMbXwZsslCoHog7wNSVHJnD9Ebp+2CC/eRYPPmenbWEUBYRazGBY Y8yyQbza6tU7xE5ibhkesJE3yR4CSFEl3wlvNz5x5HzS9E42qZxjikoNR4E3ypG8dYovD9ElSiZ e3hrsivVswuaG6faWkvwz/BVhyro= X-Received: by 2002:a05:6300:6186:b0:3e0:c2ce:3f71 with SMTP id adf61e73a8af0-3eb983e5911mr1315097637.37.1793869053599; Thu, 05 Nov 2026 00:57:33 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:42 +0800 Subject: [PATCH 06/19] tests/qtest: ds1338: cover the power-on register defaults MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-6-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=1861; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=sNuGg4g0N4khunE3Y+1axZd9urwfd6Pf1mqgjJj3DK8=; b=XWSEM0g75FqI52Z+SqjmB5ZhBbzHFfKNyO/bA7AROXfJqbRbJVjHiXVQgD/rx1usAYS+be3Ye kSJtO5k03bkBiVx52iARyC6HBm/fgVnrg3qFuctzv7uNCJXSs1bFMpr X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.210.179; envelope-from=eblot.ml@gmail.com; helo=mail-pf1-f179.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869115030158500 Nothing pinned the reset value of the control register, which is how it sat at zero rather than at its documented power-on state. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1338-test.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index 6066a34846..fad0ca53d4 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -31,6 +31,7 @@ #define DS1338_NUM_REGS 0x40 =20 #define DS1338_CTRL_OSF 0x20 +#define DS1338_CTRL_POR 0xb3 =20 /* The clock and calendar come up on the host time. */ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) @@ -49,6 +50,14 @@ static void send_and_receive(void *obj, void *data, QGue= stAllocator *alloc) g_assert_cmpuint(2000 + from_bcd(resp[6]), =3D=3D , 1900 + tm_ptr->tm_= year); } =20 +/* The control register comes up in its documented power-on state. */ +static void test_reset_defaults(void *obj, void *data, QGuestAllocator *al= loc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL), =3D=3D, DS1338_CTRL_= POR); +} + /* Writable control bits round-trip; the reserved ones read back zero. */ static void test_control_register(void *obj, void *data, QGuestAllocator *alloc) @@ -110,6 +119,7 @@ static void ds1338_register_nodes(void) qos_node_consumes("ds1338", "i2c-bus", &opts); =20 qos_add_test("tx-rx", "ds1338", send_and_receive, NULL); + qos_add_test("reset-defaults", "ds1338", test_reset_defaults, NULL); qos_add_test("control-register", "ds1338", test_control_register, NULL= ); qos_add_test("osf-write-protect", "ds1338", test_osf_write_protect, NU= LL); qos_add_test("nvram", "ds1338", test_nvram, NULL); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869091; cv=none; d=zohomail.com; s=zohoarc; b=HPuJ/dDz7jyrSgcyXnE6G2vKbpREMA/zJs0MDlvaRJ1zLyDKShRNEQeATwPjtEsE6TcLX/geMGUBgL/VNAFfSqakEpfJbWgz/Zn93J9mJGbwOJlO+Qr1Ex5gBIOSg8iEyAKPcyWz5Ru26YPz9GvNDvDSpykeUSxC16ilncFCjio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869091; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=QSX7oFL3j7413Q4nQT+SGQuVL91uJZdU8V0ijp2OEps=; b=R4quvba5UuxcsugBfIcJgs/8sEzuSiVS8wWpShApL02fDJo4Zc8lTIZry3LYsiROT3CbekTp4hdjAdMc1Rtf8DVSOMS+PUzliw5M8+VmWnbceprL+RPeo7c+DthINfL1ShNAOynql4JPF3a2ppU4W9LtzK5J9vaXiB9vqH8nADc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869091754352.388496136767; Thu, 5 Nov 2026 00:58:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtI2-0003TV-6q; Thu, 05 Nov 2026 03:57:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtI0-0003Re-F9 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:44 -0500 Received: from mail-pl1-f180.google.com ([209.85.214.180]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtHy-0003jN-Ks for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:44 -0500 Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2e96502e447so13903215ad.1 for ; Thu, 05 Nov 2026 00:57:42 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ed0906175bsm15699265ad.27.2026.11.05.00.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869061; x=1794473861; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QSX7oFL3j7413Q4nQT+SGQuVL91uJZdU8V0ijp2OEps=; b=CQz9jjT+Kd73bDYu8LQdyTnh6YlaFa/ECcLKg5k1AyLUnGqMlpyVNbdqofD360pkRa XYMf7+yc1q4K3ZdwlGUbEqvKUC3p3gx2jqQ2Hz7W78Z2iYRBj3bqWppyNiLToR6V+oXO ZGEKEdmCrSLkdZt5jdmcr01Yy5rA6Vc6EWPvJ6RYDhOICk8N4BMZnYaoZXqYRUrbdjMm LcE3J/qPeXaHYqMMtNoWKnxmeL+TyYdKsDySvAxVWTOnr0e2d+yOv5hTyVupZbvaCN+Z RJiKICEq5GnzFUhyaGEDEOHT+lc5T23SmZaXIBBzZcP/v4Xgiwat5lfnkFM5dHoRlGbF Cxmw== X-Gm-Message-State: APuU4Z9bLlmetJiZkzrE+5/JFgr57OJNu7HYRRflmpcPN5j37Iab9dJk lHp9qCchhN+leUnP1JESHqXU97eNtQFqEFj2VDfzV2zGspFi1y0OXfSuxk2uAOtAAJ4= X-Gm-Gg: AYBFou1u/KBGCWAo1RFvtmSsczvv/M9rQYHLe2BSgtkPX9KUdbYoPb/QxYkYub9e37v UGe2oP5FRzmpm26IJVTTaqvrLdZC+Ly2+U2OZIBwQb/ObrOx645Xr7Ffr07uxFKEAmZOjBKicxg JmJu3NbgHfnG197C3j7xl2gt1LUXJFEZGZjmrjVb7dvwOPR4usm4xv9B7JZKy4zwKzRu58/SUJE NvLClqBXeErvN7mG0iDFIijUvONCo5PNunguPP1Xqb9Uvpjqv1ml7bPSepD3isIDPppaCnvPtJQ jjNgRKlRGv2EXfxNBABLq6MhvnySuPlWyTju1etwwislMUz3d9uWXrYIONSePZH0Dd5gxU/XE3v fKFZQOjE6RLTD+B6hrbREifyPyFW01Fo6Z8Z2tzYt8hL1Rxf4XA3ZCHl2RLZGF/PAp9jg8DbCcN 27Wn4LG2C3/KiDRDO0LLgZQQmmxPRT8yZKniUZd4n7BUvdRSauYLjR9ooQU6DBGYUPsO3cx+Sju xEcKxBOolWP6zgGg4VaRu1OGswLiga6fq2H3eOTcoMpquPqs1wYjwIox1PnKalzj6k06H+kvhMS f2q3tAv3lvkeLJ47HGiAhajrhXu3MzFEq1W7Ro5V9USMYIQ9DvQ8b3XMmgwwGKwGiqVyzFAroOn nIzj72A== X-Received: by 2002:a17:902:ec90:b0:2e8:1910:e398 with SMTP id d9443c01a7336-2eb3649bf6amr187321315ad.9.1793869060817; Thu, 05 Nov 2026 00:57:40 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:43 +0800 Subject: [PATCH 07/19] tests/qtest: ds1338: cover the clock-halt bit MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-7-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=2998; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=ZuX+spACHMjQ3cHCqU6XOjJREiGhA+BBWl2nnVGddEk=; b=iB0UPmJGsAbiIGYduo3YMEceUwkNmXgz5aYh98m6vjvwTeFiV2iTlRfj+XH7ZpM5MayC9LLbU eLpkqAV2nH3A2fCG+fJJTqiolQENZTRjDmxCVuPr15FHDuB0+ST7otO X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.214.180; envelope-from=eblot.ml@gmail.com; helo=mail-pl1-f180.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869092793158500 The clock-halt bit had no coverage, nor did its effect on the oscillator-stop flag. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1338-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index fad0ca53d4..1b73dca98d 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -32,6 +32,7 @@ =20 #define DS1338_CTRL_OSF 0x20 #define DS1338_CTRL_POR 0xb3 +#define DS1338_SEC_CH 0x80 =20 /* The clock and calendar come up on the host time. */ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) @@ -85,6 +86,42 @@ static void test_osf_write_protect(void *obj, void *data, g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, = =3D=3D, 0); } =20 +/* Halting the clock freezes the counters; clearing the halt resumes them.= */ +static void test_clock_halt(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + uint8_t frozen[7], again[7]; + unsigned idx; + + /* Clear OSF first, so that halting the clock is what sets it again. */ + i2c_set8(i2cdev, DS1338_CONTROL, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, = =3D=3D, 0); + + i2c_set8(i2cdev, DS1338_SECONDS, DS1338_SEC_CH | 0x30); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_SECONDS), =3D=3D, + DS1338_SEC_CH | 0x30); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, + =3D=3D, DS1338_CTRL_OSF); + + i2c_read_block(i2cdev, DS1338_SECONDS, frozen, sizeof(frozen)); + g_usleep(1200 * 1000); + i2c_read_block(i2cdev, DS1338_SECONDS, again, sizeof(again)); + g_assert_cmpmem(frozen, sizeof(frozen), again, sizeof(again)); + + i2c_set8(i2cdev, DS1338_SECONDS, 0x30); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_SECONDS) & DS1338_SEC_CH, =3D= =3D, 0); + for (idx =3D 0; idx < 50; idx++) { + if (i2c_get8(i2cdev, DS1338_SECONDS) !=3D 0x30) { + break; + } + g_usleep(100 * 1000); + } + g_assert_cmpuint(from_bcd(i2c_get8(i2cdev, DS1338_SECONDS)), >, 30); + + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL) & DS1338_CTRL_OSF, + =3D=3D, DS1338_CTRL_OSF); +} + /* The user RAM returns what the guest wrote to it. */ static void test_nvram(void *obj, void *data, QGuestAllocator *alloc) { @@ -122,6 +159,7 @@ static void ds1338_register_nodes(void) qos_add_test("reset-defaults", "ds1338", test_reset_defaults, NULL); qos_add_test("control-register", "ds1338", test_control_register, NULL= ); qos_add_test("osf-write-protect", "ds1338", test_osf_write_protect, NU= LL); + qos_add_test("clock-halt", "ds1338", test_clock_halt, NULL); qos_add_test("nvram", "ds1338", test_nvram, NULL); qos_add_test("address-wrap", "ds1338", test_address_wrap, NULL); } --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869098; cv=none; d=zohomail.com; s=zohoarc; b=EpAsfk4GabPf7jbVbv3WvCXAj2BEurtaI3AgQiaxktiNK0w2l0MXMykvl7rpXCuW/IOAQCjM7OJi5ELlLlYiQWUG10J2DX1JTgqPbsvGVmVSkJLezt54Uc/xuhDMWZaseIcQEtBCZR7oXbacijCf8RZr8PFgSmyWN6Uk5paMVdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869098; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=dMwnpBYmBX5DRYiAUaLE3vWJxcd/Dwa3k0x3lhQO1fU=; b=m88qUITIFltroWLxQ/bX670Xsxnzw1F2yBSsi7vP6Be9/eD/tkUZGyJDeshFJ7fRFWS2PhCtKTROV7SVQao8mkcooPmz43j4NChDYfi1D8562ePBGm5IHFuKkW66FQ2msBORYSY/jsKnhsi52KRjfUWIXmB9J4lzOR0cuyLG00Y= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869098259607.8997398128542; Thu, 5 Nov 2026 00:58:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIL-0003qu-Jo; Thu, 05 Nov 2026 03:58:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIA-0003WI-Hc for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:54 -0500 Received: from mail-pj1-f47.google.com ([209.85.216.47]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtI6-0003jz-TK for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:57:52 -0500 Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3b0b3438540so404191a91.0 for ; Thu, 05 Nov 2026 00:57:50 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cdb467f8355sm1917049a12.6.2026.11.05.00.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869069; x=1794473869; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dMwnpBYmBX5DRYiAUaLE3vWJxcd/Dwa3k0x3lhQO1fU=; b=m98kM3F+Mt7CRyZUP33YMRCzA0Kw5zxJp+LXxB/4uxkl5dYv7BovrJ+DGMY7n1GtrH kVjL6iiZY8P8w9DDai5Dv0+3YkBOD54HbuQt4g0KvRM4XIT26PLxbuxWM/SnBjMMTKuZ IHElFuAEC84p7EA+CQm4unW53sPUPCCY3/xgDo2RiGf0cB1/aMJgLpdwvZggU8n90CDK 0tontevUgUxlnSUcd1dLO3E7UHEfFk57INXgwiPBaEIrVNx98gXEGbrSIKltLDlTZEAt kuIyalqwN4wSscSCcRu0zw5830z7GYdgK+OOiyXSPg0gIJoKIch0oGtM+dr8M8FOW0N+ JS+Q== X-Gm-Message-State: APuU4Z/gTGOUBTuvh/qzOOzVDy6xjfoDZZe6lyC0brL0dTSHNyihcgMA rOk1KnyM3I9obFhG8ZiD3+H+NBQ/447KZbBb/XNbrbUel3ILliupJBgX6GYky612cTI= X-Gm-Gg: AYBFou1TLTWqFWuhBiNdwaDzKfe5rs1BD2tzyREqZTUab9CGqy6+SdClFBda0uPWx5i Ffj+ku+2BcN/SVtgTZJf401jw6ypwYX/LKS3BOpq7EXAsKB8acuw2ZeudBaKWDH+B6zBETD/ejt GKhQN0UYfwPb7f0p/g/x6orxwdaatownVn3oTWsuVvzLr1TEYTTWwrQ66orZmFNg1z0vUL+K1Qi 39SkkznB5ATW6F9wTVw0n+2kqciK8KsQ4REwbQrsEx7XvkuAn8ky4YZ2Hx7TNI/78LGZmOscvdq jzhyV46ETJS4SI1t/mOgCmpqECh+WhPAg7tX1hHtL0Na0VrGzP3ITzG6LNzC+CaeIXdYQ6DD/c2 I5A/34IH6NI9++19FxP0WojFpxRCTPhNLM3wkMvg2Jr8R/ETQ7NcyxSgDWoXLq96ARezKe3wtSN HudEiqVKTKcHoU/P1kA+eA9pPBCWr0eu4CIOGIUK48tDBf6GeRdr44GsIqmEEuZvBuBkZ9Swvnm ON4m11dFwacVF6ywficCAVnuy2BS9omBxxDSGk03HW7Jza2rdrJKPQHeXQ/qCQ6AU58peyyribd OkUCHbiAYVxa/cYkSrAa+Q1G7h8jVRWrQw3QNysJi5gEqTrUd5t1OuWxlJxWWJC2/tONVMD9Db1 NTtiZounL54jjhUBG4M1o2+gt4cU= X-Received: by 2002:a17:90b:5485:b0:3ad:c482:ae9a with SMTP id 98e67ed59e1d1-3ae8957cc71mr15395829a91.1.1793869069256; Thu, 05 Nov 2026 00:57:49 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:44 +0800 Subject: [PATCH 08/19] tests/qtest: ds1338: cover persist-on-reset MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-8-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=3613; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=C9yegjbOQTpe/jjT1t7Ut7zcw5lIqG8k17Dnwvy8ngI=; b=mBI9QuIER9uA3mdSNfD/JTx/9gJI2qSEhcohXl17PL18qmGtgbBrWU40rOLuSRexA3WEDONPQ a0xTpN86corBKXyPd9ErXz7g4aeQaiVPdrj5PEz6kLn7h+erXCHKi8W X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.216.47; envelope-from=eblot.ml@gmail.com; helo=mail-pj1-f47.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869098732158500 The property had no coverage in either of its two settings. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1338-test.c | 54 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 54 insertions(+) diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index 1b73dca98d..1b9c02d931 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -20,12 +20,15 @@ #include "qemu/osdep.h" #include "qemu/bcd.h" #include "libqtest.h" +#include "libqtest-single.h" #include "libqos/i2c.h" +#include "qobject/qdict.h" =20 #define DS1338_ADDR 0x68 =20 /* DS1338 register map */ #define DS1338_SECONDS 0x00 +#define DS1338_YEAR 0x06 #define DS1338_CONTROL 0x07 #define DS1338_NVRAM 0x08 #define DS1338_NUM_REGS 0x40 @@ -136,6 +139,50 @@ static void test_nvram(void *obj, void *data, QGuestAl= locator *alloc) g_assert_cmphex(i2c_get8(i2cdev, 0x3f), =3D=3D, 0xc3); } =20 +/* A reset restores the power-on state, unless persist-on-reset is set. */ +static void check_reset(QI2CDevice *i2cdev, bool persists) +{ + uint8_t year =3D i2c_get8(i2cdev, DS1338_YEAR); + /* A year the clock is not already showing, so the check discriminates= . */ + uint8_t marker =3D year =3D=3D 0x42 ? 0x77 : 0x42; + QDict *rsp; + + i2c_set8(i2cdev, DS1338_NVRAM, 0xa5); + i2c_set8(i2cdev, DS1338_CONTROL, 0x00); + i2c_set8(i2cdev, DS1338_YEAR, marker); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_NVRAM), =3D=3D, 0xa5); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_YEAR), =3D=3D, marker); + + rsp =3D qmp("{ 'execute': 'system_reset' }"); + g_assert(qdict_haskey(rsp, "return")); + qobject_unref(rsp); + qmp_eventwait("RESET"); + + if (persists) { + g_assert_cmphex(i2c_get8(i2cdev, DS1338_NVRAM), =3D=3D, 0xa5); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_YEAR), =3D=3D, marker); + } else { + g_assert_cmphex(i2c_get8(i2cdev, DS1338_NVRAM), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1338_CONTROL), =3D=3D, DS1338_C= TRL_POR); + /* Back on host time, which is where the year came from. */ + g_assert_cmphex(i2c_get8(i2cdev, DS1338_YEAR), =3D=3D, year); + } +} + +/* Without persist-on-reset, a reset takes the part back to power-on. */ +static void test_reset_clears(void *obj, void *data, QGuestAllocator *allo= c) +{ + check_reset((QI2CDevice *)obj, false); +} + +/* With persist-on-reset, the registers and the clock survive a reset. */ +static void test_reset_persists(void *obj, void *data, QGuestAllocator *al= loc) +{ + check_reset((QI2CDevice *)obj, true); +} + /* The register pointer wraps at the end of the map. */ static void test_address_wrap(void *obj, void *data, QGuestAllocator *allo= c) { @@ -162,6 +209,13 @@ static void ds1338_register_nodes(void) qos_add_test("clock-halt", "ds1338", test_clock_halt, NULL); qos_add_test("nvram", "ds1338", test_nvram, NULL); qos_add_test("address-wrap", "ds1338", test_address_wrap, NULL); + qos_add_test("reset-clears", "ds1338", test_reset_clears, NULL); + + opts.extra_device_opts =3D "address=3D0x68,persist-on-reset=3Don"; + qos_node_create_driver_named("ds1338-persist", "ds1338", i2c_device_cr= eate); + qos_node_consumes("ds1338-persist", "i2c-bus", &opts); + + qos_add_test("reset-persists", "ds1338-persist", test_reset_persists, = NULL); } =20 libqos_init(ds1338_register_nodes); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869149; cv=none; d=zohomail.com; s=zohoarc; b=KkWeb1nm+rx6uXJaiSIx9QT3mcHNRtP4elWcD261iCZCcmEbB+7yLyTMq++4iJp8l0TAR/cV93Wi+sX0Ck+l5ZLyLVAiHhpot+WIrNJcdslmCsFMGsqI7WcpU6ayyzz1cXT/o6g420g1IXlPIGmeiqM5W47r4zczUQyGXtyqCys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869149; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=oYoBAtb0sGasvrkB8IWuXlvz+SK9VWJjTLvw46YHTLI=; b=JPlhDof2dVbZC0qRiU43QIBXcAlSr1yuyoWPfLUMDWuCk1x/RuWzSJ1b4+B5xpsk5rmhoXpjHrLiCQoqr00oenkVI/ZZHPUI4bInCYt/5qJzuFO7xhJ3xM7osITFUkUB0D36pFZk07Mot89y8OwRsH8T1XsEUOruUsnHxJLzPLs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869149125637.7942092057095; Thu, 5 Nov 2026 00:59:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIT-0003xr-Du; Thu, 05 Nov 2026 03:58:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIH-0003qo-Ua for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:03 -0500 Received: from mail-pj1-f46.google.com ([209.85.216.46]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtIF-0003kV-S0 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:01 -0500 Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-3adc4590de4so1441121a91.2 for ; Thu, 05 Nov 2026 00:57:58 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b3265a52sm2713011a91.10.2026.11.05.00.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:57:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869077; x=1794473877; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oYoBAtb0sGasvrkB8IWuXlvz+SK9VWJjTLvw46YHTLI=; b=mQ5cwslIBgudHxm5/Ddw7vJewM7Yq4PZMWVwIqXIMl5ogVxziGITl/1MbQfwmq2LNY T2RRtKjCJ6e5aupTX47AJsGaos1/0tIpFTImVkAFdsE/zemNsi1Ov4WVZ0aGqIEFWZ3a zClEU87NP8J4V1Nk47DZBNiW5meRm2ZYaI9aSBIj8mPHGYdW1z4zEAlsjp2W5WVZIKSg CgeSB2z7jKA2YboVHEfvDCHTEe0ZePLKhcWbd/30AbQeWVQfq/NIjXo+60pr3dVHdF5t JrBN+Pi2dvge1lwRMSAP78XWuWL8gsvym5xmb8/NLzO32DIe7D5bkcjOWkIdEg57z4Bu EaKA== X-Gm-Message-State: APuU4Z+SGW2qrdTkzlPOyRi2I9JW5oYq3kc+4KUDaG9MhipVi0VwfwM9 Mu+gNtCks5eJacAftTTJlXZrEsPbpox+lnh89Pl8LLWBkdMSSKFQuYgvgDsbampC+YU= X-Gm-Gg: AYBFou1dhfMfqhRDTSOXMeCL+qUZM6EDw2UwLeVG7VDg92ucwcWLfmM+kh9mI+I4DZv Bs3sm4LS8FzEUBIXG4uC3RYC4VonwcfYHT000ithU8ePHKvdU2DBDgBGHd8lNlac90Rbepe+1dF NO3dC0HTDw8/b5lPe2XtEwLzcXyepqVWUnPZdbJw8bsAQJWj1iwd6ldjTDD3R4j/jXOjn53WcUL 4Qq81sAZXz+CKMIwdQI2sWvWlQ75Nbco5aG5Uqn/cSOmbNkmw1Bh0GGMjulIMgM6wwCBSVfUNnx gtCWnamnx2ahuFJpHikNnvIGbGMzKQcEdLeNQ3lOFbKJtZM/vryUVOzteAygTxTVKqTldliGFi4 pliOMzLTj09Cx6MuU/fyogs0LQBL+bBxf/jnwMrQfbnxVxA+ybUlD+7WD9Y1auGaccf/kWL4k+C QRjjBicSEAy5zjiD5uHtlKlpcskqRaYeCMkCQlolZRX0NS+/x2vqjBV4Wz7VwMaB6Q7kAqc54Z2 8/dSlx532BRR8bX7r4ukwqPYJmL22YjCBLByxhRcQsc8bMwMKhvvBMmMd46r4Q06Rq9929C8OE/ 1i3WYzHwuZ6pFQGeT/RjK1L8g2/advvL2YLfpfjbyV5nWuuG6eHPSainZruM4LGJ7akPhBzTj58 usN120Dk= X-Received: by 2002:a17:90b:534b:b0:3ab:4f1:4f76 with SMTP id 98e67ed59e1d1-3ae898127f4mr16026476a91.24.1793869077290; Thu, 05 Nov 2026 00:57:57 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:45 +0800 Subject: [PATCH 09/19] tests/qtest: ds1338: cover the reserved bits of the time registers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-9-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=2167; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=suWA8DePj/ePX9LP9LtQ2tCEt/OdWCTqNVEUhuz1G58=; b=T8h1VbWrZkrWJgUBcgqWfj6DA4QX3w+5EyDFK5X/4wSt0ooMApSn/C3NHq4HJJ/mkOVRkX9iS 8D6M+RbZ7MIA3+zUUiATwwC6oBLhoSyj4iMQm9dUfo6d6IM8/aDRO8Y X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.216.46; envelope-from=eblot.ml@gmail.com; helo=mail-pj1-f46.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869149782158500 Nothing pinned which bits of a time register survive a write. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1338-test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index 1b9c02d931..9e2e257307 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -125,6 +125,26 @@ static void test_clock_halt(void *obj, void *data, QGu= estAllocator *alloc) =3D=3D, DS1338_CTRL_OSF); } =20 +/* Reserved time-register bits read back zero even with the clock halted. = */ +static void test_stopped_reserved_bits(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + const uint8_t all_ones[7] =3D { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x= ff }; + uint8_t resp[7]; + + i2c_write_block(i2cdev, DS1338_SECONDS, all_ones, sizeof(all_ones)); + + i2c_read_block(i2cdev, DS1338_SECONDS, resp, sizeof(resp)); + g_assert_cmphex(resp[0], =3D=3D, 0xff); /* the halt bit is writable = here */ + g_assert_cmphex(resp[1], =3D=3D, 0x7f); + g_assert_cmphex(resp[2], =3D=3D, 0x7f); + g_assert_cmphex(resp[3], =3D=3D, 0x07); + g_assert_cmphex(resp[4], =3D=3D, 0x3f); + g_assert_cmphex(resp[5], =3D=3D, 0x1f); /* no century bit on this pa= rt */ + g_assert_cmphex(resp[6], =3D=3D, 0xff); +} + /* The user RAM returns what the guest wrote to it. */ static void test_nvram(void *obj, void *data, QGuestAllocator *alloc) { @@ -207,6 +227,8 @@ static void ds1338_register_nodes(void) qos_add_test("control-register", "ds1338", test_control_register, NULL= ); qos_add_test("osf-write-protect", "ds1338", test_osf_write_protect, NU= LL); qos_add_test("clock-halt", "ds1338", test_clock_halt, NULL); + qos_add_test("stopped-reserved-bits", "ds1338", + test_stopped_reserved_bits, NULL); qos_add_test("nvram", "ds1338", test_nvram, NULL); qos_add_test("address-wrap", "ds1338", test_address_wrap, NULL); qos_add_test("reset-clears", "ds1338", test_reset_clears, NULL); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869110; cv=none; d=zohomail.com; s=zohoarc; b=lbASFqOsbx/GGX5KGHnO1Y2j76OOIzgryJ7itSOsmXR2KZkxpzLj8djmHU7YWaVoWPVNyX6CGO/vM47aJe7PpGR7kbIG+E2d7fS/0aF9OzWu78WwSXrjVuskVRQasdpnQ3nP+3rtCuuTIprZ63cHlqS4KBrvRqkTSYy6vTFnvmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869110; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=i/fJVu0RAkQNpYAD+bvYA8hnncGtRkMKhtyQVwo+Ypc=; b=eV6srnhLZBlD0yJ5xpR/CmtrVhFT1S0LYE7lt1YUQMxyFDL/5vjQKi3zQ7S3CNM3IZigEcwExxU1Mixvrl0n42nqQ14nkOAMUjBCXB0VbdoGZ8yQJo8yWMD1OwbR5RNjg6p1X4TWvjK1l0A6CT4nu5bQcC3cvNqrOtSP3B3sqxg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869110659308.73650345443275; Thu, 5 Nov 2026 00:58:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIZ-0004E7-4a; Thu, 05 Nov 2026 03:58:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIQ-0003vw-1u for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:11 -0500 Received: from mail-pl1-f174.google.com ([209.85.214.174]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtIN-0003lJ-Ft for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:09 -0500 Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2e9ae391a05so3175455ad.1 for ; Thu, 05 Nov 2026 00:58:07 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ed08fe55bdsm15377455ad.15.2026.11.05.00.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869085; x=1794473885; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=i/fJVu0RAkQNpYAD+bvYA8hnncGtRkMKhtyQVwo+Ypc=; b=JMzCxmnK/Qs84we3HowJKRx8zR4XqtmmJqgcyb0d1IEyuVQ+UBc/kmwUULxkcrj0lo plpTylvnHc+O3/AF3JlKXzuBlf0GKY/p+7xE/WfvBiai3hnaJjkryuFGKbC0gA/PyMzY fPivaR5UcXfORLkCqs3WmUR/WD+V47zoiXxpTSjWwGACNfygWDBYLOhXgoBB3BTuGccx hBAOR2bjiak5zCtNP5zVdk/iUZZ+Xf82l07tPVWaMaiyEL+RyE0VGuk1lLMF5D8/1CuZ NjAnWk8OBF3l/BtEfggW7JEu3/cPqgFMX3fGWbd5pY4RkrpCUtiF7K2ZQVHXAoC9Xdui tVBg== X-Gm-Message-State: APuU4Z+vC64oaR8YtEYD8l3wTbu145DUmJkckzUDLX8t2yKRdIQw8pcZ joJOsm0ESENIRWE6SPmhHHcgIyoVFnd5d+xlxo+k9lHZPpSO8YdZPyBx4qVHzomt/ok= X-Gm-Gg: AYBFou3Lj9DBJ8hzLeWsX1+clNr51er6Vfyb4WG6Ul+lrdCOxm6IArqEfe2wpDE3d+/ EEHjMyKcAYXLtrCt8SOG++Ds1H/VPf7czRXZpNiGDoHhVjiJGDUR+1rlCDgB/e4kWgtYbBJa5Y3 irtbkgaUgsTYt+dgexYoPtRydidZXMsu2uYa2I2rp+i3dTlTM3v7e/GjGpVntdMxAQxlDZl2+hD boOcvyXKHLGjXCofjkPS7avcfI/8wy4NgWJMq0/YuRb97MaJS9UA9HmwEkRVkWWv0g3ylvvniMs PYMRr1gSDuYDPShFImbY6JGZSfXczWmdEbYAZ7QXaC/Q2cPZ+v6V8mQiPLLvXSwkH74gc+rId+J UW4b8m9nKpU/n7s/b8QTiJuE6N98pLbaRZpU62QBvZbdGuFqxPfkFLrK3mSiKMzjCnEp5Ao3DkF /9t0eDorqdw3bn3YBWTvfSRekge6YDIBICJ/DopxEUUgGyOIL0QdPZvJOcGJHbVUYNvJA3/X7hF Nxk5Ofnot84NhxxQ/kktjgHmMTaP6oHDBrCDmMpvMLH4oP1WnRX63yq4b75gWqVbtie80GmRPMN TFqPFmonY68QOvHtqqweqg3+dsgBN79X6SmtXi4nHYG8ZA4wI7W/zpQ475R/sEgCuZx8rNWr6qi +ypvpxw== X-Received: by 2002:a17:902:ecce:b0:2dd:86a3:232d with SMTP id d9443c01a7336-2ed2407d509mr12245015ad.8.1793869084915; Thu, 05 Nov 2026 00:58:04 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:46 +0800 Subject: [PATCH 10/19] hw/rtc: ds1338: add DS1339 variant MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-10-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=13377; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=renBzme08gMcnv/4M4nG6ZLUFiR64cw9Bpyli/NRkr8=; b=IGsljTOV7eG6GMyjeXNY/BthGkCqhFwu/UxvKtlFRthi7Ptnc4k+EfG0Arv13fkgkZIl0YucO 960qR3shK2pCkT3Na7t8YGcs5Lig2B8c+HLiPzxVvHBzDfD6PqX4YZr X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.214.174; envelope-from=eblot.ml@gmail.com; helo=mail-pl1-f174.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869111072158500 The Dallas/Maxim DS1339 register map is only partially compatible with the DS1338: it shares the clock/calendar time registers but differs elsewhere. It has no general-purpose NVRAM, moves the control register, and relocates the oscillator-stop flag. Add a 'ds1339' variant, modelling the EOSC oscillator stop, the OSF/A2F/A1F status register and the century bit. The alarm, square-wave and trickle-charger functions are not modelled. A migrated register pointer is now range-checked; it used to index the register array unvalidated. Signed-off-by: Emmanuel Blot --- hw/rtc/ds1338.c | 180 ++++++++++++++++++++++++++++++++++++++++++++= ---- include/hw/rtc/ds1338.h | 3 +- 2 files changed, 168 insertions(+), 15 deletions(-) diff --git a/hw/rtc/ds1338.c b/hw/rtc/ds1338.c index 21deb94689..63a049292e 100644 --- a/hw/rtc/ds1338.c +++ b/hw/rtc/ds1338.c @@ -1,5 +1,5 @@ /* - * MAXIM DS1338 I2C RTC+NVRAM + * MAXIM DS1338/DS1339 I2C RTC+NVRAM * * Copyright (c) 2009 CodeSourcery. * Written by Paul Brook @@ -10,6 +10,13 @@ * GNU GPL, version 2 or (at your option) any later version. * * Limitations: + * - The DS1339 alarm registers, the alarm-enable control bits, the A1F/A2F + * status flags and the trickle charger are stored but never evaluated: = no + * alarm matching is performed, no flag is ever set by hardware and no + * charging happens. + * - The INT#/SQW output pin is not exposed: neither alarm interrupts nor + * square-wave generation are produced. No board wires this pin and the = guest + * does not use the RTC wakealarm here. * - Writing the seconds register does not reset the internal countdown ch= ain, * so the sub-second phase of the clock is not modelled. * - The user registers are refreshed on a START and on a read that wraps = the @@ -47,6 +54,23 @@ /* POR: OUT, OSF, SQWE and both rate-select bits come up set. */ #define DS1338_CTRL_RESET 0xb3 =20 +/* Sentinel register address meaning "this variant has no such register". = */ +#define DS1338_NO_REG 0xff + +/* DS1339 register map: 0x00..0x10 only, no general-purpose NVRAM */ +#define DS1339_NUM_REGS 0x11 /* 0x00..0x10, then wraps */ +#define DS1339_CONTROL 0x0e +#define DS1339_CTRL_MASK 0xbf /* bit 6 is reserved, reads back z= ero */ +#define DS1339_CTRL_EOSC 0x80 /* EOSC: 1 stops the oscillator */ +#define DS1339_CTRL_RESET 0x18 /* POR: RS2=3DRS1=3D1 (32 kHz), re= st zero */ +#define DS1339_MONTH_CENTURY 0x80 /* Century is bit 7 of the month r= eg */ +#define DS1339_STATUS 0x0f +#define DS1339_STATUS_OSF 0x80 /* OSF is bit 7 of the status reg = */ +/* Status bits that exist (OSF | A2F | A1F); bits 6..2 are reserved, read = 0. */ +#define DS1339_STATUS_MASK 0x83 +/* All three status flags are hardware-set and clear-only (write 0). */ +#define DS1339_STATUS_W0 0x83 + OBJECT_DECLARE_TYPE(DS1338State, DS1338Class, DS1338) =20 struct DS1338State { @@ -58,6 +82,7 @@ struct DS1338State { int32_t ptr; bool addr_byte; bool osc_stopped; /* oscillator halted: time is frozen */ + uint8_t prev_century; /* century index (tm_year/100) at last capture = */ bool persist_on_reset; /* keep the registers across a reset */ }; =20 @@ -69,24 +94,70 @@ struct DS1338Class { uint8_t ctrl_mask; /* writable/read-back bits of the control reg = */ uint8_t osf_addr; /* register holding the OSF flag */ uint8_t osf_mask; /* OSF bit within osf_addr */ + uint8_t status_addr; /* status register address */ + uint8_t status_mask; /* bits that exist; reserved bits read 0 */ + uint8_t status_w0_mask; /* flags that can only be cleared */ uint8_t ctrl_reset; /* control-register power-on value */ + uint8_t status_reset; /* status-register power-on value */ + uint8_t eosc_mask; /* oscillator-disable bit in the control reg */ + uint8_t century_mask; /* Century bit in the month register */ uint8_t ch_mask; /* Clock-halt bit in the seconds reg */ }; =20 +static int ds1338_post_load(void *opaque, int version_id) +{ + DS1338State *s =3D opaque; + DS1338Class *k =3D DS1338_GET_CLASS(s); + + /* Both accessors index nvram[] with ptr before incrementing it. */ + if (s->ptr < 0 || s->ptr >=3D k->num_regs) { + return -EINVAL; + } + + /* + * prev_century did not exist before version 3, so an older incoming s= tream + * leaves it zero. + */ + if (version_id < 3) { + struct tm now; + + qemu_get_timedate(&now, s->offset); + s->prev_century =3D now.tm_year / 100; + } + return 0; +} + +static const VMStateField vmstate_ds1338_fields[] =3D { + VMSTATE_I2C_SLAVE(parent_obj, DS1338State), + VMSTATE_INT64(offset, DS1338State), + VMSTATE_UINT8_V(wday_offset, DS1338State, 2), + VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE), + VMSTATE_INT32(ptr, DS1338State), + VMSTATE_BOOL(addr_byte, DS1338State), + VMSTATE_BOOL_V(osc_stopped, DS1338State, 3), + VMSTATE_UINT8_V(prev_century, DS1338State, 3), + VMSTATE_END_OF_LIST() +}; + static const VMStateDescription vmstate_ds1338 =3D { .name =3D "ds1338", .version_id =3D 3, .minimum_version_id =3D 1, - .fields =3D (const VMStateField[]) { - VMSTATE_I2C_SLAVE(parent_obj, DS1338State), - VMSTATE_INT64(offset, DS1338State), - VMSTATE_UINT8_V(wday_offset, DS1338State, 2), - VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE), - VMSTATE_INT32(ptr, DS1338State), - VMSTATE_BOOL(addr_byte, DS1338State), - VMSTATE_BOOL_V(osc_stopped, DS1338State, 3), - VMSTATE_END_OF_LIST() - } + .post_load =3D ds1338_post_load, + .fields =3D vmstate_ds1338_fields, +}; + +/* + * The DS1339 reuses the DS1338 migration field list, so it migrates the f= ull + * NVRAM_SIZE-byte nvram[] array even though it only implements registers + * 0x00..0x10. + */ +static const VMStateDescription vmstate_ds1339 =3D { + .name =3D "ds1339", + .version_id =3D 3, + .minimum_version_id =3D 3, + .post_load =3D ds1338_post_load, + .fields =3D vmstate_ds1338_fields, }; =20 /* Reconstruct a struct tm from the BCD time registers in nvram. */ @@ -109,7 +180,7 @@ static void ds1338_time_from_regs(DS1338State *s, struc= t tm *now) } now->tm_mday =3D from_bcd(s->nvram[4] & 0x3f); now->tm_mon =3D from_bcd(s->nvram[5] & 0x1f) - 1; - now->tm_year =3D from_bcd(s->nvram[6]) + 100; + now->tm_year =3D s->prev_century * 100 + from_bcd(s->nvram[6]); } =20 static void ds1338_resync_from_regs(DS1338State *s) @@ -129,13 +200,22 @@ static void ds1338_capture_current_time(DS1338State *= s) /* Capture the current time into the secondary registers * which will be actually read by the data transfer operation. */ + DS1338Class *k =3D DS1338_GET_CLASS(s); struct tm now; + uint8_t century; =20 if (s->osc_stopped) { return; } =20 qemu_get_timedate(&now, s->offset); + + century =3D now.tm_year / 100; + if (k->century_mask && ((century ^ s->prev_century) & 1)) { + s->nvram[5] ^=3D k->century_mask; + } + s->prev_century =3D century; + s->nvram[0] =3D to_bcd(now.tm_sec); s->nvram[1] =3D to_bcd(now.tm_min); if (s->nvram[2] & HOURS_12) { @@ -153,7 +233,7 @@ static void ds1338_capture_current_time(DS1338State *s) } s->nvram[3] =3D (now.tm_wday + s->wday_offset) % 7 + 1; s->nvram[4] =3D to_bcd(now.tm_mday); - s->nvram[5] =3D to_bcd(now.tm_mon + 1); + s->nvram[5] =3D to_bcd(now.tm_mon + 1) | (s->nvram[5] & k->century_mas= k); s->nvram[6] =3D to_bcd(now.tm_year % 100); } =20 @@ -204,6 +284,16 @@ static uint8_t ds1338_recv(I2CSlave *i2c) return res; } =20 +/* OSF is raised by hardware whenever the oscillator stops. */ +static void ds1338_raise_osf(DS1338State *s) +{ + DS1338Class *k =3D DS1338_GET_CLASS(s); + + if (k->osf_addr !=3D DS1338_NO_REG) { + s->nvram[k->osf_addr] |=3D k->osf_mask; + } +} + static int ds1338_send(I2CSlave *i2c, uint8_t data) { DS1338State *s =3D DS1338(i2c); @@ -234,12 +324,14 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) if (k->ch_mask) { halt =3D data & k->ch_mask; } + } else if (s->ptr =3D=3D 5) { + mask |=3D k->century_mask; } =20 if (halt && !s->osc_stopped) { /* CH set: freeze the counters before the register is stored. = */ ds1338_capture_current_time(s); - s->nvram[k->osf_addr] |=3D k->osf_mask; + ds1338_raise_osf(s); } s->nvram[s->ptr] =3D data & mask; s->osc_stopped =3D halt; @@ -250,6 +342,19 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) if (s->ptr =3D=3D k->ctrl_addr) { /* Control register: reserved bits read back as zero. */ data &=3D k->ctrl_mask; + if (k->eosc_mask) { + bool now_stop =3D data & k->eosc_mask; + bool was_stop =3D s->nvram[k->ctrl_addr] & k->eosc_mask; + if (now_stop && !was_stop) { + ds1338_capture_current_time(s); + s->osc_stopped =3D true; + ds1338_raise_osf(s); + } else if (!now_stop && was_stop) { + /* EOSC cleared: resume counting from the frozen time.= */ + ds1338_resync_from_regs(s); + s->osc_stopped =3D false; + } + } } if (s->ptr =3D=3D k->osf_addr) { /* @@ -259,6 +364,13 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) data =3D (data & ~k->osf_mask) | (data & s->nvram[s->ptr] & k->osf_mask); } + if (s->ptr =3D=3D k->status_addr) { + /* Reserved bits read zero; flags are clear-only, OSF included= . */ + uint8_t cur =3D s->nvram[s->ptr]; + data &=3D k->status_mask; + data =3D (data & ~k->status_w0_mask) | + (data & cur & k->status_w0_mask); + } s->nvram[s->ptr] =3D data; } ds1338_inc_regptr(s); @@ -268,13 +380,19 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) static void ds1338_power_on(DS1338State *s) { DS1338Class *k =3D DS1338_GET_CLASS(s); + struct tm now; =20 /* The clock is running and synchronized with the host */ s->offset =3D 0; s->wday_offset =3D 0; memset(s->nvram, 0, NVRAM_SIZE); s->nvram[k->ctrl_addr] =3D k->ctrl_reset; + if (k->status_addr !=3D DS1338_NO_REG) { + s->nvram[k->status_addr] =3D k->status_reset; + } s->osc_stopped =3D false; + qemu_get_timedate(&now, 0); + s->prev_century =3D now.tm_year / 100; } =20 static void ds1338_realize(DeviceState *dev, Error **errp) @@ -318,10 +436,39 @@ static void ds1338_class_init(ObjectClass *klass, con= st void *data) dsc->ctrl_mask =3D DS1338_CTRL_MASK; dsc->osf_addr =3D DS1338_CONTROL; dsc->osf_mask =3D CTRL_OSF; + dsc->status_addr =3D DS1338_NO_REG; /* the DS1338 has no status regi= ster */ + dsc->status_mask =3D 0; + dsc->status_w0_mask =3D 0; dsc->ctrl_reset =3D DS1338_CTRL_RESET; + dsc->status_reset =3D 0; + dsc->eosc_mask =3D 0; + dsc->century_mask =3D 0; dsc->ch_mask =3D SECONDS_CH; } =20 +static void ds1339_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + DS1338Class *dsc =3D DS1338_CLASS(klass); + + dc->desc =3D "DS1339 I2C serial real-time clock"; + dc->vmsd =3D &vmstate_ds1339; + + dsc->num_regs =3D DS1339_NUM_REGS; + dsc->ctrl_addr =3D DS1339_CONTROL; + dsc->ctrl_mask =3D DS1339_CTRL_MASK; + dsc->osf_addr =3D DS1339_STATUS; /* OSF lives in the status regist= er */ + dsc->osf_mask =3D DS1339_STATUS_OSF; + dsc->status_addr =3D DS1339_STATUS; + dsc->status_mask =3D DS1339_STATUS_MASK; + dsc->status_w0_mask =3D DS1339_STATUS_W0; + dsc->ctrl_reset =3D DS1339_CTRL_RESET; + dsc->status_reset =3D DS1339_STATUS_OSF; /* OSF set at power-on */ + dsc->eosc_mask =3D DS1339_CTRL_EOSC; + dsc->century_mask =3D DS1339_MONTH_CENTURY; + dsc->ch_mask =3D 0; /* bit 7 of the seconds register reads back zero= */ +} + static const TypeInfo ds1338_types[] =3D { { .name =3D TYPE_DS1338, @@ -330,6 +477,11 @@ static const TypeInfo ds1338_types[] =3D { .class_size =3D sizeof(DS1338Class), .class_init =3D ds1338_class_init, }, + { + .name =3D TYPE_DS1339, + .parent =3D TYPE_DS1338, + .class_init =3D ds1339_class_init, + }, }; =20 DEFINE_TYPES(ds1338_types) diff --git a/include/hw/rtc/ds1338.h b/include/hw/rtc/ds1338.h index f4cfe6a8e7..fff04c225d 100644 --- a/include/hw/rtc/ds1338.h +++ b/include/hw/rtc/ds1338.h @@ -1,5 +1,5 @@ /* - * MAXIM DS1338 I2C RTC+NVRAM + * MAXIM DS1338/DS1339 I2C RTC+NVRAM * * Copyright (c) 2009 CodeSourcery. * Written by Paul Brook @@ -16,5 +16,6 @@ #define HW_RTC_DS1338_H =20 #define TYPE_DS1338 "ds1338" +#define TYPE_DS1339 "ds1339" =20 #endif --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869127; cv=none; d=zohomail.com; s=zohoarc; b=fpCZH4GYYg06pppwa9JqiiSo/6SHHE3H+/TZYczGdoPjroy6woV8SNkdXI7rEBe+t0m1UdUOAl5QY+mNsTtwpj5gAnA8oLTKlPe/Ln0wqQPFv2XnyBHWsXz4FGujYBPtRwOf29pwbHajkFZ84ecognGmCR4x6vZMVg13678k6vE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869127; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=f+J/E7rlsF4ENqt+oSs16NilK9Jn/qUNnLTlrU6QonQ=; b=eXfGFvMq5jQ2VLeWhQ88jd5f8pqfxSZqxCK9sWLHlYv40FH1/4R2hOo/OGDEBuyY1XcVxTHwRT548BKLZSlyvJLbbFGlKWutB0CW7ENg9/s6C/v0FqukenIsAb3vGWanKw4hrCt4mjN7iB2AxJc/FlYoHtwZc/Vs9D0ibWFIHvg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869127875516.2942458794821; Thu, 5 Nov 2026 00:58:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIe-0004Nm-5V; Thu, 05 Nov 2026 03:58:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIX-0004AA-3m for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:18 -0500 Received: from mail-pg1-f169.google.com ([209.85.215.169]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtIU-0003lu-Gy for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:16 -0500 Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-cd8ba7c2694so621780a12.1 for ; Thu, 05 Nov 2026 00:58:14 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b313c0dcsm2899944a91.1.2026.11.05.00.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869092; x=1794473892; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=f+J/E7rlsF4ENqt+oSs16NilK9Jn/qUNnLTlrU6QonQ=; b=IYNX/PV1BUSUxJKDARebUoXAMlmRR13D4QCjW/VI4M02kddpRSvWOtoev73XaNX/Dq iz1tFSVqcEH4YmFm6ULel7kyOPIZHoQtAApzUs8TbeP9rFJOo1+3v2zgPDbmcCm4NOc9 fkJPAmVqWcUdcz8u52eS8YP5z6xb07xsvDd1Nzpc51d21DqT5bbIQicatPDrndZJselK UqK4/whtvpqWCWWN6EyTekM4tZ3qTMUl4imEP2LfJqNwDp9oMXg6mirvfFZZwmjTQdU2 C8o83AwAflUzER6/JFt1cAP0/r7abxzfTzF4oHjP6PgukrKRvISu8mTR6QkQWjVvFGZm kdlw== X-Gm-Message-State: APuU4Z+E6LU8i5V3nQYpBUcN7wuo33To+u0vvxkOWWf604EmA0+wnr1t pwh/9M2jlXHO6yYthbjMiM+1yd/ukVFtOcoBxyH9H8ur6gzp9lCUY4yxCVykFeO6SLc= X-Gm-Gg: AYBFou3zNXyhPz1kp4crFhDNr5YFHqtxvgLMlZSExk2ct8MsmuJKFSmbuK2IkdRm0r0 u0Xqk0GcOZWsVx7eLYbR7r4xaQMrBIARB5Rmiy1/GOZVcI+wrYjoI4EnT68sY8aFgjDKnTx54ju s3RQ1linmr4er/GLxN++98/P3DWgj9Di+B7HJjICrV3iurqMrfXCWSELWDru28oLLFYgMPSvp7o 7XWfffhc4gx42sp9PwnoA+AKnfRmX+fXxWF6pmBn0kKsgXtJp4wGEtV2eb2R31QX48HL7yEOpb8 Xw3NJcpJx77Yy/sQSR0C2ToVbhrZD4tC+KM7rNqEesCQZl0JmmaSynH1vSJ0AUI2tuSywuv+I50 FGbPGYm0nqMh8KvY+N8o6ibI3tXjz1fpCS6m/W7WKTpwtC2ATxCjzFafCJ0VkGkFjsZQmsq/Co4 kV/CWVsSzkyZx0/mxF6lJ2p9Lb0IUC/KoQ+wCMwUWhObe6imWDfz1+CZ4xBoz5vyXisuOuDAE/S aGFlpb5UA/qh/zmOWYcRQg1Ds5At+P2GliDUwHCj6RJsChFV4HLPsWN2VyVfyFwtDsbfa+h/K7d BtqtJxyzE7bhc3A/T8FCbkXLSMFjduVbG+LqGVOajmVXwyP0OjqQ+RK0BHAgl2gQpAtRPU0S8jM eKlW/6A== X-Received: by 2002:a17:90b:3881:b0:3ad:5c64:c7a0 with SMTP id 98e67ed59e1d1-3ae89814e7dmr15012925a91.38.1793869092039; Thu, 05 Nov 2026 00:58:12 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:47 +0800 Subject: [PATCH 11/19] tests/qtest: ds1339: add RTC test MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-11-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=7125; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=y/YegUWDnNx3TOGpnx4wFBpa4TX5WO9a9LqgZpv2Rq8=; b=maXU+bX9lYHM81AOmIdGvEH/cFnv53O712hPAKUe8Lm9FGEpbw0iyXw4eTLXlfGCeeNXG7f8y wKrDEIJe6oPDP/BUs8ZDErxW6umWvXsbillnlOweuFg8AeHjrZmhlM7 X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.215.169; envelope-from=eblot.ml@gmail.com; helo=mail-pg1-f169.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869129357158500 The variant had no test of its own. Cover its register map, the write-protection of the oscillator-stop flag, and the wrap of the register pointer at the end of the map. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 166 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qtest/meson.build | 1 + 2 files changed, 167 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c new file mode 100644 index 0000000000..08fc16acda --- /dev/null +++ b/tests/qtest/ds1339-test.c @@ -0,0 +1,166 @@ +/* + * QTest testcase for the DS1339 RTC + * + * Copyright (c) 2026 Meta Platforms, Inc. and affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/bcd.h" +#include "libqos/i2c.h" + +#define DS1339_ADDR 0x68 + +/* DS1339 register map */ +#define DS1339_SECONDS 0x00 +#define DS1339_MONTH 0x05 +#define DS1339_YEAR 0x06 +#define DS1339_ALARM1 0x07 +#define DS1339_ALARM2 0x0b +#define DS1339_CONTROL 0x0e +#define DS1339_STATUS 0x0f +#define DS1339_TRICKLE 0x10 +#define DS1339_NUM_REGS 0x11 + +#define DS1339_STATUS_OSF 0x80 + +/* The clock and calendar come up on the host time. */ +static void test_time(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + uint8_t resp[7]; + time_t now =3D time(NULL); + struct tm *tm_ptr =3D gmtime(&now); + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + + g_assert_cmpuint(from_bcd(resp[4]), =3D=3D, tm_ptr->tm_mday); + g_assert_cmpuint(from_bcd(resp[5]), =3D=3D, 1 + tm_ptr->tm_mon); + g_assert_cmpuint(2000 + from_bcd(resp[6]), =3D=3D, 1900 + tm_ptr->tm_y= ear); +} + +/* Writable control bits round-trip; the reserved one reads back zero. */ +static void test_control_register(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_CONTROL, 0x1c); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL), =3D=3D, 0x1c); + + i2c_set8(i2cdev, DS1339_CONTROL, 0xff); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL), =3D=3D, 0xbf); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL), =3D=3D, 0x00); +} + +/* The oscillator-stop flag can only be cleared by a write, never set. */ +static void test_osf_write_protect(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + =3D=3D, DS1339_STATUS_OSF); + i2c_set8(i2cdev, DS1339_STATUS, DS1339_STATUS_OSF); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + =3D=3D, DS1339_STATUS_OSF); + + i2c_set8(i2cdev, DS1339_STATUS, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, = =3D=3D, 0); + i2c_set8(i2cdev, DS1339_STATUS, DS1339_STATUS_OSF); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, = =3D=3D, 0); +} + +/* The register pointer wraps at the end of the map. */ +static void test_address_wrap(void *obj, void *data, QGuestAllocator *allo= c) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_CONTROL, 0x2a); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL + DS1339_NUM_REGS), + =3D=3D, 0x2a); +} + +/* A block transfer off the end of the map carries on from the start. */ +static void test_block_wrap(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + /* The alarm 2 block, then on into the time registers once it wraps. */ + const uint8_t out[11] =3D { + 0x0b, 0x0c, 0x0d, /* alarm 2 */ + 0x18, /* control */ + 0x00, /* status */ + 0xa5, /* trickle charger */ + 0x30, 0x20, 0x10, 0x05, 0x12, /* 10:20:30, day 5, the 12th */ + }; + uint8_t resp[11]; + + /* A month and year the wrapping write never reaches. */ + i2c_set8(i2cdev, DS1339_MONTH, 0x07); + i2c_set8(i2cdev, DS1339_YEAR, 0x31); + + i2c_write_block(i2cdev, DS1339_ALARM2, out, sizeof(out)); + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, 7); + g_assert_cmphex(resp[2], =3D=3D, 0x10); + g_assert_cmphex(resp[3], =3D=3D, 0x05); + g_assert_cmphex(resp[4], =3D=3D, 0x12); + g_assert_cmphex(resp[5] & 0x1f, =3D=3D, 0x07); + g_assert_cmphex(resp[6], =3D=3D, 0x31); + + i2c_read_block(i2cdev, DS1339_ALARM2, resp, sizeof(resp)); + g_assert_cmphex(resp[0], =3D=3D, 0x0b); + g_assert_cmphex(resp[1], =3D=3D, 0x0c); + g_assert_cmphex(resp[2], =3D=3D, 0x0d); + g_assert_cmphex(resp[3], =3D=3D, 0x18); + g_assert_cmphex(resp[4], =3D=3D, 0x00); + g_assert_cmphex(resp[5], =3D=3D, 0xa5); + g_assert_cmphex(resp[8], =3D=3D, 0x10); + g_assert_cmphex(resp[9], =3D=3D, 0x05); + g_assert_cmphex(resp[10], =3D=3D, 0x12); +} + +/* The alarm and trickle registers are stored but never evaluated. */ +static void test_alarm_registers(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + static const uint8_t regs[] =3D { + DS1339_ALARM1, 0x08, 0x09, 0x0a, /* alarm 1 */ + DS1339_ALARM2, 0x0c, 0x0d, /* alarm 2 */ + DS1339_TRICKLE, + }; + static const uint8_t vals[] =3D { 0xff, 0x00, 0x5a, 0xa5 }; + unsigned reg, val; + + for (reg =3D 0; reg < ARRAY_SIZE(regs); reg++) { + for (val =3D 0; val < ARRAY_SIZE(vals); val++) { + i2c_set8(i2cdev, regs[reg], vals[val]); + g_assert_cmphex(i2c_get8(i2cdev, regs[reg]), =3D=3D, vals[val]= ); + } + } +} + +static void ds1339_register_nodes(void) +{ + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "address=3D0x68" + }; + add_qi2c_address(&opts, &(QI2CAddress) { DS1339_ADDR }); + + qos_node_create_driver("ds1339", i2c_device_create); + qos_node_consumes("ds1339", "i2c-bus", &opts); + + qos_add_test("time", "ds1339", test_time, NULL); + qos_add_test("control-register", "ds1339", test_control_register, NULL= ); + qos_add_test("osf-write-protect", "ds1339", test_osf_write_protect, NU= LL); + qos_add_test("address-wrap", "ds1339", test_address_wrap, NULL); + qos_add_test("block-wrap", "ds1339", test_block_wrap, NULL); + qos_add_test("alarm-registers", "ds1339", test_alarm_registers, + NULL); +} + +libqos_init(ds1339_register_nodes); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index ff4bf9528a..f700442607 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -335,6 +335,7 @@ qos_test_ss.add( 'adm1272-test.c', 'adm1266-test.c', 'ds1338-test.c', + 'ds1339-test.c', 'e1000-test.c', 'eepro100-test.c', 'es1370-test.c', --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869128; cv=none; d=zohomail.com; s=zohoarc; b=KY2GXVDSV2OWg59vvREP/g3zXp7nCFwgwp60tRpm9ASCPxbKm7jT1L7YyPy7MiFDWG2BgZEcFxQTjR7MnTbwDQprhYfN5XlVxs1fkbLy3K/bZjkzsR08XhqhNOQv3PCOC4DA+hOcnmqyv9LOQu//3RJOKTjbXEzeyIj3KP1jIOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869128; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=T+aQuOytqkO9L6viQdmuDORw5uxFjnolQFIJ54bA1P8=; b=ZSEWKcVKLPjjcgSK+N/vEW4SkDunecEPNwe5oZGXFk2Q/Isrg67ffSstj173/+ZvazLcrfFmMphwoOYylqRfvC2HPrSdGv2LIMx9YDxVOoKMKMRpRCt0Q3MdfgX2HCrIpICqbJxgtG/Bmc6B11bmBjCgOiQBHw09oJNcFr3phd4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869128775203.45186117175922; Thu, 5 Nov 2026 00:58:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIo-0004gn-OS; Thu, 05 Nov 2026 03:58:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIe-0004Qy-8d for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:26 -0500 Received: from mail-pj1-f41.google.com ([209.85.216.41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtIc-0003mg-3t for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:23 -0500 Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-3b08a162d4bso1144823a91.3 for ; Thu, 05 Nov 2026 00:58:21 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b3131f8csm3122209a91.2.2026.11.05.00.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869100; x=1794473900; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=T+aQuOytqkO9L6viQdmuDORw5uxFjnolQFIJ54bA1P8=; b=KoCapjSv+NLQUrsm6LWu5Uj5l68i57NraYQRfv4PLf2WwMpOsGoxtXdxHC1UHLA80W L/ORItlayP7cNcqHsYo+c148ErU8KL7LIPPiIw2JDowjroYbKA+UnrH+gpSbyrlcjCdO kI6FnmQaWWerheE+Jh6K82x+fS/AO04dQkZdd6ITIEBUbdDrn5lL+ZXmTMP1DWg0/CXC 9ZmBPoycx+86Xh6NF0eWGjAghcjpzJV9jAT8kKWCdW+uU1nsnqI9gMJ5lDa4WHpib9fY eIa3L4l6D2qOKx7+BVHSj2as4tykWzncFGUq/Jiui2/86MrfrV5KqvZ9N1veJzouE1Vw 4YUg== X-Gm-Message-State: APuU4Z/iMlnzCrLyU0H7MaZ0qmOqjurrRI0ujlxIlpH3zBGnUiLEKaYm 2GNPckE/DHkLOoR8aPE7OOKOYTf7JtA7VHYse+I1PD4HZt7gkJ082SgGRw082gUp1zc= X-Gm-Gg: AYBFou3W6T/I5Jn0O4JyRIFo7rWHF/rn60Kb8h0flWxj5i/ut+6bFAkNYocpfXJzMpy YChhhE0wVou1L8gk8o6JJT1sFpHTvH8IXMp6I+T7BsFbJGzTVtZOEaE35ocOHD7u119HFEq2110 AWrvDnqBgPVT6Fenn4MI3QQVbyq2Dxr6j1DHUc6ABJuYdI4eEq09wEHiO8xAY/FLYyoeiCgpgPG 7Dxc8CAdbd3IfBOgoYJcabfofZhcYtlxwDbAVHlSTq4m04KbYJS/Rzo3LVNjvUW36xF3x0Lf61v lCx3UDsVKjPYHv7FU7MLMB2lTnkhcNYuU0ZSn+NKVuzMIk1GJ9s7ACpsa2pOYzxyPR8agMeKtve 9MVwPe0mmNfYnDEiLZ6ExywZOySTlVVQyv/PAV8daCo+XtyTSm6q/llvaaSTpWCBr/qTgE+/TAx 2VTNkRtFJ1zgKvU1TgR9AihfhJZOrFXvViRwlCeBU5xGxcm7v8aJFZS/dAXuhPV3CmAyWRTXV9T KMPiveCQm05qGzQ6IxCnvuX8hb7bewnqGsrcf2/mBNyLAatkjh4PdU556eMhFlUtmmcMCGbIYLE cgVTDVhMeV5n0NVtA4Q7U8r3+qqXBUTl6tWUzF4EN5OsyR+k81LYTjN6vdZr/BoCoG19PShFXm3 sDDq7eVAbQP7ZWfJKaGONSKxesNU= X-Received: by 2002:a17:90b:440d:b0:3a4:fe48:d410 with SMTP id 98e67ed59e1d1-3ae897f8c6fmr14253255a91.30.1793869100051; Thu, 05 Nov 2026 00:58:20 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:48 +0800 Subject: [PATCH 12/19] tests/qtest: ds1339: cover power-on defaults and reserved-bit masking MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-12-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=3431; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=4kpdPaxvZVkT90Xwee/1AVTNKhV96yGus/onpPPZ95Q=; b=cAyl8nSVGv4OeaAiHI5rybYAtkTOV3dIMJX45zJGqhhwnk5B5h8UrhOKDnXFliuWT0NqiRUry Nbrd3sGjDiJC1YWInMSEGas/OUwCVgaPh116S4bbKhY7E7X3fjYK8Wa X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.216.41; envelope-from=eblot.ml@gmail.com; helo=mail-pj1-f41.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869129415158500 Neither the power-on defaults nor the reserved bits of the register file were pinned. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 51 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 51 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index 08fc16acda..e9dcdc36da 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -74,6 +74,53 @@ static void test_osf_write_protect(void *obj, void *data, g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, = =3D=3D, 0); } =20 +/* The control and status registers come up in their power-on state. */ +static void test_reset_defaults(void *obj, void *data, QGuestAllocator *al= loc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL), =3D=3D, 0x18); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + =3D=3D, DS1339_STATUS_OSF); +} + +/* Neither the reserved status bits nor the alarm flags are guest-writable= . */ +static void test_status_register(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_STATUS, 0x7c); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS), =3D=3D, 0x00); + + i2c_set8(i2cdev, DS1339_STATUS, 0x03); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS), =3D=3D, 0x00); + + i2c_set8(i2cdev, DS1339_STATUS, 0xff); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS), =3D=3D, 0x00); +} + +/* Reserved time-register bits read back zero even with the clock stopped.= */ +static void test_stopped_reserved_bits(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + const uint8_t all_ones[7] =3D { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x= ff }; + uint8_t resp[7]; + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + i2c_write_block(i2cdev, DS1339_SECONDS, all_ones, sizeof(all_ones)); + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmphex(resp[0], =3D=3D, 0x7f); + g_assert_cmphex(resp[1], =3D=3D, 0x7f); + g_assert_cmphex(resp[2], =3D=3D, 0x7f); + g_assert_cmphex(resp[3], =3D=3D, 0x07); + g_assert_cmphex(resp[4], =3D=3D, 0x3f); + g_assert_cmphex(resp[5], =3D=3D, 0x9f); + g_assert_cmphex(resp[6], =3D=3D, 0xff); +} + /* The register pointer wraps at the end of the map. */ static void test_address_wrap(void *obj, void *data, QGuestAllocator *allo= c) { @@ -155,8 +202,12 @@ static void ds1339_register_nodes(void) qos_node_consumes("ds1339", "i2c-bus", &opts); =20 qos_add_test("time", "ds1339", test_time, NULL); + qos_add_test("reset-defaults", "ds1339", test_reset_defaults, NULL); qos_add_test("control-register", "ds1339", test_control_register, NULL= ); + qos_add_test("status-register", "ds1339", test_status_register, NULL); qos_add_test("osf-write-protect", "ds1339", test_osf_write_protect, NU= LL); + qos_add_test("stopped-reserved-bits", "ds1339", + test_stopped_reserved_bits, NULL); qos_add_test("address-wrap", "ds1339", test_address_wrap, NULL); qos_add_test("block-wrap", "ds1339", test_block_wrap, NULL); qos_add_test("alarm-registers", "ds1339", test_alarm_registers, --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869146; cv=none; d=zohomail.com; s=zohoarc; b=SKLl9pzrBFaKzwfSblewbquNVgnmAJbFSI9H2y9PcUtyrCn2WlYzl8RKOrZThjKVu85+3WlF4+AUY89dAbOHi4tGmb6pLKAVwfJtGSDYuzIlxe8WU9cd9s1sS9QWReLX1EQcJuGxs527HSFYre0t+IEnys9CFwuygyEgyAeWfM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869146; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=56pPJS+C8la1MYmTdNNflpT7tU5QoCQdslzftdKxEFk=; b=PY4PYkuffUrFZIInpxeeD1hoIRH357B3VZsLGDf9I1zbyIsqo+T8+lVaVeaLNfUiEAU6o63enaic8FdBlvj+xcr/Khwm1GANq250q/Ich2jwyEb67gJD7s9wVRiSsgYLqKmg4+NmaA1Owoh+HVX8zJEcZ2+j6kwlWTWUkRC1wFk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869146638916.7417466849745; Thu, 5 Nov 2026 00:59:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIs-0004sD-OM; Thu, 05 Nov 2026 03:58:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIn-0004iF-Vp for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:35 -0500 Received: from mail-pj1-f44.google.com ([209.85.216.44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtIl-0003nb-JC for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:33 -0500 Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3ac78f4c10bso714250a91.1 for ; Thu, 05 Nov 2026 00:58:30 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cdb46998fe1sm1910261a12.27.2026.11.05.00.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869108; x=1794473908; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=56pPJS+C8la1MYmTdNNflpT7tU5QoCQdslzftdKxEFk=; b=L2/XRHaaKAF9E56NhgtfsZJoBpHUHWs4huDVLDPi+NnIBLdLKfyx9/EOPD4BRM7f3p LX1iVYr5f8Rr9ZUgx1vc2oXpPsj6dxwy5Qaq+6La7gJ7OOGF9iJcUI2pP0tryBEUVyXK 9ws2Zq3L8rRUdn/FJZCoNBIUSbMWz47OBAv6AF8naKCaQJBebFUn3cFGBuVburbVF6o+ IXEhs6KGSpRrfHQzjZtYadpLPxnJELOMX2mGgRNnxgCKanqW/zjZoG0E1Vx3QQuUn3c+ TQFkuo9KaGOc2ziMAmgQNqlsJBGx92bi4oP42yOcZFPCxv+Ze/wItF71VVD6izvtYPMh Cw6g== X-Gm-Message-State: APuU4Z/5BnhN9PlnG/fimu+aLGdABwbEWVHNKARXK9ErSqGqvAkJEsAq enPX5OK0hT7YgzZOCdLYV4kv4pgfA5N7H/DPQKwUBtDyh0dkXL/JCWwTpPOPrz5zSRE= X-Gm-Gg: AYBFou2LDPet9nHE5oTxroqa1TYOxO2l/mJBP6Vxg87o6aMHJ0bzocXhaKCnYApFNHr 0XjRj8mXgw3T2/H2VCx2UgDPvx5Q9D63MTKJgMqPz6bE7N2iWvmOnjpj4BeTdiJUUoaIOPdetJ8 RmXAIKfTOGXdPzRGxUIB8UdbORV/gzn6agnUBzrcRzdjpKrACKFWUhfqjlniro+UASwH+lTiCtu dGLSMfg16Espo9PUDl9iV9CXcUHNRj95haUPD0PZPW3KuWoEcAHiFPJo+aJHhy4MkoyhBuOfG5H S6k97jsZMx799Z0cW1aBbpABI2M840iCT2piCJs8DbNDbx9OkDFkZmHSf6YSsQYiWKHPEt2JPF/ aMz2lpCD3RcjCmgj1D646VnHI2cgRCsMJQQhQDW0v30umzPZrl/6EmNbjIBRlGuRCdynhTN6iFP KYUpJqV12uAhoMHeMX3Zs1e2Z+OUJI8E7n1paoPOzf+2Kqv31JJQEauxIiJaeIzKHEHeMSva5Nv ZWxKxmTjidkJ6nImNqL1u0YaDwYcWIrN3gtO/nsAibvKfdqM/0TCikDkxU6GcJDLQSmMv4gVqPC GAKrycXzYd4OIuRVUAzf9TOJdcsuiWuCEp2afsjxDrZxbyMDRYrNrxNtrApA0PrY7Izn39izWhX ZRkkRN9wyL+eyL4GmpEdA+KvjNgE= X-Received: by 2002:a17:90b:164c:b0:3b0:9a1b:b709 with SMTP id 98e67ed59e1d1-3b09a1bb873mr4311055a91.54.1793869108187; Thu, 05 Nov 2026 00:58:28 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:49 +0800 Subject: [PATCH 13/19] tests/qtest: ds1339: cover oscillator stop/restart and time programming MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-13-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=3347; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=/xAI0glxvoShi8yf2NDQf97RUj4tlRYLrP33FMRgSlE=; b=n9eMy+ZaO2gYL3OP60BHI5X6b0Dl3KrUmmhCNzzl/ZLZurzBFl8bXhM3E+C+fz/PHdjGCKxZq gMoGeNZ6cKEAi8AEU8gFbbC1+5/Elj6ZcLY6/gxPq+clt3+sgYozA5j X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.216.44; envelope-from=eblot.ml@gmail.com; helo=mail-pj1-f44.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869147771158500 Stopping and restarting the oscillator had no coverage, nor did the time the clock resumes from. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 50 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 50 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index e9dcdc36da..ac19ebd71d 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -121,6 +121,54 @@ static void test_stopped_reserved_bits(void *obj, void= *data, g_assert_cmphex(resp[6], =3D=3D, 0xff); } =20 +/* Setting EOSC stops the oscillator and sets OSF; OSF outlives the restar= t. */ +static void test_eosc(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_STATUS, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, = =3D=3D, 0); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + =3D=3D, DS1339_STATUS_OSF); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + =3D=3D, DS1339_STATUS_OSF); + i2c_set8(i2cdev, DS1339_STATUS, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, = =3D=3D, 0); +} + +/* A stopped clock resumes from the time it was programmed with. */ +static void test_eosc_restart(void *obj, void *data, QGuestAllocator *allo= c) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + /* 10:20:30 on the 12th of July 2031, the day counter reading 2. */ + const uint8_t tod[7] =3D { 0x30, 0x20, 0x10, 0x02, 0x12, 0x07, 0x31 }; + uint8_t resp[7]; + unsigned idx; + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmpmem(resp, sizeof(resp), tod, sizeof(tod)); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18); + /* The seconds counter steps within a second of the restart. */ + for (idx =3D 0; idx < 15 && i2c_get8(i2cdev, DS1339_SECONDS) =3D=3D 0x= 30; idx++) { + g_usleep(100 * 1000); + } + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmpuint(from_bcd(resp[0]), >, 30); + g_assert_cmphex(resp[2], =3D=3D, 0x10); + g_assert_cmphex(resp[4], =3D=3D, 0x12); + g_assert_cmphex(resp[5] & 0x1f, =3D=3D, 0x07); + g_assert_cmphex(resp[6], =3D=3D, 0x31); +} + /* The register pointer wraps at the end of the map. */ static void test_address_wrap(void *obj, void *data, QGuestAllocator *allo= c) { @@ -206,6 +254,8 @@ static void ds1339_register_nodes(void) qos_add_test("control-register", "ds1339", test_control_register, NULL= ); qos_add_test("status-register", "ds1339", test_status_register, NULL); qos_add_test("osf-write-protect", "ds1339", test_osf_write_protect, NU= LL); + qos_add_test("eosc", "ds1339", test_eosc, NULL); + qos_add_test("eosc-restart", "ds1339", test_eosc_restart, NULL); qos_add_test("stopped-reserved-bits", "ds1339", test_stopped_reserved_bits, NULL); qos_add_test("address-wrap", "ds1339", test_address_wrap, NULL); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869134; cv=none; d=zohomail.com; s=zohoarc; b=L5sEC0RTFZtRP2rZEcCDAS8pJnnvFnwKhpVnc8QePwMM8VDpvSavk09PUx6GD0srN1AgEvYqjRNgtkqf68dAtA7i+cbZVFOP9FlB2E+pfq2AZhuU3m0Kxb2rJiww5CbwDJ5goAd/VGJ9bZY85+avi5uIrO4H/3uiNqtAbiDyeTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869134; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=Zzjq066d1DK9BL6AffnijbYCb4eLXuskQFLQ8zYtsCk=; b=HsaSTTV6dYa7rraTq/5RUfHaV+EPpgiJaxg/5/wybw1YIEJCTzVf0y/6/FPzpIRdvKAmw3YSHCGq3hFaWv09hs0kFYKFATkCmTXpa/zTpe3VstB6eRw2vU3AJfHE2M8R2sGxm0ByOWwU0h4tEUeR1WgbiwwVyWo/D2F3taEiMi4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869134447202.94879203277344; Thu, 5 Nov 2026 00:58:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtIz-0005VG-U3; Thu, 05 Nov 2026 03:58:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtIv-0005Ar-OL for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:42 -0500 Received: from mail-pf1-f181.google.com ([209.85.210.181]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtIt-0003oa-7Q for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:41 -0500 Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8a058315c79so896451b3a.3 for ; Thu, 05 Nov 2026 00:58:38 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8b09a8c303dsm1692412b3a.20.2026.11.05.00.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869117; x=1794473917; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Zzjq066d1DK9BL6AffnijbYCb4eLXuskQFLQ8zYtsCk=; b=lXwJ5qb5QaDYukUvTr0tzpd2Q6oS30d5jwQh2l9AUblcpGaXdSs4c1yJqdvYVU8wXY gIQCn2M2+sDvSkkJI7543ms+MX1TMT6NeXW0YQN1s/rv165rcELt4fPikSWpmnPhtuOe u+KQiWHn6LjDwT1jhhN4V2sUr2RSCifwoLmnCHV7qNw6lxaq+c3zIGWKI5TyY1OicWJP xxAIN2gzpldHV+GmUcT/GGvDk+q8lnDqUt3mBtdk9Pji0Sur1ULb6fzjnCXv+EILGqxS ZaC4k7EMCkUOUSRs2SzpwF+pZ0OvYRxqrT+NEHWAqvabQq0NsA0M2HwiUIobeJzDK336 Jcfw== X-Gm-Message-State: APuU4Z8y/IvS9bJGXUaYkRB2WO37pqYCpn82RkLQowzXUSHPfdamh9e+ +p+kJjLkeCPnbEEg6xSEbiSyXP6CTJ13o7y3s3AW/WmnDX8vmlbbjjaubFZ7iLyLUP8= X-Gm-Gg: AYBFou3UGahkAEHrvBGuDyLvb9oIRWcK7Ohb0vzx+ZBsm6wup3iOPnlYANeYft+r+Lp /CZySepoL5fcT3la7HVzAd3iuWxq+p7sZkfrHRZU3jIZuUgCckycESjV58rT8j5TR8Nrwja1paU rtyXB/ozQ27cHCcELEQ+BPy0r9bBzXendtJ7k3pn2YoHAAZtvwxkzoWFRs/DCxYfdzIfXXwIyh+ ipYY85Vw25RiMVw3Ov7VvVAz5/sFa3rxEfUGvUUHvLDu9Zkjm34knCkTL8d4Yd3m/+fCx9AKAWZ SDoDr4fmK5XLGZo2wiab/sXXfXhKmuYlijT8ozKHpjTHOYSfXcwnCiVWF32cYlY9XoT/Rn7kfJM p82E5R1iyqEPzDTRSx7duugjqX2gKI4oveS90jUBA7phcZFI/yVL5DNiM6nUUMElMAvvvvGV/R7 WKcy9yct2qSyAh+peGaV+1lmXgt4kfcqaEnXdh1ad2MfTfMnqsMOIq1wFoVstiOFTTNdhOY65nk cz9NoRNirq9Bk487TzYzWin5/4bs/veAYOTdJAcqc9J4vlnVGWkq2hhG22xJfrltBR2LP1QNN8i ddKFwvL8QX5UFGN+4S4LDbU60Sx9tQHqVe0rDA++Qoc72Cq9KMs/F42jPaeRDM+VnIDSegF8PJI cYK4BXg== X-Received: by 2002:a05:6a00:22c7:b0:881:cbb0:6a90 with SMTP id d2e1a72fcca58-8a9bef522cbmr14521222b3a.58.1793869116526; Thu, 05 Nov 2026 00:58:36 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:50 +0800 Subject: [PATCH 14/19] tests/qtest: ds1339: cover the Century bit MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-14-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=3691; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=a51PVO883sS5BmzswPWqVtyHVJ/pN81H084v6xEIBwk=; b=2PDOqlPZg5yc5wNW7YYIRCeZcoSg/V0lP9ZQoQZ8NsyL4RUAXehjpWjHZtbKNmGq5dc7G7MOF ZYvlRIHdaulDXs2gbogiHxVJZF4D+M31o/d26WAUHLYYCmfqJOLSfyo X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.210.181; envelope-from=eblot.ml@gmail.com; helo=mail-pf1-f181.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869135450158500 The Century bit had no coverage: neither its guest read/write behaviour, nor the rule that only an elapsed rollover toggles it. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 60 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 60 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index ac19ebd71d..8c144579e6 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -169,6 +169,62 @@ static void test_eosc_restart(void *obj, void *data, Q= GuestAllocator *alloc) g_assert_cmphex(resp[6], =3D=3D, 0x31); } =20 +/* The Century bit is guest-writable and survives an oscillator restart. */ +static void test_century_bit(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_MONTH, 0x86); /* Century | June */ + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x80); + + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + i2c_set8(i2cdev, DS1339_CONTROL, 0x18); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x80); + + i2c_set8(i2cdev, DS1339_MONTH, 0x06); /* June, century clear */ + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x00); +} + +/* A guest write never toggles the Century bit. */ +static void test_century_write_no_toggle(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + i2c_set8(i2cdev, DS1339_MONTH, 0x86); + i2c_set8(i2cdev, DS1339_YEAR, 0x99); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x80); + i2c_set8(i2cdev, DS1339_YEAR, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x80); + + i2c_set8(i2cdev, DS1339_MONTH, 0x06); + i2c_set8(i2cdev, DS1339_YEAR, 0x99); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x00); + i2c_set8(i2cdev, DS1339_YEAR, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x00); +} + +/* A clock-driven year rollover from 99 to 00 toggles the Century bit. */ +static void test_century_rollover(void *obj, void *data, + QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + const uint8_t tod[7] =3D { 0x59, 0x59, 0x23, 0x01, 0x31, 0x12, 0x99 }; + unsigned idx; + + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + + for (idx =3D 0; idx < 50; idx++) { + if (i2c_get8(i2cdev, DS1339_YEAR) =3D=3D 0x00) { + break; + } + g_usleep(100 * 1000); + } + + g_assert_cmphex(i2c_get8(i2cdev, DS1339_YEAR), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_MONTH) & 0x80, =3D=3D, 0x80); +} + /* The register pointer wraps at the end of the map. */ static void test_address_wrap(void *obj, void *data, QGuestAllocator *allo= c) { @@ -258,6 +314,10 @@ static void ds1339_register_nodes(void) qos_add_test("eosc-restart", "ds1339", test_eosc_restart, NULL); qos_add_test("stopped-reserved-bits", "ds1339", test_stopped_reserved_bits, NULL); + qos_add_test("century-bit", "ds1339", test_century_bit, NULL); + qos_add_test("century-write-no-toggle", "ds1339", + test_century_write_no_toggle, NULL); + qos_add_test("century-rollover", "ds1339", test_century_rollover, NULL= ); qos_add_test("address-wrap", "ds1339", test_address_wrap, NULL); qos_add_test("block-wrap", "ds1339", test_block_wrap, NULL); qos_add_test("alarm-registers", "ds1339", test_alarm_registers, --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869150; cv=none; d=zohomail.com; s=zohoarc; b=VpypLDkQ0KQiHPQhMz0YwNHUyleNxP+UI66BPbaW4AmpqaIpFelxnmXWA0+ekbC0kD01+fEoWkEdRrtLCc7KPNGNXSRRduAtKI5nzEHqqJpsVLoI2DiH/cGw2/D+oShIpVd9yJbb3eXCO0c/b6mjwzOY+tId7X7rW6MPvRgU+zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869150; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=Adz/rIkVxKmnpzPklQqKGWWgHGHy0e2h5cr4SvKWE0I=; b=aBIOXVC8f9DUGC52FBvjAl0TCzVjBJQSt94hByrWEqXYENWXvvWRk7lYSgYtCgV0esbtY07Fir0vQYj+PSKh0x66437EvplFuwiWdQl0y8QZgpYLRrqjWK9TozuAq7Fai+62TOPT3sd90+CNUDs5lwZVffFJvyaVfCMZiF29YGc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869150125554.4317063519346; Thu, 5 Nov 2026 00:59:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtJ8-0006B5-1j; Thu, 05 Nov 2026 03:58:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtJ4-0005vP-N3 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:50 -0500 Received: from mail-pf1-f179.google.com ([209.85.210.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtJ1-0003p6-C6 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:50 -0500 Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8a0880a46e7so278786b3a.1 for ; Thu, 05 Nov 2026 00:58:46 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8b097fe0dc0sm1887655b3a.1.2026.11.05.00.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869124; x=1794473924; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Adz/rIkVxKmnpzPklQqKGWWgHGHy0e2h5cr4SvKWE0I=; b=ptGI8x7DDZdlzT58vy52Rb3xkQpzFlMdM0akhpII01EofIRETGdgz/Jfi4u13HxlIt OBKYWX6mXQ6hYIFvKVqOXt42pHsA+JW1EcnFzpUv75+WtCxqUyXnMRiQmp1/QIRaWirE n9Gs0fBHTcUH9ymAZ+aWfTS2mAac3X6cvTAkCtylvgd69zC3MppUWU1ecsTnhII64kJp cXdDxrOOGoFkTauEQvrBVPz66JLfkqYaAqiYZvTGNM7APnbyQdINmAKHI0Fg5Z82eqhT 8wduYzkRbTB5YFPr8nQ6ZjAM2XN/6+Nq0JAmgTbt2O/RAkjwIIDJIXwzz03WY08J0RBS sRWA== X-Gm-Message-State: APuU4Z81HpSJ0L1tyMVpLu2tW0474SwigVEoy4QIvf525NSLE2vcnc0O E5VmnR9NL7QvLFQ07C5xN4iLyP1ggOzah002vacClybmTny3CMKbAq7Io/dyaUgHKt4= X-Gm-Gg: AYBFou2nKLYXcwG+YYUSdAMKU7+JA2rVgviKhoYMkLXTS9zULJ97/qS6Je0Y+Dfjr+R nBd0UPVjMn34I96ffF52qB/p2ipF3iPHHwZ0kARRb5ZYJvpTnLn3gTRqfHXGCVxm/N2o90juTmy GrQVjOcPP2WUomvMkiNG9LkonbvQSaafLobSCQPQn8sRDvL+1DEAbv523YUPAKgdOrwflB3wGSU 563YHLhhucufqvW8YbqGIPG0CLE2yLsMB7YpzTRGUsV83cejBvreqWqpazl7R/oHw/tO2RQrd7W j9PdTE/+CqWc2VMJc828KnuEgEPuBZmCuhZm5RW7BDBp3GGTIt80GBoXowUL3AZ32sZAJEEbafw n0Bi6qx2C15er7nRq23xylf2DpkvPmzQjnmnfC2OSe1PGdnO6yh/XIei6dat+avAeXH7VFqtG7+ orWv1JRoopzRl9UMNy1cnRbz7i7O1TDKW1NA89iiVRIOveIoBcMLtb4GZgCfJAs26xhIR/oF4tV iRwEcj7TYX2bpbp2+w2HYyAs7yTMHaOVcs5tGN7Y0wnbxOPZXeZ3nbINq2XlPL6liFfEc2v6VHo 2PeIhI/bI+N+rIwHtcwYM6bQKAxAeXAVEVgW6qM4cCW4JTDIVZrwBdmy/hleKrWqRbEfCcptRp5 FqB7qlg== X-Received: by 2002:a05:6a00:400a:b0:8a0:6db5:9450 with SMTP id d2e1a72fcca58-8b1e612e4c2mr1270976b3a.38.1793869124456; Thu, 05 Nov 2026 00:58:44 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:51 +0800 Subject: [PATCH 15/19] tests/qtest: ds1339: cover the end-of-month rollover MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-15-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=3758; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=iOwmzyJ4hd6oW//GUNriTfBTlQKKZhGGR+JckreHq5Q=; b=aczM5V7X7kWpZY3oaaYAdR/UfuPs3pgS+59/up+DFOunBG+VEjlsSiYxVlaaPJne4wNqyCmu/ hbXPI9XV+AKDhrh0GUYP4L4pnGMBkLWYpxJ4luKHnbPXhfrPjKa+shO X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.210.179; envelope-from=eblot.ml@gmail.com; helo=mail-pf1-f179.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869151857158500 The end-of-month rollover was untested, for any of the lengths the calendar gives a month. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 60 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 60 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index 8c144579e6..7eec163049 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -14,6 +14,7 @@ =20 /* DS1339 register map */ #define DS1339_SECONDS 0x00 +#define DS1339_DATE 0x04 #define DS1339_MONTH 0x05 #define DS1339_YEAR 0x06 #define DS1339_ALARM1 0x07 @@ -169,6 +170,61 @@ static void test_eosc_restart(void *obj, void *data, Q= GuestAllocator *alloc) g_assert_cmphex(resp[6], =3D=3D, 0x31); } =20 +/* Program 23:59:59 on the last day of a month and run the clock past it. = */ +static void check_month_rollover(QI2CDevice *i2cdev, + uint8_t date, uint8_t month, uint8_t year, + uint8_t next_date, uint8_t next_month, + uint8_t next_year) +{ + const uint8_t tod[7] =3D { 0x59, 0x59, 0x23, 0x01, date, month, year }; + uint8_t resp[7]; + unsigned idx; + + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + + for (idx =3D 0; idx < 50; idx++) { + if (i2c_get8(i2cdev, DS1339_DATE) !=3D date) { + break; + } + g_usleep(100 * 1000); + } + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmphex(resp[4], =3D=3D, next_date); + g_assert_cmphex(resp[5] & 0x1f, =3D=3D, next_month); + g_assert_cmphex(resp[6], =3D=3D, next_year); +} + +/* A 31-day month rolls over to the first of the next. */ +static void test_month_31_days(void *obj, void *data, QGuestAllocator *all= oc) +{ + check_month_rollover((QI2CDevice *)obj, + 0x31, 0x01, 0x23, 0x01, 0x02, 0x23); +} + +/* A 30-day month rolls over to the first of the next. */ +static void test_month_30_days(void *obj, void *data, QGuestAllocator *all= oc) +{ + check_month_rollover((QI2CDevice *)obj, + 0x30, 0x04, 0x23, 0x01, 0x05, 0x23); +} + +/* Outside a leap year, February rolls over after the 28th. */ +static void test_month_28_days(void *obj, void *data, QGuestAllocator *all= oc) +{ + check_month_rollover((QI2CDevice *)obj, + 0x28, 0x02, 0x23, 0x01, 0x03, 0x23); +} + +/* In a leap year the 28th is not the last day of February. */ +static void test_month_29_days(void *obj, void *data, QGuestAllocator *all= oc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + + check_month_rollover(i2cdev, 0x28, 0x02, 0x24, 0x29, 0x02, 0x24); + check_month_rollover(i2cdev, 0x29, 0x02, 0x24, 0x01, 0x03, 0x24); +} + /* The Century bit is guest-writable and survives an oscillator restart. */ static void test_century_bit(void *obj, void *data, QGuestAllocator *alloc) { @@ -314,6 +370,10 @@ static void ds1339_register_nodes(void) qos_add_test("eosc-restart", "ds1339", test_eosc_restart, NULL); qos_add_test("stopped-reserved-bits", "ds1339", test_stopped_reserved_bits, NULL); + qos_add_test("month-28-days", "ds1339", test_month_28_days, NULL); + qos_add_test("month-29-days", "ds1339", test_month_29_days, NULL); + qos_add_test("month-30-days", "ds1339", test_month_30_days, NULL); + qos_add_test("month-31-days", "ds1339", test_month_31_days, NULL); qos_add_test("century-bit", "ds1339", test_century_bit, NULL); qos_add_test("century-write-no-toggle", "ds1339", test_century_write_no_toggle, NULL); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869173; cv=none; d=zohomail.com; s=zohoarc; b=X1OnR1QuAHFgd0d5bWiTmCYCq9afWjDnUwOIJ0IO9FxIh98rYnYXjtZD+oKjgmkE4XLXCY/rWG342jfF1yof8ZyoEy+YM/rRaXR2Y5ZeDAti3ie6YPxWq1K8E/HZEMLA4XLD8vmqMZAmNt6ccOBpe6CuSveQh8a9tnLxPiWGwSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869173; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=D3hF72qvu3mgNYGBtKwkXMBkTiV/O1VMMDWIM4mwyd4=; b=JuwHOd/pLlos5qvkX3fO82f77KytMz5qEq7phzbmWQQY79bcBDe4lxmGNlPOG0yWZPR1by7FKfJg72MNLQxvC7SVTzo8NeMK0o2RkWmZ9PR6CWd+vg0szlNIip6R6f6cH6EFCbg2pu9Rze7pKFg2K2pInjagTDEMrETnjwlzkbg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869173827486.88794981966225; Thu, 5 Nov 2026 00:59:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtJF-0006jS-1R; Thu, 05 Nov 2026 03:59:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtJB-0006Pr-5K for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:57 -0500 Received: from mail-pj1-f48.google.com ([209.85.216.48]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtJ8-0003qT-S7 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:58:56 -0500 Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-3adc4590de4so1441719a91.2 for ; Thu, 05 Nov 2026 00:58:54 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b32678ecsm3136610a91.9.2026.11.05.00.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869132; x=1794473932; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=D3hF72qvu3mgNYGBtKwkXMBkTiV/O1VMMDWIM4mwyd4=; b=axM3X04lUIKfXUNjTxDaGFEig2nlglBou8GsuqnMfrF+n6Retj+DB12n8ATncfIO/F MICILNRTfSZgGrPcXhFwV6oCUphzSa1WILdVidBfGN8GsfG8/vrSQSJdxTDQ3QLOM6D4 Bzu1Ytd6GtTkIiu0e1CC9I9XwEkhI4qVTdEdMAKEXnv6o0kRIa3UahLdcDyKPIl0CmTD VL+67s6qFAVj/hSi0cdBGlHl0ZQH1R7mvLDW6PhP/TFYMuJkak3o6+HuVV0XBUoROQ9l N720UeQL/ZMXZa/eTpkRcItExBOoSvMoNoWYkPavp9UGhmVJu4s0Fnnwvp70d+My7N0A o5+g== X-Gm-Message-State: APuU4Z8CuNeK/d6dfryRPoI8UfjOkbNsgGG19RUYQF18o0qSI7IGsRXA /cZR7/l/sD2MhPcjU50wqas/K0HeqmvfbbDQQ7jkzufbDCuMgHk6LW7WB1wjzGMnFuo= X-Gm-Gg: AYBFou3g9FJ0O1802Oe1FJZRZTJPIrwApQuPJE1ZsUlUooxkEcuk4ZQ4sp6WzSNWrYB QzEvBxj+E21mKdduP0fEQa7bCXbi7ZqH6gDGkqZxFkRzefKTctWIBu/oAb4fypTUv2p0C4Sp+fN MflaFWrWeBgL0QV/J1mb0nvIGhk+b+Mq/L0vE6xLWv7x10h4cuPm0aLUolIRE53q3c02NtPLVQs 8MVbGRpRuJE0aGpeWwlp1YGV4pRssU16VQFS4PpDNedbv/9Gh1JUcIL8gQETR3J5zI3qL4uvI/V lDqmKHDZ8u62S3A43rfFsG9WdS/TrfdRwXHJlRi9l9jTsxbcfpNpVqlKqzTQkhFdxD1rixuQ8Kh z87foBqFkgdJKEA8BCAcxjilXp4aPRLLLwXz318avaehSPiBMrUrQzGJ2cuRQ5TGbv/CmAOav8J 3nkzP4KN1RBxRgCBpNikYe5ZUFzWUYesrCYf0U32GeOmVtCNzFTs7dDEhDFcvPYmunwS0Ti8l9p ftdh9vJ9wAwyreGIFtxePyKitGEkKW5bw2T6uAZXQoAlNBIdqXLmMHSA1PlHKBJPq9dgb4sYY1z czU0+L+Ihl0fNDvqC0/2o2eN/BFWMD5nohID3XSLRhT1BrEar6lShEdLZ2Ylx2bEEAd46HIPmni b+kLiVQ== X-Received: by 2002:a17:90b:28c3:b0:3b0:ae41:2707 with SMTP id 98e67ed59e1d1-3b0ae41298bmr2190428a91.45.1793869132267; Thu, 05 Nov 2026 00:58:52 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:52 +0800 Subject: [PATCH 16/19] tests/qtest: ds1339: cover the 12-hour format MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-16-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=3522; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=H+2NRBVduAD0kusIRvsLO1TF7emsp4ss30ZRGVmVNhU=; b=gIUjxoRzKDS0r9jgzfLmn02mP+6bFwZNVGEqs4tVQCy/KXUmq69cirw/B1ihnpEwtHW4c3msB iTfRXr5V9V4ASOdqQrP81F1+qpUeykuJv/IuqJeib4Gj9OmhBQbWSeL X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.216.48; envelope-from=eblot.ml@gmail.com; helo=mail-pj1-f48.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869174363158500 Both directions of the 12-hour conversion carry a fixup for midnight and noon, and neither had been exercised. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 45 +++++++++++++++++++++++++++++++++++++++++++= ++ 1 file changed, 45 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index 7eec163049..3259fa1df3 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -14,6 +14,7 @@ =20 /* DS1339 register map */ #define DS1339_SECONDS 0x00 +#define DS1339_HOURS 0x02 #define DS1339_DATE 0x04 #define DS1339_MONTH 0x05 #define DS1339_YEAR 0x06 @@ -26,6 +27,9 @@ =20 #define DS1339_STATUS_OSF 0x80 =20 +#define DS1339_HOURS_12 0x40 +#define DS1339_HOURS_PM 0x20 + /* The clock and calendar come up on the host time. */ static void test_time(void *obj, void *data, QGuestAllocator *alloc) { @@ -170,6 +174,46 @@ static void test_eosc_restart(void *obj, void *data, Q= GuestAllocator *alloc) g_assert_cmphex(resp[6], =3D=3D, 0x31); } =20 +/* Midnight and noon are the hours the 12-hour encoding special-cases. */ +static void test_hour_mode_12(void *obj, void *data, QGuestAllocator *allo= c) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + const uint8_t tod[3] =3D { + 0x59, 0x59, DS1339_HOURS_12 | DS1339_HOURS_PM | 0x11 /* 11:59:59 P= M */ + }; + unsigned idx; + + i2c_set8(i2cdev, DS1339_HOURS, DS1339_HOURS_12 | 0x12); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_HOURS), =3D=3D, + DS1339_HOURS_12 | 0x12); /* 12 AM is midnight= */ + + i2c_set8(i2cdev, DS1339_HOURS, DS1339_HOURS_12 | DS1339_HOURS_PM | 0x1= 2); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_HOURS), =3D=3D, + DS1339_HOURS_12 | DS1339_HOURS_PM | 0x12); /* 12 PM no= on */ + + i2c_set8(i2cdev, DS1339_HOURS, DS1339_HOURS_12 | DS1339_HOURS_PM | 0x0= 1); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_HOURS), =3D=3D, + DS1339_HOURS_12 | DS1339_HOURS_PM | 0x01); + + i2c_set8(i2cdev, DS1339_HOURS, DS1339_HOURS_12 | 0x11); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_HOURS), =3D=3D, + DS1339_HOURS_12 | 0x11); + + i2c_set8(i2cdev, DS1339_HOURS, 0x13); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_HOURS), =3D=3D, 0x13); + + /* An elapsed midnight moves 11 PM on to 12 AM, not to 00 or 13. */ + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + for (idx =3D 0; idx < 50; idx++) { + if (i2c_get8(i2cdev, DS1339_HOURS) !=3D tod[2]) { + break; + } + g_usleep(100 * 1000); + } + g_assert_cmphex(i2c_get8(i2cdev, DS1339_HOURS), =3D=3D, + DS1339_HOURS_12 | 0x12); +} + /* Program 23:59:59 on the last day of a month and run the clock past it. = */ static void check_month_rollover(QI2CDevice *i2cdev, uint8_t date, uint8_t month, uint8_t year, @@ -370,6 +414,7 @@ static void ds1339_register_nodes(void) qos_add_test("eosc-restart", "ds1339", test_eosc_restart, NULL); qos_add_test("stopped-reserved-bits", "ds1339", test_stopped_reserved_bits, NULL); + qos_add_test("hour-mode-12", "ds1339", test_hour_mode_12, NULL); qos_add_test("month-28-days", "ds1339", test_month_28_days, NULL); qos_add_test("month-29-days", "ds1339", test_month_29_days, NULL); qos_add_test("month-30-days", "ds1339", test_month_30_days, NULL); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869150; cv=none; d=zohomail.com; s=zohoarc; b=Xtj70p2PqPu0C4yEkP9zXmq3/IcLNUEO3PY0ppXkSs9iM9lrNFkUNXHFlcyfZqlHwwxyW+E7BRR1F/AYTqYw1CfniAewlcrkFJQRN85Q3pa/g8GlQvhdRhMiHmI5AAioLHodki/isGGFe8KO4vs1pQj3ix1WGTXm8NMkPbnwf9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869150; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=imFMkJM4Su/meWF7Bk/irxYZZDqQDWRnzR3YhZvsMNY=; b=CwU04kZjHVjGg/8dwqRzx7fxNsqsnMS9Lt0C5d7UlVybYYJOB1KVy0P58fESNdvayRaV2qSaJ4GxP+6xegiJ3dwGdbygY0PMCwzVOS/pAJ1yENaOwFn4YOrBO+C6PdCGbXVNBOYJslkItpJQTSp8yiiA9CTHSCTSeyvYvERPloM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869150642195.31240711486407; Thu, 5 Nov 2026 00:59:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtJL-0007IN-Cj; Thu, 05 Nov 2026 03:59:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtJH-0006zj-VY for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:59:04 -0500 Received: from mail-pj1-f45.google.com ([209.85.216.45]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtJF-0003rL-T3 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:59:03 -0500 Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-3ab41538192so1358952a91.0 for ; Thu, 05 Nov 2026 00:59:01 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b313c143sm2912122a91.2.2026.11.05.00.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:58:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869139; x=1794473939; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=imFMkJM4Su/meWF7Bk/irxYZZDqQDWRnzR3YhZvsMNY=; b=SoWI1sERSMXCROdS2G5IvZZJvZMfkyykF8himYT/4B8xDKR+cnmXe+OZEvZGmeSR/V c+ZbyuA6VhL3E/uZQHiOU6BE+8ZEoL5nXfqfI5Va/Gx9l1v6AO58Y19PTxpIGKHqT5ab B8i040gaurAa01hbNnGzAi1PU3w4mgaC2sE+qWixJdtpBK1/mrzUCiGT1LmpcrPEcTAd F/Rewi3tDjwlQVWb5ywTe/e7bZZSnKbsjlyzWapeFygo+wshRsRU856BGjHzrHs7ue27 ziIXHBReFbb9lp6FG2Heq88ylKwMRuSsXN23TdJ4A+OZntn3adeAh7X6BUCqjAQpYcQF 6/7w== X-Gm-Message-State: APuU4Z/dEV2RFfIjd3ruDVKrTethPEOezs3j3O+Oq4IuUPG5pErTzjro KCCbuHH03d1FUaQVRNXVgkj2HoWmRVm2d7EFD4pl+ajmkWU5MFPRtimrgrRZjKyTF2E= X-Gm-Gg: AYBFou3tmngmUTNPyHDAvicFPI0VjI7Fz+G/wsCqn6TrGOklWXr4RFGYRCwRA5bCTpT wWq5vmQb0Sr/OzwcIqsh1ZocStlfNvuDlSzOXkLKTSym7wgXYpwCwRA2OjWMNPIMLv37HkyIARM m55hZY/5RASdbf0+FY+YWzV1weYZhylOk9Dhe96OkhH58OJfSYTT2kIl3Tt0aM6fcTrgZTEwxmx MFeBUAIwzEdxT/zAQCRqT2ZMz0QuBu4ryuniP3TrOiDkv0dSWdfGHiH7NfOkQN1WkOiBQlnyMeg dIQMFijaFd0b6CDAktRfnHTnXCDOBA/yCi3l1tQQTSTjzwMA4IvhAn8VrQ7OHcHZiDl188Q9cDl aLIwzpRx2sp00V3q5UwP/CjwTbiOXqHGAJRocfXgjN71BzU7hgGlDZZOTHjwBF9eojA0JJi328K izT8tTD0eXpIjXdyLmb8oHMD6t3rjNW3rIPLdISbF7myiHJ61ao0DlsYctsOKuYsTvBhLqJw5XQ AYp+wwMGoPUSFZFA7k1MZ3C/pj4VNS3NMoDyOaJBSybJLhzC74o43CwH56elF5HEIAlYCG6J4Kx BldT+GW4ZM0c/k8Z3O4+KtzVBtnQL+d9mjxv/9RVTd5XHXWuudzKGZhBYYh16gk4kyqywx+F2bD AND4TEQ== X-Received: by 2002:a17:90b:4d85:b0:3b0:a378:1cf with SMTP id 98e67ed59e1d1-3b0a378049cmr2988421a91.22.1793869139290; Thu, 05 Nov 2026 00:58:59 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:53 +0800 Subject: [PATCH 17/19] tests/qtest: ds1339: cover the day-of-week counter MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-17-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868640; l=2635; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=eyo+ejkyIwGpn53A6NDRDtcAT+GA1L3xUgmQjCv7Q5U=; b=zhPRDSo2ujJgQ9oQZNK7SLcFBa/Q1z1VOoCTrgUam58E6o7BDfq9EGvF/LCCLM8287s3ElFjn hEHCpgP0L9HCuHpdUqUOd948R0RBToIBqaOrY1yMfO07vBP8+R/XN5o X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.216.45; envelope-from=eblot.ml@gmail.com; helo=mail-pj1-f45.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869151837158500 The day-of-week register and the offset behind it had no coverage at all. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index 3259fa1df3..12562eff5f 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -15,6 +15,7 @@ /* DS1339 register map */ #define DS1339_SECONDS 0x00 #define DS1339_HOURS 0x02 +#define DS1339_DAY 0x03 #define DS1339_DATE 0x04 #define DS1339_MONTH 0x05 #define DS1339_YEAR 0x06 @@ -174,6 +175,36 @@ static void test_eosc_restart(void *obj, void *data, Q= GuestAllocator *alloc) g_assert_cmphex(resp[6], =3D=3D, 0x31); } =20 +/* The day counter is the guest's own numbering, and steps at midnight. */ +static void test_day_of_week(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + /* 23:59:59 on 14 June 2024, the day counter reading 7. */ + const uint8_t tod[7] =3D { 0x59, 0x59, 0x23, 0x07, 0x14, 0x06, 0x24 }; + unsigned idx; + + for (idx =3D 1; idx <=3D 7; idx++) { + i2c_set8(i2cdev, DS1339_DAY, idx); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_DAY), =3D=3D, idx); + } + + i2c_set8(i2cdev, DS1339_DAY, 0x03); + i2c_set8(i2cdev, DS1339_DATE, 0x14); + i2c_set8(i2cdev, DS1339_MONTH, 0x06); + i2c_set8(i2cdev, DS1339_YEAR, 0x24); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_DAY), =3D=3D, 0x03); + + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + for (idx =3D 0; idx < 50; idx++) { + if (i2c_get8(i2cdev, DS1339_DAY) !=3D 0x07) { + break; + } + g_usleep(100 * 1000); + } + g_assert_cmphex(i2c_get8(i2cdev, DS1339_DAY), =3D=3D, 0x01); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_DATE), =3D=3D, 0x15); +} + /* Midnight and noon are the hours the 12-hour encoding special-cases. */ static void test_hour_mode_12(void *obj, void *data, QGuestAllocator *allo= c) { @@ -414,6 +445,7 @@ static void ds1339_register_nodes(void) qos_add_test("eosc-restart", "ds1339", test_eosc_restart, NULL); qos_add_test("stopped-reserved-bits", "ds1339", test_stopped_reserved_bits, NULL); + qos_add_test("day-of-week", "ds1339", test_day_of_week, NULL); qos_add_test("hour-mode-12", "ds1339", test_hour_mode_12, NULL); qos_add_test("month-28-days", "ds1339", test_month_28_days, NULL); qos_add_test("month-29-days", "ds1339", test_month_29_days, NULL); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869173; cv=none; d=zohomail.com; s=zohoarc; b=apjylA9zF9YL+gNI5QJQoJOxduGfEiW3ZE7BBtXGmc6cKJMpo4fRIApqY2nFdArv1CCVTWxoI3R0bjCEJiV++KNNuReYzNhY9SzyohKlAwLovsqrTRJdV++w9i39H1WOejCniSG1ZhbuEAbDPj9KVYr+9nUYRwVA12qf/kWtqY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869173; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=UoANilWHPQU+jFLM2oOvVUgxMcTpl1I7pWBnWHE9eEg=; b=jw9DZAUb8XMljXknMi5e7r2O73IqXxXKT3Tqm8PndaNAb+BzG1XsVBHxnsC/C3+edqM3eUuooHS5D1GL6HfSwJDr8GrTj5o6V1cwrS1IF4hz71xYUIHuXOR/hwcUmfYbguOgl62/KtrZWfA79goRbcOR6S8a29VHSqaJmvO+Leg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869173952702.571393306774; Thu, 5 Nov 2026 00:59:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtJi-0007xA-2r; Thu, 05 Nov 2026 03:59:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtJP-0007k1-FD for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:59:11 -0500 Received: from mail-pg1-f169.google.com ([209.85.215.169]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtJN-0003sQ-Ee for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:59:10 -0500 Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-cc4c02ddd62so1059352a12.0 for ; Thu, 05 Nov 2026 00:59:08 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8b09a7cc077sm1775988b3a.15.2026.11.05.00.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:59:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869147; x=1794473947; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UoANilWHPQU+jFLM2oOvVUgxMcTpl1I7pWBnWHE9eEg=; b=Xl/0372U+kGBrytQTgxfzfldU4M4gSW74wiwY57DeXGASBRjednsfLfHliys2Ai7Qr lyvUmaMWmURsRkBYNOJkspmDATWjpJAuNJG4YhLoy+TDorRaV9+igMj5S44b/sGqh34e sI5sJNWdpyUI0/MOcplBe6+CmG5Sri8v1tvHzIIN3FS1zOXA3BarWX3Yh2Z/8zOCXaYB CD7aCU/ZK3diKKsR16jzhZMVcBC5NopMO6qx/KqtYAf1mNygyn9zZ3Qm2Gcu7v2VXIc8 uTalBsOu6NYx+U8bvTMx2Nu6zizIy/2BW9NaFaQt5A3kLJHO3dGTB34eFO0EBfUA9Hhc NRdQ== X-Gm-Message-State: APuU4Z+tTCHnvR0uHAlrN70Qt1z9g2NWQ4pL7Ifrz5tBLDCsnz1gWX50 3A8SYm8O2YikbcWCOL1HumcFH3pYeA8cAG2R+9cTIAHxOI+hQpATaoacYYOh/kWQlrU= X-Gm-Gg: AYBFou2ZtTURGohCS2JVgz4rjwoJ3L8rwUKlj8/rWpcrLCc32lT7015bBvWlhj1Zghe ooRuF8xqZj9KdisqbC8GO8CRKm6oVLYhLdX5gRdGG3+DfwV3vj3A2Db8VokiMmZTTvDXrG2EaO9 QXx7Jb0r0I7X33PnNU9xCLeyG0yy47oZbqTt3NFZR9QG1HuVQ5TWowS86Eqq1KhJOI3bUU10FV8 WS56wGDTsCksuqjaaFmDmm3gXSjJ0ajncETpStNwXXrp8v6KiDpxCMWrwHAJqdqqWp9RGC4Z8gW 4cJjUznMpylq+IONKirnasrgmCRe6mMS51iiTJQRlrmWIEcbwEHXqEGeB/5bE5PbDbD0/c3qGK8 NWZHD9AvxAAapA6quQIrtlAEn3Cfod7sW6dRJWPXsJA3rKlttiQYuKCK8CrGOxtIe/ME+SgLDU0 5k9leSOdotQ+A9ckFBiAfRlywBE4T+GPWPMp0BWvIy1XY1P9+vFrgMJOthvHoQ1Ls5eMZxehsGJ /XhmREigiKDOlTDRp5w73Pnt+SFdN287IVPROSDlr8Xe2sTwkT8Rem/5HJ52b+AtHW6SV2J0ooM 3KJZQ1nBTPFtKTSSxYS7F6a3Mmp1Na6lyw8qYKFcAtpB5mwlYX0yQEGswDtbjhLzWb7sdGFH1rN XXv6nWg== X-Received: by 2002:a05:6a21:a88:b0:3e2:b400:2b04 with SMTP id adf61e73a8af0-3e929010560mr16241243637.45.1793869147203; Thu, 05 Nov 2026 00:59:07 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:54 +0800 Subject: [PATCH 18/19] tests/qtest: ds1339: cover persist-on-reset MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-18-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868641; l=3352; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=KvLAOs8b9crRgRWHo/H40bGm4hfaQpkysjJaNXTXaqY=; b=eimiYI3Mtrfb0xV5ZD9t6RuK3n2eMBsxlUne/S4uRRy0BK8L3f3wy4X+rbbKm4qXscmkgv45B WSc04NHtrKYB7gT6NincvNPGuzvyVH2I5JJw+ad2RDiUeu4/zMFHB1H X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.215.169; envelope-from=eblot.ml@gmail.com; helo=mail-pg1-f169.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869174362158500 The property was untested on this variant. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 56 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 56 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index 12562eff5f..a1b5afb331 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -8,7 +8,10 @@ =20 #include "qemu/osdep.h" #include "qemu/bcd.h" +#include "libqtest.h" +#include "libqtest-single.h" #include "libqos/i2c.h" +#include "qobject/qdict.h" =20 #define DS1339_ADDR 0x68 =20 @@ -426,6 +429,52 @@ static void test_alarm_registers(void *obj, void *data, } } =20 +/* A reset restores the power-on state, unless persist-on-reset is set. */ +static void check_reset(QI2CDevice *i2cdev, bool persists) +{ + uint8_t year =3D i2c_get8(i2cdev, DS1339_YEAR); + /* A year the clock is not already showing, so the check discriminates= . */ + uint8_t marker =3D year =3D=3D 0x42 ? 0x77 : 0x42; + QDict *rsp; + + i2c_set8(i2cdev, DS1339_ALARM1, 0xa5); + i2c_set8(i2cdev, DS1339_STATUS, 0x00); + i2c_set8(i2cdev, DS1339_YEAR, marker); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_ALARM1), =3D=3D, 0xa5); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_YEAR), =3D=3D, marker); + + rsp =3D qmp("{ 'execute': 'system_reset' }"); + g_assert(qdict_haskey(rsp, "return")); + qobject_unref(rsp); + qmp_eventwait("RESET"); + + if (persists) { + g_assert_cmphex(i2c_get8(i2cdev, DS1339_ALARM1), =3D=3D, 0xa5); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_YEAR), =3D=3D, marker); + } else { + g_assert_cmphex(i2c_get8(i2cdev, DS1339_ALARM1), =3D=3D, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL), =3D=3D, 0x18); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS), =3D=3D, + DS1339_STATUS_OSF); + /* Back on host time, which is where the year came from. */ + g_assert_cmphex(i2c_get8(i2cdev, DS1339_YEAR), =3D=3D, year); + } +} + +/* Without persist-on-reset, a reset takes the part back to power-on. */ +static void test_reset_clears(void *obj, void *data, QGuestAllocator *allo= c) +{ + check_reset((QI2CDevice *)obj, false); +} + +/* With persist-on-reset, the registers and the clock survive a reset. */ +static void test_reset_persists(void *obj, void *data, QGuestAllocator *al= loc) +{ + check_reset((QI2CDevice *)obj, true); +} + static void ds1339_register_nodes(void) { QOSGraphEdgeOptions opts =3D { @@ -459,6 +508,13 @@ static void ds1339_register_nodes(void) qos_add_test("block-wrap", "ds1339", test_block_wrap, NULL); qos_add_test("alarm-registers", "ds1339", test_alarm_registers, NULL); + qos_add_test("reset-clears", "ds1339", test_reset_clears, NULL); + + opts.extra_device_opts =3D "address=3D0x68,persist-on-reset=3Don"; + qos_node_create_driver_named("ds1339-persist", "ds1339", i2c_device_cr= eate); + qos_node_consumes("ds1339-persist", "i2c-bus", &opts); + + qos_add_test("reset-persists", "ds1339-persist", test_reset_persists, = NULL); } =20 libqos_init(ds1339_register_nodes); --=20 2.53.0-Meta From nobody Mon Nov 23 04:29:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793869183; cv=none; d=zohomail.com; s=zohoarc; b=fxyi6AxOBoyqT2DBkmvjgH1PLLqoH/JuPrrNNv/MCA85cVjjLj7DgnF/cBC5fbjHRlqatwqU6euS1JeMFBCGw1E/nYAtN1CmTjDE3eKDA1C0IJT95RHCdTN/pDPpIYiLa8VnZAYFmqvohrqnXRRWQA/PGf6q5ZRnAKlnpyGT0B0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793869183; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=j+gXiFsnHI5EyngmwOix3lm5w1ZzHauKps/Zt2m/+e8=; b=ltxBv7uGhqI7TVaRzLW7bVCAeBGaE4Tfb6dIk1siiVWGz6IddYJgxJovT5cRaREKRzAqqSAxKDl9sXUm4S4z01P78nAhPDfjFS0KeqtdWfSN6O+F5i3YZ4104wEBYsCuhrEHWib8M5Yq7h0OF6UxFil875LuGM5NUbE8Fzk5QVs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793869183337267.36655902531504; Thu, 5 Nov 2026 00:59:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOtJl-0008GW-QI; Thu, 05 Nov 2026 03:59:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOtJZ-0007yp-CB for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:59:23 -0500 Received: from mail-pg1-f182.google.com ([209.85.215.182]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xOtJU-0003tf-D2 for qemu-devel@nongnu.org; Thu, 05 Nov 2026 03:59:19 -0500 Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cc502d509c0so691921a12.2 for ; Thu, 05 Nov 2026 00:59:16 -0800 (PST) Received: from localhost (118-163-122-149.hinet-ip.hinet.net. [118.163.122.149]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b313c0dcsm2904124a91.1.2026.11.05.00.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 00:59:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793869155; x=1794473955; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=j+gXiFsnHI5EyngmwOix3lm5w1ZzHauKps/Zt2m/+e8=; b=aAxDGpwq8nsAuagFHAom3Y3r3GRRnMvwNjFfcrBGOQ24ZDRhTKUhRhvjQwYw/xFhTm /Vh3vMLfmBFgf5cLwJmNMtGkVhQVrGrQBM+0UmvceDvtMBRDivJRTuiEdmBsLBU3bOW3 6VEiP2ws4PPHm9P97u7lLcGuoOplzN0baPb1ypCsPmxe+ImdvaNdYKE0wbYwpCwJSgth bagV+oQXNa4ll+qg9wZjuQglVI81xPHuVaegX8Qkz0LgSe60VHrRvFSUsexx2MAKP59O 2Oa2AlM6jC5YqoSS0eSENjN3h50/qk8hPkHrZrF/pwpELFSfziZiCC9YgWajDUnpeEX+ TiKw== X-Gm-Message-State: APuU4Z98CVySiMjjzESeQySp5HxN/T6cj4NmtebB0Huy8YhFbI5h2qj+ m4jlc4X7tMa28TyBtbIhv/353cRjspp+/V4wHbTzrXc8OjNA12qSmP0VDh9vIbzmLic= X-Gm-Gg: AYBFou2SSI8jL/LXGFuxks80Lba1RIii8TlMiP4IDHAN9e287cM0fkKW/dGjs6WkAhu l34W89NtKUQ9llZGrvV0ZAu14u5jGINfhnPWHoACDAttfUe2Yb8jP5xB1+xi2hvW5Yp3tECmUcU FI8CFXq81ArnK9nO9VlXbXIOzGGTKiT2wEdMzZKXO/FclEhICyTZoyEyCxq638C7+t9RGFIQLq2 wBgV5dvDlYecF/gtfdBMBVvz28uPaKy10m1P2+RSCqVwcIrCX1lKqeF8gGA39fBd+PfmHY97W8x Fx9Gki9T+PZ/aBpqO8JIcFrHJHVB+ykeAwuxkEYknsUM+Hswowywku/w6BmeQV/rb3HmdSsXwOo ZRac4wji+IeRWQOV0Qv+4bYvff2gKg7SRE5UJTKHyvWRdB5i4c/1Zc9UBr2R1etdXzbdbWGh7+P MWrJhUjPzinYonqxoXj0CtiwvRY45y4Be1nTKR0iGhsfx/wyxknwK4sDbeEG4GBdA5TI+yF8fBf mAMKLqB3osOJd+KCOYfzw4prH8/ughoi5vxR3hwhHXId8DxwNLrNRpg1hesu/+PJd7Se3xlLaEz MEkWj9xV3ed6nlvjaiW2zY3TB+Zs51ieXCoKzUOG2QA4l5iv5Y6/g1yMal5NVKU/x5AXA9uWl4/ MNgdqLQ== X-Received: by 2002:a17:90b:2711:b0:3ac:7449:40b4 with SMTP id 98e67ed59e1d1-3ae8981bdebmr13627664a91.45.1793869154888; Thu, 05 Nov 2026 00:59:14 -0800 (PST) Date: Thu, 05 Nov 2026 16:50:55 +0800 Subject: [PATCH 19/19] tests/qtest: ds1339: cover the migration round trip MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261105-rtc-ds1339-v1-19-50a8dc463ee8@free.fr> References: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> In-Reply-To: <20261105-rtc-ds1339-v1-0-50a8dc463ee8@free.fr> To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , eblot@meta.com, Emmanuel Blot X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1793868641; l=3505; i=emmanuel.blot@free.fr; s=20260602; h=from:subject:message-id; bh=EVk3l6BltgZHiZGej4u7LBFepngMOkTM/mSpC5HjJ9U=; b=3m41MzT78EtX/lzWApcElgYPcba0rBS/xcTaPu3c32CRiVNhVpsX3oPZKq8qwHO2fDaoP1r9c eSBlAsEJHHVDsxShGGHlBiMebK0KfU6M+aKV4JAGUdK0+9ZNxZonQzQ X-Developer-Key: i=emmanuel.blot@free.fr; a=ed25519; pk=0qFrZ21FAAN8OfVsSoVcCFTk/NMYOWzxJz4paSAVm0g= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=209.85.215.182; envelope-from=eblot.ml@gmail.com; helo=mail-pg1-f182.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Emmanuel Blot From: Emmanuel Blot via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1793869184292158500 Nothing covered the migration of the register file or the oscillator state, so a dropped field or a wrong version gate would have gone unnoticed. Signed-off-by: Emmanuel Blot --- tests/qtest/ds1339-test.c | 61 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 61 insertions(+) diff --git a/tests/qtest/ds1339-test.c b/tests/qtest/ds1339-test.c index a1b5afb331..ca2378aa34 100644 --- a/tests/qtest/ds1339-test.c +++ b/tests/qtest/ds1339-test.c @@ -7,9 +7,13 @@ */ =20 #include "qemu/osdep.h" + +#include + #include "qemu/bcd.h" #include "libqtest.h" #include "libqtest-single.h" +#include "libqos/qgraph.h" #include "libqos/i2c.h" #include "qobject/qdict.h" =20 @@ -475,6 +479,62 @@ static void test_reset_persists(void *obj, void *data,= QGuestAllocator *alloc) check_reset((QI2CDevice *)obj, true); } =20 +/* The register file, the Century bit and a stopped clock all migrate. */ +static void test_migration(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + /* 23:59:59 on the last day of 2099, Century set. */ + const uint8_t tod[7] =3D { 0x59, 0x59, 0x23, 0x03, 0x31, 0x8c, 0x99 }; + g_autofree char *tmpfs =3D NULL; + g_autofree char *mig_path =3D NULL; + g_autofree char *uri =3D NULL; + GString *dest_cmdline; + GError *err =3D NULL; + QTestState *from, *to; + uint8_t resp[7]; + QDict *rsp; + + tmpfs =3D g_dir_make_tmp("ds1339-test-XXXXXX", &err); + g_assert_no_error(err); + g_assert(tmpfs); + + mig_path =3D g_strdup_printf("%s/socket.mig", tmpfs); + uri =3D g_strdup_printf("unix:%s", mig_path); + + /* Stop the clock first, so both sides have the same time to compare. = */ + i2c_set8(i2cdev, DS1339_CONTROL, 0x18 | 0x80); + i2c_write_block(i2cdev, DS1339_SECONDS, tod, sizeof(tod)); + i2c_set8(i2cdev, DS1339_ALARM1, 0xa5); + + dest_cmdline =3D g_string_new(qos_get_current_command_line()); + g_string_append_printf(dest_cmdline, " -incoming %s", uri); + to =3D qtest_init(dest_cmdline->str); + + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); + g_assert(qdict_haskey(rsp, "return")); + qobject_unref(rsp); + + qmp_eventwait("STOP"); + qtest_qmp_eventwait(to, "RESUME"); + + from =3D i2cdev->bus->qts; + i2cdev->bus->qts =3D to; + + i2c_read_block(i2cdev, DS1339_SECONDS, resp, sizeof(resp)); + g_assert_cmpmem(resp, sizeof(resp), tod, sizeof(tod)); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_ALARM1), =3D=3D, 0xa5); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_CONTROL), =3D=3D, 0x18 | 0x80); + g_assert_cmphex(i2c_get8(i2cdev, DS1339_STATUS) & DS1339_STATUS_OSF, + =3D=3D, DS1339_STATUS_OSF); + + i2cdev->bus->qts =3D from; + + qtest_quit(to); + g_unlink(mig_path); + g_rmdir(tmpfs); + g_string_free(dest_cmdline, true); +} + static void ds1339_register_nodes(void) { QOSGraphEdgeOptions opts =3D { @@ -509,6 +569,7 @@ static void ds1339_register_nodes(void) qos_add_test("alarm-registers", "ds1339", test_alarm_registers, NULL); qos_add_test("reset-clears", "ds1339", test_reset_clears, NULL); + qos_add_test("migration", "ds1339", test_migration, NULL); =20 opts.extra_device_opts =3D "address=3D0x68,persist-on-reset=3Don"; qos_node_create_driver_named("ds1339-persist", "ds1339", i2c_device_cr= eate); --=20 2.53.0-Meta