From patchwork Sun Feb 13 20:12:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 12744678 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC11CC433EF for ; Sun, 13 Feb 2022 20:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=f4ThAntLbwdzkayBM2V9fcJ9ogvxEpd2AvlI4+mVq4g=; b=1PkWfVvVcyzGOV n9FODgmoMEHUCWq35y5qGACcp9TcZtj47HNTDP4WOy+R6W5CkA+YEuG+gKwA7C9LoznSDQSLHOTDk ql96o20UUUpawfDpqEL00V4TeIJZrpcHBE0z0GMeRHoBlvVGZwHOzfckrRXmQlcyRj5PjYWPqEHXY /4N6so8dAyQCk5kYMSxaXvxrZBMyufP8Bq7H6I/OYgRW6YNa340z3UrPICfmmlHDkqs8pShADzjAD JvGJ5tclQGo9rj8UiA0AobVe1G/NXpvHd/lYziXExpAFhCq4U/WQcBgtaKx5/R5i1xZ+i/WoHuIsf rJJAvnTLS5NbSpjnAu7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLF5-00CSqC-L3; Sun, 13 Feb 2022 20:13:07 +0000 Received: from lelv0143.ext.ti.com ([198.47.23.248]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLEs-00CSmu-Dz for linux-arm-kernel@lists.infradead.org; Sun, 13 Feb 2022 20:12:56 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCo2o015311; Sun, 13 Feb 2022 14:12:50 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1644783170; bh=9irqzYnrEpjWi9U3Xpk+DuQR+/hIGdWOOh9XnlBDeH0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=mqg31rRxFQoh9uwzs82GMt0MYdPhhWfznOUXujfzScP9BPiB9oEvpG9sReET0AjX9 OtRcQWYqnyKRruiKwRtT2B2XjD5PiBLiSNRE/MDF7kf/AMNm3YWaRtJJMJqA+3CmuQ XfVL4RS4YHzTac7dWMvEE8G7Tup6ynevoVe+5Jck= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 21DKCogc065496 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 13 Feb 2022 14:12:50 -0600 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Sun, 13 Feb 2022 14:12:49 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) 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 via Frontend Transport; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnQO085417; Sun, 13 Feb 2022 14:12:49 -0600 Received: from localhost ([10.249.37.221]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 21DKCnNG002412; Sun, 13 Feb 2022 14:12:49 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier Subject: [PATCH v3 1/5] remoteproc: Change rproc_shutdown() to return a status Date: Sun, 13 Feb 2022 14:12:42 -0600 Message-ID: <20220213201246.25952-2-s-anna@ti.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220213201246.25952-1-s-anna@ti.com> References: <20220213201246.25952-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_121254_603223_9EF43CCD X-CRM114-Status: GOOD ( 19.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Praneeth Bajjuri , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Hari Nagalla Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The rproc_shutdown() function is currently not returning any error code, and any failures within rproc_stop() are not passed back to the users. Change the signature to return a success value back to the callers. The remoteproc sysfs and cdev interfaces are also updated to return back this status to userspace. Signed-off-by: Suman Anna --- v3: - New patch in place of v2 patch "remoteproc: Add support for detach-only during shutdown", https://patchwork.kernel.org/project/linux-remoteproc/patch/20210723220248.6554-2-s-anna@ti.com/ Documentation/staging/remoteproc.rst | 3 ++- drivers/remoteproc/remoteproc_cdev.c | 2 +- drivers/remoteproc/remoteproc_core.c | 9 ++++++--- drivers/remoteproc/remoteproc_sysfs.c | 2 +- include/linux/remoteproc.h | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Documentation/staging/remoteproc.rst b/Documentation/staging/remoteproc.rst index 9cccd3dd6a4b..348ee7e508ac 100644 --- a/Documentation/staging/remoteproc.rst +++ b/Documentation/staging/remoteproc.rst @@ -49,13 +49,14 @@ might also consider using dev_archdata for this). :: - void rproc_shutdown(struct rproc *rproc) + int rproc_shutdown(struct rproc *rproc) Power off a remote processor (previously booted with rproc_boot()). In case @rproc is still being used by an additional user(s), then this function will just decrement the power refcount and exit, without really powering off the device. +Returns 0 on success, and an appropriate error value otherwise. Every call to rproc_boot() must (eventually) be accompanied by a call to rproc_shutdown(). Calling rproc_shutdown() redundantly is a bug. diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 4ad98b0b8caa..906ff3c4dfdd 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -42,7 +42,7 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else if (!strncmp(cmd, "detach", len)) { if (rproc->state != RPROC_ATTACHED) return -EINVAL; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 69f51acf235e..c510125769b9 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2061,16 +2061,18 @@ EXPORT_SYMBOL(rproc_boot); * which means that the @rproc handle stays valid even after rproc_shutdown() * returns, and users can still use it with a subsequent rproc_boot(), if * needed. + * + * Return: 0 on success, and an appropriate error value otherwise */ -void rproc_shutdown(struct rproc *rproc) +int rproc_shutdown(struct rproc *rproc) { struct device *dev = &rproc->dev; - int ret; + int ret = 0; ret = mutex_lock_interruptible(&rproc->lock); if (ret) { dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); - return; + return ret; } /* if the remote proc is still needed, bail out */ @@ -2097,6 +2099,7 @@ void rproc_shutdown(struct rproc *rproc) rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); + return ret; } EXPORT_SYMBOL(rproc_shutdown); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index ea8b89f97d7b..645c70c8109b 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -206,7 +206,7 @@ static ssize_t state_store(struct device *dev, rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else if (sysfs_streq(buf, "detach")) { if (rproc->state != RPROC_ATTACHED) return -EINVAL; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e0600e1e5c17..cfc0c95c95b2 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -669,7 +669,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len, u32 da, const char *name, ...); int rproc_boot(struct rproc *rproc); -void rproc_shutdown(struct rproc *rproc); +int rproc_shutdown(struct rproc *rproc); int rproc_detach(struct rproc *rproc); int rproc_set_firmware(struct rproc *rproc, const char *fw_name); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); From patchwork Sun Feb 13 20:12:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 12744680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BBB8FC433EF for ; Sun, 13 Feb 2022 20:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=EH2KznbbO4OwV+nBK4YdfhTrVD5myOdg5HJDo71JfjI=; b=NpE831fNrWdjxk 9UtSWyXgoSZbMmTp5YjE5/bi8PBfd6NTkS6V0gFITh+iVNIk4kfNPAVht6fIOjD3ufkmLBXHeMacl nW4ucVzgl8YS7g2GTE0lzT0BXi7c7UByzT21eX0vwHe7ZsuSOoQSicvy+yr0c+s29ge3RTpAj+moO VzX0zQCs5pqQQWCtcciDrS5bioNPhsVsP4/0IzYdZ20lXX+/yb7zM5f3w2zDqvn0HYqznGBP1k0S0 g/K2SsquF2vG5NdC8vK8Nyz0tvSp6TZ3agl/z8R5AKvyZ6mrG8fLYLq5ZmV4Dm0fB9cQf3DZzIuII 0AzJ9kmU0hfrTCn7ZU9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLFF-00CSrv-0n; Sun, 13 Feb 2022 20:13:17 +0000 Received: from fllv0015.ext.ti.com ([198.47.19.141]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLEs-00CSmy-MA for linux-arm-kernel@lists.infradead.org; Sun, 13 Feb 2022 20:12:57 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnMN106250; Sun, 13 Feb 2022 14:12:49 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1644783169; bh=VlsO5Co1YhSU4oiDDo1I0Cx/Bw8CNI0Q8dDUb0hAK2I=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=NawsxXxR6eIs7TMKija8kqcc++qcaNWEq8iHOncWMtPphMzxSPm00wLL5k5HwAkJZ x6V/xlwE0pACnm8G2773C+3nVWmr7lV5f65AgRpaj9t00bpjBkgdvMmSC+6QRExXFI zB/3uV49CYeEdTPY5k9NSqZf/mTZevmelqps/94s= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 21DKCnPd065490 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 13 Feb 2022 14:12:49 -0600 Received: from DLEE110.ent.ti.com (157.170.170.21) 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.2308.14; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE110.ent.ti.com (157.170.170.21) 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; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnsU020622; Sun, 13 Feb 2022 14:12:49 -0600 Received: from localhost ([10.249.37.221]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 21DKCnFd002415; Sun, 13 Feb 2022 14:12:49 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier Subject: [PATCH v3 2/5] remoteproc: k3-r5: Refactor mbox request code in start Date: Sun, 13 Feb 2022 14:12:43 -0600 Message-ID: <20220213201246.25952-3-s-anna@ti.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220213201246.25952-1-s-anna@ti.com> References: <20220213201246.25952-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_121254_854622_6E3819F8 X-CRM114-Status: GOOD ( 17.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Praneeth Bajjuri , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Hari Nagalla Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Refactor out the mailbox request and associated ping logic code from k3_r5_rproc_start() function into its own separate function so that it can be re-used in the soon to be added .attach() ops callback. Signed-off-by: Suman Anna Reviewed-by: Mathieu Poirier --- v3: Updated license years, no code changes v2: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210723220248.6554-3-s-anna@ti.com/ v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210522000309.26134-4-s-anna@ti.com/ drivers/remoteproc/ti_k3_r5_remoteproc.c | 68 ++++++++++++++---------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 969531c05b13..ff4e1fac1c7f 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -2,7 +2,7 @@ /* * TI K3 R5F (MCU) Remote Processor driver * - * Copyright (C) 2017-2020 Texas Instruments Incorporated - https://www.ti.com/ + * Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/ * Suman Anna */ @@ -376,6 +376,44 @@ static inline int k3_r5_core_run(struct k3_r5_core *core) 0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT); } +static int k3_r5_rproc_request_mbox(struct rproc *rproc) +{ + struct k3_r5_rproc *kproc = rproc->priv; + struct mbox_client *client = &kproc->client; + struct device *dev = kproc->dev; + int ret; + + client->dev = dev; + client->tx_done = NULL; + client->rx_callback = k3_r5_rproc_mbox_callback; + client->tx_block = false; + client->knows_txdone = false; + + kproc->mbox = mbox_request_channel(client, 0); + if (IS_ERR(kproc->mbox)) { + ret = -EBUSY; + dev_err(dev, "mbox_request_channel failed: %ld\n", + PTR_ERR(kproc->mbox)); + return ret; + } + + /* + * Ping the remote processor, this is only for sanity-sake for now; + * there is no functional effect whatsoever. + * + * Note that the reply will _not_ arrive immediately: this message + * will wait in the mailbox fifo until the remote processor is booted. + */ + ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); + if (ret < 0) { + dev_err(dev, "mbox_send_message failed: %d\n", ret); + mbox_free_channel(kproc->mbox); + return ret; + } + + return 0; +} + /* * The R5F cores have controls for both a reset and a halt/run. The code * execution from DDR requires the initial boot-strapping code to be run @@ -495,38 +533,14 @@ static int k3_r5_rproc_start(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; struct k3_r5_cluster *cluster = kproc->cluster; - struct mbox_client *client = &kproc->client; struct device *dev = kproc->dev; struct k3_r5_core *core; u32 boot_addr; int ret; - client->dev = dev; - client->tx_done = NULL; - client->rx_callback = k3_r5_rproc_mbox_callback; - client->tx_block = false; - client->knows_txdone = false; - - kproc->mbox = mbox_request_channel(client, 0); - if (IS_ERR(kproc->mbox)) { - ret = -EBUSY; - dev_err(dev, "mbox_request_channel failed: %ld\n", - PTR_ERR(kproc->mbox)); + ret = k3_r5_rproc_request_mbox(rproc); + if (ret) return ret; - } - - /* - * Ping the remote processor, this is only for sanity-sake for now; - * there is no functional effect whatsoever. - * - * Note that the reply will _not_ arrive immediately: this message - * will wait in the mailbox fifo until the remote processor is booted. - */ - ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); - if (ret < 0) { - dev_err(dev, "mbox_send_message failed: %d\n", ret); - goto put_mbox; - } boot_addr = rproc->bootaddr; /* TODO: add boot_addr sanity checking */ From patchwork Sun Feb 13 20:12:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 12744683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0A92C433F5 for ; Sun, 13 Feb 2022 20:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=FQVOBS5OyNuaJW+Ndu7OhL5Ejv9kVYQwE5tt5XUxNuY=; b=qGW1MqgRwQaXYh kMddXWpGzo38Md1ZSLO9B4x/W+EzzmqjozfsD237j2mhTWzcIALZfA8s0rWjQmw3Tyjz0O3l3Gp59 WvFnSP4wvJKOEwPdQ7thJPkvK+4I1b5fXA8l0o8O6X6nS55c5hfk2wzHXrb+J0htKmNkPfvmaPpsJ SBDcl6tDSKY/7Ob3LExXRBhZAJh2L/XDN3jXv/pyyStgocxCsPHnoa6WQAcLywqx9pbS9rXX5znln y2ULHSlDGSZNgY2JHjc9Z5kMU3CQwnwQYOgSDian0kfcXHAnBUMDIJeP6kfBQR2Bnwvd9TCe81hkw DPq4OBPER6nbG/oD/+hA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLFi-00CT02-EQ; Sun, 13 Feb 2022 20:13:46 +0000 Received: from lelv0142.ext.ti.com ([198.47.23.249]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLEs-00CSms-It for linux-arm-kernel@lists.infradead.org; Sun, 13 Feb 2022 20:12:58 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnf2017975; Sun, 13 Feb 2022 14:12:49 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1644783169; bh=GcmN7pw+JRq0CVRhAkBWYyW4VkiTFmlM4mCV9ZiwAG0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=H1SpIJYMdt2MP1uFTgS2yIaSROF2p5l9Cp40TZdk76N4bp20tKmFriyG0hDD6WlWF kZ8mV+/zsdAQpHUDLZC4UUwFrkFvLqfnShXo5MpwVNh3gTbpA+T9Nwf8mN6qdYadHV 2HBVAxApadbQVlY9UG/tS1GTWI0n/F0BUF2Cyeqs= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 21DKCnts065493 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 13 Feb 2022 14:12:49 -0600 Received: from DFLE104.ent.ti.com (10.64.6.25) 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.2308.14; Sun, 13 Feb 2022 14:12:49 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE104.ent.ti.com (10.64.6.25) 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; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnbI022108; Sun, 13 Feb 2022 14:12:49 -0600 Received: from localhost ([10.249.37.221]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 21DKCnug002418; Sun, 13 Feb 2022 14:12:49 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier Subject: [PATCH v3 3/5] remoteproc: k3-r5: Add support for IPC-only mode for all R5Fs Date: Sun, 13 Feb 2022 14:12:44 -0600 Message-ID: <20220213201246.25952-4-s-anna@ti.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220213201246.25952-1-s-anna@ti.com> References: <20220213201246.25952-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_121254_755971_A6CB96AA X-CRM114-Status: GOOD ( 39.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Praneeth Bajjuri , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Hari Nagalla Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support to the K3 R5F remoteproc driver to configure all the R5F cores to be either in IPC-only mode or the traditional remoteproc mode. The IPC-only mode expects that the remote processors are already booted by the bootloader, and only performs the minimum steps required to initialize and deinitialize the virtio IPC transports. The remoteproc mode allows the kernel remoteproc driver to do the regular load and boot and other device management operations for a R5F core. The IPC-only mode for a R5F core is detected and configured at driver probe time by querying the System Firmware for the R5F power and reset state and/or status and making sure that the R5F core is indeed started by the bootloaders, otherwise the device is configured for remoteproc mode. Support for IPC-only mode is achieved through .attach(), .detach() and .get_loaded_rsc_table() callback ops and zeroing out the regular rproc ops .prepare(), .unprepare(), .start() and .stop(). The resource table follows a design-by-contract approach and is expected to be at the base of the DDR firmware region reserved for each remoteproc, it is mostly expected to contain only the virtio device and trace resource entries. NOTE: The driver cannot configure a R5F core for remoteproc mode by any means without rebooting the kernel if that R5F core has been started by a bootloader. This is the current desired behavior and can be enhanced in the future if the feature is needed. Signed-off-by: Suman Anna --- v3: Revised version of v2 patch adjusted for dropping v2 Patch 1 - Added rproc_detach logic in k3_r5_cluster_rproc_exit() before invoking rproc_del() - Added rproc_detach logic in cleanup path in k3_r5_cluster_rproc_exit() before invoking rproc_del() v2: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210723220248.6554-4-s-anna@ti.com/ v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210522000309.26134-5-s-anna@ti.com/ drivers/remoteproc/ti_k3_r5_remoteproc.c | 219 ++++++++++++++++++++++- 1 file changed, 215 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index ff4e1fac1c7f..4840ad906018 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -428,6 +428,7 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc) * private to each core. Only Core0 needs to be unhalted for running the * cluster in this mode. The function uses the same reset logic as LockStep * mode for this (though the behavior is agnostic of the reset release order). + * This callback is invoked only in remoteproc mode. */ static int k3_r5_rproc_prepare(struct rproc *rproc) { @@ -493,7 +494,8 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) * both cores. The access is made possible only with releasing the resets for * both cores, but with only Core0 unhalted. This function re-uses the same * reset assert logic as LockStep mode for this mode (though the behavior is - * agnostic of the reset assert order). + * agnostic of the reset assert order). This callback is invoked only in + * remoteproc mode. */ static int k3_r5_rproc_unprepare(struct rproc *rproc) { @@ -527,7 +529,8 @@ static int k3_r5_rproc_unprepare(struct rproc *rproc) * * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute * code, so only Core0 needs to be unhalted. The function uses the same logic - * flow as Split-mode for this. + * flow as Split-mode for this. This callback is invoked only in remoteproc + * mode. */ static int k3_r5_rproc_start(struct rproc *rproc) { @@ -598,7 +601,8 @@ static int k3_r5_rproc_start(struct rproc *rproc) * be done here, but is preferred to be done in the .unprepare() ops - this * maintains the symmetric behavior between the .start(), .stop(), .prepare() * and .unprepare() ops, and also balances them well between sysfs 'state' - * flow and device bind/unbind or module removal. + * flow and device bind/unbind or module removal. This callback is invoked + * only in remoteproc mode. */ static int k3_r5_rproc_stop(struct rproc *rproc) { @@ -635,6 +639,78 @@ static int k3_r5_rproc_stop(struct rproc *rproc) return ret; } +/* + * Attach to a running R5F remote processor (IPC-only mode) + * + * The R5F attach callback only needs to request the mailbox, the remote + * processor is already booted, so there is no need to issue any TI-SCI + * commands to boot the R5F cores in IPC-only mode. This callback is invoked + * only in IPC-only mode. + */ +static int k3_r5_rproc_attach(struct rproc *rproc) +{ + struct k3_r5_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + int ret; + + ret = k3_r5_rproc_request_mbox(rproc); + if (ret) + return ret; + + dev_info(dev, "R5F core initialized in IPC-only mode\n"); + return 0; +} + +/* + * Detach from a running R5F remote processor (IPC-only mode) + * + * The R5F detach callback performs the opposite operation to attach callback + * and only needs to release the mailbox, the R5F cores are not stopped and + * will be left in booted state in IPC-only mode. This callback is invoked + * only in IPC-only mode. + */ +static int k3_r5_rproc_detach(struct rproc *rproc) +{ + struct k3_r5_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + + mbox_free_channel(kproc->mbox); + dev_info(dev, "R5F core deinitialized in IPC-only mode\n"); + return 0; +} + +/* + * This function implements the .get_loaded_rsc_table() callback and is used + * to provide the resource table for the booted R5F in IPC-only mode. The K3 R5F + * firmwares follow a design-by-contract approach and are expected to have the + * resource table at the base of the DDR region reserved for firmware usage. + * This provides flexibility for the remote processor to be booted by different + * bootloaders that may or may not have the ability to publish the resource table + * address and size through a DT property. This callback is invoked only in + * IPC-only mode. + */ +static struct resource_table *k3_r5_get_loaded_rsc_table(struct rproc *rproc, + size_t *rsc_table_sz) +{ + struct k3_r5_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + + if (!kproc->rmem[0].cpu_addr) { + dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found"); + return ERR_PTR(-ENOMEM); + } + + /* + * NOTE: The resource table size is currently hard-coded to a maximum + * of 256 bytes. The most common resource table usage for K3 firmwares + * is to only have the vdev resource entry and an optional trace entry. + * The exact size could be computed based on resource table address, but + * the hard-coded value suffices to support the IPC-only mode. + */ + *rsc_table_sz = 256; + return (struct resource_table *)kproc->rmem[0].cpu_addr; +} + /* * Internal Memory translation helper * @@ -1014,6 +1090,116 @@ static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc) } } +/* + * This function checks and configures a R5F core for IPC-only or remoteproc + * mode. The driver is configured to be in IPC-only mode for a R5F core when + * the core has been loaded and started by a bootloader. The IPC-only mode is + * detected by querying the System Firmware for reset, power on and halt status + * and ensuring that the core is running. Any incomplete steps at bootloader + * are validated and errored out. + * + * In IPC-only mode, the driver state flags for ATCM, BTCM and LOCZRAMA settings + * and cluster mode parsed originally from kernel DT are updated to reflect the + * actual values configured by bootloader. The driver internal device memory + * addresses for TCMs are also updated. + */ +static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) +{ + struct k3_r5_cluster *cluster = kproc->cluster; + struct k3_r5_core *core = kproc->core; + struct device *cdev = core->dev; + bool r_state = false, c_state = false; + u32 ctrl = 0, cfg = 0, stat = 0, halted = 0; + u64 boot_vec = 0; + u32 atcm_enable, btcm_enable, loczrama; + struct k3_r5_core *core0; + enum cluster_mode mode; + int ret; + + core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); + + ret = core->ti_sci->ops.dev_ops.is_on(core->ti_sci, core->ti_sci_id, + &r_state, &c_state); + if (ret) { + dev_err(cdev, "failed to get initial state, mode cannot be determined, ret = %d\n", + ret); + return ret; + } + if (r_state != c_state) { + dev_warn(cdev, "R5F core may have been powered on by a different host, programmed state (%d) != actual state (%d)\n", + r_state, c_state); + } + + ret = reset_control_status(core->reset); + if (ret < 0) { + dev_err(cdev, "failed to get initial local reset status, ret = %d\n", + ret); + return ret; + } + + ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, + &stat); + if (ret < 0) { + dev_err(cdev, "failed to get initial processor status, ret = %d\n", + ret); + return ret; + } + atcm_enable = cfg & PROC_BOOT_CFG_FLAG_R5_ATCM_EN ? 1 : 0; + btcm_enable = cfg & PROC_BOOT_CFG_FLAG_R5_BTCM_EN ? 1 : 0; + loczrama = cfg & PROC_BOOT_CFG_FLAG_R5_TCM_RSTBASE ? 1 : 0; + if (cluster->soc_data->single_cpu_mode) { + mode = cfg & PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE ? + CLUSTER_MODE_SINGLECPU : CLUSTER_MODE_SPLIT; + } else { + mode = cfg & PROC_BOOT_CFG_FLAG_R5_LOCKSTEP ? + CLUSTER_MODE_LOCKSTEP : CLUSTER_MODE_SPLIT; + } + halted = ctrl & PROC_BOOT_CTRL_FLAG_R5_CORE_HALT; + + /* + * IPC-only mode detection requires both local and module resets to + * be deasserted and R5F core to be unhalted. Local reset status is + * irrelevant if module reset is asserted (POR value has local reset + * deasserted), and is deemed as remoteproc mode + */ + if (c_state && !ret && !halted) { + dev_info(cdev, "configured R5F for IPC-only mode\n"); + kproc->rproc->state = RPROC_DETACHED; + ret = 1; + /* override rproc ops with only required IPC-only mode ops */ + kproc->rproc->ops->prepare = NULL; + kproc->rproc->ops->unprepare = NULL; + kproc->rproc->ops->start = NULL; + kproc->rproc->ops->stop = NULL; + kproc->rproc->ops->attach = k3_r5_rproc_attach; + kproc->rproc->ops->detach = k3_r5_rproc_detach; + kproc->rproc->ops->get_loaded_rsc_table = + k3_r5_get_loaded_rsc_table; + } else if (!c_state) { + dev_info(cdev, "configured R5F for remoteproc mode\n"); + ret = 0; + } else { + dev_err(cdev, "mismatched mode: local_reset = %s, module_reset = %s, core_state = %s\n", + !ret ? "deasserted" : "asserted", + c_state ? "deasserted" : "asserted", + halted ? "halted" : "unhalted"); + ret = -EINVAL; + } + + /* fixup TCMs, cluster & core flags to actual values in IPC-only mode */ + if (ret > 0) { + if (core == core0) + cluster->mode = mode; + core->atcm_enable = atcm_enable; + core->btcm_enable = btcm_enable; + core->loczrama = loczrama; + core->mem[0].dev_addr = loczrama ? 0 : K3_R5_TCM_DEV_ADDR; + core->mem[1].dev_addr = loczrama ? K3_R5_TCM_DEV_ADDR : 0; + } + + return ret; +} + static int k3_r5_cluster_rproc_init(struct platform_device *pdev) { struct k3_r5_cluster *cluster = platform_get_drvdata(pdev); @@ -1023,7 +1209,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) struct device *cdev; const char *fw_name; struct rproc *rproc; - int ret; + int ret, ret1; core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); list_for_each_entry(core, &cluster->cores, elem) { @@ -1054,6 +1240,12 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) kproc->rproc = rproc; core->rproc = rproc; + ret = k3_r5_rproc_configure_mode(kproc); + if (ret < 0) + goto err_config; + if (ret) + goto init_rmem; + ret = k3_r5_rproc_configure(kproc); if (ret) { dev_err(dev, "initial configure failed, ret = %d\n", @@ -1061,6 +1253,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) goto err_config; } +init_rmem: k3_r5_adjust_tcm_sizes(kproc); ret = k3_r5_reserved_mem_init(kproc); @@ -1085,6 +1278,15 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) return 0; err_split: + if (rproc->state == RPROC_ATTACHED) { + ret1 = rproc_detach(rproc); + if (ret1) { + dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", + ret1); + return ret1; + } + } + rproc_del(rproc); err_add: k3_r5_reserved_mem_exit(kproc); @@ -1108,6 +1310,7 @@ static void k3_r5_cluster_rproc_exit(void *data) struct k3_r5_rproc *kproc; struct k3_r5_core *core; struct rproc *rproc; + int ret; /* * lockstep mode and single-cpu modes have only one rproc associated @@ -1123,6 +1326,14 @@ static void k3_r5_cluster_rproc_exit(void *data) rproc = core->rproc; kproc = rproc->priv; + if (rproc->state == RPROC_ATTACHED) { + ret = rproc_detach(rproc); + if (ret) { + dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", ret); + return; + } + } + rproc_del(rproc); k3_r5_reserved_mem_exit(kproc); From patchwork Sun Feb 13 20:12:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 12744681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F23BC433EF for ; Sun, 13 Feb 2022 20:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=N8aZiqCZ9T0q5z2U1s5TYvS36Q5MPb1FFFgFkcUKStk=; b=wrQbTBJQlfuMcS 4NOuqz4S5Cs2SYYrx1LTCYxSZ3cFcxZ6zapVr1YSarD7ptoTnDrrooGp9gRWo4EHWk1yYJ4JcPO0X CeKM/f1z6lLWrgW/UrN6mcsvnflKq6gTv4m8bTu9OFjiKT4CUur1jV+ZVQ5ei/OFaWF9MSCzSxlUO jL+NA2tARiRyvlKDtmIcs0GdEUfM0AdSemx6xEi/YnpYvIbdqqzAdOnap4sPoCKeyoNGYFwDluMPV X2QdrK5jVK7cTEa8y17+RhJcNLnlWVZpOQ7yBKJyInMhyxPg4vaZIDh1POyCr0XwG/GGjuSQjz+Vi aIaTk16+zrgkOx7rltCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLFO-00CStQ-B6; Sun, 13 Feb 2022 20:13:26 +0000 Received: from fllv0016.ext.ti.com ([198.47.19.142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLEt-00CSn3-3m for linux-arm-kernel@lists.infradead.org; Sun, 13 Feb 2022 20:12:58 +0000 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCpoH123615; Sun, 13 Feb 2022 14:12:51 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1644783171; bh=QUgtMxF0n5onBV3IW94Ab7+3PnJF6Yddzd42KgZ6mtE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=kCpg9w09zb2X4KXzCLZJElHZ92/Xam/SM9JQjNsA6BVyl4Ka5CsKkFf//CwAlm3EJ TaOGMbj3BWlZaFtzfTcsD3/iHICmu/7ZZJAb+ujl+Jhvkef9GNnuZNsj/TMUggv8T1 gZoHhCUHMvOZaENehHgu6dDFBntE5LFoZETDwhfI= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 21DKCprF112367 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 13 Feb 2022 14:12:51 -0600 Received: from DLEE101.ent.ti.com (157.170.170.31) 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.2308.14; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE101.ent.ti.com (157.170.170.31) 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; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnWQ020625; Sun, 13 Feb 2022 14:12:49 -0600 Received: from localhost ([10.249.37.221]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 21DKCnmY002421; Sun, 13 Feb 2022 14:12:49 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier Subject: [PATCH v3 4/5] remoteproc: k3-dsp: Refactor mbox request code in start Date: Sun, 13 Feb 2022 14:12:45 -0600 Message-ID: <20220213201246.25952-5-s-anna@ti.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220213201246.25952-1-s-anna@ti.com> References: <20220213201246.25952-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_121255_281567_80F8ABD7 X-CRM114-Status: GOOD ( 17.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Praneeth Bajjuri , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Hari Nagalla Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Refactor out the mailbox request and associated ping logic code from k3_dsp_rproc_start() function into its own separate function so that it can be re-used in the soon to be added .attach() ops callback. Signed-off-by: Suman Anna Reviewed-by: Mathieu Poirier --- v3: Updated license years, no code changes v2: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210723220248.6554-5-s-anna@ti.com/ v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210522000309.26134-6-s-anna@ti.com/ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 67 ++++++++++++++--------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 939c5d90b562..b3ee03da5569 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -2,7 +2,7 @@ /* * TI K3 DSP Remote Processor(s) driver * - * Copyright (C) 2018-2020 Texas Instruments Incorporated - https://www.ti.com/ + * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ * Suman Anna */ @@ -216,6 +216,43 @@ static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc) return ret; } +static int k3_dsp_rproc_request_mbox(struct rproc *rproc) +{ + struct k3_dsp_rproc *kproc = rproc->priv; + struct mbox_client *client = &kproc->client; + struct device *dev = kproc->dev; + int ret; + + client->dev = dev; + client->tx_done = NULL; + client->rx_callback = k3_dsp_rproc_mbox_callback; + client->tx_block = false; + client->knows_txdone = false; + + kproc->mbox = mbox_request_channel(client, 0); + if (IS_ERR(kproc->mbox)) { + ret = -EBUSY; + dev_err(dev, "mbox_request_channel failed: %ld\n", + PTR_ERR(kproc->mbox)); + return ret; + } + + /* + * Ping the remote processor, this is only for sanity-sake for now; + * there is no functional effect whatsoever. + * + * Note that the reply will _not_ arrive immediately: this message + * will wait in the mailbox fifo until the remote processor is booted. + */ + ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); + if (ret < 0) { + dev_err(dev, "mbox_send_message failed: %d\n", ret); + mbox_free_channel(kproc->mbox); + return ret; + } + + return 0; +} /* * The C66x DSP cores have a local reset that affects only the CPU, and a * generic module reset that powers on the device and allows the DSP internal @@ -273,37 +310,13 @@ static int k3_dsp_rproc_unprepare(struct rproc *rproc) static int k3_dsp_rproc_start(struct rproc *rproc) { struct k3_dsp_rproc *kproc = rproc->priv; - struct mbox_client *client = &kproc->client; struct device *dev = kproc->dev; u32 boot_addr; int ret; - client->dev = dev; - client->tx_done = NULL; - client->rx_callback = k3_dsp_rproc_mbox_callback; - client->tx_block = false; - client->knows_txdone = false; - - kproc->mbox = mbox_request_channel(client, 0); - if (IS_ERR(kproc->mbox)) { - ret = -EBUSY; - dev_err(dev, "mbox_request_channel failed: %ld\n", - PTR_ERR(kproc->mbox)); + ret = k3_dsp_rproc_request_mbox(rproc); + if (ret) return ret; - } - - /* - * Ping the remote processor, this is only for sanity-sake for now; - * there is no functional effect whatsoever. - * - * Note that the reply will _not_ arrive immediately: this message - * will wait in the mailbox fifo until the remote processor is booted. - */ - ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); - if (ret < 0) { - dev_err(dev, "mbox_send_message failed: %d\n", ret); - goto put_mbox; - } boot_addr = rproc->bootaddr; if (boot_addr & (kproc->data->boot_align_addr - 1)) { From patchwork Sun Feb 13 20:12:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 12744682 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B23C7C433EF for ; Sun, 13 Feb 2022 20:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=OVGC9WNnHqYaLDpFiIob068NAc8kQaJ5Na+9bFFuoYA=; b=Ztf3/BL++qiW6d OEe54uXgIV13sA1biMk6Go5BFEHcKzp4S8Z8wGQgDiD4YJrl0yi0/q8Hc4mStchkAmClxVlq1AHzL wPcLarkOn6D/ea6bohR14E+fCqH0xQpc3vmX1PQ4ngGBYSxXk95CX3YDQpIiAB1T56vfcS+EyvJGq se5no5/QPWNw5jT+IixfT/jEa3fDNoYLGv89jX8Ww64jDlTT6FCzHgXkoAt16d1bs1yweuJSzRBxQ Sgt/s2NNK6R5oUsb9QxkvAHpbpLIseuWYi4DW3NFnKJTCacPjMmwKvPBaqxSb68EpZkranZCKRxMC hsnaiJUjn3KnX3XEc4TQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLFX-00CSwG-QV; Sun, 13 Feb 2022 20:13:35 +0000 Received: from lelv0142.ext.ti.com ([198.47.23.249]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJLEs-00CSmt-HU for linux-arm-kernel@lists.infradead.org; Sun, 13 Feb 2022 20:12:58 +0000 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCosm017979; Sun, 13 Feb 2022 14:12:50 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1644783170; bh=Hezq1HwvYvPdObXSVdr7ef8Fd0u4XHVQ/eNP2Clqhcc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=abLnosUpx9EuhKJ7qvhQNs81vZEHNTeYOEtxe+e2ESxz86W3TGf8ubqndBtuphkVe LfXzHSrCk5ITFVLfK51r7NWoJrLLmWN22ISsdr2rU9opihLoyhxGJGaQeN+r4OWiZ5 c8klYqOBYWHbBEOrkczu0+4saQilPNQ51i4T/N/s= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 21DKCnwF065517 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 13 Feb 2022 14:12:50 -0600 Received: from DLEE115.ent.ti.com (157.170.170.26) 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; Sun, 13 Feb 2022 14:12:49 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE115.ent.ti.com (157.170.170.26) 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; Sun, 13 Feb 2022 14:12:49 -0600 Received: from lelv0854.itg.ti.com (lelv0854.itg.ti.com [10.181.64.140]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 21DKCnhj022115; Sun, 13 Feb 2022 14:12:49 -0600 Received: from localhost ([10.249.37.221]) by lelv0854.itg.ti.com (8.14.7/8.14.7) with ESMTP id 21DKCnQf002424; Sun, 13 Feb 2022 14:12:49 -0600 From: Suman Anna To: Bjorn Andersson , Mathieu Poirier Subject: [PATCH v3 5/5] remoteproc: k3-dsp: Add support for IPC-only mode for all K3 DSPs Date: Sun, 13 Feb 2022 14:12:46 -0600 Message-ID: <20220213201246.25952-6-s-anna@ti.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220213201246.25952-1-s-anna@ti.com> References: <20220213201246.25952-1-s-anna@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_121254_738707_C00D0846 X-CRM114-Status: GOOD ( 33.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Praneeth Bajjuri , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Hari Nagalla Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support to the K3 DSP remoteproc driver to configure all the C66x and C71x cores on J721E SoCs to be either in IPC-only mode or the traditional remoteproc mode. The IPC-only mode expects that the remote processors are already booted by the bootloader, and only perform the minimum steps required to initialize and deinitialize the virtio IPC transports. The remoteproc mode allows the kernel remoteproc driver to do the regular load and boot and other device management operations for a DSP. The IPC-only mode for a DSP is detected and configured at driver probe time by querying the System Firmware for the DSP power and reset state and/or status and making sure that the DSP is indeed started by the bootloaders, otherwise the device is configured for remoteproc mode. Support for IPC-only mode is achieved through .attach(), .detach() and .get_loaded_rsc_table() callback ops and zeroing out the regular rproc ops .prepare(), .unprepare(), .start() and .stop(). The resource table follows a design-by-contract approach and is expected to be at the base of the DDR firmware region reserved for each remoteproc, it is mostly expected to contain only the virtio device and trace resource entries. NOTE: The driver cannot configure a DSP core for remoteproc mode by any means without rebooting the kernel if that DSP core has been started by a bootloader. This is the current desired behavior and can be enhanced in the future if the feature is needed. Signed-off-by: Suman Anna --- v3: Revised version of v2 patch adjusted for dropping v2 Patch 1 - Added rproc_detach logic in k3_dsp_rproc_remove() before invoking rproc_del() v2: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210723220248.6554-6-s-anna@ti.com/ v1: https://patchwork.kernel.org/project/linux-remoteproc/patch/20210522000309.26134-7-s-anna@ti.com/ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 141 +++++++++++++++++++--- 1 file changed, 124 insertions(+), 17 deletions(-) diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index b3ee03da5569..eb9c64f7b9b4 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -260,7 +260,8 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc) * used to release the global reset on C66x DSPs to allow loading into the DSP * internal RAMs. The .prepare() ops is invoked by remoteproc core before any * firmware loading, and is followed by the .start() ops after loading to - * actually let the C66x DSP cores run. + * actually let the C66x DSP cores run. This callback is invoked only in + * remoteproc mode. */ static int k3_dsp_rproc_prepare(struct rproc *rproc) { @@ -284,7 +285,7 @@ static int k3_dsp_rproc_prepare(struct rproc *rproc) * powering down the C66x DSP cores. The cores themselves are only halted in the * .stop() callback through the local reset, and the .unprepare() ops is invoked * by the remoteproc core after the remoteproc is stopped to balance the global - * reset. + * reset. This callback is invoked only in remoteproc mode. */ static int k3_dsp_rproc_unprepare(struct rproc *rproc) { @@ -305,7 +306,7 @@ static int k3_dsp_rproc_unprepare(struct rproc *rproc) * * This function will be invoked only after the firmware for this rproc * was loaded, parsed successfully, and all of its resource requirements - * were met. + * were met. This callback is invoked only in remoteproc mode. */ static int k3_dsp_rproc_start(struct rproc *rproc) { @@ -346,7 +347,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc) * Stop the DSP remote processor. * * This function puts the DSP processor into reset, and finishes processing - * of any pending messages. + * of any pending messages. This callback is invoked only in remoteproc mode. */ static int k3_dsp_rproc_stop(struct rproc *rproc) { @@ -359,6 +360,78 @@ static int k3_dsp_rproc_stop(struct rproc *rproc) return 0; } +/* + * Attach to a running DSP remote processor (IPC-only mode) + * + * This rproc attach callback only needs to request the mailbox, the remote + * processor is already booted, so there is no need to issue any TI-SCI + * commands to boot the DSP core. This callback is invoked only in IPC-only + * mode. + */ +static int k3_dsp_rproc_attach(struct rproc *rproc) +{ + struct k3_dsp_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + int ret; + + ret = k3_dsp_rproc_request_mbox(rproc); + if (ret) + return ret; + + dev_info(dev, "DSP initialized in IPC-only mode\n"); + return 0; +} + +/* + * Detach from a running DSP remote processor (IPC-only mode) + * + * This rproc detach callback performs the opposite operation to attach callback + * and only needs to release the mailbox, the DSP core is not stopped and will + * be left to continue to run its booted firmware. This callback is invoked only + * in IPC-only mode. + */ +static int k3_dsp_rproc_detach(struct rproc *rproc) +{ + struct k3_dsp_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + + mbox_free_channel(kproc->mbox); + dev_info(dev, "DSP deinitialized in IPC-only mode\n"); + return 0; +} + +/* + * This function implements the .get_loaded_rsc_table() callback and is used + * to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP + * firmwares follow a design-by-contract approach and are expected to have the + * resource table at the base of the DDR region reserved for firmware usage. + * This provides flexibility for the remote processor to be booted by different + * bootloaders that may or may not have the ability to publish the resource table + * address and size through a DT property. This callback is invoked only in + * IPC-only mode. + */ +static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc, + size_t *rsc_table_sz) +{ + struct k3_dsp_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + + if (!kproc->rmem[0].cpu_addr) { + dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found"); + return ERR_PTR(-ENOMEM); + } + + /* + * NOTE: The resource table size is currently hard-coded to a maximum + * of 256 bytes. The most common resource table usage for K3 firmwares + * is to only have the vdev resource entry and an optional trace entry. + * The exact size could be computed based on resource table address, but + * the hard-coded value suffices to support the IPC-only mode. + */ + *rsc_table_sz = 256; + return (struct resource_table *)kproc->rmem[0].cpu_addr; +} + /* * Custom function to translate a DSP device address (internal RAMs only) to a * kernel virtual address. The DSPs can access their RAMs at either an internal @@ -605,6 +678,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) struct k3_dsp_rproc *kproc; struct rproc *rproc; const char *fw_name; + bool p_state = false; int ret = 0; int ret1; @@ -683,19 +757,43 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) goto release_tsp; } - /* - * ensure the DSP local reset is asserted to ensure the DSP doesn't - * execute bogus code in .prepare() when the module reset is released. - */ - if (data->uses_lreset) { - ret = reset_control_status(kproc->reset); - if (ret < 0) { - dev_err(dev, "failed to get reset status, status = %d\n", - ret); - goto release_mem; - } else if (ret == 0) { - dev_warn(dev, "local reset is deasserted for device\n"); - k3_dsp_rproc_reset(kproc); + ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id, + NULL, &p_state); + if (ret) { + dev_err(dev, "failed to get initial state, mode cannot be determined, ret = %d\n", + ret); + goto release_mem; + } + + /* configure J721E devices for either remoteproc or IPC-only mode */ + if (p_state) { + dev_info(dev, "configured DSP for IPC-only mode\n"); + rproc->state = RPROC_DETACHED; + /* override rproc ops with only required IPC-only mode ops */ + rproc->ops->prepare = NULL; + rproc->ops->unprepare = NULL; + rproc->ops->start = NULL; + rproc->ops->stop = NULL; + rproc->ops->attach = k3_dsp_rproc_attach; + rproc->ops->detach = k3_dsp_rproc_detach; + rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table; + } else { + dev_info(dev, "configured DSP for remoteproc mode\n"); + /* + * ensure the DSP local reset is asserted to ensure the DSP + * doesn't execute bogus code in .prepare() when the module + * reset is released. + */ + if (data->uses_lreset) { + ret = reset_control_status(kproc->reset); + if (ret < 0) { + dev_err(dev, "failed to get reset status, status = %d\n", + ret); + goto release_mem; + } else if (ret == 0) { + dev_warn(dev, "local reset is deasserted for device\n"); + k3_dsp_rproc_reset(kproc); + } } } @@ -730,9 +828,18 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) static int k3_dsp_rproc_remove(struct platform_device *pdev) { struct k3_dsp_rproc *kproc = platform_get_drvdata(pdev); + struct rproc *rproc = kproc->rproc; struct device *dev = &pdev->dev; int ret; + if (rproc->state == RPROC_ATTACHED) { + ret = rproc_detach(rproc); + if (ret) { + dev_err(dev, "failed to detach proc, ret = %d\n", ret); + return ret; + } + } + rproc_del(kproc->rproc); ret = ti_sci_proc_release(kproc->tsp);