Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3712220ybl; Fri, 20 Dec 2019 14:17:13 -0800 (PST) X-Google-Smtp-Source: APXvYqw1o7MPKZ7A5iP0hHQK2jOiE6x5vnz3fXdc1278Mwm84Yldhj4HrD+AxJGjQ6V+o1T0RcWN X-Received: by 2002:a9d:6f8f:: with SMTP id h15mr16683124otq.1.1576880233057; Fri, 20 Dec 2019 14:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576880233; cv=none; d=google.com; s=arc-20160816; b=QBcb6SN8efoaccsPCs2sH8NxtjsIeLH6Iv97VniF+2Q0BFCUdH5GW42XCIW+yxN46x NjHMfMJh7Rn9IU303htoIfvff0MJXcEwK1B0MfevqSZNVNnCy3gm3SFlcT3//KEUjnRQ Y4FG8OPAXhh10ol7+JoQ4fwfgj4ahgUctUSWMbtuWVY8nfu+fOLcyQerPglHjHXOzrD9 pNcuOB8O5d9l6ynFypG12Qcfl/PgcTXncC9vv/1cjVVoGRMA+bBNXR7TdZ7PODQuWVYt /cwpGHnTuvX5NFCza+fuGEN5LgvO33ZxQaP8PhEU9ej+PbxufKXtumKpTyk3KMRYnXh+ vf1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PvWa7xcnllmgFIQc5TjQdgByUUuzYx3n1hiBZ4AYta4=; b=Tthx9ymLOWeQ72dl7miDoQY4uTQR7W94KUV/U2ZqrFVuZOZ3gqRt5aNKPRvsX+QLVl 5pyMby1gBo7sQsxylCueHwTuf8V7kTk8H7bn7KTFFlOoPTpc7CciKwVnouy1QT18ToFY lCXdxrWyCGvIAuwO9e+um/8U+bE8Jk+RHzUSkY4pPI8j2Nq1UsC7RkpwF5lfI8dYBrfh rA6+HeGu5nubTDU/9D15ZnnaP8fSdH0Abg0lx3joPDuzxoLfy7NNf90+epufnbUCS5S8 KUc2rZ6tAkC7ToiW1jwCnWmNb0RQQpxntRnHi/HwIla3mfHzITlIwNAhE5UlTLT57sJS BzXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hrMufeuc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s64si5509502oig.147.2019.12.20.14.17.01; Fri, 20 Dec 2019 14:17:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hrMufeuc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727549AbfLTWQA (ORCPT + 99 others); Fri, 20 Dec 2019 17:16:00 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:35672 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727473AbfLTWQA (ORCPT ); Fri, 20 Dec 2019 17:16:00 -0500 Received: by mail-il1-f195.google.com with SMTP id g12so9264127ild.2 for ; Fri, 20 Dec 2019 14:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PvWa7xcnllmgFIQc5TjQdgByUUuzYx3n1hiBZ4AYta4=; b=hrMufeuc588g/HgbK0LCytUMm0WsbqweLxtriW77oNbPiw/MmW29qb3nVIlxDJYmNj oinggwU2fJ8dyX+5eQo1i7w7GQFvuelA6PS2q1+kh3lLOq19/+76Ob3Pkj4qmOz8q+wq k6pHEcSy/GQDx0MuWS0zlnUWE/W0OJMwhZ411utN6dsp1N9D0b/NW0j0cAZauMWvOa1M GshDLEwzCJIiB04QNgJmUHXVXawziFsB+laAsNfFpObfxHZsTf1AwBNZc03+Jdmg6La+ 0EtE1ODpS+JmqAcUi8sMZtWzOFynmvQH1S861bJXgG6gq9M5r34155lAP8LchHweDmnW ly5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PvWa7xcnllmgFIQc5TjQdgByUUuzYx3n1hiBZ4AYta4=; b=ksX2cSoo/SD0NwF8OPR9KVPRLxns9d8F6w715ae7DktZpd1W+z8KH1wQCH0mLUNOnM mBdshzXD/sT/Eu6pr+PLLzhsFhSFRoUwhvR8Sp13kMoa5wM0tcZL6rSSjYxY/DKLh7Lx S6eDkHMGHie0+Ca7tAgYzQy2F8BeetaponWtrJWXtTAhKC6mXc1HF7FsyEOGbRjpPyFm UaWrMRSErRcvbYVDc18u8tvXgtAnCSBicBrWwjybKdQuEGq1Ah09X2DnhEYx/KEmUcjp dL7NJQHmpXQVqzrLFsQQyAx+rO8CDTkQyqlC9arqMn4fyRvCpE296RDJxBhElDXCgoh5 hjMQ== X-Gm-Message-State: APjAAAWGGv7UgIeDFuQtRjNJz9DptNbgKJ9GmDso1atn0p8hNMIyxesa 2Lmlf8b39nZZrziWLqI515+lk06p0CaHq89dS3XYkw== X-Received: by 2002:a92:1547:: with SMTP id v68mr13877236ilk.58.1576880159104; Fri, 20 Dec 2019 14:15:59 -0800 (PST) MIME-Version: 1.0 References: <20191213125537.11509-1-t-kristo@ti.com> <20191213125537.11509-6-t-kristo@ti.com> <20191218003815.GC16271@xps15> <5869498f-086c-cea4-edcf-1b75fb22cf22@ti.com> In-Reply-To: From: Mathieu Poirier Date: Fri, 20 Dec 2019 15:15:48 -0700 Message-ID: Subject: Re: [PATCHv3 05/15] remoteproc/omap: Add the rproc ops .da_to_va() implementation To: Suman Anna Cc: Tero Kristo , Bjorn Andersson , Ohad Ben-Cohen , linux-remoteproc@vger.kernel.org, Linux Kernel Mailing List , linux-omap@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 19 Dec 2019 at 19:34, Suman Anna wrote: > > On 12/19/19 6:12 PM, Mathieu Poirier wrote: > > On Thu, 19 Dec 2019 at 06:18, Tero Kristo wrote: > >> > >> On 18/12/2019 02:38, Mathieu Poirier wrote: > >>> On Fri, Dec 13, 2019 at 02:55:27PM +0200, Tero Kristo wrote: > >>>> From: Suman Anna > >>>> > >>>> 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 > >>>> --- > >>>> drivers/remoteproc/omap_remoteproc.c | 39 ++++++++++++++++++++++++++++ > >>>> 1 file changed, 39 insertions(+) > >>>> > >>>> diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c > >>>> index 844703507a74..28f14e24b389 100644 > >>>> --- a/drivers/remoteproc/omap_remoteproc.c > >>>> +++ b/drivers/remoteproc/omap_remoteproc.c > >>>> @@ -232,10 +232,49 @@ 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. > >>>> + * Returns the translated virtual address in kernel memory space, or NULL > >>>> + * in failure. > >>>> + */ > >>>> +static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, int 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 <= > >>> > >>> Shouldn't this be '<' rather than '<=' ? > >> > >> No, I think <= is correct. You need to consider the initial byte in the > >> range also. Consider a simple case where you provide the exact da + len > >> corresponding to a specific memory range. > > > > For that specific case you are correct. On the flip side if @da falls > > somewhere after @mem[i].dev_addr, there is a possibility to clobber > > the first byte of the next range if <= is used. > > Not really, you will miss out on the last byte actually if you use just > <. This is just address range check, any memcpy would actually end one > byte before. I am indeed worried about actual memory accesses but rproc_da_to_va() is using the same logic as you are when circling through carveouts. As such you can forget about my comment. Thanks, Mathieu > > Eg: 0x80000 of len 0x10000. I should perfectly be able to copy 0x1000 > bytes at 0x8f000. > > regards > Suman > > > > > > Thanks, > > Mathieu > > > >> > >>> > >>>> + oproc->mem[i].dev_addr + oproc->mem[i].size) { > >>> > >>> One space too many after the '+' . > >> > >> True, I wonder why checkpatch did not catch this. > >> > >>> > >>>> + offset = da - oproc->mem[i].dev_addr; > >>> > >>> One space too many after then '-' . > >> > >> Same, will fix these two. > >> > >> -Tero > >> > >>> > >>>> + /* __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 char * const ipu_mem_names[] = { > >>>> -- > >>>> 2.17.1 > >>>> > >>>> -- > >> > >> -- > >> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki >