From patchwork Tue Aug 13 16:52:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 818832 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp357994wrm; Tue, 13 Aug 2024 09:54:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV4+H4mDU6or0evdFDzGKysRrua5n3YULoJ0pUj5IVtmzYzOSCt5fUlITdTbkw6WdpOwLKNX+PKldtRXZaBVw06 X-Google-Smtp-Source: AGHT+IF25T4x6SHYh/V8y7V/GC1bNT2TK/hA9/5kqLMPc60kk3Dy7pC3S23FZ6A1NFuJOm/DgOyX X-Received: by 2002:a05:6214:540a:b0:6bb:9b66:f264 with SMTP id 6a1803df08f44-6bf5d066eb2mr2468526d6.0.1723568041241; Tue, 13 Aug 2024 09:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723568041; cv=none; d=google.com; s=arc-20160816; b=gmqfGaRTjj1v638rbyzq+i5SCKcCJ0vV8h2VaqWVKvU8OfetD5JhOYDMYipkRnwHpE vRNV1O1OOorHiYr7FuKWWa3ZzfCKSLOohgQfYda56TrZITmcpLpX2qivdeFOhGAdPAkt kvAoxY2072lMStfndhjFZ8SzsStDhBu9h9ZPZhLcOpszx7z+FGl2h/Cwo3IzjBfPNzoT jR8yzn/SVf25fb1zd/bj6Mw9pK4ffBIV/aCK/5jPt2c5D9nuS0j6BdG/O+xJYyongnLf TU4i+VUTSCCEFZCafI8m7R2V7lh1Cty6S0GEXKpALz41KxlNbynKkZFcrFUctQDxQKiC aVyA== 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=Zj3+M66bxOFhlrx+GWHtYLelzpxVSar2LL0gkYxOSew=; fh=PDIsXZw44mkelYbulZxc+mNRoIrKCS+0dYZTfUcAsFs=; b=0LWL2J0KQlua1+WWUZtv1N87OZbPAfmtmUFl1sp6ef1ri+c5jt/jkyoU9OQKxdpxWW iWDwl+gdmiMGDDv4Da5Kd0GK4/YJeAGnfS4YfYsOgw41HTXDLkNOuYR9uGAAFwUkSdEF +gXgcqdOBWXa+ryfGV5H9qS7EE12BwddDLNu/+fVEBxx80wMkC66DM5IXbtKNgqqgEwk j19FN3ZWGQc0fJcdzZ1UKgGwnR5mgiwQ0hvlwSHoFeiaBGiuYMeBkjIgnIglfmpkOxRY 9tyUlR9TU6KxtiAdcS5FwkR7oqU4b+QEFr0XI9Tg2YEEydV/K962HPB89RRnd2/WOuSF rKaw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dWI4n96Y; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6bd82f9c8a0si88060696d6.588.2024.08.13.09.54.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Aug 2024 09:54:01 -0700 (PDT) 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=dWI4n96Y; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sdulc-000541-Vy; Tue, 13 Aug 2024 12:53:05 -0400 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 1sdula-0004uy-PF for qemu-devel@nongnu.org; Tue, 13 Aug 2024 12:53:02 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sdulW-0001CC-Tx for qemu-devel@nongnu.org; Tue, 13 Aug 2024 12:53:02 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-367990aaef3so3242118f8f.0 for ; Tue, 13 Aug 2024 09:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723567977; x=1724172777; 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=Zj3+M66bxOFhlrx+GWHtYLelzpxVSar2LL0gkYxOSew=; b=dWI4n96YJ6dB+ucPhVsv5sY1MlRLtlawskS9pRu0i/BAlYj1biBCVX8RhpmyriBkaX UT4bQWerk5qype9IDFjMe14/+cQOT39UC8biMedlQ4z312hcpmrqZMVcP0x0Irb/UufE zb/U9QW97a74tbRNaDkD0za9amTNa6ht5NmW8E+Rhba0jYCWmshYd28mi85BmmCSawdI dmo8tGxRZlwyLoHQnpNGu0/jfNMU6DUL/LaMCmKkZpP8Uky6HDy1KvUzpLSijIw7LDqj lUvBqEaAHVpCfOtr9t4OEEDx2ZppSe+U116SfMqZTTIGUkhhNrH/5DC+I2I/KkqcGmIX RlVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723567977; x=1724172777; 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=Zj3+M66bxOFhlrx+GWHtYLelzpxVSar2LL0gkYxOSew=; b=Bby5A4FklwvfVWXSsB69QX5WJkwR0zADdw/2txl0AQPhyszxr3jKD6gpuXlr7lOkmB dOih6b5vQuc9ovb0t4gSGRcWVJx3V0runqCVHQniiT1njoSF4La8++vjbGrr+KZtG/8i tQ6xpX106JJYWHo2qU/lNP/6jOKuOus+LMnwcWOuDAa+FHKGwh1i9dLvPWzO/zlGk2SN /SsJcbiHIpZ5DJ3GNo2nvZI1A8WlaqoszgkXcEjsMyGyeHvCLzDQRbKmFqmkAyJnzwIu NiyK6oapOnrz8I1NuItMrkqmLQU4QrvF1tkb+WR+gkWfkUniOg5JGlBX7HK8YgRt186+ aIGg== X-Gm-Message-State: AOJu0YyV6TAY0FNDf4QqPAqJHAfkPPgSxk2ddlPykbYkiYWLikXCeo04 8Vd8OGtkc02cASTFB5EE96T+ME1HixO63dj7H53Yyk5YbTBvSRFSjv0l5aauRjZGoyVsEoTv/bA T X-Received: by 2002:a05:6000:2a1:b0:368:37d5:3f2e with SMTP id ffacd0b85a97d-371777adb2bmr171586f8f.32.1723567977273; Tue, 13 Aug 2024 09:52:57 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429c77374a5sm147347015e9.30.2024.08.13.09.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 09:52:57 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Thomas Huth , qemu-s390x@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , David Hildenbrand , Ilya Leoshkevich , Cornelia Huck , Halil Pasic , Eric Farman , Christian Borntraeger Subject: [PATCH for-9.2 07/10] hw: Define new device_class_set_legacy_reset() Date: Tue, 13 Aug 2024 17:52:47 +0100 Message-Id: <20240813165250.2717650-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240813165250.2717650-1-peter.maydell@linaro.org> References: <20240813165250.2717650-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.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 Define a device_class_set_legacy_reset() function which sets the DeviceClass::reset field. This serves two purposes: * it makes it clearer to the person writing code that DeviceClass::reset is now legacy and they should look for the new alternative (which is Resettable) * it makes it easier to rename the reset field (which in turn makes it easier to find places that call it) The Coccinelle script can be used to automatically convert code that was doing an open-coded assignment to DeviceClass::reset to call device_class_set_legacy_reset() instead. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- scripts/coccinelle/device-reset.cocci | 30 +++++++++++++++++++++++++++ include/hw/qdev-core.h | 13 ++++++++++++ hw/core/qdev.c | 5 +++++ 3 files changed, 48 insertions(+) create mode 100644 scripts/coccinelle/device-reset.cocci diff --git a/scripts/coccinelle/device-reset.cocci b/scripts/coccinelle/device-reset.cocci new file mode 100644 index 00000000000..510042afcca --- /dev/null +++ b/scripts/coccinelle/device-reset.cocci @@ -0,0 +1,30 @@ +// Convert opencoded DeviceClass::reset assignments to calls to +// device_class_set_legacy_reset() +// +// Copyright Linaro Ltd 2024 +// This work is licensed under the terms of the GNU GPLv2 or later. +// +// spatch --macro-file scripts/cocci-macro-file.h \ +// --sp-file scripts/coccinelle/device-reset.cocci \ +// --keep-comments --smpl-spacing --in-place --include-headers --dir hw +// +// For simplicity we assume some things about the code we're modifying +// that happen to be true for all our targets: +// * all cpu_class_set_parent_reset() callsites have a 'DeviceClass *dc' local +// * the parent reset field in the target CPU class is 'parent_reset' +// * no reset function already has a 'dev' local + +@@ +identifier dc, resetfn; +@@ + DeviceClass *dc; + ... +- dc->reset = resetfn; ++ device_class_set_legacy_reset(dc, resetfn); +@@ +identifier dc, resetfn; +@@ + DeviceClass *dc; + ... +- dc->reset = &resetfn; ++ device_class_set_legacy_reset(dc, resetfn); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 18c7845ce9b..ade85c31e05 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -953,6 +953,19 @@ void device_class_set_parent_realize(DeviceClass *dc, DeviceRealize dev_realize, DeviceRealize *parent_realize); +/** + * device_class_set_legacy_reset(): set the DeviceClass::reset method + * @dc: The device class + * @dev_reset: the reset function + * + * This function sets the DeviceClass::reset method. This is widely + * used in existing code, but new code should prefer to use the + * Resettable API as documented in docs/devel/reset.rst. + * In addition, devices which need to chain to their parent class's + * reset methods or which need to be subclassed must use Resettable. + */ +void device_class_set_legacy_reset(DeviceClass *dc, + DeviceReset dev_reset); /** * device_class_set_parent_unrealize() - set up for chaining unrealize fns diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cf811580621..51827858ce7 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -844,6 +844,11 @@ static void device_class_init(ObjectClass *class, void *data) offsetof(DeviceState, parent_bus), NULL, 0); } +void device_class_set_legacy_reset(DeviceClass *dc, DeviceReset dev_reset) +{ + dc->reset = dev_reset; +} + void device_class_set_parent_realize(DeviceClass *dc, DeviceRealize dev_realize, DeviceRealize *parent_realize)