From patchwork Wed Aug 31 20:50:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic PALLARDY X-Patchwork-Id: 9307825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B35F9607D2 for ; Wed, 31 Aug 2016 20:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5A272909A for ; Wed, 31 Aug 2016 20:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A5BC290B0; Wed, 31 Aug 2016 20:53:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C8E42909A for ; Wed, 31 Aug 2016 20:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753618AbcHaUxN (ORCPT ); Wed, 31 Aug 2016 16:53:13 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:5575 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933795AbcHaUwK (ORCPT ); Wed, 31 Aug 2016 16:52:10 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7VKpl8V021419; Wed, 31 Aug 2016 22:52:06 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 255bs839hr-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 31 Aug 2016 22:52:06 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3C26C31; Wed, 31 Aug 2016 20:52:06 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0D40550E2; Wed, 31 Aug 2016 20:52:06 +0000 (GMT) Received: from localhost (10.129.5.21) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.279.2; Wed, 31 Aug 2016 22:52:05 +0200 From: Loic Pallardy To: , , CC: , , , Subject: [PATCH v2 18/19] remoteproc: core: Add function to create remoteproc local resource table Date: Wed, 31 Aug 2016 22:50:21 +0200 Message-ID: <1472676622-32533-19-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1472676622-32533-1-git-send-email-loic.pallardy@st.com> References: <1472676622-32533-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.129.5.21] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-31_04:, , signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rproc driver has now the capability to add resources dynamically thanks to rproc_request_resource API. Depending on associated action, resource request could impact firmware resource table or define new local resource. In order to preserve current remoteproc resource handling mechanism, all local resources are gathered in a local resource table which won't be shared with firmware and proceed by remoteproc core as firmware one. It is rproc driver responsibility to provide the right resource information using rproc_request_resource API. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 80 +++++++++++++++++++++++++++++++++++- include/linux/remoteproc.h | 1 + 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index cbfbdf8..73b460a 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1270,6 +1270,65 @@ static int rproc_apply_resource_overrides(struct rproc *rproc, return ret; } +static struct resource_table* +rproc_local_resource_create(struct rproc *rproc, int *tablesz) +{ + struct fw_rsc_hdr *hdr; + struct fw_rsc_spare *spare_rsc; + struct rproc_request_resource *resource; + struct resource_table *table = NULL; + int size = 0, ret; + + /* compute total request size */ + list_for_each_entry(resource, &rproc->override_resources, node) { + if (resource->action == RSC_ACT_LOCAL) + size += resource->size + sizeof(hdr) + 4; /* entry offset */ + } + + /* any extra resource ? */ + if (!size) + goto out; + + /* add table header and spare resource */ + size += sizeof(*table); + size += sizeof(*hdr) + sizeof(*spare_rsc) + 4; + + /* create new rsc tbl with only a spare resource */ + table = devm_kzalloc(&rproc->dev, size, GFP_KERNEL); + if (!table) { + table = ERR_PTR(-ENOMEM); + goto out; + } + table->ver = 1; + table->num = 1; + table->offset[0] = sizeof(*table) + 4; + + hdr = (void *)table + table->offset[0]; + hdr->type = RSC_SPARE; + + spare_rsc = (void *)hdr + sizeof(*hdr); + spare_rsc->len = size - table->offset[0] - sizeof(*hdr) - sizeof(*spare_rsc); + + /* add new resource one by one */ + list_for_each_entry(resource, &rproc->override_resources, node) { + if (resource->action == RSC_ACT_LOCAL) { + /* Create a new enty */ + ret = __add_rsc_tbl_entry(rproc, resource, + table, size); + if (ret) { + table = ERR_PTR(ret); + goto out; + } + } + } + + *tablesz = size; + rproc_dump_resource_table(rproc, table, *tablesz); +out: + return table; +} + + /* * take a firmware and boot a remote processor with it. */ @@ -1278,7 +1337,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) struct device *dev = &rproc->dev; const char *name = rproc->firmware; struct resource_table *table, *loaded_table; - int ret, tablesz; + int ret, tablesz, local_tablesz; ret = rproc_fw_sanity_check(rproc, fw); if (ret) @@ -1335,6 +1394,11 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up; } + rproc->local_table = rproc_local_resource_create(rproc, &local_tablesz); + if (IS_ERR(rproc->local_table)) { + dev_err(dev, "Failed to create local resource table\n"); + goto clean_up; + } } /* reset max_notifyid */ @@ -1348,6 +1412,13 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up; } + ret = rproc_handle_resources(rproc, rproc->local_table, + local_tablesz, rproc_vdev_handler); + if (ret) { + dev_err(dev, "Failed to handle vdev resources: %d\n", ret); + goto clean_up; + } + /* handle fw resources which are required to boot rproc */ ret = rproc_handle_resources(rproc, rproc->cached_table, tablesz, rproc_loading_handlers); @@ -1356,6 +1427,13 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up; } + ret = rproc_handle_resources(rproc, rproc->local_table, + local_tablesz, rproc_loading_handlers); + if (ret) { + dev_err(dev, "Failed to handle vdev resources: %d\n", ret); + goto clean_up; + } + /* load the ELF segments to memory */ ret = rproc_load_segments(rproc, fw); if (ret) { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 2b0f1d7..653e6f3 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -495,6 +495,7 @@ struct rproc { int max_notifyid; struct resource_table *table_ptr; struct resource_table *cached_table; + struct resource_table *local_table; bool has_iommu; bool auto_boot; };