Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5863559rwl; Tue, 11 Apr 2023 11:01:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bRnlS58b1+XinsDqvQmB66+Rs0OPOtWjt1HiPox4B/ppt2jpMJgM5wC4yO63NWKJ5ku7nW X-Received: by 2002:a17:902:c402:b0:1a2:7462:d674 with SMTP id k2-20020a170902c40200b001a27462d674mr27348236plk.24.1681236091794; Tue, 11 Apr 2023 11:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681236091; cv=none; d=google.com; s=arc-20160816; b=FKvZ4DWKI5mImKOSoftG3/Zl9SFab1k7qaAoe7RKFbWXdhZRcom7TzxKtCpT3ldJ+B AgQ6Gi7pm6KtQD4hsPnxxSg6z4YSmerpiyuIj9nMoiOHad9z+A779xHM6TFCdjRzGFwl 3yRFflMfWTB2l0/qEAtakdmbrGMQgw2ToBI/w0FzsOQZCCnwBerHhfkunuiv6F4dw6f+ Fhfwvt6TXscZ5y1z+ZpJC8a+Ev/edEJAKU2H/vOtaNFS6v2JVtAnGM0SJ9Wah7kgIC4G nylxGx8+zsKYbVo4rx6EOAA+vo5CnNhZh+sh3HgOoUarJirNWpKa6HT4VktkBG2OmlNk ukYw== 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=Qbuj7VpjZ04yn+wg2bJaslUI/L4vbCkU/bi684VY7gU=; b=BF+P3u5zpQTLJnw7kWLm9FIWPr8sH4qQH4j6dFuWSvK5PNaswwgFQRjA9IauSUEfwA gmBRpX8w4H5X9PDX73RVdFH07Xdfnw+TTm82iVkz9SDJ5lr46DQyakeuMkwfY572bWoc aMxU+ySsc8W0xeB8fA8bpFIaPkkelGbuIjX9EhLRVnMesvlpa7S8EDxuwdEyIiClNrRQ yYn1E+0u7s7CViOBu/+AZs4uqBWcSwLCxCkDff8A1gWk6xsydgzwKc8aSbboQeOhPxCO S+2+wIXrplJdTcMcoiJyeg+CmBbEoqf1oLpCQ6px56JeBgwVnrm5WbOZzqRdHElmvJF+ MMww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rGqy3gXE; 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 q71-20020a632a4a000000b0051b25ff72a9si717132pgq.889.2023.04.11.11.01.19; Tue, 11 Apr 2023 11:01:31 -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=rGqy3gXE; 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 S230012AbjDKRvs (ORCPT + 99 others); Tue, 11 Apr 2023 13:51:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbjDKRvq (ORCPT ); Tue, 11 Apr 2023 13:51:46 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CE5B6A64 for ; Tue, 11 Apr 2023 10:51:41 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-635df3bd6e9so3518571b3a.1 for ; Tue, 11 Apr 2023 10:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681235501; 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=Qbuj7VpjZ04yn+wg2bJaslUI/L4vbCkU/bi684VY7gU=; b=rGqy3gXENEdQs9vwdi5+0tC3AYSczqHIF80RMZjqiYEC8liJHBMqz38foZT4QOZJHf 2BEiKR+utiGB6SNIy6QKcFABt+CjNDhFonLiW1GEKifNs6KbEhLK6JWn31aUy4f3Wo+D QMb2xGdP6Dp1s7JEKq1KNQK6mqlh9kA+DwQ8hv3wnqjGQOdJZ3lcOwmQL/R2eTNJPIx0 BlSKSjOV1coNnS5G1X/RQy1xv5DeH1pkC1fKohcn8IyExr2IRswySVeMImOJDLCUhuHv KU2K9SCdluLLdPipsRNPlljEcsGuKcbaQiUN7iFtd89VoQbxmejkjCcyXpnzEi4VwbtB PqmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681235501; 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=Qbuj7VpjZ04yn+wg2bJaslUI/L4vbCkU/bi684VY7gU=; b=O7U1NPY2sLYGYRe6N/R+w2MJUnagOcV1onRfCsamc6G/d1WetSAMJCmYEHwS1kGGMr B46hlYaraW0u9OrkIxd/iCjxLvry75PieMvpR42TOB5kGW9j7tLowzVgb+qDAn8EHCcD ku9xrAT2ApcrTBrwSVDT51UXB4foJjEeaY5v21Wu1emOdUbsN1OuC+YTGgpLxBTpWg6P 0AoCbo1pXTdIvmoX1pE1AcYPvG/VIrkYIGJ4X3mQt7Z89R3dY7GHvjylPVrMBIQz3cRC +dDH837MztObw8y/X3i+/jqMV6t9ZQoo/HhloUmRQehV1q1Wl+klri+tOlDzLWdmZQr+ zURw== X-Gm-Message-State: AAQBX9e+3Inj0dJQveMLKAo1v+ktldtAVnwhAICUtPdMyLPzgLOES7Is FCWA6oUaSPgfc+R4U8+42x4V6A== X-Received: by 2002:a62:ab14:0:b0:625:524b:9712 with SMTP id p20-20020a62ab14000000b00625524b9712mr41711pff.2.1681235500775; Tue, 11 Apr 2023 10:51:40 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:f795:eecb:467b:d183]) by smtp.gmail.com with ESMTPSA id s21-20020a056a00195500b006243e706195sm10084448pfk.196.2023.04.11.10.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:51:40 -0700 (PDT) Date: Tue, 11 Apr 2023 11:51:37 -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 v7 2/4] soc: ti: pruss: Add pruss_{request,release}_mem_region() API Message-ID: <20230411175137.GC38361@p14s> References: <20230404115336.599430-1-danishanwar@ti.com> <20230404115336.599430-3-danishanwar@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230404115336.599430-3-danishanwar@ti.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Tue, Apr 04, 2023 at 05:23:34PM +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 > Signed-off-by: MD Danish Anwar > --- > drivers/soc/ti/pruss.c | 77 ++++++++++++++++++++++++++++++++ > include/linux/pruss_internal.h | 27 +++-------- > include/linux/remoteproc/pruss.h | 39 ++++++++++++++++ > 3 files changed, 121 insertions(+), 22 deletions(-) > > diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c > index 28b77d715903..7aa0f7171af1 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); > + These stay here. > 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_internal.h b/include/linux/pruss_internal.h > index 8f91cb164054..cf5287fa01df 100644 > --- a/include/linux/pruss_internal.h > +++ b/include/linux/pruss_internal.h > @@ -9,37 +9,18 @@ > #ifndef _PRUSS_INTERNAL_H_ > #define _PRUSS_INTERNAL_H_ > > +#include > #include > #include > > -/* > - * enum pruss_mem - PRUSS memory range identifiers > - */ > -enum pruss_mem { > - PRUSS_MEM_DRAM0 = 0, > - PRUSS_MEM_DRAM1, > - PRUSS_MEM_SHRD_RAM2, > - PRUSS_MEM_MAX, > -}; > - > -/** > - * struct pruss_mem_region - PRUSS memory region structure > - * @va: kernel virtual address of the PRUSS memory region > - * @pa: physical (bus) address of the PRUSS memory region > - * @size: size of the PRUSS memory region > - */ > -struct pruss_mem_region { > - void __iomem *va; > - phys_addr_t pa; > - size_t size; > -}; > - These stay here. > /** > * struct pruss - PRUSS parent structure > * @dev: pruss device pointer > * @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 > */ > @@ -48,6 +29,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; > }; > diff --git a/include/linux/remoteproc/pruss.h b/include/linux/remoteproc/pruss.h > index 93a98cac7829..33f930e0a0ce 100644 > --- a/include/linux/remoteproc/pruss.h > +++ b/include/linux/remoteproc/pruss.h > @@ -44,6 +44,28 @@ enum pru_ctable_idx { > PRU_C31, > }; > > +/* > + * enum pruss_mem - PRUSS memory range identifiers > + */ > +enum pruss_mem { > + PRUSS_MEM_DRAM0 = 0, > + PRUSS_MEM_DRAM1, > + PRUSS_MEM_SHRD_RAM2, > + PRUSS_MEM_MAX, > +}; > + > +/** > + * struct pruss_mem_region - PRUSS memory region structure > + * @va: kernel virtual address of the PRUSS memory region > + * @pa: physical (bus) address of the PRUSS memory region > + * @size: size of the PRUSS memory region > + */ > +struct pruss_mem_region { > + void __iomem *va; > + phys_addr_t pa; > + size_t size; > +}; > + > struct device_node; > struct rproc; > struct pruss; > @@ -52,6 +74,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 > > @@ -62,6 +88,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; > +} > + These go in pruss_driver.h > #endif /* CONFIG_TI_PRUSS */ > > #if IS_ENABLED(CONFIG_PRU_REMOTEPROC) > -- > 2.25.1 >