From patchwork Thu Mar 1 16:23:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 130327 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp3005513edc; Thu, 1 Mar 2018 08:25:33 -0800 (PST) X-Google-Smtp-Source: AG47ELusFbB/n5VZZTAj/9EFhHPXnlb2I0Bz+DHp9YKc05i0K1MMzRTJR4SxHrpqb+moyGB35hPy X-Received: by 10.99.184.1 with SMTP id p1mr1981685pge.96.1519921533271; Thu, 01 Mar 2018 08:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519921533; cv=none; d=google.com; s=arc-20160816; b=crn8F6r61ug+ujLopmb2r9gn8Tsh5JkrvRYmqtfNDBv9JGoW3sFR0ZKD15+QgxmguZ JkRJ0khNjY48KVGUhSyxFMtbdeiXXmQ5g6mRUep2VGyDnhUBsVndLoSb9tKwsWqunkSW D+2+08VD6z0hkzf8AGbOAAEYkaWiXdDNThVWDQu2QSYWAzCUs22+9+FuqkINnzr030i/ q0Xbg0QX+A2XaiyE/LU1SX9E0gzJVp6yF9/UpntTHYtyJghx1wIFDnaGjCu36TqhzGBr Af4Cy9znEWcTl6m79J1bZMOJFdG5XL8YYjKNZGNlRpO3Tkdtl79sOFdXzyIRUm2upBlO 1eAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=wgXwVSprgxIijd2eNwTQQiKzFbY+nfes5BLDt6RAEh8=; b=Q2el1VnrB2+Gf93aCE2IXf56kIXZAbV7YFolGcuX9AC3jdHCyGI4BYmYo4A4od3XDT 2FAiWyzpNM7Rc5hCzaVyYGVBuTZMhvKIcqPuzmBJCz/WDTvx3CnNyLnf0nedE8GKJeMb dKclIRpzZ4ERCpMWA3gR/hxkxJ0PZaqqrU5kwl/3ATieo/QgyZJjOKnZfKjc1m1je4RK vVxFH53njTIzusxgBPSmEcjBaqMooa/rmfOW/TcP2c5h5Q3fOs630x2FjmPa1xrOPeUb IJj1Vmg1CK43MKgmtOCl3nZOofabJmLOvFRTF56Y+h8T0EnQvXNMe/0eNPVSWyOAi7g0 WSog== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v61-v6si3245065plb.698.2018.03.01.08.25.33; Thu, 01 Mar 2018 08:25:33 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033009AbeCAQYV (ORCPT + 28 others); Thu, 1 Mar 2018 11:24:21 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:15371 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032974AbeCAQYQ (ORCPT ); Thu, 1 Mar 2018 11:24:16 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w21GIeV6028256; Thu, 1 Mar 2018 17:24:14 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2gbwb1dpjr-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 01 Mar 2018 17:24:14 +0100 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 30BDE34; Thu, 1 Mar 2018 16:24:14 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0FF1F51FF; Thu, 1 Mar 2018 16:24:14 +0000 (GMT) Received: from localhost (10.75.127.45) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 1 Mar 2018 17:24:13 +0100 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH v3 05/13] remoteproc: add helper function to allocate and init rproc_mem_entry struct Date: Thu, 1 Mar 2018 17:23:52 +0100 Message-ID: <1519921440-21356-6-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519921440-21356-1-git-send-email-loic.pallardy@st.com> References: <1519921440-21356-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-01_08:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces rproc_mem_entry_init helper function to simplify rproc_mem_entry structure allocation and filling by client. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 64 +++++++++++++++++++++++++++--------- include/linux/remoteproc.h | 5 +++ 2 files changed, 53 insertions(+), 16 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index f73a0cf..4c92b7d 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -636,7 +636,7 @@ static int rproc_handle_carveout(struct rproc *rproc, struct fw_rsc_carveout *rsc, int offset, int avail) { - struct rproc_mem_entry *carveout, *mapping; + struct rproc_mem_entry *carveout, *mapping = NULL; struct device *dev = &rproc->dev; dma_addr_t dma; void *va; @@ -656,16 +656,11 @@ static int rproc_handle_carveout(struct rproc *rproc, dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); - carveout = kzalloc(sizeof(*carveout), GFP_KERNEL); - if (!carveout) - return -ENOMEM; - va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, "failed to allocate dma memory: len 0x%x\n", rsc->len); - ret = -ENOMEM; - goto free_carv; + return -ENOMEM; } dev_dbg(dev, "carveout va %p, dma %pad, len 0x%x\n", @@ -744,27 +739,64 @@ static int rproc_handle_carveout(struct rproc *rproc, */ rsc->pa = (u32)rproc_va_to_pa(va); - carveout->va = va; - carveout->len = rsc->len; - carveout->dma = dma; - carveout->da = rsc->da; - carveout->release = rproc_release_carveout; - strlcpy(carveout->name, rsc->name, sizeof(carveout->name)); + carveout = rproc_mem_entry_init(dev, va, dma, rsc->len, rsc->da, + rproc_release_carveout, rsc->name); + if (!carveout) + goto free_carv; list_add_tail(&carveout->node, &rproc->carveouts); return 0; +free_carv: + kfree(carveout); free_mapping: kfree(mapping); dma_free: dma_free_coherent(dev->parent, rsc->len, va, dma); -free_carv: - kfree(carveout); return ret; } -/* +/** + * rproc_mem_entry_init() - allocate and initialize rproc_mem_entry struct + * @dev: pointer on device struct + * @va: virtual address + * @dma: dma address + * @len: memory carveout length + * @da: device address + * @release: memory carveout function + * @name: carveout name + * + * This function allocates a rproc_mem_entry struct and fill it with parameters + * provided by client. + */ +struct rproc_mem_entry *rproc_mem_entry_init(struct device *dev, + void *va, dma_addr_t dma, int len, u32 da, + int (*release)(struct rproc *, struct rproc_mem_entry *), + const char *name, ...) +{ + struct rproc_mem_entry *mem; + va_list args; + + mem = devm_kzalloc(dev, sizeof(*mem), GFP_KERNEL); + if (!mem) + return ERR_PTR(-ENOMEM); + + mem->va = va; + mem->dma = dma; + mem->da = da; + mem->len = len; + mem->release = release; + + va_start(args, name); + snprintf(mem->name, sizeof(mem->name), name, args); + va_end(args); + + return mem; +} +EXPORT_SYMBOL(rproc_mem_entry_init); + +/** * A lookup table for resource handlers. The indices are defined in * enum fw_resource_type. */ diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 2202c08..59b60f1 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -536,6 +536,11 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, int rproc_del(struct rproc *rproc); void rproc_free(struct rproc *rproc); +struct rproc_mem_entry *rproc_mem_entry_init(struct device *dev, + void *va, dma_addr_t dma, int len, u32 da, + int (*release)(struct rproc *, struct rproc_mem_entry *), + const char *name, ...); + int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);