lkml.org 
[lkml]   [2024]   [Apr]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 1/2] firmware: arm_scmi: Add support for multiple vendors custom protocols
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 <cristian.marussi@arm.com>
> > > ---
> > > 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

\
 
 \ /
  Last update: 2024-04-17 15:21    [W:0.042 / U:0.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site