From patchwork Thu Nov 22 11:39:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 151761 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp628565ljp; Thu, 22 Nov 2018 03:40:09 -0800 (PST) X-Google-Smtp-Source: AJdET5c0Rhr+enPLerWtQinDqrEgMsgbCC9dXu5BJZ5zQfv8IS6NwZJqXxGnwlZh7/buaankCAIJ X-Received: by 2002:a62:e201:: with SMTP id a1mr10839732pfi.75.1542886808965; Thu, 22 Nov 2018 03:40:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542886808; cv=none; d=google.com; s=arc-20160816; b=dQ0dO51FZWd9NGPswmNCp/QrQf65lVH+qtilGoav82oFcI3oNeFkHOSRwQqNqWcaPb jmT35jJk4m6gbdjezACzWi+pXHXVjFS370T42H9YAb0NZFnCi7szQlui3SlNo0J23Ngc y28IDQvGfZ1ndyJQ087ffNlQ5JT6XaaJ6hGyz2Q2K0pNr8ygnsBqTWcQJYPdJBJEnWZ+ n4+gqdVdE8bcpHahKasj0XbRGGW3AeasmDTmPovaDu4KlCEq7yUxovlrELUAYex2JjQG Yzvyq+32WCzNopfABvepnwZGzyWeQGBP4yQzqxZlPgJ0mF+9PAbhXEXfYum7zVVb4C4k GTgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=kOyCfU8xu52K1rFh2Alr7YiAlWDJE4ZlzFpySZgmULM=; b=PLa179U9uamAKLdn1Y26OQ68GScJxleqpN7NXVbkawvJGBx9+2XBN2JEnFSVBEgSPk 0a3dPM+g1KpAmDCLu65PRZgIfjlFmk8AuDM7Xn2A6ikLkbnGw0GY4RpjIwVB4s/7o8Yh qqYIjwcI2aAmFg+tzW98YHufIPtbCxCeXIzCDYVPjmiV7XB3hefVrUBlbDkhwMnIeROp UtmFwN+bi0pHw03C6yi9tOzfJ7IeR7PIE2xSZEq5TZYF3SR6pI0kZXxmumFl18ik00na U1CQ4YfvtdkT4GrKqQ9URTU76XsAzr5TZ/jioVjG0djFlJCSPh9YA1n0Ck0baSJ+VKAu Nc6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eidyErn7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i39si22778481plb.256.2018.11.22.03.40.08; Thu, 22 Nov 2018 03:40:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eidyErn7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2394896AbeKVWTH (ORCPT + 32 others); Thu, 22 Nov 2018 17:19:07 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:35462 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391015AbeKVWTG (ORCPT ); Thu, 22 Nov 2018 17:19:06 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id wAMBe34r078110; Thu, 22 Nov 2018 05:40:03 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1542886803; bh=kOyCfU8xu52K1rFh2Alr7YiAlWDJE4ZlzFpySZgmULM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=eidyErn7rx/OG4khofgNFVKPvQnlm7kLiFRt2TkuXTmIjRgXe+mOshcfc8/wMYTae DyyTeVBmJEulL5JY8Q4W1a6zuvPtDQx6D4jbn49r2MMhLJrDL+mb05Rz6lDDu+A43F YHGBRLyFjiwVF88FvvAI9kRGFpJP3DSwwIJ+98Cg= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id wAMBe3Z9029729 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 22 Nov 2018 05:40:03 -0600 Received: from DFLE106.ent.ti.com (10.64.6.27) 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.1591.10; Thu, 22 Nov 2018 05:40:03 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Thu, 22 Nov 2018 05:40:02 -0600 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id wAMBe2rf018071; Thu, 22 Nov 2018 05:40:02 -0600 Received: from localhost.localdomain (vboxa0400828d.dhcp.ti.com [172.22.239.63]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id wAMBdDfA013203; Thu, 22 Nov 2018 05:39:59 -0600 From: Roger Quadros To: CC: , , , , , , , , , , , , , , , , Subject: [PATCH 11/17] soc: ti: pruss: add pruss_get()/put() API Date: Thu, 22 Nov 2018 13:39:07 +0200 Message-ID: <1542886753-17625-12-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542886753-17625-1-git-send-email-rogerq@ti.com> References: <1542886753-17625-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org 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(). Signed-off-by: Tero Kristo [s-anna@ti.com: various fixups and cleanups] Signed-off-by: Suman Anna --- drivers/soc/ti/pruss.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pruss.h | 10 +++++++++ 2 files changed, 67 insertions(+) -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c index c2271c4..90ee5b9 100644 --- a/drivers/soc/ti/pruss.c +++ b/drivers/soc/ti/pruss.c @@ -13,10 +13,67 @@ #include #include #include +#include #include "pruss.h" /** + * 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. + * + * Returns the 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; + if (!dev->parent) + return ERR_PTR(-ENODEV); + + /* rudimentary check to make sure rproc handle is for a PRU */ + if (!strstr(dev_name(dev->parent), "pru")) + return ERR_PTR(-ENODEV); + + ppdev = to_platform_device(dev->parent->parent); + pruss = platform_get_drvdata(ppdev); + if (pruss) + get_device(pruss->dev); + + return pruss ? pruss : ERR_PTR(-ENODEV); +} +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); + +/** * pruss_request_mem_region() - request a memory resource * @pruss: the pruss instance * @mem_id: the memory resource id diff --git a/include/linux/pruss.h b/include/linux/pruss.h index 768b698..b9135d6 100644 --- a/include/linux/pruss.h +++ b/include/linux/pruss.h @@ -36,6 +36,9 @@ struct pruss; #if IS_ENABLED(CONFIG_TI_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, @@ -45,6 +48,13 @@ int pruss_intc_trigger(unsigned int irq); #else +static inline struct pruss *pruss_get(struct rproc *rproc) +{ + return ERR_PTR(-ENOTSUPP); +} + +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)