Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp46246rwe; Thu, 13 Apr 2023 21:56:58 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9vaYO6q7WDvp78CkEzDa1tKWhxY3L+Qbz1YxtQcK+gv+PKleIyzmrEW34Qb09JNXkx0px X-Received: by 2002:a05:6a20:3b24:b0:cb:f76c:ceda with SMTP id c36-20020a056a203b2400b000cbf76ccedamr4495882pzh.22.1681448218176; Thu, 13 Apr 2023 21:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681448218; cv=none; d=google.com; s=arc-20160816; b=icFAGQBNuKTE09onxeGNO1a5kfJ9bxiXPbW6S4N6PLY7xugbFd4YXQYY6oBo5Zptzc ztImiUV6O0BLB5lR5lxlDzxZFxOV9JJoiqGP/Awp98TbD1TTVfVXHsFc+UPFtWAgUUug N/nDEYBgvbu1E6S0LhBTHhvdNNIN0kA5SV58dGn7WpER4/Nu4K0UcDW+w+x07MtdPx8A 1SN79EGqDZYo1q2LHNOoa3RJmw6R/a0us/9Llmqrb1hiiF9jE6to9ICRrCi2pHZ0dper WnyVy7EKz3TEXtdgbRZO/MKwWt3JXhcTQ0VEm21vxHTYTlsOSaSDSde6QNwwnW3RR73o sJ/w== 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=lPo8Hv7mVbjRd4dZidWJ03ImB0sPWQlM8BJ1VFM/Ox4=; b=eQlkXnNzO5hdppmZmXKZ7FPy0a2VSX+Fp7uCJKKdIYYY8WRT31AjKP6vl89K4uJwmx +AlVDJvXNQzRUVrsMBBQ7xHR2s4WywFhIU7yw9VNdud5b/72bnlP1wV9be8MsHg3EDfG QN+MN0jtS0p3BCo90Afho2za6p9oe4wjwwIgzUDpsxsJjhQYjsxaPWruRjtBWM3qk38t w72B0WMrqPuR8xGFWR5gF/mdeixnJsOoPtM3dMdpxlrmAlH2KeDw+kSQl8JjE3CPMYZw ZaJtQZpagJKXRXn43vM8smhri/dlpEsFgRCWkPJfRF4LJjExxF8xRZ/X5InPiRHFt2Ds 1AdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Ju7HwVvw; 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 z11-20020aa79f8b000000b005a7ea9c6d7csi3523975pfr.41.2023.04.13.21.56.46; Thu, 13 Apr 2023 21:56:58 -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=Ju7HwVvw; 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 S229762AbjDNE4I (ORCPT + 99 others); Fri, 14 Apr 2023 00:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjDNE4E (ORCPT ); Fri, 14 Apr 2023 00:56:04 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B281E44A8; Thu, 13 Apr 2023 21:56:02 -0700 (PDT) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 33E4tvaS071665; Thu, 13 Apr 2023 23:55:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1681448157; bh=lPo8Hv7mVbjRd4dZidWJ03ImB0sPWQlM8BJ1VFM/Ox4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Ju7HwVvwIN8fgXrW59YHOMQftuvXyxnKe28wvdVJ8BA6YsNswzVvCVsfh8LUJ2mdK S4+9BGPQXtHdKw+RBeRH5HDbtx38QJUKVBfrxx8c3GO6DkAnPz5EBzIsUeSsigZntn eTLhoMbn3ydo/h3dyCPCS2cZgIT3yiMy1Q6P7qXA= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 33E4tv5A103589 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 13 Apr 2023 23:55:57 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Thu, 13 Apr 2023 23:55:56 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE105.ent.ti.com (10.64.6.26) 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; Thu, 13 Apr 2023 23:55:56 -0500 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 33E4tuCo119897; Thu, 13 Apr 2023 23:55:56 -0500 Received: from localhost (uda0501179.dhcp.ti.com [10.24.69.114]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 33E4tt3m017959; Thu, 13 Apr 2023 23:55:56 -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 v9 1/4] soc: ti: pruss: Add pruss_get()/put() API Date: Fri, 14 Apr 2023 10:25:39 +0530 Message-ID: <20230414045542.3249939-2-danishanwar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414045542.3249939-1-danishanwar@ti.com> References: <20230414045542.3249939-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 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: Tero Kristo Add two new get and put API, pruss_get() and pruss_put() to the PRUSS platform driver to allow client drivers to request a handle to a PRUSS device. This handle will be used by client drivers to request various operations of the PRUSS platform driver through additional API that will be added in the following patches. The pruss_get() function returns the pruss handle corresponding to a PRUSS device referenced by a PRU remoteproc instance. The pruss_put() is the complimentary function to pruss_get(). Co-developed-by: Suman Anna Signed-off-by: Suman Anna Signed-off-by: Tero Kristo Co-developed-by: Grzegorz Jaszczyk Signed-off-by: Grzegorz Jaszczyk Signed-off-by: Puranjay Mohan Reviewed-by: Roger Quadros Reviewed-by: Tony Lindgren Reviewed-by: Simon Horman Acked-by: Mathieu Poirier Signed-off-by: MD Danish Anwar --- drivers/soc/ti/pruss.c | 62 ++++++++++++++++++++++++++++++++++++ include/linux/pruss_driver.h | 18 +++++++++++ 2 files changed, 80 insertions(+) diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c index 6882c86b3ce5..3fac92df8790 100644 --- a/drivers/soc/ti/pruss.c +++ b/drivers/soc/ti/pruss.c @@ -6,6 +6,7 @@ * Author(s): * Suman Anna * Andrew F. Davis + * Tero Kristo */ #include @@ -18,6 +19,7 @@ #include #include #include +#include #include /** @@ -30,6 +32,66 @@ struct pruss_private_data { bool has_core_mux_clock; }; +/** + * pruss_get() - get the pruss for a given PRU remoteproc + * @rproc: remoteproc handle of a PRU instance + * + * Finds the parent pruss device for a PRU given the @rproc handle of the + * PRU remote processor. This function increments the pruss device's refcount, + * so always use pruss_put() to decrement it back once pruss isn't needed + * anymore. + * + * This API doesn't check if @rproc is valid or not. It is expected the caller + * will have done a pru_rproc_get() on @rproc, before calling this API to make + * sure that @rproc is valid. + * + * Return: pruss handle on success, and an ERR_PTR on failure using one + * of the following error values + * -EINVAL if invalid parameter + * -ENODEV if PRU device or PRUSS device is not found + */ +struct pruss *pruss_get(struct rproc *rproc) +{ + struct pruss *pruss; + struct device *dev; + struct platform_device *ppdev; + + if (IS_ERR_OR_NULL(rproc)) + return ERR_PTR(-EINVAL); + + dev = &rproc->dev; + + /* make sure it is PRU rproc */ + if (!dev->parent || !is_pru_rproc(dev->parent)) + return ERR_PTR(-ENODEV); + + ppdev = to_platform_device(dev->parent->parent); + pruss = platform_get_drvdata(ppdev); + if (!pruss) + return ERR_PTR(-ENODEV); + + get_device(pruss->dev); + + return pruss; +} +EXPORT_SYMBOL_GPL(pruss_get); + +/** + * pruss_put() - decrement pruss device's usecount + * @pruss: pruss handle + * + * Complimentary function for pruss_get(). Needs to be called + * after the PRUSS is used, and only if the pruss_get() succeeds. + */ +void pruss_put(struct pruss *pruss) +{ + if (IS_ERR_OR_NULL(pruss)) + return; + + put_device(pruss->dev); +} +EXPORT_SYMBOL_GPL(pruss_put); + static void pruss_of_free_clk_provider(void *data) { struct device_node *clk_mux_np = data; diff --git a/include/linux/pruss_driver.h b/include/linux/pruss_driver.h index ecfded30ed05..cb40c2b31045 100644 --- a/include/linux/pruss_driver.h +++ b/include/linux/pruss_driver.h @@ -9,7 +9,9 @@ #ifndef _PRUSS_DRIVER_H_ #define _PRUSS_DRIVER_H_ +#include #include +#include /* * enum pruss_mem - PRUSS memory range identifiers @@ -51,4 +53,20 @@ struct pruss { struct clk *iep_clk_mux; }; +#if IS_ENABLED(CONFIG_TI_PRUSS) + +struct pruss *pruss_get(struct rproc *rproc); +void pruss_put(struct pruss *pruss); + +#else + +static inline struct pruss *pruss_get(struct rproc *rproc) +{ + return ERR_PTR(-EOPNOTSUPP); +} + +static inline void pruss_put(struct pruss *pruss) { } + +#endif /* CONFIG_TI_PRUSS */ + #endif /* _PRUSS_DRIVER_H_ */ -- 2.34.1