Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1449076ybz; Thu, 16 Apr 2020 09:20:31 -0700 (PDT) X-Google-Smtp-Source: APiQypI963zFUn0L/p48gvi9tz4kVJOkWG4dYGM4H25I+FUH+FG6QpnQ7nrGlepm+IUOwsrybsh2 X-Received: by 2002:aa7:c681:: with SMTP id n1mr30971645edq.83.1587054030921; Thu, 16 Apr 2020 09:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587054030; cv=none; d=google.com; s=arc-20160816; b=w+72Jc6rreCAE28HEgdMaMTUUloua6Qw1O/KBHr1YloGgyJ8yvb4n2lCc8fqKJnH8r LhdMGVut0ngv0Vtzq3KdcxrbPNwXxLcjONVzAf/f/aJx+9y+/YMa5FZI7xoSmfc/mVit PAUid9YB4N10XEfh435HQg4kpN7PxWIF6AfO4//NkY63vjAoIdmzB/J4uuXoW1k1PFTP ehVALHWVyRwVT6A5/JqgBf/Zui6o3ikjxVtNV4HDS/8DUY3xNfAlVnj4cEF5sLfwPiyj z82W/qM22XpHse7AZKkLDXjVIOPbdCxau4oBHcVk4eNlBz6bHitvFi//nnqcc9HuGUrJ 8HSA== 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:dkim-signature; bh=BnLDwpVavIoWUlJvnJXxlP7jRIgDXwSpYFB3LVEa9rQ=; b=DUUJ15OCgyLas6f6nM5FAOVFtcOJsLJ9Wx09dGL2lPqggvRmVyMN5xuEjzwq+0curG k0KkYSgl3ugKS646ZXEP39pZb20cxunbgTAy/gYG+iwp5rsrL+BAzCFd2Ssy4AgWj8HL 81ByZMp9SJutrC+h1NpO6QRLW/fn526c4U3UIMX3yaHxwz8d+9b3EuUgZcW4wQQR1XH5 DlfHoPpU0UN2TGs5IDsbYlIUuELPXFB5P0/yeICTpIqA9CoHF8Dba67Sg9PY4b2MeG/g +E/0JboorRSdTpzyh+6cGIqvBhr5ylRkz8RSqqBgV7g/SZ5CW/KlHpz3dxPFv64LhnPm FkKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=ae2jYbNB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s7si12857607edh.266.2020.04.16.09.20.07; Thu, 16 Apr 2020 09:20:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=ae2jYbNB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896799AbgDPQPg (ORCPT + 99 others); Thu, 16 Apr 2020 12:15:36 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:46871 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728958AbgDPQOZ (ORCPT ); Thu, 16 Apr 2020 12:14:25 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03GGCFia010372; Thu, 16 Apr 2020 18:14:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=BnLDwpVavIoWUlJvnJXxlP7jRIgDXwSpYFB3LVEa9rQ=; b=ae2jYbNByuYpMObCYUimmLeavvGxBYez7RROONuWOeoptsMV+WYpaitC94VTSA1y3zhC RwuXaysBQpUcXp7PhAbnmSQm7St8wlGXtpyP/ejn+VldOR7thWVEvwe4I1U9DluKoSxA NwGEzvYuvc1DoCVxwCIfbd6Nq8jz5exHcmISAMPAHEt2dPEu5WVAuVjvKuJW5f5BMHES tNxxZ/sWz37IlqVWa1B+IN/Z71zbW0UCDVaKMeH9yuL6hwjY1TdW6dmfsn74a+bo+N/f StEyjehyfpEmYMTEbTM2UU4db6cp9rOKaeb2tMrKDtyZ9YAAHIvRyNbBW5fbC325a0Aw mQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 30dn94kmvx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Apr 2020 18:14:20 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 06EEB10002A; Thu, 16 Apr 2020 18:14:20 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id ED8962B2D2A; Thu, 16 Apr 2020 18:14:19 +0200 (CEST) Received: from localhost (10.75.127.46) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 16 Apr 2020 18:14:19 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [RFC 09/18] remoteproc: Move vring management from core to virtio Date: Thu, 16 Apr 2020 18:13:22 +0200 Message-ID: <20200416161331.7606-10-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200416161331.7606-1-arnaud.pouliquen@st.com> References: <20200416161331.7606-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-16_06:2020-04-14,2020-04-16 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The vrings are correlated to the virtio implementation. Move following functions to rproc virtio: - rproc_alloc_vring - rproc_free_vring - rproc_parse_vring Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 97 ----------------------- drivers/remoteproc/remoteproc_internal.h | 4 - drivers/remoteproc/remoteproc_virtio.c | 98 ++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 101 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ac57cd8016be..c9e07c53ed0c 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -312,103 +312,6 @@ int rproc_check_carveout_da(struct rproc *rproc, } EXPORT_SYMBOL(rproc_check_carveout_da); -int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) -{ - struct rproc *rproc = rvdev->rproc; - struct device *dev = &rproc->dev; - struct rproc_vring *rvring = &rvdev->vring[i]; - struct fw_rsc_vdev *rsc; - int ret, size, notifyid; - struct rproc_mem_entry *mem; - - /* actual size of vring (in bytes) */ - size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); - - rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; - - /* Search for pre-registered carveout */ - mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, - i); - if (mem) { - if (rproc_check_carveout_da(rproc, mem, rsc->vring[i].da, size)) - return -ENOMEM; - } else { - /* Register carveout in in list */ - mem = rproc_mem_entry_init(dev, NULL, 0, - size, rsc->vring[i].da, - rproc_alloc_carveout, - rproc_release_carveout, - "vdev%dvring%d", - rvdev->index, i); - if (!mem) { - dev_err(dev, "Can't allocate memory entry structure\n"); - return -ENOMEM; - } - - rproc_add_carveout(rproc, mem); - } - - /* - * Assign an rproc-wide unique index for this vring - * TODO: assign a notifyid for rvdev updates as well - * TODO: support predefined notifyids (via resource table) - */ - ret = idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KERNEL); - if (ret < 0) { - dev_err(dev, "idr_alloc failed: %d\n", ret); - return ret; - } - notifyid = ret; - - /* Potentially bump max_notifyid */ - if (notifyid > rproc->max_notifyid) - rproc->max_notifyid = notifyid; - - rvring->notifyid = notifyid; - - /* Let the rproc know the notifyid of this vring.*/ - rsc->vring[i].notifyid = notifyid; - return 0; -} - -int rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i) -{ - struct rproc *rproc = rvdev->rproc; - struct device *dev = &rproc->dev; - struct fw_rsc_vdev_vring *vring = &rsc->vring[i]; - struct rproc_vring *rvring = &rvdev->vring[i]; - - dev_dbg(dev, "vdev rsc: vring%d: da 0x%x, qsz %d, align %d\n", - i, vring->da, vring->num, vring->align); - - /* verify queue size and vring alignment are sane */ - if (!vring->num || !vring->align) { - dev_err(dev, "invalid qsz (%d) or alignment (%d)\n", - vring->num, vring->align); - return -EINVAL; - } - - rvring->len = vring->num; - rvring->align = vring->align; - rvring->rvdev = rvdev; - - return 0; -} - -void rproc_free_vring(struct rproc_vring *rvring) -{ - struct rproc *rproc = rvring->rvdev->rproc; - int idx = rvring - rvring->rvdev->vring; - struct fw_rsc_vdev *rsc; - - idr_remove(&rproc->notifyids, rvring->notifyid); - - /* reset resource entry info */ - rsc = (void *)rproc->table_ptr + rvring->rvdev->rsc_offset; - rsc->vring[idx].da = 0; - rsc->vring[idx].notifyid = -1; -} - static int rproc_compare_of(struct device *dev, void *data) { if (dev->of_node) diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index f230296908ac..5139cca646ca 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -55,10 +55,6 @@ extern struct class rproc_class; int rproc_init_sysfs(void); void rproc_exit_sysfs(void); -int rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i); -void rproc_free_vring(struct rproc_vring *rvring); -int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); - void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); phys_addr_t rproc_va_to_pa(void *cpu_addr); int rproc_trigger_recovery(struct rproc *rproc); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index e1d7371d2d64..4634cd63d547 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -26,6 +26,104 @@ #include "remoteproc_internal.h" +static int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) +{ + struct rproc *rproc = rvdev->rproc; + struct device *dev = &rproc->dev; + struct rproc_vring *rvring = &rvdev->vring[i]; + struct fw_rsc_vdev *rsc; + int ret, size, notifyid; + struct rproc_mem_entry *mem; + + /* actual size of vring (in bytes) */ + size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); + + rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; + + /* Search for pre-registered carveout */ + mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, + i); + if (mem) { + if (rproc_check_carveout_da(rproc, mem, rsc->vring[i].da, size)) + return -ENOMEM; + } else { + /* Register carveout in in list */ + mem = rproc_mem_entry_init(dev, NULL, 0, + size, rsc->vring[i].da, + rproc_alloc_carveout, + rproc_release_carveout, + "vdev%dvring%d", + rvdev->index, i); + if (!mem) { + dev_err(dev, "Can't allocate memory entry structure\n"); + return -ENOMEM; + } + + rproc_add_carveout(rproc, mem); + } + + /* + * Assign an rproc-wide unique index for this vring + * TODO: assign a notifyid for rvdev updates as well + * TODO: support predefined notifyids (via resource table) + */ + ret = idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KERNEL); + if (ret < 0) { + dev_err(dev, "idr_alloc failed: %d\n", ret); + return ret; + } + notifyid = ret; + + /* Potentially bump max_notifyid */ + if (notifyid > rproc->max_notifyid) + rproc->max_notifyid = notifyid; + + rvring->notifyid = notifyid; + + /* Let the rproc know the notifyid of this vring.*/ + rsc->vring[i].notifyid = notifyid; + return 0; +} + +static int rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, + int i) +{ + struct rproc *rproc = rvdev->rproc; + struct device *dev = &rproc->dev; + struct fw_rsc_vdev_vring *vring = &rsc->vring[i]; + struct rproc_vring *rvring = &rvdev->vring[i]; + + dev_dbg(dev, "vdev rsc: vring%d: da 0x%x, qsz %d, align %d\n", + i, vring->da, vring->num, vring->align); + + /* verify queue size and vring alignment are sane */ + if (!vring->num || !vring->align) { + dev_err(dev, "invalid qsz (%d) or alignment (%d)\n", + vring->num, vring->align); + return -EINVAL; + } + + rvring->len = vring->num; + rvring->align = vring->align; + rvring->rvdev = rvdev; + + return 0; +} + +static void rproc_free_vring(struct rproc_vring *rvring) +{ + struct rproc *rproc = rvring->rvdev->rproc; + int idx = rvring - rvring->rvdev->vring; + struct fw_rsc_vdev *rsc; + + idr_remove(&rproc->notifyids, rvring->notifyid); + + /* reset resource entry info */ + rsc = (void *)rproc->table_ptr + rvring->rvdev->rsc_offset; + rsc->vring[idx].da = 0; + rsc->vring[idx].notifyid = -1; +} + /* kick the remote processor, and let it know which virtqueue to poke at */ static bool rproc_virtio_notify(struct virtqueue *vq) { -- 2.17.1