From patchwork Tue Feb 27 13:32:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 776201 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp156806wro; Tue, 27 Feb 2024 05:36:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXHU7Q77tIfo5o11zMcZdSQ1lJozMW2Oh3pQqSsOkkrDRMu5k8zXC48psqRC52FIu1lKcXaE+/BKNqzksw2/088 X-Google-Smtp-Source: AGHT+IHDUzrt9OCzlaMmo+PMQ0PpNP3cALYLY+6+uC4Oqg11hGZ6HN0GIAV18eE5CY2NvzpiwsG1 X-Received: by 2002:a05:6871:750c:b0:21e:3d6e:bb85 with SMTP id ny12-20020a056871750c00b0021e3d6ebb85mr10056864oac.0.1709040996643; Tue, 27 Feb 2024 05:36:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709040996; cv=none; d=google.com; s=arc-20160816; b=kxO914+lEwGUAncqyQU5pIzl6sEl3+wtFU2iTdPO9VXZKnlXNkAIGt4HKWeJ1R1Mgy sIQXcci8pQEiPwtxtPscA4PFA4F6uCokif8sghSFRMmHiWl1MSNt8c2nCWhCfXUKRoI4 QEQyRA5LzuOxwsLk5FIlvnuD3O1JQ7eCKQySzFfDt0ksxfVAOkgK8yQ+PgRCo5Li5d/G +yHAJY/hRavx7jQ/ahkw0/ot9AdTKQ5oQJksTNjdUk+z5c82HjVhnObmaR44uuZUMBaI 6noi1KGb+dXvzdRP20fD4uyrKB8M/cYN956cOVHBT2V6ckbyp/I05STxGgWpMJbiRUme A+Kg== 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:to:from :dkim-signature; bh=EOihe31CmPAbuzzjsksYd8G0LxILYXs9z7dL8tuuTcw=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=UsI6ON6Enc3NAnGSGNdqbadCQqFL594tIJpAoL+KpdhUeM2rLfH51zzP0YhnsPYu8o Y8pmUYWS4jNbbHlt4w2KtPA3GGSc8e+feP0+heAvkUHO2d+2TqS22LDs8UuXVS10QbdQ M1LgwuoJvs2gPIBOvQlzqWJmqK+5yq4fRh9YMvrKiU08GIExp5+9iXOyE3riiv3tKTs1 yaf/uUakmxHXiNFj3yqeYyCMhL5juMehvewon8iP+5VZV6Occjfazc8sdDq1O8Ot/yul av3s55k34suLuKaAtPrX+LnQ/mRlGH053Q75D71KEYKflSbzojvd7TXGkHFMIzIKhF+A CpeA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bj1XwZEM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y10-20020ae9f40a000000b007879c17eb3asi7481089qkl.699.2024.02.27.05.36.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 05:36:36 -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=pass header.i=@linaro.org header.s=google header.b=bj1XwZEM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rexad-0000pI-7b; Tue, 27 Feb 2024 08:33:47 -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 1rexaM-0000kJ-Gv for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:33 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rexaI-0002sX-4E for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:28 -0500 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33d754746c3so2868729f8f.1 for ; Tue, 27 Feb 2024 05:33:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709040805; x=1709645605; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=EOihe31CmPAbuzzjsksYd8G0LxILYXs9z7dL8tuuTcw=; b=bj1XwZEMZsuU7ZcZZAx2EEnJKi/6l950+9o0dCOc8fQrtutRC2d8T6wW0oNoogS+cC 57Ey2Dhz+Xi9wqQO194CIBfMx7r25QigCLloX0/RJS1CuLu86+q0IEZp+/k3B8km7bLE a2FyLOU3Vv4V6FA3r38+Yx4+OJsFuGZ8uMaUwTFxoICg5q57hjvZSERlg0tOiM+4WqJX tixrpTsYoOqtCYoFtlkc37HdnfDUssM1pKRoOu38a+uoYDG8hm8Iq5ycAZ2x8Wn3AVtI eJe9aJayrd03hBQ83mIWXy+JcO9p5tuPOnF1jhi4t4yODYSd+VhaPGwYeSxHIN9RUxCJ vuPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709040805; x=1709645605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EOihe31CmPAbuzzjsksYd8G0LxILYXs9z7dL8tuuTcw=; b=vcLFx7ESgzIYOsF4b0kcITN/cWUcKbMBdQpkIXza/boMv6EDdK0DbgMGsd1Nrbxd+9 cIiZRroGGIJ95MAEUT04BertBHccm1EyAJF6ReqjdG9qqj1tWKhrJdnRqIxupu1CWpLH on8dqHdZl0Aq8GT8p8UwLhEU3sE01i22DVvdc2KYJXogn05jMWu2UbAflTnsyvRZD3LI rV6SFsxkcwy8s5fY2nvllS4iWYAfp69dICDKBI/S0a41lK5tU0yO+5ZkZB9UVcLxmXci PnJyYOaEDpZw/qS7blqo+pm/goHRXWpCN//C5idl40XivoGAhqN04YtrYA/WF/gIfTnw jxPg== X-Gm-Message-State: AOJu0Yz+C036iXPpTOvB4G8irtSae9B6GbmeEGPsVPm1Jt7xzfEAbS1n 5z1RwQaKhfMs9/LpR3El+Gu7YMpWwceY4t/WcodgeAcRjt33z53Zoj/oGAmxD1iRklirUSeR/3a 3 X-Received: by 2002:adf:ef87:0:b0:33d:a011:ae42 with SMTP id d7-20020adfef87000000b0033da011ae42mr6830316wro.38.1709040804860; Tue, 27 Feb 2024 05:33:24 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i13-20020adfe48d000000b0033ae7d768b2sm11319552wrm.117.2024.02.27.05.33.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 05:33:24 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 16/45] hw/core: Add ResetContainer which holds objects implementing Resettable Date: Tue, 27 Feb 2024 13:32:45 +0000 Message-Id: <20240227133314.1721857-17-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227133314.1721857-1-peter.maydell@linaro.org> References: <20240227133314.1721857-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x435.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 a ResetContainer. This is a subclass of Object, and it implements the Resettable interface. The container holds a list of arbitrary other objects which implement Resettable, and when the container is reset, all the objects it contains are also reset. This will allow us to have a 3-phase-reset equivalent of the old qemu_register_reset() API: we will have a single "simulation reset" top level ResetContainer, and objects in it are the equivalent of the old QEMUResetHandler functions. The qemu_register_reset() API manages its list of callbacks using a QTAILQ, but here we use a GPtrArray for our list of Resettable children: we expect the "remove" operation (which will need to do an iteration through the list) to be fairly uncommon, and we get simpler code with fewer memory allocations. Since there is currently no listed owner in MAINTAINERS for the existing reset-related source files, create a new section for them, and add these new files there also. Signed-off-by: Peter Maydell Reviewed-by: Michael S. Tsirkin Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Message-id: 20240220160622.114437-7-peter.maydell@linaro.org Reviewed-by: Zhao Liu --- MAINTAINERS | 10 +++++ include/hw/core/resetcontainer.h | 48 ++++++++++++++++++++ hw/core/resetcontainer.c | 77 ++++++++++++++++++++++++++++++++ hw/core/meson.build | 1 + 4 files changed, 136 insertions(+) create mode 100644 include/hw/core/resetcontainer.h create mode 100644 hw/core/resetcontainer.c diff --git a/MAINTAINERS b/MAINTAINERS index ca97b627188..65dfdc9677e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3676,6 +3676,16 @@ F: hw/core/clock-vmstate.c F: hw/core/qdev-clock.c F: docs/devel/clocks.rst +Reset framework +M: Peter Maydell +S: Maintained +F: include/hw/resettable.h +F: include/hw/core/resetcontainer.h +F: include/sysemu/reset.h +F: hw/core/reset.c +F: hw/core/resettable.c +F: hw/core/resetcontainer.c + Usermode Emulation ------------------ Overall usermode emulation diff --git a/include/hw/core/resetcontainer.h b/include/hw/core/resetcontainer.h new file mode 100644 index 00000000000..23db0c7a880 --- /dev/null +++ b/include/hw/core/resetcontainer.h @@ -0,0 +1,48 @@ +/* + * Reset container + * + * Copyright (c) 2024 Linaro, Ltd + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_RESETCONTAINER_H +#define HW_RESETCONTAINER_H + +/* + * The "reset container" is an object which implements the Resettable + * interface. It contains a list of arbitrary other objects which also + * implement Resettable. Resetting the reset container resets all the + * objects in it. + */ + +#include "qom/object.h" + +#define TYPE_RESETTABLE_CONTAINER "resettable-container" +OBJECT_DECLARE_TYPE(ResettableContainer, ResettableContainerClass, RESETTABLE_CONTAINER) + +/** + * resettable_container_add: Add a resettable object to the container + * @rc: container + * @obj: object to add to the container + * + * Add @obj to the ResettableContainer @rc. @obj must implement the + * Resettable interface. + * + * When @rc is reset, it will reset every object that has been added + * to it, in the order they were added. + */ +void resettable_container_add(ResettableContainer *rc, Object *obj); + +/** + * resettable_container_remove: Remove an object from the container + * @rc: container + * @obj: object to remove from the container + * + * Remove @obj from the ResettableContainer @rc. @obj must have been + * previously added to this container. + */ +void resettable_container_remove(ResettableContainer *rc, Object *obj); + +#endif diff --git a/hw/core/resetcontainer.c b/hw/core/resetcontainer.c new file mode 100644 index 00000000000..e4ece68e83a --- /dev/null +++ b/hw/core/resetcontainer.c @@ -0,0 +1,77 @@ +/* + * Reset container + * + * Copyright (c) 2024 Linaro, Ltd + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +/* + * The "reset container" is an object which implements the Resettable + * interface. It contains a list of arbitrary other objects which also + * implement Resettable. Resetting the reset container resets all the + * objects in it. + */ + +#include "qemu/osdep.h" +#include "hw/resettable.h" +#include "hw/core/resetcontainer.h" + +struct ResettableContainer { + Object parent; + ResettableState reset_state; + GPtrArray *children; +}; + +OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(ResettableContainer, resettable_container, RESETTABLE_CONTAINER, OBJECT, { TYPE_RESETTABLE_INTERFACE }, { }) + +void resettable_container_add(ResettableContainer *rc, Object *obj) +{ + INTERFACE_CHECK(void, obj, TYPE_RESETTABLE_INTERFACE); + g_ptr_array_add(rc->children, obj); +} + +void resettable_container_remove(ResettableContainer *rc, Object *obj) +{ + g_ptr_array_remove(rc->children, obj); +} + +static ResettableState *resettable_container_get_state(Object *obj) +{ + ResettableContainer *rc = RESETTABLE_CONTAINER(obj); + return &rc->reset_state; +} + +static void resettable_container_child_foreach(Object *obj, + ResettableChildCallback cb, + void *opaque, ResetType type) +{ + ResettableContainer *rc = RESETTABLE_CONTAINER(obj); + unsigned int len = rc->children->len; + + for (unsigned int i = 0; i < len; i++) { + cb(g_ptr_array_index(rc->children, i), opaque, type); + /* Detect callbacks trying to unregister themselves */ + assert(len == rc->children->len); + } +} + +static void resettable_container_init(Object *obj) +{ + ResettableContainer *rc = RESETTABLE_CONTAINER(obj); + + rc->children = g_ptr_array_new(); +} + +static void resettable_container_finalize(Object *obj) +{ +} + +static void resettable_container_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + + rc->get_state = resettable_container_get_state; + rc->child_foreach = resettable_container_child_foreach; +} diff --git a/hw/core/meson.build b/hw/core/meson.build index 67dad04de55..e26f2e088c3 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -4,6 +4,7 @@ hwcore_ss.add(files( 'qdev-properties.c', 'qdev.c', 'reset.c', + 'resetcontainer.c', 'resettable.c', 'vmstate-if.c', # irq.c needed for qdev GPIO handling: