Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp3873151ima; Tue, 23 Oct 2018 12:41:17 -0700 (PDT) X-Google-Smtp-Source: AJdET5fFKc3zxxDRqlZMRXLAI/P5PUl8630fMcNcsgG8RKr+ehqcK04TgQc64qocOHKBsOta9rnc X-Received: by 2002:a17:902:aa09:: with SMTP id be9-v6mr13537812plb.255.1540323677412; Tue, 23 Oct 2018 12:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540323677; cv=none; d=google.com; s=arc-20160816; b=bVt6BHXnRV9d2UV1TE0cAkEcD6BJhwfrZ+BQQqwH7lb8Qdykj5UBinLVI18uMN3Sue CHwoWKe1fmo/R85DzQlTnjXQEqytxFQAEm+BvUI3mrzv0rQYot3/E8HXiSsZhr8gzKY+ fJ8AsRmi8mHFyL+ZHbi+UtWAs9vZP0U9NhjxnKSAs+oVnYStlnPm9Po2zMNlVWrLUrCp cUChjgtz+b/QT1Od8uNywKlt2GcKRwGi0nkcWVOLUf49OHyGgDu69LddT4m1OQprSsYy p6Gzl9Yt75l6bq1IBiKfIQhJr0pXb1WWsbFsjIz6iCL2u+FkZLLOtajzLEtiQZyyf/r+ hniw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ZE4TrxNLcDxi3S6X+ZvK4bpQAk3fgatJoVLMnMqF3Fk=; b=J9cF8J5QZGwB2rxOOeE4b9kS8t966j676/fpF9qoTJB3INQBNKayr1dsR3Ua9VPyl7 bbXR/rck2pWENRm3Kk4JOJnIIGC/UBvH5V7AKHed9IAzQ2nG563ciIOGO8UbJRJX2gtK b43fwTwm/QwuTEn55S/9lJuyfL617QQZtQNA8Xm1XpyMx76b4lzAMNawayz9Row6uIFl 3HYFnie304Z0rLO1oAB6DrbewWWcl557ZlM2FKIbEkcuw0tEEOQAoTQ68xXDMJHBJ+rF 6PxgPqySPeh63SDWZJyXJaOma7N74oCi0N28RfJMGgBfCW9Y4qPfZyaas8VcR8VheOdr WFyQ== 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si2226259pln.388.2018.10.23.12.41.00; Tue, 23 Oct 2018 12:41:17 -0700 (PDT) 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728687AbeJXDs5 (ORCPT + 99 others); Tue, 23 Oct 2018 23:48:57 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:56436 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727758AbeJXDs5 (ORCPT ); Tue, 23 Oct 2018 23:48:57 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id w9NJO9VH099669; Tue, 23 Oct 2018 14:24:09 -0500 Received: from DFLE111.ent.ti.com (dfle111.ent.ti.com [10.64.6.32]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id w9NJO94B036916 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Oct 2018 14:24:09 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 23 Oct 2018 14:24:08 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Tue, 23 Oct 2018 14:24:08 -0500 Received: from [128.247.58.153] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w9NJO81n002264; Tue, 23 Oct 2018 14:24:08 -0500 Subject: Re: [PATCH v4 05/17] remoteproc: add helper function to allocate and init rproc_mem_entry struct To: Loic Pallardy , , CC: , , , References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> <1532697292-14272-6-git-send-email-loic.pallardy@st.com> From: Suman Anna Message-ID: <12b7cb33-279d-1e6e-28b5-cddf3f43d0e9@ti.com> Date: Tue, 23 Oct 2018 14:24:08 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1532697292-14272-6-git-send-email-loic.pallardy@st.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/27/18 8:14 AM, Loic Pallardy wrote: > 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 Reviewed-by: Suman Anna > --- > drivers/remoteproc/remoteproc_core.c | 65 +++++++++++++++++++++++++++--------- > include/linux/remoteproc.h | 6 ++++ > 2 files changed, 55 insertions(+), 16 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index d7e3138..b76760e 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -639,7 +639,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; > @@ -659,16 +659,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 %pK, dma %pad, len 0x%x\n", > @@ -747,27 +742,65 @@ 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 = kzalloc(sizeof(*mem), GFP_KERNEL); > + if (!mem) > + return mem; > + > + mem->va = va; > + mem->dma = dma; > + mem->da = da; > + mem->len = len; > + mem->release = release; > + > + va_start(args, name); > + vsnprintf(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 0e21098..4bc961f 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -558,6 +558,12 @@ 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); >