From patchwork Mon Mar 17 12:05:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019128 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3A27233728; Mon, 17 Mar 2025 12:06:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213207; cv=none; b=grS9LpWGXeKIlJN7aIbHJ2/H7oJdGLEhPf+hOb/Jz3iArSVJ4P3PNqF1oTtiEP7jyohpYQ0BBC2/nbt5NiHd5NBIbG3Ntbmzw3z6A866WWfI9dqXxprIuls9qhFNTcE+XUgz6L0e3cHrDbYSh9qtxI5Yh+rrSonLRBeeAMjha1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213207; c=relaxed/simple; bh=s+yJxp49VF/mwK0XtZkFZkXqt/DFzILJbKyBePbaHK0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l25WFNurlP2zOWCB6y9aQIxKJf30GDiNgJ430n52jPh7775Z4jo0fuaBmxnnCcpexETMkqSAOLB71UnjixpWKtP7IWcmRCZxW3AM2WzCnZdEwJdf6a3B9fWGyR3y0G4yq6UbPmMUUMifxr6Wy8a8BgyWqjrlGdIDzheL7DOGdzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=hVgIajtK; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="hVgIajtK" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6ZeO2331215 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:06:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213196; bh=RTq9KbVztCwplzBxgIFcygBTDAf+k8lLRX80fGBWqS8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=hVgIajtK1EgzFkP7jQ9wvRSHr6XY+QuMyB6oWjBfEY0QeIoMQ+ea27B/L0sfXGLSw roZmBqK+S59iEUtIBrR76TcMjXxMYGSODlFpUkbUverOiDCIbS+tS+muCR112AMZln cxPXFCNRVqxoc/cVQe213OXRmZ+7JVXjR+xG5i2k= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6Zad032695 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:06:35 -0500 Received: from DLEE101.ent.ti.com (157.170.170.31) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:06:35 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:35 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MJw060901; Mon, 17 Mar 2025 07:06:32 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 01/26] remoteproc: k3-r5: Re-order internal memory initialization function Date: Mon, 17 Mar 2025 17:35:57 +0530 Message-ID: <20250317120622.1746415-2-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The core's internal memory data structure will be refactored to be part of the k3_r5_rproc structure in a future commit. As a result, internal memory initialization will need to be performed inside k3_r5_cluster_rproc_init() after rproc_alloc(). Therefore, move the internal memory initialization function, k3_r5_core_of_get_internal_memories() above k3_r5_rproc_init() so that it can be invoked from there. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 158 +++++++++++------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index dbc513c5569c..b2738b9a1b2d 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -1199,6 +1199,85 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) return ret; } +static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, + struct k3_r5_core *core) +{ + static const char * const mem_names[] = {"atcm", "btcm"}; + struct device *dev = &pdev->dev; + struct resource *res; + int num_mems; + int i; + + num_mems = ARRAY_SIZE(mem_names); + core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL); + if (!core->mem) + return -ENOMEM; + + for (i = 0; i < num_mems; i++) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + mem_names[i]); + if (!res) { + dev_err(dev, "found no memory resource for %s\n", + mem_names[i]); + return -EINVAL; + } + if (!devm_request_mem_region(dev, res->start, + resource_size(res), + dev_name(dev))) { + dev_err(dev, "could not request %s region for resource\n", + mem_names[i]); + return -EBUSY; + } + + /* + * TCMs are designed in general to support RAM-like backing + * memories. So, map these as Normal Non-Cached memories. This + * also avoids/fixes any potential alignment faults due to + * unaligned data accesses when using memcpy() or memset() + * functions (normally seen with device type memory). + */ + core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, + resource_size(res)); + if (!core->mem[i].cpu_addr) { + dev_err(dev, "failed to map %s memory\n", mem_names[i]); + return -ENOMEM; + } + core->mem[i].bus_addr = res->start; + + /* + * TODO: + * The R5F cores can place ATCM & BTCM anywhere in its address + * based on the corresponding Region Registers in the System + * Control coprocessor. For now, place ATCM and BTCM at + * addresses 0 and 0x41010000 (same as the bus address on AM65x + * SoCs) based on loczrama setting + */ + if (!strcmp(mem_names[i], "atcm")) { + core->mem[i].dev_addr = core->loczrama ? + 0 : K3_R5_TCM_DEV_ADDR; + } else { + core->mem[i].dev_addr = core->loczrama ? + K3_R5_TCM_DEV_ADDR : 0; + } + core->mem[i].size = resource_size(res); + + dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n", + mem_names[i], &core->mem[i].bus_addr, + core->mem[i].size, core->mem[i].cpu_addr, + core->mem[i].dev_addr); + } + core->num_mems = num_mems; + + return 0; +} + +static void k3_r5_release_tsp(void *data) +{ + struct ti_sci_proc *tsp = data; + + ti_sci_proc_release(tsp); +} + static int k3_r5_cluster_rproc_init(struct platform_device *pdev) { struct k3_r5_cluster *cluster = platform_get_drvdata(pdev); @@ -1358,78 +1437,6 @@ static void k3_r5_cluster_rproc_exit(void *data) } } -static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, - struct k3_r5_core *core) -{ - static const char * const mem_names[] = {"atcm", "btcm"}; - struct device *dev = &pdev->dev; - struct resource *res; - int num_mems; - int i; - - num_mems = ARRAY_SIZE(mem_names); - core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL); - if (!core->mem) - return -ENOMEM; - - for (i = 0; i < num_mems; i++) { - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - mem_names[i]); - if (!res) { - dev_err(dev, "found no memory resource for %s\n", - mem_names[i]); - return -EINVAL; - } - if (!devm_request_mem_region(dev, res->start, - resource_size(res), - dev_name(dev))) { - dev_err(dev, "could not request %s region for resource\n", - mem_names[i]); - return -EBUSY; - } - - /* - * TCMs are designed in general to support RAM-like backing - * memories. So, map these as Normal Non-Cached memories. This - * also avoids/fixes any potential alignment faults due to - * unaligned data accesses when using memcpy() or memset() - * functions (normally seen with device type memory). - */ - core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, - resource_size(res)); - if (!core->mem[i].cpu_addr) { - dev_err(dev, "failed to map %s memory\n", mem_names[i]); - return -ENOMEM; - } - core->mem[i].bus_addr = res->start; - - /* - * TODO: - * The R5F cores can place ATCM & BTCM anywhere in its address - * based on the corresponding Region Registers in the System - * Control coprocessor. For now, place ATCM and BTCM at - * addresses 0 and 0x41010000 (same as the bus address on AM65x - * SoCs) based on loczrama setting - */ - if (!strcmp(mem_names[i], "atcm")) { - core->mem[i].dev_addr = core->loczrama ? - 0 : K3_R5_TCM_DEV_ADDR; - } else { - core->mem[i].dev_addr = core->loczrama ? - K3_R5_TCM_DEV_ADDR : 0; - } - core->mem[i].size = resource_size(res); - - dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - mem_names[i], &core->mem[i].bus_addr, - core->mem[i].size, core->mem[i].cpu_addr, - core->mem[i].dev_addr); - } - core->num_mems = num_mems; - - return 0; -} - static int k3_r5_core_of_get_sram_memories(struct platform_device *pdev, struct k3_r5_core *core) { @@ -1487,13 +1494,6 @@ static int k3_r5_core_of_get_sram_memories(struct platform_device *pdev, return 0; } -static void k3_r5_release_tsp(void *data) -{ - struct ti_sci_proc *tsp = data; - - ti_sci_proc_release(tsp); -} - static int k3_r5_core_of_init(struct platform_device *pdev) { struct device *dev = &pdev->dev; From patchwork Mon Mar 17 12:05:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019131 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E88FC2376ED; Mon, 17 Mar 2025 12:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213218; cv=none; b=H2OoA5VW08N6u5/lRXOUg+zhO6PYpSPe2gQBhqnrO3bNQSSCO7H1Yw2v4+ly4QFsrpxqORNfIGgJUUmkc3rWB4qyLkm/dHTAWc2HZ2SV2noUkWqBi1PNKxmRb98F55XrbAWJNX05YmFcLdtcUOZBW2T0Z0Ars4RJ1oEWrbPL3Og= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213218; c=relaxed/simple; bh=EFon17fl/5f8yHsJej4/n8l9GJ9B6kMnolTP8FnwSN0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bz4wwqeOThkYPwjqd6/aEtyGLjtASmO5402YBPHjwvV5Pw4N4n0vCmwiv+xfP9DJTjQkYKNcTkL+HDDQaVbiN1OxeeTux06Nmzi+WafLRTYEQrzwQZee2prcrycUsh4Ba+t+/1R2J8sybKsWabi2adFhfjMpkcQCa0fhtXgFLl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=hfdQgdQe; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="hfdQgdQe" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6djM2802821 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:06:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213199; bh=75ALpHD6hyMFusAZx5Lv3Z1J6hg9kA9b1BiofihXObM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=hfdQgdQerThMAtvuufWfVuQftfx1PaY8+LicnsEilBTzDzhGQkDUu94Kmcg5FhXi8 ZGxBVH6es7Jt6uturHy4Dn5nK2mOtSGb3jVubz/mdaYn8l9sUhmzH3xvRyA4Xi8YX6 hLK3YkrFOYNxofJtwvzF/qP4rV3lSsSvcU3y9LBU= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6dqp004905; Mon, 17 Mar 2025 07:06:39 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:06:39 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:39 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MJx060901; Mon, 17 Mar 2025 07:06:35 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 02/26] remoteproc: k3-r5: Refactor Data Structures to Align with DSP and M4 Date: Mon, 17 Mar 2025 17:35:58 +0530 Message-ID: <20250317120622.1746415-3-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Currently, struct members such as mem, num_mems, reset, tsp, ti_sci and ti_sci_id are part of the k3_r5_core structure. To align the rproc->priv data structure of the R5 remote processor with that of the DSP and M4, move the above members from k3_r5_core to k3_r5_rproc. Additionally, introduce a void *priv pointer in k3_r5_rproc that can be typecasted to point to the k3_r5_core structure. This abstraction is done to ensure common functionalities across R5, DSP and M4 drivers can be refactored at a later stage. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 381 ++++++++++++----------- 1 file changed, 198 insertions(+), 183 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index b2738b9a1b2d..525f26996b56 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -114,19 +114,16 @@ struct k3_r5_cluster { const struct k3_r5_soc_data *soc_data; }; +struct k3_r5_rproc; + /** * struct k3_r5_core - K3 R5 core structure * @elem: linked list item * @dev: cached device pointer - * @rproc: rproc handle representing this core - * @mem: internal memory regions data + * @kproc: K3 rproc handle representing this core + * @cluster: cached pointer to parent cluster structure * @sram: on-chip SRAM memory regions data - * @num_mems: number of internal memory regions * @num_sram: number of on-chip SRAM memory regions - * @reset: reset control handle - * @tsp: TI-SCI processor control handle - * @ti_sci: TI-SCI handle - * @ti_sci_id: TI-SCI device identifier * @atcm_enable: flag to control ATCM enablement * @btcm_enable: flag to control BTCM enablement * @loczrama: flag to dictate which TCM is at device address 0x0 @@ -135,15 +132,10 @@ struct k3_r5_cluster { struct k3_r5_core { struct list_head elem; struct device *dev; - struct rproc *rproc; - struct k3_r5_mem *mem; + struct k3_r5_rproc *kproc; + struct k3_r5_cluster *cluster; struct k3_r5_mem *sram; - int num_mems; int num_sram; - struct reset_control *reset; - struct ti_sci_proc *tsp; - const struct ti_sci_handle *ti_sci; - u32 ti_sci_id; u32 atcm_enable; u32 btcm_enable; u32 loczrama; @@ -153,23 +145,33 @@ struct k3_r5_core { /** * struct k3_r5_rproc - K3 remote processor state * @dev: cached device pointer - * @cluster: cached pointer to parent cluster structure - * @mbox: mailbox channel handle - * @client: mailbox client to request the mailbox channel * @rproc: rproc handle - * @core: cached pointer to r5 core structure being used + * @mem: internal memory regions data + * @num_mems: number of internal memory regions * @rmem: reserved memory regions data * @num_rmems: number of reserved memory regions + * @reset: reset control handle + * @tsp: TI-SCI processor control handle + * @ti_sci: TI-SCI handle + * @ti_sci_id: TI-SCI device identifier + * @mbox: mailbox channel handle + * @client: mailbox client to request the mailbox channel + * @priv: Remote processor private data */ struct k3_r5_rproc { struct device *dev; - struct k3_r5_cluster *cluster; - struct mbox_chan *mbox; - struct mbox_client client; struct rproc *rproc; - struct k3_r5_core *core; + struct k3_r5_mem *mem; + int num_mems; struct k3_r5_mem *rmem; int num_rmems; + struct reset_control *reset; + struct ti_sci_proc *tsp; + const struct ti_sci_handle *ti_sci; + u32 ti_sci_id; + struct mbox_chan *mbox; + struct mbox_client client; + void *priv; }; /** @@ -244,48 +246,48 @@ static void k3_r5_rproc_kick(struct rproc *rproc, int vqid) ret); } -static int k3_r5_split_reset(struct k3_r5_core *core) +static int k3_r5_split_reset(struct k3_r5_rproc *kproc) { int ret; - ret = reset_control_assert(core->reset); + ret = reset_control_assert(kproc->reset); if (ret) { - dev_err(core->dev, "local-reset assert failed, ret = %d\n", + dev_err(kproc->dev, "local-reset assert failed, ret = %d\n", ret); return ret; } - ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci, - core->ti_sci_id); + ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id); if (ret) { - dev_err(core->dev, "module-reset assert failed, ret = %d\n", + dev_err(kproc->dev, "module-reset assert failed, ret = %d\n", ret); - if (reset_control_deassert(core->reset)) - dev_warn(core->dev, "local-reset deassert back failed\n"); + if (reset_control_deassert(kproc->reset)) + dev_warn(kproc->dev, "local-reset deassert back failed\n"); } return ret; } -static int k3_r5_split_release(struct k3_r5_core *core) +static int k3_r5_split_release(struct k3_r5_rproc *kproc) { int ret; - ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci, - core->ti_sci_id); + ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, + kproc->ti_sci_id); if (ret) { - dev_err(core->dev, "module-reset deassert failed, ret = %d\n", + dev_err(kproc->dev, "module-reset deassert failed, ret = %d\n", ret); return ret; } - ret = reset_control_deassert(core->reset); + ret = reset_control_deassert(kproc->reset); if (ret) { - dev_err(core->dev, "local-reset deassert failed, ret = %d\n", + dev_err(kproc->dev, "local-reset deassert failed, ret = %d\n", ret); - if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, - core->ti_sci_id)) - dev_warn(core->dev, "module-reset assert back failed\n"); + if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id)) + dev_warn(kproc->dev, "module-reset assert back failed\n"); } return ret; @@ -294,11 +296,12 @@ static int k3_r5_split_release(struct k3_r5_core *core) static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster) { struct k3_r5_core *core; + struct k3_r5_rproc *kproc; int ret; /* assert local reset on all applicable cores */ list_for_each_entry(core, &cluster->cores, elem) { - ret = reset_control_assert(core->reset); + ret = reset_control_assert(core->kproc->reset); if (ret) { dev_err(core->dev, "local-reset assert failed, ret = %d\n", ret); @@ -309,8 +312,9 @@ static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster) /* disable PSC modules on all applicable cores */ list_for_each_entry(core, &cluster->cores, elem) { - ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci, - core->ti_sci_id); + kproc = core->kproc; + ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id); if (ret) { dev_err(core->dev, "module-reset assert failed, ret = %d\n", ret); @@ -322,14 +326,15 @@ static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster) unroll_module_reset: list_for_each_entry_continue_reverse(core, &cluster->cores, elem) { - if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, - core->ti_sci_id)) + kproc = core->kproc; + if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id)) dev_warn(core->dev, "module-reset assert back failed\n"); } core = list_last_entry(&cluster->cores, struct k3_r5_core, elem); unroll_local_reset: list_for_each_entry_from_reverse(core, &cluster->cores, elem) { - if (reset_control_deassert(core->reset)) + if (reset_control_deassert(core->kproc->reset)) dev_warn(core->dev, "local-reset deassert back failed\n"); } @@ -339,12 +344,14 @@ static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster) static int k3_r5_lockstep_release(struct k3_r5_cluster *cluster) { struct k3_r5_core *core; + struct k3_r5_rproc *kproc; int ret; /* enable PSC modules on all applicable cores */ list_for_each_entry_reverse(core, &cluster->cores, elem) { - ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci, - core->ti_sci_id); + kproc = core->kproc; + ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, + kproc->ti_sci_id); if (ret) { dev_err(core->dev, "module-reset deassert failed, ret = %d\n", ret); @@ -355,7 +362,7 @@ static int k3_r5_lockstep_release(struct k3_r5_cluster *cluster) /* deassert local reset on all applicable cores */ list_for_each_entry_reverse(core, &cluster->cores, elem) { - ret = reset_control_deassert(core->reset); + ret = reset_control_deassert(core->kproc->reset); if (ret) { dev_err(core->dev, "module-reset deassert failed, ret = %d\n", ret); @@ -367,29 +374,30 @@ static int k3_r5_lockstep_release(struct k3_r5_cluster *cluster) unroll_local_reset: list_for_each_entry_continue(core, &cluster->cores, elem) { - if (reset_control_assert(core->reset)) + if (reset_control_assert(core->kproc->reset)) dev_warn(core->dev, "local-reset assert back failed\n"); } core = list_first_entry(&cluster->cores, struct k3_r5_core, elem); unroll_module_reset: list_for_each_entry_from(core, &cluster->cores, elem) { - if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, - core->ti_sci_id)) + kproc = core->kproc; + if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id)) dev_warn(core->dev, "module-reset assert back failed\n"); } return ret; } -static inline int k3_r5_core_halt(struct k3_r5_core *core) +static inline int k3_r5_core_halt(struct k3_r5_rproc *kproc) { - return ti_sci_proc_set_control(core->tsp, + return ti_sci_proc_set_control(kproc->tsp, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT, 0); } -static inline int k3_r5_core_run(struct k3_r5_core *core) +static inline int k3_r5_core_run(struct k3_r5_rproc *kproc) { - return ti_sci_proc_set_control(core->tsp, + return ti_sci_proc_set_control(kproc->tsp, 0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT); } @@ -447,15 +455,15 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc) static int k3_r5_rproc_prepare(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_cluster *cluster = kproc->cluster; - struct k3_r5_core *core = kproc->core; + struct k3_r5_core *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; u32 ctrl = 0, cfg = 0, stat = 0; u64 boot_vec = 0; bool mem_init_dis; int ret; - ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, &stat); + ret = ti_sci_proc_get_status(kproc->tsp, &boot_vec, &cfg, &ctrl, &stat); if (ret < 0) return ret; mem_init_dis = !!(cfg & PROC_BOOT_CFG_FLAG_R5_MEM_INIT_DIS); @@ -463,7 +471,7 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) /* Re-use LockStep-mode reset logic for Single-CPU mode */ ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || cluster->mode == CLUSTER_MODE_SINGLECPU) ? - k3_r5_lockstep_release(cluster) : k3_r5_split_release(core); + k3_r5_lockstep_release(cluster) : k3_r5_split_release(kproc); if (ret) { dev_err(dev, "unable to enable cores for TCM loading, ret = %d\n", ret); @@ -487,10 +495,10 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) * can be effective on all TCM addresses. */ dev_dbg(dev, "zeroing out ATCM memory\n"); - memset_io(core->mem[0].cpu_addr, 0x00, core->mem[0].size); + memset_io(kproc->mem[0].cpu_addr, 0x00, kproc->mem[0].size); dev_dbg(dev, "zeroing out BTCM memory\n"); - memset_io(core->mem[1].cpu_addr, 0x00, core->mem[1].size); + memset_io(kproc->mem[1].cpu_addr, 0x00, kproc->mem[1].size); return 0; } @@ -514,15 +522,15 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) static int k3_r5_rproc_unprepare(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_cluster *cluster = kproc->cluster; - struct k3_r5_core *core = kproc->core; + struct k3_r5_core *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; int ret; /* Re-use LockStep-mode reset logic for Single-CPU mode */ ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || cluster->mode == CLUSTER_MODE_SINGLECPU) ? - k3_r5_lockstep_reset(cluster) : k3_r5_split_reset(core); + k3_r5_lockstep_reset(cluster) : k3_r5_split_reset(kproc); if (ret) dev_err(dev, "unable to disable cores, ret = %d\n", ret); @@ -549,9 +557,9 @@ static int k3_r5_rproc_unprepare(struct rproc *rproc) static int k3_r5_rproc_start(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_cluster *cluster = kproc->cluster; + struct k3_r5_core *core0, *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; - struct k3_r5_core *core0, *core; u32 boot_addr; int ret; @@ -560,15 +568,14 @@ static int k3_r5_rproc_start(struct rproc *rproc) dev_dbg(dev, "booting R5F core using boot addr = 0x%x\n", boot_addr); /* boot vector need not be programmed for Core1 in LockStep mode */ - core = kproc->core; - ret = ti_sci_proc_set_config(core->tsp, boot_addr, 0, 0); + ret = ti_sci_proc_set_config(kproc->tsp, boot_addr, 0, 0); if (ret) return ret; /* unhalt/run all applicable cores */ if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { list_for_each_entry_reverse(core, &cluster->cores, elem) { - ret = k3_r5_core_run(core); + ret = k3_r5_core_run(core->kproc); if (ret) goto unroll_core_run; } @@ -576,13 +583,13 @@ static int k3_r5_rproc_start(struct rproc *rproc) /* do not allow core 1 to start before core 0 */ core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); - if (core != core0 && core0->rproc->state == RPROC_OFFLINE) { + if (core != core0 && core0->kproc->rproc->state == RPROC_OFFLINE) { dev_err(dev, "%s: can not start core 1 before core 0\n", __func__); return -EPERM; } - ret = k3_r5_core_run(core); + ret = k3_r5_core_run(core->kproc); if (ret) return ret; @@ -594,7 +601,7 @@ static int k3_r5_rproc_start(struct rproc *rproc) unroll_core_run: list_for_each_entry_continue(core, &cluster->cores, elem) { - if (k3_r5_core_halt(core)) + if (k3_r5_core_halt(core->kproc)) dev_warn(core->dev, "core halt back failed\n"); } return ret; @@ -627,15 +634,15 @@ static int k3_r5_rproc_start(struct rproc *rproc) static int k3_r5_rproc_stop(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_cluster *cluster = kproc->cluster; + struct k3_r5_core *core1, *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; - struct k3_r5_core *core1, *core = kproc->core; int ret; /* halt all applicable cores */ if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { list_for_each_entry(core, &cluster->cores, elem) { - ret = k3_r5_core_halt(core); + ret = k3_r5_core_halt(core->kproc); if (ret) { core = list_prev_entry(core, elem); goto unroll_core_halt; @@ -645,14 +652,14 @@ static int k3_r5_rproc_stop(struct rproc *rproc) /* do not allow core 0 to stop before core 1 */ core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); - if (core != core1 && core1->rproc->state != RPROC_OFFLINE) { + if (core != core1 && core1->kproc->rproc->state != RPROC_OFFLINE) { dev_err(dev, "%s: can not stop core 0 before core 1\n", __func__); ret = -EPERM; goto out; } - ret = k3_r5_core_halt(core); + ret = k3_r5_core_halt(core->kproc); if (ret) goto out; } @@ -661,7 +668,7 @@ static int k3_r5_rproc_stop(struct rproc *rproc) unroll_core_halt: list_for_each_entry_from_reverse(core, &cluster->cores, elem) { - if (k3_r5_core_run(core)) + if (k3_r5_core_run(core->kproc)) dev_warn(core->dev, "core run back failed\n"); } out: @@ -731,7 +738,7 @@ static struct resource_table *k3_r5_get_loaded_rsc_table(struct rproc *rproc, static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_core *core = kproc->core; + struct k3_r5_core *core = kproc->priv; void __iomem *va = NULL; phys_addr_t bus_addr; u32 dev_addr, offset; @@ -742,22 +749,22 @@ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool return NULL; /* handle both R5 and SoC views of ATCM and BTCM */ - for (i = 0; i < core->num_mems; i++) { - bus_addr = core->mem[i].bus_addr; - dev_addr = core->mem[i].dev_addr; - size = core->mem[i].size; + for (i = 0; i < kproc->num_mems; i++) { + bus_addr = kproc->mem[i].bus_addr; + dev_addr = kproc->mem[i].dev_addr; + size = kproc->mem[i].size; /* handle R5-view addresses of TCMs */ if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { offset = da - dev_addr; - va = core->mem[i].cpu_addr + offset; + va = kproc->mem[i].cpu_addr + offset; return (__force void *)va; } /* handle SoC-view addresses of TCMs */ if (da >= bus_addr && ((da + len) <= (bus_addr + size))) { offset = da - bus_addr; - va = core->mem[i].cpu_addr + offset; + va = kproc->mem[i].cpu_addr + offset; return (__force void *)va; } } @@ -835,9 +842,9 @@ static const struct rproc_ops k3_r5_rproc_ops = { */ static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc) { - struct k3_r5_cluster *cluster = kproc->cluster; + struct k3_r5_core *temp, *core0, *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; - struct k3_r5_core *core0, *core, *temp; u32 ctrl = 0, cfg = 0, stat = 0; u32 set_cfg = 0, clr_cfg = 0; u64 boot_vec = 0; @@ -851,10 +858,10 @@ static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc) cluster->mode == CLUSTER_MODE_SINGLECORE) { core = core0; } else { - core = kproc->core; + core = kproc->priv; } - ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, + ret = ti_sci_proc_get_status(core->kproc->tsp, &boot_vec, &cfg, &ctrl, &stat); if (ret < 0) return ret; @@ -924,7 +931,7 @@ static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc) * and TEINIT config is only allowed with Core0. */ list_for_each_entry(temp, &cluster->cores, elem) { - ret = k3_r5_core_halt(temp); + ret = k3_r5_core_halt(temp->kproc); if (ret) goto out; @@ -932,7 +939,7 @@ static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc) clr_cfg &= ~PROC_BOOT_CFG_FLAG_R5_LOCKSTEP; clr_cfg &= ~PROC_BOOT_CFG_FLAG_R5_TEINIT; } - ret = ti_sci_proc_set_config(temp->tsp, boot_vec, + ret = ti_sci_proc_set_config(temp->kproc->tsp, boot_vec, set_cfg, clr_cfg); if (ret) goto out; @@ -940,14 +947,14 @@ static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc) set_cfg = PROC_BOOT_CFG_FLAG_R5_LOCKSTEP; clr_cfg = 0; - ret = ti_sci_proc_set_config(core->tsp, boot_vec, + ret = ti_sci_proc_set_config(core->kproc->tsp, boot_vec, set_cfg, clr_cfg); } else { - ret = k3_r5_core_halt(core); + ret = k3_r5_core_halt(core->kproc); if (ret) goto out; - ret = ti_sci_proc_set_config(core->tsp, boot_vec, + ret = ti_sci_proc_set_config(core->kproc->tsp, boot_vec, set_cfg, clr_cfg); } @@ -1057,10 +1064,9 @@ static int k3_r5_reserved_mem_init(struct k3_r5_rproc *kproc) */ static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc) { - struct k3_r5_cluster *cluster = kproc->cluster; - struct k3_r5_core *core = kproc->core; + struct k3_r5_core *core0, *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *cdev = core->dev; - struct k3_r5_core *core0; if (cluster->mode == CLUSTER_MODE_LOCKSTEP || cluster->mode == CLUSTER_MODE_SINGLECPU || @@ -1070,14 +1076,14 @@ static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc) core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); if (core == core0) { - WARN_ON(core->mem[0].size != SZ_64K); - WARN_ON(core->mem[1].size != SZ_64K); + WARN_ON(kproc->mem[0].size != SZ_64K); + WARN_ON(kproc->mem[1].size != SZ_64K); - core->mem[0].size /= 2; - core->mem[1].size /= 2; + kproc->mem[0].size /= 2; + kproc->mem[1].size /= 2; dev_dbg(cdev, "adjusted TCM sizes, ATCM = 0x%zx BTCM = 0x%zx\n", - core->mem[0].size, core->mem[1].size); + kproc->mem[0].size, kproc->mem[1].size); } } @@ -1096,22 +1102,21 @@ static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc) */ 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 k3_r5_core *core0, *core = kproc->priv; + struct k3_r5_cluster *cluster = core->cluster; struct device *cdev = core->dev; bool r_state = false, c_state = false, lockstep_en = false, single_cpu = 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 = cluster->mode; int reset_ctrl_status; 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); + ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->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); @@ -1122,7 +1127,7 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) r_state, c_state); } - reset_ctrl_status = reset_control_status(core->reset); + reset_ctrl_status = reset_control_status(kproc->reset); if (reset_ctrl_status < 0) { dev_err(cdev, "failed to get initial local reset status, ret = %d\n", reset_ctrl_status); @@ -1135,7 +1140,7 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) */ core->released_from_reset = c_state; - ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, + ret = ti_sci_proc_get_status(kproc->tsp, &boot_vec, &cfg, &ctrl, &stat); if (ret < 0) { dev_err(cdev, "failed to get initial processor status, ret = %d\n", @@ -1192,25 +1197,26 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) 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; + kproc->mem[0].dev_addr = loczrama ? 0 : K3_R5_TCM_DEV_ADDR; + kproc->mem[1].dev_addr = loczrama ? K3_R5_TCM_DEV_ADDR : 0; } return ret; } static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, - struct k3_r5_core *core) + struct k3_r5_rproc *kproc) { static const char * const mem_names[] = {"atcm", "btcm"}; struct device *dev = &pdev->dev; + struct k3_r5_core *core = kproc->priv; struct resource *res; int num_mems; int i; num_mems = ARRAY_SIZE(mem_names); - core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL); - if (!core->mem) + kproc->mem = devm_kcalloc(dev, num_mems, sizeof(*kproc->mem), GFP_KERNEL); + if (!kproc->mem) return -ENOMEM; for (i = 0; i < num_mems; i++) { @@ -1236,13 +1242,13 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, * unaligned data accesses when using memcpy() or memset() * functions (normally seen with device type memory). */ - core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, - resource_size(res)); - if (!core->mem[i].cpu_addr) { + kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, + resource_size(res)); + if (!kproc->mem[i].cpu_addr) { dev_err(dev, "failed to map %s memory\n", mem_names[i]); return -ENOMEM; } - core->mem[i].bus_addr = res->start; + kproc->mem[i].bus_addr = res->start; /* * TODO: @@ -1253,20 +1259,20 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, * SoCs) based on loczrama setting */ if (!strcmp(mem_names[i], "atcm")) { - core->mem[i].dev_addr = core->loczrama ? + kproc->mem[i].dev_addr = core->loczrama ? 0 : K3_R5_TCM_DEV_ADDR; } else { - core->mem[i].dev_addr = core->loczrama ? + kproc->mem[i].dev_addr = core->loczrama ? K3_R5_TCM_DEV_ADDR : 0; } - core->mem[i].size = resource_size(res); + kproc->mem[i].size = resource_size(res); dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - mem_names[i], &core->mem[i].bus_addr, - core->mem[i].size, core->mem[i].cpu_addr, - core->mem[i].dev_addr); + mem_names[i], &kproc->mem[i].bus_addr, + kproc->mem[i].size, kproc->mem[i].cpu_addr, + kproc->mem[i].dev_addr); } - core->num_mems = num_mems; + kproc->num_mems = num_mems; return 0; } @@ -1284,6 +1290,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) struct device *dev = &pdev->dev; struct k3_r5_rproc *kproc; struct k3_r5_core *core, *core1; + struct device_node *np; struct device *cdev; const char *fw_name; struct rproc *rproc; @@ -1292,6 +1299,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); list_for_each_entry(core, &cluster->cores, elem) { cdev = core->dev; + np = dev_of_node(cdev); ret = rproc_of_parse_firmware(cdev, 0, &fw_name); if (ret) { dev_err(dev, "failed to parse firmware-name property, ret = %d\n", @@ -1312,11 +1320,63 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) rproc->recovery_disabled = true; kproc = rproc->priv; - kproc->cluster = cluster; - kproc->core = core; + kproc->priv = core; kproc->dev = cdev; kproc->rproc = rproc; - core->rproc = rproc; + core->kproc = kproc; + + kproc->ti_sci = devm_ti_sci_get_by_phandle(cdev, "ti,sci"); + if (IS_ERR(kproc->ti_sci)) { + ret = dev_err_probe(cdev, PTR_ERR(kproc->ti_sci), + "failed to get ti-sci handle\n"); + kproc->ti_sci = NULL; + goto out; + } + + ret = of_property_read_u32(np, "ti,sci-dev-id", &kproc->ti_sci_id); + if (ret) { + dev_err(cdev, "missing 'ti,sci-dev-id' property\n"); + goto out; + } + + kproc->reset = devm_reset_control_get_exclusive(cdev, NULL); + if (IS_ERR_OR_NULL(kproc->reset)) { + ret = PTR_ERR_OR_ZERO(kproc->reset); + if (!ret) + ret = -ENODEV; + dev_err_probe(cdev, ret, "failed to get reset handle\n"); + goto out; + } + + kproc->tsp = ti_sci_proc_of_get_tsp(cdev, kproc->ti_sci); + if (IS_ERR(kproc->tsp)) { + ret = dev_err_probe(cdev, PTR_ERR(kproc->tsp), + "failed to construct ti-sci proc control\n"); + goto out; + } + + ret = k3_r5_core_of_get_internal_memories(to_platform_device(cdev), kproc); + if (ret) { + dev_err(cdev, "failed to get internal memories, ret = %d\n", + ret); + goto out; + } + + ret = ti_sci_proc_request(kproc->tsp); + if (ret < 0) { + dev_err(cdev, "ti_sci_proc_request failed, ret = %d\n", ret); + goto out; + } + + ret = devm_add_action_or_reset(cdev, k3_r5_release_tsp, kproc->tsp); + if (ret) + goto out; + } + + list_for_each_entry(core, &cluster->cores, elem) { + cdev = core->dev; + kproc = core->kproc; + rproc = kproc->rproc; ret = k3_r5_rproc_request_mbox(rproc); if (ret) @@ -1330,7 +1390,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) ret = k3_r5_rproc_configure(kproc); if (ret) { - dev_err(dev, "initial configure failed, ret = %d\n", + dev_err(cdev, "initial configure failed, ret = %d\n", ret); goto out; } @@ -1340,14 +1400,14 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) ret = k3_r5_reserved_mem_init(kproc); if (ret) { - dev_err(dev, "reserved memory init failed, ret = %d\n", + dev_err(cdev, "reserved memory init failed, ret = %d\n", ret); goto out; } - ret = devm_rproc_add(dev, rproc); + ret = devm_rproc_add(cdev, rproc); if (ret) { - dev_err_probe(dev, ret, "rproc_add failed\n"); + dev_err_probe(cdev, ret, "rproc_add failed\n"); goto out; } @@ -1373,7 +1433,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) core->released_from_reset, msecs_to_jiffies(2000)); if (ret <= 0) { - dev_err(dev, + dev_err(cdev, "Timed out waiting for %s core to power up!\n", rproc->name); goto out; @@ -1396,8 +1456,8 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) /* undo core0 upon any failures on core1 in split-mode */ if (cluster->mode == CLUSTER_MODE_SPLIT && core == core1) { core = list_prev_entry(core, elem); - rproc = core->rproc; - kproc = rproc->priv; + kproc = core->kproc; + rproc = kproc->rproc; goto err_split; } return ret; @@ -1422,8 +1482,8 @@ static void k3_r5_cluster_rproc_exit(void *data) list_last_entry(&cluster->cores, struct k3_r5_core, elem); list_for_each_entry_from_reverse(core, &cluster->cores, elem) { - rproc = core->rproc; - kproc = rproc->priv; + kproc = core->kproc; + rproc = kproc->rproc; if (rproc->state == RPROC_ATTACHED) { ret = rproc_detach(rproc); @@ -1539,58 +1599,12 @@ static int k3_r5_core_of_init(struct platform_device *pdev) goto err; } - core->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); - if (IS_ERR(core->ti_sci)) { - ret = dev_err_probe(dev, PTR_ERR(core->ti_sci), "failed to get ti-sci handle\n"); - core->ti_sci = NULL; - goto err; - } - - ret = of_property_read_u32(np, "ti,sci-dev-id", &core->ti_sci_id); - if (ret) { - dev_err(dev, "missing 'ti,sci-dev-id' property\n"); - goto err; - } - - core->reset = devm_reset_control_get_exclusive(dev, NULL); - if (IS_ERR_OR_NULL(core->reset)) { - ret = PTR_ERR_OR_ZERO(core->reset); - if (!ret) - ret = -ENODEV; - dev_err_probe(dev, ret, "failed to get reset handle\n"); - goto err; - } - - core->tsp = ti_sci_proc_of_get_tsp(dev, core->ti_sci); - if (IS_ERR(core->tsp)) { - ret = dev_err_probe(dev, PTR_ERR(core->tsp), - "failed to construct ti-sci proc control\n"); - goto err; - } - - ret = k3_r5_core_of_get_internal_memories(pdev, core); - if (ret) { - dev_err(dev, "failed to get internal memories, ret = %d\n", - ret); - goto err; - } - ret = k3_r5_core_of_get_sram_memories(pdev, core); if (ret) { dev_err(dev, "failed to get sram memories, ret = %d\n", ret); goto err; } - ret = ti_sci_proc_request(core->tsp); - if (ret < 0) { - dev_err(dev, "ti_sci_proc_request failed, ret = %d\n", ret); - goto err; - } - - ret = devm_add_action_or_reset(dev, k3_r5_release_tsp, core->tsp); - if (ret) - goto err; - platform_set_drvdata(pdev, core); devres_close_group(dev, k3_r5_core_of_init); @@ -1652,6 +1666,7 @@ static int k3_r5_cluster_of_init(struct platform_device *pdev) } core = platform_get_drvdata(cpdev); + core->cluster = cluster; put_device(&cpdev->dev); list_add_tail(&core->elem, &cluster->cores); } From patchwork Mon Mar 17 12:05:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019129 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86C05158DA3; Mon, 17 Mar 2025 12:06:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213216; cv=none; b=F6hXibowoSC9CU5xMxj2yyGPAYuDrP8EE31X4EQzOfhGbvWtlYHIBDkx7oVVfOoQkJyNIwJ1LgF95ufoGoOrazvWaljKoPqXxjSdKkswLyLytnJGC3nVZtSzZyAzB6IFji3T//992Vjao5hImT8Slw81f1BgXjyiD6p2WcinicE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213216; c=relaxed/simple; bh=BPeTsao/CI9iFCaJIKL+Je3Pb+9ZJWaiRaaVYcgcfnk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gH3LNxE2/1/A6ck1RzWEVvgE9akuiF8TgHfwyaDOcpnOCw3IfkN8TDeM4+5g0IFDwMgTxpPxilkgi7d+E/eHKNNLn1o6ge0rWRqCjxX+suP/qol/KSc16Lw0SI4mt9tZanHjayvtnb22vtoHmv9ucbPHiP8PsPz3UVBFtESMHlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=afL51ZRq; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="afL51ZRq" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6h352266609 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:06:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213203; bh=iGimkSxYNA9BThU4h1cp/WR44F+7o3nXZTSdOlQwL5g=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=afL51ZRqdNXbGmLxB/E0ypWZG/FLqsThFRZvEBdBcwjw0mTCn+IUlaFw+HUPPP2xu fIYp5j8UM5VIL14PUWhEMENvaZrvrUtJzQNIo1unkkMjn2kDhshF6FbYHv4uTF/A90 VtQqLgn77LJQc747SV8yL0jlqPa2u6zrFBqjf+VI= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6hJt032735 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:06:43 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:06:43 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:42 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK0060901; Mon, 17 Mar 2025 07:06:39 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 03/26] remoteproc: k3-r5: Use k3_r5_rproc_mem_data structure for memory info Date: Mon, 17 Mar 2025 17:35:59 +0530 Message-ID: <20250317120622.1746415-4-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The ti_k3_r5_remoteproc.c driver previously hardcoded device memory region addresses and names. Change this to use the k3_r5_rproc_mem_data structure to store memory information. This aligns with K3 DSP and M4 drivers, and can be refactored out later. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 65 ++++++++++++++++++++---- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 525f26996b56..29205d9e21af 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -84,18 +84,44 @@ enum cluster_mode { CLUSTER_MODE_SINGLECORE }; +/** + * struct k3_r5_mem_data - memory definitions for a R5 + * @name: name for this memory entry + * @dev_addr: device address for the memory entry + */ +struct k3_r5_mem_data { + const char *name; + const u32 dev_addr; +}; + +/** + * struct k3_r5_dev_data - device data structure for a R5 + * @mems: pointer to memory definitions for a R5 + * @num_mems: number of memory regions in @mems + * @boot_align_addr: boot vector address alignment granularity + * @uses_lreset: flag to denote the need for local reset management + */ +struct k3_r5_dev_data { + const struct k3_r5_mem_data *mems; + u32 num_mems; + u32 boot_align_addr; + bool uses_lreset; +}; + /** * struct k3_r5_soc_data - match data to handle SoC variations * @tcm_is_double: flag to denote the larger unified TCMs in certain modes * @tcm_ecc_autoinit: flag to denote the auto-initialization of TCMs for ECC * @single_cpu_mode: flag to denote if SoC/IP supports Single-CPU mode * @is_single_core: flag to denote if SoC/IP has only single core R5 + * @core_data: pointer to R5-core-specific device data */ struct k3_r5_soc_data { bool tcm_is_double; bool tcm_ecc_autoinit; bool single_cpu_mode; bool is_single_core; + const struct k3_r5_dev_data *core_data; }; /** @@ -151,6 +177,7 @@ struct k3_r5_core { * @rmem: reserved memory regions data * @num_rmems: number of reserved memory regions * @reset: reset control handle + * @data: pointer to R5-core-specific device data * @tsp: TI-SCI processor control handle * @ti_sci: TI-SCI handle * @ti_sci_id: TI-SCI device identifier @@ -166,6 +193,7 @@ struct k3_r5_rproc { struct k3_r5_mem *rmem; int num_rmems; struct reset_control *reset; + const struct k3_r5_dev_data *data; struct ti_sci_proc *tsp; const struct ti_sci_handle *ti_sci; u32 ti_sci_id; @@ -1207,31 +1235,32 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, struct k3_r5_rproc *kproc) { - static const char * const mem_names[] = {"atcm", "btcm"}; + const struct k3_r5_dev_data *data = kproc->data; struct device *dev = &pdev->dev; struct k3_r5_core *core = kproc->priv; struct resource *res; int num_mems; int i; - num_mems = ARRAY_SIZE(mem_names); - kproc->mem = devm_kcalloc(dev, num_mems, sizeof(*kproc->mem), GFP_KERNEL); + num_mems = kproc->data->num_mems; + kproc->mem = devm_kcalloc(kproc->dev, num_mems, sizeof(*kproc->mem), + GFP_KERNEL); if (!kproc->mem) return -ENOMEM; for (i = 0; i < num_mems; i++) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - mem_names[i]); + data->mems[i].name); if (!res) { dev_err(dev, "found no memory resource for %s\n", - mem_names[i]); + data->mems[i].name); return -EINVAL; } if (!devm_request_mem_region(dev, res->start, resource_size(res), dev_name(dev))) { dev_err(dev, "could not request %s region for resource\n", - mem_names[i]); + data->mems[i].name); return -EBUSY; } @@ -1245,7 +1274,8 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, resource_size(res)); if (!kproc->mem[i].cpu_addr) { - dev_err(dev, "failed to map %s memory\n", mem_names[i]); + dev_err(dev, "failed to map %s memory\n", + data->mems[i].name); return -ENOMEM; } kproc->mem[i].bus_addr = res->start; @@ -1258,7 +1288,7 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, * addresses 0 and 0x41010000 (same as the bus address on AM65x * SoCs) based on loczrama setting */ - if (!strcmp(mem_names[i], "atcm")) { + if (!strcmp(data->mems[i].name, "atcm")) { kproc->mem[i].dev_addr = core->loczrama ? 0 : K3_R5_TCM_DEV_ADDR; } else { @@ -1268,7 +1298,7 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, kproc->mem[i].size = resource_size(res); dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - mem_names[i], &kproc->mem[i].bus_addr, + data->mems[i].name, &kproc->mem[i].bus_addr, kproc->mem[i].size, kproc->mem[i].cpu_addr, kproc->mem[i].dev_addr); } @@ -1323,6 +1353,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) kproc->priv = core; kproc->dev = cdev; kproc->rproc = rproc; + kproc->data = cluster->soc_data->core_data; core->kproc = kproc; kproc->ti_sci = devm_ti_sci_get_by_phandle(cdev, "ti,sci"); @@ -1764,11 +1795,24 @@ static int k3_r5_probe(struct platform_device *pdev) return 0; } +static const struct k3_r5_mem_data r5_mems[] = { + { .name = "atcm", .dev_addr = 0x0 }, + { .name = "btcm", .dev_addr = K3_R5_TCM_DEV_ADDR }, +}; + +static const struct k3_r5_dev_data r5_data = { + .mems = r5_mems, + .num_mems = ARRAY_SIZE(r5_mems), + .boot_align_addr = 0, + .uses_lreset = true, +}; + static const struct k3_r5_soc_data am65_j721e_soc_data = { .tcm_is_double = false, .tcm_ecc_autoinit = false, .single_cpu_mode = false, .is_single_core = false, + .core_data = &r5_data, }; static const struct k3_r5_soc_data j7200_j721s2_soc_data = { @@ -1776,6 +1820,7 @@ static const struct k3_r5_soc_data j7200_j721s2_soc_data = { .tcm_ecc_autoinit = true, .single_cpu_mode = false, .is_single_core = false, + .core_data = &r5_data, }; static const struct k3_r5_soc_data am64_soc_data = { @@ -1783,6 +1828,7 @@ static const struct k3_r5_soc_data am64_soc_data = { .tcm_ecc_autoinit = true, .single_cpu_mode = true, .is_single_core = false, + .core_data = &r5_data, }; static const struct k3_r5_soc_data am62_soc_data = { @@ -1790,6 +1836,7 @@ static const struct k3_r5_soc_data am62_soc_data = { .tcm_ecc_autoinit = true, .single_cpu_mode = false, .is_single_core = true, + .core_data = &r5_data, }; static const struct of_device_id k3_r5_of_match[] = { From patchwork Mon Mar 17 12:06:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019130 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED078237702; Mon, 17 Mar 2025 12:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213217; cv=none; b=Zjm6aWEl0BkQEgsw3uK9CyMSTls645wv8SR1Ye6Adox70Wg2Abk9iico0KCwBAYsAyaV5mckSA70MvRBI/a4W2Vew2gym/OuOLhOAYeCIHyBEM0x725K8cQvwIODDtNIIvdUL+2y4RGf2aRCiOSHOFErEThUbMVy4rPwFOtY0yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213217; c=relaxed/simple; bh=fHvN3SeufGoM2fTYZPedWl6rS124Ik77Iqo8gEyIIoE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FTGZ26kXIeIYhNeNWLlWUn3PR65tfp5IQO7pJS3OzhW2auyAsU/3k6TDtfGr+uzAqAXDpfk6W9vqicRYDnIFFycQwwuIBmhYPVh79jnherjI46h+gJthQBOy7XHN2QCRZmZDJi8zgPv2Vha40onZvIi7f0LEDETojRfXOsBOhW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=Hy9kBjB3; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Hy9kBjB3" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6lCU2331252 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:06:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213207; bh=ctTUdnR2MdrpDLtA+XdCyp46a6uSDi77ljjnnnnR8jw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Hy9kBjB3XrFZ/xMBuAwui9IGd5zhgd4CLMHAmRv10ZNP4iDPCTDBp5rUKhtRgN2yF QoZAG8+gIyAb6Bqi/idhdaMV8g1Bq11XfcajFJkV1WelByTMO6d7pKpCXiW9xLEG1L +9ZrHh2M0LTkimqTNWx01G7MOamBxJi31SgKFN50= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6lJs004930; Mon, 17 Mar 2025 07:06:47 -0500 Received: from DLEE111.ent.ti.com (157.170.170.22) 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.2507.23; Mon, 17 Mar 2025 07:06:46 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:46 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK1060901; Mon, 17 Mar 2025 07:06:43 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 04/26] remoteproc: k3-{m4/dsp}: Align internal rproc data structure with R5 Date: Mon, 17 Mar 2025 17:36:00 +0530 Message-ID: <20250317120622.1746415-5-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Introduce a void pointer in the k3_{m4/dsp}_rproc internal data structure which can be used to point to any private data needed by the driver. Currently, the M4/DSP drivers do not have any private data, so the pointer can be left pointing to NULL. Additionally, add a pointer to the rproc struct within k3_m4_rproc internal struct. This is done to align the data structures with R5 driver which can be factored out at a later stage. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_dsp_remoteproc.c | 2 ++ drivers/remoteproc/ti_k3_m4_remoteproc.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index a695890254ff..31e43e49f1e4 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -76,6 +76,7 @@ struct k3_dsp_dev_data { * @ti_sci_id: TI-SCI device identifier * @mbox: mailbox channel handle * @client: mailbox client to request the mailbox channel + * @priv: Remote processor private data */ struct k3_dsp_rproc { struct device *dev; @@ -91,6 +92,7 @@ struct k3_dsp_rproc { u32 ti_sci_id; struct mbox_chan *mbox; struct mbox_client client; + void *priv; }; /** diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index a16fb165fced..d0ee7a8d460d 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -50,6 +50,7 @@ struct k3_m4_rproc_mem_data { /** * struct k3_m4_rproc - k3 remote processor driver structure * @dev: cached device pointer + * @rproc: remoteproc device handle * @mem: internal memory regions data * @num_mems: number of internal memory regions * @rmem: reserved memory regions data @@ -60,9 +61,11 @@ struct k3_m4_rproc_mem_data { * @ti_sci_id: TI-SCI device identifier * @mbox: mailbox channel handle * @client: mailbox client to request the mailbox channel + * @priv: Remote processor private data */ struct k3_m4_rproc { struct device *dev; + struct rproc *rproc; struct k3_m4_rproc_mem *mem; int num_mems; struct k3_m4_rproc_mem *rmem; @@ -73,6 +76,7 @@ struct k3_m4_rproc { u32 ti_sci_id; struct mbox_chan *mbox; struct mbox_client client; + void *priv; }; /** @@ -578,6 +582,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) rproc->recovery_disabled = true; kproc = rproc->priv; kproc->dev = dev; + kproc->rproc = rproc; platform_set_drvdata(pdev, rproc); kproc->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); From patchwork Mon Mar 17 12:06:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019133 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D57A423A989; Mon, 17 Mar 2025 12:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213220; cv=none; b=GQyaD10C3+vjyqEroOo+GB8aEL7B3wOEpDRH+zqTMEC1CEkU1uAz7ybHrzsredIuAoK++xJ7NH/JZDfsgVuynEjZ+FXMmX8rjt5VpsSdUncEdPJ4TH218xJ6lAKjWmgHz0tyzEa07oXUywJdiAycJPGhDvMumBC81FXlGT0VD2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213220; c=relaxed/simple; bh=AowoFTfsKQbBqG6rpHEqUBJQ3OPHxzz3f1dnUdF1jaI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c7caCfqeaHqRu5r/JoXgATUKG+Jqu8cZR/LPvcoXq3+awXvmHGBEtg/eXjxCG50YaLhussiuOFq4zxXczse1VReWwo2piEpWx8xMX2At/JjZNOYdrt0/a6eF8PEFB9xJKAbTn2OuMoiZROR5a7cTHBC1YVhCzp7XGvKaTChSFLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=giOaodDS; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="giOaodDS" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6oVG2802849 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:06:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213210; bh=YtzlVUK/7mdF8Q7fSUI9qUIz3UfjgJl75wxmwzWbSWg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=giOaodDSMIKmCNQyQ5MEo8ZY+MqBrclKVhDddrJb47OubogrVr+qJya/y2qYSWrv6 BUSJJjeynV5Nkr1I1dBjb9ObxZ18c/MrcJHekiOZvxnecdQ4nbmgDxZb/Ok5W+yarQ OJv8r63t+VEQnlCyWOI2hsoep5iMKk8xJXagWJ6c= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6oNZ004945; Mon, 17 Mar 2025 07:06:50 -0500 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:06:50 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:50 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK2060901; Mon, 17 Mar 2025 07:06:47 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 05/26] remoteproc: k3-m4: Use k3_rproc_mem_data structure for memory info Date: Mon, 17 Mar 2025 17:36:01 +0530 Message-ID: <20250317120622.1746415-6-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The ti_k3_m4_remoteproc.c driver previously hardcoded device memory region addresses and names. Change this to use the k3_rproc_mem_data structure to store memory information. This aligns with DSP and R5 drivers, and can be refactored out later. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_m4_remoteproc.c | 60 ++++++++++++++++++------ 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index d0ee7a8d460d..e83bef7cfddf 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -20,9 +20,6 @@ #include "remoteproc_internal.h" #include "ti_sci_proc.h" -#define K3_M4_IRAM_DEV_ADDR 0x00000 -#define K3_M4_DRAM_DEV_ADDR 0x30000 - /** * struct k3_m4_rproc_mem - internal memory structure * @cpu_addr: MPU virtual address of the memory region @@ -38,15 +35,29 @@ struct k3_m4_rproc_mem { }; /** - * struct k3_m4_rproc_mem_data - memory definitions for a remote processor + * struct k3_m4_mem_data - memory definitions for a remote processor * @name: name for this memory entry * @dev_addr: device address for the memory entry */ -struct k3_m4_rproc_mem_data { +struct k3_m4_mem_data { const char *name; const u32 dev_addr; }; +/** + * struct k3_m4_dev_data - device data structure for a M4 core + * @mems: pointer to memory definitions for a M4 core + * @num_mems: number of memory regions in @mems + * @boot_align_addr: boot vector address alignment granularity + * @uses_lreset: flag to denote the need for local reset management + */ +struct k3_m4_dev_data { + const struct k3_m4_mem_data *mems; + u32 num_mems; + u32 boot_align_addr; + bool uses_lreset; +}; + /** * struct k3_m4_rproc - k3 remote processor driver structure * @dev: cached device pointer @@ -56,6 +67,7 @@ struct k3_m4_rproc_mem_data { * @rmem: reserved memory regions data * @num_rmems: number of reserved memory regions * @reset: reset control handle + * @data: pointer to M4-specific device data * @tsp: TI-SCI processor control handle * @ti_sci: TI-SCI handle * @ti_sci_id: TI-SCI device identifier @@ -71,6 +83,7 @@ struct k3_m4_rproc { struct k3_m4_rproc_mem *rmem; int num_rmems; struct reset_control *reset; + const struct k3_m4_dev_data *data; struct ti_sci_proc *tsp; const struct ti_sci_handle *ti_sci; u32 ti_sci_id; @@ -336,14 +349,13 @@ static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool static int k3_m4_rproc_of_get_memories(struct platform_device *pdev, struct k3_m4_rproc *kproc) { - static const char * const mem_names[] = { "iram", "dram" }; - static const u32 mem_addrs[] = { K3_M4_IRAM_DEV_ADDR, K3_M4_DRAM_DEV_ADDR }; + const struct k3_m4_dev_data *data = kproc->data; struct device *dev = &pdev->dev; struct resource *res; int num_mems; int i; - num_mems = ARRAY_SIZE(mem_names); + num_mems = kproc->data->num_mems; kproc->mem = devm_kcalloc(kproc->dev, num_mems, sizeof(*kproc->mem), GFP_KERNEL); if (!kproc->mem) @@ -351,17 +363,17 @@ static int k3_m4_rproc_of_get_memories(struct platform_device *pdev, for (i = 0; i < num_mems; i++) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - mem_names[i]); + data->mems[i].name); if (!res) { dev_err(dev, "found no memory resource for %s\n", - mem_names[i]); + data->mems[i].name); return -EINVAL; } if (!devm_request_mem_region(dev, res->start, resource_size(res), dev_name(dev))) { dev_err(dev, "could not request %s region for resource\n", - mem_names[i]); + data->mems[i].name); return -EBUSY; } @@ -369,15 +381,15 @@ static int k3_m4_rproc_of_get_memories(struct platform_device *pdev, resource_size(res)); if (!kproc->mem[i].cpu_addr) { dev_err(dev, "failed to map %s memory\n", - mem_names[i]); + data->mems[i].name); return -ENOMEM; } kproc->mem[i].bus_addr = res->start; - kproc->mem[i].dev_addr = mem_addrs[i]; + kproc->mem[i].dev_addr = data->mems[i].dev_addr; kproc->mem[i].size = resource_size(res); dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - mem_names[i], &kproc->mem[i].bus_addr, + data->mems[i].name, &kproc->mem[i].bus_addr, kproc->mem[i].size, kproc->mem[i].cpu_addr, kproc->mem[i].dev_addr); } @@ -563,12 +575,17 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct k3_m4_rproc *kproc; + const struct k3_m4_dev_data *data; struct rproc *rproc; const char *fw_name; bool r_state = false; bool p_state = false; int ret; + data = of_device_get_match_data(dev); + if (!data) + return -ENODEV; + ret = rproc_of_parse_firmware(dev, 0, &fw_name); if (ret) return dev_err_probe(dev, ret, "failed to parse firmware-name property\n"); @@ -583,6 +600,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) kproc = rproc->priv; kproc->dev = dev; kproc->rproc = rproc; + kproc->data = data; platform_set_drvdata(pdev, rproc); kproc->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); @@ -650,8 +668,20 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) return 0; } +static const struct k3_m4_mem_data am64_m4_mems[] = { + { .name = "iram", .dev_addr = 0x0 }, + { .name = "dram", .dev_addr = 0x30000 }, +}; + +static const struct k3_m4_dev_data am64_m4_data = { + .mems = am64_m4_mems, + .num_mems = ARRAY_SIZE(am64_m4_mems), + .boot_align_addr = SZ_1K, + .uses_lreset = true, +}; + static const struct of_device_id k3_m4_of_match[] = { - { .compatible = "ti,am64-m4fss", }, + { .compatible = "ti,am64-m4fss", .data = &am64_m4_data, }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, k3_m4_of_match); From patchwork Mon Mar 17 12:06:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019135 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE02723E351; Mon, 17 Mar 2025 12:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213230; cv=none; b=Au9enita38pRVwRbouLzY0FOz9KIC3S8qmgDyyPFcSMU+N5XZ1DelCjPGSUdahwXxLL3+kHQZz9QnT6u7H7q2JNBV0zxQlyhz3EhBmyfATHMMBUMi6gpB3PmOwK2GpSMmpeoHH6ZuRdzlH2RznikaI1sfN4YmmHO0u8eOyMJo2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213230; c=relaxed/simple; bh=OrUgEXbdIIeVX00IDa7prbDFTGP859u72n4IozZFlm4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=syODO5xaeIGmw4cQIvsRXqkBXkCwVUg6OOvEOUDOyljq+qjkGabBi1I0oWzLGUUE9VfjS6X2T/UgG3Z1XoTvL/2pDzAwWH2HMcPMQHgN6DsuTQHto22ohA6RHoyMQdM8QiUhJhsYJxNskDJjnxZYpZbcJTjPR56C1ob74wE+84s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=QqqWUeVv; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="QqqWUeVv" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6sxp2266703 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:06:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213214; bh=pksPektTyS60s6/3akVXsyJBmN5OKsAuJ3jxU7pccgo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=QqqWUeVvcokZEXKpIl0eX2EOcdjXamy2q5ajp4MLQKEX3wnq3z0DLR2VETb8P3/+f OUNAO6fQ5L21CvPNfX7w1BYWoSz2MkGeqBVKRnFJ0jSdWAgZOeXeAJ2+v+3n1GQX6Y eKY9HFQFbjkqh3IMEf70ZJUKxILkmUNeKvQeqRyI= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6sus000332 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:06:54 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:06:54 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:54 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK3060901; Mon, 17 Mar 2025 07:06:50 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 06/26] remoteproc: k3-r5: Drop check performed in k3_r5_rproc_{mbox_callback/kick} Date: Mon, 17 Mar 2025 17:36:02 +0530 Message-ID: <20250317120622.1746415-7-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea From: Siddharth Vadapalli Commit f3f11cfe8907 ("remoteproc: k3-r5: Acquire mailbox handle during probe routine") introduced a check in the "k3_r5_rproc_mbox_callback()" and "k3_r5_rproc_kick()" callbacks, causing them to exit if the remote core's state is "RPROC_DETACHED". However, the "__rproc_attach()" function that is responsible for attaching to a remote core, updates the state of the remote core to "RPROC_ATTACHED" only after invoking "rproc_start_subdevices()". The "rproc_start_subdevices()" function triggers the probe of the Virtio RPMsg devices associated with the remote core, which require that the "k3_r5_rproc_kick()" and "k3_r5_rproc_mbox_callback()" callbacks are functional. Hence, drop the check in the callbacks. Fixes: f3f11cfe8907 ("remoteproc: k3-r5: Acquire mailbox handle during probe routine") Signed-off-by: Siddharth Vadapalli Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 29205d9e21af..c0e4da82775d 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -224,10 +224,6 @@ static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data) const char *name = kproc->rproc->name; u32 msg = omap_mbox_message(data); - /* Do not forward message from a detached core */ - if (kproc->rproc->state == RPROC_DETACHED) - return; - dev_dbg(dev, "mbox msg: 0x%x\n", msg); switch (msg) { @@ -263,10 +259,6 @@ static void k3_r5_rproc_kick(struct rproc *rproc, int vqid) mbox_msg_t msg = (mbox_msg_t)vqid; int ret; - /* Do not forward message to a detached core */ - if (kproc->rproc->state == RPROC_DETACHED) - return; - /* send the index of the triggered virtqueue in the mailbox payload */ ret = mbox_send_message(kproc->mbox, (void *)msg); if (ret < 0) From patchwork Mon Mar 17 12:06:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019134 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F9F238D5B; Mon, 17 Mar 2025 12:07:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213227; cv=none; b=eq3GzYyY1AqlMSvAOnZ9zX50v/Xhl2PN8I4xNveM2MqUdhOaHLcNcqLPGJfkJHBgY9fsjiG3trEKG+Rd8yp5egaymc0pSyzjZpBfozMH5NqHk170a/orc1SIZQ72BM1Qd6Ikav6xT0p6nnmgnzsAthFbSgMJSrp/EXD0lJ2cr48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213227; c=relaxed/simple; bh=MJuPNT69rqW561jwGJ7oI/wOoA7XySl0yt5QGfpDOQc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f2xlxpV1IaSvm835/c03Sp6r0UDwEpH68nnN0JOmpIkdtuulOuwtQn+bwsGDNFjBxgROp4zld6IEQu/vRwpZct6x1ICJTY4EhkeMcbJbRfDeFxGcnCfKGNOfs+FHjVkS2Is1DZfkiKoM6Ch5eeYxSbGmGt8w9/ngY7F6mkCrGMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=uLq4iG72; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="uLq4iG72" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6wvv2331274 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:06:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213218; bh=vMuBacFLZpVHc7KMK0QkqKhc/im326/SdOzsx3bzvrQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=uLq4iG72v2uSk3zw5ohTCNdPiEkmjaMUUotEUkti5RDLFMX4rgDziYWSwwgFwW9ta HVIpXoH9+d9fe8RYVqEfgAWaQekE+MsdgWfSXJDtwu54ijtXwUwagAVZ04KDPMoEIG GrA1TVE0awRu+12cmtX3m74jJ+uzZu9FZkRZgIGU= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC6wuq124003 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:06:58 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:06:57 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:06:57 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK4060901; Mon, 17 Mar 2025 07:06:54 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 07/26] remoteproc: k3-dsp: Drop check performed in k3_dsp_rproc_{mbox_callback/kick} Date: Mon, 17 Mar 2025 17:36:03 +0530 Message-ID: <20250317120622.1746415-8-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea From: Siddharth Vadapalli Commit ea1d6fb5b571 ("remoteproc: k3-dsp: Acquire mailbox handle during probe routine") introduced a check in the "k3_dsp_rproc_mbox_callback()" and "k3_dsp_rproc_kick()" callbacks, causing them to exit if the remote core's state is "RPROC_DETACHED". However, the "__rproc_attach()" function that is responsible for attaching to a remote core, updates the state of the remote core to "RPROC_ATTACHED" only after invoking "rproc_start_subdevices()". The "rproc_start_subdevices()" function triggers the probe of the Virtio RPMsg devices associated with the remote core, which require that the "k3_dsp_rproc_kick()" and "k3_dsp_rproc_mbox_callback()" callbacks are functional. Hence, drop the check in the callbacks. Fixes: ea1d6fb5b571 ("remoteproc: k3-dsp: Acquire mailbox handle during probe routine") Signed-off-by: Siddharth Vadapalli Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_dsp_remoteproc.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 31e43e49f1e4..2191547529c5 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -117,10 +117,6 @@ static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data) const char *name = kproc->rproc->name; u32 msg = omap_mbox_message(data); - /* Do not forward messages from a detached core */ - if (kproc->rproc->state == RPROC_DETACHED) - return; - dev_dbg(dev, "mbox msg: 0x%x\n", msg); switch (msg) { @@ -161,10 +157,6 @@ static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid) mbox_msg_t msg = (mbox_msg_t)vqid; int ret; - /* Do not forward messages to a detached core */ - if (kproc->rproc->state == RPROC_DETACHED) - return; - /* send the index of the triggered virtqueue in the mailbox payload */ ret = mbox_send_message(kproc->mbox, (void *)msg); if (ret < 0) From patchwork Mon Mar 17 12:06:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019138 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8FF723F267; Mon, 17 Mar 2025 12:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213244; cv=none; b=iNS/TM/b1G+R+kwXyDy3uQo1MoNs8cwLTeFiqB6zh25y9rl+oSnT9S8WrQqxSdTruIGTlUDUTt+AA0C5GZ6uz33z7d9eqTSRqlMmXS7rtzST5zuH+1T8iXIdho0XgKUvRK+TjZUWFtUPOgvz5akpUq37xZv4iRJyHLrcir8LFLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213244; c=relaxed/simple; bh=6+8nkkIGP/zxXJ54YweBKDvwo9j/bt+Zf9uOcOgYx5o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hntfHMl5Rot/JHCax4DVkMWQYkWLjtQGle4mcj0VrucqpXEzyKD/QNx1yjtunAsOGXwWDc//fjEABufi13jO082NosD6ypnlugFAGZKIRE9FsnuNTW1jysy5Lyyl/GZZhWti1Vp29Oud52CIcYzlTeSPu8BqwoVVIqMx4FQFSJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=cBtQl4Vd; arc=none smtp.client-ip=198.47.19.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="cBtQl4Vd" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC71762755497 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213221; bh=1EE+ZrQgMh4heXy6zTMEUqhBiUfVWjX7abghlTFwA+k=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=cBtQl4VdptWGpgMHA60gHHWpoSBOcODnAXUuD+JTWNujAb9a76Mu2pFm6fKiFECkZ WxU4PM6+G1Ku2L14PZe5gmSuBenH4UkrQ24DLTgIzYvxr+GE0dzuMv4oRHqWTOrHH9 th6bNmVV3vQRbkZBwGdONPGDxV05r+3ufLeSjPt4= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC71Gd108376 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:01 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:01 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:01 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK5060901; Mon, 17 Mar 2025 07:06:58 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 08/26] remoteproc: k3-r5: Refactor sequential core power up/down operations Date: Mon, 17 Mar 2025 17:36:04 +0530 Message-ID: <20250317120622.1746415-9-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The existing implementation of the waiting mechanism in "k3_r5_cluster_rproc_init()" waits for the "released_from_reset" flag to be set as part of the firmware boot process in "k3_r5_rproc_start()". The "k3_r5_cluster_rproc_init()" function is invoked in the probe routine which causes unexpected failures in cases where the firmware is unavailable at boot time, resulting in probe failure and removal of the remoteproc handles in the sysfs paths. To address this, the waiting mechanism is refactored out of the probe routine into the appropriate "k3_r5_rproc_{prepare/unprepare}()" functions. This allows the probe routine to complete without depending on firmware booting, while still maintaining the required power-synchronization between cores. Further, this wait mechanism is dropped from "k3_r5_rproc_{start/stop}()" functions as they deal with Core Run/Halt operations, and as such, there is no constraint in Running or Halting the cores of a cluster in order. Fixes: 61f6f68447ab ("remoteproc: k3-r5: Wait for core0 power-up before powering up core1") Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 114 +++++++++++++---------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index c0e4da82775d..30081eafbd36 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -475,7 +475,7 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc) static int k3_r5_rproc_prepare(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_core *core = kproc->priv; + struct k3_r5_core *core = kproc->priv, *core0, *core1; struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; u32 ctrl = 0, cfg = 0, stat = 0; @@ -483,6 +483,29 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) bool mem_init_dis; int ret; + /* + * R5 cores require to be powered on sequentially, core0 should be in + * higher power state than core1 in a cluster. So, wait for core0 to + * power up before proceeding to core1 and put timeout of 2sec. This + * waiting mechanism is necessary because rproc_auto_boot_callback() for + * core1 can be called before core0 due to thread execution order. + * + * By placing the wait mechanism here in .prepare() ops, this condition + * is enforced for rproc boot requests from sysfs as well. + */ + core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); + core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); + if (cluster->mode == CLUSTER_MODE_SPLIT && core == core1 && + !core0->released_from_reset) { + ret = wait_event_interruptible_timeout(cluster->core_transition, + core0->released_from_reset, + msecs_to_jiffies(2000)); + if (ret <= 0) { + dev_err(dev, "can not power up core1 before core0"); + return -EPERM; + } + } + ret = ti_sci_proc_get_status(kproc->tsp, &boot_vec, &cfg, &ctrl, &stat); if (ret < 0) return ret; @@ -498,6 +521,14 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) return ret; } + /* + * Notify all threads in the wait queue when core0 state has changed so + * that threads waiting for this condition can be executed. + */ + core->released_from_reset = true; + if (core == core0) + wake_up_interruptible(&cluster->core_transition); + /* * Newer IP revisions like on J7200 SoCs support h/w auto-initialization * of TCMs, so there is no need to perform the s/w memzero. This bit is @@ -542,11 +573,31 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) static int k3_r5_rproc_unprepare(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_core *core = kproc->priv; + struct k3_r5_core *core = kproc->priv, *core0, *core1; struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; int ret; + /* + * Ensure power-down of cores is sequential in split mode. Core1 must + * power down before Core0 to maintain the expected state. By placing + * the wait mechanism here in .unprepare() ops, this condition is + * enforced for rproc stop or shutdown requests from sysfs and device + * removal as well. + */ + core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); + core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); + if (cluster->mode == CLUSTER_MODE_SPLIT && core == core0 && + core1->released_from_reset) { + ret = wait_event_interruptible_timeout(cluster->core_transition, + !core1->released_from_reset, + msecs_to_jiffies(2000)); + if (ret <= 0) { + dev_err(dev, "can not power down core0 before core1"); + return -EPERM; + } + } + /* Re-use LockStep-mode reset logic for Single-CPU mode */ ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || cluster->mode == CLUSTER_MODE_SINGLECPU) ? @@ -554,6 +605,14 @@ static int k3_r5_rproc_unprepare(struct rproc *rproc) if (ret) dev_err(dev, "unable to disable cores, ret = %d\n", ret); + /* + * Notify all threads in the wait queue when core1 state has changed so + * that threads waiting for this condition can be executed. + */ + core->released_from_reset = false; + if (core == core1) + wake_up_interruptible(&cluster->core_transition); + return ret; } @@ -577,7 +636,7 @@ static int k3_r5_rproc_unprepare(struct rproc *rproc) static int k3_r5_rproc_start(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_core *core0, *core = kproc->priv; + struct k3_r5_core *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; u32 boot_addr; @@ -600,21 +659,9 @@ static int k3_r5_rproc_start(struct rproc *rproc) goto unroll_core_run; } } else { - /* do not allow core 1 to start before core 0 */ - core0 = list_first_entry(&cluster->cores, struct k3_r5_core, - elem); - if (core != core0 && core0->kproc->rproc->state == RPROC_OFFLINE) { - dev_err(dev, "%s: can not start core 1 before core 0\n", - __func__); - return -EPERM; - } - - ret = k3_r5_core_run(core->kproc); + ret = k3_r5_core_run(kproc); if (ret) return ret; - - core->released_from_reset = true; - wake_up_interruptible(&cluster->core_transition); } return 0; @@ -654,9 +701,8 @@ static int k3_r5_rproc_start(struct rproc *rproc) static int k3_r5_rproc_stop(struct rproc *rproc) { struct k3_r5_rproc *kproc = rproc->priv; - struct k3_r5_core *core1, *core = kproc->priv; + struct k3_r5_core *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; - struct device *dev = kproc->dev; int ret; /* halt all applicable cores */ @@ -669,17 +715,7 @@ static int k3_r5_rproc_stop(struct rproc *rproc) } } } else { - /* do not allow core 0 to stop before core 1 */ - core1 = list_last_entry(&cluster->cores, struct k3_r5_core, - elem); - if (core != core1 && core1->kproc->rproc->state != RPROC_OFFLINE) { - dev_err(dev, "%s: can not stop core 0 before core 1\n", - __func__); - ret = -EPERM; - goto out; - } - - ret = k3_r5_core_halt(core->kproc); + ret = k3_r5_core_halt(kproc); if (ret) goto out; } @@ -1441,26 +1477,6 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) cluster->mode == CLUSTER_MODE_SINGLECPU || cluster->mode == CLUSTER_MODE_SINGLECORE) break; - - /* - * R5 cores require to be powered on sequentially, core0 - * should be in higher power state than core1 in a cluster - * So, wait for current core to power up before proceeding - * to next core and put timeout of 2sec for each core. - * - * This waiting mechanism is necessary because - * rproc_auto_boot_callback() for core1 can be called before - * core0 due to thread execution order. - */ - ret = wait_event_interruptible_timeout(cluster->core_transition, - core->released_from_reset, - msecs_to_jiffies(2000)); - if (ret <= 0) { - dev_err(cdev, - "Timed out waiting for %s core to power up!\n", - rproc->name); - goto out; - } } return 0; From patchwork Mon Mar 17 12:06:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019136 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E59E2356C2; Mon, 17 Mar 2025 12:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213239; cv=none; b=IrNzUy335Un1LuBXZ6Jqd1wtNxtVxRfAhjJf/zW2ttTQt965sD5xXYC8Q6I5Ldp+jGTkRV/ylfmiv7AOhnMjhiwbInDrVwUULGKlrEi3DsijRha7bjtm1ONsasCOus8OgF+5yNsxVPmZ1yJOBRbgRJ7jWxqIZIDFzf5EdLLqE5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213239; c=relaxed/simple; bh=Sc7ZL9QvqR9uf6/7ET0gaYlY1P8t6oPSilp9Z7ksD/E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SLKnbzJ1Lij5bvL4XzcJgcZ/1n2xrc94n2fY81xrd3J5wmBArFRG03Mw9oqD53ECKVFb//RWxj3nagxztAr3dTttIcmfA1Q4tJDLfSRNbd4gXMEZevWDZd/i3Vp2RrSx7m/o9f2pv7mFCMP/PQszpq7s+8hXeeVw1tWDaHvn/XE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=FjDJ5eyj; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="FjDJ5eyj" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC75202266727 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213225; bh=H5jY5nKcQ4WWy1mBXBeZRxVV5wZ3+ta3RmbBqiRwMeg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=FjDJ5eyjeQcjrDrmuj3SoFIgNm9il9N0jEP9rAIgN3FbkPh6ingvdFQVZGU+fOjHz fNhWONGhy3AXCcKu5pE5n6Wo6jeqZn4g6cuVEXRG8atfM49MLPXJ8VoeslAa9uRbjM kbYaj7BfCuWcWsq5vC+Aq0FRiq1Q6NZGlAma0SXE= Received: from DFLE111.ent.ti.com (dfle111.ent.ti.com [10.64.6.32]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7543000454 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:05 -0500 Received: from DFLE114.ent.ti.com (10.64.6.35) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:05 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:05 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK6060901; Mon, 17 Mar 2025 07:07:01 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 09/26] remoteproc: k3: Refactor shared data structures Date: Mon, 17 Mar 2025 17:36:05 +0530 Message-ID: <20250317120622.1746415-10-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The TI K3 R5, DSP and M4 remoteproc drivers share the same data structure definitions. Refactor the shared data structures into a new common header file, 'ti_k3_common.h', and update the drivers to use the unified data structures. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.h | 91 +++++++++++++++ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 120 ++++---------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 105 +++-------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 132 +++++----------------- 4 files changed, 161 insertions(+), 287 deletions(-) create mode 100644 drivers/remoteproc/ti_k3_common.h diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h new file mode 100644 index 000000000000..43aedab9f0aa --- /dev/null +++ b/drivers/remoteproc/ti_k3_common.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * TI K3 Remote Processor(s) driver common code + * + * Refactored out of ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c. + * + * ti_k3_dsp_remoteproc.c: + * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ + * Suman Anna + * + * ti_k3_m4_remoteproc.c: + * Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/ + * Hari Nagalla + */ + +#ifndef REMOTEPROC_TI_K3_COMMON_H +#define REMOTEPROC_TI_K3_COMMON_H + +/** + * struct k3_rproc_mem - internal memory structure + * @cpu_addr: MPU virtual address of the memory region + * @bus_addr: Bus address used to access the memory region + * @dev_addr: Device address of the memory region from remote processor view + * @size: Size of the memory region + */ +struct k3_rproc_mem { + void __iomem *cpu_addr; + phys_addr_t bus_addr; + u32 dev_addr; + size_t size; +}; + +/** + * struct k3_rproc_mem_data - memory definitions for a remote processor + * @name: name for this memory entry + * @dev_addr: device address for the memory entry + */ +struct k3_rproc_mem_data { + const char *name; + const u32 dev_addr; +}; + +/** + * struct k3_rproc_dev_data - device data structure for a remote processor + * @mems: pointer to memory definitions for a remote processor + * @num_mems: number of memory regions in @mems + * @boot_align_addr: boot vector address alignment granularity + * @uses_lreset: flag to denote the need for local reset management + */ +struct k3_rproc_dev_data { + const struct k3_rproc_mem_data *mems; + u32 num_mems; + u32 boot_align_addr; + bool uses_lreset; +}; + +/** + * struct k3_rproc - k3 remote processor driver structure + * @dev: cached device pointer + * @rproc: remoteproc device handle + * @mem: internal memory regions data + * @num_mems: number of internal memory regions + * @rmem: reserved memory regions data + * @num_rmems: number of reserved memory regions + * @reset: reset control handle + * @data: pointer to DSP-specific device data + * @tsp: TI-SCI processor control handle + * @ti_sci: TI-SCI handle + * @ti_sci_id: TI-SCI device identifier + * @mbox: mailbox channel handle + * @client: mailbox client to request the mailbox channel + * @priv: void pointer to carry any private data + */ +struct k3_rproc { + struct device *dev; + struct rproc *rproc; + struct k3_rproc_mem *mem; + int num_mems; + struct k3_rproc_mem *rmem; + int num_rmems; + struct reset_control *reset; + const struct k3_rproc_dev_data *data; + struct ti_sci_proc *tsp; + const struct ti_sci_handle *ti_sci; + u32 ti_sci_id; + struct mbox_chan *mbox; + struct mbox_client client; + void *priv; +}; + +#endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 2191547529c5..e92fab831670 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -20,81 +20,10 @@ #include "omap_remoteproc.h" #include "remoteproc_internal.h" #include "ti_sci_proc.h" +#include "ti_k3_common.h" #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/** - * struct k3_dsp_mem - internal memory structure - * @cpu_addr: MPU virtual address of the memory region - * @bus_addr: Bus address used to access the memory region - * @dev_addr: Device address of the memory region from DSP view - * @size: Size of the memory region - */ -struct k3_dsp_mem { - void __iomem *cpu_addr; - phys_addr_t bus_addr; - u32 dev_addr; - size_t size; -}; - -/** - * struct k3_dsp_mem_data - memory definitions for a DSP - * @name: name for this memory entry - * @dev_addr: device address for the memory entry - */ -struct k3_dsp_mem_data { - const char *name; - const u32 dev_addr; -}; - -/** - * struct k3_dsp_dev_data - device data structure for a DSP - * @mems: pointer to memory definitions for a DSP - * @num_mems: number of memory regions in @mems - * @boot_align_addr: boot vector address alignment granularity - * @uses_lreset: flag to denote the need for local reset management - */ -struct k3_dsp_dev_data { - const struct k3_dsp_mem_data *mems; - u32 num_mems; - u32 boot_align_addr; - bool uses_lreset; -}; - -/** - * struct k3_dsp_rproc - k3 DSP remote processor driver structure - * @dev: cached device pointer - * @rproc: remoteproc device handle - * @mem: internal memory regions data - * @num_mems: number of internal memory regions - * @rmem: reserved memory regions data - * @num_rmems: number of reserved memory regions - * @reset: reset control handle - * @data: pointer to DSP-specific device data - * @tsp: TI-SCI processor control handle - * @ti_sci: TI-SCI handle - * @ti_sci_id: TI-SCI device identifier - * @mbox: mailbox channel handle - * @client: mailbox client to request the mailbox channel - * @priv: Remote processor private data - */ -struct k3_dsp_rproc { - struct device *dev; - struct rproc *rproc; - struct k3_dsp_mem *mem; - int num_mems; - struct k3_dsp_mem *rmem; - int num_rmems; - struct reset_control *reset; - const struct k3_dsp_dev_data *data; - struct ti_sci_proc *tsp; - const struct ti_sci_handle *ti_sci; - u32 ti_sci_id; - struct mbox_chan *mbox; - struct mbox_client client; - void *priv; -}; - /** * k3_dsp_rproc_mbox_callback() - inbound mailbox message handler * @client: mailbox client pointer used for requesting the mailbox channel @@ -111,8 +40,7 @@ struct k3_dsp_rproc { */ static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data) { - struct k3_dsp_rproc *kproc = container_of(client, struct k3_dsp_rproc, - client); + struct k3_rproc *kproc = container_of(client, struct k3_rproc, client); struct device *dev = kproc->rproc->dev.parent; const char *name = kproc->rproc->name; u32 msg = omap_mbox_message(data); @@ -152,7 +80,7 @@ static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data) */ static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid) { - struct k3_dsp_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = rproc->dev.parent; mbox_msg_t msg = (mbox_msg_t)vqid; int ret; @@ -165,7 +93,7 @@ static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid) } /* Put the DSP processor into reset */ -static int k3_dsp_rproc_reset(struct k3_dsp_rproc *kproc) +static int k3_dsp_rproc_reset(struct k3_rproc *kproc) { struct device *dev = kproc->dev; int ret; @@ -191,7 +119,7 @@ static int k3_dsp_rproc_reset(struct k3_dsp_rproc *kproc) } /* Release the DSP processor from reset */ -static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc) +static int k3_dsp_rproc_release(struct k3_rproc *kproc) { struct device *dev = kproc->dev; int ret; @@ -220,7 +148,7 @@ static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc) static int k3_dsp_rproc_request_mbox(struct rproc *rproc) { - struct k3_dsp_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct mbox_client *client = &kproc->client; struct device *dev = kproc->dev; int ret; @@ -264,7 +192,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc) */ static int k3_dsp_rproc_prepare(struct rproc *rproc) { - struct k3_dsp_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; int ret; @@ -288,7 +216,7 @@ static int k3_dsp_rproc_prepare(struct rproc *rproc) */ static int k3_dsp_rproc_unprepare(struct rproc *rproc) { - struct k3_dsp_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; int ret; @@ -309,7 +237,7 @@ 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 k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; u32 boot_addr; int ret; @@ -341,7 +269,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc) */ static int k3_dsp_rproc_stop(struct rproc *rproc) { - struct k3_dsp_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; k3_dsp_rproc_reset(kproc); @@ -381,7 +309,7 @@ static int k3_dsp_rproc_detach(struct rproc *rproc) { return 0; } 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 k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; if (!kproc->rmem[0].cpu_addr) { @@ -410,7 +338,7 @@ static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc, */ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) { - struct k3_dsp_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; void __iomem *va = NULL; phys_addr_t bus_addr; u32 dev_addr, offset; @@ -467,9 +395,9 @@ static const struct rproc_ops k3_dsp_rproc_ops = { }; static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev, - struct k3_dsp_rproc *kproc) + struct k3_rproc *kproc) { - const struct k3_dsp_dev_data *data = kproc->data; + const struct k3_rproc_dev_data *data = kproc->data; struct device *dev = &pdev->dev; struct resource *res; int num_mems = 0; @@ -525,7 +453,7 @@ static void k3_dsp_mem_release(void *data) of_reserved_mem_device_release(dev); } -static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc) +static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc) { struct device *dev = kproc->dev; struct device_node *np = dev->of_node; @@ -606,8 +534,8 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - const struct k3_dsp_dev_data *data; - struct k3_dsp_rproc *kproc; + const struct k3_rproc_dev_data *data; + struct k3_rproc *kproc; struct rproc *rproc; const char *fw_name; bool p_state = false; @@ -723,7 +651,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) static void k3_dsp_rproc_remove(struct platform_device *pdev) { - struct k3_dsp_rproc *kproc = platform_get_drvdata(pdev); + struct k3_rproc *kproc = platform_get_drvdata(pdev); struct rproc *rproc = kproc->rproc; struct device *dev = &pdev->dev; int ret; @@ -737,37 +665,37 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev) mbox_free_channel(kproc->mbox); } -static const struct k3_dsp_mem_data c66_mems[] = { +static const struct k3_rproc_mem_data c66_mems[] = { { .name = "l2sram", .dev_addr = 0x800000 }, { .name = "l1pram", .dev_addr = 0xe00000 }, { .name = "l1dram", .dev_addr = 0xf00000 }, }; /* C71x cores only have a L1P Cache, there are no L1P SRAMs */ -static const struct k3_dsp_mem_data c71_mems[] = { +static const struct k3_rproc_mem_data c71_mems[] = { { .name = "l2sram", .dev_addr = 0x800000 }, { .name = "l1dram", .dev_addr = 0xe00000 }, }; -static const struct k3_dsp_mem_data c7xv_mems[] = { +static const struct k3_rproc_mem_data c7xv_mems[] = { { .name = "l2sram", .dev_addr = 0x800000 }, }; -static const struct k3_dsp_dev_data c66_data = { +static const struct k3_rproc_dev_data c66_data = { .mems = c66_mems, .num_mems = ARRAY_SIZE(c66_mems), .boot_align_addr = SZ_1K, .uses_lreset = true, }; -static const struct k3_dsp_dev_data c71_data = { +static const struct k3_rproc_dev_data c71_data = { .mems = c71_mems, .num_mems = ARRAY_SIZE(c71_mems), .boot_align_addr = SZ_2M, .uses_lreset = false, }; -static const struct k3_dsp_dev_data c7xv_data = { +static const struct k3_rproc_dev_data c7xv_data = { .mems = c7xv_mems, .num_mems = ARRAY_SIZE(c7xv_mems), .boot_align_addr = SZ_2M, diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index e83bef7cfddf..04095407a483 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -19,78 +19,7 @@ #include "omap_remoteproc.h" #include "remoteproc_internal.h" #include "ti_sci_proc.h" - -/** - * struct k3_m4_rproc_mem - internal memory structure - * @cpu_addr: MPU virtual address of the memory region - * @bus_addr: Bus address used to access the memory region - * @dev_addr: Device address of the memory region from remote processor view - * @size: Size of the memory region - */ -struct k3_m4_rproc_mem { - void __iomem *cpu_addr; - phys_addr_t bus_addr; - u32 dev_addr; - size_t size; -}; - -/** - * struct k3_m4_mem_data - memory definitions for a remote processor - * @name: name for this memory entry - * @dev_addr: device address for the memory entry - */ -struct k3_m4_mem_data { - const char *name; - const u32 dev_addr; -}; - -/** - * struct k3_m4_dev_data - device data structure for a M4 core - * @mems: pointer to memory definitions for a M4 core - * @num_mems: number of memory regions in @mems - * @boot_align_addr: boot vector address alignment granularity - * @uses_lreset: flag to denote the need for local reset management - */ -struct k3_m4_dev_data { - const struct k3_m4_mem_data *mems; - u32 num_mems; - u32 boot_align_addr; - bool uses_lreset; -}; - -/** - * struct k3_m4_rproc - k3 remote processor driver structure - * @dev: cached device pointer - * @rproc: remoteproc device handle - * @mem: internal memory regions data - * @num_mems: number of internal memory regions - * @rmem: reserved memory regions data - * @num_rmems: number of reserved memory regions - * @reset: reset control handle - * @data: pointer to M4-specific device data - * @tsp: TI-SCI processor control handle - * @ti_sci: TI-SCI handle - * @ti_sci_id: TI-SCI device identifier - * @mbox: mailbox channel handle - * @client: mailbox client to request the mailbox channel - * @priv: Remote processor private data - */ -struct k3_m4_rproc { - struct device *dev; - struct rproc *rproc; - struct k3_m4_rproc_mem *mem; - int num_mems; - struct k3_m4_rproc_mem *rmem; - int num_rmems; - struct reset_control *reset; - const struct k3_m4_dev_data *data; - struct ti_sci_proc *tsp; - const struct ti_sci_handle *ti_sci; - u32 ti_sci_id; - struct mbox_chan *mbox; - struct mbox_client client; - void *priv; -}; +#include "ti_k3_common.h" /** * k3_m4_rproc_mbox_callback() - inbound mailbox message handler @@ -147,7 +76,7 @@ static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data) */ static void k3_m4_rproc_kick(struct rproc *rproc, int vqid) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; u32 msg = (u32)vqid; int ret; @@ -163,7 +92,7 @@ static void k3_m4_rproc_kick(struct rproc *rproc, int vqid) ret); } -static int k3_m4_rproc_ping_mbox(struct k3_m4_rproc *kproc) +static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc) { struct device *dev = kproc->dev; int ret; @@ -195,7 +124,7 @@ static int k3_m4_rproc_ping_mbox(struct k3_m4_rproc *kproc) */ static int k3_m4_rproc_prepare(struct rproc *rproc) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; int ret; @@ -240,7 +169,7 @@ static int k3_m4_rproc_prepare(struct rproc *rproc) */ static int k3_m4_rproc_unprepare(struct rproc *rproc) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; int ret; @@ -271,7 +200,7 @@ static int k3_m4_rproc_unprepare(struct rproc *rproc) static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc, size_t *rsc_table_sz) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; if (!kproc->rmem[0].cpu_addr) { @@ -301,7 +230,7 @@ static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc, */ static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; void __iomem *va = NULL; phys_addr_t bus_addr; u32 dev_addr, offset; @@ -347,9 +276,9 @@ static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool } static int k3_m4_rproc_of_get_memories(struct platform_device *pdev, - struct k3_m4_rproc *kproc) + struct k3_rproc *kproc) { - const struct k3_m4_dev_data *data = kproc->data; + const struct k3_rproc_dev_data *data = kproc->data; struct device *dev = &pdev->dev; struct resource *res; int num_mems; @@ -405,7 +334,7 @@ static void k3_m4_rproc_dev_mem_release(void *data) of_reserved_mem_device_release(dev); } -static int k3_m4_reserved_mem_init(struct k3_m4_rproc *kproc) +static int k3_m4_reserved_mem_init(struct k3_rproc *kproc) { struct device *dev = kproc->dev; struct device_node *np = dev->of_node; @@ -490,7 +419,7 @@ static void k3_m4_release_tsp(void *data) */ static int k3_m4_rproc_start(struct rproc *rproc) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; int ret; @@ -515,7 +444,7 @@ static int k3_m4_rproc_start(struct rproc *rproc) */ static int k3_m4_rproc_stop(struct rproc *rproc) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; int ret; @@ -537,7 +466,7 @@ static int k3_m4_rproc_stop(struct rproc *rproc) */ static int k3_m4_rproc_attach(struct rproc *rproc) { - struct k3_m4_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; int ret; ret = k3_m4_rproc_ping_mbox(kproc); @@ -574,8 +503,8 @@ static const struct rproc_ops k3_m4_rproc_ops = { static int k3_m4_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct k3_m4_rproc *kproc; - const struct k3_m4_dev_data *data; + const struct k3_rproc_dev_data *data; + struct k3_rproc *kproc; struct rproc *rproc; const char *fw_name; bool r_state = false; @@ -668,12 +597,12 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) return 0; } -static const struct k3_m4_mem_data am64_m4_mems[] = { +static const struct k3_rproc_mem_data am64_m4_mems[] = { { .name = "iram", .dev_addr = 0x0 }, { .name = "dram", .dev_addr = 0x30000 }, }; -static const struct k3_m4_dev_data am64_m4_data = { +static const struct k3_rproc_dev_data am64_m4_data = { .mems = am64_m4_mems, .num_mems = ARRAY_SIZE(am64_m4_mems), .boot_align_addr = SZ_1K, diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 30081eafbd36..ee833d506c97 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -26,6 +26,7 @@ #include "omap_remoteproc.h" #include "remoteproc_internal.h" #include "ti_sci_proc.h" +#include "ti_k3_common.h" /* This address can either be for ATCM or BTCM with the other at address 0x0 */ #define K3_R5_TCM_DEV_ADDR 0x41010000 @@ -55,20 +56,6 @@ /* Applicable to only AM64x SoCs */ #define PROC_BOOT_STATUS_FLAG_R5_SINGLECORE_ONLY 0x00000200 -/** - * struct k3_r5_mem - internal memory structure - * @cpu_addr: MPU virtual address of the memory region - * @bus_addr: Bus address used to access the memory region - * @dev_addr: Device address from remoteproc view - * @size: Size of the memory region - */ -struct k3_r5_mem { - void __iomem *cpu_addr; - phys_addr_t bus_addr; - u32 dev_addr; - size_t size; -}; - /* * All cluster mode values are not applicable on all SoCs. The following * are the modes supported on various SoCs: @@ -84,30 +71,6 @@ enum cluster_mode { CLUSTER_MODE_SINGLECORE }; -/** - * struct k3_r5_mem_data - memory definitions for a R5 - * @name: name for this memory entry - * @dev_addr: device address for the memory entry - */ -struct k3_r5_mem_data { - const char *name; - const u32 dev_addr; -}; - -/** - * struct k3_r5_dev_data - device data structure for a R5 - * @mems: pointer to memory definitions for a R5 - * @num_mems: number of memory regions in @mems - * @boot_align_addr: boot vector address alignment granularity - * @uses_lreset: flag to denote the need for local reset management - */ -struct k3_r5_dev_data { - const struct k3_r5_mem_data *mems; - u32 num_mems; - u32 boot_align_addr; - bool uses_lreset; -}; - /** * struct k3_r5_soc_data - match data to handle SoC variations * @tcm_is_double: flag to denote the larger unified TCMs in certain modes @@ -121,7 +84,7 @@ struct k3_r5_soc_data { bool tcm_ecc_autoinit; bool single_cpu_mode; bool is_single_core; - const struct k3_r5_dev_data *core_data; + const struct k3_rproc_dev_data *core_data; }; /** @@ -140,8 +103,6 @@ struct k3_r5_cluster { const struct k3_r5_soc_data *soc_data; }; -struct k3_r5_rproc; - /** * struct k3_r5_core - K3 R5 core structure * @elem: linked list item @@ -158,9 +119,9 @@ struct k3_r5_rproc; struct k3_r5_core { struct list_head elem; struct device *dev; - struct k3_r5_rproc *kproc; + struct k3_rproc *kproc; struct k3_r5_cluster *cluster; - struct k3_r5_mem *sram; + struct k3_rproc_mem *sram; int num_sram; u32 atcm_enable; u32 btcm_enable; @@ -168,40 +129,6 @@ struct k3_r5_core { bool released_from_reset; }; -/** - * struct k3_r5_rproc - K3 remote processor state - * @dev: cached device pointer - * @rproc: rproc handle - * @mem: internal memory regions data - * @num_mems: number of internal memory regions - * @rmem: reserved memory regions data - * @num_rmems: number of reserved memory regions - * @reset: reset control handle - * @data: pointer to R5-core-specific device data - * @tsp: TI-SCI processor control handle - * @ti_sci: TI-SCI handle - * @ti_sci_id: TI-SCI device identifier - * @mbox: mailbox channel handle - * @client: mailbox client to request the mailbox channel - * @priv: Remote processor private data - */ -struct k3_r5_rproc { - struct device *dev; - struct rproc *rproc; - struct k3_r5_mem *mem; - int num_mems; - struct k3_r5_mem *rmem; - int num_rmems; - struct reset_control *reset; - const struct k3_r5_dev_data *data; - struct ti_sci_proc *tsp; - const struct ti_sci_handle *ti_sci; - u32 ti_sci_id; - struct mbox_chan *mbox; - struct mbox_client client; - void *priv; -}; - /** * k3_r5_rproc_mbox_callback() - inbound mailbox message handler * @client: mailbox client pointer used for requesting the mailbox channel @@ -218,8 +145,7 @@ struct k3_r5_rproc { */ static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data) { - struct k3_r5_rproc *kproc = container_of(client, struct k3_r5_rproc, - client); + struct k3_rproc *kproc = container_of(client, struct k3_rproc, client); struct device *dev = kproc->rproc->dev.parent; const char *name = kproc->rproc->name; u32 msg = omap_mbox_message(data); @@ -254,7 +180,7 @@ static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data) /* kick a virtqueue */ static void k3_r5_rproc_kick(struct rproc *rproc, int vqid) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct device *dev = rproc->dev.parent; mbox_msg_t msg = (mbox_msg_t)vqid; int ret; @@ -266,7 +192,7 @@ static void k3_r5_rproc_kick(struct rproc *rproc, int vqid) ret); } -static int k3_r5_split_reset(struct k3_r5_rproc *kproc) +static int k3_r5_split_reset(struct k3_rproc *kproc) { int ret; @@ -289,7 +215,7 @@ static int k3_r5_split_reset(struct k3_r5_rproc *kproc) return ret; } -static int k3_r5_split_release(struct k3_r5_rproc *kproc) +static int k3_r5_split_release(struct k3_rproc *kproc) { int ret; @@ -316,7 +242,7 @@ static int k3_r5_split_release(struct k3_r5_rproc *kproc) static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster) { struct k3_r5_core *core; - struct k3_r5_rproc *kproc; + struct k3_rproc *kproc; int ret; /* assert local reset on all applicable cores */ @@ -364,7 +290,7 @@ static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster) static int k3_r5_lockstep_release(struct k3_r5_cluster *cluster) { struct k3_r5_core *core; - struct k3_r5_rproc *kproc; + struct k3_rproc *kproc; int ret; /* enable PSC modules on all applicable cores */ @@ -409,13 +335,13 @@ static int k3_r5_lockstep_release(struct k3_r5_cluster *cluster) return ret; } -static inline int k3_r5_core_halt(struct k3_r5_rproc *kproc) +static inline int k3_r5_core_halt(struct k3_rproc *kproc) { return ti_sci_proc_set_control(kproc->tsp, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT, 0); } -static inline int k3_r5_core_run(struct k3_r5_rproc *kproc) +static inline int k3_r5_core_run(struct k3_rproc *kproc) { return ti_sci_proc_set_control(kproc->tsp, 0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT); @@ -423,7 +349,7 @@ static inline int k3_r5_core_run(struct k3_r5_rproc *kproc) static int k3_r5_rproc_request_mbox(struct rproc *rproc) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct mbox_client *client = &kproc->client; struct device *dev = kproc->dev; int ret; @@ -474,7 +400,7 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc) */ static int k3_r5_rproc_prepare(struct rproc *rproc) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct k3_r5_core *core = kproc->priv, *core0, *core1; struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; @@ -572,7 +498,7 @@ static int k3_r5_rproc_prepare(struct rproc *rproc) */ static int k3_r5_rproc_unprepare(struct rproc *rproc) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct k3_r5_core *core = kproc->priv, *core0, *core1; struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; @@ -635,7 +561,7 @@ static int k3_r5_rproc_unprepare(struct rproc *rproc) */ static int k3_r5_rproc_start(struct rproc *rproc) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct k3_r5_core *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; struct device *dev = kproc->dev; @@ -700,7 +626,7 @@ static int k3_r5_rproc_start(struct rproc *rproc) */ static int k3_r5_rproc_stop(struct rproc *rproc) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct k3_r5_core *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; int ret; @@ -764,7 +690,7 @@ static int k3_r5_rproc_detach(struct rproc *rproc) { return 0; } 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 k3_rproc *kproc = rproc->priv; struct device *dev = kproc->dev; if (!kproc->rmem[0].cpu_addr) { @@ -793,7 +719,7 @@ static struct resource_table *k3_r5_get_loaded_rsc_table(struct rproc *rproc, */ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) { - struct k3_r5_rproc *kproc = rproc->priv; + struct k3_rproc *kproc = rproc->priv; struct k3_r5_core *core = kproc->priv; void __iomem *va = NULL; phys_addr_t bus_addr; @@ -896,7 +822,7 @@ static const struct rproc_ops k3_r5_rproc_ops = { * both the cores with the same settings, before reconfiguing again for * LockStep mode. */ -static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc) +static int k3_r5_rproc_configure(struct k3_rproc *kproc) { struct k3_r5_core *temp, *core0, *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; @@ -1025,7 +951,7 @@ static void k3_r5_mem_release(void *data) of_reserved_mem_device_release(dev); } -static int k3_r5_reserved_mem_init(struct k3_r5_rproc *kproc) +static int k3_r5_reserved_mem_init(struct k3_rproc *kproc) { struct device *dev = kproc->dev; struct device_node *np = dev_of_node(dev); @@ -1118,7 +1044,7 @@ static int k3_r5_reserved_mem_init(struct k3_r5_rproc *kproc) * supported SoCs. The Core0 TCM sizes therefore have to be adjusted to only * half the original size in Split mode. */ -static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc) +static void k3_r5_adjust_tcm_sizes(struct k3_rproc *kproc) { struct k3_r5_core *core0, *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; @@ -1156,7 +1082,7 @@ static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc) * 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) +static int k3_r5_rproc_configure_mode(struct k3_rproc *kproc) { struct k3_r5_core *core0, *core = kproc->priv; struct k3_r5_cluster *cluster = core->cluster; @@ -1261,9 +1187,9 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) } static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, - struct k3_r5_rproc *kproc) + struct k3_rproc *kproc) { - const struct k3_r5_dev_data *data = kproc->data; + const struct k3_rproc_dev_data *data = kproc->data; struct device *dev = &pdev->dev; struct k3_r5_core *core = kproc->priv; struct resource *res; @@ -1346,7 +1272,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) { struct k3_r5_cluster *cluster = platform_get_drvdata(pdev); struct device *dev = &pdev->dev; - struct k3_r5_rproc *kproc; + struct k3_rproc *kproc; struct k3_r5_core *core, *core1; struct device_node *np; struct device *cdev; @@ -1505,7 +1431,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) static void k3_r5_cluster_rproc_exit(void *data) { struct k3_r5_cluster *cluster = platform_get_drvdata(data); - struct k3_r5_rproc *kproc; + struct k3_rproc *kproc; struct k3_r5_core *core; struct rproc *rproc; int ret; @@ -1803,12 +1729,12 @@ static int k3_r5_probe(struct platform_device *pdev) return 0; } -static const struct k3_r5_mem_data r5_mems[] = { +static const struct k3_rproc_mem_data r5_mems[] = { { .name = "atcm", .dev_addr = 0x0 }, { .name = "btcm", .dev_addr = K3_R5_TCM_DEV_ADDR }, }; -static const struct k3_r5_dev_data r5_data = { +static const struct k3_rproc_dev_data r5_data = { .mems = r5_mems, .num_mems = ARRAY_SIZE(r5_mems), .boot_align_addr = 0, From patchwork Mon Mar 17 12:06:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019137 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A919239587; Mon, 17 Mar 2025 12:07:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213242; cv=none; b=u5UYSf8RwClaosZ8a5KsfXuefknmirOdeviEVVCkbj+HQLkl+UMm7VCRprzfoG4jyiq/loFSLj88xaC4Jxu45jNf0HxTceRjjlzHtEJQsD4mgj0WRMSqCEKikueXdQwSIAWMLuxH4cvRgEUgrehL/itsYm+YCVFZb6ulLDiH7yY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213242; c=relaxed/simple; bh=eCY+z11y5wZbGzC+NfUTrfMFmYuaTznrPFuX/dcZOIU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hzjwbE8Zyh/VnO/N6jBfni4XJt+cpNDEPIEmYE8BgCTyDUf7mdnXniC7OzSp+UWW/ZZdH7o1F8dfHhjBdIZmLIdikIfgJGPKtbdr9K6PJ05K44gJVqthv+IbkViYbc/tVlwsFPU8LjgzYbymcdE/maNnK47s+RoOoNrL2G7t2h0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=yI18NWtG; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="yI18NWtG" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC794V2266859 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:07:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213229; bh=zaf2qOSCeXN9fe99hTcH1tWZp87IoJV8bGnMUVfVTds=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=yI18NWtGZR/OvIaouPyzZ8VC2vg0yVQT0FV6P75hE/veIJ5JzsS9FHXgxgR3Y7Kvz +ndSU6R5OdQ0MmYXsHGS+yqtU6fRoN8OFbAOhvf3svuAA+PGI7v0x67G5To40j9lEW p+xq8XlLcv4zReVPV5LVQPmld/orwMLCT8gakdWA= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC798M005156; Mon, 17 Mar 2025 07:07:09 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:08 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:09 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK7060901; Mon, 17 Mar 2025 07:07:05 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 10/26] remoteproc: k3: Refactor mailbox rx_callback functions into common driver Date: Mon, 17 Mar 2025 17:36:06 +0530 Message-ID: <20250317120622.1746415-11-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The mailbox .rx_callback implementations in TI K3 R5, DSP and M4 remoteproc drivers handle inbound mailbox messages in the same way. Introduce a common driver 'ti_k3_common.c' and refactor the implementations into a common function 'k3_rproc_mbox_callback'() in it. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/Makefile | 4 +- drivers/remoteproc/ti_k3_common.c | 83 +++++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 50 +------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 49 +------------ drivers/remoteproc/ti_k3_r5_remoteproc.c | 50 +------------- 6 files changed, 89 insertions(+), 148 deletions(-) create mode 100644 drivers/remoteproc/ti_k3_common.c diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile index 5ff4e2fee4ab..e30908ca4bfc 100644 --- a/drivers/remoteproc/Makefile +++ b/drivers/remoteproc/Makefile @@ -36,7 +36,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o -obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o -obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o +obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o +obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c new file mode 100644 index 000000000000..56caf7a51b59 --- /dev/null +++ b/drivers/remoteproc/ti_k3_common.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * TI K3 Remote Processor(s) driver common code + * + * Refactored out of ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c. + * + * ti_k3_dsp_remoteproc.c: + * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ + * Suman Anna + * + * ti_k3_m4_remoteproc.c: + * Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/ + * Hari Nagalla + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "omap_remoteproc.h" +#include "remoteproc_internal.h" +#include "ti_sci_proc.h" +#include "ti_k3_common.h" + +/** + * k3_rproc_mbox_callback() - inbound mailbox message handler + * @client: mailbox client pointer used for requesting the mailbox channel + * @data: mailbox payload + * + * This handler is invoked by the K3 mailbox driver whenever a mailbox + * message is received. Usually, the mailbox payload simply contains + * the index of the virtqueue that is kicked by the remote processor, + * and we let remoteproc core handle it. + * + * In addition to virtqueue indices, we also have some out-of-band values + * that indicate different events. Those values are deliberately very + * large so they don't coincide with virtqueue indices. + */ +void k3_rproc_mbox_callback(struct mbox_client *client, void *data) +{ + struct k3_rproc *kproc = container_of(client, struct k3_rproc, client); + struct device *dev = kproc->rproc->dev.parent; + struct rproc *rproc = kproc->rproc; + u32 msg = (u32)(uintptr_t)(data); + + dev_dbg(dev, "mbox msg: 0x%x\n", msg); + + switch (msg) { + case RP_MBOX_CRASH: + /* + * remoteproc detected an exception, but error recovery is not + * supported. So, just log this for now + */ + dev_err(dev, "K3 rproc %s crashed\n", rproc->name); + break; + case RP_MBOX_ECHO_REPLY: + dev_info(dev, "received echo reply from %s\n", rproc->name); + break; + default: + /* silently handle all other valid messages */ + if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG) + return; + if (msg > rproc->max_notifyid) { + dev_dbg(dev, "dropping unknown message 0x%x", msg); + return; + } + /* msg contains the index of the triggered vring */ + if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE) + dev_dbg(dev, "no message was found in vqid %d\n", msg); + } +} +EXPORT_SYMBOL_GPL(k3_rproc_mbox_callback); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 43aedab9f0aa..785bb4b17d02 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -88,4 +88,5 @@ struct k3_rproc { void *priv; }; +void k3_rproc_mbox_callback(struct mbox_client *client, void *data); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index e92fab831670..7bd1d5a790cb 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,54 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/** - * k3_dsp_rproc_mbox_callback() - inbound mailbox message handler - * @client: mailbox client pointer used for requesting the mailbox channel - * @data: mailbox payload - * - * This handler is invoked by the OMAP mailbox driver whenever a mailbox - * message is received. Usually, the mailbox payload simply contains - * the index of the virtqueue that is kicked by the remote processor, - * and we let remoteproc core handle it. - * - * In addition to virtqueue indices, we also have some out-of-band values - * that indicate different events. Those values are deliberately very - * large so they don't coincide with virtqueue indices. - */ -static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data) -{ - struct k3_rproc *kproc = container_of(client, struct k3_rproc, client); - struct device *dev = kproc->rproc->dev.parent; - const char *name = kproc->rproc->name; - u32 msg = omap_mbox_message(data); - - dev_dbg(dev, "mbox msg: 0x%x\n", msg); - - switch (msg) { - case RP_MBOX_CRASH: - /* - * remoteproc detected an exception, but error recovery is not - * supported. So, just log this for now - */ - dev_err(dev, "K3 DSP rproc %s crashed\n", name); - break; - case RP_MBOX_ECHO_REPLY: - dev_info(dev, "received echo reply from %s\n", name); - break; - default: - /* silently handle all other valid messages */ - if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG) - return; - if (msg > kproc->rproc->max_notifyid) { - dev_dbg(dev, "dropping unknown message 0x%x", msg); - return; - } - /* msg contains the index of the triggered vring */ - if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE) - dev_dbg(dev, "no message was found in vqid %d\n", msg); - } -} - /* * Kick the remote processor to notify about pending unprocessed messages. * The vqid usage is not used and is inconsequential, as the kick is performed @@ -155,7 +107,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc) client->dev = dev; client->tx_done = NULL; - client->rx_callback = k3_dsp_rproc_mbox_callback; + client->rx_callback = k3_rproc_mbox_callback; client->tx_block = false; client->knows_txdone = false; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 04095407a483..a1bcc4b265df 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,53 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -/** - * k3_m4_rproc_mbox_callback() - inbound mailbox message handler - * @client: mailbox client pointer used for requesting the mailbox channel - * @data: mailbox payload - * - * This handler is invoked by the K3 mailbox driver whenever a mailbox - * message is received. Usually, the mailbox payload simply contains - * the index of the virtqueue that is kicked by the remote processor, - * and we let remoteproc core handle it. - * - * In addition to virtqueue indices, we also have some out-of-band values - * that indicate different events. Those values are deliberately very - * large so they don't coincide with virtqueue indices. - */ -static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data) -{ - struct device *dev = client->dev; - struct rproc *rproc = dev_get_drvdata(dev); - u32 msg = (u32)(uintptr_t)(data); - - dev_dbg(dev, "mbox msg: 0x%x\n", msg); - - switch (msg) { - case RP_MBOX_CRASH: - /* - * remoteproc detected an exception, but error recovery is not - * supported. So, just log this for now - */ - dev_err(dev, "K3 rproc %s crashed\n", rproc->name); - break; - case RP_MBOX_ECHO_REPLY: - dev_info(dev, "received echo reply from %s\n", rproc->name); - break; - default: - /* silently handle all other valid messages */ - if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG) - return; - if (msg > rproc->max_notifyid) { - dev_dbg(dev, "dropping unknown message 0x%x", msg); - return; - } - /* msg contains the index of the triggered vring */ - if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE) - dev_dbg(dev, "no message was found in vqid %d\n", msg); - } -} - /* * Kick the remote processor to notify about pending unprocessed messages. * The vqid usage is not used and is inconsequential, as the kick is performed @@ -581,7 +534,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) kproc->client.dev = dev; kproc->client.tx_done = NULL; - kproc->client.rx_callback = k3_m4_rproc_mbox_callback; + kproc->client.rx_callback = k3_rproc_mbox_callback; kproc->client.tx_block = false; kproc->client.knows_txdone = false; kproc->mbox = mbox_request_channel(&kproc->client, 0); diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index ee833d506c97..c817a4ac54a7 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -129,54 +129,6 @@ struct k3_r5_core { bool released_from_reset; }; -/** - * k3_r5_rproc_mbox_callback() - inbound mailbox message handler - * @client: mailbox client pointer used for requesting the mailbox channel - * @data: mailbox payload - * - * This handler is invoked by the OMAP mailbox driver whenever a mailbox - * message is received. Usually, the mailbox payload simply contains - * the index of the virtqueue that is kicked by the remote processor, - * and we let remoteproc core handle it. - * - * In addition to virtqueue indices, we also have some out-of-band values - * that indicate different events. Those values are deliberately very - * large so they don't coincide with virtqueue indices. - */ -static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data) -{ - struct k3_rproc *kproc = container_of(client, struct k3_rproc, client); - struct device *dev = kproc->rproc->dev.parent; - const char *name = kproc->rproc->name; - u32 msg = omap_mbox_message(data); - - dev_dbg(dev, "mbox msg: 0x%x\n", msg); - - switch (msg) { - case RP_MBOX_CRASH: - /* - * remoteproc detected an exception, but error recovery is not - * supported. So, just log this for now - */ - dev_err(dev, "K3 R5F rproc %s crashed\n", name); - break; - case RP_MBOX_ECHO_REPLY: - dev_info(dev, "received echo reply from %s\n", name); - break; - default: - /* silently handle all other valid messages */ - if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG) - return; - if (msg > kproc->rproc->max_notifyid) { - dev_dbg(dev, "dropping unknown message 0x%x", msg); - return; - } - /* msg contains the index of the triggered vring */ - if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE) - dev_dbg(dev, "no message was found in vqid %d\n", msg); - } -} - /* kick a virtqueue */ static void k3_r5_rproc_kick(struct rproc *rproc, int vqid) { @@ -356,7 +308,7 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc) client->dev = dev; client->tx_done = NULL; - client->rx_callback = k3_r5_rproc_mbox_callback; + client->rx_callback = k3_rproc_mbox_callback; client->tx_block = false; client->knows_txdone = false; From patchwork Mon Mar 17 12:06:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019139 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DF862397BE; Mon, 17 Mar 2025 12:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213245; cv=none; b=dfAyH5MmF3+Josn49nV7Uru0gd78PHL4+z9iefOICsQQvKfbFWAWdkfYUpxXsKK8S8KrMxEOIkMEQfALs8AAo+x11xReWj0zFTHmGfeios8HS/pLc/SYzNOsWcw8bpe4hnyvDUxqQdHC77n1xgm/7rfGswTxeM9wYgqNu2UDWXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213245; c=relaxed/simple; bh=+SbaA0yiBC7g0hVGBVSAHkXPOUgEm+rI17go6LQU5M0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WBtavOFWlaYvAs+rJ//sbTusV+OcRRl8qEV9JM6uWF92HhMtjn7nJbAk15mq7SPZBHGVG1X+4t4brFv/pnY6hT4q7nb7oTN9iS1QPBhxuHwOBRI6RrX/WKGGygUodfKvIUSijarcxE+k6I8dKPDa8H/kGZ+jewDqp7Ms/wuaCW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=c55JaDGA; arc=none smtp.client-ip=198.47.19.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="c55JaDGA" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7Dmp2755521 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:07:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213233; bh=q1DkX2pACE4CykC32zg9yYF4imOvW9d6IGICR1ICLQo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=c55JaDGAdAodJIpEu7+P6SdAf/rohR+VFq58jNjMIaGMOsqPdZDR4JPRqCrGcCBzg RjJpBadxJeM0zqdKp/sNO1Ug0lapMYrs2Whd4K7BpMtjVbvP/F/axdMIAFxpcjlXQU SoxIWhyRKJ2jXd4z0H8l70Uo9Jj5lz9a21TQwnFI= 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 ESMTP id 52HC7Drg005180; Mon, 17 Mar 2025 07:07:13 -0500 Received: from DLEE114.ent.ti.com (157.170.170.25) 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.2507.23; Mon, 17 Mar 2025 07:07:12 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:12 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK8060901; Mon, 17 Mar 2025 07:07:09 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 11/26] remoteproc: k3: Refactor .kick rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:07 +0530 Message-ID: <20250317120622.1746415-12-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .kick rproc ops implementations in TI K3 R5, DSP and M4 remoteproc drivers sends a mailbox message to the remote processor in the same way. Refactor the implementations into a common function 'k3_rproc_kick()' in the ti_k3_common.c driver. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 25 ++++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 22 +------------------ drivers/remoteproc/ti_k3_m4_remoteproc.c | 26 +---------------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 17 +-------------- 5 files changed, 29 insertions(+), 62 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 56caf7a51b59..f91ca9f0079f 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -79,5 +79,30 @@ void k3_rproc_mbox_callback(struct mbox_client *client, void *data) } EXPORT_SYMBOL_GPL(k3_rproc_mbox_callback); +/* + * Kick the remote processor to notify about pending unprocessed messages. + * The vqid usage is not used and is inconsequential, as the kick is performed + * through a simulated GPIO (a bit in an IPC interrupt-triggering register), + * the remote processor is expected to process both its Tx and Rx virtqueues. + */ +void k3_rproc_kick(struct rproc *rproc, int vqid) +{ + struct k3_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + u32 msg = (u32)vqid; + int ret; + + /* + * Send the index of the triggered virtqueue in the mailbox payload. + * NOTE: msg is cast to uintptr_t to prevent compiler warnings when + * void* is 64bit. It is safely cast back to u32 in the mailbox driver. + */ + ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg); + if (ret < 0) + dev_err(dev, "failed to send mailbox message, status = %d\n", + ret); +} +EXPORT_SYMBOL_GPL(k3_rproc_kick); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 785bb4b17d02..6ae7ac4ec569 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -89,4 +89,5 @@ struct k3_rproc { }; void k3_rproc_mbox_callback(struct mbox_client *client, void *data); +void k3_rproc_kick(struct rproc *rproc, int vqid); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 7bd1d5a790cb..476f4e69d2c1 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,26 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/* - * Kick the remote processor to notify about pending unprocessed messages. - * The vqid usage is not used and is inconsequential, as the kick is performed - * through a simulated GPIO (a bit in an IPC interrupt-triggering register), - * the remote processor is expected to process both its Tx and Rx virtqueues. - */ -static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = rproc->dev.parent; - mbox_msg_t msg = (mbox_msg_t)vqid; - int ret; - - /* send the index of the triggered virtqueue in the mailbox payload */ - ret = mbox_send_message(kproc->mbox, (void *)msg); - if (ret < 0) - dev_err(dev, "failed to send mailbox message (%pe)\n", - ERR_PTR(ret)); -} - /* Put the DSP processor into reset */ static int k3_dsp_rproc_reset(struct k3_rproc *kproc) { @@ -342,7 +322,7 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool static const struct rproc_ops k3_dsp_rproc_ops = { .start = k3_dsp_rproc_start, .stop = k3_dsp_rproc_stop, - .kick = k3_dsp_rproc_kick, + .kick = k3_rproc_kick, .da_to_va = k3_dsp_rproc_da_to_va, }; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index a1bcc4b265df..8a6917259ce6 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,30 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -/* - * Kick the remote processor to notify about pending unprocessed messages. - * The vqid usage is not used and is inconsequential, as the kick is performed - * through a simulated GPIO (a bit in an IPC interrupt-triggering register), - * the remote processor is expected to process both its Tx and Rx virtqueues. - */ -static void k3_m4_rproc_kick(struct rproc *rproc, int vqid) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - u32 msg = (u32)vqid; - int ret; - - /* - * Send the index of the triggered virtqueue in the mailbox payload. - * NOTE: msg is cast to uintptr_t to prevent compiler warnings when - * void* is 64bit. It is safely cast back to u32 in the mailbox driver. - */ - ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg); - if (ret < 0) - dev_err(dev, "failed to send mailbox message, status = %d\n", - ret); -} - static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc) { struct device *dev = kproc->dev; @@ -448,7 +424,7 @@ static const struct rproc_ops k3_m4_rproc_ops = { .stop = k3_m4_rproc_stop, .attach = k3_m4_rproc_attach, .detach = k3_m4_rproc_detach, - .kick = k3_m4_rproc_kick, + .kick = k3_rproc_kick, .da_to_va = k3_m4_rproc_da_to_va, .get_loaded_rsc_table = k3_m4_get_loaded_rsc_table, }; diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index c817a4ac54a7..36fffcf1e881 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -129,21 +129,6 @@ struct k3_r5_core { bool released_from_reset; }; -/* kick a virtqueue */ -static void k3_r5_rproc_kick(struct rproc *rproc, int vqid) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = rproc->dev.parent; - mbox_msg_t msg = (mbox_msg_t)vqid; - int ret; - - /* send the index of the triggered virtqueue in the mailbox payload */ - ret = mbox_send_message(kproc->mbox, (void *)msg); - if (ret < 0) - dev_err(dev, "failed to send mailbox message, status = %d\n", - ret); -} - static int k3_r5_split_reset(struct k3_rproc *kproc) { int ret; @@ -735,7 +720,7 @@ static const struct rproc_ops k3_r5_rproc_ops = { .unprepare = k3_r5_rproc_unprepare, .start = k3_r5_rproc_start, .stop = k3_r5_rproc_stop, - .kick = k3_r5_rproc_kick, + .kick = k3_rproc_kick, .da_to_va = k3_r5_rproc_da_to_va, }; From patchwork Mon Mar 17 12:06:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019140 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE94423A563; Mon, 17 Mar 2025 12:07:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213246; cv=none; b=X6iR/ERTHCXK3OSI6xwvJNBPuqt53qOXqFlwts8YD/YTmyiz/MnQ2sR2YwZiDpIlxQgqwl9ng9FlaQFum5hrhfVnTTT765P7zXTX+NoifqkDXm1KZVSO38lSoyelMTJ880HU3LLa9j4T398fySP8x9IxUydSMAOmKGdGRM1Shvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213246; c=relaxed/simple; bh=oitq38LFTS+dfpwNlEu1jnZGkypffIfm+Lb3si+ZKWg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OB5GzrF8k7c14bqH8HyIf2xe5yRtRZ7DThyMfcGeUlqb/qIG/WL0RZPBOH9Mldba4tgz7GFv4Uk7QeC5K/RjJ47RSeILonsCqz8EP7jNfxqzr9j8ziIw5TvE3qK5f9pFxI7jH5X0pJdQQmYyCAaYdSitSrDfMso/KR3EDDUgN8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=TjeOfH36; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="TjeOfH36" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7GdU2802885 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:07:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213236; bh=FmpFBvAzI+PELtAJ29va2+xIMxs9wnT0Ex7hPpgkDAI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=TjeOfH36AmKDHbVJkSScMIo3ofFknmLSmS6WLaQLOS3p8dMKp24yvVKM1dgj8g4nv WOsrtb0ykE5+rC89R4LYC1aPPE9l43L7IfrMC67P5JJALeUGA3nM1MYmDN64UWarcY TVE8KdGr73gIuZWaGYPGfdkbH23edysGzCvDGKbQ= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC7G2P005196; Mon, 17 Mar 2025 07:07:16 -0500 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:16 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:16 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MK9060901; Mon, 17 Mar 2025 07:07:13 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 12/26] remoteproc: k3: Refactor rproc_reset() implementation into common driver Date: Mon, 17 Mar 2025 17:36:08 +0530 Message-ID: <20250317120622.1746415-13-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_dsp_rproc_reset() function erroneously asserts the local reset even for devices which do not support it. Even though it results in a no-operation, Update the logic to explicitly assert the local reset for devices that support it and only the global reset for those that do not. Further, refactor the above function into the ti_k3_common.c driver as k3_rproc_reset() and use it throughout DSP and M4 drivers for resetting the remote processor. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 25 +++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 30 ++--------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 16 +++--------- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index f91ca9f0079f..db6a12c89226 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -104,5 +104,30 @@ void k3_rproc_kick(struct rproc *rproc, int vqid) } EXPORT_SYMBOL_GPL(k3_rproc_kick); +/* Put the remote processor into reset */ +int k3_rproc_reset(struct k3_rproc *kproc) +{ + struct device *dev = kproc->dev; + int ret; + + if (kproc->data->uses_lreset) { + ret = reset_control_assert(kproc->reset); + if (ret) + dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret)); + return ret; + } + + ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id); + if (ret) { + dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret)); + if (reset_control_deassert(kproc->reset)) + dev_warn(dev, "local-reset deassert back failed\n"); + } + + return ret; +} +EXPORT_SYMBOL_GPL(k3_rproc_reset); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 6ae7ac4ec569..f3400fc77476 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -90,4 +90,5 @@ struct k3_rproc { void k3_rproc_mbox_callback(struct mbox_client *client, void *data); void k3_rproc_kick(struct rproc *rproc, int vqid); +int k3_rproc_reset(struct k3_rproc *kproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 476f4e69d2c1..f8a5282df5b7 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,32 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/* Put the DSP processor into reset */ -static int k3_dsp_rproc_reset(struct k3_rproc *kproc) -{ - struct device *dev = kproc->dev; - int ret; - - ret = reset_control_assert(kproc->reset); - if (ret) { - dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret)); - return ret; - } - - if (kproc->data->uses_lreset) - return ret; - - ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, - kproc->ti_sci_id); - if (ret) { - dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret)); - if (reset_control_deassert(kproc->reset)) - dev_warn(dev, "local-reset deassert back failed\n"); - } - - return ret; -} - /* Release the DSP processor from reset */ static int k3_dsp_rproc_release(struct k3_rproc *kproc) { @@ -203,7 +177,7 @@ static int k3_dsp_rproc_stop(struct rproc *rproc) { struct k3_rproc *kproc = rproc->priv; - k3_dsp_rproc_reset(kproc); + k3_rproc_reset(kproc); return 0; } @@ -567,7 +541,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "failed to get reset status\n"); } else if (ret == 0) { dev_warn(dev, "local reset is deasserted for device\n"); - k3_dsp_rproc_reset(kproc); + k3_rproc_reset(kproc); } } } diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 8a6917259ce6..7d5b75be2e4f 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -65,11 +65,9 @@ static int k3_m4_rproc_prepare(struct rproc *rproc) * Ensure the local reset is asserted so the core doesn't * execute bogus code when the module reset is released. */ - ret = reset_control_assert(kproc->reset); - if (ret) { - dev_err(dev, "could not assert local reset\n"); + ret = k3_rproc_reset(kproc); + if (ret) return ret; - } ret = reset_control_status(kproc->reset); if (ret <= 0) { @@ -374,16 +372,8 @@ static int k3_m4_rproc_start(struct rproc *rproc) static int k3_m4_rproc_stop(struct rproc *rproc) { struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - int ret; - ret = reset_control_assert(kproc->reset); - if (ret) { - dev_err(dev, "local-reset assert failed, ret = %d\n", ret); - return ret; - } - - return 0; + return k3_rproc_reset(kproc); } /* From patchwork Mon Mar 17 12:06:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019141 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62971241131; Mon, 17 Mar 2025 12:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213251; cv=none; b=FnoCylInzKL6bPhY5JZEOX3gEoAX+PgRkRfTNwKxweZIeV3nJvQgLrFhOs2RUDlzC4KydJ7NKYuwqis0eHFvtUtaKK4ixgta81haplIyakcGaVzXseSV+r1GgZJpDzEscQRTJU8KCsUzn15T/qSrepbwGgPnxBqhnurcayRP1vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213251; c=relaxed/simple; bh=lzzZgZEkOiAWPB4ufuINXi6X98kVKrVdAnyrcp19Z2Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nJYV0oVnLPdKJtg+6iyybnzFyNI2GxknvUBnX0HJYRxWfwehlFpfdV5r7Y4+hFFF8TYpKEYvzkRf5zlQRhJ5bbhRV1D6vem8g47t+8sDoovQ6Q9vDusSlQrd+3qzfisBh7ZaojntqArOj4UwhgDHsT1btDNo3otyDMCoDfF2jRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=n6DsbIkx; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="n6DsbIkx" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7K0S2802895 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213240; bh=tY5l8nx9prH+KWgvUgwULRS9nJ8usFY32vn4hHQj1Q4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=n6DsbIkxjElh1mT0ANILT/RjpnDAYAvx+RKQgmkLqfRR6zbmMqTyiUmtujdJHXuXM tg+sIAqx/gC37eGdbqArHiI3iGTxR/wtKtpMWJN/DeoG2W5UkEV1aDitFhW3qyHmC9 EIMMVyGZ04CrE7dVaKsCAknvPYLfyeBAXwAX10zE= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7KJL108565 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:20 -0500 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:19 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:19 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKA060901; Mon, 17 Mar 2025 07:07:16 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 13/26] remoteproc: k3: Refactor rproc_release() implementation into common driver Date: Mon, 17 Mar 2025 17:36:09 +0530 Message-ID: <20250317120622.1746415-14-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_dsp_rproc_release() function erroneously deasserts the local reset even for devices which do not support it. Even though it results in a no-operation, Update the logic to explicitly deassert the local reset for devices that support it and only the global reset for those that do not. Further, refactor the above function into the ti_k3_common.c driver as k3_rproc_release() and use it throughout DSP and M4 drivers for releasing the reset from the remote processor. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 27 ++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 30 +---------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 8 +++--- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index db6a12c89226..3b1d041fec7b 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -129,5 +129,32 @@ int k3_rproc_reset(struct k3_rproc *kproc) } EXPORT_SYMBOL_GPL(k3_rproc_reset); +/* Release the remote processor from reset */ +int k3_rproc_release(struct k3_rproc *kproc) +{ + struct device *dev = kproc->dev; + int ret; + + if (kproc->data->uses_lreset) { + ret = reset_control_deassert(kproc->reset); + if (ret) { + dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret)); + if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id)) + dev_warn(dev, "module-reset assert back failed\n"); + } + + return ret; + } + + ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, + kproc->ti_sci_id); + if (ret) + dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret)); + + return ret; +} +EXPORT_SYMBOL_GPL(k3_rproc_release); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index f3400fc77476..c1af39cd288c 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -91,4 +91,5 @@ struct k3_rproc { void k3_rproc_mbox_callback(struct mbox_client *client, void *data); void k3_rproc_kick(struct rproc *rproc, int vqid); int k3_rproc_reset(struct k3_rproc *kproc); +int k3_rproc_release(struct k3_rproc *kproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index f8a5282df5b7..577dcd65093a 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,34 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/* Release the DSP processor from reset */ -static int k3_dsp_rproc_release(struct k3_rproc *kproc) -{ - struct device *dev = kproc->dev; - int ret; - - if (kproc->data->uses_lreset) - goto lreset; - - ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, - kproc->ti_sci_id); - if (ret) { - dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret)); - return ret; - } - -lreset: - ret = reset_control_deassert(kproc->reset); - if (ret) { - dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret)); - if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, - kproc->ti_sci_id)) - dev_warn(dev, "module-reset assert back failed\n"); - } - - return ret; -} - static int k3_dsp_rproc_request_mbox(struct rproc *rproc) { struct k3_rproc *kproc = rproc->priv; @@ -160,7 +132,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc) if (ret) return ret; - ret = k3_dsp_rproc_release(kproc); + ret = k3_rproc_release(kproc); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 7d5b75be2e4f..a8a5211bf0c7 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -354,13 +354,11 @@ static int k3_m4_rproc_start(struct rproc *rproc) if (ret) return ret; - ret = reset_control_deassert(kproc->reset); - if (ret) { + ret = k3_rproc_release(kproc); + if (ret) dev_err(dev, "local-reset deassert failed, ret = %d\n", ret); - return ret; - } - return 0; + return ret; } /* From patchwork Mon Mar 17 12:06:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019142 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDF9F238169; Mon, 17 Mar 2025 12:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213256; cv=none; b=OycsyYuKH44pEr8wIAxmB09KzFjJ+BxdO1vmkdTupfHxqyK6hCag/tAMzlKrrMWL64ccFcvKZaqk2HAwrL+PTp9/DgX9hEz8L0gqRuRlMnk0gBTNAqvJ53YVxjp1fEz0DbpaX72xVqoAhf8+nDeza53wBisKGomsjN91wtqPrTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213256; c=relaxed/simple; bh=dwyeB45KixiI9Mswpt1UmS3KAWcchU777LsUqOmNcgk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HNiu3hgTgdXn1Hq+FLdPuR/wDpyAqNTNu1Ldg1LrRb0mDzeAScLFiYeaMbZxHLxZ1O9aSmoXou3TrLLgSouNNjeBZXvUWg65WnlpSHTH5Y0O4iTI/sjrIwYaGQ5WIgxYHB+tjRHOYH+VfaK96F0NqTUx4fjJoUPnY7lVnUkVcSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=R3ZgAoni; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="R3ZgAoni" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7P6t2266875 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213245; bh=FXylo7+1ZXRUB93KYMsehvOdYPVANZEXW1xj70ZzNPk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=R3ZgAonixS9gSHmss60piO+w4N9Tmm0aSSKXKXM78cp9KSJk1ppJ8UBoHa9Ouxzog S1Q8qjMEpg6K9fJMGNSgu2GExORxLAxehhfltCBy7YSdxYlfME4QfjJSxsLxRp1v/v deug0kPbeYmyUNAAYJd3UbpgpdgTNtFJw/NWKHyc= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7P4p124251 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:25 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:24 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:23 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKB060901; Mon, 17 Mar 2025 07:07:20 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 14/26] remoteproc: k3: Refactor rproc_request_mbox() implementations into common driver Date: Mon, 17 Mar 2025 17:36:10 +0530 Message-ID: <20250317120622.1746415-15-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_{r5/dsp}_rproc_request_mbox() function acquires the mailbox channel and sends a message through the acquired channel. The TI K3 M4 remoteproc driver acquires the mailbox channel in probe and sends the message later in .attach()/.start() callbacks. Refactor the k3_{r5/dsp}_rproc_request_mbox() function into ti_k3_common.c as k3_rproc_request_mbox() and align R5, DSP and M4 drivers to use this common function during probe routine. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 36 +++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 36 +------------------ drivers/remoteproc/ti_k3_m4_remoteproc.c | 44 ++--------------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 37 +------------------ 5 files changed, 42 insertions(+), 112 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 3b1d041fec7b..5a39ce834a82 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -156,5 +156,41 @@ int k3_rproc_release(struct k3_rproc *kproc) } EXPORT_SYMBOL_GPL(k3_rproc_release); +int k3_rproc_request_mbox(struct rproc *rproc) +{ + struct k3_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_rproc_mbox_callback; + client->tx_block = false; + client->knows_txdone = false; + + kproc->mbox = mbox_request_channel(client, 0); + if (IS_ERR(kproc->mbox)) + return dev_err_probe(dev, PTR_ERR(kproc->mbox), + "mbox_request_channel failed\n"); + + /* + * 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 (%pe)\n", ERR_PTR(ret)); + mbox_free_channel(kproc->mbox); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(k3_rproc_request_mbox); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index c1af39cd288c..721492fa0fb7 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -92,4 +92,5 @@ void k3_rproc_mbox_callback(struct mbox_client *client, void *data); void k3_rproc_kick(struct rproc *rproc, int vqid); int k3_rproc_reset(struct k3_rproc *kproc); int k3_rproc_release(struct k3_rproc *kproc); +int k3_rproc_request_mbox(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 577dcd65093a..d1d35f819c23 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,40 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -static int k3_dsp_rproc_request_mbox(struct rproc *rproc) -{ - struct k3_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_rproc_mbox_callback; - client->tx_block = false; - client->knows_txdone = false; - - kproc->mbox = mbox_request_channel(client, 0); - if (IS_ERR(kproc->mbox)) - return dev_err_probe(dev, PTR_ERR(kproc->mbox), - "mbox_request_channel failed\n"); - - /* - * 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 (%pe)\n", ERR_PTR(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 @@ -443,7 +409,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) kproc->dev = dev; kproc->data = data; - ret = k3_dsp_rproc_request_mbox(rproc); + ret = k3_rproc_request_mbox(rproc); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index a8a5211bf0c7..15e7943a12c1 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,27 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc) -{ - struct device *dev = kproc->dev; - int 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); - return ret; - } - - return 0; -} - /* * The M4 cores have a local reset that affects only the CPU, and a * generic module reset that powers on the device and allows the internal @@ -350,10 +329,6 @@ static int k3_m4_rproc_start(struct rproc *rproc) struct device *dev = kproc->dev; int ret; - ret = k3_m4_rproc_ping_mbox(kproc); - if (ret) - return ret; - ret = k3_rproc_release(kproc); if (ret) dev_err(dev, "local-reset deassert failed, ret = %d\n", ret); @@ -383,13 +358,6 @@ static int k3_m4_rproc_stop(struct rproc *rproc) */ static int k3_m4_rproc_attach(struct rproc *rproc) { - struct k3_rproc *kproc = rproc->priv; - int ret; - - ret = k3_m4_rproc_ping_mbox(kproc); - if (ret) - return ret; - return 0; } @@ -496,15 +464,9 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) dev_info(dev, "configured M4F for remoteproc mode\n"); } - kproc->client.dev = dev; - kproc->client.tx_done = NULL; - kproc->client.rx_callback = k3_rproc_mbox_callback; - kproc->client.tx_block = false; - kproc->client.knows_txdone = false; - kproc->mbox = mbox_request_channel(&kproc->client, 0); - if (IS_ERR(kproc->mbox)) - return dev_err_probe(dev, PTR_ERR(kproc->mbox), - "mbox_request_channel failed\n"); + ret = k3_rproc_request_mbox(rproc); + if (ret) + return ret; ret = devm_rproc_add(dev, rproc); if (ret) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 36fffcf1e881..2bec94755e31 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -284,41 +284,6 @@ static inline int k3_r5_core_run(struct k3_rproc *kproc) 0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT); } -static int k3_r5_rproc_request_mbox(struct rproc *rproc) -{ - struct k3_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_rproc_mbox_callback; - client->tx_block = false; - client->knows_txdone = false; - - kproc->mbox = mbox_request_channel(client, 0); - if (IS_ERR(kproc->mbox)) - return dev_err_probe(dev, PTR_ERR(kproc->mbox), - "mbox_request_channel failed\n"); - - /* - * 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 @@ -1300,7 +1265,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) kproc = core->kproc; rproc = kproc->rproc; - ret = k3_r5_rproc_request_mbox(rproc); + ret = k3_rproc_request_mbox(rproc); if (ret) return ret; From patchwork Mon Mar 17 12:06:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019143 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84A023A9B2; Mon, 17 Mar 2025 12:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213257; cv=none; b=dK4Sjb/fE8E6AnGB4CNZeNQjVmpFFlNjyPek1aHa/nMGFtP3dR0I3R06V+vOMbzoL27Lfyt8pqI1ygiKTgplxzRBwDC5oVJNQJrSGwhLePvac9v8Ffua3cMf+QGrbGJzUS1sT+522ICoulZ/aroD9IMsKgaR5WG9Ghnv4FWglaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213257; c=relaxed/simple; bh=RifMcGKh0HsD+eKElwHGJtUY8rCajamv9b1qIjyaAvs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nt8o3DYY/v5B1YN4gsdNnT3My22kU0+tNecjbG1eMyrpV+owr+W8h19/qsQ0BO9obIHq1LKlPKy/7ZPAktkg+tDvOUq1Y4mv2GS9rqHju2MFWS4OQq48BwJD9ypT7xNzSRn2l2bCTefnOx3NzF64Op/B04uNonRR9bGHfQtSxiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=IR9Ne95I; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="IR9Ne95I" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7S7a2802909 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213248; bh=+c+vsqIt9vAf0SKUu0zw91WjC8xr8yRn1kaqCAtYBZI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=IR9Ne95IKSjc564j+gZVvhAwCpgZEYK/vC/N4VjMO9hXYmKiIJG2rg1pcKeBLzyvz wwuUcQZGVv1g6oyKW5GRDzPy1S7AMN0eAlD2LN8vGjl52cG0Ezhrgd9vkGTtAjF2g/ 4sCnlNw7FQBh9TxOKTshyZ36b6CidVqmkxK+N5wU= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7SpO000619 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:28 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:27 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:28 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKC060901; Mon, 17 Mar 2025 07:07:24 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 15/26] remoteproc: k3: Refactor .prepare rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:11 +0530 Message-ID: <20250317120622.1746415-16-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The ti_k3_dsp_remoteproc.c driver asserts the local reset in probe and releases the global reset in .prepare callback. Whereas, the ti_k3_m4_remoteproc.c driver does both operations in .prepare callback, which is more suitable as it ensures lreset is asserted for subsequent core start operations from sysfs. Refactor the k3_m4_rproc_prepare() function into the ti_k3_common.c driver as k3_rproc_prepare() and align DSP and M4 drivers to register this common function as .prepare ops. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 46 +++++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 42 +-------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 45 +--------------------- 4 files changed, 49 insertions(+), 85 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 5a39ce834a82..6550890334cd 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -192,5 +192,51 @@ int k3_rproc_request_mbox(struct rproc *rproc) } EXPORT_SYMBOL_GPL(k3_rproc_request_mbox); +/* + * The K3 DSP and M4 cores have a local reset that affects only the CPU, and a + * generic module reset that powers on the device and allows the internal + * memories to be accessed while the local reset is asserted. This function is + * used to release the global reset on remote cores to allow loading into the + * 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 remote cores to run. + */ +int k3_rproc_prepare(struct rproc *rproc) +{ + struct k3_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + int ret; + + /* If the core is running already no need to deassert the module reset */ + if (rproc->state == RPROC_DETACHED) + return 0; + + /* + * Ensure the local reset is asserted so the core doesn't + * execute bogus code when the module reset is released. + */ + if (kproc->data->uses_lreset) { + ret = k3_rproc_reset(kproc); + if (ret) + return ret; + + ret = reset_control_status(kproc->reset); + if (ret <= 0) { + dev_err(dev, "local reset still not asserted\n"); + return ret; + } + } + + ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, + kproc->ti_sci_id); + if (ret) { + dev_err(dev, "could not deassert module-reset for internal RAM loading\n"); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(k3_rproc_prepare); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 721492fa0fb7..5992a29ff492 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -93,4 +93,5 @@ void k3_rproc_kick(struct rproc *rproc, int vqid); int k3_rproc_reset(struct k3_rproc *kproc); int k3_rproc_release(struct k3_rproc *kproc); int k3_rproc_request_mbox(struct rproc *rproc); +int k3_rproc_prepare(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index d1d35f819c23..2fe2d4e89a48 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,31 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/* - * 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 - * memories to be accessed while the local reset is asserted. This function is - * 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. This callback is invoked only in - * remoteproc mode. - */ -static int k3_dsp_rproc_prepare(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - int ret; - - ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, - kproc->ti_sci_id); - if (ret) - dev_err(dev, "module-reset deassert failed, cannot enable internal RAM loading (%pe)\n", - ERR_PTR(ret)); - - return ret; -} - /* * This function implements the .unprepare() ops and performs the complimentary * operations to that of the .prepare() ops. The function is used to assert the @@ -401,7 +376,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) rproc->has_iommu = false; rproc->recovery_disabled = true; if (data->uses_lreset) { - rproc->ops->prepare = k3_dsp_rproc_prepare; + rproc->ops->prepare = k3_rproc_prepare; rproc->ops->unprepare = k3_dsp_rproc_unprepare; } kproc = rproc->priv; @@ -459,7 +434,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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; @@ -468,20 +442,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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) { - return dev_err_probe(dev, ret, "failed to get reset status\n"); - } else if (ret == 0) { - dev_warn(dev, "local reset is deasserted for device\n"); - k3_rproc_reset(kproc); - } - } } ret = devm_rproc_add(dev, rproc); diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 15e7943a12c1..0ad09e9b3ce0 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,49 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -/* - * The M4 cores have a local reset that affects only the CPU, and a - * generic module reset that powers on the device and allows the internal - * memories to be accessed while the local reset is asserted. This function is - * used to release the global reset on remote cores to allow loading into the - * 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 remote cores to run. - */ -static int k3_m4_rproc_prepare(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - int ret; - - /* If the core is running already no need to deassert the module reset */ - if (rproc->state == RPROC_DETACHED) - return 0; - - /* - * Ensure the local reset is asserted so the core doesn't - * execute bogus code when the module reset is released. - */ - ret = k3_rproc_reset(kproc); - if (ret) - return ret; - - ret = reset_control_status(kproc->reset); - if (ret <= 0) { - dev_err(dev, "local reset still not asserted\n"); - return ret; - } - - ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, - kproc->ti_sci_id); - if (ret) { - dev_err(dev, "could not deassert module-reset for internal RAM loading\n"); - return ret; - } - - return 0; -} - /* * This function implements the .unprepare() ops and performs the complimentary * operations to that of the .prepare() ops. The function is used to assert the @@ -374,7 +331,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc) } static const struct rproc_ops k3_m4_rproc_ops = { - .prepare = k3_m4_rproc_prepare, + .prepare = k3_rproc_prepare, .unprepare = k3_m4_rproc_unprepare, .start = k3_m4_rproc_start, .stop = k3_m4_rproc_stop, From patchwork Mon Mar 17 12:06:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019144 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 317952417F7; Mon, 17 Mar 2025 12:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213263; cv=none; b=i6FtZnZytnPMKGEU2vpeAx9BsJ8fK+8cWqEFmvpR0uvMjfJlAvDklTfY/dUm9Ktbsp/Kxefh8OF8dTap1nb1YVzPQJ2f/VVM93ZCikEZL10jMKKqNcVwiqfWTXAyJkd5actBuIjUGVojdJF6NX80MyHM8aYfMm+KCMJ0zN1o66U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213263; c=relaxed/simple; bh=JVtSbWra6fTD1ZwmVUY2kipOT1suSFjOH/jGRJ2Y8E4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MH2jjnuWtxu878V6BV0G6IsrC56krsf5xJnebasbiWGjowJaM23E1Xfw0zvY3xfEPRQKdZjWMexP2c1U4tsh9EowhZt0SeHtjAhB0P69RaKSJUePlr2etMrAmEtvWxRCi4o2pzEMuPeYu7/qpbeNFYvFokJuk5DBW++BN4T1orI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=kWQN2d3Z; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="kWQN2d3Z" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7YBP2802923 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213254; bh=CqX+VDh+ORktgaDcUkehV68TPkN3kEsOtuazldEfvUU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=kWQN2d3Za47XHZBIbP0NqbtRMOUy3nMC0VB4TdAawU9mbIAUgb2ppCAW8ag/welHg glPrtipmUe4Z8FreftrekjuHYCgCAp1YYmaIoQ2GvXFSCe1tkX4H7HLZqPNDkXsFKp 8aJTZC7YlqBq1yYmwpged1V87k+q8OUbkQwJjYpI= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7YNj108617 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:34 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) 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.2507.23; Mon, 17 Mar 2025 07:07:31 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:31 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKD060901; Mon, 17 Mar 2025 07:07:28 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 16/26] remoteproc: k3: Refactor .unprepare rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:12 +0530 Message-ID: <20250317120622.1746415-17-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .unprepare rproc ops implementations in ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c drivers assert the global reset on the remote processor. Refactor the implementations into ti_k3_common.c driver as k3_rproc_unprepare() and align DSP and M4 drivers to register this common function as .unprepare ops. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 30 ++++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 26 +------------------ drivers/remoteproc/ti_k3_m4_remoteproc.c | 31 +---------------------- 4 files changed, 33 insertions(+), 55 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 6550890334cd..e548beb817ca 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -238,5 +238,35 @@ int k3_rproc_prepare(struct rproc *rproc) } EXPORT_SYMBOL_GPL(k3_rproc_prepare); +/* + * This function implements the .unprepare() ops and performs the complimentary + * operations to that of the .prepare() ops. The function is used to assert the + * global reset on applicable K3 DSP and M4 cores. This completes the second + * portion of powering down the remote core. 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. + */ +int k3_rproc_unprepare(struct rproc *rproc) +{ + struct k3_rproc *kproc = rproc->priv; + struct device *dev = kproc->dev; + int ret; + + /* If the core is going to be detached do not assert the module reset */ + if (rproc->state == RPROC_ATTACHED) + return 0; + + ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, + kproc->ti_sci_id); + if (ret) { + dev_err(dev, "module-reset assert failed\n"); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(k3_rproc_unprepare); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 5992a29ff492..c1b07187c124 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -94,4 +94,5 @@ int k3_rproc_reset(struct k3_rproc *kproc); int k3_rproc_release(struct k3_rproc *kproc); int k3_rproc_request_mbox(struct rproc *rproc); int k3_rproc_prepare(struct rproc *rproc); +int k3_rproc_unprepare(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 2fe2d4e89a48..ca3afd11fb89 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -24,29 +24,6 @@ #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) -/* - * This function implements the .unprepare() ops and performs the complimentary - * operations to that of the .prepare() ops. The function is used to assert the - * global reset on applicable C66x cores. This completes the second portion of - * 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. This callback is invoked only in remoteproc mode. - */ -static int k3_dsp_rproc_unprepare(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - int ret; - - ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, - kproc->ti_sci_id); - if (ret) - dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret)); - - return ret; -} - /* * Power up the DSP remote processor. * @@ -377,7 +354,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) rproc->recovery_disabled = true; if (data->uses_lreset) { rproc->ops->prepare = k3_rproc_prepare; - rproc->ops->unprepare = k3_dsp_rproc_unprepare; + rproc->ops->unprepare = k3_rproc_unprepare; } kproc = rproc->priv; kproc->rproc = rproc; @@ -434,7 +411,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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->unprepare = NULL; rproc->ops->start = NULL; rproc->ops->stop = NULL; rproc->ops->attach = k3_dsp_rproc_attach; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 0ad09e9b3ce0..d53538d7dc0d 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,35 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -/* - * This function implements the .unprepare() ops and performs the complimentary - * operations to that of the .prepare() ops. The function is used to assert the - * global reset on applicable cores. This completes the second portion of - * powering down the remote core. 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. - */ -static int k3_m4_rproc_unprepare(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - int ret; - - /* If the core is going to be detached do not assert the module reset */ - if (rproc->state == RPROC_ATTACHED) - return 0; - - ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, - kproc->ti_sci_id); - if (ret) { - dev_err(dev, "module-reset assert failed\n"); - return ret; - } - - return 0; -} - /* * This function implements the .get_loaded_rsc_table() callback and is used * to provide the resource table for a booted remote processor in IPC-only @@ -332,7 +303,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc) static const struct rproc_ops k3_m4_rproc_ops = { .prepare = k3_rproc_prepare, - .unprepare = k3_m4_rproc_unprepare, + .unprepare = k3_rproc_unprepare, .start = k3_m4_rproc_start, .stop = k3_m4_rproc_stop, .attach = k3_m4_rproc_attach, From patchwork Mon Mar 17 12:06:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019145 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4E2323BD02; Mon, 17 Mar 2025 12:07:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213266; cv=none; b=R/XwAFfMORVvP63zJyErHQeM1o7tyDcG7Dc4BrBDxGykaFBdfzyfy/3oEgWEhZdIielbVX8zWqrY2CXjlqlsBKvNXT2qQQWwkHzU111zjYaYW4n1PMQz2W9wbUHQqZgvs4DhZgZhB1NF850qzNrF1c6Q5A/cphw+hCuF90wk9oU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213266; c=relaxed/simple; bh=twB3VnTcAf6TnhnidOIfI8EqbX6+m14S+IxS5axSL0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t9ifglQBFXJCMgqB/Rqfxcl7zGZvk6wDa49Vt6JCizHzlX7I7um5/DuPdzFVIQ1K9iu7VyHZtKq8lLNkfc9NBVDIBTUke/GA/DqCU6hm6m9HlaY30+mq0F89oRpcPD7hRsw2CfQSaLp+v6MOKKP/rrqbujLTfFEUILVNfgqkiVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=o/yHlMSu; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="o/yHlMSu" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7ZW62266961 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213255; bh=JARC1+Q5f9wGAvl+IXbS0Oin1wCKT8XeCIAeU4lhnCU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=o/yHlMSuTTys/p83FAuidmB0XUM7SVjpeLjtXZCmfZKK0wtNNo2RyKa5n5dc1QOpl W7DXLfcBBM5iZ0tXDByOT8jxGanTaZ8qp/QlqlCdegXaM0sxxdhYb61QNsheHOXpp6 bH//jTPYBQNfkPQMfvithaao9cXcMl97or2YPRZ4= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7ZGA000681 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:35 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:35 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:35 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKE060901; Mon, 17 Mar 2025 07:07:32 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 17/26] remoteproc: k3: Refactor .start rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:13 +0530 Message-ID: <20250317120622.1746415-18-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_dsp_rproc_start() function sets the boot address and releases the reset on the remote processor. Whereas, the k3_m4_rproc_start() function only needs to release the reset. Refactor the k3_m4_rproc_start() into ti_k3_common.c as k3_rproc_start() and align the DSP and M4 drivers to invoke this common function when releasing the reset on the remote processor. Further, do not override the .start ops with NULL when operating in IPC-only mode in ti_k3_dsp_remoteproc.c, as .start is never invoked in rproc_attach routine. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 15 +++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 4 ++-- drivers/remoteproc/ti_k3_m4_remoteproc.c | 22 +--------------------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index e548beb817ca..e2c7da357ab5 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -268,5 +268,20 @@ int k3_rproc_unprepare(struct rproc *rproc) } EXPORT_SYMBOL_GPL(k3_rproc_unprepare); +/* + * Power up the remote processor. + * + * This function will be invoked only after the firmware for this rproc + * was loaded, parsed successfully, and all of its resource requirements + * were met. This callback is invoked only in remoteproc mode. + */ +int k3_rproc_start(struct rproc *rproc) +{ + struct k3_rproc *kproc = rproc->priv; + + return k3_rproc_release(kproc); +} +EXPORT_SYMBOL_GPL(k3_rproc_start); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index c1b07187c124..51a92a306479 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -95,4 +95,5 @@ int k3_rproc_release(struct k3_rproc *kproc); int k3_rproc_request_mbox(struct rproc *rproc); int k3_rproc_prepare(struct rproc *rproc); int k3_rproc_unprepare(struct rproc *rproc); +int k3_rproc_start(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index ca3afd11fb89..fb3ba5a1e07c 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -50,7 +50,8 @@ static int k3_dsp_rproc_start(struct rproc *rproc) if (ret) return ret; - ret = k3_rproc_release(kproc); + /* Call the K3 common start function after doing DSP specific stuff */ + ret = k3_rproc_start(rproc); if (ret) return ret; @@ -411,7 +412,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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->start = NULL; rproc->ops->stop = NULL; rproc->ops->attach = k3_dsp_rproc_attach; rproc->ops->detach = k3_dsp_rproc_detach; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index d53538d7dc0d..69066cb91740 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -244,26 +244,6 @@ static void k3_m4_release_tsp(void *data) ti_sci_proc_release(tsp); } -/* - * Power up the M4 remote processor. - * - * This function will be invoked only after the firmware for this rproc - * was loaded, parsed successfully, and all of its resource requirements - * were met. This callback is invoked only in remoteproc mode. - */ -static int k3_m4_rproc_start(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - struct device *dev = kproc->dev; - int ret; - - ret = k3_rproc_release(kproc); - if (ret) - dev_err(dev, "local-reset deassert failed, ret = %d\n", ret); - - return ret; -} - /* * Stop the M4 remote processor. * @@ -304,7 +284,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc) static const struct rproc_ops k3_m4_rproc_ops = { .prepare = k3_rproc_prepare, .unprepare = k3_rproc_unprepare, - .start = k3_m4_rproc_start, + .start = k3_rproc_start, .stop = k3_m4_rproc_stop, .attach = k3_m4_rproc_attach, .detach = k3_m4_rproc_detach, From patchwork Mon Mar 17 12:06:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019146 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BA4C23BD02; Mon, 17 Mar 2025 12:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213272; cv=none; b=EL70i6a3/giLMZEKwndz3S7wqrCSs7+anPTafkJFysVdwvBZ7uglYYCojwJsamYXmBLDZ3uj2nse+BDbOebutAMfVIuNnwFigHJ3r0xKZ+8fw2U31px2X1jOmdk09DahLttl0gynKt4zdmxcWbVEviAkjTnjInZO+5Vzu01vqAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213272; c=relaxed/simple; bh=l9Ndok2AQJEgSzbnoTNC6wGc3mMyHnPL5DkSyEPO74M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NwlKzsXGqKwlX3GGQTzCHXHOsKbvhk7+A3vHGAwmguHWfJX3Bep6hxjaWVxUFe/x+mdY8ADXeozeNgOI7GRgWYgVYtLsE6OwF8CCmeNvdfz64dR7vTIj7997e0/SM3mA6t5SsHyw/6NUsSXXuHHLiPBo4prMecqvDn2f+VLJWa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=c6vQUetX; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="c6vQUetX" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7d9p2266969 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213259; bh=aWjv01r1zcFzNOjSzFjjXP3YPhZ89BccdUX/AsEVbBM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=c6vQUetXcW9gho/TVAPVNB3NxgWpn8KF18U+MU9jK5FcLXh1k5HXbh+c/LRuV3zCf /KPbM2MyITGarA58JcJ6/CZfcjy+EYNAs/7l4ANIllHQgKygZcPcbR2yczaysiDjSV JN/qLf34jx+rJaj+Ct1hnpvvI4l4MlrpP/R2CkA8= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7dIc000703 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:39 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:39 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:39 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKF060901; Mon, 17 Mar 2025 07:07:35 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 18/26] remoteproc: k3: Refactor .stop rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:14 +0530 Message-ID: <20250317120622.1746415-19-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .stop rproc ops implementations in ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c drivers put the remote processor into reset. Refactor the implementations into ti_k3_common.c driver as k3_rproc_stop() and align DSP and M4 drivers to register this common function as .stop ops. Further, do not override the .stop ops with NULL when operating in IPC-only mode in ti_k3_dsp_remoteproc.c, as .stop is never invoked in rproc_detach routine. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 14 ++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 18 +----------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 15 +-------------- 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index e2c7da357ab5..93d793e0899f 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -283,5 +283,19 @@ int k3_rproc_start(struct rproc *rproc) } EXPORT_SYMBOL_GPL(k3_rproc_start); +/* + * Stop the remote processor. + * + * This function puts the remote processor into reset, and finishes processing + * of any pending messages. This callback is invoked only in remoteproc mode. + */ +int k3_rproc_stop(struct rproc *rproc) +{ + struct k3_rproc *kproc = rproc->priv; + + return k3_rproc_reset(kproc); +} +EXPORT_SYMBOL_GPL(k3_rproc_stop); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 51a92a306479..0162757f024c 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -96,4 +96,5 @@ int k3_rproc_request_mbox(struct rproc *rproc); int k3_rproc_prepare(struct rproc *rproc); int k3_rproc_unprepare(struct rproc *rproc); int k3_rproc_start(struct rproc *rproc); +int k3_rproc_stop(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index fb3ba5a1e07c..c5fe2b097a6f 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -58,21 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc) return 0; } -/* - * Stop the DSP remote processor. - * - * This function puts the DSP processor into reset, and finishes processing - * of any pending messages. This callback is invoked only in remoteproc mode. - */ -static int k3_dsp_rproc_stop(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - - k3_rproc_reset(kproc); - - return 0; -} - /* * Attach to a running DSP remote processor (IPC-only mode) * @@ -186,7 +171,7 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool static const struct rproc_ops k3_dsp_rproc_ops = { .start = k3_dsp_rproc_start, - .stop = k3_dsp_rproc_stop, + .stop = k3_rproc_stop, .kick = k3_rproc_kick, .da_to_va = k3_dsp_rproc_da_to_va, }; @@ -412,7 +397,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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->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; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 69066cb91740..8830b1d84675 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -244,19 +244,6 @@ static void k3_m4_release_tsp(void *data) ti_sci_proc_release(tsp); } -/* - * Stop the M4 remote processor. - * - * This function puts the M4 processor into reset, and finishes processing - * of any pending messages. This callback is invoked only in remoteproc mode. - */ -static int k3_m4_rproc_stop(struct rproc *rproc) -{ - struct k3_rproc *kproc = rproc->priv; - - return k3_rproc_reset(kproc); -} - /* * Attach to a running M4 remote processor (IPC-only mode) * @@ -285,7 +272,7 @@ static const struct rproc_ops k3_m4_rproc_ops = { .prepare = k3_rproc_prepare, .unprepare = k3_rproc_unprepare, .start = k3_rproc_start, - .stop = k3_m4_rproc_stop, + .stop = k3_rproc_stop, .attach = k3_m4_rproc_attach, .detach = k3_m4_rproc_detach, .kick = k3_rproc_kick, From patchwork Mon Mar 17 12:06:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019147 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBC4323C380; Mon, 17 Mar 2025 12:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213273; cv=none; b=XT8xjBtNhp8h96manPpKk6GjHtMLPVUaLmzlwuRABev8bTdyl5MTh8yKc1njKjpXKV8YDfcPgxcCzKOhtyvHBv0IezKBxXfc7BO6rT67GSVjyVT4BCaTel537ivYio9REAL3vIgdGlQUJAol3hNLjmEZJ/f5T9EYmUzBC/aK/sU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213273; c=relaxed/simple; bh=8iqJpMchQusj/fBz7nNUxocmhmDyYv2EJHkhn+0G2AM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TMV0g9mvH7f7AprsIJzcJk99h3vL9aX+bX6bxm5MpHQjMDhFnpvrsFg2s2x4H77IUBO0RbbH/2jMdWO2kQ56g87vzaTtcPVblScsKENxLJX4LcP9ZZRbDx+IaMAXfuXNI6Y7OyNPHvU7Y7P9EWJAaSUmTkVjqMQM6kP00AtEDTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=MRJcNSM1; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="MRJcNSM1" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7hDA2331370 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213263; bh=zua5Uy3WOy5LEXtu2zKe3lbTOB/TCSkC5p/TEW38TFU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=MRJcNSM1llJ+1sqEEbH6LFqIxv3H0ncF94YrUizp26TyLlnHoIQCYa8nce4VpchzN C+9EGF8EHaoRgG4ZOFOtcG7WGE5yMRHYx4FGoqG9MqpmaSwYVkQamXnMXVv+DNKXaB f12MlGnSH7H9ERGfQeO3cyTZgQAhUu4ygHpGcWCg= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7hke000712 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:43 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) 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.2507.23; Mon, 17 Mar 2025 07:07:42 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:42 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKG060901; Mon, 17 Mar 2025 07:07:39 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 19/26] remoteproc: k3: Refactor .attach rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:15 +0530 Message-ID: <20250317120622.1746415-20-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .attach rproc ops implementations in TI K3 R5, DSP and M4 drivers are NOPs. Refactor the implementations into ti_k3_common.c driver as k3_rproc_attach() and align R5, DSP and M4 drivers to register this common function as .attach ops. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 12 ++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 13 +------------ drivers/remoteproc/ti_k3_m4_remoteproc.c | 14 +------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 13 +------------ 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 93d793e0899f..9e80d4da0d43 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -297,5 +297,17 @@ int k3_rproc_stop(struct rproc *rproc) } EXPORT_SYMBOL_GPL(k3_rproc_stop); +/* + * Attach to a running remote processor (IPC-only mode) + * + * The rproc attach callback is a NOP. The remote processor is already booted, + * and all required resources have been acquired during probe routine, so there + * is no need to issue any TI-SCI commands to boot the remote cores in IPC-only + * mode. This callback is invoked only in IPC-only mode and exists because + * rproc_validate() checks for its existence. + */ +int k3_rproc_attach(struct rproc *rproc) { return 0; } +EXPORT_SYMBOL_GPL(k3_rproc_attach); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 0162757f024c..93f41ee41505 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -97,4 +97,5 @@ int k3_rproc_prepare(struct rproc *rproc); int k3_rproc_unprepare(struct rproc *rproc); int k3_rproc_start(struct rproc *rproc); int k3_rproc_stop(struct rproc *rproc); +int k3_rproc_attach(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index c5fe2b097a6f..d7ae4b202f92 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -58,17 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc) return 0; } -/* - * Attach to a running DSP remote processor (IPC-only mode) - * - * This rproc attach callback is a NOP. The remote processor is already booted, - * and all required resources have been acquired during probe routine, 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 and exists because rproc_validate() checks - * for its existence. - */ -static int k3_dsp_rproc_attach(struct rproc *rproc) { return 0; } - /* * Detach from a running DSP remote processor (IPC-only mode) * @@ -172,6 +161,7 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool static const struct rproc_ops k3_dsp_rproc_ops = { .start = k3_dsp_rproc_start, .stop = k3_rproc_stop, + .attach = k3_rproc_attach, .kick = k3_rproc_kick, .da_to_va = k3_dsp_rproc_da_to_va, }; @@ -397,7 +387,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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->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 { diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 8830b1d84675..b52a1014c934 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -244,18 +244,6 @@ static void k3_m4_release_tsp(void *data) ti_sci_proc_release(tsp); } -/* - * Attach to a running M4 remote processor (IPC-only mode) - * - * The remote processor is already booted, so there is no need to issue any - * TI-SCI commands to boot the M4 core. This callback is used only in IPC-only - * mode. - */ -static int k3_m4_rproc_attach(struct rproc *rproc) -{ - return 0; -} - /* * Detach from a running M4 remote processor (IPC-only mode) * @@ -273,7 +261,7 @@ static const struct rproc_ops k3_m4_rproc_ops = { .unprepare = k3_rproc_unprepare, .start = k3_rproc_start, .stop = k3_rproc_stop, - .attach = k3_m4_rproc_attach, + .attach = k3_rproc_attach, .detach = k3_m4_rproc_detach, .kick = k3_rproc_kick, .da_to_va = k3_m4_rproc_da_to_va, diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 2bec94755e31..fe1bc3a74b09 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -559,17 +559,6 @@ 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 is a NOP. The remote processor is already booted, and - * all required resources have been acquired during probe routine, 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 and exists because - * rproc_validate() checks for its existence. - */ -static int k3_r5_rproc_attach(struct rproc *rproc) { return 0; } - /* * Detach from a running R5F remote processor (IPC-only mode) * @@ -1059,7 +1048,7 @@ static int k3_r5_rproc_configure_mode(struct k3_rproc *kproc) 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->attach = k3_rproc_attach; kproc->rproc->ops->detach = k3_r5_rproc_detach; kproc->rproc->ops->get_loaded_rsc_table = k3_r5_get_loaded_rsc_table; From patchwork Mon Mar 17 12:06:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019148 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27539238D25; Mon, 17 Mar 2025 12:07:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213279; cv=none; b=T5KNXKjxNnv1eFJ7d3XURJQSJrBqLcQLWMTE4Spqo5MX//67iCOlaXaFlyqheLVyBRmf9qweTYSqy9fT+zIkUvNbu6XupQufKTvn+vkvTx5wb1ueV04x178RFRjV+F+LpaiPvtHvEoVmbsVzVTIGMabUdEQCKp8J94PcobOjhbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213279; c=relaxed/simple; bh=KoXnTTvKKbTVITUBoCqWNz2j5omol39ytBAPwuFUicw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V8w7+oDFbsJ7bjD+6HzO4CWYQ5rn4QHjvnq0NPr1KUjDaa6XEOFjT0Y9j9MdBO61tiNHTHK6BnkOBBRCqOWFOCGFpwwahK6Fb5GrWdksqdFfngU0KoJGVLNYpmVAdlsZQKrLedOcgcaCoY3rfDcSJYvOi9ck5PwrzvzdVCYgnsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=o/HqErLW; arc=none smtp.client-ip=198.47.19.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="o/HqErLW" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7lpF2755821 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213267; bh=NqMCLBjr01kU/bl5NRhutDtfMj9xfCr/kPkKJKIFGGY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=o/HqErLWUjrbuTKkOYsaHeA3amfIYsmN9BQBiC19B2wZ8HeKD+0Fm2qezDF++9k39 B/0++aV8ozCb5ubZHEv/7anBbzH3mNbaGK8XE8A3Art25vUdk0R7Voe68AwxcHBSYi hK84piQAM9o+mJvOMWm9vgxT4lHn+eVg4PrQnX/o= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7ldW124360 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:47 -0500 Received: from DLEE105.ent.ti.com (157.170.170.35) 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.2507.23; Mon, 17 Mar 2025 07:07:46 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:46 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKH060901; Mon, 17 Mar 2025 07:07:43 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 20/26] remoteproc: k3: Refactor .detach rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:16 +0530 Message-ID: <20250317120622.1746415-21-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .detach rproc ops implementations in TI K3 R5, DSP and M4 remoteproc drivers are NOPs. Refactor the implementations into ti_k3_common.c driver as k3_rproc_detach() and align R5, DSP and M4 drivers to register this common function as .detach ops. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 10 ++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 11 +---------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 14 +------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 11 +---------- 5 files changed, 14 insertions(+), 33 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 9e80d4da0d43..84e263f159a0 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -309,5 +309,15 @@ EXPORT_SYMBOL_GPL(k3_rproc_stop); int k3_rproc_attach(struct rproc *rproc) { return 0; } EXPORT_SYMBOL_GPL(k3_rproc_attach); +/* + * Detach from a running remote processor (IPC-only mode) + * + * The rproc detach callback is a NOP. The remote processor is not stopped and + * will be left in booted state in IPC-only mode. This callback is invoked only + * in IPC-only mode and exists for sanity sake + */ +int k3_rproc_detach(struct rproc *rproc) { return 0; } +EXPORT_SYMBOL_GPL(k3_rproc_detach); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 93f41ee41505..97345349b818 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -98,4 +98,5 @@ int k3_rproc_unprepare(struct rproc *rproc); int k3_rproc_start(struct rproc *rproc); int k3_rproc_stop(struct rproc *rproc); int k3_rproc_attach(struct rproc *rproc); +int k3_rproc_detach(struct rproc *rproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index d7ae4b202f92..dd81bcc8e1e4 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -58,15 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc) return 0; } -/* - * Detach from a running DSP remote processor (IPC-only mode) - * - * This rproc detach callback is a NOP. 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 and exists for sanity sake. - */ -static int k3_dsp_rproc_detach(struct rproc *rproc) { 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 @@ -162,6 +153,7 @@ static const struct rproc_ops k3_dsp_rproc_ops = { .start = k3_dsp_rproc_start, .stop = k3_rproc_stop, .attach = k3_rproc_attach, + .detach = k3_rproc_detach, .kick = k3_rproc_kick, .da_to_va = k3_dsp_rproc_da_to_va, }; @@ -387,7 +379,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) 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->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"); diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index b52a1014c934..accf8b9aea6e 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -244,25 +244,13 @@ static void k3_m4_release_tsp(void *data) ti_sci_proc_release(tsp); } -/* - * Detach from a running M4 remote processor (IPC-only mode) - * - * This rproc detach callback performs the opposite operation to attach - * callback, the M4 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_m4_rproc_detach(struct rproc *rproc) -{ - return 0; -} - static const struct rproc_ops k3_m4_rproc_ops = { .prepare = k3_rproc_prepare, .unprepare = k3_rproc_unprepare, .start = k3_rproc_start, .stop = k3_rproc_stop, .attach = k3_rproc_attach, - .detach = k3_m4_rproc_detach, + .detach = k3_rproc_detach, .kick = k3_rproc_kick, .da_to_va = k3_m4_rproc_da_to_va, .get_loaded_rsc_table = k3_m4_get_loaded_rsc_table, diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index fe1bc3a74b09..a17c4b5418ae 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -559,15 +559,6 @@ static int k3_r5_rproc_stop(struct rproc *rproc) return ret; } -/* - * Detach from a running R5F remote processor (IPC-only mode) - * - * The R5F detach callback is a NOP. 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 and exists for sanity sake. - */ -static int k3_r5_rproc_detach(struct rproc *rproc) { 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 @@ -1049,7 +1040,7 @@ static int k3_r5_rproc_configure_mode(struct k3_rproc *kproc) kproc->rproc->ops->start = NULL; kproc->rproc->ops->stop = NULL; kproc->rproc->ops->attach = k3_rproc_attach; - kproc->rproc->ops->detach = k3_r5_rproc_detach; + kproc->rproc->ops->detach = k3_rproc_detach; kproc->rproc->ops->get_loaded_rsc_table = k3_r5_get_loaded_rsc_table; } else if (!c_state) { From patchwork Mon Mar 17 12:06:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019149 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C266023C390; Mon, 17 Mar 2025 12:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213280; cv=none; b=o4xnj5rg+aAx/qIgmDlgxhZoBe7R2BK/mPRyJBkq8rgOxFMlriulgh0phOF4kbGXBK6PaVfbQYJjk8Dvr4niZziK9CObx1omsqVd9H2y8CtZ5M+siMlXjOLjfGUyFVB/Q4PYimxluRdt+JruvDMV0knc1rssMDQOb7o4SW8Nq3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213280; c=relaxed/simple; bh=JO8IvKpkO3tmPlWgY5KTs+gID131t1oPGEgBIeEXRPE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZbdsE48GmZNLD/at00nyTGOIboH78BZ5P9RbuMQByBx2fmhSYCp6U4PB+kL/UQzvTSTu9SQn9L/Ka5MWY9glf+8H6VYHXWLxmBSTQsKs6gnYzcL5tuecxo5T7usxVWBN3xnod6sv7vAMv+gpq3IUoYgWrjt6Pf1cybck8iTJ2Ok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=AMZYTk/U; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="AMZYTk/U" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7po62331378 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213271; bh=1K9d74Mm9Yp4gg9kqiZA5wE5tSW8+6DGE32O4ndbBk0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=AMZYTk/ULbY7s7uMb9TysxFMlih1zKXVV0Rkiy43eiiMO9ckymo1pjNhZNOPBKatH krtbXo7x8jRkEpoCBSJEz95eYOdj4xWyedsnMCh1Uj+90jzRiipbpgBSa0lg+7Cacf lgS47TcNAdjG3ffAuW+yTluTTM0p1i28Do9pz5c8= 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 52HC7pnK124375 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:51 -0500 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.2507.23; Mon, 17 Mar 2025 07:07:50 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:50 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKI060901; Mon, 17 Mar 2025 07:07:47 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 21/26] remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver Date: Mon, 17 Mar 2025 17:36:17 +0530 Message-ID: <20250317120622.1746415-22-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .get_loaded_rsc_table rproc ops implementations in TI K3 R5, DSP and M4 remoteproc drivers return a pointer to the resource table that was pre-loaded at the base address of the DDR region reserved for firmware usage. Refactor the implementations into ti_k3_common.c driver as k3_get_loaded_rsc_table() and align R5, DSP and M4 drivers to register this common function as .get_loaded_rsc_table ops. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 33 +++++++++++++++ drivers/remoteproc/ti_k3_common.h | 2 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 49 ++++------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 34 +--------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 34 +--------------- 5 files changed, 45 insertions(+), 107 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 84e263f159a0..92681d24a20a 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -319,5 +319,38 @@ EXPORT_SYMBOL_GPL(k3_rproc_attach); int k3_rproc_detach(struct rproc *rproc) { return 0; } EXPORT_SYMBOL_GPL(k3_rproc_detach); +/* + * This function implements the .get_loaded_rsc_table() callback and is used + * to provide the resource table for a booted remote processor in IPC-only + * mode. The remote processor 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. + */ +struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc, + size_t *rsc_table_sz) +{ + struct k3_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 (__force struct resource_table *)kproc->rmem[0].cpu_addr; +} +EXPORT_SYMBOL_GPL(k3_get_loaded_rsc_table); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 97345349b818..266e5c66762f 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -99,4 +99,6 @@ int k3_rproc_start(struct rproc *rproc); int k3_rproc_stop(struct rproc *rproc); int k3_rproc_attach(struct rproc *rproc); int k3_rproc_detach(struct rproc *rproc); +struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc, + size_t *rsc_table_sz); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index dd81bcc8e1e4..0bfa3b730d1f 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -58,38 +58,6 @@ static int k3_dsp_rproc_start(struct rproc *rproc) 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_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 (__force 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 @@ -150,12 +118,13 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool } static const struct rproc_ops k3_dsp_rproc_ops = { - .start = k3_dsp_rproc_start, - .stop = k3_rproc_stop, - .attach = k3_rproc_attach, - .detach = k3_rproc_detach, - .kick = k3_rproc_kick, - .da_to_va = k3_dsp_rproc_da_to_va, + .start = k3_dsp_rproc_start, + .stop = k3_rproc_stop, + .attach = k3_rproc_attach, + .detach = k3_rproc_detach, + .kick = k3_rproc_kick, + .da_to_va = k3_dsp_rproc_da_to_va, + .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev, @@ -374,12 +343,10 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "failed to get initial state, mode cannot be determined\n"); - /* configure J721E devices for either remoteproc or IPC-only mode */ + /* configure 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->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table; } else { dev_info(dev, "configured DSP for remoteproc mode\n"); } diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index accf8b9aea6e..59c696a493c5 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,38 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -/* - * This function implements the .get_loaded_rsc_table() callback and is used - * to provide the resource table for a booted remote processor in IPC-only - * mode. The remote processor 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. - */ -static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc, - size_t *rsc_table_sz) -{ - struct k3_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 (__force struct resource_table *)kproc->rmem[0].cpu_addr; -} - /* * Custom function to translate a remote processor device address (internal * RAMs only) to a kernel virtual address. The remote processors can access @@ -253,7 +221,7 @@ static const struct rproc_ops k3_m4_rproc_ops = { .detach = k3_rproc_detach, .kick = k3_rproc_kick, .da_to_va = k3_m4_rproc_da_to_va, - .get_loaded_rsc_table = k3_m4_get_loaded_rsc_table, + .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; static int k3_m4_rproc_probe(struct platform_device *pdev) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index a17c4b5418ae..34ee5669238b 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -559,38 +559,6 @@ static int k3_r5_rproc_stop(struct rproc *rproc) return ret; } -/* - * 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_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 (__force struct resource_table *)kproc->rmem[0].cpu_addr; -} - /* * Internal Memory translation helper * @@ -1042,7 +1010,7 @@ static int k3_r5_rproc_configure_mode(struct k3_rproc *kproc) kproc->rproc->ops->attach = k3_rproc_attach; kproc->rproc->ops->detach = k3_rproc_detach; kproc->rproc->ops->get_loaded_rsc_table = - k3_r5_get_loaded_rsc_table; + k3_get_loaded_rsc_table; } else if (!c_state) { dev_info(cdev, "configured R5F for remoteproc mode\n"); ret = 0; From patchwork Mon Mar 17 12:06:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019150 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DCFD2459F8; Mon, 17 Mar 2025 12:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213287; cv=none; b=WNW2Il0Lh07RMPzTVlDNfoul4J6g5trOboDpt9mDlzI5OEYtaCvj3Wc6taTtbzJKp1678YRkyhJxcmhA2LIBphpqbCPhFHoPhg1r32uJkuMuQRZTosTosD7QjrqYMXNjJuBSWkj2WIDTgFK4b7ZD2uyCLyWWrPut21IWnCkAie8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213287; c=relaxed/simple; bh=sNQbgVOO0tEqnTmxQslAMVTkMoQW5i3rNMxPpzhAodU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jMNEMM5uYsI3H6eU0nnLz46pt6+7pfyzZgcPbJV8cy5+7dVAtSmEmXAXnwTlgfjXeIJ1V99ijwpKnhdlLsqVB+SA3hesyX0P8uhtYKf/nt3zkgL3V8oJwubYuy/Ntkr23QKuZgG2yqE7DXZF4/HDHdJJbldREnXhX4GB8tc9qQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=o3WaTfc2; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="o3WaTfc2" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7sBm2267010 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:07:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213275; bh=B7q/2a/BjF5X3WM4pIQbeKEPWHPe6L4eu9IuiA0IsXg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=o3WaTfc2G3Ah9Ep67odlL/AqCVgz+wKv17MY1+JVfsYxgk6MbZVhIwxkw2AUHZNTl NOVCs4GeDrLWCnIbeqkvnhGxIKWfscUr5OA37KJZH/7qDPT+egK8BsjyJWsA0WuUMh baq9roh2RXQS4EgW3tdk/PoAseXVuGCXRHSV6YVk= Received: from DLEE101.ent.ti.com (dlee101.ent.ti.com [157.170.170.31]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7svs124389 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:07:54 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) 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.2507.23; Mon, 17 Mar 2025 07:07:54 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:54 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKJ060901; Mon, 17 Mar 2025 07:07:51 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 22/26] remoteproc: k3: Refactor .da_to_va rproc ops into common driver Date: Mon, 17 Mar 2025 17:36:18 +0530 Message-ID: <20250317120622.1746415-23-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The .da_to_va rproc ops implementations in TI K3 R5, DSP and M4 remoteproc drivers return the Kernel virtual address for a corresponding rproc device address. Refactor the implementations into ti_k3_common.c driver as k3_rproc_da_to_va and align R5, DSP and M4 drivers to use this common function for address translation. Additionally, handle R5 SRAM memory translations specifically in the R5 remoteproc driver. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 57 ++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 4 ++ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 63 +---------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 58 +-------------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 37 +------------ 5 files changed, 65 insertions(+), 154 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 92681d24a20a..818d66d0ca10 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -352,5 +352,62 @@ struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc, } EXPORT_SYMBOL_GPL(k3_get_loaded_rsc_table); +/* + * Custom function to translate a remote processor device address (internal + * RAMs only) to a kernel virtual address. The remote processors can access + * their RAMs at either an internal address visible only from a remote + * processor, or at the SoC-level bus address. Both these addresses need to be + * looked through for translation. The translated addresses can be used either + * by the remoteproc core for loading (when using kernel remoteproc loader), or + * by any rpmsg bus drivers. + */ +void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) +{ + struct k3_rproc *kproc = rproc->priv; + void __iomem *va = NULL; + phys_addr_t bus_addr; + u32 dev_addr, offset; + size_t size; + int i; + + if (len == 0) + return NULL; + + for (i = 0; i < kproc->num_mems; i++) { + bus_addr = kproc->mem[i].bus_addr; + dev_addr = kproc->mem[i].dev_addr; + size = kproc->mem[i].size; + + /* handle rproc-view addresses */ + if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { + offset = da - dev_addr; + va = kproc->mem[i].cpu_addr + offset; + return (__force void *)va; + } + + /* handle SoC-view addresses */ + if (da >= bus_addr && (da + len) <= (bus_addr + size)) { + offset = da - bus_addr; + va = kproc->mem[i].cpu_addr + offset; + return (__force void *)va; + } + } + + /* handle static DDR reserved memory regions */ + for (i = 0; i < kproc->num_rmems; i++) { + dev_addr = kproc->rmem[i].dev_addr; + size = kproc->rmem[i].size; + + if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { + offset = da - dev_addr; + va = kproc->rmem[i].cpu_addr + offset; + return (__force void *)va; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(k3_rproc_da_to_va); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 266e5c66762f..d600d18b9c7e 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -16,6 +16,8 @@ #ifndef REMOTEPROC_TI_K3_COMMON_H #define REMOTEPROC_TI_K3_COMMON_H +#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) + /** * struct k3_rproc_mem - internal memory structure * @cpu_addr: MPU virtual address of the memory region @@ -101,4 +103,6 @@ int k3_rproc_attach(struct rproc *rproc); int k3_rproc_detach(struct rproc *rproc); struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc, size_t *rsc_table_sz); +void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, + bool *is_iomem); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 0bfa3b730d1f..3d888ab9de6b 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -22,8 +22,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) - /* * Power up the DSP remote processor. * @@ -58,72 +56,13 @@ static int k3_dsp_rproc_start(struct rproc *rproc) return 0; } -/* - * 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 - * address visible only from a DSP, or at the SoC-level bus address. Both these - * addresses need to be looked through for translation. The translated addresses - * can be used either by the remoteproc core for loading (when using kernel - * remoteproc loader), or by any rpmsg bus drivers. - */ -static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) -{ - struct k3_rproc *kproc = rproc->priv; - void __iomem *va = NULL; - phys_addr_t bus_addr; - u32 dev_addr, offset; - size_t size; - int i; - - if (len == 0) - return NULL; - - for (i = 0; i < kproc->num_mems; i++) { - bus_addr = kproc->mem[i].bus_addr; - dev_addr = kproc->mem[i].dev_addr; - size = kproc->mem[i].size; - - if (da < KEYSTONE_RPROC_LOCAL_ADDRESS_MASK) { - /* handle DSP-view addresses */ - if (da >= dev_addr && - ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->mem[i].cpu_addr + offset; - return (__force void *)va; - } - } else { - /* handle SoC-view addresses */ - if (da >= bus_addr && - (da + len) <= (bus_addr + size)) { - offset = da - bus_addr; - va = kproc->mem[i].cpu_addr + offset; - return (__force void *)va; - } - } - } - - /* handle static DDR reserved memory regions */ - for (i = 0; i < kproc->num_rmems; i++) { - dev_addr = kproc->rmem[i].dev_addr; - size = kproc->rmem[i].size; - - if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->rmem[i].cpu_addr + offset; - return (__force void *)va; - } - } - - return NULL; -} - static const struct rproc_ops k3_dsp_rproc_ops = { .start = k3_dsp_rproc_start, .stop = k3_rproc_stop, .attach = k3_rproc_attach, .detach = k3_rproc_detach, .kick = k3_rproc_kick, - .da_to_va = k3_dsp_rproc_da_to_va, + .da_to_va = k3_rproc_da_to_va, .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 59c696a493c5..063025738e6a 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,62 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -/* - * Custom function to translate a remote processor device address (internal - * RAMs only) to a kernel virtual address. The remote processors can access - * their RAMs at either an internal address visible only from a remote - * processor, or at the SoC-level bus address. Both these addresses need to be - * looked through for translation. The translated addresses can be used either - * by the remoteproc core for loading (when using kernel remoteproc loader), or - * by any rpmsg bus drivers. - */ -static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) -{ - struct k3_rproc *kproc = rproc->priv; - void __iomem *va = NULL; - phys_addr_t bus_addr; - u32 dev_addr, offset; - size_t size; - int i; - - if (len == 0) - return NULL; - - for (i = 0; i < kproc->num_mems; i++) { - bus_addr = kproc->mem[i].bus_addr; - dev_addr = kproc->mem[i].dev_addr; - size = kproc->mem[i].size; - - /* handle M4-view addresses */ - if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->mem[i].cpu_addr + offset; - return (__force void *)va; - } - - /* handle SoC-view addresses */ - if (da >= bus_addr && ((da + len) <= (bus_addr + size))) { - offset = da - bus_addr; - va = kproc->mem[i].cpu_addr + offset; - return (__force void *)va; - } - } - - /* handle static DDR reserved memory regions */ - for (i = 0; i < kproc->num_rmems; i++) { - dev_addr = kproc->rmem[i].dev_addr; - size = kproc->rmem[i].size; - - if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->rmem[i].cpu_addr + offset; - return (__force void *)va; - } - } - - return NULL; -} - static int k3_m4_rproc_of_get_memories(struct platform_device *pdev, struct k3_rproc *kproc) { @@ -220,7 +164,7 @@ static const struct rproc_ops k3_m4_rproc_ops = { .attach = k3_rproc_attach, .detach = k3_rproc_detach, .kick = k3_rproc_kick, - .da_to_va = k3_m4_rproc_da_to_va, + .da_to_va = k3_rproc_da_to_va, .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 34ee5669238b..dd70a11a9140 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -572,7 +572,6 @@ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool struct k3_rproc *kproc = rproc->priv; struct k3_r5_core *core = kproc->priv; void __iomem *va = NULL; - phys_addr_t bus_addr; u32 dev_addr, offset; size_t size; int i; @@ -580,27 +579,6 @@ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool if (len == 0) return NULL; - /* handle both R5 and SoC views of ATCM and BTCM */ - for (i = 0; i < kproc->num_mems; i++) { - bus_addr = kproc->mem[i].bus_addr; - dev_addr = kproc->mem[i].dev_addr; - size = kproc->mem[i].size; - - /* handle R5-view addresses of TCMs */ - if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->mem[i].cpu_addr + offset; - return (__force void *)va; - } - - /* handle SoC-view addresses of TCMs */ - if (da >= bus_addr && ((da + len) <= (bus_addr + size))) { - offset = da - bus_addr; - va = kproc->mem[i].cpu_addr + offset; - return (__force void *)va; - } - } - /* handle any SRAM regions using SoC-view addresses */ for (i = 0; i < core->num_sram; i++) { dev_addr = core->sram[i].dev_addr; @@ -613,19 +591,8 @@ static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool } } - /* handle static DDR reserved memory regions */ - for (i = 0; i < kproc->num_rmems; i++) { - dev_addr = kproc->rmem[i].dev_addr; - size = kproc->rmem[i].size; - - if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->rmem[i].cpu_addr + offset; - return (__force void *)va; - } - } - - return NULL; + /* handle both TCM and DDR memory regions */ + return k3_rproc_da_to_va(rproc, da, len, is_iomem); } static const struct rproc_ops k3_r5_rproc_ops = { From patchwork Mon Mar 17 12:06:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019151 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FEF823C390; Mon, 17 Mar 2025 12:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213288; cv=none; b=ZI4vgqchV5c9De6vbmuESD4bLHlbi+9dJgbguGXACB5USJ5k3+ntihp8JKF03V/AmB0hQeMAyI1uXc1VHshStNXihq8vennwP8CjpjScBaIgP5HHlFJcP/HcaqmgYYNmi8R87EcSWyth/U+wTD0bvBW8kqfHMRlRsAEL97BV4zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213288; c=relaxed/simple; bh=CiPOH4XA3YkshuSzDKaJQJOY3rBF6+KF2Y2SvrKjaZw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TKP4mER0a6kbq3QTR/JieS4L9RSa75SB1SUkd3+nObGHQGtW3KPrmFAvUYAEDvitEo2/twawtR1/DjfBxoNKrO4v+lPdhpcxUc6pZoeWiNf0RnpGfwTJeoZMHsAGOiunhLFKWLlq85298tTvjL0VLdKu+pC0joK+JLBKZPUePfY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=rbeDC7zY; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="rbeDC7zY" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC7wuq2802965 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Mar 2025 07:07:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213278; bh=l0VAbMHogXm91bFjBxPyczvTSpcQlNcyyUakBB8nTx0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=rbeDC7zYri5NmFln4VY7yyAE7SCiGXz/D8zsg4k8DuGEOv2g1WPTDbmxPztKBvc5x 14onwGVjE91rz5lwViDHTlSF9q0qcla9WarqF6YHhKRGG7tpQaE+HlWP9s74KRCdjH AfModSdBDRc2lr1OfwPmqwRfa0d6+4OeKXwYR5t0= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC7wSc005398; Mon, 17 Mar 2025 07:07:58 -0500 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:07:57 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:07:57 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKK060901; Mon, 17 Mar 2025 07:07:54 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 23/26] remoteproc: k3: Refactor of_get_memories() functions into common driver Date: Mon, 17 Mar 2025 17:36:19 +0530 Message-ID: <20250317120622.1746415-24-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_r5_core_of_get_internal_memories() and k3_{/dsp/m4}_rproc_of_get_memories() functions initialize and assigns memory regions used by the remote processor. Refactor these implementations into ti_k3_common.c driver as k3_rproc_of_get_memories() and align R5, DSP and M4 drivers to use this common function throughout. Further, override the bus_addr assignment for TCMs for R5 remote processors by reading the 'loczrama' DT property in k3_r5_core_of_get_internal_memories(). Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 53 ++++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 2 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 54 +--------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 54 +--------------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 55 ++++------------------- 5 files changed, 66 insertions(+), 152 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 818d66d0ca10..27295d1b1932 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -409,5 +409,58 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) } EXPORT_SYMBOL_GPL(k3_rproc_da_to_va); +int k3_rproc_of_get_memories(struct platform_device *pdev, + struct k3_rproc *kproc) +{ + const struct k3_rproc_dev_data *data = kproc->data; + struct device *dev = &pdev->dev; + struct resource *res; + int num_mems = 0; + int i; + + num_mems = kproc->data->num_mems; + kproc->mem = devm_kcalloc(kproc->dev, num_mems, + sizeof(*kproc->mem), GFP_KERNEL); + if (!kproc->mem) + return -ENOMEM; + + for (i = 0; i < num_mems; i++) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + data->mems[i].name); + if (!res) { + dev_err(dev, "found no memory resource for %s\n", + data->mems[i].name); + return -EINVAL; + } + if (!devm_request_mem_region(dev, res->start, + resource_size(res), + dev_name(dev))) { + dev_err(dev, "could not request %s region for resource\n", + data->mems[i].name); + return -EBUSY; + } + + kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, + resource_size(res)); + if (!kproc->mem[i].cpu_addr) { + dev_err(dev, "failed to map %s memory\n", + data->mems[i].name); + return -ENOMEM; + } + kproc->mem[i].bus_addr = res->start; + kproc->mem[i].dev_addr = data->mems[i].dev_addr; + kproc->mem[i].size = resource_size(res); + + dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n", + data->mems[i].name, &kproc->mem[i].bus_addr, + kproc->mem[i].size, kproc->mem[i].cpu_addr, + kproc->mem[i].dev_addr); + } + kproc->num_mems = num_mems; + + return 0; +} +EXPORT_SYMBOL_GPL(k3_rproc_of_get_memories); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index d600d18b9c7e..a811c4951e6b 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -105,4 +105,6 @@ struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc, size_t *rsc_table_sz); void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem); +int k3_rproc_of_get_memories(struct platform_device *pdev, + struct k3_rproc *kproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 3d888ab9de6b..476f53249793 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -66,58 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = { .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; -static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev, - struct k3_rproc *kproc) -{ - const struct k3_rproc_dev_data *data = kproc->data; - struct device *dev = &pdev->dev; - struct resource *res; - int num_mems = 0; - int i; - - num_mems = kproc->data->num_mems; - kproc->mem = devm_kcalloc(kproc->dev, num_mems, - sizeof(*kproc->mem), GFP_KERNEL); - if (!kproc->mem) - return -ENOMEM; - - for (i = 0; i < num_mems; i++) { - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - data->mems[i].name); - if (!res) { - dev_err(dev, "found no memory resource for %s\n", - data->mems[i].name); - return -EINVAL; - } - if (!devm_request_mem_region(dev, res->start, - resource_size(res), - dev_name(dev))) { - dev_err(dev, "could not request %s region for resource\n", - data->mems[i].name); - return -EBUSY; - } - - kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, - resource_size(res)); - if (!kproc->mem[i].cpu_addr) { - dev_err(dev, "failed to map %s memory\n", - data->mems[i].name); - return -ENOMEM; - } - kproc->mem[i].bus_addr = res->start; - kproc->mem[i].dev_addr = data->mems[i].dev_addr; - kproc->mem[i].size = resource_size(res); - - dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - data->mems[i].name, &kproc->mem[i].bus_addr, - kproc->mem[i].size, kproc->mem[i].cpu_addr, - kproc->mem[i].dev_addr); - } - kproc->num_mems = num_mems; - - return 0; -} - static void k3_dsp_mem_release(void *data) { struct device *dev = data; @@ -269,7 +217,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) if (ret) return ret; - ret = k3_dsp_rproc_of_get_memories(pdev, kproc); + ret = k3_rproc_of_get_memories(pdev, kproc); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 063025738e6a..771769e3dd66 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,58 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -static int k3_m4_rproc_of_get_memories(struct platform_device *pdev, - struct k3_rproc *kproc) -{ - const struct k3_rproc_dev_data *data = kproc->data; - struct device *dev = &pdev->dev; - struct resource *res; - int num_mems; - int i; - - num_mems = kproc->data->num_mems; - kproc->mem = devm_kcalloc(kproc->dev, num_mems, - sizeof(*kproc->mem), GFP_KERNEL); - if (!kproc->mem) - return -ENOMEM; - - for (i = 0; i < num_mems; i++) { - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - data->mems[i].name); - if (!res) { - dev_err(dev, "found no memory resource for %s\n", - data->mems[i].name); - return -EINVAL; - } - if (!devm_request_mem_region(dev, res->start, - resource_size(res), - dev_name(dev))) { - dev_err(dev, "could not request %s region for resource\n", - data->mems[i].name); - return -EBUSY; - } - - kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, - resource_size(res)); - if (!kproc->mem[i].cpu_addr) { - dev_err(dev, "failed to map %s memory\n", - data->mems[i].name); - return -ENOMEM; - } - kproc->mem[i].bus_addr = res->start; - kproc->mem[i].dev_addr = data->mems[i].dev_addr; - kproc->mem[i].size = resource_size(res); - - dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - data->mems[i].name, &kproc->mem[i].bus_addr, - kproc->mem[i].size, kproc->mem[i].cpu_addr, - kproc->mem[i].dev_addr); - } - kproc->num_mems = num_mems; - - return 0; -} - static void k3_m4_rproc_dev_mem_release(void *data) { struct device *dev = data; @@ -225,7 +173,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) if (ret) return ret; - ret = k3_m4_rproc_of_get_memories(pdev, kproc); + ret = k3_rproc_of_get_memories(pdev, kproc); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index dd70a11a9140..b392c40b4670 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -1009,55 +1009,22 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, const struct k3_rproc_dev_data *data = kproc->data; struct device *dev = &pdev->dev; struct k3_r5_core *core = kproc->priv; - struct resource *res; - int num_mems; - int i; + int num_mems = data->num_mems; + int i, ret; - num_mems = kproc->data->num_mems; - kproc->mem = devm_kcalloc(kproc->dev, num_mems, sizeof(*kproc->mem), - GFP_KERNEL); - if (!kproc->mem) - return -ENOMEM; + ret = k3_rproc_of_get_memories(pdev, kproc); + if (ret) + return ret; for (i = 0; i < num_mems; i++) { - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - data->mems[i].name); - if (!res) { - dev_err(dev, "found no memory resource for %s\n", - data->mems[i].name); - return -EINVAL; - } - if (!devm_request_mem_region(dev, res->start, - resource_size(res), - dev_name(dev))) { - dev_err(dev, "could not request %s region for resource\n", - data->mems[i].name); - return -EBUSY; - } - - /* - * TCMs are designed in general to support RAM-like backing - * memories. So, map these as Normal Non-Cached memories. This - * also avoids/fixes any potential alignment faults due to - * unaligned data accesses when using memcpy() or memset() - * functions (normally seen with device type memory). - */ - kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, - resource_size(res)); - if (!kproc->mem[i].cpu_addr) { - dev_err(dev, "failed to map %s memory\n", - data->mems[i].name); - return -ENOMEM; - } - kproc->mem[i].bus_addr = res->start; - /* * TODO: * The R5F cores can place ATCM & BTCM anywhere in its address * based on the corresponding Region Registers in the System * Control coprocessor. For now, place ATCM and BTCM at * addresses 0 and 0x41010000 (same as the bus address on AM65x - * SoCs) based on loczrama setting + * SoCs) based on loczrama setting overriding default assignment + * done by k3_rproc_of_get_memories(). */ if (!strcmp(data->mems[i].name, "atcm")) { kproc->mem[i].dev_addr = core->loczrama ? @@ -1066,14 +1033,10 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, kproc->mem[i].dev_addr = core->loczrama ? K3_R5_TCM_DEV_ADDR : 0; } - kproc->mem[i].size = resource_size(res); - dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n", - data->mems[i].name, &kproc->mem[i].bus_addr, - kproc->mem[i].size, kproc->mem[i].cpu_addr, - kproc->mem[i].dev_addr); + dev_dbg(dev, "Updating bus addr %pa of memory %5s\n", + &kproc->mem[i].bus_addr, data->mems[i].name); } - kproc->num_mems = num_mems; return 0; } From patchwork Mon Mar 17 12:06:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019152 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BA0224886E; Mon, 17 Mar 2025 12:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213294; cv=none; b=OgWfNihLQ7kv/R44H12PDxahpS2MI89Oxr4nPYT7RSGeHNn8zZG/rhVI80O9p6h6qiLw9RtDeUtY1CsZ5f4xCVoVh3AnxDaovn1+HeAsDGhUfQ3DC6pBROI/3ykuZoeC6VvP9uJjPyn4ChO3moiKmku26SUOKNtD7lEUPMXm1lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213294; c=relaxed/simple; bh=ZJi/Qn+rYlROSgyP+c5aAhzKngV+AnTMXVWmqOzuUTI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=plElBhq9FtVlaV1cYK7mSUe1V70g/p3qVkErqj+3VqPo2PZq1JDUMyw53sqkmLwNUzxNce/PF5K6GbOTv7WIyDoW4EJkj8bbfYRXeFLGw5hpfhAkFBWrY6Ox65Mby3WU69b5iSj9PZEG2xLvxNqAp/18iDrIBgBCBmaMG4zOu0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=lCjq3Bi2; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="lCjq3Bi2" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC838C2267180 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:08:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213283; bh=uvbt/2QUKnblCaZEiYV6Ya27n6TLlpLFTLful0J9tI0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lCjq3Bi2NSyHxjT9YzlhlPBJa89YRrJj00SRfF7RLQ4aWEDHMqRSRj8ouDTE9La95 dRl64DyAsO105rIFhoi4N3DsLe2FOaqKT3BUn0cG8bI241+bcjJ0ykSc1NFjlDJLpe 9NDIb/zNTaX+CuMdFYXm/vUck6QS3CKjzvsXnVdE= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC838x108802 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:08:03 -0500 Received: from DLEE101.ent.ti.com (157.170.170.31) 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.2507.23; Mon, 17 Mar 2025 07:08:02 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:08:02 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKL060901; Mon, 17 Mar 2025 07:07:58 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 24/26] remoteproc: k3: Refactor mem_release() functions into common driver Date: Mon, 17 Mar 2025 17:36:20 +0530 Message-ID: <20250317120622.1746415-25-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_{r5/dsp}_mem_release() and k3_m4_rproc_dev_mem_release() functions release the reserved memory of the device, which get auto triggered upon device removal. Refactor these functions into ti_k3_common.c driver as k3_mem_release() and align R5, DSP and M4 drivers to use this common function throughout. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 8 ++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 9 +-------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 9 +-------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 9 +-------- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index 27295d1b1932..a51c0196530e 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -462,5 +462,13 @@ int k3_rproc_of_get_memories(struct platform_device *pdev, } EXPORT_SYMBOL_GPL(k3_rproc_of_get_memories); +void k3_mem_release(void *data) +{ + struct device *dev = data; + + of_reserved_mem_device_release(dev); +} +EXPORT_SYMBOL_GPL(k3_mem_release); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index a811c4951e6b..70656215c4d7 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -107,4 +107,5 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem); int k3_rproc_of_get_memories(struct platform_device *pdev, struct k3_rproc *kproc); +void k3_mem_release(void *data); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 476f53249793..1176a6f4c977 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -66,13 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = { .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; -static void k3_dsp_mem_release(void *data) -{ - struct device *dev = data; - - of_reserved_mem_device_release(dev); -} - static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc) { struct device *dev = kproc->dev; @@ -102,7 +95,7 @@ static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc) ERR_PTR(ret)); return ret; } - ret = devm_add_action_or_reset(dev, k3_dsp_mem_release, dev); + ret = devm_add_action_or_reset(dev, k3_mem_release, dev); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 771769e3dd66..67b92cbf7c2b 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,13 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -static void k3_m4_rproc_dev_mem_release(void *data) -{ - struct device *dev = data; - - of_reserved_mem_device_release(dev); -} - static int k3_m4_reserved_mem_init(struct k3_rproc *kproc) { struct device *dev = kproc->dev; @@ -56,7 +49,7 @@ static int k3_m4_reserved_mem_init(struct k3_rproc *kproc) dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret); return ret; } - ret = devm_add_action_or_reset(dev, k3_m4_rproc_dev_mem_release, dev); + ret = devm_add_action_or_reset(dev, k3_mem_release, dev); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index b392c40b4670..fed1d189144a 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -761,13 +761,6 @@ static int k3_r5_rproc_configure(struct k3_rproc *kproc) return ret; } -static void k3_r5_mem_release(void *data) -{ - struct device *dev = data; - - of_reserved_mem_device_release(dev); -} - static int k3_r5_reserved_mem_init(struct k3_rproc *kproc) { struct device *dev = kproc->dev; @@ -798,7 +791,7 @@ static int k3_r5_reserved_mem_init(struct k3_rproc *kproc) return ret; } - ret = devm_add_action_or_reset(dev, k3_r5_mem_release, dev); + ret = devm_add_action_or_reset(dev, k3_mem_release, dev); if (ret) return ret; From patchwork Mon Mar 17 12:06:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019153 Received: from lelvem-ot02.ext.ti.com (lelvem-ot02.ext.ti.com [198.47.23.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE668246333; Mon, 17 Mar 2025 12:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213295; cv=none; b=HItGPG1j56jYUAhEwSmvUW1/t+Ia+GViGOF0UwEzn6UXlIwlRNhhw+IEqjhJHJq8gShmTXhomxIjwDktZH62zY7rFGPPfePDzwcCUssQ/GbfdGay8YFlsetFJ/WTbEX7Q2LcKS+Th5hpMHywiR+xzMBRZth2f06gBbJajOn63Zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213295; c=relaxed/simple; bh=JewcrYwDBFSk+fQ1z+NLef+gtNFyQxq4oxtg31ZjkCk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I3S+I4FLDKUiRmK11MXOgh6zrGBou+aHt10T49wzzA/gtydU8so+xqbxY91pRs/88VxZM0MezGxfLxuOq3R0gYLX0uWa5qLGg+DQU2S5ZMJ26pevRj6G0sVZAIGLX6LD0nFrrM0XALpMWJ80D70wbkrpO22YQCSXiRjg+CdYBGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=lZKxkHpd; arc=none smtp.client-ip=198.47.23.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="lZKxkHpd" Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelvem-ot02.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC86ZO2802977 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:08:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213286; bh=eIHUahv9R0Bi7huOuYXql7JJgbjFhwQnw9A3eSvQqmw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lZKxkHpdYkovCNb9Pn3Krs/5Pf/DgyMfxFudMiw1hxKUXMRsfnl8rsVdap7Q3AM7z cYfLVciBZERM5rs/9IkAg7tjV6s94yzkBYE4XrlpmBfVMhwR2tCP3+AHq8ospIunRv j5AgnvsKYJ5ecoHguXBcDmVokXoV9Bj1kij4Ua7w= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC86pF108865 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:08:06 -0500 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:08:06 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:08:06 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKM060901; Mon, 17 Mar 2025 07:08:02 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 25/26] remoteproc: k3: Refactor reserved_mem_init() functions into common driver Date: Mon, 17 Mar 2025 17:36:21 +0530 Message-ID: <20250317120622.1746415-26-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_{r5/dsp/m4}_reserved_mem_init() functions initialize the reserved memory regions associated with the remote processor. Refactor these functions into ti_k3_common.c driver as k3_reserved_mem_init() and align R5, DSP and M4 drivers to use this common function throughout. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 70 +++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 72 +------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 71 +------------------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 82 +---------------------- 5 files changed, 74 insertions(+), 222 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index a51c0196530e..b72c4c179c97 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -470,5 +470,75 @@ void k3_mem_release(void *data) } EXPORT_SYMBOL_GPL(k3_mem_release); +int k3_reserved_mem_init(struct k3_rproc *kproc) +{ + struct device *dev = kproc->dev; + struct device_node *np = dev->of_node; + struct device_node *rmem_np; + struct reserved_mem *rmem; + int num_rmems; + int ret, i; + + num_rmems = of_property_count_elems_of_size(np, "memory-region", + sizeof(phandle)); + if (num_rmems < 0) { + dev_err(dev, "device does not reserved memory regions (%d)\n", + num_rmems); + return -EINVAL; + } + if (num_rmems < 2) { + dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n", + num_rmems); + return -EINVAL; + } + + /* use reserved memory region 0 for vring DMA allocations */ + ret = of_reserved_mem_device_init_by_idx(dev, np, 0); + if (ret) { + dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret); + return ret; + } + ret = devm_add_action_or_reset(dev, k3_mem_release, dev); + if (ret) + return ret; + + num_rmems--; + kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); + if (!kproc->rmem) + return -ENOMEM; + + /* use remaining reserved memory regions for static carveouts */ + for (i = 0; i < num_rmems; i++) { + rmem_np = of_parse_phandle(np, "memory-region", i + 1); + if (!rmem_np) + return -EINVAL; + + rmem = of_reserved_mem_lookup(rmem_np); + of_node_put(rmem_np); + if (!rmem) + return -EINVAL; + + kproc->rmem[i].bus_addr = rmem->base; + /* 64-bit address regions currently not supported */ + kproc->rmem[i].dev_addr = (u32)rmem->base; + kproc->rmem[i].size = rmem->size; + kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size); + if (!kproc->rmem[i].cpu_addr) { + dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n", + i + 1, &rmem->base, &rmem->size); + return -ENOMEM; + } + + dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n", + i + 1, &kproc->rmem[i].bus_addr, + kproc->rmem[i].size, kproc->rmem[i].cpu_addr, + kproc->rmem[i].dev_addr); + } + kproc->num_rmems = num_rmems; + + return 0; +} +EXPORT_SYMBOL_GPL(k3_reserved_mem_init); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 70656215c4d7..148717942dfb 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -108,4 +108,5 @@ void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, int k3_rproc_of_get_memories(struct platform_device *pdev, struct k3_rproc *kproc); void k3_mem_release(void *data); +int k3_reserved_mem_init(struct k3_rproc *kproc); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 1176a6f4c977..40187d03206f 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -66,76 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = { .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; -static int k3_dsp_reserved_mem_init(struct k3_rproc *kproc) -{ - struct device *dev = kproc->dev; - struct device_node *np = dev->of_node; - struct device_node *rmem_np; - struct reserved_mem *rmem; - int num_rmems; - int ret, i; - - num_rmems = of_property_count_elems_of_size(np, "memory-region", - sizeof(phandle)); - if (num_rmems < 0) { - dev_err(dev, "device does not reserved memory regions (%pe)\n", - ERR_PTR(num_rmems)); - return -EINVAL; - } - if (num_rmems < 2) { - dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n", - num_rmems); - return -EINVAL; - } - - /* use reserved memory region 0 for vring DMA allocations */ - ret = of_reserved_mem_device_init_by_idx(dev, np, 0); - if (ret) { - dev_err(dev, "device cannot initialize DMA pool (%pe)\n", - ERR_PTR(ret)); - return ret; - } - ret = devm_add_action_or_reset(dev, k3_mem_release, dev); - if (ret) - return ret; - - num_rmems--; - kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); - if (!kproc->rmem) - return -ENOMEM; - - /* use remaining reserved memory regions for static carveouts */ - for (i = 0; i < num_rmems; i++) { - rmem_np = of_parse_phandle(np, "memory-region", i + 1); - if (!rmem_np) - return -EINVAL; - - rmem = of_reserved_mem_lookup(rmem_np); - of_node_put(rmem_np); - if (!rmem) - return -EINVAL; - - kproc->rmem[i].bus_addr = rmem->base; - /* 64-bit address regions currently not supported */ - kproc->rmem[i].dev_addr = (u32)rmem->base; - kproc->rmem[i].size = rmem->size; - kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size); - if (!kproc->rmem[i].cpu_addr) { - dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n", - i + 1, &rmem->base, &rmem->size); - return -ENOMEM; - } - - dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n", - i + 1, &kproc->rmem[i].bus_addr, - kproc->rmem[i].size, kproc->rmem[i].cpu_addr, - kproc->rmem[i].dev_addr); - } - kproc->num_rmems = num_rmems; - - return 0; -} - static void k3_dsp_release_tsp(void *data) { struct ti_sci_proc *tsp = data; @@ -214,7 +144,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) if (ret) return ret; - ret = k3_dsp_reserved_mem_init(kproc); + ret = k3_reserved_mem_init(kproc); if (ret) return dev_err_probe(dev, ret, "reserved memory init failed\n"); diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index 67b92cbf7c2b..a1a31c4f8c3e 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,75 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -static int k3_m4_reserved_mem_init(struct k3_rproc *kproc) -{ - struct device *dev = kproc->dev; - struct device_node *np = dev->of_node; - struct device_node *rmem_np; - struct reserved_mem *rmem; - int num_rmems; - int ret, i; - - num_rmems = of_property_count_elems_of_size(np, "memory-region", - sizeof(phandle)); - if (num_rmems < 0) { - dev_err(dev, "device does not reserved memory regions (%d)\n", - num_rmems); - return -EINVAL; - } - if (num_rmems < 2) { - dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n", - num_rmems); - return -EINVAL; - } - - /* use reserved memory region 0 for vring DMA allocations */ - ret = of_reserved_mem_device_init_by_idx(dev, np, 0); - if (ret) { - dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret); - return ret; - } - ret = devm_add_action_or_reset(dev, k3_mem_release, dev); - if (ret) - return ret; - - num_rmems--; - kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); - if (!kproc->rmem) - return -ENOMEM; - - /* use remaining reserved memory regions for static carveouts */ - for (i = 0; i < num_rmems; i++) { - rmem_np = of_parse_phandle(np, "memory-region", i + 1); - if (!rmem_np) - return -EINVAL; - - rmem = of_reserved_mem_lookup(rmem_np); - of_node_put(rmem_np); - if (!rmem) - return -EINVAL; - - kproc->rmem[i].bus_addr = rmem->base; - /* 64-bit address regions currently not supported */ - kproc->rmem[i].dev_addr = (u32)rmem->base; - kproc->rmem[i].size = rmem->size; - kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size); - if (!kproc->rmem[i].cpu_addr) { - dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n", - i + 1, &rmem->base, &rmem->size); - return -ENOMEM; - } - - dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n", - i + 1, &kproc->rmem[i].bus_addr, - kproc->rmem[i].size, kproc->rmem[i].cpu_addr, - kproc->rmem[i].dev_addr); - } - kproc->num_rmems = num_rmems; - - return 0; -} - static void k3_m4_release_tsp(void *data) { struct ti_sci_proc *tsp = data; @@ -170,7 +101,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) if (ret) return ret; - ret = k3_m4_reserved_mem_init(kproc); + ret = k3_reserved_mem_init(kproc); if (ret) return dev_err_probe(dev, ret, "reserved memory init failed\n"); diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index fed1d189144a..ecac013b6482 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -761,86 +761,6 @@ static int k3_r5_rproc_configure(struct k3_rproc *kproc) return ret; } -static int k3_r5_reserved_mem_init(struct k3_rproc *kproc) -{ - struct device *dev = kproc->dev; - struct device_node *np = dev_of_node(dev); - struct device_node *rmem_np; - struct reserved_mem *rmem; - int num_rmems; - int ret, i; - - num_rmems = of_property_count_elems_of_size(np, "memory-region", - sizeof(phandle)); - if (num_rmems <= 0) { - dev_err(dev, "device does not have reserved memory regions, ret = %d\n", - num_rmems); - return -EINVAL; - } - if (num_rmems < 2) { - dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n", - num_rmems); - return -EINVAL; - } - - /* use reserved memory region 0 for vring DMA allocations */ - ret = of_reserved_mem_device_init_by_idx(dev, np, 0); - if (ret) { - dev_err(dev, "device cannot initialize DMA pool, ret = %d\n", - ret); - return ret; - } - - ret = devm_add_action_or_reset(dev, k3_mem_release, dev); - if (ret) - return ret; - - num_rmems--; - kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); - if (!kproc->rmem) - return -ENOMEM; - - /* use remaining reserved memory regions for static carveouts */ - for (i = 0; i < num_rmems; i++) { - rmem_np = of_parse_phandle(np, "memory-region", i + 1); - if (!rmem_np) - return -EINVAL; - - rmem = of_reserved_mem_lookup(rmem_np); - of_node_put(rmem_np); - if (!rmem) - return -EINVAL; - - kproc->rmem[i].bus_addr = rmem->base; - /* - * R5Fs do not have an MMU, but have a Region Address Translator - * (RAT) module that provides a fixed entry translation between - * the 32-bit processor addresses to 64-bit bus addresses. The - * RAT is programmable only by the R5F cores. Support for RAT - * is currently not supported, so 64-bit address regions are not - * supported. The absence of MMUs implies that the R5F device - * addresses/supported memory regions are restricted to 32-bit - * bus addresses, and are identical - */ - kproc->rmem[i].dev_addr = (u32)rmem->base; - kproc->rmem[i].size = rmem->size; - kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size); - if (!kproc->rmem[i].cpu_addr) { - dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n", - i + 1, &rmem->base, &rmem->size); - return -ENOMEM; - } - - dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n", - i + 1, &kproc->rmem[i].bus_addr, - kproc->rmem[i].size, kproc->rmem[i].cpu_addr, - kproc->rmem[i].dev_addr); - } - kproc->num_rmems = num_rmems; - - return 0; -} - /* * Each R5F core within a typical R5FSS instance has a total of 64 KB of TCMs, * split equally into two 32 KB banks between ATCM and BTCM. The TCMs from both @@ -1156,7 +1076,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) init_rmem: k3_r5_adjust_tcm_sizes(kproc); - ret = k3_r5_reserved_mem_init(kproc); + ret = k3_reserved_mem_init(kproc); if (ret) { dev_err(cdev, "reserved memory init failed, ret = %d\n", ret); From patchwork Mon Mar 17 12:06:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Padhi X-Patchwork-Id: 14019154 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C577D24A042; Mon, 17 Mar 2025 12:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213304; cv=none; b=Icc1mCTx7SBjl0Bjmn7tNoCfcTKO61bFP9UA/mKUT97slZXabywBwq0C56UMDul0KmyHcOK4JRfXeY11KrN1LHkqjUjiGWhnAEAauzZPMsaz/YQHWUOiwk3tNXeBU7C/q08i3ClE85uc1udMqrSJVCMxfEJA79HAFUagLU5QfBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742213304; c=relaxed/simple; bh=zayEsJU+c8cOBRixd8Ws3Oj7Y3PF77IZpr5UDqJofo0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kgf0rzP+D+h5NTGbv7HLJ2UD+mpirKZ8+Fr8Bbjx4L+CkolGojzAE4JDljjJMb8xk4jfXDHd3/nA9zIrypk8YPfWy13e6DR0aCTcu9s+7C7iKZMo7O+t3bgsZNpxs9z4IFTxi/DbAjdP36XPKV+ITNcMKqa8kx8qYm+Z5sM8mHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=PZ/Pjrqn; arc=none smtp.client-ip=198.47.19.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="PZ/Pjrqn" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC8Cg42755841 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Mar 2025 07:08:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1742213292; bh=NgtW+ifdP60oEZkzqO6isD8I+BsOR6W5AuC7p1fICE8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=PZ/PjrqnS9QVIWZED7Yx4r81Vew8oXcdfTHMjt7es+fF5Y3HEkMAitDThgdJyHWOW JVjADAMVxEmEvFn7VjqICbYt4XsU+nlUNN3fK0ysfpThflbYTjmPeufFzja9I5lY0E 3dXFjLMaDTZZWQ1Sjl+lyPjqocsW2E/AG6KJs1nc= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 52HC8CTY124573 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Mar 2025 07:08:12 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 17 Mar 2025 07:08:11 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 17 Mar 2025 07:08:11 -0500 Received: from uda0510294.dhcp.ti.com (uda0510294.dhcp.ti.com [172.24.227.151]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 52HC6MKN060901; Mon, 17 Mar 2025 07:08:06 -0500 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v9 26/26] remoteproc: k3: Refactor release_tsp() functions into common driver Date: Mon, 17 Mar 2025 17:36:22 +0530 Message-ID: <20250317120622.1746415-27-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317120622.1746415-1-b-padhi@ti.com> References: <20250317120622.1746415-1-b-padhi@ti.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea The k3_{r5/dsp/m4}_release_tsp() functions release the TI-SCI processor control of a remote processor, which is auto triggered upon device removal. Refactor these functions into ti_k3_common.c driver as k3_release_tsp() and align R5, DSP and M4 drivers to use this common function throughout. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 8 ++++++++ drivers/remoteproc/ti_k3_common.h | 1 + drivers/remoteproc/ti_k3_dsp_remoteproc.c | 9 +-------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 9 +-------- drivers/remoteproc/ti_k3_r5_remoteproc.c | 9 +-------- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index b72c4c179c97..d5003112136b 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -540,5 +540,13 @@ int k3_reserved_mem_init(struct k3_rproc *kproc) } EXPORT_SYMBOL_GPL(k3_reserved_mem_init); +void k3_release_tsp(void *data) +{ + struct ti_sci_proc *tsp = data; + + ti_sci_proc_release(tsp); +} +EXPORT_SYMBOL_GPL(k3_release_tsp); + MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("TI K3 common Remoteproc code"); diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h index 148717942dfb..a9981303dde8 100644 --- a/drivers/remoteproc/ti_k3_common.h +++ b/drivers/remoteproc/ti_k3_common.h @@ -109,4 +109,5 @@ int k3_rproc_of_get_memories(struct platform_device *pdev, struct k3_rproc *kproc); void k3_mem_release(void *data); int k3_reserved_mem_init(struct k3_rproc *kproc); +void k3_release_tsp(void *data); #endif /* REMOTEPROC_TI_K3_COMMON_H */ diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c index 40187d03206f..f5f17c18fc1b 100644 --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c @@ -66,13 +66,6 @@ static const struct rproc_ops k3_dsp_rproc_ops = { .get_loaded_rsc_table = k3_get_loaded_rsc_table, }; -static void k3_dsp_release_tsp(void *data) -{ - struct ti_sci_proc *tsp = data; - - ti_sci_proc_release(tsp); -} - static int k3_dsp_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -136,7 +129,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) dev_err_probe(dev, ret, "ti_sci_proc_request failed\n"); return ret; } - ret = devm_add_action_or_reset(dev, k3_dsp_release_tsp, kproc->tsp); + ret = devm_add_action_or_reset(dev, k3_release_tsp, kproc->tsp); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c index a1a31c4f8c3e..c9c563c75ff6 100644 --- a/drivers/remoteproc/ti_k3_m4_remoteproc.c +++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c @@ -21,13 +21,6 @@ #include "ti_sci_proc.h" #include "ti_k3_common.h" -static void k3_m4_release_tsp(void *data) -{ - struct ti_sci_proc *tsp = data; - - ti_sci_proc_release(tsp); -} - static const struct rproc_ops k3_m4_rproc_ops = { .prepare = k3_rproc_prepare, .unprepare = k3_rproc_unprepare, @@ -93,7 +86,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev) ret = ti_sci_proc_request(kproc->tsp); if (ret < 0) return dev_err_probe(dev, ret, "ti_sci_proc_request failed\n"); - ret = devm_add_action_or_reset(dev, k3_m4_release_tsp, kproc->tsp); + ret = devm_add_action_or_reset(dev, k3_release_tsp, kproc->tsp); if (ret) return ret; diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index ecac013b6482..ffb146c9cd47 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -954,13 +954,6 @@ static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, return 0; } -static void k3_r5_release_tsp(void *data) -{ - struct ti_sci_proc *tsp = data; - - ti_sci_proc_release(tsp); -} - static int k3_r5_cluster_rproc_init(struct platform_device *pdev) { struct k3_r5_cluster *cluster = platform_get_drvdata(pdev); @@ -1046,7 +1039,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) goto out; } - ret = devm_add_action_or_reset(cdev, k3_r5_release_tsp, kproc->tsp); + ret = devm_add_action_or_reset(cdev, k3_release_tsp, kproc->tsp); if (ret) goto out; }