From patchwork Wed Apr 12 10:30:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MD Danish Anwar X-Patchwork-Id: 82374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp222087vqo; Wed, 12 Apr 2023 03:40:15 -0700 (PDT) X-Google-Smtp-Source: AKy350Zs3JcDseoWEFjFsksPocKOSDkFLtF2NdrhqKmzuZEMUv3qCESwH3iey+NqMU5wjD2+83C4 X-Received: by 2002:a17:906:805:b0:92f:de0c:c914 with SMTP id e5-20020a170906080500b0092fde0cc914mr13485576ejd.28.1681296015322; Wed, 12 Apr 2023 03:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681296015; cv=none; d=google.com; s=arc-20160816; b=hyo915OMAPXEVc3kMUwDxCetxmFZrQNBv/wTB16ikEoNqwJ7AZQ6k4Cx60PC076dtI MWg1dns850r7fjylIpKCPLelnzEmIUmig1DtIG/Sth0iufAoUZekNoQC1AWgov8vwho6 IMGyzObNPp116GLdYs701DnjmjpJ0QXNbXUR+5D3m7xchZpaAYdDUI97X3gzZcLRoE0W wP8XcN+O0h5IfaXrRyDB/jcb4aFy2Ujs44mCuIA6ZxqbDLN7V2Ed1p2vPyXZSonj4pIV i8WITHYfqIeHR2SxWETTJDALs5A0/F3c6IOWf1ZQm1azNU4OGWvEvh6DoZ1hAWnSlc92 03cA== 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=IXrrYTbN5sBuVfxvsP9hoCClp8l/UI1aq8vXxJkwBnw=; b=U31cy3FG1V20A5K1MRMz/xg5+frcGUqe3CvNqOK2lCq+5UHAwUJnKXFYIKGIeXMTND C4pMKYEfqlZa1YI7Vp68Nlx/YvqIrjB+bG4Qb81pcz5703LakPK7okxA68UpbjA87i0v L3PFhmC111PTbakEiAz9+X2vj5+u3qKLH8lThlzvxeBk2Oh6miTPqht3iSCLhI9+okwg zUtIu80EzriRvxgK0t8icc9sbNYqAyxrNzbhLtq3pOfl3lSHqRGkbtFgBs/EFq6uu815 pPJyt/GTDRL6Cs86KrrC8aA3TIWRWePeS0utnJ/lbtGf93kugeTImbrlGIe2U4lUbtxY SB4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="Yj/SxQ9h"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga31-20020a1709070c1f00b009227ddac2b7si3835562ejc.434.2023.04.12.03.39.51; Wed, 12 Apr 2023 03:40:15 -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="Yj/SxQ9h"; 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 S230256AbjDLKah (ORCPT + 99 others); Wed, 12 Apr 2023 06:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbjDLKa1 (ORCPT ); Wed, 12 Apr 2023 06:30:27 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E105149D1; Wed, 12 Apr 2023 03:30:25 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 33CAUHRl046660; Wed, 12 Apr 2023 05:30:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1681295417; bh=IXrrYTbN5sBuVfxvsP9hoCClp8l/UI1aq8vXxJkwBnw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Yj/SxQ9hCpIKjogrbwXlMAi/VLofymmYhgm01IWA12kmeTxWNmh6y9zDAIERZQ/DL pQJD/u/zB5cXSl4iZQuL+pe0CV2LlPXNXHFCGWrot/mb5BVJf/utkXPMua2pGAs4vJ guVODTOgeL02Ku2oKizNHJpiLsDc66Br+tg8Apwc= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 33CAUHZq088109 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Apr 2023 05:30:17 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE108.ent.ti.com (157.170.170.38) 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:17 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE113.ent.ti.com (157.170.170.24) 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:17 -0500 Received: from fllv0122.itg.ti.com (fllv0122.itg.ti.com [10.247.120.72]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 33CAUHGg089955; Wed, 12 Apr 2023 05:30:17 -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 33CAUGQG028926; Wed, 12 Apr 2023 05:30:16 -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 1/4] soc: ti: pruss: Add pruss_get()/put() API Date: Wed, 12 Apr 2023 16:00:09 +0530 Message-ID: <20230412103012.1754161-2-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762966650479288692?= X-GMAIL-MSGID: =?utf-8?q?1762966650479288692?= 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 Signed-off-by: MD Danish Anwar Acked-by: Mathieu Poirier --- 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_ */