From patchwork Sat Mar 14 00:43:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 11438153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B48BF6CA for ; Sat, 14 Mar 2020 00:43:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 833A22074A for ; Sat, 14 Mar 2020 00:43:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Jq90n2Hd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727715AbgCNAnj (ORCPT ); Fri, 13 Mar 2020 20:43:39 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:34788 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbgCNAni (ORCPT ); Fri, 13 Mar 2020 20:43:38 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02E0hbt5054349; Fri, 13 Mar 2020 19:43:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584146617; bh=+LlX08aW7D5n6KvWyBHiiiHaHMCtun+6QGACeFnP7bs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Jq90n2HdRGWZz3H4kRyWFoDhEuniFD2J0TI5E2ufuLoIvOIT/r0bMxsrDJ/xkJqSi 9nQV/ijDpa4hwXs0cfbo4CXy+bOaBTl8Ac5bRGiwlCu2yrhwpKLu8l3YKbBqlCkQwu sLsn8AR671284BCqA24IJ4I3zBgoMrVCMdevWp3g= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02E0hbiK062346; Fri, 13 Mar 2020 19:43:37 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) 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.1847.3; Fri, 13 Mar 2020 19:43:37 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) 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.1847.3 via Frontend Transport; Fri, 13 Mar 2020 19:43:37 -0500 Received: from lelv0597.itg.ti.com (lelv0597.itg.ti.com [10.181.64.32]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02E0hbWa071056; Fri, 13 Mar 2020 19:43:37 -0500 Received: from localhost (irmo.dhcp.ti.com [128.247.81.254]) by lelv0597.itg.ti.com (8.14.7/8.14.7) with ESMTP id 02E0hbiH116041; Fri, 13 Mar 2020 19:43:37 -0500 From: Suman Anna To: Bjorn Andersson , Ohad Ben-Cohen , CC: , Mathieu Poirier , Suman Anna , "Andrew F. Davis" , Tero Kristo Subject: [PATCHv8 RESEND 03/15] remoteproc/omap: Add a sanity check for DSP boot address alignment Date: Fri, 13 Mar 2020 19:43:34 -0500 Message-ID: <20200314004334.26509-1-s-anna@ti.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200313081718.30612-4-t-kristo@ti.com> References: <20200313081718.30612-4-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The DSP remote processors on OMAP SoCs require a boot register to be programmed with a boot address, and this boot address needs to be on a 1KB boundary. The current code is simply masking the boot address appropriately without performing any sanity checks before releasing the resets. An unaligned boot address results in an undefined execution behavior and can result in various bus errors like MMU Faults or L3 NoC errors. Such errors are hard to debug and can be easily avoided by adding a sanity check for the alignment before booting a DSP remote processor. Signed-off-by: Suman Anna Signed-off-by: Tero Kristo Reviewed-by: Bjorn Andersson Reviewed-by: Andrew F. Davis Acked-by: Mathieu Poirier --- v8-Resend: Updated to fix compilation issues against rproc-next drivers/remoteproc/omap_remoteproc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c index d47d5ded651a..fe11cb709770 100644 --- a/drivers/remoteproc/omap_remoteproc.c +++ b/drivers/remoteproc/omap_remoteproc.c @@ -121,14 +121,23 @@ static void omap_rproc_kick(struct rproc *rproc, int vqid) * @rproc: handle of a remote processor * * Set boot address for a supported DSP remote processor. + * + * Return: 0 on success, or -EINVAL if boot address is not aligned properly */ -static void omap_rproc_write_dsp_boot_addr(struct rproc *rproc) +static int omap_rproc_write_dsp_boot_addr(struct rproc *rproc) { + struct device *dev = rproc->dev.parent; struct omap_rproc *oproc = rproc->priv; struct omap_rproc_boot_data *bdata = oproc->boot_data; u32 offset = bdata->boot_reg; - regmap_write(bdata->syscon, offset, rproc->bootaddr); + if (rproc->bootaddr & (SZ_1K - 1)) { + dev_err(dev, "invalid boot address 0x%llx, must be aligned on a 1KB boundary\n", + rproc->bootaddr); + return -EINVAL; + } + + return regmap_write(bdata->syscon, offset, rproc->bootaddr); } /* @@ -145,8 +154,11 @@ static int omap_rproc_start(struct rproc *rproc) int ret; struct mbox_client *client = &oproc->client; - if (oproc->boot_data) - omap_rproc_write_dsp_boot_addr(rproc); + if (oproc->boot_data) { + ret = omap_rproc_write_dsp_boot_addr(rproc); + if (ret) + return ret; + } client->dev = dev; client->tx_done = NULL; From patchwork Sat Mar 14 00:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 11438155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EB6D6CA for ; Sat, 14 Mar 2020 00:43:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F6B62074A for ; Sat, 14 Mar 2020 00:43:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="UQw0O3pb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgCNAnk (ORCPT ); Fri, 13 Mar 2020 20:43:40 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:45114 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbgCNAnk (ORCPT ); Fri, 13 Mar 2020 20:43:40 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02E0hcbl090466; Fri, 13 Mar 2020 19:43:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584146618; bh=pPGfl1/MfmLCax7BhN6s6oSzE9jBgXIiLPf5nVaagEI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=UQw0O3pboRXiJCKg5Sg/S7ehhpupRltTIvHm9kn1yNzGpGUwNC6vQTzQfgCht4u7J oiHk2/dUjCZWAGcNOuHfMwCdJdg4rrlzP8thZCncGNrjcOo0ijO3JriLb0AlgTzHLE gwr9lMMAMA4D/iZmmIJ2cZq7H3cbo6LTvi5B2Abw= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02E0hc6Q055650 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Mar 2020 19:43:38 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 13 Mar 2020 19:43:38 -0500 Received: from localhost.localdomain (10.64.41.19) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 13 Mar 2020 19:43:38 -0500 Received: from lelv0597.itg.ti.com (lelv0597.itg.ti.com [10.181.64.32]) by localhost.localdomain (8.15.2/8.15.2) with ESMTP id 02E0hcSQ123457; Fri, 13 Mar 2020 19:43:38 -0500 Received: from localhost (irmo.dhcp.ti.com [128.247.81.254]) by lelv0597.itg.ti.com (8.14.7/8.14.7) with ESMTP id 02E0hcwQ116067; Fri, 13 Mar 2020 19:43:38 -0500 From: Suman Anna To: Bjorn Andersson , Ohad Ben-Cohen , CC: , Mathieu Poirier , Suman Anna , "Andrew F. Davis" , Tero Kristo Subject: [PATCHv8 RESEND 05/15] remoteproc/omap: Add the rproc ops .da_to_va() implementation Date: Fri, 13 Mar 2020 19:43:37 -0500 Message-ID: <20200314004337.26556-1-s-anna@ti.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200313081718.30612-6-t-kristo@ti.com> References: <20200313081718.30612-6-t-kristo@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org An implementation for the rproc ops .da_to_va() has been added that provides the address translation between device addresses to kernel virtual addresses for internal RAMs present on that particular remote processor device. The implementation provides the translations based on the addresses parsed and stored during the probe. This ops gets invoked by the exported rproc_da_to_va() function and allows the remoteproc core's ELF loader to be able to load program data directly into the internal memories. Signed-off-by: Suman Anna Signed-off-by: Tero Kristo Reviewed-by: Andrew F. Davis Acked-by: Mathieu Poirier --- v8-Resend: Updated to fix compilation issues against rproc-next drivers/remoteproc/omap_remoteproc.c | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c index cdcc9c227b96..6091666697ed 100644 --- a/drivers/remoteproc/omap_remoteproc.c +++ b/drivers/remoteproc/omap_remoteproc.c @@ -245,10 +245,50 @@ static int omap_rproc_stop(struct rproc *rproc) return 0; } +/** + * omap_rproc_da_to_va() - internal memory translation helper + * @rproc: remote processor to apply the address translation for + * @da: device address to translate + * @len: length of the memory buffer + * + * Custom function implementing the rproc .da_to_va ops to provide address + * translation (device address to kernel virtual address) for internal RAMs + * present in a DSP or IPU device). The translated addresses can be used + * either by the remoteproc core for loading, or by any rpmsg bus drivers. + * + * Return: translated virtual address in kernel memory space on success, + * or NULL on failure. + */ +static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len) +{ + struct omap_rproc *oproc = rproc->priv; + int i; + u32 offset; + + if (len == 0) + return NULL; + + if (!oproc->num_mems) + return NULL; + + for (i = 0; i < oproc->num_mems; i++) { + if (da >= oproc->mem[i].dev_addr && da + len <= + oproc->mem[i].dev_addr + oproc->mem[i].size) { + offset = da - oproc->mem[i].dev_addr; + /* __force to make sparse happy with type conversion */ + return (__force void *)(oproc->mem[i].cpu_addr + + offset); + } + } + + return NULL; +} + static const struct rproc_ops omap_rproc_ops = { .start = omap_rproc_start, .stop = omap_rproc_stop, .kick = omap_rproc_kick, + .da_to_va = omap_rproc_da_to_va, }; static const struct omap_rproc_mem_data ipu_mems[] = {