Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp33836pxb; Tue, 23 Feb 2021 17:09:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJye3hhve4owgQn/HqheyopfAf3Hx6qmgBcbma4n5yo94x8sp8Q+C21XN2cebwLRqCgnp7IA X-Received: by 2002:a17:906:33c5:: with SMTP id w5mr28901046eja.319.1614128984845; Tue, 23 Feb 2021 17:09:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614128984; cv=none; d=google.com; s=arc-20160816; b=wnUSKTxTnWgqYcc1qB1l6kQMOE6eMqYwZv1yP3JDXV9e7KEo17Cn8XKRpMrPx8hsJg 4Nn6L2n7C7vipkPtCd8RFmnaQHFzIgm+gSEw2YpiaJGNIuxJ1IEaGSK6cgL2jktJy3nM dYbwWnwkoEudPQCVUbuJKAQ+YivvM+MNTTNtA2NCTVLsaKhwgreHCD04S9Jt/Nx6Er6U Y1hm/EtBLDYE7lAGosgKyPv7QaxX5uP80xILUeqCG1w0m+iOu5189/S3uvuHdRwPnUzA BnfDBy4KQpf6VMlY18FuIETXJhLIaBOUWCCwi8QvBUY/YiI1DdzwT0Stqj6/mlJCY3y3 /ACQ== 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=kLNVNgyYcxdqJmRqLa5XNmkFnVZ2anTxOTUhUAuTSOQ=; b=bjLPVvykrPfX2boovTcV/P9h2HwrRoTN4l6Z15z11qmryQ1zAFm2IxQuNegFkpAhO4 NbZY3wHD8xjRMm3KTn5KUTBMeJUApDbJODrETHq7NUkxYC7q1j2TBXys4IQDJOSX0+jL DiTIdXW4e6QMC7rg/1mKFKaaUnsSH9p5sQ4DR/dI/E0hZFTR+4OENmjWycdnqsUg7kcN hRN/dMn/vw7WmNTtOI/2xCRuJJ8CzAhPH6rIjWytnptQNuV5kJ1p/wkNI4qDoMjkD1Io KO6/LX/5w22hUbdcSOFOHH1LichRFEzbFuUHThiI9NL7wz46jXyEOju8ld3+JWp2j11u qVEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=brMDm+Yr; 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 bf13si128925edb.426.2021.02.23.17.09.21; Tue, 23 Feb 2021 17:09:44 -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=brMDm+Yr; 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 S234567AbhBWXzr (ORCPT + 99 others); Tue, 23 Feb 2021 18:55:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233360AbhBWXim (ORCPT ); Tue, 23 Feb 2021 18:38:42 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A23F3C061356 for ; Tue, 23 Feb 2021 15:35:23 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id q20so46317pfu.8 for ; Tue, 23 Feb 2021 15:35:23 -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=kLNVNgyYcxdqJmRqLa5XNmkFnVZ2anTxOTUhUAuTSOQ=; b=brMDm+YrllAIy0EMAf2YORgbS5YJdVihgVpAn6zkEHPcvFsvCLQbdW4rUSoPnXSvQz fKWAflTzrm0ayYjtPn7Wy4VR/HpOqdEMBi96b25w0OYij6xf4HxcFvlB2ecfCLq/0OD2 DRIrKrm9U6pn0o2UwM0OYDuKZ8rrxZ7PQHEBf2ft/91VsCA5GerXag0jXc6tuK0m3pT3 ROA/3aNyTah8Hy6uxzh1RstKCxez0E6YFbY02KsvkKMtjZEeXJ6NQtO0u8bJuSNgQd8i QLalzEj82IkAmZ4/PPXp4yw0OoVwNPsic7z5Jp0wcec10stReoI5zKlkbAyk6dnhJ+xc Iwjw== 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=kLNVNgyYcxdqJmRqLa5XNmkFnVZ2anTxOTUhUAuTSOQ=; b=qaFAoff0FnvhSLfeftqbCq5XyjDlPmyywaJN2/0GLBh0jmTSW3bS2VM3g5jzRCr449 7uRtALFR/DMFv5fUhE4OR4O2DnrM9uP5UKhfBdYphvRsBj/9mHwZNk7VcAEA8RjPQntu gZI2UJ2l/2/J7xZy65cMNiC5YReCq5NXJjeJRemFf5PVGFM+eGCVtwabFzKLD+27G1p5 zJsp80DGzHavi+pP4zPBWH2UgsNGrURQkqmc0tLo6vN0AoE5998fF2kYhrh3mdoxUKc0 lKhaS37iKS+ou2om76hUw8p1xKM7k/2o1M0jZ/NAM25f/kFkbMkZShm95PSN0J8tXyik fKVA== X-Gm-Message-State: AOAM5337UEnwggst6ohmSQhuKJSylwu4kgAsnbEdhy3lTcq8aJ9QgABp U+NOcsPpKPBAG8hEwR0ACzbwpg== X-Received: by 2002:a63:5a02:: with SMTP id o2mr15912066pgb.202.1614123323178; Tue, 23 Feb 2021 15:35:23 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id c24sm311999pfd.11.2021.02.23.15.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 15:35:22 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, arnaud.pouliquen@st.com Cc: mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 06/16] remoteproc: stm32: Move resource table setup to rproc_ops Date: Tue, 23 Feb 2021 16:35:05 -0700 Message-Id: <20210223233515.3468677-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210223233515.3468677-1-mathieu.poirier@linaro.org> References: <20210223233515.3468677-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 | 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; -- 2.25.1