From nobody Fri Dec 19 17:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1733512353; cv=none; d=zohomail.com; s=zohoarc; b=Z46H0EmS5qPAcDRrO553WL9wax6/ize6kVCFw3ZOX9kE3GE6un95ygDZ/MNgXKJFzqrxTtLG912rib9lftSUMlLOne38gfBdvBUFjsW3wRRUYy6b3+bLdk/kLOJ8Iymo+Afj8RE4tepkHt9BzjyBkagtmDC4oRw2fbrH5REnLyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733512353; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=usuUWxdQ8ewKippAge2X3v0Dk+bE+NLkyVAycBl0ZOQ=; b=nzRE56h2+fV/xfD7FNaPlGF0M5C5Fp0QYdKTnRulMbAJxmMjVP9X0ROx0RcuwV0iZFonpKfOWAjTYgG8Yye7zfXq1MnrdvY/MZZU16MBIt+vNEPXNbbLpZPB1zDDRkVYYGicacY0hYqyj4QRE2QSTaAs5Ab7keheRp53giSLFDs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733512353886145.3784766054472; Fri, 6 Dec 2024 11:12:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJdkB-0005xe-Va; Fri, 06 Dec 2024 14:12:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJdkA-0005xV-Vt for qemu-devel@nongnu.org; Fri, 06 Dec 2024 14:12:03 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJdk9-0001fS-6k for qemu-devel@nongnu.org; Fri, 06 Dec 2024 14:12:02 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-385e2880606so2074950f8f.3 for ; Fri, 06 Dec 2024 11:12:00 -0800 (PST) Received: from localhost.localdomain ([95.127.41.180]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-386219095easm5400867f8f.83.2024.12.06.11.11.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 06 Dec 2024 11:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733512319; x=1734117119; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=usuUWxdQ8ewKippAge2X3v0Dk+bE+NLkyVAycBl0ZOQ=; b=rxmsR1l/a4FkHH7rqqPFaJ55XtXrBfFk3Vv57OqjHE5U6BUP2syAZy4vVjhx/dX+TE w2fwLFZPp6eJn+H62wM9FvnMauDHKpf2YiiB/TWeUQNnPLNObowTE2YYw2lqRW1gwoLl FMyWxZ5yjH6XFZd/Fil4KE70kOBE2N9LoXyHC8cSeaVj0gk2LSjimhEoJ9d9BwZYInQt q0DdrA69d0PvMFmKLnF99ojm2X7YT/cj179q0MOjuaAQfQ7h7vnIMxLA9gjDMAJ1Y9eO AJ3aJ6Zvv6xEBsBt2u78MRGltcya6Fm8Dw5w8/rLg3kOiODtVdcCUmO3J/HRhTk6OLUD U8Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733512319; x=1734117119; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=usuUWxdQ8ewKippAge2X3v0Dk+bE+NLkyVAycBl0ZOQ=; b=EuI0aPwZrmTUWFTqJhSDom3qjpC2aOP4UQ2FGnWbhvpOn4LZJDTZdn5dhdF5ZTp3xH w6VfluoAh+SHMtjczk+zav2Xe2Pp6WoJvAyzlMKebLWut141Ez4sswBFwSl0gIXg2FNE dAcri6rXULf7Sji0AsErEMJsk11sjVpj8Fk9jCxcdzQM0eorv6zz8Fyf0X3z7P2uc+Qa x7rCO7qei8Y8Yvho3OH2D446A4NNJhLyiAp6YkygNAo9ElAK7Gza2o5bMslTYrkedIXm o7+Gkvy0YbHQb+CaJdkC4otVbvJhAlu8GaLG1Pi6VuIE88fQ8ww5c090oyrsXYfhsgaM R8nA== X-Gm-Message-State: AOJu0YxME0vs9WyxKXpHvsQRhNLFIKlGvoU+vctnAfaMCr7hB0ElmOG9 QbdwLJLQcub6TKqAUKc64SHULliGWwT9a/QcJ81eiftJ6LPlKSvucnj55NNohy7Ah1GuDDW94fj V6X4= X-Gm-Gg: ASbGncsd61Hw2pJ5K5kmFC/0YWXq2YDhrgv5yK+GA5rOAEQea21VnHjlNUkRjcdD7cu gGwNrL3zuoT6h3RHY0MRXmctS9kK9q4iLoXfiEJe/afz9ykMbZKTRLQilwpb25lIjlAVM9fIEBt KXiY/Kld9pWT1kfYvp9tQxHt46MLzS3vgkqlraDGUVDqO71r7jK0je+ux/MfRg6riEanm1nAhJX y8ixYHifdnzerKjGlTe1sZyTdB3UXf7UFcdtlPLfig8Uc00z7f4GaD0Ya+qNkaHkgA= X-Google-Smtp-Source: AGHT+IGLZHNP1iVokAKRip01VWw4auDu3tIDhR95tQQDmSfTUI6AuJvvISDTyS1PxmPYxeH7LzCG4A== X-Received: by 2002:a05:6000:401e:b0:385:e4a7:df09 with SMTP id ffacd0b85a97d-3862b3cdcd3mr3352553f8f.44.1733512319429; Fri, 06 Dec 2024 11:11:59 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum , Zhao Liu , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 4/4] hw/timer/hpet: Hold fw_cfg state within HPET class Date: Fri, 6 Dec 2024 20:11:24 +0100 Message-ID: <20241206191124.9195-5-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241206191124.9195-1-philmd@linaro.org> References: <20241206191124.9195-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philmd@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1733512355015116600 We maintain one hpet_cfg[] state for all HPET instances. Move it to a new HPET class. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/timer/hpet.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 849cb3e669b..c5aeac860b4 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -57,7 +57,7 @@ struct hpet_fw_config =20 #define HPET_MSI_SUPPORT 0 =20 -OBJECT_DECLARE_SIMPLE_TYPE(HPETState, HPET) +OBJECT_DECLARE_TYPE(HPETState, HPETClass, HPET) =20 struct HPETState; typedef struct HPETTimer { /* timers */ @@ -101,7 +101,11 @@ struct HPETState { uint8_t hpet_id; /* instance id */ }; =20 -static struct hpet_fw_config hpet_cfg =3D {.count =3D UINT8_MAX}; +struct HPETClass { + SysBusDeviceClass parent_class; + + struct hpet_fw_config fw_cfg; +}; =20 static uint32_t hpet_in_legacy_mode(HPETState *s) { @@ -279,6 +283,7 @@ static bool hpet_validate_num_timers(void *opaque, int = version_id) static int hpet_post_load(void *opaque, int version_id) { HPETState *s =3D opaque; + HPETClass *hc =3D HPET_GET_CLASS(s); int i; =20 for (i =3D 0; i < s->num_timers; i++) { @@ -295,7 +300,7 @@ static int hpet_post_load(void *opaque, int version_id) /* Push number of timers into capability returned via HPET_ID */ s->capability &=3D ~HPET_ID_NUM_TIM_MASK; s->capability |=3D (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT; - hpet_cfg.hpet[s->hpet_id].event_timer_block_id =3D (uint32_t)s->capabi= lity; + hc->fw_cfg.hpet[s->hpet_id].event_timer_block_id =3D (uint32_t)s->capa= bility; =20 /* Derive HPET_MSI_SUPPORT from the capability of the first timer. */ s->flags &=3D ~(1 << HPET_MSI_SUPPORT); @@ -660,6 +665,7 @@ static const MemoryRegionOps hpet_ram_ops =3D { static void hpet_reset(DeviceState *d) { HPETState *s =3D HPET(d); + HPETClass *hc =3D HPET_GET_CLASS(d); SysBusDevice *sbd =3D SYS_BUS_DEVICE(d); int i; =20 @@ -682,8 +688,8 @@ static void hpet_reset(DeviceState *d) s->hpet_counter =3D 0ULL; s->hpet_offset =3D 0ULL; s->config =3D 0ULL; - hpet_cfg.hpet[s->hpet_id].event_timer_block_id =3D (uint32_t)s->capabi= lity; - hpet_cfg.hpet[s->hpet_id].address =3D sbd->mmio[0].addr; + hc->fw_cfg.hpet[s->hpet_id].event_timer_block_id =3D (uint32_t)s->capa= bility; + hc->fw_cfg.hpet[s->hpet_id].address =3D sbd->mmio[0].addr; =20 /* to document that the RTC lowers its output on reset as well */ s->rtc_irq_level =3D 0; @@ -719,23 +725,24 @@ static void hpet_realize(DeviceState *dev, Error **er= rp) { SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); HPETState *s =3D HPET(dev); + HPETClass *hc =3D HPET_GET_CLASS(dev); int i; HPETTimer *timer; =20 if (!s->intcap) { warn_report("Hpet's intcap not initialized"); } - if (hpet_cfg.count =3D=3D UINT8_MAX) { + if (hc->fw_cfg.count =3D=3D UINT8_MAX) { /* first instance */ - hpet_cfg.count =3D 0; + hc->fw_cfg.count =3D 0; } =20 - if (hpet_cfg.count =3D=3D 8) { + if (hc->fw_cfg.count =3D=3D 8) { error_setg(errp, "Only 8 instances of HPET is allowed"); return; } =20 - s->hpet_id =3D hpet_cfg.count++; + s->hpet_id =3D hc->fw_cfg.count++; =20 for (i =3D 0; i < HPET_NUM_IRQ_ROUTES; i++) { sysbus_init_irq(sbd, &s->irqs[i]); @@ -773,11 +780,14 @@ static Property hpet_device_properties[] =3D { static void hpet_device_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); + HPETClass *hc =3D HPET_CLASS(klass); =20 dc->realize =3D hpet_realize; device_class_set_legacy_reset(dc, hpet_reset); dc->vmsd =3D &vmstate_hpet; device_class_set_props(dc, hpet_device_properties); + + hc->fw_cfg.count =3D UINT8_MAX; } =20 static const TypeInfo hpet_device_info =3D { @@ -797,7 +807,9 @@ type_init(hpet_register_types) =20 bool hpet_add_fw_cfg_bytes(FWCfgState *fw_cfg, Error **errp) { - fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hpet_cfg, sizeof(hpet_cfg)); + HPETClass *hc =3D HPET_GET_CLASS(hpet_find()); + + fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hc->fw_cfg, sizeof(hc->fw_cfg)); =20 return true; } --=20 2.45.2