Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1126921pxb; Wed, 6 Apr 2022 09:19:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSeShTtRa0A7qcrX3ZGscxdOUTOirIVbKFVaTR9ByVIKfEpRxmvlkGLuXR6hdTFa5Tpvfq X-Received: by 2002:a63:447:0:b0:399:58c5:2cc2 with SMTP id 68-20020a630447000000b0039958c52cc2mr7829075pge.592.1649261971420; Wed, 06 Apr 2022 09:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649261971; cv=none; d=google.com; s=arc-20160816; b=Lez5eryb33vDu2vaPeNW8vU0tLbmDqTsddM2dQMDouhvFs6RiebevqwH0JKA2ddc9r 0IFFtLRspcCgSeUC1HfhCdUr+IoPJ8g9R5AFUDoe9o1JqK+aX0Y8SnCIOE1oM43Up5zj saxS7FLhqsvFxWEKV4Aaw/oW6IhrjGzkXkJOOd2fhn2X0ZUKSMI/c2IEgrKA29N/KgHZ uy9BhdiNbyMHfWyOlzVR4e4R/n9I23Rl/DfGbaenzMNcv9tAVYAgpAfF9EVAHyuS8VVa wjViRA0kBDYDuWPo1pMP/yit5+goJM9LpPklNyGyhCxXARR/7x88vgHz7N+dDykSbL1a Q2XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8ZJvkTO49sL1UlwISsywDpSiSi6n3UzwpsnvvwlZkxg=; b=AiY+sIT/M+FMoeG9VXDHCg2Q5c9tbrk1dMG2kj/D2t4roKLbanDdTxBJXfeZCvwEs/ l5tACIqTLRh927VkdaDMSmW5w95jvQ49zKfocmoON274e3Mv8AJrh/LiP1dChSaHNL+/ bsFhmVCK5rWWuNjC4pWDhFOmevgz5sZjNf2EfCrmFX/4x+VfI5mRMLJmkcRt4W7Twnag JuBIUN+4GjwFkCzjLdqbNccHLGXxUuYrPF8pYTS4bb0uwubae1w1A0UC7GVMITCsNsM3 TAdTrEvU6yR2IzhOOxAMMVmb8IXl4QOCCaaSWOeZIufYceGa6uOdS8ccJ9lnGvHxCIQu exMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eShzWZcq; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ik20-20020a170902ab1400b00156fceb78f1si222560plb.318.2022.04.06.09.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:19:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eShzWZcq; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1C40248800D; Wed, 6 Apr 2022 08:17:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235376AbiDFPSk (ORCPT + 99 others); Wed, 6 Apr 2022 11:18:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235874AbiDFPRX (ORCPT ); Wed, 6 Apr 2022 11:17:23 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901A564A629; Wed, 6 Apr 2022 05:18:30 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2369iIJu031102; Wed, 6 Apr 2022 04:44:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1649238258; bh=8ZJvkTO49sL1UlwISsywDpSiSi6n3UzwpsnvvwlZkxg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=eShzWZcq2X7ga17Sk3n5XnRM8xS/JA4TR8dm0OB2w+6IpT0wUgrjIsv2XCOh0Hswa 0rFaZbQp4NJ/ZztAzI9VMsn7DPpla7f3+QWxD/AifjynhlgBlk6N8IVV9sV4dwWYvw 05wy0fTEwowiO2HatH7opOmeRfDn4eNwEhaQKAyQ= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2369iIGs030599 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Apr 2022 04:44:18 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Wed, 6 Apr 2022 04:44:17 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Wed, 6 Apr 2022 04:44:17 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2369iGHR107679; Wed, 6 Apr 2022 04:44:17 -0500 From: Puranjay Mohan To: CC: , , , , , , , , , , , , , , Subject: [RFC 06/13] soc: ti: pruss: Add pruss_get()/put() API Date: Wed, 6 Apr 2022 15:13:51 +0530 Message-ID: <20220406094358.7895-7-p-mohan@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220406094358.7895-1-p-mohan@ti.com> References: <20220406094358.7895-1-p-mohan@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 --- drivers/soc/ti/pruss.c | 58 ++++++++++++++++++++++++++++++++++++ include/linux/pruss.h | 19 ++++++++++++ include/linux/pruss_driver.h | 1 + 3 files changed, 78 insertions(+) diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c index b36779309e49..5ad62c35da5d 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,62 @@ 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. + * + * 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.h b/include/linux/pruss.h index d830e20056c7..23d556e0dd72 100644 --- a/include/linux/pruss.h +++ b/include/linux/pruss.h @@ -4,12 +4,14 @@ * * Copyright (C) 2015-2022 Texas Instruments Incorporated - http://www.ti.com * Suman Anna + * Tero Kristo */ #ifndef __LINUX_PRUSS_H #define __LINUX_PRUSS_H #include +#include #include #define PRU_RPROC_DRVNAME "pru-rproc" @@ -39,6 +41,23 @@ enum pru_ctable_idx { struct device_node; struct rproc; +struct pruss; + +#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 */ #if IS_ENABLED(CONFIG_PRU_REMOTEPROC) diff --git a/include/linux/pruss_driver.h b/include/linux/pruss_driver.h index ecfded30ed05..d054d2179d82 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 /* -- 2.17.1