Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1337297pxb; Fri, 26 Feb 2021 08:18:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMzzbUgTTA1S7ljxHQ+ZqLjF6KoQTzluPNZbPnSp9U7QLT/tn4JHIKtw63rdUG4AmcFxjE X-Received: by 2002:a05:6402:1aca:: with SMTP id ba10mr4253225edb.6.1614356322634; Fri, 26 Feb 2021 08:18:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614356322; cv=none; d=google.com; s=arc-20160816; b=v45ByHtgHxQqE6zfwWpddizj/Vq2vVOOx2BI32rcpDbVTKvxqxxvaz1lPfrySuX/Iv Hhj186AQFQKLxMcMVfZauNq2j85R/WxvFyCtjXMadNtEC7yqbZfj8gX1PY8Lcnj/wDT5 zTfJZjA9pjjHrdSjntyXfw/ha+ucdyIIRTgW339uFvsKX0lWWrU3QS2bzfPSW+YQXoP8 /9rWCKFwaN50JBKyLu7F50eI+FWUC2d4zevICLL0kWl+EjmgcMaa3anoOr9vcg0oj9LY Hk+LCX+ICBOA3t7MCRIqXi0eeXHvgVafRi/knKYm/W/VgpOLBUqiWKVGKY3GPra2bWzN Ictg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=ltG/OX6c6RPU8ASiBmXqyjD3MmtqWH96U4xplSNeJ5Y=; b=Qe6m6ZOy6baVqnFTxM94cvOVhZ1VVliILmT1YQ9yWDIvymeSgmz1xhoR+drVfW0Zqh kbXi/PlmQnNv46H6We/dUCvNF2QvTgSwKjVNLFZm2I4JjnfDOZu8osiSLFd7Vl/s6jjv x7vEqsbDBcopafvcgRRwIr7LCAtrAm3A5yfvoQ6fgCgmQBB0mS78uBv0SmKJVVbyKgbB /jnUgPI59aqfXR8L3QfuL2vZ3b5H09sU63eAFUSCa8Edvd7E0XIOIf7vQYKsuw0IeqDJ TgBFTBrIWQg1EfPh6RjW54yMj/iQ5HbgIn9cbqP8CsX9p+xOszAsJCHyWnJbJfggi7dF bJIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=xNMzTGH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn4si7035534ejc.635.2021.02.26.08.18.08; Fri, 26 Feb 2021 08:18:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=xNMzTGH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbhBZQPr (ORCPT + 99 others); Fri, 26 Feb 2021 11:15:47 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:34202 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229566AbhBZQPm (ORCPT ); Fri, 26 Feb 2021 11:15:42 -0500 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 11QGCff1030026; Fri, 26 Feb 2021 17:14:54 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=ltG/OX6c6RPU8ASiBmXqyjD3MmtqWH96U4xplSNeJ5Y=; b=xNMzTGH98JDl7nbX7xUAvN896X1d2efACXYDF7D9Llcrt8ZkJcDIytvm9liz07xykQj8 KXFKghZ/aVjq/m4anDj9gvw/V6t6SBA3kzrluEEuAAaUhKaLS5D8Ak1Uf/FEvPx+ARjz aFo+sbBZfiKv2U1V11OjyV4QKFG8uR1BroyP85VIPfMEpwXhg3SnqzsI7yhJPR3lAMC7 TOVOgnShEmRXE4NsQB/DWhNHNJCRqLyBTsszxwo2xPzznSkBzGoMWCoXJqADboGTch37 5iWmkbGabUOqfprq707myFxGc46t+hdp2u4CXB1w1nexc4FFUtyGih8Uir0Z3BFE8rkK Lw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 36w66vxq6q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Feb 2021 17:14:54 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 52B2410002A; Fri, 26 Feb 2021 17:14:54 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 40A382A4D99; Fri, 26 Feb 2021 17:14:54 +0100 (CET) Received: from lmecxl0889.lme.st.com (10.75.127.50) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 26 Feb 2021 17:14:53 +0100 Subject: Re: [PATCH v6 06/16] remoteproc: stm32: Move resource table setup to rproc_ops To: Mathieu Poirier , , , CC: , , , , References: <20210223233515.3468677-1-mathieu.poirier@linaro.org> <20210223233515.3468677-7-mathieu.poirier@linaro.org> From: Arnaud POULIQUEN Message-ID: <3fe71628-d37a-94f5-3d08-132b0b0cf0f6@foss.st.com> Date: Fri, 26 Feb 2021 17:14:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210223233515.3468677-7-mathieu.poirier@linaro.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-02-26_05:2021-02-26,2021-02-26 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/24/21 12:35 AM, Mathieu Poirier wrote: > Move the setting of the resource table installed by an external > entity to rproc_ops::get_loaded_rsc_table(). This is to support > scenarios where a remote processor has been started by the core > but is detached at a later stage. To re-attach the remote > processor, the address of the resource table needs to be available > at a later time than the platform driver's probe() function. > > Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Thanks, Arnaud > --- > drivers/remoteproc/stm32_rproc.c | 141 +++++++++++++++---------------- > 1 file changed, 68 insertions(+), 73 deletions(-) > > diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c > index ccb3c14a0023..f647e565014b 100644 > --- a/drivers/remoteproc/stm32_rproc.c > +++ b/drivers/remoteproc/stm32_rproc.c > @@ -546,6 +546,73 @@ static void stm32_rproc_kick(struct rproc *rproc, int vqid) > } > } > > +static int stm32_rproc_da_to_pa(struct rproc *rproc, > + u64 da, phys_addr_t *pa) > +{ > + struct stm32_rproc *ddata = rproc->priv; > + struct device *dev = rproc->dev.parent; > + struct stm32_rproc_mem *p_mem; > + unsigned int i; > + > + for (i = 0; i < ddata->nb_rmems; i++) { > + p_mem = &ddata->rmems[i]; > + > + if (da < p_mem->dev_addr || > + da >= p_mem->dev_addr + p_mem->size) > + continue; > + > + *pa = da - p_mem->dev_addr + p_mem->bus_addr; > + dev_dbg(dev, "da %llx to pa %#x\n", da, *pa); > + > + return 0; > + } > + > + dev_err(dev, "can't translate da %llx\n", da); > + > + return -EINVAL; > +} > + > +static struct resource_table * > +stm32_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) > +{ > + struct stm32_rproc *ddata = rproc->priv; > + struct device *dev = rproc->dev.parent; > + phys_addr_t rsc_pa; > + u32 rsc_da; > + int err; > + > + /* The resource table has already been mapped, nothing to do */ > + if (ddata->rsc_va) > + goto done; > + > + err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da); > + if (err) { > + dev_err(dev, "failed to read rsc tbl addr\n"); > + return ERR_PTR(-EINVAL); > + } > + > + if (!rsc_da) > + /* no rsc table */ > + return ERR_PTR(-ENOENT); > + > + err = stm32_rproc_da_to_pa(rproc, rsc_da, &rsc_pa); > + if (err) > + return ERR_PTR(err); > + > + ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE); > + if (IS_ERR_OR_NULL(ddata->rsc_va)) { > + dev_err(dev, "Unable to map memory region: %pa+%zx\n", > + &rsc_pa, RSC_TBL_SIZE); > + ddata->rsc_va = NULL; > + return ERR_PTR(-ENOMEM); > + } > + > +done: > + /* Assuming the resource table fits in 1kB is fair */ > + *table_sz = RSC_TBL_SIZE; > + return (struct resource_table *)ddata->rsc_va; > +} > + > static const struct rproc_ops st_rproc_ops = { > .start = stm32_rproc_start, > .stop = stm32_rproc_stop, > @@ -554,6 +621,7 @@ static const struct rproc_ops st_rproc_ops = { > .load = rproc_elf_load_segments, > .parse_fw = stm32_rproc_parse_fw, > .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, > + .get_loaded_rsc_table = stm32_rproc_get_loaded_rsc_table, > .sanity_check = rproc_elf_sanity_check, > .get_boot_addr = rproc_elf_get_boot_addr, > }; > @@ -695,75 +763,6 @@ static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata, > return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state); > } > > -static int stm32_rproc_da_to_pa(struct platform_device *pdev, > - struct stm32_rproc *ddata, > - u64 da, phys_addr_t *pa) > -{ > - struct device *dev = &pdev->dev; > - struct stm32_rproc_mem *p_mem; > - unsigned int i; > - > - for (i = 0; i < ddata->nb_rmems; i++) { > - p_mem = &ddata->rmems[i]; > - > - if (da < p_mem->dev_addr || > - da >= p_mem->dev_addr + p_mem->size) > - continue; > - > - *pa = da - p_mem->dev_addr + p_mem->bus_addr; > - dev_dbg(dev, "da %llx to pa %#x\n", da, *pa); > - > - return 0; > - } > - > - dev_err(dev, "can't translate da %llx\n", da); > - > - return -EINVAL; > -} > - > -static int stm32_rproc_get_loaded_rsc_table(struct platform_device *pdev, > - struct rproc *rproc, > - struct stm32_rproc *ddata) > -{ > - struct device *dev = &pdev->dev; > - phys_addr_t rsc_pa; > - u32 rsc_da; > - int err; > - > - err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da); > - if (err) { > - dev_err(dev, "failed to read rsc tbl addr\n"); > - return err; > - } > - > - if (!rsc_da) > - /* no rsc table */ > - return 0; > - > - err = stm32_rproc_da_to_pa(pdev, ddata, rsc_da, &rsc_pa); > - if (err) > - return err; > - > - ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE); > - if (IS_ERR_OR_NULL(ddata->rsc_va)) { > - dev_err(dev, "Unable to map memory region: %pa+%zx\n", > - &rsc_pa, RSC_TBL_SIZE); > - ddata->rsc_va = NULL; > - return -ENOMEM; > - } > - > - /* > - * The resource table is already loaded in device memory, no need > - * to work with a cached table. > - */ > - rproc->cached_table = NULL; > - /* Assuming the resource table fits in 1kB is fair */ > - rproc->table_sz = RSC_TBL_SIZE; > - rproc->table_ptr = (struct resource_table *)ddata->rsc_va; > - > - return 0; > -} > - > static int stm32_rproc_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -803,10 +802,6 @@ static int stm32_rproc_probe(struct platform_device *pdev) > ret = stm32_rproc_parse_memory_regions(rproc); > if (ret) > goto free_resources; > - > - ret = stm32_rproc_get_loaded_rsc_table(pdev, rproc, ddata); > - if (ret) > - goto free_resources; > } > > rproc->has_iommu = false; >