Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp158243ybz; Fri, 24 Apr 2020 13:35:49 -0700 (PDT) X-Google-Smtp-Source: APiQypItdlVpi1hE/fYB/8bPeHDOnn4iKrLgMSyOFK2em/CnHMFObUDTgLHkE/MmBaxGQTtJzTQB X-Received: by 2002:aa7:c497:: with SMTP id m23mr8889109edq.155.1587760549169; Fri, 24 Apr 2020 13:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587760549; cv=none; d=google.com; s=arc-20160816; b=QgkbUiHcPdvYMcORXYH5ZCHpRn9MkS4H6z8HqZ91LoS7L7EkE02ur3ssiJECjc7h2C PULBW/uQawxIdT/eZfppW/U9ajbiwxWo1O+HRhmtnXb2MVfx/7k9ZPKvshOP2zKTWFhd 1OoYWtkUm3amcWc2bsmeE7XCrOq0uM/v4uV6+3EzakSlfEnFN+Bt+2rpBKDmFX97skSX Y8S3zBf1I+8oSpSjraXkJPysyUedcxg3TC7/M8z2/YnR0S7W9Ua3hyG3hRJ3wzWHnxnw eVpSlbbCX/9YAvXmKt6fdoQjDs3HC3XVxmhxV3TFyTS5gb64Q9ZODywoTKOvDGOljAvw rJKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b/9JpqDGNjADvobyqVov6ERIhhQq5sF+ThZw9VRS9LA=; b=i0yo1GA7lHAPFDcBhIpn8TWJrdXIcCxwYgc10AFEKu6t6YyAR+AOw7ZB/2K8EvhTav EwN3Nm09lZayYAZ10xMUBuD1xsBCU6IoH6ZyKWdSkYcTzAHrXHIyZQPsCOSplsPFBjuv AuNPF7nEAwYRWLPv5ABXh4tczEnvJ+CVlftI9ERiPepgOBfrBJcRK+mIG0/9h+fCzwZR rN+CtsXsVcgkDt1DrKWck3q5yr/Cp9zLli+oM8/yZv4Kk3l0PLIyc+528BLoBrwf11h8 QkaUDbtr6AwgCD/TblD5Uf8mHpYinSejSRPaOry1+ArW5ZNnmJhDHIEzJ9zr0WhNSx3T IQNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xQjAWYd1; 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 i63si3512631edd.601.2020.04.24.13.35.25; Fri, 24 Apr 2020 13:35:49 -0700 (PDT) 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=xQjAWYd1; 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 S1729539AbgDXUZV (ORCPT + 99 others); Fri, 24 Apr 2020 16:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729482AbgDXUZQ (ORCPT ); Fri, 24 Apr 2020 16:25:16 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D182C09B048 for ; Fri, 24 Apr 2020 13:25:16 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id q18so5140415pgm.11 for ; Fri, 24 Apr 2020 13:25:16 -0700 (PDT) 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=b/9JpqDGNjADvobyqVov6ERIhhQq5sF+ThZw9VRS9LA=; b=xQjAWYd18hiyO5V0QYqMaeY/LOdTA4JZkq26bNfHGDnNHufoeImakGwcRqMqD/UJ/i sdrA3YIk6Lfs+FNXCOoz3StXLJ4psRo+5Yh358CRePGLe7idf/RriCP5/ghspMrKrmeo T5vJhITHRiJoRuvvzHAzt6EOde+AQhFYK+U4Gb2HTyDwNV5NQdy9Iurcg1StWCblJt83 j8tWeyYw5FFZldBDlWNPMYpfW6rG+zP/mRhLcAAt9klkpEOfYlLcGkNTDK9ol2He5pM2 YMjoSOhkewz8RIFgQvMkUI9NmYLBU3RlG3KpqUH16yeJ0CnVEHCBEd4qinSRilbr0opl JxZA== 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=b/9JpqDGNjADvobyqVov6ERIhhQq5sF+ThZw9VRS9LA=; b=N+ECoBM28ujenVZz+mdWOrPGi4ktj3w/oKyi/YUGpbDCzycx7zTZSXSFZ5U5BMVESo W5jfT0E2NQdWF5OphQz1gRdZMjr0UIT7NSMwLw+7CVSz1rQBy2dwie3ShEw4TZF+/57H mfM95cbusrvwQ8SNHbZ/mx7OV0dI+rTeUCfzQjFwNPj4Eqmu+4rkJ+7Wv13o6iOk4ApS pgXmLn4ryNJvpYlS1IcsUyCytUP5FypmJVX3H80EpQtGXhttXrZb1pzyuT7QEQuA56Bb HY1C8AmvuYrSF5Kp7KeTJ2WlxVSHv0XQp831FnD6lCW/Q9hoGRmqJ6FgEVAdrIH0dNGQ OWSg== X-Gm-Message-State: AGi0PuaOCNu9FWEDaFMzqwzw7EMzgvxsOCyBw8pyGwxZaGiMAru2vBs/ T2RFOHw1aH8CRI4hD2+Jjidt92rfmYo= X-Received: by 2002:a63:b954:: with SMTP id v20mr10481894pgo.100.1587759915628; Fri, 24 Apr 2020 13:25:15 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id c1sm6553245pfc.94.2020.04.24.13.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 13:25:15 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com Cc: loic.pallardy@st.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/12] remoteproc: stm32: Get loaded resource table for synchronisation Date: Fri, 24 Apr 2020 14:25:00 -0600 Message-Id: <20200424202505.29562-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424202505.29562-1-mathieu.poirier@linaro.org> References: <20200424202505.29562-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Get the resource table location when synchronising with the M4 so that the remoteproc and rpmsg subsystem can be initialised properly. Mainly based on the work published by Arnaud Pouliquen [1]. [1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877 Signed-off-by: Mathieu Poirier Reviewed-by: Loic Pallardy --- drivers/remoteproc/stm32_rproc.c | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 89fbd2ffac93..8ba69e903851 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -87,6 +87,7 @@ struct stm32_rproc { struct stm32_mbox mb[MBOX_NB_MBX]; struct workqueue_struct *workqueue; bool secured_soc; + void __iomem *rsc_va; }; static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da) @@ -654,6 +655,65 @@ 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 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; + } + + return 0; +} + static int stm32_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -693,6 +753,12 @@ static int stm32_rproc_probe(struct platform_device *pdev) state = M4_STATE_OFF; } + if (state == M4_STATE_CRUN) { + ret = stm32_rproc_get_loaded_rsc_table(pdev, ddata); + if (ret) + goto free_rproc; + } + rproc->auto_boot = auto_boot; rproc->has_iommu = false; ddata->workqueue = create_workqueue(dev_name(dev)); -- 2.20.1