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 X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EB49C388F9 for ; Wed, 4 Nov 2020 16:17:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A468D20665 for ; Wed, 4 Nov 2020 16:17:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gVxn1Drv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QOr8wzrO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A468D20665 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:References: To:Subject:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lG2wAhFHrEFXXn1QkcmazGTuYyK15lcBuD0k+F/kED8=; b=gVxn1DrvVWn6MPD2mipMfpDkU L7QhvMeClcQNZlCHwoqPsknXElhrqAUfxaRAFV88YTRc6CN4y5C7C7y878p8ZMPyM7C3h2L5cU5Sf itR0F9qwo8Xfi1q+NIAdeHdGnCK78YHmCkXQF52oY3msc7T+Q5+qhAoRadP1WcLlvjDEOIFm/6hTk zdo3IJgeWQ/YVFFepiQldkz9k1eFXTJWV8/dIsdia2IPTUar8vxocJJ25VEfrdWiY3BiVen/UneWv zf70SlRFmWNSQcyExyY+3VQFSPmefmBUzFGGQbjtmgOoZwy2i/6Iu2EwitFTyQMpyYyiVvejZCseU LqEySjWzg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaLSF-0001qy-PO; Wed, 04 Nov 2020 16:16:11 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaLSC-0001qQ-Vv for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 16:16:09 +0000 Received: by mail-qk1-x741.google.com with SMTP id z6so19812042qkz.4 for ; Wed, 04 Nov 2020 08:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=IlTAb4BQFKLR3Tp2hVVjxVAiIHililKzH5OOJDZzwxc=; b=QOr8wzrOvSlBhZ2KeMtFcbmJEhtHgIaT6+6g88ZBDvljUOSxxEwVe5zPghnzfdSkgr 9cjGuWrwaEQcnIbUxY4PFPnLedMUsHGfEv/tmMYRvMTrro4owFbK7oSIoPScj0k0PXpi fheanQ/c6UCG3EHEPDKfhEZ3EbWMQCOPmBHGJFcKjBm3pSBNkNSo7tRD4jbt85uFDyji rFtL2DGQsPwJENXzwRqrLBHokB0oTyftZY7d3uJYuyDnIDlknN0tkwmgRHBY5wGdBsAz WCPWfs+YetVLsE2UDVQRme14fbKVnVLaeQOpiubIVGUhw74nQVdmtmh6IcLhSdSlXyk9 wYiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=IlTAb4BQFKLR3Tp2hVVjxVAiIHililKzH5OOJDZzwxc=; b=hVG2fMCmOyjjndP8ufAzU3JVYhcz+z35PFlORBZsIleh82bHpo1gTQ/WxU24HVm+3e M5NlrmneEK9yVLTszrz7CL675TIFU8YwnVtzPNE+iKDsF+Z6N42fW0nsQ5SE3xFg2Ydn e1sIcigdTj//cXKzWi7tJv3itJnLA3tg4icq8aYQplrHZGyal9J69pwCnterrP0DDBPN ei/kugZUeKDY8k0qJ1EgOQZkw3kq1oX7TRSJYAceZNBWB/dSw0IhuKG+IL9FHmvX91MI QFKiNyzGulbleRsRhIiU5V7ZFkPDgYlFSM5yjjquoXQl29t83JLKrTamwR7yX7+6nyg5 bofg== X-Gm-Message-State: AOAM532Cwq1aNvkIruhkb6a+EuOCE6yRem4Vnku9pj3VuUAoEY+dMo68 bULoxXt6jY1vpGS2JHe77a/NqA== X-Google-Smtp-Source: ABdhPJwCPsL0biegx2jXavgl6FstsvZSJZYZFXvWTOeFm1W9KodCIvCfGi1jcZnKVCiIFSCBZ4BvFw== X-Received: by 2002:a05:620a:20c5:: with SMTP id f5mr2332163qka.69.1604506567074; Wed, 04 Nov 2020 08:16:07 -0800 (PST) Received: from [192.168.1.93] (pool-71-163-245-5.washdc.fios.verizon.net. [71.163.245.5]) by smtp.gmail.com with ESMTPSA id u31sm465634qtu.87.2020.11.04.08.16.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 08:16:06 -0800 (PST) From: Thara Gopinath Subject: Re: [PATCH v2 1/8] firmware: arm_scmi: review protocol registration interface To: Cristian Marussi , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20201028202914.43662-1-cristian.marussi@arm.com> <20201028202914.43662-2-cristian.marussi@arm.com> Message-ID: <5bc2f96e-bb66-c816-d856-56a18456dcf5@linaro.org> Date: Wed, 4 Nov 2020 11:16:06 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201028202914.43662-2-cristian.marussi@arm.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_111609_075581_1E35E823 X-CRM114-Status: GOOD ( 34.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: f.fainelli@gmail.com, vincent.guittot@linaro.org, sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com, souvik.chakravarty@arm.com, etienne.carriere@linaro.org, lukasz.luba@arm.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Cristian, On 10/28/20 4:29 PM, Cristian Marussi wrote: > Extend common protocol registration routines and provide some new generic > protocols' init/deinit helpers that tracks protocols' users and automatically > perform the proper initialization/de-initialization on demand. > > Convert all protocols to use new registration schema while modifying only Base > protocol to use also the new initialization helpers. > > All other standard protocols' initialization is still umodified and bound to > SCMI devices probing. minor nit : umodified->unmodified. > > Signed-off-by: Cristian Marussi > --- > v1 --> v2 > - made all scmi_protocol refs const > - introduced IDR to handle protocols instead of static array > - refactored code around fast path > --- > drivers/firmware/arm_scmi/base.c | 10 +- > drivers/firmware/arm_scmi/bus.c | 61 +++++++--- > drivers/firmware/arm_scmi/clock.c | 10 +- > drivers/firmware/arm_scmi/common.h | 31 ++++- > drivers/firmware/arm_scmi/driver.c | 168 +++++++++++++++++++++++++++- > drivers/firmware/arm_scmi/notify.c | 3 +- > drivers/firmware/arm_scmi/perf.c | 10 +- > drivers/firmware/arm_scmi/power.c | 10 +- > drivers/firmware/arm_scmi/reset.c | 10 +- > drivers/firmware/arm_scmi/sensors.c | 10 +- > drivers/firmware/arm_scmi/system.c | 8 +- > include/linux/scmi_protocol.h | 6 +- > 12 files changed, 299 insertions(+), 38 deletions(-) > [...] > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c > index 3dfd8b6a0ebf..beae8991422d 100644 > --- a/drivers/firmware/arm_scmi/driver.c > +++ b/drivers/firmware/arm_scmi/driver.c > @@ -11,11 +11,12 @@ > * various power domain DVFS including the core/cluster, certain system > * clocks configuration, thermal sensors and many others. > * > - * Copyright (C) 2018 ARM Ltd. > + * Copyright (C) 2018-2020 ARM Ltd. > */ > > #include > #include > +#include > #include > #include > #include > @@ -23,6 +24,7 @@ > #include > #include > #include > +#include > #include > > #include "common.h" > @@ -68,6 +70,21 @@ struct scmi_xfers_info { > spinlock_t xfer_lock; > }; > > +/** > + * struct scmi_protocol_instance - Describe an initialized protocol instance. > + * @proto: A reference to the protocol descriptor. > + * @gid: A reference for per-protocol devres management. > + * @users: A refcount to track effective users of this protocol. > + * > + * Each protocol is initialized independently once for each SCMI platform in > + * which is defined by DT and implemented by the SCMI server fw. > + */ > +struct scmi_protocol_instance { > + const struct scmi_protocol *proto; > + void *gid; > + refcount_t users; > +}; Why do you need a separate protocol_instance? Will there be two instances of the same protocol for a single scmi device/instance? Else everything that has been defined in this struct in this patch the following ones can be rolled into scmi_protocol struct, right ? > + > /** > * struct scmi_info - Structure representing a SCMI instance > * > @@ -80,6 +97,10 @@ struct scmi_xfers_info { > * @rx_minfo: Universal Receive Message management info > * @tx_idr: IDR object to map protocol id to Tx channel info pointer > * @rx_idr: IDR object to map protocol id to Rx channel info pointer > + * @protocols: IDR for protocols' instance descriptors initialized for > + * this SCMI instance: populated on protocol's first attempted > + * usage. > + * @protocols_mtx: A mutex to protect protocols instances initialization. > * @protocols_imp: List of protocols implemented, currently maximum of > * MAX_PROTOCOLS_IMP elements allocated by the base protocol > * @node: List head > @@ -94,6 +115,9 @@ struct scmi_info { > struct scmi_xfers_info rx_minfo; > struct idr tx_idr; > struct idr rx_idr; > + struct idr protocols; > + /* Ensure mutual exclusive access to protocols instance array */ > + struct mutex protocols_mtx; > u8 *protocols_imp; > struct list_head node; > int users; > @@ -519,6 +543,127 @@ int scmi_version_get(const struct scmi_handle *handle, u8 protocol, > return ret; > } > > +/** > + * scmi_get_protocol_instance - Protocol initialization helper. > + * @handle: A reference to the SCMI platform instance. > + * @protocol_id: The protocol being requested. > + * > + * In case the required protocol has never been requested before for this > + * instance, allocate and initialize all the needed structures while handling > + * resource allocation with a dedicated per-protocol devres subgroup. > + * > + * Return: A reference to an initialized protocol instance or error on failure. > + */ > +static struct scmi_protocol_instance * __must_check > +scmi_get_protocol_instance(struct scmi_handle *handle, u8 protocol_id) > +{ > + int ret = -ENOMEM; > + void *gid; > + struct scmi_protocol_instance *pi; > + struct scmi_info *info = handle_to_scmi_info(handle); > + > + mutex_lock(&info->protocols_mtx); > + pi = idr_find(&info->protocols, protocol_id); > + > + if (pi) { > + refcount_inc(&pi->users); > + } else { > + const struct scmi_protocol *proto; > + > + /* Fail if protocol not registered on bus */ > + proto = scmi_get_protocol(protocol_id); > + if (!proto) { > + ret = -ENODEV; > + goto out; > + } > + > + /* Protocol specific devres group */ > + gid = devres_open_group(handle->dev, NULL, GFP_KERNEL); > + if (!gid) > + goto out; > + > + pi = devm_kzalloc(handle->dev, sizeof(*pi), GFP_KERNEL); > + if (!pi) > + goto clean; > + > + pi->gid = gid; > + pi->proto = proto; > + refcount_set(&pi->users, 1); > + /* proto->init is assured NON NULL by scmi_protocol_register */ > + ret = pi->proto->init(handle); So init for a protocol will be called twice. Is this intentional ? Once during the device probe via scmi_dev_probe and scmi_protocol_init. And once via scmi_get_protocol_instance which gets called in get_ops apis defined and used in the later patches. > + if (ret) > + goto clean; > + > + ret = idr_alloc(&info->protocols, pi, > + protocol_id, protocol_id + 1, GFP_KERNEL); > + if (ret != protocol_id) > + goto clean; > + > + devres_close_group(handle->dev, pi->gid); > + dev_dbg(handle->dev, "Initialized protocol: 0x%X\n", > + protocol_id); > + } > + mutex_unlock(&info->protocols_mtx); > + > + return pi; > + > +clean: > + devres_release_group(handle->dev, gid); > +out: > + mutex_unlock(&info->protocols_mtx); > + return ERR_PTR(ret); > +} > + > +/** > + * scmi_acquire_protocol - Protocol acquire > + * @handle: A reference to the SCMI platform instance. > + * @protocol_id: The protocol being requested. > + * > + * Register a new user for the requested protocol on the specified SCMI > + * platform instance, possibly triggering its initialization on first user. > + * > + * Return: 0 if protocol was acquired successfully. > + */ > +int scmi_acquire_protocol(struct scmi_handle *handle, u8 protocol_id) > +{ > + return PTR_ERR_OR_ZERO(scmi_get_protocol_instance(handle, protocol_id)); > +} > + > +/** > + * scmi_release_protocol - Protocol de-initialization helper. > + * @handle: A reference to the SCMI platform instance. > + * @protocol_id: The protocol being requested. > + * > + * Remove one user for the specified protocol and triggers de-initialization > + * and resources de-allocation once the last user has gone. > + */ > +void scmi_release_protocol(struct scmi_handle *handle, u8 protocol_id) > +{ > + struct scmi_info *info = handle_to_scmi_info(handle); > + struct scmi_protocol_instance *pi; > + > + mutex_lock(&info->protocols_mtx); > + pi = idr_find(&info->protocols, protocol_id); > + if (WARN_ON(!pi)) > + goto out; > + > + if (refcount_dec_and_test(&pi->users)) { > + void *gid = pi->gid; > + > + if (pi->proto->deinit) > + pi->proto->deinit(handle); > + > + idr_remove(&info->protocols, protocol_id); > + > + devres_release_group(handle->dev, gid); > + dev_dbg(handle->dev, "De-Initialized protocol: 0x%X\n", > + protocol_id); > + } > + > +out: > + mutex_unlock(&info->protocols_mtx); > +} > + > void scmi_setup_protocol_implemented(const struct scmi_handle *handle, > u8 *prot_imp) > { > @@ -785,6 +930,8 @@ static int scmi_probe(struct platform_device *pdev) > info->dev = dev; > info->desc = desc; > INIT_LIST_HEAD(&info->node); > + idr_init(&info->protocols); > + mutex_init(&info->protocols_mtx); > > platform_set_drvdata(pdev, info); > idr_init(&info->tx_idr); > @@ -805,9 +952,14 @@ static int scmi_probe(struct platform_device *pdev) > if (scmi_notification_init(handle)) > dev_err(dev, "SCMI Notifications NOT available.\n"); > > - ret = scmi_base_protocol_init(handle); > + /* > + * Trigger SCMI Base protocol initialization. > + * It's mandatory and won't be ever released/deinit until the > + * SCMI stack is shutdown/unloaded as a whole. > + */ > + ret = scmi_acquire_protocol(handle, SCMI_PROTOCOL_BASE); > if (ret) { > - dev_err(dev, "unable to communicate with SCMI(%d)\n", ret); > + dev_err(dev, "unable to communicate with SCMI\n"); > return ret; > } > > @@ -859,6 +1011,10 @@ static int scmi_remove(struct platform_device *pdev) > if (ret) > return ret; > > + mutex_lock(&info->protocols_mtx); > + idr_destroy(&info->protocols); > + mutex_unlock(&info->protocols_mtx); > + > /* Safe to free channels since no more users */ > ret = idr_for_each(idr, info->desc->ops->chan_free, idr); > idr_destroy(&info->tx_idr); > @@ -941,6 +1097,8 @@ static int __init scmi_driver_init(void) > { > scmi_bus_init(); > > + scmi_base_register(); > + minor nit. extra line addeed ? -- Warm Regards Thara _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel