From patchwork Thu Mar 1 16:23:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 130325 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp3004854edc; Thu, 1 Mar 2018 08:24:57 -0800 (PST) X-Google-Smtp-Source: AG47ELszo2nqZTvcBVweMvGtlhIiveWeOlJeC7ZQCaI9M0XIm7G8ua8NR3uk5Q8YxhYb2FWdNZm6 X-Received: by 2002:a17:902:b416:: with SMTP id x22-v6mr2382070plr.279.1519921497720; Thu, 01 Mar 2018 08:24:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519921497; cv=none; d=google.com; s=arc-20160816; b=ssqfoH697btkUPD9ELUXIIwOuYPJhKEUks9JNUMQ9hiK5GvyAEPQUP5HSh9Gv6+nLc fLzfbSoqiIPpOfSKVcgzNio+ylTYms4cPsKT+a8r8ka/uExVLrYxFsQ7B7SGNW3+/H9L nWq6QjclQf5FMUIltWqCODi/mLSkD/6i6vsLHN37II7uIW0oDmGT3Fh0jfwVBzUd/oHk NTp0yKRBDvMkASkb9l4zYsveZr1djjTk5XQq8Fz56yI1eQPopMkADWKYhhMtuz4qqKVC sYlNuE59YHea4cg593rTbRtW4gPCK6RntbobXM8BhJEyqdgBLWW/ldpffOIdec6P8ots g7hg== 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=wCBahKe0nmd8eoP3kinO9cC25POc/aPO7+ODX/Ht5do=; b=w09q2zxQaVPm8KSz+E/7RhoV+hlluNMnfcn6bvwtssWri3RgO1cYdKfxymnSxiiLSv wNbbxA41JmOSAbiLmZsxAlIN4Lzd9O4Xv174TJ8eU0whRVWMLxKOKeEWcU99jhQCm9lv LE1WNdJSht0UFU03Nrb1jFZ4L9PEAAWhXtDUiDZl/s3+27IdF3yDVR9EchUPgzr5KxPM KRWxLJPJ700rPLnXnhSTd3/nOf1M6dWcNHpff/z7HSd+thhULXbuvQLQqZy3KOUWzlAZ /iaWLEU/K9kRoJl/OxpBwR1j28xxA/ec+N1w6OD1b6GszY5SyTl9mkSlGcejJEN/t2QA LTVA== 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 f18-v6si310931plr.726.2018.03.01.08.24.57; Thu, 01 Mar 2018 08:24:57 -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 S1033066AbeCAQYw (ORCPT + 28 others); Thu, 1 Mar 2018 11:24:52 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:6823 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032997AbeCAQYV (ORCPT ); Thu, 1 Mar 2018 11:24:21 -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 w21GIdON028249; Thu, 1 Mar 2018 17:24:19 +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 2gbwb1dpk2-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 01 Mar 2018 17:24:19 +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 AA74A31; Thu, 1 Mar 2018 16:24:18 +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 7E7E951FF; Thu, 1 Mar 2018 16:24:18 +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, 1 Mar 2018 17:24:17 +0100 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH v3 11/13] remoteproc: create vdev subdevice with specific dma memory pool Date: Thu, 1 Mar 2018 17:23:58 +0100 Message-ID: <1519921440-21356-12-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.49] X-ClientProxiedBy: SFHDAG5NODE2.st.com (10.75.127.14) 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 creates a dedicated vdev subdevice for each vdev declared in firmware resource table and associates carveout named "vdev%dbuffer" (with %d vdev index in resource table) if any as dma coherent memory pool. Then vdev subdevice is used as parent for virtio device. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 40 ++++++++++++++++++++++++++++++++++ drivers/remoteproc/remoteproc_virtio.c | 2 +- include/linux/remoteproc.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3041772..61c9927 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -427,8 +427,10 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, { struct device *dev = &rproc->dev; struct rproc_vdev *rvdev; + struct rproc_mem_entry *carveout; int i, ret; static int index; + char name[16]; /* make sure resource isn't truncated */ if (sizeof(*rsc) + rsc->num_of_vrings * sizeof(struct fw_rsc_vdev_vring) @@ -479,6 +481,41 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, goto unwind_vring_allocations; } + /* Initialise vdev subdevice */ + snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index); + rvdev->dev.parent = rproc->dev.parent; + dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name); + dev_set_drvdata(&rvdev->dev, rvdev); + dma_set_coherent_mask(&rvdev->dev, DMA_BIT_MASK(32)); + + ret = device_register(&rvdev->dev); + if (ret) + goto unwind_vring_allocations; + + /* Try to find dedicated vdev buffer carveout */ + carveout = rproc_find_carveout_by_name(rproc, name); + + if (carveout) { + phys_addr_t pa; + + if (carveout->va) { + dev_warn(dev, "vdev %d buffer carveout already mapped\n", + rvdev->index); + pa = rproc_va_to_pa(carveout->va); + } else { + /* Use dma address as carveout no memmapped yet */ + pa = (phys_addr_t)carveout->dma; + } + + /* Associate vdev buffer memory pool to vdev subdevice */ + ret = dmam_declare_coherent_memory(&rvdev->dev, pa, + carveout->da, + carveout->len, + DMA_MEMORY_EXCLUSIVE); + if (ret < 0) + goto unregister_device; + } + list_add_tail(&rvdev->node, &rproc->rvdevs); rproc_add_subdev(rproc, &rvdev->subdev, @@ -486,6 +523,9 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, return 0; +unregister_device: + put_device(&rvdev->dev); + unwind_vring_allocations: for (i--; i >= 0; i--) rproc_free_vring(&rvdev->vring[i]); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index b0633fd..f80014f 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -303,7 +303,7 @@ static void rproc_virtio_dev_release(struct device *dev) int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) { struct rproc *rproc = rvdev->rproc; - struct device *dev = &rproc->dev; + struct device *dev = &rvdev->dev; struct virtio_device *vdev = &rvdev->vdev; int ret; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 0c9d0f6..dfc44af7 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -518,6 +518,7 @@ struct rproc_vdev { struct kref refcount; struct rproc_subdev subdev; + struct device dev; unsigned int id; unsigned int index;