From nobody Sat Apr 5 01:35:23 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1739462572; cv=none; d=zohomail.com; s=zohoarc; b=AIAVnYGtt5FKlgOl9nI/DnVseO55CKMJJXvOYs36vmoFdXGDgQhHjIHNIwq6m+q5BMmNUMGdIyUXMdhSDQf0WuMM+QE6+w5lexMz5n/N3tiBKhsyaXiA7S43PbfcIoTKyt4LcnPcbdxSKRyPl6uXUzcB8IBN77l/MlwOf0Dah/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739462572; h=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=Tt5qLjgDkzgeWvrd3siaS5OYB5bi/JKRwTeutA8JPDs=; b=PvI/8jU/mF6QaNvOt14yXHYZfYe2CvOJ5TOHYiTgDOsxBdkzK4rLRDzSqBslmNBC+I4tzFEaDzokhZ25bcMW7uZKtOJNvhfiO7fJbKVbJymTcXtEkwiNA9eBxknZAc+P0JxSIyyo/sMUfJ7eKnICGp21fymvu31YQ75atuBHT1E= 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 1739462571957301.72145203965806; Thu, 13 Feb 2025 08:02:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tibfB-00010t-7z; Thu, 13 Feb 2025 11:02:05 -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 1tibep-0000uk-KP for qemu-devel@nongnu.org; Thu, 13 Feb 2025 11:01:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tiben-0005Yd-8k for qemu-devel@nongnu.org; Thu, 13 Feb 2025 11:01:43 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-MyoQmwq9N9GYK3iHDwzLxA-1; Thu, 13 Feb 2025 11:01:39 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4395586f952so5401285e9.2 for ; Thu, 13 Feb 2025 08:01:38 -0800 (PST) Received: from [192.168.126.123] (93-38-211-213.ip72.fastwebnet.it. [93.38.211.213]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4395a04f217sm51970905e9.1.2025.02.13.08.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 08:01:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739462500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tt5qLjgDkzgeWvrd3siaS5OYB5bi/JKRwTeutA8JPDs=; b=HxoSqHhgGPA0tdtCLxjRsrPZC/EGgDbY+P/7GuofRNl+/mX+nMSVkdYhjRZRpv832pagF9 fZ3KdmWhFN5K9owD3mRfHebiqCVYvNwZGy05Dpl5CFuBBoV7Gb/j28EnFtxDr+gQo5/coI +Vk05zBOdvLuztX75C95/2qHKiD6ieo= X-MC-Unique: MyoQmwq9N9GYK3iHDwzLxA-1 X-Mimecast-MFC-AGG-ID: MyoQmwq9N9GYK3iHDwzLxA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739462497; x=1740067297; 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=Tt5qLjgDkzgeWvrd3siaS5OYB5bi/JKRwTeutA8JPDs=; b=jRXaKmRFncAmmEnB7nGa1PMRYevkcuRnYPk/sH9ub8O0RBCtiSndS/DBVk2yJbVf0f nnLAAo8F4m9e8YYZnYXqzeWu8WN+xIcCnsOqrwwpHDn2RGEcwykjlKM7fB9GfHGmLwva WIPbifMYu+wf/VbnK1n4xjkDnK1ylZaYstcNfvVceVshkcytEV4ePNM3MM24OSnxIjcP y/Gx7m9omwYwSIFMhxguHs4YoRwH/yNRZajgy/y8TzIDrslAZTz3NQrFvvLFgfIK7nsT mmXFOOplDa4RMfHdFsAn5DYoDVSWC/83Zz1pdErw6wKr6sWHpB/x0KJsnk6SLI8Bxt3v IleA== X-Gm-Message-State: AOJu0Yx77PK23PQT7B2YQrJ7rgZgvcV4M3CJUvAox6o1Nw+LHn2XX8Cu O4iIe5YakWm6CFoerBoysIbPbtWXnzJekRYmxWAqVXooBxLfborwDLFJB5ok4zmIQwInM+O/IWM g2WYIDUnQNa99uB/FLQYYtClwh1nyaUTJvBNOPzkqZCG1gz/RUiJ2fgt1QFhxthk38mF0b+LYOu cWr4yjKdAHKICIrEZSk0SgqLtByBmJWg6aHlBY7Ys= X-Gm-Gg: ASbGnctq4T3a48PFD6VHxzUP9vhlipE0ZfeACbO3qH5CaXSjWn8uIILbGeejbns4Zv3 rIUzPY5QoBzwH0GGL+p2GxOcahPslGLKyB6w3WIZ/RrhUX5hRaKAJ1ypBs8XTcI4TB56457i3TL mxuDn4m++pliLCwwyBnQ8g+AERFTazM+QNz6rLABP2+fUmG7MWcTJWgY5kiJoa+0ZQhbaNsRfUH n9rcdbclOtUrcxFPxUIj6YXPKDkG8T661Lr0AgQ6oinN4IT7woYyzCHZs2boIlsPq0cXMR90IXO ceoN8kBviMqpzE5SLy+9jvK0KJsA8xcCbpCQnXH1+8OOdQ== X-Received: by 2002:a05:600c:4fc6:b0:434:a734:d268 with SMTP id 5b1f17b1804b1-43960185baemr53667795e9.14.1739462497285; Thu, 13 Feb 2025 08:01:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwKGPXT5gHUdEmjdR6lkKJRyUOwEe0aqs6m32ToYFsCbVjYOVebAqe87dOi3od8vOfT+b3pg== X-Received: by 2002:a05:600c:4fc6:b0:434:a734:d268 with SMTP id 5b1f17b1804b1-43960185baemr53665375e9.14.1739462495153; Thu, 13 Feb 2025 08:01:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 14/27] i386/fw_cfg: move hpet_cfg definition to hpet.c Date: Thu, 13 Feb 2025 17:00:41 +0100 Message-ID: <20250213160054.3937012-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213160054.3937012-1-pbonzini@redhat.com> References: <20250213160054.3937012-1-pbonzini@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.495, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1739462573989019100 Content-Type: text/plain; charset="utf-8" From: Zhao Liu HPET device needs to access and update hpet_cfg variable, but now it is defined in hw/i386/fw_cfg.c and Rust code can't access it. Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This allows Rust HPET device implements its own global hpet_fw_cfg variable, and will further reduce the use of unsafe C code access and calls in the Rust HPET implementation. Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250210030051.2562726-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- include/hw/timer/hpet.h | 2 +- hw/i386/fw_cfg.c | 6 ++++-- hw/timer/hpet.c | 16 +++++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h index 71e8c62453d..c2656f7f0be 100644 --- a/include/hw/timer/hpet.h +++ b/include/hw/timer/hpet.h @@ -73,7 +73,7 @@ struct hpet_fw_config struct hpet_fw_entry hpet[8]; } QEMU_PACKED; =20 -extern struct hpet_fw_config hpet_cfg; +extern struct hpet_fw_config hpet_fw_cfg; =20 #define TYPE_HPET "hpet" =20 diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c index 91bf1df0f2e..d08aefa0291 100644 --- a/hw/i386/fw_cfg.c +++ b/hw/i386/fw_cfg.c @@ -26,7 +26,9 @@ #include CONFIG_DEVICES #include "target/i386/cpu.h" =20 -struct hpet_fw_config hpet_cfg =3D {.count =3D UINT8_MAX}; +#if !defined(CONFIG_HPET) && !defined(CONFIG_X_HPET_RUST) +struct hpet_fw_config hpet_fw_cfg =3D {.count =3D UINT8_MAX}; +#endif =20 const char *fw_cfg_arch_key_name(uint16_t key) { @@ -149,7 +151,7 @@ FWCfgState *fw_cfg_arch_create(MachineState *ms, #endif fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, 1); =20 - fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hpet_cfg, sizeof(hpet_cfg)); + fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hpet_fw_cfg, sizeof(hpet_fw_cfg= )); /* allocate memory for the NUMA channel: one (64bit) word for the numb= er * of nodes, one word for each VCPU->node and one word for each node to * hold the amount of memory. diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 1c8c6c69ef5..dcff18a9871 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -40,6 +40,8 @@ #include "qom/object.h" #include "trace.h" =20 +struct hpet_fw_config hpet_fw_cfg =3D {.count =3D UINT8_MAX}; + #define HPET_MSI_SUPPORT 0 =20 OBJECT_DECLARE_SIMPLE_TYPE(HPETState, HPET) @@ -278,7 +280,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; + hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id =3D (uint32_t)s->cap= ability; =20 /* Derive HPET_MSI_SUPPORT from the capability of the first timer. */ s->flags &=3D ~(1 << HPET_MSI_SUPPORT); @@ -665,8 +667,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; + hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id =3D (uint32_t)s->cap= ability; + hpet_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; @@ -708,17 +710,17 @@ static void hpet_realize(DeviceState *dev, Error **er= rp) if (!s->intcap) { warn_report("Hpet's intcap not initialized"); } - if (hpet_cfg.count =3D=3D UINT8_MAX) { + if (hpet_fw_cfg.count =3D=3D UINT8_MAX) { /* first instance */ - hpet_cfg.count =3D 0; + hpet_fw_cfg.count =3D 0; } =20 - if (hpet_cfg.count =3D=3D 8) { + if (hpet_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 hpet_fw_cfg.count++; =20 for (i =3D 0; i < HPET_NUM_IRQ_ROUTES; i++) { sysbus_init_irq(sbd, &s->irqs[i]); --=20 2.48.1