From patchwork Fri Feb 9 12:32:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 771316 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp823871wre; Fri, 9 Feb 2024 04:33:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqRCvm2MEJW7+kBCo2RuV8yLyQp0qRd1VUukAly0U9vJ7x6obmkUm9vvNcMVAJiLsJaidC X-Received: by 2002:a0c:ca0b:0:b0:68c:9b53:8eb6 with SMTP id c11-20020a0cca0b000000b0068c9b538eb6mr1454314qvk.43.1707482021953; Fri, 09 Feb 2024 04:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707482021; cv=none; d=google.com; s=arc-20160816; b=wRExJfmbCbGscLOnqyvt++BC4z/KER90WrHF6Hu/0m4DqknXXb+CTmEa/fjOBe3O1T 3ndglbxHqC/0BE82uitwL8NUa2ZE639AWyeS/uRavYbZXQHXpG4rsofmvNaSUDtIF+jP mCDhNxjWjGgJ5fYx314VyQWczMwVljyKB/D/3w4LC5g5umpp47qGc3yRaiDskTx9BaYU Sr13xMIXKNr+Jug6J83qCAUxkGmOYSQPadD2IvlZ5FHcHVYL5LrBfHvwqogq4VURRzwN iYAr++Br1eQHQw2+UrUPriBLy0LSTw0+bDQf0RO6nxYVcCd3q8NtufRk7paz+2yNlKRF dzFw== 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=D/EF0ukeLn1gu/zaqcDjARqMaoRLvmGATkelLRoHEzw=; fh=b4tN4WcEU40+ZNS4BF0BqykdAyDMoWHosKiY/Q9/cD0=; b=kzSchP4XUTf6xZSTEbJMH7RlkZ+2kzmltUoxv88Fa4+249n8MhRWaGoV1hTdOQI8VQ LQ/AVpIUnC4JIurh7qgzcpyviIEJSzL6YNciyC66GVzRGY2aDxGJ2s7Cz+s3SuiYOMNF xoQRt+LswTj+XEwUnOR9pPoCaGaCCuKG2k9tDWpHTCXh6gF27dKhBbynsQ2CyF3ET+pC YNR3IIJZakPTLMbAyY0e+rNaE4OTwCFeJFuhYZ49QlxeHJenGF3ws/R8bn5mlxN37xAk LzAses1KnMvZrHcSuX49if8u2VlQXP6zX2BXuurAeVBzvx9v4fJOvzkQ9sPjmkYkbKWn m4kQ==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wT9dB7Rh; 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 X-Forwarded-Encrypted: i=1; AJvYcCXSLE0JLvHE9FPd8OHHQV4WOKHBz6+gblUQ79raXEPn4bOFKxCDcTRKtNK/0Syqo6O4rNa6ZlVO1/fcZQBXqTMa Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jo12-20020a056214500c00b0068cc0ed1f88si1847487qvb.326.2024.02.09.04.33.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Feb 2024 04:33:41 -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=wT9dB7Rh; 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 1rYQ3e-0007kC-Gx; Fri, 09 Feb 2024 07:32:42 -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 1rYQ3c-0007ix-H5 for qemu-devel@nongnu.org; Fri, 09 Feb 2024 07:32:40 -0500 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rYQ3Z-0001pS-BW for qemu-devel@nongnu.org; Fri, 09 Feb 2024 07:32:40 -0500 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-5116b017503so1145525e87.1 for ; Fri, 09 Feb 2024 04:32:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707481955; x=1708086755; 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=D/EF0ukeLn1gu/zaqcDjARqMaoRLvmGATkelLRoHEzw=; b=wT9dB7Rhhr4feEQsUkJWsAoMzDnk41S7aB+GfGEB3NbzKbD0wHCMFP13HKpJbtgAA0 ghkiupFWJVmKDTUiONufcOStB4jeLiq1EWrXTS2j55bKa7+ZLHxk9U/dz5WYTVCuX/Uv lYu1BAj2L/Paw9V27JHKe5cGTMCDsr9dE3wKpwTF16RcyzAxOX01yBOWmcNnJAWxP5pZ em4qyLDBvRLHEGUzft2q2lrBXGebRz1T4+WpI1SyOvc+pDkN6sCoQrYeuFfl2TVR62bF fQyc5TV+vgHtOi4trnfnU53dGldDnTCbKkc8EQlUCc3WN2O6yzYb1QTdUjBgIL1E/SGb x7mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707481955; x=1708086755; 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=D/EF0ukeLn1gu/zaqcDjARqMaoRLvmGATkelLRoHEzw=; b=rxI7jjhf2aLhuNCaS7fIfe4QLD5fqEkWXm+vtERA7DeoS7PyNcA3iplubWxjmnweEv yYjXxNX9MLsQe0e1/2bxGt8BEoDIWmStFbxE/Vi4trjY8ENejrc+kCNLEzohUxHxilCu zx8K8nSOyW2NjEZC9kvZqL4DckC2gHBQINie26Bn5P0yIC6RHySEgo9tJz7+Rfh5o0yM vDbnWDUTtZEZJrrX0C4ZkN3KZGCiXkPhWK4asFbZCL+XPGjo22QqkdDVG/NcCNSRD76E YnF3j4+UntQbAms3xXuCAWN94E+1DguEespzXGstSn6/mDTnsj0PtBFn1rtlxlLLG93A lpSQ== X-Gm-Message-State: AOJu0YxvwrLVjbckowGudeApXBBQrjqaXHlM43omR/ef0DiIUf823lay Y8uMTLGGKJ9tpqa62wBZpi4efXwzO5on3/yv7p0ppK6XGnJrIC6BaOFnocAUTDtV4rKpQ5hxPQ3 A X-Received: by 2002:ac2:5213:0:b0:511:78bb:a9da with SMTP id a19-20020ac25213000000b0051178bba9damr1050764lfl.39.1707481955364; Fri, 09 Feb 2024 04:32:35 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWOxnzVCCy/U/2x4P2+0KM350C3xhqnQsKdrTEyWhR73+BTmRLGIr6ib1IOOGp8wKrXY3m5Ew8fI8vgpaeHbL58EZ67MtBtC8SAyviYbCiAEUENUfRQfJ/P6+oCFZ/SDCVW+jowkVVQpahRotlAHzlXntDPh+V4kyIcFvk2fn9NtyDKRB1tfyPkL2iUgnumUkj0dmzIw9NHNuupSJoQnAW9MvqNWNXQVEAvkvRqi7Pp17CIMioFku4/J5iKUM/eOpuP6FHQIxOdTXf7szYJBcdmc9CU4p+y1aFO6F22dVzl7X07kreNMoNiJs/pN42aV3jh7DXLWNuh3FE= Received: from m1x-phil.lan ([176.187.218.105]) by smtp.gmail.com with ESMTPSA id 7-20020a05600c248700b0040fddaf9ff4sm482987wms.40.2024.02.09.04.32.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 09 Feb 2024 04:32:34 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Paolo Bonzini , BALATON Zoltan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Jiaxun Yang , qemu-block@nongnu.org, John Snow , qemu-ppc@nongnu.org, Eduardo Habkost , "Michael S. Tsirkin" Subject: [RFC PATCH 1/7] hw/qdev: Introduce DeviceClass::[un]wire() handlers Date: Fri, 9 Feb 2024 13:32:19 +0100 Message-ID: <20240209123226.32576-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240209123226.32576-1-philmd@linaro.org> References: <20240209123226.32576-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=philmd@linaro.org; helo=mail-lf1-x131.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=unavailable 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 Signed-off-by: Philippe Mathieu-Daudé --- include/hw/qdev-core.h | 8 +++++++- hw/core/qdev.c | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index d47536eadb..2ca33aea3b 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -101,8 +101,12 @@ typedef void (*BusUnrealize)(BusState *bus); * @props: Properties accessing state fields. * @realize: Callback function invoked when the #DeviceState:realized * property is changed to %true. + * @wire: Callback function called after @realize to connect IRQs, + * clocks and map memories. Can not fail. + * @unwire: Callback function to undo @wire. Called before @unrealize. + * Can not fail. * @unrealize: Callback function invoked when the #DeviceState:realized - * property is changed to %false. + * property is changed to %false. Can not fail. * @hotpluggable: indicates if #DeviceClass is hotpluggable, available * as readonly "hotpluggable" property of #DeviceState instance * @@ -161,6 +165,8 @@ struct DeviceClass { */ DeviceReset reset; DeviceRealize realize; + void (*wire)(DeviceState *dev); + void (*unwire)(DeviceState *dev); DeviceUnrealize unrealize; /** diff --git a/hw/core/qdev.c b/hw/core/qdev.c index c68d0f7c51..1d399aae71 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -303,6 +303,16 @@ bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp) void qdev_unrealize(DeviceState *dev) { + DeviceClass *dc = DEVICE_GET_CLASS(dev); + + if (dc->unwire) { + if (!dc->wire) { + error_report("disconnect() without connect() for type '%s'", + object_get_typename(OBJECT(dev))); + abort(); + } + dc->unwire(dev); + } object_property_set_bool(OBJECT(dev), "realized", false, &error_abort); } @@ -601,8 +611,17 @@ static void device_set_realized(Object *obj, bool value, Error **errp) dev->pending_deleted_event = true; DEVICE_LISTENER_CALL(unrealize, Reverse, dev); } - assert(local_err == NULL); + + if (dc->wire) { + if (!dc->unwire) { + warn_report_once("wire() without unwire() for type '%s'", + object_get_typename(OBJECT(dev))); + } + dc->wire(dev); + } + + /* At this point the device is "guest visible". */ return; child_realize_fail: