From patchwork Thu Aug 4 09:21:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 73253 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1290154qga; Thu, 4 Aug 2016 02:25:28 -0700 (PDT) X-Received: by 10.98.17.152 with SMTP id 24mr123897674pfr.13.1470302728718; Thu, 04 Aug 2016 02:25:28 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id x190si13784370pfd.105.2016.08.04.02.25.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 02:25:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bVEt7-0006X5-HU; Thu, 04 Aug 2016 09:24:25 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bVEri-0005PR-Sw for linux-arm-kernel@lists.infradead.org; Thu, 04 Aug 2016 09:23:01 +0000 Received: by mail-wm0-x234.google.com with SMTP id o80so370133452wme.1 for ; Thu, 04 Aug 2016 02:22:40 -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; bh=NUPO3Ou9+pa9DUaKqaRBxwL5ywzHgg2XCiDaTpUGfd4=; b=SEQdFlo3jmmD7T9V9a+qe+qfMSt0ZkDMOuFFrGo7eW0iAxSZb/s8SCMcVDTz8eUvoQ uA/JEh7mjQhs086yGECVmRgAfjaEIy+sqiUXQIscnSHwYkWAYV1eV75ZBxWp//5MhbAc WMZ2Jkeqi6Bpp0NMoM7dQIZTeREtYGIFdLIu0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NUPO3Ou9+pa9DUaKqaRBxwL5ywzHgg2XCiDaTpUGfd4=; b=QWNfBhCtm0NlxKEQUlGTb97tGoOmzbWJfCWocQ351EKJqKILUZTbJHLnfv4Mbi5yYW Pwn47NPdV0pvNM30/MdgQx7el/FiCDh8p+C3I8srbr6g+KR3cxkCjbo4p64w/14/+Mqt A2DOKZysQ7TQDSDIKnEXNIFr4QqmMf+9C685m9Wqi0ROY6fAgYBcQTDh2kqbstAI1kZ1 anU0VzTAVuwv/DTGFARaVSwrjsl7JhKKu2KEKCJhxxnKl1fVdsepryeYgnefLrR/GEcw 88rCZwMuGpqoRYVSRYM9ufiYjrIwvM5A2W0l0IWvpS7qWzMhg6mXSF4zypE9ADs5TENq ljYA== X-Gm-Message-State: AEkoouvP8qRjEp6aHM4HOm2nw5MsSOcTnsJmMfQO4n+QmCoKf8GVCTEf/+KaJGe9XiCWkkQ8 X-Received: by 10.28.171.214 with SMTP id u205mr51769970wme.97.1470302558920; Thu, 04 Aug 2016 02:22:38 -0700 (PDT) Received: from localhost.localdomain (host86-185-202-8.range86-185.btcentralplus.com. [86.185.202.8]) by smtp.gmail.com with ESMTPSA id d64sm2615461wmc.22.2016.08.04.02.22.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 02:22:38 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] remoteproc: core: Add function to append a new resource table entry Date: Thu, 4 Aug 2016 10:21:50 +0100 Message-Id: <20160804092153.23032-7-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160804092153.23032-1-lee.jones@linaro.org> References: <20160804092153.23032-1-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160804_022259_230014_1DD1C9F6 X-CRM114-Status: GOOD ( 14.30 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:234 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ohad@wizery.com, kernel@stlinux.com, loic.pallardy@st.com, linux-remoteproc@vger.kernel.org, patrice.chotard@st.com, bjorn.andersson@linaro.org, Lee Jones MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org A new function now exists to pull in and amend and existing resource table entry. But what if we wish to provide a new resource? This function provides functionality to append a brand new resource entry onto the resource table. All complexity related to shuffling parts of the table around, providing new offsets and incriminating number of entries in the resource table's top-level header is taken care of here. Signed-off-by: Lee Jones --- drivers/remoteproc/remoteproc_core.c | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) -- 2.9.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3318ebd..111350e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -980,6 +980,61 @@ static int rproc_update_resource_table_entry(struct rproc *rproc, return !updated; } +static struct resource_table* +rproc_add_resource_table_entry(struct rproc *rproc, + struct rproc_request_resource *request, + struct resource_table *old_table, int *tablesz) +{ + struct resource_table *table; + struct fw_rsc_hdr h; + void *new_rsc_loc; + void *fw_header_loc; + void *start_of_rscs; + int new_rsc_offset; + int size = *tablesz; + int i; + + h.type = request->type; + + new_rsc_offset = size; + + /* + * Allocate another contiguous chunk of memory, large enough to + * contain the new, expanded resource table. + * + * The +4 is for the extra offset[] element in the top level header + */ + size += sizeof(struct fw_rsc_hdr) + request->size + 4; + table = devm_kmemdup(&rproc->dev, old_table, size, GFP_KERNEL); + if (!table) + return ERR_PTR(-ENOMEM); + + /* Shunt table by 4 Bytes to account for the extra offset[] element */ + start_of_rscs = (void *)table + table->offset[0]; + memmove(start_of_rscs + 4, + start_of_rscs, new_rsc_offset - table->offset[0]); + new_rsc_offset += 4; + + /* Update existing resource entry's offsets */ + for (i = 0; i < table->num; i++) + table->offset[i] += 4; + + /* Update the top level 'resource table' header */ + table->offset[table->num] = new_rsc_offset; + table->num++; + + /* Copy new firmware header into table */ + fw_header_loc = (void *)table + new_rsc_offset; + memcpy(fw_header_loc, &h, sizeof(h)); + + /* Copy new resource entry into table */ + new_rsc_loc = (void *)fw_header_loc + sizeof(h); + memcpy(new_rsc_loc, request->resource, request->size); + + *tablesz = size; + return table; +} + /* * take a firmware and boot a remote processor with it. */