Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp783141rwl; Wed, 12 Apr 2023 04:11:39 -0700 (PDT) X-Google-Smtp-Source: AKy350YpeFkq/CWacoqA6Wr2Hmowry1Wi623P8fFwjsFG6Bo9qC/PbyF30e/5UwH4FnZWdSRwCRq X-Received: by 2002:a17:903:120c:b0:1a0:42d4:e38a with SMTP id l12-20020a170903120c00b001a042d4e38amr7553420plh.11.1681297899432; Wed, 12 Apr 2023 04:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681297899; cv=none; d=google.com; s=arc-20160816; b=a8ZFSJJCjiahH5AIwCkwC4yEzXWGgkuAFZHUvo4e4nPm50pLEmgz/BJVeJobJuR0IV XSlKr0Tpt7LNrn1/+IqrZ8klkKRU/TgiqjEyZsIyc+pUNyPOwacb16OsCajWhQY5I3A0 05+7k7gNwlRTGTT26rog+f5D6rUPurBYvA3pStUrOMWuVU7XlcNJksAaU+sBlUYC8Qwn N62ztPGmzobnr22ulDS/iKbATqQGGkZqljc9yg4rd90o/+0LBiAHwxBLUmiCV7uslvdQ KH3pZTpyIegJ45GxHln+QkOct60L302nLLZOgBYQ7mE+MKaTLo85n0RGa6YTLAPA77ck 5+IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dGO+LaGVOk29cf36FklMYJChk9NGcDDsM7QD9QuVRBA=; b=wU4jZ8qReIMyUyh9KTW8O+SpjrZn6bxNAiBsCvXdWCO+o34R+iw/OGJHnRFNluk1zV ivK3TwZAZ2lLH3oFT77+G0cJnfe8NNVrWhWkcnPlR/1qARU3rHzU4o/Zja+E6JxM3gz+ UBqntA+8IL6oAvcbbzBt4ADJtX52alqcziJOSIspGHeQfI7aDd/dG+rod5m3abssGEbK 805N57MQpw9hdZs2TSxG9ff2iDZTzKHqj5kfVTJhVBcyXCG0L2yee7pdhdnDLd+M6uOO Qkc9mDF0Bb9ITbW+BcjimUxVdzr7hvfPKu+cG/+rCne2+cnVhUnUm5jqZ35sLhVYmd7u jc4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MeP2q3zH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 5-20020a630f45000000b00519cded062csi8154055pgp.788.2023.04.12.04.11.27; Wed, 12 Apr 2023 04:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MeP2q3zH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbjDLLJa (ORCPT + 99 others); Wed, 12 Apr 2023 07:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjDLLJ2 (ORCPT ); Wed, 12 Apr 2023 07:09:28 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83DC71BD; Wed, 12 Apr 2023 04:09:26 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id s2so7214124wra.7; Wed, 12 Apr 2023 04:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681297765; x=1683889765; 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=dGO+LaGVOk29cf36FklMYJChk9NGcDDsM7QD9QuVRBA=; b=MeP2q3zHTymS32ugCSJabv9lQy4/FYzsnn7cm2pA1JzNgNltj1ed3r0YHawXaMZDT1 Orgij9HV213j7YDORZ9TfG65iZK7PyLpVFO5W3YbtyEGDaLbzyzprSrTMGS6Ns4TV0l9 t0Lcf9fOhKoOOLKlW+YNtDxCVfa1n3HYAXyuaFqzC8mdaKVlf7ajnSM+sPw34RGGTAU0 uCJ8ZXkcXKpKxIf3IQQGpu9yDpXxMzeDrx77XeXn3H0rUJPs/VXcegQhuV9vHbwVz0Bl cjvnBZCEqxSiaGNWXjW6z4alV4ec7eZTTp+9XLlxbAclyO9GS89KNilAzTG5UdFbaB49 yqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681297765; x=1683889765; 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=dGO+LaGVOk29cf36FklMYJChk9NGcDDsM7QD9QuVRBA=; b=yW1fE3BStBNoj+SjhgJg8X9EUptD+Cko8N/OsjuHHIisdq9lHMZaGLJ0TBoLdSNoBk rcHzw1xMh0b0Q2h9OtcyPxY3uVL460LBy7w+nbXL6J2fDBxnWhhWoDoTrm6RBMfp34P3 8dwx15ehAnu6QHQZ1UH9ZqUTNOK/VBJzW5NtJe0Fy3FbkZdm23fc0x/9w6V6ewP/QsZX ogaaVwQineZZejGhDn3cq9uGaYgFcUbpokBvAd0z5Hn0OIqZF0Tf6Oewfohp4m7vNbNV 2wktqXpfoa3D0Tg43EoWOvemuTbeeyijRDeUGTk7kANIqwAAlCjF7XqofLkf+Gwc4aog DE1g== X-Gm-Message-State: AAQBX9d4hBgQXIUzh5HBeAr4ef55XKtF9prVPLrw1jjdZpjEz3LPj/Oa w1WCT+8v3r71Tb+ZnqiZmhU= X-Received: by 2002:a5d:65cd:0:b0:2f0:2cf9:fed0 with SMTP id e13-20020a5d65cd000000b002f02cf9fed0mr6792924wrw.49.1681297764779; Wed, 12 Apr 2023 04:09:24 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:783d:9280:20c4:db22]) by smtp.gmail.com with ESMTPSA id l13-20020a5d668d000000b002e61e002943sm16863582wru.116.2023.04.12.04.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:09:23 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Arnd Bergmann , Conor Dooley , Geert Uytterhoeven , Heiko Stuebner , Guo Ren , Andrew Jones , Paul Walmsley , Palmer Dabbelt , Albert Ou , Samuel Holland , linux-riscv@lists.infradead.org Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar , Heiko Stuebner Subject: [PATCH v8 1/7] riscv: asm: alternative-macros: Introduce ALTERNATIVE_3() macro Date: Wed, 12 Apr 2023 12:08:54 +0100 Message-Id: <20230412110900.69738-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230412110900.69738-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230412110900.69738-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lad Prabhakar Introduce ALTERNATIVE_3() macro. A vendor wants to replace an old_content, but another vendor has used ALTERNATIVE_2() to patch its customized content at the same location. In this case, this vendor can use macro ALTERNATIVE_3() and then replace ALTERNATIVE_2() with ALTERNATIVE_3() to append its customized content. While at it update comment above ALTERNATIVE_2() macro and make it generic so that the comment holds good for any new addition of ALTERNATIVE_X() macros. Signed-off-by: Lad Prabhakar Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley --- v5->v8 * Added RB tags from Conor and Heiko * Fixed review comments pointed by Geert and Conor v4->v5 * Rebased the patch on top of Andrew's series (now in Palmers for next-branch) * Updated comment for ALTERNATIVE_x() as suggested by Heiko RFC v3 -> v4 * New patch --- arch/riscv/include/asm/alternative-macros.h | 51 +++++++++++++++++++-- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/alternative-macros.h b/arch/riscv/include/asm/alternative-macros.h index b8c55fb3ab2c..fd5f99714f29 100644 --- a/arch/riscv/include/asm/alternative-macros.h +++ b/arch/riscv/include/asm/alternative-macros.h @@ -50,8 +50,17 @@ ALT_NEW_CONTENT \vendor_id_2, \patch_id_2, \enable_2, "\new_c_2" .endm +.macro ALTERNATIVE_CFG_3 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \ + new_c_2, vendor_id_2, errata_id_2, enable_2, \ + new_c_3, vendor_id_3, errata_id_3, enable_3 + ALTERNATIVE_CFG_2 "\old_c", "\new_c_1", \vendor_id_1, \errata_id_1, \enable_1, \ + "\new_c_2", \vendor_id_2, \errata_id_2, \enable_2 + ALT_NEW_CONTENT \vendor_id_3, \errata_id_3, \enable_3, "\new_c_3" +.endm + #define __ALTERNATIVE_CFG(...) ALTERNATIVE_CFG __VA_ARGS__ #define __ALTERNATIVE_CFG_2(...) ALTERNATIVE_CFG_2 __VA_ARGS__ +#define __ALTERNATIVE_CFG_3(...) ALTERNATIVE_CFG_3 __VA_ARGS__ #else /* !__ASSEMBLY__ */ @@ -98,6 +107,13 @@ __ALTERNATIVE_CFG(old_c, new_c_1, vendor_id_1, patch_id_1, enable_1) \ ALT_NEW_CONTENT(vendor_id_2, patch_id_2, enable_2, new_c_2) +#define __ALTERNATIVE_CFG_3(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \ + new_c_2, vendor_id_2, errata_id_2, enable_2, \ + new_c_3, vendor_id_3, errata_id_3, enable_3) \ + __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \ + new_c_2, vendor_id_2, errata_id_2, enable_2) \ + ALT_NEW_CONTENT(vendor_id_3, errata_id_3, enable_3, new_c_3) + #endif /* __ASSEMBLY__ */ #define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, patch_id, CONFIG_k) \ @@ -108,6 +124,13 @@ __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, patch_id_1, IS_ENABLED(CONFIG_k_1), \ new_c_2, vendor_id_2, patch_id_2, IS_ENABLED(CONFIG_k_2)) +#define _ALTERNATIVE_CFG_3(old_c, new_c_1, vendor_id_1, errata_id_1, CONFIG_k_1, \ + new_c_2, vendor_id_2, errata_id_2, CONFIG_k_2, \ + new_c_3, vendor_id_3, errata_id_3, CONFIG_k_3) \ + __ALTERNATIVE_CFG_3(old_c, new_c_1, vendor_id_1, errata_id_1, IS_ENABLED(CONFIG_k_1), \ + new_c_2, vendor_id_2, errata_id_2, IS_ENABLED(CONFIG_k_2), \ + new_c_3, vendor_id_3, errata_id_3, IS_ENABLED(CONFIG_k_3)) + #else /* CONFIG_RISCV_ALTERNATIVE */ #ifdef __ASSEMBLY__ @@ -121,6 +144,9 @@ #define _ALTERNATIVE_CFG_2(old_c, ...) \ ALTERNATIVE_CFG old_c +#define _ALTERNATIVE_CFG_3(old_c, ...) \ + ALTERNATIVE_CFG old_c + #else /* !__ASSEMBLY__ */ #define __ALTERNATIVE_CFG(old_c) \ @@ -132,6 +158,9 @@ #define _ALTERNATIVE_CFG_2(old_c, ...) \ __ALTERNATIVE_CFG(old_c) +#define _ALTERNATIVE_CFG_3(old_c, ...) \ + __ALTERNATIVE_CFG(old_c) + #endif /* __ASSEMBLY__ */ #endif /* CONFIG_RISCV_ALTERNATIVE */ @@ -152,15 +181,27 @@ _ALTERNATIVE_CFG(old_content, new_content, vendor_id, patch_id, CONFIG_k) /* - * A vendor wants to replace an old_content, but another vendor has used - * ALTERNATIVE() to patch its customized content at the same location. In - * this case, this vendor can create a new macro ALTERNATIVE_2() based - * on the following sample code and then replace ALTERNATIVE() with - * ALTERNATIVE_2() to append its customized content. + * ALTERNATIVE_x macros allow providing multiple replacement options + * for an ALTERNATIVE code section. This is helpful if multiple + * implementation variants for the same functionality. + * + * Usage: + * ALTERNATIVE_x(old_content, + * new_content1, vendor_id1, errata_id1, CONFIG_k1, + * new_content2, vendor_id2, errata_id2, CONFIG_k2, + * ... + * new_contentx, vendor_idx, errata_idx, CONFIG_kx) */ #define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, patch_id_1, CONFIG_k_1, \ new_content_2, vendor_id_2, patch_id_2, CONFIG_k_2) \ _ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, patch_id_1, CONFIG_k_1, \ new_content_2, vendor_id_2, patch_id_2, CONFIG_k_2) +#define ALTERNATIVE_3(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \ + new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2, \ + new_content_3, vendor_id_3, errata_id_3, CONFIG_k_3) \ + _ALTERNATIVE_CFG_3(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \ + new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2, \ + new_content_3, vendor_id_3, errata_id_3, CONFIG_k_3) + #endif -- 2.25.1