From patchwork Fri Jan 3 10:12:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beleswar Prasad Padhi X-Patchwork-Id: 13925470 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 4013E1FA8E5; Fri, 3 Jan 2025 10:13:45 +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=1735899228; cv=none; b=l7vjo2faMVYulrCtt1fxB2EbxwyjPGfyGM6TTQT00hzJqXp1menqkp/jO6OTBeSkAJdUOf4BgMf+fzqldvzX3KVJgZz1ygPUd5OBW1h5tVApe7wFWg4SNSGfDXtyl+MbwelAjhsPRcHJiBnbzaqfNZoU8BsLRvxVVWO68P5rF6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735899228; c=relaxed/simple; bh=MTBPwjex1C92dfwP9Ce+zqig5cGatiXjEK/S09vKHcI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pM3QBqPJsheXDTulioLQdETY97TeY+DN7LElwDV67eo8VjIftiYkqsT0P+dxpi59OUWXkd7jDij4gnesDDMt3aFGW7MY2zmTqeNtB2EOm4R+btE6flW6f7tfQLX7PDov3TX4aH/j16fAw9povrLfqqAh9I/fFRyFBlxUrAVeFaE= 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=TM8AgAbm; 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="TM8AgAbm" 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 503ADa3l2306967 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 3 Jan 2025 04:13:36 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1735899216; bh=i2aRulhPpfXN3jzGKGrViMTOBHWmKdH6T7LKk1jq8Vo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=TM8AgAbmJFz+jkhBzfdoh6srEdeYdc/QxlNvL/GvmqSILdYowzinHKeSIgMcpfSij YQPXa3/XRMJJs9m43wT4s3UZEVeYR2khn2GJ9EKdWSu7i1w6HNM81vx6ymUm0gGAXn l8hD+8EeYh8vZXnf//a8GBCyOZzG9c4a3SARsEs8= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTP id 503ADaL7042144; Fri, 3 Jan 2025 04:13:36 -0600 Received: from DLEE111.ent.ti.com (157.170.170.22) 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; Fri, 3 Jan 2025 04:13:35 -0600 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; Fri, 3 Jan 2025 04:13:35 -0600 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 503ACVSY126047; Fri, 3 Jan 2025 04:13:32 -0600 From: Beleswar Padhi To: , CC: , , , , , , , , , , Subject: [PATCH v8 16/20] remoteproc: k3: Refactor .da_to_va rproc ops into common driver Date: Fri, 3 Jan 2025 15:42:27 +0530 Message-ID: <20250103101231.1508151-17-b-padhi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250103101231.1508151-1-b-padhi@ti.com> References: <20250103101231.1508151-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_dsp_remoteproc.c and ti_k3_m4_remoteproc.c 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 DSP and M4 drivers to register this common function as .da_to_va ops. Signed-off-by: Beleswar Padhi --- drivers/remoteproc/ti_k3_common.c | 61 ++++++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 4 ++ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 63 +---------------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 58 +-------------------- 4 files changed, 67 insertions(+), 119 deletions(-) diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c index f56d2553a669..520f3fa44195 100644 --- a/drivers/remoteproc/ti_k3_common.c +++ b/drivers/remoteproc/ti_k3_common.c @@ -382,5 +382,66 @@ 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; + + if (da < KEYSTONE_RPROC_LOCAL_ADDRESS_MASK) { + /* 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; + } + } 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; +} +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 663911dc7032..622711951811 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 e1caa5ee9a0d..a959f361aae2 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, };