From patchwork Fri Dec 11 18:48:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 11969103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78EA7C4361B for ; Fri, 11 Dec 2020 18:53:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB2BC23FB6 for ; Fri, 11 Dec 2020 18:53:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB2BC23FB6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kXh16FJ8E+pH47ZSTdRQLoHshpeD6UgKFxizQp/NL8s=; b=ZIYNwrjrp8+uQMwj9Epb9SveA 1T8m8/GTAkg8jIGjqkiQ9asAJHRPrGuT3dVI3Ev7pSYDydMnRKY1WpRImNpIGbz1CX6Di7WgCZQ/3 LneREUG0u9BZAn5exPChLdrk1sF+MD9oBfIAoipKr/ADIpibMh1KrMHkCjtlg8tlyoTN26BhmC7KG 6kBYUr3OMXQ9LcwRn1AqrUZ474D4bMdkiScHBw3DFZ1Hh8i7CfjBD+29FakDro9ePZ5doC9FYt6K6 x5Hz5PlWBY3lHCAVBM5QwY5YuRnZvvzwbsp+qtTd4mtHk0UOcImCSvB2UiYdVZ82yt4LqBaAIoP1e 9vwzWVaiw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knnW3-0007rv-5Z; Fri, 11 Dec 2020 18:51:43 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knnT0-00062d-Dv for linux-arm-kernel@lists.infradead.org; Fri, 11 Dec 2020 18:48:37 +0000 Received: by mail-lj1-x235.google.com with SMTP id y16so12087221ljk.1 for ; Fri, 11 Dec 2020 10:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NWoP9tZ6oHWWAkB8TJmlPklU15pvtoRQyvnFdEsRKOI=; b=mt+MbXD2G45R++itmA44Y3a+euSVz+hpvfoElDRG++OVuwkByNS1vc7OabMmUtKWeo v0aT/8IrkEN8cN+shN8XTIaW878S+/7ha2P44D/Gt5gdkLvQvWArOX65vhoT4R645744 MIcxllWspC2Fa4BSwLkH+F0lgpokTvyV6Fnkh5CpE30AU+EvM1KFTdnl9KtSk5m0Fhz9 IkOyHfcFvMEPOnFTpXFS2eHCd+xwURCig+1YH3X+BeIQGH8bWrWFNhI9JaC4subDoRR7 avXiBmKiXVXxcSErpYNVbsJfvje5997xmBa9SNYAGvFMeqtEuNM4dUGSDu0+Ci3geU/Y 5s5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NWoP9tZ6oHWWAkB8TJmlPklU15pvtoRQyvnFdEsRKOI=; b=r6u8SbC5aNOAMmByeTAVOB20AEezCBcoM6XE1GE9Qf2Ky5PAtOuKDvT2KaSjES913U WLQaEUtR6T/NYsxHLTXRVG817ewLj0rD08CRJjd7mAKeAQEJXRioojeiqureCKfR7iOb nOvVB0zC/Ett1WZakEz0TC+FHGZ18ivBJkECCqwc+F+n2Px9SQ0D9nxX1nQ2JHVZN1Gc pva/PH0WhCygAutOQXW0Jz83usLfLiGqNvclJ/+8LnImwDrrg6MQE5+ALvh0yXEixLeA OA1vaZ7L085bw++JhQckgEh6aEVvAS0yTsMf/f5Mcp3+y/mloLthIz7bOCfNw7vsHfH9 HQjA== X-Gm-Message-State: AOAM531HgmDET5xAc03yf3LH8eCA8WFIVQkmu29JOkAvT9uR9SdCA5Be 0fHKGpvW6EI+CREEOSM5dOd+mQ== X-Google-Smtp-Source: ABdhPJz5UPyn6jKMpYkDka4oQOxNHzkev1Wzu8F53tLxnvwGa3/eIViwQYJ7dK5JY98Thny9+u8ikw== X-Received: by 2002:a2e:5753:: with SMTP id r19mr5356621ljd.240.1607712510751; Fri, 11 Dec 2020 10:48:30 -0800 (PST) Received: from gilgamesh.semihalf.com (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id b12sm903316lfb.139.2020.12.11.10.48.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Dec 2020 10:48:30 -0800 (PST) From: Grzegorz Jaszczyk To: ssantosh@kernel.org, s-anna@ti.com Subject: [PATCH 1/6] soc: ti: pruss: Add pruss_get()/put() API Date: Fri, 11 Dec 2020 19:48:06 +0100 Message-Id: <20201211184811.6490-2-grzegorz.jaszczyk@linaro.org> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201211184811.6490-1-grzegorz.jaszczyk@linaro.org> References: <20201211184811.6490-1-grzegorz.jaszczyk@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_134834_616607_8AE78023 X-CRM114-Status: GOOD ( 20.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: grzegorz.jaszczyk@linaro.org, mathieu.poirier@linaro.org, praneeth@ti.com, santosh.shilimkar@oracle.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, tony@atomide.com, linux-omap@vger.kernel.org, lee.jones@linaro.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 --- 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 5d6e7132a5c4..28eb6415cb95 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 903d0c0b75be..403951910515 100644 --- a/include/linux/pruss.h +++ b/include/linux/pruss.h @@ -4,12 +4,14 @@ * * Copyright (C) 2015-2020 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(-ENOTSUPP); +} + +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 /*