Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp748499rwl; Wed, 12 Apr 2023 03:40:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZtHNND+T4lrmyEPb9ClGe66jlUzXaa52D14rDXWPxY7Rv5EAofvAIuwAPHdSNZjbHjHVGK X-Received: by 2002:aa7:d30d:0:b0:504:92c0:1732 with SMTP id p13-20020aa7d30d000000b0050492c01732mr1908343edq.2.1681296026150; Wed, 12 Apr 2023 03:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681296026; cv=none; d=google.com; s=arc-20160816; b=Ca4DGmccur30u7ecoh7hbao0BrZdjbFgxacOdDoB97+HYmXYl9BKpD8u95zoaSELkd SAWxY59tw3NC3JxQpkvCGC0NOFEtfugvyqUOQz0adlSXYEE9NNnT03wMpzCmJW6MqTwh 7H5o2gy6fN8RBUBx6cU0k/yObTdVgXCB7XtMrVIGND/NAtEgVOleIEKz/9NH4PYhJQRL UVB97kmisjlD3uy90O38Gx20z+AKoIReCgYh4crMxUsEIOXiKaBkpYrpPQfCChLkK1SX Zdm3VeRzD+5JZty0RZVvvnp+12Uy2mP3Kue0cVtrbXqLGP2LMUOX79IbMRSbJZ/n7vho aSHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8KKbxB55hALm8ZgFIikpy1VFLRiwS+xilXlkMGdOVMs=; b=Pj70UkPThlsnWyvidEJGZUwPgPp+0Y/4az8tgECK+9aCywGZ/5m6NyNaB/ITIFXYDJ XNjM4CeZ9lQTKKOgU54pwv6NZNZyZrNb3Z6Jtz7C774n368B08slXhMeKo6hqeUfDdSs 2zEX+pws93x1UETx7tfeY/A6kHZLrVGHScqBP8QAYE45ilYyfa/9OZjN1lpm9g/elRgI MqYW+pP8s7NnVx++V11knxZ/Nn5ieCSxSNsDvdIqh2T/J5YdPUszQ7EWz+qU1r+bwIjW WybjNp+kpA+UJVbWsskjTGVb4debq+XXXVrHKdUCZ4GcKkCD9jWSoumF/qpIHqZzhnHO Q1vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=m0ri4kFe; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p19-20020aa7d313000000b00504b2f1acf5si31114edq.129.2023.04.12.03.40.01; Wed, 12 Apr 2023 03:40:26 -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=@ti.com header.s=ti-com-17Q1 header.b=m0ri4kFe; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbjDLKar (ORCPT + 99 others); Wed, 12 Apr 2023 06:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230359AbjDLKa3 (ORCPT ); Wed, 12 Apr 2023 06:30:29 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D7A32719; Wed, 12 Apr 2023 03:30:27 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 33CAUJQc067196; Wed, 12 Apr 2023 05:30:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1681295420; bh=8KKbxB55hALm8ZgFIikpy1VFLRiwS+xilXlkMGdOVMs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=m0ri4kFewB67BiSvW4WjaZRbBQlDMNum4BmvugmBgowgYoLIWfilgAgtMyY5CD+v2 AJQ6WaYEoeIkfEiZNocx8VaAjvE4tmgzl25BAFkYkz8jb4Gi6wHxmfnOZwv6rS6PZ7 Bv4jWeXhiIzNi0AOb1Wrl4BBbUr8AjK2X+9TLUiM= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 33CAUJkW088135 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Apr 2023 05:30:19 -0500 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Wed, 12 Apr 2023 05:30:19 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Wed, 12 Apr 2023 05:30:19 -0500 Received: from fllv0122.itg.ti.com (fllv0122.itg.ti.com [10.247.120.72]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 33CAUJtG094074; Wed, 12 Apr 2023 05:30:19 -0500 Received: from localhost (uda0501179.dhcp.ti.com [10.24.69.114]) by fllv0122.itg.ti.com (8.14.7/8.14.7) with ESMTP id 33CAUIcb028935; Wed, 12 Apr 2023 05:30:19 -0500 From: MD Danish Anwar To: "Andrew F. Davis" , Suman Anna , Roger Quadros , Vignesh Raghavendra , Tero Kristo , MD Danish Anwar , Mathieu Poirier , Bjorn Andersson , Santosh Shilimkar , Nishanth Menon CC: , , , , , , Subject: [PATCH v8 2/4] soc: ti: pruss: Add pruss_{request,release}_mem_region() API Date: Wed, 12 Apr 2023 16:00:10 +0530 Message-ID: <20230412103012.1754161-3-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412103012.1754161-1-danishanwar@ti.com> References: <20230412103012.1754161-1-danishanwar@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,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 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(+) 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