Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2288833pxu; Fri, 18 Dec 2020 09:36:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVQ/HQc2fj1h26uGEkeNygkM9ykDsWu94Bc32z3w79JuRj/gwyfVLkiY/G7LnF+/nfP6e8 X-Received: by 2002:a17:906:4443:: with SMTP id i3mr3590010ejp.133.1608312965600; Fri, 18 Dec 2020 09:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608312965; cv=none; d=google.com; s=arc-20160816; b=y/QpJQmUKneIcCeGJ/3iHUVXLQQG7KSlNi5K15sBrS/PpHK6zR4wbQ1gIAmXwuDuPL E5wi7IMV7STDt+E3WhnDOsqrFJy4A510JYvmxn/0LvCkyhuxevV4K0iqGtsORZ8hb3e7 IX4BfVA5OwACArFEqndxuBcw9OLSf9Sqc1/LGH5DfqVGCi6xRbV2MhUHeOBofLjzgO60 JWJqwYIEP8tSd/7hM8TUt5/MKiL02suDAHWPoQ1USZxt8TemNHIZdCRPxN8B8v2Kgfxh AK2XDqAYo0vh6yHpXtzoDmWd/zvxG15SwriojOaEFVUGPSfOzhLjVmSEtWsoBJkhp6ky QJwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g1R9Bq/TkbA5ZJxMb+U3jIOApLTRzPyrB4NxcI5os7I=; b=kuxH7LA6IIy9pRf3dBxZSMQk85w/ZrcgviUTtfm9rDrH2lDZ7mSll5awdSPW6tKygd ZpTa+P/82Ew4Om8ldgBHHe/yrKoGghtPlrO4rGM5wT27WF4FlzH8MfIkPr2g4Ws93Pb3 SoaZGVL6UuFVY6ASbDXPPy3ZEUM4nag/HzCM8d6QrahKyfH2EpoNGbPvmj76fqmAyVXG +iufaCpxYfqpZrde6qAxHdb6QTJFowAt8MAWEnrznCPJVidT97M26Mc0+5o/bVjejT7b /SEKa3o+NMvplrRsVzvJGhpgaAwdbbj5vlkLiFsWNTqlkFCMNKhd1OCFGCOrPRnJvQ2U cZOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t5wRCamd; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n14si6762699edq.574.2020.12.18.09.35.42; Fri, 18 Dec 2020 09:36:05 -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=@linaro.org header.s=google header.b=t5wRCamd; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732656AbgLRReE (ORCPT + 99 others); Fri, 18 Dec 2020 12:34:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732652AbgLRReD (ORCPT ); Fri, 18 Dec 2020 12:34:03 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA78C0619D7 for ; Fri, 18 Dec 2020 09:32:37 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id e2so1748856pgi.5 for ; Fri, 18 Dec 2020 09:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g1R9Bq/TkbA5ZJxMb+U3jIOApLTRzPyrB4NxcI5os7I=; b=t5wRCamddvBbP1gidIz9qVvy3YaRueHBIcG8WR00lGkn2knegTeSlgbq5QlaM7VMJl LoOcQJ9rLi7XcIKluTKzOBWvB1hklOY/sFX/Q3J/uw7FWs5W8/Pl0pQ1IW9/fTcqCEln shYK9ZwSWbc64d1k1i9JO20A3s6BI2f7vUguLJFLhOr5PphEUXj/CQTssw7iJenbu4+R kfo1qvB8GiDiswP8UJ++4LiEJN57I/QnT+PG+ymdOYwyIn/vegZrq8Awq2EeSvzj56qB JzirrUAxmQeRZyMUEIUxyfVmfkj7Wu6SkJ0vRdTStTB44T70QDag4kqfbJjc8wyPA+b+ XkbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g1R9Bq/TkbA5ZJxMb+U3jIOApLTRzPyrB4NxcI5os7I=; b=tTLE4WuyOQAly6qnwmUGpgv8J3fxwx/s+MUpcsz99yPw3TZrZKZQz21XzESrZ1KapR BhtDxAj3DqBYF7oUvAmUt52CG6fG6wpwSf+zjxeuTg9KR9WV2pR6o8Z4QBXSfRRlTp0o eLnkArAZgwf7D8+rAnVmdaJ8ey4tl4hY8D0cZKMrTIP7jbwTTKiEtjN3ehW0J7HlWtSY T4+MjFwtr5uEJklupbZE9cdAOvDjpFegaWbeA1LG9xkhI10rg19GwQ174a2qrNkr4XZo wxMiD/6uYi19vMlRzmazrW/ZhojP29C3TTDF3j67fyccriZQI8aEST2TzJH945aeI800 IkjA== X-Gm-Message-State: AOAM532J20ZLxCqka6T69laka++wxCo1oxTulLTVB2oIENauTmyH9hcn lqW1EQPNLw/0CartrzIykCYUPA== X-Received: by 2002:a63:5843:: with SMTP id i3mr849381pgm.209.1608312757099; Fri, 18 Dec 2020 09:32:37 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:36 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/17] remoteproc: stm32: Move resource table setup to rproc_ops Date: Fri, 18 Dec 2020 10:32:17 -0700 Message-Id: <20201218173228.2277032-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/remoteproc/stm32_rproc.c | 147 ++++++++++++++++--------------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index d2414cc1d90d..c635f746e44a 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -541,6 +541,79 @@ 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 int stm32_rproc_get_loaded_rsc_table(struct rproc *rproc) +{ + 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; + } + + if (!rsc_da) + /* no rsc table */ + return 0; + + err = stm32_rproc_da_to_pa(rproc, 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; + } + +done: + /* + * 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 struct rproc_ops st_rproc_ops = { .start = stm32_rproc_start, .stop = stm32_rproc_stop, @@ -549,6 +622,7 @@ static 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, }; @@ -692,75 +766,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; @@ -800,10 +805,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; -- 2.25.1