From patchwork Thu Nov 30 16:46:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic PALLARDY X-Patchwork-Id: 10085323 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 A21BF60586 for ; Thu, 30 Nov 2017 16:48:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 982272A220 for ; Thu, 30 Nov 2017 16:48:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D20C2A229; Thu, 30 Nov 2017 16:48:49 +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 12D702A227 for ; Thu, 30 Nov 2017 16:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753791AbdK3QrX (ORCPT ); Thu, 30 Nov 2017 11:47:23 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:59848 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753638AbdK3QrW (ORCPT ); Thu, 30 Nov 2017 11:47:22 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAUGiHCR001569; Thu, 30 Nov 2017 17:47:20 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2eexh9v2s6-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 30 Nov 2017 17:47:20 +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 47F3534; Thu, 30 Nov 2017 16:47:20 +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 2B245537A; Thu, 30 Nov 2017 16:47:20 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 30 Nov 2017 17:47:19 +0100 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH v2 12/16] remoteproc: look-up memory-device for vring allocation Date: Thu, 30 Nov 2017 17:46:47 +0100 Message-ID: <1512060411-729-13-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1512060411-729-1-git-send-email-loic.pallardy@st.com> References: <1512060411-729-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG7NODE2.st.com (10.75.127.20) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-30_05:, , 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 This patch parse existing carveout list to find a memory area matching on name. Naming rule for search is the following one: - "vdevvring" to find a memory pool dedicated to one vring belonging to one specific vdev (vdev_id). - "vdevvrings> to find common memory pool for allocation of all vrings belonging to one specific vdev (vdev_id). This allows to cover different SoC requirements like allocating vrings at best location taking into account access performance in read and write for master and slave processors. If memory area found, memory device will be used as device for vring allocation, else rproc platform device will be used as today. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 25 +++++++++++++++++++++++-- include/linux/remoteproc.h | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 8d990b1..6b5e2b2 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -410,8 +410,11 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) struct rproc_vring *rvring = &rvdev->vring[i]; struct fw_rsc_vdev *rsc; dma_addr_t dma = -1; + struct device *memdev = dev->parent; + struct rproc_mem_entry *carveout; void *va; int ret, size, notifyid; + char name[16]; /* actual size of vring (in bytes) */ size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); @@ -428,11 +431,27 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) return -ENOMEM; } } else { + /* Find any carveout matching vring */ + /* Try dedicated vdev j vring i pool. */ + snprintf(name, sizeof(name), "vdev%dvring%d", rvdev->index, i); + carveout = rproc_find_carveout_by_name(rproc, name); + + if (!carveout) { + /* Try dedicated vdev j vrings pool. */ + snprintf(name, sizeof(name), "vdev%dvring", rvdev->index); + carveout = rproc_find_carveout_by_name(rproc, name); + } + + if (carveout && carveout->memdev) + memdev = &carveout->memdev->dev; + + rvring->dev = memdev; + /* * Allocate non-cacheable memory for the vring. In the future * this call will also configure the IOMMU for us */ - va = dma_alloc_coherent(dev->parent, size, &dma, GFP_KERNEL); + va = dma_alloc_coherent(memdev, size, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, "dma_alloc_coherent failed\n"); return -EINVAL; @@ -455,7 +474,7 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) if (ret < 0) { dev_err(dev, "idr_alloc failed: %d\n", ret); if (dma != -1) - dma_free_coherent(dev->parent, size, va, dma); + dma_free_coherent(memdev, size, va, dma); return ret; } notifyid = ret; @@ -565,6 +584,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, struct device *dev = &rproc->dev; struct rproc_vdev *rvdev; int i, ret; + static int index; /* make sure resource isn't truncated */ if (sizeof(*rsc) + rsc->num_of_vrings * sizeof(struct fw_rsc_vdev_vring) @@ -596,6 +616,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, rvdev->id = rsc->id; rvdev->rproc = rproc; + rvdev->index = index++; /* parse the vrings */ for (i = 0; i < rsc->num_of_vrings; i++) { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index d7e7485..fb293d3 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -480,6 +480,7 @@ struct rproc_subdev { * @vq: the virtqueue of this vring */ struct rproc_vring { + struct device *dev; void *va; dma_addr_t dma; int len; @@ -507,6 +508,7 @@ struct rproc_vdev { struct rproc_subdev subdev; unsigned int id; + unsigned int index; struct list_head node; struct rproc *rproc; struct virtio_device vdev;