Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp612981lqb; Wed, 17 Apr 2024 06:21:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEIjgX1rhpSBxKe0jisTo/yZy4rNkNLNmTz/HH9vwj1BwWdy4kcT5VGQVTqrva9U6B999himsGWyE5rm55iEoxnpgMf1Pu0FRweW2Wtg== X-Google-Smtp-Source: AGHT+IEKS41Nn2HbJ8FFz3ajwAmDQUkm+Vv2eAMosdvt+9oLb1/NRX58dzc23OEWcZYOZ977SHrV X-Received: by 2002:a17:902:c943:b0:1e2:7734:63dd with SMTP id i3-20020a170902c94300b001e2773463ddmr9375868pla.30.1713360116789; Wed, 17 Apr 2024 06:21:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713360116; cv=pass; d=google.com; s=arc-20160816; b=p8Uy7UFGv21Iw+Fs4GaKJ3eQynrYQU6NOWxTNNr8jA+roKh8V/DdyaSMv51b2Qmybe kpeKwKQgEAzYi3RJEhyjvA8Rm6ONdq3pQYncW7no1PY7/vsaTP1200asLA/ATjjF/hlb lEVS2VbZ3n6s/rmhvUN+6Xh2bVWPASJ3tYoO6cy09A2A4yJyYsz3afL+z/+n87t/wKXO JI1ZnX4s/+iVddkr1C18qGFJCDKeHSpFnJxwcq4t2CV61tWVXBX+28aTGANF/CJH0r6I 1Md59ewyVrASmSjy9XS/26kG1WveCK+ocLVficDt+Qs9JN+ZGg1BoDAeJ6w24irMj2I+ b+MA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=fK0qMKOTx113oE3oBYG8i4w8r6LSTpyyshoMaAYSxuA=; fh=C/cESWNMc1JLdm7zSqI7StgNvmsLsHyxQVnSrtDZBBw=; b=VdJLoQN5MSugVXaV7kDVP2S/4zNyRytrh0gKLYPxvbq0WtdDyJ/HErwfi53CY5d8Jr UQwcKJcqDS5QsdyknpXSBaaRh1Q+Y1zg3xxmsnARNIS1BdlfRDY7Ufamfn7iSBC9sI/T CLqH/FsQ35KauaYEqUOGUr6huw3JVrHv7Dz1O9MXXuHmavxOKmL8d3Cy6h/doiUvyVrn finpRUuOORuaoAoH7b88v/woOlpB6YvW7JwCewxoa8vGzbK/FNadOjInywq7BMLRKRyJ krHVZUM3d8D4/U/2b/BuI+MLn2kF4vNZX8Qo/qFrV6hOxUdtYVu3JXH2wVnptd3J0Znj 6Uug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148548-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148548-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z14-20020a170903018e00b001e3cd26cef3si11426968plg.503.2024.04.17.06.21.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 06:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148548-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148548-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148548-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5342C285D5A for ; Wed, 17 Apr 2024 13:21:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58FBC13E40D; Wed, 17 Apr 2024 13:21:06 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A362B13E02A for ; Wed, 17 Apr 2024 13:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713360065; cv=none; b=Rtr52wo+lUB7uw93yN+5IciUSLn1SwF+2hBlTjh1od3wrfLkajhWi37RQ/0sc+kYNQdCyJaF77V2h1QB8/qZQmgVh+0RyZDImNezUo8eVJfk4eTMkLwATjAvi5hz+RP9FK/386o1aPYZGfc+lCY0S00wEz2olIZw7PF6k1fddUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713360065; c=relaxed/simple; bh=nETCHB7JIutC8EKJAX2M9aPwQSEYpjvigfPP7Y07kDg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kEQecvYd8NY0v2WH0VMhvs5wta/aophoh/n0HCO+n6yjxjvI5gkZLX8rFbgUo4Gs4xOPVKVV52qVzndW+/wERW7BCrhJw1PTdhsGaUgYQmp1Ir2NWX1gJmJGIXlBj02wcG5o8tNC4G5NgODHwAVkOyCJe2RLDZ9nR4+oXW29u2E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 B960F339; Wed, 17 Apr 2024 06:21:29 -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 1F7483F738; Wed, 17 Apr 2024 06:20:59 -0700 (PDT) Date: Wed, 17 Apr 2024 14:20:57 +0100 From: Sudeep Holla To: Cristian Marussi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sudeep Holla , 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: <20240417132057.2s5s2mzgub2nnyd3@bogus> References: <20240408093052.3801576-1-cristian.marussi@arm.com> <20240408093052.3801576-2-cristian.marussi@arm.com> <20240417123208.criylj2kvdngoswe@bogus> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 17, 2024 at 01:42:50PM +0100, Cristian Marussi wrote: > On Wed, Apr 17, 2024 at 01:32:08PM +0100, Sudeep Holla wrote: > > 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; > > } > > Sure...was not completely sure to proceed that way because only 2 lines > were saved for a each block....bit indeed is more clear...I'll d in V3 Agreed, that's why I was asking rather than requesting you to change ????. Even I was not sure by the time I completed writing the above one ????. It may make it bit easier to read. -- Regards, Sudeep