Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2677310pxb; Mon, 18 Apr 2022 06:08:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDOPuoc52jPXhJLkv5zJpXxjU3joohr/dpcjIlnv3MwvWwiWHEC15Svw6368CxsmJKWVvt X-Received: by 2002:a17:90b:38cb:b0:1d1:4d40:360 with SMTP id nn11-20020a17090b38cb00b001d14d400360mr15393412pjb.9.1650287337085; Mon, 18 Apr 2022 06:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650287337; cv=none; d=google.com; s=arc-20160816; b=kiu2DE6DJpYnQw/A08yRFMVxYI+3avA62VLioBqZ8iIIx++WEm3wkrvTiSNAZ3zSzv W1apYKkWGVXIwNnfIFsFU9u+me0GJWV3WAgLZZqkyETftDJthjKJLWEcWONW+J1D0Apx 3vN9gIoc/fTibnTaBDFLYcov0DYHcMCSuOxkEXbWskN1EM43Cgfi1ndjoH9a8GnouJAf FnruUwe2b87rOFEyCyYbaVPg1sTz30SZuTyX7ofvNcH2R2hHch9VmFPd2ySjDCPsWrjp 7sD/8SR1vhtNobWcftFNLZ8SYmYjzSUvv+fYL4LeRTw5/mTq6/INelyj0qxAXhfE4CkF 53Hg== 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=0ndnLJidoa5UjeSdPb58zn9AOIQv1x52nozSedEW3Hw=; b=m3dp1oDl+JPhiemVlJ8gr1mjOnlt/3IdnXHam0JNkDh6E40HSYARZk450WHaIIrD8k IGeN1/MMsDqXJcmrpHUlV+L1UNV2b940hjmEIP5qTWytrIRZnXnDXLKBo2z30xB3Z+vR AY6Mjeqvl0bSpbPbeQNKQTzAYBodOA9+8KjAWKhzrGMKNVBHxO050c7JBVFEsqfpMDZV 4bylsOI0VCJqic+eMT018d7PGKtHh8yMgtqhM0j6L4FgKnwH5ZuDqT3Ugy6xuBG6bxHu Rj+XLHPo4cMQtpXXN+BrN6ajSfY8TOuX8XhB45H+VAf1e9tG1LADl7WyYR1jBItHeNJb Dxlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=AKKnNC4K; 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 y5-20020a17090a600500b001cb710f3751si11504031pji.127.2022.04.18.06.08.40; Mon, 18 Apr 2022 06:08:57 -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=AKKnNC4K; 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 S239502AbiDRMuM (ORCPT + 99 others); Mon, 18 Apr 2022 08:50:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240728AbiDRMjf (ORCPT ); Mon, 18 Apr 2022 08:39:35 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B98913D0C; Mon, 18 Apr 2022 05:30:19 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 23ICUAvj077104; Mon, 18 Apr 2022 07:30:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1650285011; bh=0ndnLJidoa5UjeSdPb58zn9AOIQv1x52nozSedEW3Hw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=AKKnNC4KkZJ4mf3eDgHTNg4aG9/+jkkVNGGJjD/UJfQYnlzJ+FAnYBdOvRe0oZ/mk h+ccrvQE2b4pVbTnT2mpq1Dl/aQMz1NXlZ7GRLz8irvxcO8wlczK7B5DXV4vz0IJVR PD810yDAADmfFVIPYRjVZkODndn6Ka76Ga4dyPjM= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 23ICU8t1016071 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 18 Apr 2022 07:30:10 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Mon, 18 Apr 2022 07:30:09 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) 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 via Frontend Transport; Mon, 18 Apr 2022 07:30:09 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 23ICU92f011081; Mon, 18 Apr 2022 07:30:09 -0500 From: Puranjay Mohan To: CC: , , , , , , , , , , , , , Subject: [PATCH v2 1/6] soc: ti: pruss: Add pruss_get()/put() API Date: Mon, 18 Apr 2022 17:59:59 +0530 Message-ID: <20220418123004.9332-2-p-mohan@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220418123004.9332-1-p-mohan@ti.com> References: <20220418123004.9332-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=-5.0 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_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 --- 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 0e4ba0f89533..fb0a0b4a9663 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