From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43979C4345F for ; Wed, 17 Apr 2024 12:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zqjWOKcneLGMdj1w7IA38PbUv6wldATFmB+mxudSC2Y=; b=ySSsHo7S6PfOAV tqhTgXfB4pKmwoR6L4qDi5nG55oDrN8+9XidDlItCvKWD/TuY3Aq0hP65VMHKzArZyBhFobBfPtof d1AwWk/+JzptFkJJESYkNlTdHzIcaiQ/5glKlikBJNMsKd+upqR7MgX7tN5aTGX6KK+LmIyDBilML b6wSmyxgAEvYZoYvDHo/gsgn3ruDDb1aPYOKwWCXONOKSrRBgjZPlJhoH231DphW78qdzV2VSKgGE 3pjyaaMNnsRNqXEcJD3Tc5MLKFlF1dYtHralQejHEBMnvEnkoHBpTNsN9WLxns9W9LX6bL/GOjGag wKklWk3beIVn6zT0RvNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx4SW-0000000FwkH-3xs6; Wed, 17 Apr 2024 12:32:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx4SU-0000000FwiB-1ckT for linux-arm-kernel@lists.infradead.org; Wed, 17 Apr 2024 12:32:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 697B7339; Wed, 17 Apr 2024 05:32:40 -0700 (PDT) Received: from bogus (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DC7823F738; Wed, 17 Apr 2024 05:32:10 -0700 (PDT) Date: Wed, 17 Apr 2024 13:32:08 +0100 From: Sudeep Holla To: Cristian Marussi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, konrad.dybcio@linaro.org, souvik.chakravarty@arm.com Subject: Re: [PATCH v2 1/2] firmware: arm_scmi: Add support for multiple vendors custom protocols Message-ID: <20240417123208.criylj2kvdngoswe@bogus> References: <20240408093052.3801576-1-cristian.marussi@arm.com> <20240408093052.3801576-2-cristian.marussi@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240408093052.3801576-2-cristian.marussi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240417_053214_570184_9B31CE32 X-CRM114-Status: GOOD ( 24.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 08, 2024 at 10:30:51AM +0100, Cristian Marussi wrote: > Add a mechanism to be able to tag vendor protocol modules at compile-time > with a vendor/sub_vendor string and an implementation version and then to > choose to load, at run-time, only those vendor protocol modules matching > as close as possible the vendor/subvendor identification advertised by > the SCMI platform server. > > In this way, any in-tree existent vendor protocol module can be build and > shipped by default in a single kernel image, even when using the same > clashing protocol identification numbers, since the SCMI core will take > care at run-time to load only the ones pertinent to the running system. > > Signed-off-by: Cristian Marussi > --- > drivers/firmware/arm_scmi/driver.c | 165 ++++++++++++++++++++++---- > drivers/firmware/arm_scmi/protocols.h | 15 +++ > 2 files changed, 158 insertions(+), 22 deletions(-) > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c > index d0091459a276..aa18202054a5 100644 > --- a/drivers/firmware/arm_scmi/driver.c > +++ b/drivers/firmware/arm_scmi/driver.c [...] > +static const struct scmi_protocol * > +scmi_vendor_protocol_lookup(int protocol_id, char *vendor_id, > + char *sub_vendor_id, u32 impl_ver) > +{ > + unsigned long key; > + struct scmi_protocol *proto = NULL; > + > + /* Searching for closest match ...*/ > + key = scmi_protocol_key_calculate(protocol_id, vendor_id, > + sub_vendor_id, impl_ver); > + if (key) > + proto = xa_load(&scmi_protocols, key); > + > + if (proto) > + return proto; > + > + /* Any match on vendor/sub_vendor ? */ > + if (impl_ver) { > + key = scmi_protocol_key_calculate(protocol_id, vendor_id, > + sub_vendor_id, 0); > + if (key) > + proto = xa_load(&scmi_protocols, key); > + > + if (proto) > + return proto; > + } > + > + /* Any match on just the vendor ? */ > + if (sub_vendor_id) { > + key = scmi_protocol_key_calculate(protocol_id, vendor_id, > + NULL, 0); > + if (key) > + proto = xa_load(&scmi_protocols, key); > + } > I see a pattern here, can be simplify/compress by something like below ? static const struct scmi_protocol * __scmi_vendor_protocol_lookup(int protocol_id, char *vendor_id, char *sub_vendor_id, u32 impl_ver) { unsigned long key; struct scmi_protocol *proto = NULL; key = scmi_protocol_key_calculate(protocol_id, vendor_id, sub_vendor_id, impl_ver); if (key) proto = xa_load(&scmi_protocols, key); return proto; } [...] > diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h > index 317d3fb32676..45ee8b35f56d 100644 > --- a/drivers/firmware/arm_scmi/protocols.h > +++ b/drivers/firmware/arm_scmi/protocols.h > @@ -29,6 +29,8 @@ > #define PROTOCOL_REV_MAJOR(x) ((u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))) > #define PROTOCOL_REV_MINOR(x) ((u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x)))) > > +#define SCMI_PROTOCOL_VENDOR 0x80 > + s/SCMI_PROTOCOL_VENDOR/SCMI_PROTOCOL_VENDOR_BASE/ as I expect 0x80 to be used by most vendors. -- Regards, Sudeep _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel