From patchwork Wed Dec 13 22:41:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 121865 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6063496qgn; Wed, 13 Dec 2017 14:41:27 -0800 (PST) X-Google-Smtp-Source: ACJfBovU5oyVsfvtMuxjdhdu680qe8hJyp/8H3cg7svhGI4vz03A4jKvG6wGnsxC/b+qq+l/wDiK X-Received: by 10.101.88.76 with SMTP id s12mr6720838pgr.215.1513204887603; Wed, 13 Dec 2017 14:41:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513204887; cv=none; d=google.com; s=arc-20160816; b=hGgy4kgtweV8sTkeLkFCOikoNoTvnbMs9Of+x54kPH+W36hLodmCfI8moHH5oD+btl u8L1eFHDoeMG36xcHMbQxaLbmWsAOwN7Mj+PWw3a3V8L/r6ydHByphnMc8asuTPavFfa U1oT2InsHBr9UDSFbjVGVe/+VmXXWidltgnCV1uEDtpZ4HGjTCR8Bx2h2HLsdDACQyo1 1Zk29OffqN5B6oGyqyceB4ZGcyKMfFMXTgjfqJHq+z21/2kvBlpjmghCXmxNGxt2ogrq OfJdMEt1JrySAae3snaIhAItor9GvN2xiZKzCYmZA8QnK9twixFpqeXhUg6g4D3kNt0R zZmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vybEUD2Ym1nB0jZPhcn21y0tKF2tB8Iopk+yfmykgkg=; b=pk+rTi1GG8ISBwCy47UJ/Fl9DokcPaunXSfY8G+1xlwmQV4kIdsh0xCOxWy/7Av1Ty yWMarYYwrk1za2EhcmBEYorVbV8Iq1joGg7+x5u3Dq0GiUv8Imzi8taYvo+3vaKNK8D9 g0ISxPckIzPzxFG9ZFPP3WSv+eJuyuIx+q57v2V+ZkkEBVX6S6WkBp76k0ivbpmlElAZ UfxT9S73auFfiUB8ztpKap3Eow/saWFcP6teSyfZ9D32LO/2W41871AjwqPpw0zuSvm0 taybmsz0/2X6rtcbWCaet6P3+/3y/bgQh0qvINhE1zMrjL4zMGIpSNtayuwI2ZMC5+X5 P1wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=huInVnI+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id s189si1914114pgc.225.2017.12.13.14.41.27; Wed, 13 Dec 2017 14:41:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=huInVnI+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1752903AbdLMWlV (ORCPT + 23 others); Wed, 13 Dec 2017 17:41:21 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:36890 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752805AbdLMWlT (ORCPT ); Wed, 13 Dec 2017 17:41:19 -0500 Received: by mail-pg0-f68.google.com with SMTP id y6so2060493pgp.4 for ; Wed, 13 Dec 2017 14:41:18 -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; bh=vybEUD2Ym1nB0jZPhcn21y0tKF2tB8Iopk+yfmykgkg=; b=huInVnI+4EV5qbFVx5QCaNXZbbwAAgdqvG9uBPbRTYaoZPpHtrjQm5jkmtghTOMjgA oSZTfieB/inWce3L8HpaVCV1Z/sjEzNheHl9pMw9SS4g3jdJZhbVD9tXxH0XeWci84I1 TV4P13p0IBmE1AUoEsOGu7nZt0dsxnSoJpDLY= 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; bh=vybEUD2Ym1nB0jZPhcn21y0tKF2tB8Iopk+yfmykgkg=; b=jrkUn69sVQ/HzQlXra0JcA3p6wRGFtfdIAH/FDgDjZjEMrBCvwo3LjLtIydPgj57om x09iMnZLHxmU4PiWlhLCs8hEHFN0FUcC0mzxDt220hLNyNAeMMU+M80oIt0LAUf2BoNg NkFyq0q2gJi/01REvdR1gm7kcdWq8aFoGPXDvqKEoi2+QTOi6bfVdOH9CD2AiHJMyAEv rv/Jyc3Fm6MAP/VWq93ZTEAXPxNMblxwFUeG6GgtKrdlYdmAptmMTgrD8pqd2MeZh2D0 3GCFX34/Imd7D3wBF5txxhU9U0hNjnkPHTUKDW5D80sKpsjgOWh8IldHMv4flbznoZzD y3OA== X-Gm-Message-State: AKGB3mIAg0TAmmgYTdvM/JXyMpbY62ZetfxCu4gc8HGuN/DwP0G5195/ 4Jv5fT9THzeBl1wW5hfdN4yrm93Otww= X-Received: by 10.98.89.220 with SMTP id k89mr7590119pfj.36.1513204878300; Wed, 13 Dec 2017 14:41:18 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id x15sm4464205pfh.27.2017.12.13.14.41.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Dec 2017 14:41:17 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] remoteproc: Cache resource table size Date: Wed, 13 Dec 2017 14:41:05 -0800 Message-Id: <20171213224111.17864-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171213224111.17864-1-bjorn.andersson@linaro.org> References: <20171213224111.17864-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't re-read the resource table during a recovery, so it is possible in the recovery path that the resource table has a different size than cached_table. Store the original size of cached_table to avoid these getting out of sync. Signed-off-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 20 +++++++------------- include/linux/remoteproc.h | 2 ++ 2 files changed, 9 insertions(+), 13 deletions(-) -- 2.15.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 15e2c4530a0a..761268096fe0 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -732,7 +732,7 @@ static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = { }; /* handle firmware resource entries before booting the remote processor */ -static int rproc_handle_resources(struct rproc *rproc, int len, +static int rproc_handle_resources(struct rproc *rproc, rproc_handle_resource_t handlers[RSC_LAST]) { struct device *dev = &rproc->dev; @@ -742,7 +742,7 @@ static int rproc_handle_resources(struct rproc *rproc, int len, for (i = 0; i < rproc->table_ptr->num; i++) { int offset = rproc->table_ptr->offset[i]; struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; - int avail = len - offset - sizeof(*hdr); + int avail = rproc->table_sz - offset - sizeof(*hdr); void *rsc = (void *)hdr + sizeof(*hdr); /* make sure table isn't truncated */ @@ -849,16 +849,9 @@ static void rproc_resource_cleanup(struct rproc *rproc) static int rproc_start(struct rproc *rproc, const struct firmware *fw) { - struct resource_table *table, *loaded_table; + struct resource_table *loaded_table; struct device *dev = &rproc->dev; - int ret, tablesz; - - /* look for the resource table */ - table = rproc_find_rsc_table(rproc, fw, &tablesz); - if (!table) { - dev_err(dev, "Resource table look up failed\n"); - return -EINVAL; - } + int ret; /* load the ELF segments to memory */ ret = rproc_load_segments(rproc, fw); @@ -877,7 +870,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) */ loaded_table = rproc_find_loaded_rsc_table(rproc, fw); if (loaded_table) { - memcpy(loaded_table, rproc->cached_table, tablesz); + memcpy(loaded_table, rproc->cached_table, rproc->table_sz); rproc->table_ptr = loaded_table; } @@ -951,12 +944,13 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up; rproc->table_ptr = rproc->cached_table; + rproc->table_sz = tablesz; /* reset max_notifyid */ rproc->max_notifyid = -1; /* handle fw resources which are required to boot rproc */ - ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers); + ret = rproc_handle_resources(rproc, rproc_loading_handlers); if (ret) { dev_err(dev, "Failed to process resources: %d\n", ret); goto clean_up_resources; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 2d1058111e57..b72be13d773d 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -410,6 +410,7 @@ enum rproc_crash_type { * @max_notifyid: largest allocated notify id. * @table_ptr: pointer to the resource table in effect * @cached_table: copy of the resource table + * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU */ struct rproc { @@ -440,6 +441,7 @@ struct rproc { int max_notifyid; struct resource_table *table_ptr; struct resource_table *cached_table; + size_t table_sz; bool has_iommu; bool auto_boot; };