From patchwork Tue Feb 20 16:06:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 774271 Delivered-To: patch@linaro.org Received: by 2002:a5d:4943:0:b0:33b:4db1:f5b3 with SMTP id r3csp1729947wrs; Tue, 20 Feb 2024 08:07:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVsbuCP64F0fUYR1G4ad9Xxe0vtYgVBz8byaXc8IVigcq24Lcmp3d7fUhteLuGaWl/6lKKO55SGgXJLe+6+Hmw5 X-Google-Smtp-Source: AGHT+IE36WMacCNWqeV60yJajkW2PaAwILpglYudH6zXRIES1xW4mbwvLly2DDZ3w3K6546syMnt X-Received: by 2002:a05:6214:2b99:b0:68f:65b2:2af5 with SMTP id kr25-20020a0562142b9900b0068f65b22af5mr9989638qvb.7.1708445253394; Tue, 20 Feb 2024 08:07:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708445253; cv=none; d=google.com; s=arc-20160816; b=rVlMT8+GAVVc+djhEgk49aTQkUT9hfGmUdQZ/y7NmsHoQNDwbC5AbPXgkFPZZ1f7C7 VqVB4tVFnGLr8rpk85cHymG3l7YSJlSw9iRxOv3sZvKpNBJJZw349DEcAqtoolUDx6Eg RM9aqtwCtVQTtj9APBK+CgPDVQWUgcrV63xLEkKo8gv6brAnTOp1yfyb7jw9ASsZWzQP cMyplK5BCdCx+vv8mrQHKhfPSkuDHOFrMfZzVwstAFXjLnuupKydRdoKwYPEo1SXIMmB BGghk1lFz1aNi4VS3vnT+XzM8BxwtXdNF9jBh7tRf8bXcyZ2xOyuiB3FoqlxhShVJ098 O40A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7iDhlmBEzf3/xjobdXXs7/XL4KcZXNtIkpWLjY9SBqw=; fh=dm0WNFmBzWrd+9ibIS2DbEOUrG4x0hquFjik6cek7jE=; b=C1MF6o5+Alh42B6fNhWDrrojf5zaWzjtU0q0Aysu/4eKNdOY6Ho5IM/WJw3OhoRWS+ c4LMNhTsN6VVn02/2koOlk72MWsQuRWnlKa3XLQ21Ju7VyZ3pIOayeROKrnzcdoF2+EA DBvaRrPkm1NnuSZhabblePuORSa+LjmCimjyKwZp7Cfc3+aoONT+nwBoBk7XRjqSRXwi BCwm2dPrGCx+l4UZQqKZatlrAr3MAcm0D55m6PHppR0kMqj68gmb4V3OQDFRQ/4CTl88 GITwowS08oCZKDuZDc56MZpqm9pOaxmPBWriWBrE218fUT9Y3btL18QTxBxXzq8Y4pR/ TFOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nk9txZuT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j12-20020a0cf9cc000000b0068f70c5195bsi4528156qvo.614.2024.02.20.08.07.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Feb 2024 08:07:33 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nk9txZuT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcSdf-00028R-AR; Tue, 20 Feb 2024 11:06:35 -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 1rcSdd-000282-EB for qemu-devel@nongnu.org; Tue, 20 Feb 2024 11:06:33 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcSda-0005FV-Fp for qemu-devel@nongnu.org; Tue, 20 Feb 2024 11:06:33 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-41272d42297so971095e9.3 for ; Tue, 20 Feb 2024 08:06:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708445189; x=1709049989; 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=7iDhlmBEzf3/xjobdXXs7/XL4KcZXNtIkpWLjY9SBqw=; b=nk9txZuTgu3FPyEybvjiLPjw2/+cQ6lI2a4ivr6/bne6iP842lcPDbfFbjERubcptP H3ET/Ik6g9wS/JfQiwGF53q79ucLda4728FTH/1ePUjyGJh9dmVic0DwZpA8IsOXTPJy px9VZR2jNbwwW7BeOuTUD38wQsLzTLTnWCOeLoVj1Ijwsm+0k+9eBl6k5ZCory6MSPc5 BlUCJxATNreYYUxOCb8G8PWbnYqEzwTMhMJjV3U7JVoHZDU26jTEqtX4SUG5VgDkMbzD uAZFzea+N2tWF4ecqu18I1xzbz6z0bMleUsxNd1OYcTdD6EbJCGwpgvtH4WczW6wZa1L 9Z2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708445189; x=1709049989; 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=7iDhlmBEzf3/xjobdXXs7/XL4KcZXNtIkpWLjY9SBqw=; b=hwL7KFY9t5EannQ9slMHQ0J3qiq9PVH7jF90OP6ar3/aNncC0BckyyjJ4oLmd8QkPO nWXBpEep8Nk5n+dwFBSKEmAFm+gf2csVKAH4Ck1enw8I0H1vYJTUGbIoyGJ4JB4FbAnk w+6CCdUL3BEj6FgSFwi9lviKtZIMymHwTVbBxyXZKFzEQR5MaMnBbn8LtaBqyo31KnXB FDFj3OVXkLbP3VpeHCzfAWvyEP9fFSGbJtECM/NZyGDiZbIL1XaOhoXVZ5yrwfGCvGcW /qndhawW+flZm5cCtZ1qXaIcvFbnwTIVWalH07eCdOEXDCcQT7dpxWM0C93mwYzeS/b9 xmYg== X-Gm-Message-State: AOJu0YyUQC6YI4wEgaRysEpgvyQr+oCNAGcBWzUmYTo2Nzk5b84qu7o6 sRYn7asVcr0z4hA430rIb/AvZEksi4hOGlp8g+VUhCaGeb8OmZwHRIKPiQyCP7nMYm0T55ffDv0 4 X-Received: by 2002:a05:600c:4746:b0:412:7012:ee14 with SMTP id w6-20020a05600c474600b004127012ee14mr1308072wmo.0.1708445188805; Tue, 20 Feb 2024 08:06:28 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b0040f0219c371sm15299927wmq.19.2024.02.20.08.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 08:06:28 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , "Michael S. Tsirkin" , "Gonglei (Arei)" Subject: [PATCH 07/10] hw/core/reset: Add qemu_{register, unregister}_resettable() Date: Tue, 20 Feb 2024 16:06:19 +0000 Message-Id: <20240220160622.114437-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220160622.114437-1-peter.maydell@linaro.org> References: <20240220160622.114437-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Implement new functions qemu_register_resettable() and qemu_unregister_resettable(). These are intended to be three-phase-reset aware equivalents of the old qemu_register_reset() and qemu_unregister_reset(). Instead of passing in a function pointer and opaque, you register any QOM object that implements the Resettable interface. The implementation is simple: we have a single global instance of a ResettableContainer, which we reset in qemu_devices_reset(), and the Resettable objects passed to qemu_register_resettable() are added to it. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Zhao Liu --- include/sysemu/reset.h | 37 ++++++++++++++++++++++++++++++++++--- hw/core/reset.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/include/sysemu/reset.h b/include/sysemu/reset.h index 6aa11846a69..a3de48cb9cf 100644 --- a/include/sysemu/reset.h +++ b/include/sysemu/reset.h @@ -31,6 +31,36 @@ typedef void QEMUResetHandler(void *opaque); +/** + * qemu_register_resettable: Register an object to be reset + * @obj: object to be reset: it must implement the Resettable interface + * + * Register @obj on the list of objects which will be reset when the + * simulation is reset. These objects will be reset in the order + * they were added, using the three-phase Resettable protocol, + * so first all objects go through the enter phase, then all objects + * go through the hold phase, and then finally all go through the + * exit phase. + * + * It is not permitted to register or unregister reset functions or + * resettable objects from within any of the reset phase methods of @obj. + * + * We assume that the caller holds the BQL. + */ +void qemu_register_resettable(Object *obj); + +/** + * qemu_unregister_resettable: Unregister an object to be reset + * @obj: object to unregister + * + * Remove @obj from the list of objects which are reset when the + * simulation is reset. It must have been previously added to + * the list via qemu_register_resettable(). + * + * We assume that the caller holds the BQL. + */ +void qemu_unregister_resettable(Object *obj); + /** * qemu_register_reset: Register a callback for system reset * @func: function to call @@ -44,8 +74,8 @@ typedef void QEMUResetHandler(void *opaque); * for instance device model reset is better accomplished using the * methods on DeviceState. * - * It is not permitted to register or unregister reset functions from - * within the @func callback. + * It is not permitted to register or unregister reset functions or + * resettable objects from within the @func callback. * * We assume that the caller holds the BQL. */ @@ -81,7 +111,8 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque); * * This function performs the low-level work needed to do a complete reset * of the system (calling all the callbacks registered with - * qemu_register_reset()). It should only be called by the code in a + * qemu_register_reset() and resetting all the Resettable objects registered + * with qemu_register_resettable()). It should only be called by the code in a * MachineClass reset method. * * If you want to trigger a system reset from, for instance, a device diff --git a/hw/core/reset.c b/hw/core/reset.c index d3263b613e6..a9b30e705fe 100644 --- a/hw/core/reset.c +++ b/hw/core/reset.c @@ -26,8 +26,23 @@ #include "qemu/osdep.h" #include "qemu/queue.h" #include "sysemu/reset.h" +#include "hw/resettable.h" +#include "hw/core/resetcontainer.h" -/* reset/shutdown handler */ +/* + * Return a pointer to the singleton container that holds all the Resettable + * items that will be reset when qemu_devices_reset() is called. + */ +static ResettableContainer *get_root_reset_container(void) +{ + static ResettableContainer *root_reset_container; + + if (!root_reset_container) { + root_reset_container = + RESETTABLE_CONTAINER(object_new(TYPE_RESETTABLE_CONTAINER)); + } + return root_reset_container; +} typedef struct QEMUResetEntry { QTAILQ_ENTRY(QEMUResetEntry) entry; @@ -71,6 +86,16 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) } } +void qemu_register_resettable(Object *obj) +{ + resettable_container_add(get_root_reset_container(), obj); +} + +void qemu_unregister_resettable(Object *obj) +{ + resettable_container_remove(get_root_reset_container(), obj); +} + void qemu_devices_reset(ShutdownCause reason) { QEMUResetEntry *re, *nre; @@ -83,5 +108,7 @@ void qemu_devices_reset(ShutdownCause reason) } re->func(re->opaque); } -} + /* Reset the simulation */ + resettable_reset(OBJECT(get_root_reset_container()), RESET_TYPE_COLD); +}