From patchwork Thu Apr 25 10:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 792000 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1312016wrq; Thu, 25 Apr 2024 03:42:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX1Fo5X7fqD5YHIEmXldRMlWKH8NpU36OCmmiNfIKd2RWjFrej0U8qSsHkfanuKWyxEIeqdUQCGQ72gVXt8jox1 X-Google-Smtp-Source: AGHT+IGwciCTbYHD95bvDrblISp+7u+mew0UXoobjylRXuuAocOqBFUM6PIGBy0XkbyCPLOQ+2Lm X-Received: by 2002:a05:6808:14c7:b0:3c4:e8ab:deee with SMTP id f7-20020a05680814c700b003c4e8abdeeemr6166671oiw.43.1714041761925; Thu, 25 Apr 2024 03:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714041761; cv=none; d=google.com; s=arc-20160816; b=U0DnQrFli6DczTt0kCramvYjd9HKHu13oQ0ydDFYE12zFV7kxKP3sR2h/TxQMlU5bu MRlrHodvYUvF3DXCu3GLrBZSIG19YFMCkpDwLfUTYl4PO+QqbIsNvRjglH2xclphfdDr 2sWhnPD+5qZeSG1/65VDgtdEyIs0wPnz9z8pLBV2L+ml1J5fU20GmU35gblvncGHAlT6 CFCwTdnmYAC8D8/yuaw4rLFqTQzkOPa3fYDSHOeup/ZpA5K8p8HduhVTe0iQWdUpz5Mv ICK3zGszrVHDAI3Mr3U0EkdZx+Uy+Md/jAMdKhfhrrEHjBiy0eNkBger5K4zgFBXYbKJ sPlQ== 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=IZveBcQ/I3Ep99MpkKq6qvJrHhr8FNS0mASz7sTHHrA=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=qOah/cfH+6ENyDXDIcdzzrdqlgpW1by2aWbH/QOc4O4kPvyFzo7HxW8MOzFrbe7jpi ult0eEkHNtbxFnvrDmHbCkvdHr0DJyTs6ydktjH9uOvI/ZcJNAfamiwOL6F9OvMfwNk1 6fnKYN0M2mCOvII8QPaXRSlUK5/qjfXTszSGjnCMb6iFO/7hOwCtK5UbIPqppV/TfqaL /hWR1GcAqDg7zd/tQeT4h41YEUbrjRI9jy9Fj9B7LRG8+J2bIYojWKWXEQXvLwsO1TF2 TUO6/3M9nUkGsmNDsekHeNuaHl7IO1RHGMPj/jk+7/x2LjdoLrZnxyh/ViOiawlj2hwq /kAQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CLAFJ662; 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 c21-20020a05620a269500b0078d582cb7ebsi19895675qkp.336.2024.04.25.03.42.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Apr 2024 03:42:41 -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=CLAFJ662; 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 1rzwWe-0002Mt-Ny; Thu, 25 Apr 2024 06:40:24 -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 1rzwWa-00026V-0m for qemu-devel@nongnu.org; Thu, 25 Apr 2024 06:40:20 -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 1rzwWW-0007EJ-Mx for qemu-devel@nongnu.org; Thu, 25 Apr 2024 06:40:19 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-34a4772d5easo741358f8f.0 for ; Thu, 25 Apr 2024 03:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714041615; x=1714646415; 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=IZveBcQ/I3Ep99MpkKq6qvJrHhr8FNS0mASz7sTHHrA=; b=CLAFJ662SqhQqARHFMWY5C8BzeVQ9FLTIKr1RGR3radWYd1NB3M085WAbArXU/80+F cGDA5yjIO8DaEglxtHf0a7PBz1uDB3ELOMPBirxftBLr4DAIM+FPnkBitPoojVF89Rd+ EXhU3ENiucjuCP/Wt2nbcTl7jlO5bVHK48/Od6UxQqj4lVoXBpqPOnzErDt+s20WC9iY gzCycF+jsHw65oPXRHkEZcjqkCx7wOoTqiZD48ViwnosTYGgCVlmiEkV6buqhTJ9qnob p3LTUgRV8p+2DiEBl6UeMLL+GXBXEAjbCnXzmwQ71NfyZL2Dr3Qr+rEF96AoV7JnlfCo Mu4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714041615; x=1714646415; 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=IZveBcQ/I3Ep99MpkKq6qvJrHhr8FNS0mASz7sTHHrA=; b=JM+Ei237Oz/EnEChHJLHWjKlv2xL7ebv13rBq1um7eKzu1mrPHFiYTyxx+0qUEVY/i Hit9b/hXAW5FXtZqIv/yVwEIerdkL+0JjDLPEcgIp4guraJZZEOoQVC9ofnCs5NO8Ot1 G3w/6v5MOpdsCeyb5BwOpqYQskKkQjytjoQTTjjjY7JMWOVXWZ/20j7aTd2Z7/G06L+B MqyN7mtpNtLPa6OaLyYdsBgcUvirGEFOny3EnPEdhV3CXCuEfp4fRmAFQL/5FHUF3XZJ Z7+s8GMxXhYQf0uhQiDruZBIttaY6T+1GS6xh6aBr8d+Q41+XQ1VaCjjK7K/Ccb8UFKW OKeg== X-Gm-Message-State: AOJu0YwxP+TihJbdrZTUf1cRKCGl8c0BVn20Sc1xECk7Puo8lBr+/ADM BOm2kH/AWAf001NDux60nHKQ1GWyAKAxTmoK4/iXgxwSQwMoR+IWSjGL35Cly3qtdoWesBv9QQp m X-Received: by 2002:adf:e8c7:0:b0:343:c6d1:280d with SMTP id k7-20020adfe8c7000000b00343c6d1280dmr3560511wrn.21.1714041614901; Thu, 25 Apr 2024 03:40:14 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id h15-20020a056000000f00b003434c764f01sm19485768wrx.107.2024.04.25.03.40.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 03:40:14 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 29/37] scripts/coccinelle: New script to add ResetType to hold and exit phases Date: Thu, 25 Apr 2024 11:39:50 +0100 Message-Id: <20240425103958.3237225-30-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240425103958.3237225-1-peter.maydell@linaro.org> References: <20240425103958.3237225-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 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 We pass a ResetType argument to the Resettable class enter phase method, but we don't pass it to hold and exit, even though the callsites have it readily available. This means that if a device cared about the ResetType it would need to record it in the enter phase method to use later on. We should pass the type to all three of the phase methods to avoid having to do that. This coccinelle script adds the ResetType argument to the hold and exit phases of the Resettable interface. The first part of the script (rules holdfn_assigned, holdfn_defined, exitfn_assigned, exitfn_defined) update implementations of the interface within device models, both to change the signature of their method implementations and to pass on the reset type when they invoke reset on some other device. The second part of the script is various special cases: * method callsites in resettable_phase_hold(), resettable_phase_exit() and device_phases_reset() * updating the typedefs for the methods * isl_pmbus_vr.c has some code where one device's reset method directly calls the implementation of a different device's method Signed-off-by: Peter Maydell Reviewed-by: Luc Michel Message-id: 20240412160809.1260625-4-peter.maydell@linaro.org --- scripts/coccinelle/reset-type.cocci | 133 ++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 scripts/coccinelle/reset-type.cocci diff --git a/scripts/coccinelle/reset-type.cocci b/scripts/coccinelle/reset-type.cocci new file mode 100644 index 00000000000..14abdd7bd0c --- /dev/null +++ b/scripts/coccinelle/reset-type.cocci @@ -0,0 +1,133 @@ +// Convert device code using three-phase reset to add a ResetType +// argument to implementations of ResettableHoldPhase and +// ResettableEnterPhase methods. +// +// Copyright Linaro Ltd 2024 +// SPDX-License-Identifier: GPL-2.0-or-later +// +// for dir in include hw target; do \ +// spatch --macro-file scripts/cocci-macro-file.h \ +// --sp-file scripts/coccinelle/reset-type.cocci \ +// --keep-comments --smpl-spacing --in-place --include-headers \ +// --dir $dir; done +// +// This coccinelle script aims to produce a complete change that needs +// no human interaction, so as well as the generic "update device +// implementations of the hold and exit phase methods" it includes +// the special-case transformations needed for the core code and for +// one device model that does something a bit nonstandard. Those +// special cases are at the end of the file. + +// Look for where we use a function as a ResettableHoldPhase method, +// either by directly assigning it to phases.hold or by calling +// resettable_class_set_parent_phases, and remember the function name. +@ holdfn_assigned @ +identifier enterfn, holdfn, exitfn; +identifier rc; +expression e; +@@ +ResettableClass *rc; +... +( + rc->phases.hold = holdfn; +| + resettable_class_set_parent_phases(rc, enterfn, holdfn, exitfn, e); +) + +// Look for the definition of the function we found in holdfn_assigned, +// and add the new argument. If the function calls a hold function +// itself (probably chaining to the parent class reset) then add the +// new argument there too. +@ holdfn_defined @ +identifier holdfn_assigned.holdfn; +typedef Object; +identifier obj; +expression parent; +@@ +-holdfn(Object *obj) ++holdfn(Object *obj, ResetType type) +{ + <... +- parent.hold(obj) ++ parent.hold(obj, type) + ...> +} + +// Similarly for ResettableExitPhase. +@ exitfn_assigned @ +identifier enterfn, holdfn, exitfn; +identifier rc; +expression e; +@@ +ResettableClass *rc; +... +( + rc->phases.exit = exitfn; +| + resettable_class_set_parent_phases(rc, enterfn, holdfn, exitfn, e); +) +@ exitfn_defined @ +identifier exitfn_assigned.exitfn; +typedef Object; +identifier obj; +expression parent; +@@ +-exitfn(Object *obj) ++exitfn(Object *obj, ResetType type) +{ + <... +- parent.exit(obj) ++ parent.exit(obj, type) + ...> +} + +// SPECIAL CASES ONLY BELOW HERE +// We use a python scripted constraint on the position of the match +// to ensure that they only match in a particular function. See +// https://public-inbox.org/git/alpine.DEB.2.21.1808240652370.2344@hadrien/ +// which recommends this as the way to do "match only in this function". + +// Special case: isl_pmbus_vr.c has some reset methods calling others directly +@ isl_pmbus_vr @ +identifier obj; +@@ +- isl_pmbus_vr_exit_reset(obj); ++ isl_pmbus_vr_exit_reset(obj, type); + +// Special case: device_phases_reset() needs to pass RESET_TYPE_COLD +@ device_phases_reset_hold @ +expression obj; +identifier rc; +identifier phase; +position p : script:python() { p[0].current_element == "device_phases_reset" }; +@@ +- rc->phases.phase(obj)@p ++ rc->phases.phase(obj, RESET_TYPE_COLD) + +// Special case: in resettable_phase_hold() and resettable_phase_exit() +// we need to pass through the ResetType argument to the method being called +@ resettable_phase_hold @ +expression obj; +identifier rc; +position p : script:python() { p[0].current_element == "resettable_phase_hold" }; +@@ +- rc->phases.hold(obj)@p ++ rc->phases.hold(obj, type) +@ resettable_phase_exit @ +expression obj; +identifier rc; +position p : script:python() { p[0].current_element == "resettable_phase_exit" }; +@@ +- rc->phases.exit(obj)@p ++ rc->phases.exit(obj, type) +// Special case: the typedefs for the methods need to declare the new argument +@ phase_typedef_hold @ +identifier obj; +@@ +- typedef void (*ResettableHoldPhase)(Object *obj); ++ typedef void (*ResettableHoldPhase)(Object *obj, ResetType type); +@ phase_typedef_exit @ +identifier obj; +@@ +- typedef void (*ResettableExitPhase)(Object *obj); ++ typedef void (*ResettableExitPhase)(Object *obj, ResetType type);