Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3430063rwl; Mon, 27 Mar 2023 14:03:32 -0700 (PDT) X-Google-Smtp-Source: AKy350YAA1TtLD+zXfsxB07xLENYJRnjvTG6oN1GkRV4oDzgv6iobrPP+X2zTIfeXOr1UwO1d40S X-Received: by 2002:a62:1c4e:0:b0:626:2984:8a76 with SMTP id c75-20020a621c4e000000b0062629848a76mr12047974pfc.34.1679951012517; Mon, 27 Mar 2023 14:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679951012; cv=none; d=google.com; s=arc-20160816; b=0RLBG0zBzGZJqYHh5vn9wNDKFs1s0Nqrw+Bxa+D2HRp2NeRMAvlMAVJWPCdZADXPBx DarPeUTBPcPPmBZcPfZQCtz8NcF/7wZaixWSbsFpnkSHTJAa8JYco2iv2s5wwpdUaWpq KybiSuV/iXX6R9sKSBqAzt/AycLt1BMPxjquiImniWDxKUZ9eCcjlDi1WOGQHADw3FZE y1tvol/Y+9ziQTOJ0KsOifzGPgopyzU9GxtNOe0CXtyHxegKEYjdxYUht23nA6KL5DsX +piUVXvTmpK3mPTp1lkJ1jWfxSpDlHI7eY8CoQHVe7F8leIqvb+wHZV/ZK4l8lsForIh VYYw== 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=uG/5wcDW+jLGbvb1fCE7bHB6/XtxbvifgcwRAVEJYi4=; b=mxE30dnfcnOIcnPQdFgduT58AqyA2OXF3FdZ3Gz/NmBQEn9TzAAjlezKck+/3oygQi s3xrv09+hs1kKhJ5CwITnGSHY8Beur5A2sRVx2x29bLbf/319Z7WVYtRrVaB1kmbf9rc ZEth/obAJa82E0hojqVue40rcxrUXoPdC32VNtpEK2BMtBQ7sCWpLLF/wemjMV8NDmh5 NawnZySO17SDug4iPJmxBIf/btadZmsGPD228dbrBLkzwvlF4auM7O2GxzQKFQULt5Gk 2A1yeGSygvpH7Pp9WaA11pZr/MMpgTkjxtkrzlz5nbQx987dPG1d06odUKc2i6aTSZlo YNtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ycBvad2D; 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 o17-20020a056a00215100b00627f017391csi21661244pfk.273.2023.03.27.14.03.20; Mon, 27 Mar 2023 14:03:32 -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=ycBvad2D; 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 S230138AbjC0U74 (ORCPT + 99 others); Mon, 27 Mar 2023 16:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjC0U7y (ORCPT ); Mon, 27 Mar 2023 16:59:54 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C28191FC7 for ; Mon, 27 Mar 2023 13:59:52 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id om3-20020a17090b3a8300b0023efab0e3bfso13097264pjb.3 for ; Mon, 27 Mar 2023 13:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679950792; 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=uG/5wcDW+jLGbvb1fCE7bHB6/XtxbvifgcwRAVEJYi4=; b=ycBvad2Dx5zKzGBEIS1WZwXbjxoyNagbqYrk/KL+Jd+Fr/juDTLbx3Pc9XN905n7gI VQBVHRjY3sy1rPMuQ/QytvclS20looFDbLGenJdg/B4yENyay1oASx0Zd1Ee3B2CwwWW 4WkcLDmd7x3A0pNyGSOSbpEcgAi5bPH/SKQAbz4EfWG+6DSQ071QiqceOU5HJXTkqYFT 5Vkgi8ZRUm4LhhllfBMyx7Mwr4SggPgZA7GUi4YQSKOpCA6KiDSa/udL87uMUx4kAwvc TtmU1ASAbMDoCWhwvgsEl1Gg7arAc0v1XVguqjH42xlYLLdvtRdjbDqf6gLjt7pKACoQ LmGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679950792; 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=uG/5wcDW+jLGbvb1fCE7bHB6/XtxbvifgcwRAVEJYi4=; b=lg+iUlqDLinAupppW77hkY/0W5IVPADhqPldoydnOOrlWuwZwgrpjEPNUgIo9mE1nB ZMaEIiQzqrKCLcn/8dJLL6bm1owHffSD8K9cZ6jQMVthNv50MIEnGC8u+JynDKooLhmf wZeIVNi6rKGjTzBzA+tONy1fh5QZCPeYk4mwOVgveu1YEXrHnpL0kILWaXUwIDpB2HKF 69l1XwF1LLXJPDdKC60Mx6z2L2wLHhGVfyFug93yssfWNCXRdSZ9IsCt9qDlkdOW5+eP 8P2kB3MX4EEsWeasiWmb1dfuHQ/gRNOSVU9n2lBnY6T5G1pyXg+MxCDkeYitQsqOklHV x6pA== X-Gm-Message-State: AO0yUKWN1JeBdAoS2X2B0pKrHWLAxpgqU04Cdi5xjiLHQgiTqIT82Ja4 zxFOs8O2wGii1987fzbkjFlluA== X-Received: by 2002:a05:6a20:ba83:b0:db:b960:d319 with SMTP id fb3-20020a056a20ba8300b000dbb960d319mr12660514pzb.12.1679950792228; Mon, 27 Mar 2023 13:59:52 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:ad52:968f:ad4a:52d2]) by smtp.gmail.com with ESMTPSA id c26-20020aa781da000000b0062d7fa4b618sm2778708pfn.175.2023.03.27.13.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 13:59:51 -0700 (PDT) Date: Mon, 27 Mar 2023 14:59:49 -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 v5 2/5] soc: ti: pruss: Add pruss_{request,release}_mem_region() API Message-ID: <20230327205949.GB3158115@p14s> References: <20230323062451.2925996-1-danishanwar@ti.com> <20230323062451.2925996-3-danishanwar@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230323062451.2925996-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 Thu, Mar 23, 2023 at 11:54:48AM +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 > Signed-off-by: MD Danish Anwar > Reviewed-by: Roger Quadros Acked-by: Mathieu Poirier > --- > 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 6c2bb02a521d..126b672b9b30 100644 > --- a/drivers/soc/ti/pruss.c > +++ b/drivers/soc/ti/pruss.c > @@ -88,6 +88,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; > @@ -290,6 +366,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; > -}; > - > /** > * 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; > +} > + > #endif /* CONFIG_TI_PRUSS */ > > #if IS_ENABLED(CONFIG_PRU_REMOTEPROC) > -- > 2.25.1 >