Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1262944rwl; Wed, 12 Apr 2023 10:12:20 -0700 (PDT) X-Google-Smtp-Source: AKy350bmrhYuKJnwwm12aAYeN21A07rma/Yy016irUdmr71wO5KDztplVb70Qw6CSh6mm9zmU0lH X-Received: by 2002:a17:906:4fc8:b0:94a:8b35:f15d with SMTP id i8-20020a1709064fc800b0094a8b35f15dmr3284948ejw.45.1681319540420; Wed, 12 Apr 2023 10:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319540; cv=none; d=google.com; s=arc-20160816; b=v8sZ+S5hO1Zj1TD0QmuvXgWgSSryx9bBZyLr6grChaOix1xOJH3zv2//6yW/AE57hz qUCgXrvey5IOfGYytPGZ1CDlVZsCZ+lRx52URpf2uj/AMLtBdcMBEX6bOKckojUwXvnS Pc45b/fS7fpGGtG4Fh4KgYP4SA6d5puoo3IeJDrk3hY5lRAQqgNVPLoraiSjWPGliyZ+ yjH1qt4pCgIbvXVJO+zP+vs+mLFe8rlgaMxqGkZY1xw3f03xgAUarSaRViOQv6d5er7v rlJJyDSgIViaztIKpjnMtInVkuUtZ84J6FViQwAOW3oHq8TU2O+sWdDeHJqqQOciI2jj A5Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pfUsMfkrejVXr5qJizoytRX5TpIEEU2cEnidL9qtDPI=; b=l5aNWgrrtzjclbqIO08ksViBiWPU31/xtcVYlQczDU/TVZ7uZUgS2OTyRyZzAWJ0wn VMNEhzQj+2sFn3qnpFb+YsysmfwZI0AMm0SoMfkYX5swnICg5A6rc3RIT328lWRmYX2L fknnNhZpb8WXOAiXPwkwL+pD2fRJ2nXxu2BfZX6B/wvp3NKOUx047CEdL34pl9qAdhWw iaZsaHaxHULPHuY2eTjhl1wMbCLJGko5zVVptyR2xn2EYqiwnqB2s+gohKDFCUiCj67f 0jaNu1109OWdhiy6QeqbOyEo2aEPZZ+xK0vKZVPvahqkVSs/r23U4HL2Wcp75DwlrHsw BIpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wYiC7zU0; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a17090617c400b009331f6583a1si13680807eje.514.2023.04.12.10.11.41; Wed, 12 Apr 2023 10:12:20 -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=@linaro.org header.s=google header.b=wYiC7zU0; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230487AbjDLRBs (ORCPT + 99 others); Wed, 12 Apr 2023 13:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbjDLRBd (ORCPT ); Wed, 12 Apr 2023 13:01:33 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07DB94206 for ; Wed, 12 Apr 2023 10:01:14 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id f2so3654481pjs.3 for ; Wed, 12 Apr 2023 10:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681318872; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pfUsMfkrejVXr5qJizoytRX5TpIEEU2cEnidL9qtDPI=; b=wYiC7zU09HzT5NwU6kVUFeXU5eGu/ear7WFELkED0oHU9+asu/YX8c1hxHuOwY/5Yt r/ADbqytIgvlGPpgtJdPDa68WehaZFMZimJjpGObFMQrIt+3x7S4yPNH4b9q/z54xyne o7mu2G/EZHJsTfs2zimGZccO1A31Kum5g18LB3viozu0AmZiNqI4VRaCqgG1eLeTyBt7 OQdC12oBUak1lSXsvUOZMIRIyzBoqIwNxqC+8+cYhNv2r6PzkvzHY2lhVy45vvjuZ/K+ g6b8t48tnMa4Gc0Ztj/TllWL+3PtpB53HArPqnMtE2BxLgD9jPBEvfWRkcHHS6qEVEYC 545w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681318872; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pfUsMfkrejVXr5qJizoytRX5TpIEEU2cEnidL9qtDPI=; b=hMYnb1cHOB5BOXaSo5gnCISZG76C+siPEwCGT0Kfwiz6ufjmkNSPm4pnrbwg/TKurC mVEmj9c9TeRb+J7V5HciAoHQF0dGPoIAjdYhWw+J6zQZSJMX2MaAg7Vo6pGJbHAsnuw+ 8wfnNeBqGmIloQPdq8E5j3N0+p2VnC5wgweuGQSYDvKIZ1HHmEQBJEqwfEp/dL8WjIIq MqKNi/UjroeVY0NOlszSeA+9NDyMUNoPuHMiWPBqQ/FKUoYVVC5AyBWzwbliU7KPuwtL hBIIQITfb8nL1EvIUux6C47fREePDxjOVwvsEvHrm8kujcHQP4j0XdoJdSs1eHLfXAES ef2g== X-Gm-Message-State: AAQBX9cpqefjAhCOSyoXC/b80aqFB1P0N8hm0MaSOKnEMTjQ1xafP2rc BsnP6eZaNcY1hTX6Gb7juF5l06lfaGdOiGBxGoM= X-Received: by 2002:a17:902:e749:b0:1a6:61b5:9e78 with SMTP id p9-20020a170902e74900b001a661b59e78mr5729967plf.20.1681318872311; Wed, 12 Apr 2023 10:01:12 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:1cd7:1135:5e45:5f77]) by smtp.gmail.com with ESMTPSA id p6-20020a1709026b8600b001a04ff0e2eesm11749209plk.58.2023.04.12.10.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 10:01:11 -0700 (PDT) Date: Wed, 12 Apr 2023 11:01:09 -0600 From: Mathieu Poirier To: MD Danish Anwar Cc: "Andrew F. Davis" , Suman Anna , Roger Quadros , Vignesh Raghavendra , Tero Kristo , Bjorn Andersson , Santosh Shilimkar , Nishanth Menon , linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, srk@ti.com, devicetree@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v8 2/4] soc: ti: pruss: Add pruss_{request,release}_mem_region() API Message-ID: <20230412170109.GB86761@p14s> References: <20230412103012.1754161-1-danishanwar@ti.com> <20230412103012.1754161-3-danishanwar@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230412103012.1754161-3-danishanwar@ti.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Wed, Apr 12, 2023 at 04:00:10PM +0530, MD Danish Anwar wrote: > From: "Andrew F. Davis" > > Add two new API - pruss_request_mem_region() & pruss_release_mem_region(), > to the PRUSS platform driver to allow client drivers to acquire and release > the common memory resources present within a PRU-ICSS subsystem. This > allows the client drivers to directly manipulate the respective memories, > as per their design contract with the associated firmware. > > Co-developed-by: Suman Anna > Signed-off-by: Suman Anna > Signed-off-by: Andrew F. Davis > Co-developed-by: Grzegorz Jaszczyk > Signed-off-by: Grzegorz Jaszczyk > Reviewed-by: Roger Quadros > Acked-by: Mathieu Poirier > Reviewed-by: Tony Lindgren > Reviewed-by: Simon Horman > Signed-off-by: MD Danish Anwar > --- > drivers/soc/ti/pruss.c | 77 ++++++++++++++++++++++++++++++++++++ > include/linux/pruss_driver.h | 22 +++++++++++ > 2 files changed, 99 insertions(+) > Acked-by: Mathieu Poirier > diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c > index 3fac92df8790..8ada3758b31a 100644 > --- a/drivers/soc/ti/pruss.c > +++ b/drivers/soc/ti/pruss.c > @@ -92,6 +92,82 @@ void pruss_put(struct pruss *pruss) > } > EXPORT_SYMBOL_GPL(pruss_put); > > +/** > + * pruss_request_mem_region() - request a memory resource > + * @pruss: the pruss instance > + * @mem_id: the memory resource id > + * @region: pointer to memory region structure to be filled in > + * > + * This function allows a client driver to request a memory resource, > + * and if successful, will let the client driver own the particular > + * memory region until released using the pruss_release_mem_region() > + * API. > + * > + * Return: 0 if requested memory region is available (in such case pointer to > + * memory region is returned via @region), an error otherwise > + */ > +int pruss_request_mem_region(struct pruss *pruss, enum pruss_mem mem_id, > + struct pruss_mem_region *region) > +{ > + if (!pruss || !region || mem_id >= PRUSS_MEM_MAX) > + return -EINVAL; > + > + mutex_lock(&pruss->lock); > + > + if (pruss->mem_in_use[mem_id]) { > + mutex_unlock(&pruss->lock); > + return -EBUSY; > + } > + > + *region = pruss->mem_regions[mem_id]; > + pruss->mem_in_use[mem_id] = region; > + > + mutex_unlock(&pruss->lock); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(pruss_request_mem_region); > + > +/** > + * pruss_release_mem_region() - release a memory resource > + * @pruss: the pruss instance > + * @region: the memory region to release > + * > + * This function is the complimentary function to > + * pruss_request_mem_region(), and allows the client drivers to > + * release back a memory resource. > + * > + * Return: 0 on success, an error code otherwise > + */ > +int pruss_release_mem_region(struct pruss *pruss, > + struct pruss_mem_region *region) > +{ > + int id; > + > + if (!pruss || !region) > + return -EINVAL; > + > + mutex_lock(&pruss->lock); > + > + /* find out the memory region being released */ > + for (id = 0; id < PRUSS_MEM_MAX; id++) { > + if (pruss->mem_in_use[id] == region) > + break; > + } > + > + if (id == PRUSS_MEM_MAX) { > + mutex_unlock(&pruss->lock); > + return -EINVAL; > + } > + > + pruss->mem_in_use[id] = NULL; > + > + mutex_unlock(&pruss->lock); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(pruss_release_mem_region); > + > static void pruss_of_free_clk_provider(void *data) > { > struct device_node *clk_mux_np = data; > @@ -294,6 +370,7 @@ static int pruss_probe(struct platform_device *pdev) > return -ENOMEM; > > pruss->dev = dev; > + mutex_init(&pruss->lock); > > child = of_get_child_by_name(np, "memories"); > if (!child) { > diff --git a/include/linux/pruss_driver.h b/include/linux/pruss_driver.h > index cb40c2b31045..c8f2e53b911b 100644 > --- a/include/linux/pruss_driver.h > +++ b/include/linux/pruss_driver.h > @@ -9,6 +9,7 @@ > #ifndef _PRUSS_DRIVER_H_ > #define _PRUSS_DRIVER_H_ > > +#include > #include > #include > #include > @@ -41,6 +42,8 @@ struct pruss_mem_region { > * @cfg_base: base iomap for CFG region > * @cfg_regmap: regmap for config region > * @mem_regions: data for each of the PRUSS memory regions > + * @mem_in_use: to indicate if memory resource is in use > + * @lock: mutex to serialize access to resources > * @core_clk_mux: clk handle for PRUSS CORE_CLK_MUX > * @iep_clk_mux: clk handle for PRUSS IEP_CLK_MUX > */ > @@ -49,6 +52,8 @@ struct pruss { > void __iomem *cfg_base; > struct regmap *cfg_regmap; > struct pruss_mem_region mem_regions[PRUSS_MEM_MAX]; > + struct pruss_mem_region *mem_in_use[PRUSS_MEM_MAX]; > + struct mutex lock; /* PRU resource lock */ > struct clk *core_clk_mux; > struct clk *iep_clk_mux; > }; > @@ -57,6 +62,10 @@ struct pruss { > > struct pruss *pruss_get(struct rproc *rproc); > void pruss_put(struct pruss *pruss); > +int pruss_request_mem_region(struct pruss *pruss, enum pruss_mem mem_id, > + struct pruss_mem_region *region); > +int pruss_release_mem_region(struct pruss *pruss, > + struct pruss_mem_region *region); > > #else > > @@ -67,6 +76,19 @@ static inline struct pruss *pruss_get(struct rproc *rproc) > > static inline void pruss_put(struct pruss *pruss) { } > > +static inline int pruss_request_mem_region(struct pruss *pruss, > + enum pruss_mem mem_id, > + struct pruss_mem_region *region) > +{ > + return -EOPNOTSUPP; > +} > + > +static inline int pruss_release_mem_region(struct pruss *pruss, > + struct pruss_mem_region *region) > +{ > + return -EOPNOTSUPP; > +} > + > #endif /* CONFIG_TI_PRUSS */ > > #endif /* _PRUSS_DRIVER_H_ */ > -- > 2.34.1 >