Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2551157pxb; Thu, 11 Feb 2021 15:52:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx22Btv+Pe8Qp8YfZKuTmEx7/FoI0EbLikVzgluve0rdAGyewF0DoRQr3/gzXWyt7pVKcEh X-Received: by 2002:a17:906:c010:: with SMTP id e16mr173882ejz.91.1613087554758; Thu, 11 Feb 2021 15:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613087554; cv=none; d=google.com; s=arc-20160816; b=HNlLEmqVTOFHCh0p76Z9HF4O0MXgBMkpmS8bUHYl9Bg7/zx8A9cnDbLg+3tWCaQali sZeVBoekniv5CDjpya6Y6sXSRejOKMk1AABXOKVBpzl86rOzjzP4POeRJhevU/6U8r5N ssHRvC8XaZA9Edj5gXggSq9t6e6OXz/jNCjNn8j1/Z/NCM9zzW3x0HkFKyvSqop2qpbt W+35w/glWJ5Hmydg+ucKVZ/dtB4IEZ2ncJePM9czpFl7y3xxfgtbmfTxwbNMU341TRlj QZ1VRsrAOs27/XJ5994A3kl3dZzk1VXkOgrIl5rqSquwa98k69KtQCEfz5yN1SwzQ4XN bciA== 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=tgj/edDkEdxRhIM+wgjO9M5oMofNW86OJezP/GK0ahs=; b=s41kuvhhO9R9tDArBafas8Fy1sRR6QTc1oeEm26moywW92WJCdVuJvgeeDIaGKoauC wiccEcMQ0i4/80Phzo7EviqeEGk1UVullqbjHCc4kZnUWntdT29KHYQzaX/9rG79KhmL hVnhby1SaEE8TKUGgGBYekU+GAUQjwUMyRWZQpo8+H9Gubk8NuwSxyd0se5I2Rd/O5Z0 Ov2I6UsUiEXQ6rAMey/acNzvar56w3edw+gsB3wJPuZ9Fbhjr+hLqjo3bfVCoshjyb0F +DY0nuyRjAPb/G9RdLQq03quipCtEPxEupd564tZuPkR4Qzlo6OKw4sDZ0lsyLTUoN5E m6Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tHoROy0Z; 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 gx20si4769823ejb.599.2021.02.11.15.52.11; Thu, 11 Feb 2021 15:52:34 -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=tHoROy0Z; 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 S230453AbhBKXur (ORCPT + 99 others); Thu, 11 Feb 2021 18:50:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbhBKXsY (ORCPT ); Thu, 11 Feb 2021 18:48:24 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B9BC061A28 for ; Thu, 11 Feb 2021 15:46:37 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id z6so4737980pfq.0 for ; Thu, 11 Feb 2021 15:46: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=tgj/edDkEdxRhIM+wgjO9M5oMofNW86OJezP/GK0ahs=; b=tHoROy0ZBJibDn2Qqw0ubJ5sF9B8braEhy6lRyzWgXr3EpwW0qQYoWp+Zbrht7G7uv 4cNiCfhTHwoV4givIOfoimydEvmIMyV4eJjHD6yDoNO2YDJaT3iZlr2fF/HJv59lP0y8 w2nEuhlU3Vf+iMOPH2CLHZebGHi00KdIGoCMas2RP6WifJdcObdP7Ib1FuU64SqvnSeH EGEyBmFuNQ46DgHbOd+crIbuvkIagiBxPseDjcdkyVGMuL/8cq3Qz3sM/iJ/ZGfONfMA /eUlZYGTNuh+WfzCohR4Adk9+Oih6wIJdaUUKyDzw3hMNGDRLuKJ8S6APfyZLpcdPfag 9gJw== 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=tgj/edDkEdxRhIM+wgjO9M5oMofNW86OJezP/GK0ahs=; b=RMDBPM6QE+edQJ5KHl4J+CZ1xuRlmySzEkhA/qdnmX7MBYCpVChyoSeRk6yUuM++fU uQBA8hyTojEPGqR+8kmvaYnvNaRrbK2vfme1mCWyjWBHQg5xJ0nMOYqjgzdsMSQjInE3 ATzWhbPGqyoGdK7dcQBvTYCj8KRuSjTiIzzpHUP3U3OmKg6sF7vlazmsOFFnEOw9/sUA fSBUKPytx+3PUqX7B/vUwk865IsdOkXQOaPz5CJsrSDtYs+GFMX8i4fWjdUbZLFcLYUj F8Ubudgt0uoeClPI1hBN+dlvzY5hOg8fMOhSvjTeaJB4zMvpdEB/wVmcStzDW+YKeXDF 3vPA== X-Gm-Message-State: AOAM5330AegxbyMrtcSZCzNLCXojP4IWEwxi3zLMcSmjMB03xc/li67v +q1YK5h+LtPJG3dI3T6F7p3xSQ== X-Received: by 2002:a63:347:: with SMTP id 68mr554653pgd.164.1613087196808; Thu, 11 Feb 2021 15:46:36 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id iq6sm5932740pjb.6.2021.02.11.15.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 15:46:36 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, arnaud.pouliquen@st.com Cc: robh+dt@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 08/19] remoteproc: stm32: Move resource table setup to rproc_ops Date: Thu, 11 Feb 2021 16:46:16 -0700 Message-Id: <20210211234627.2669674-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211234627.2669674-1-mathieu.poirier@linaro.org> References: <20210211234627.2669674-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 --- New for V5: - stm32_rproc_get_loaded_rsc_table() now returns a resource table pointer. --- 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 a180aeae9675..826cb7a045df 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -541,6 +541,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, @@ -549,6 +616,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, }; @@ -692,75 +760,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 +799,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