Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1685051ybz; Thu, 16 Apr 2020 13:39:43 -0700 (PDT) X-Google-Smtp-Source: APiQypJlDr6NgzUOfrE2OB8+UwFDazyqlXJqStL1VoHVh36ZcWQRO+fiE4dm8e88j5tjBRk+hJkV X-Received: by 2002:a05:6402:1619:: with SMTP id f25mr27370edv.201.1587069582859; Thu, 16 Apr 2020 13:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069582; cv=none; d=google.com; s=arc-20160816; b=NBHYMcnofqI5rbRTEITRN3cBTMBQg0IsXIt3lAVIUxTK3PjmyApWF/ZQZx1DS2KrAm pZwZMYcIEhaoZRhbMeZpw4Wx2L3xpKl/3G95H1LOvNTdw2GshpU6x8gS+6IHDDb7b10V Ov+ij0MmNAE6WLsOgJY8sZRGZmuPAcY7fwn1hwdj5QE8Bc9SbrPX1Zw6qF4/3mrCtj+I rLgM518sg8F2I7kfImjOgCRUp4MMVEGpE11VGou9mo2h4vdWZwDcnG3VTOapxSfz/f8X uezCuM4U6krPFQ5TmiktIN3SGbZ8e9XuZATPnYoz9iUG9fT2voO54KLaVmpnxXz+xPEi BYkQ== 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=Cwjql6eiDaqwrFTsuNZJ1xtw/Hxa6DOpsF+k+xk4lPI=; b=pTqcWfjfAcHnIPMMKEI/lWsgxiN9llAXRu1WkSHP5uBLw9ay0PnjGOdbPzxnNvmhGz RwipSTV1d+srAiSrChZOqJJRX6e3Juz4yelaYmWA2jmP1KJB4nbAb2s/iGVpP70p3x2F 0dd9a4jBZaq3noY26BKAySZ/aTWPrlJuDx1LFPs6p/0xB4ObSjzJnEI6uLWrGnLPBTfq TXWIcBaFk18rUqjwQEOQvo6lfasMYQeE/Yn5jxJmtrIyOCy1F2Fl4mwPdGcZZyvvTw33 3CXQAgvRTodK74FzjJ2xnzH3+Cu2dG8pB1C1yveMGDwrgGPzzJtNOXc4FflnmAALtH8D qKQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=wymU8dLC; 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 e16si12619053ejr.309.2020.04.16.13.39.19; Thu, 16 Apr 2020 13:39:42 -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=wymU8dLC; 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 S2636502AbgDPQO0 (ORCPT + 99 others); Thu, 16 Apr 2020 12:14:26 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:13624 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388004AbgDPQON (ORCPT ); Thu, 16 Apr 2020 12:14:13 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03GGDXZ7026476; Thu, 16 Apr 2020 18:14:09 +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=Cwjql6eiDaqwrFTsuNZJ1xtw/Hxa6DOpsF+k+xk4lPI=; b=wymU8dLCKivMPa2f4wr9o+F3jfZOuZGwt3XBEB49bakagWRP6/DY5v4nmbD6IcE350xz 2Y/oB+k4wulbye3TzvfHdtRsxtefARQhAeoRrW32rGq3d60318fF+tJ56LSSG8hM4s8t goIcUil5iIz2cwLccsCnUEsKghdWCJMjTdJBYni+IVk8ea7EiH0wuKbC8RUulpYmNf9l fwb97Wjz43656k/irklATGPOnjTdUivNiu6ePdDOA8Bj2OR4khR01oI4BkEnDMme3KQw Tl4Y4FZh9CWxj3i436F56fdqV6Bpebvx3wcmeS0nTBY2CV/aIdO1tl3CHwdUTIpZxk3M UA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 30dn8s3kky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Apr 2020 18:14:09 +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 1382B10002A; Thu, 16 Apr 2020 18:14:09 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 082A42B2D2A; Thu, 16 Apr 2020 18:14:09 +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:08 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [RFC 02/18] remoteproc: Introduce virtio device add/remove functions in core. Date: Thu, 16 Apr 2020 18:13:15 +0200 Message-ID: <20200416161331.7606-3-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: SFHDAG7NODE3.st.com (10.75.127.21) 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 In preparation of the migration of the management of rvdev in rproc_virtio, this patch spins off new functions to manage the virtio device. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 149 +++++++++++++++------------ 1 file changed, 83 insertions(+), 66 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 2a0425ab82a7..5c90d569c0f7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -441,6 +441,86 @@ static void rproc_rvdev_release(struct device *dev) kfree(rvdev); } +static int rproc_rvdev_add_device(struct rproc_vdev *rvdev) +{ + struct rproc *rproc = rvdev->rproc; + struct fw_rsc_vdev *rsc = rvdev->rsc; + char name[16]; + int ret, i; + + /* Initialise vdev subdevice */ + snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index); + rvdev->dev.parent = &rproc->dev; + rvdev->dev.dma_pfn_offset = rproc->dev.parent->dma_pfn_offset; + rvdev->dev.release = rproc_rvdev_release; + dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name); + dev_set_drvdata(&rvdev->dev, rvdev); + + ret = device_register(&rvdev->dev); + if (ret) { + put_device(&rvdev->dev); + return ret; + } + /* Make device dma capable by inheriting from parent's capabilities */ + set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent)); + + ret = dma_coerce_mask_and_coherent(&rvdev->dev, + dma_get_mask(rproc->dev.parent)); + if (ret) { + dev_warn(&rvdev->dev, + "Failed to set DMA mask %llx. Trying to continue... %x\n", + dma_get_mask(rproc->dev.parent), ret); + } + + /* parse the vrings */ + for (i = 0; i < rsc->num_of_vrings; i++) { + ret = rproc_parse_vring(rvdev, rsc, i); + if (ret) + goto free_rvdev; + } + + /* allocate the vring resources */ + for (i = 0; i < rsc->num_of_vrings; i++) { + ret = rproc_alloc_vring(rvdev, i); + if (ret) + goto free_vg; + } + + rvdev->subdev.start = rproc_vdev_do_start; + rvdev->subdev.stop = rproc_vdev_do_stop; + + rproc_add_subdev(rproc, &rvdev->subdev); + + return 0; + +free_vg: + for (i--; i >= 0; i--) { + struct rproc_vring *rvring = &rvdev->vring[i]; + + rproc_free_vring(rvring); + } + +free_rvdev: + device_unregister(&rvdev->dev); + + return ret; +} + +static void rproc_rvdev_remove_device(struct rproc_vdev *rvdev) +{ + struct rproc *rproc = rvdev->rproc; + struct rproc_vring *rvring; + int id; + + for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) { + rvring = &rvdev->vring[id]; + rproc_free_vring(rvring); + } + + rproc_remove_subdev(rproc, &rvdev->subdev); + device_unregister(&rvdev->dev); +} + /** * rproc_handle_vdev() - handle a vdev fw resource * @rproc: the remote processor @@ -473,8 +553,6 @@ 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; - char name[16]; /* make sure resource isn't truncated */ if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len > @@ -505,83 +583,22 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, kref_init(&rvdev->refcount); rvdev->rsc = rsc; + rvdev->rsc_offset = offset; rvdev->id = rsc->id; rvdev->rproc = rproc; rvdev->index = rproc->nb_vdev++; - /* Initialise vdev subdevice */ - snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index); - rvdev->dev.parent = rproc->dev.parent; - rvdev->dev.dma_pfn_offset = rproc->dev.parent->dma_pfn_offset; - rvdev->dev.release = rproc_rvdev_release; - dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name); - dev_set_drvdata(&rvdev->dev, rvdev); - - ret = device_register(&rvdev->dev); - if (ret) { - put_device(&rvdev->dev); - return ret; - } - /* Make device dma capable by inheriting from parent's capabilities */ - set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent)); - - ret = dma_coerce_mask_and_coherent(&rvdev->dev, - dma_get_mask(rproc->dev.parent)); - if (ret) { - dev_warn(dev, - "Failed to set DMA mask %llx. Trying to continue... %x\n", - dma_get_mask(rproc->dev.parent), ret); - } - - /* parse the vrings */ - for (i = 0; i < rsc->num_of_vrings; i++) { - ret = rproc_parse_vring(rvdev, rsc, i); - if (ret) - goto free_rvdev; - } - - /* remember the resource offset*/ - rvdev->rsc_offset = offset; - - /* allocate the vring resources */ - for (i = 0; i < rsc->num_of_vrings; i++) { - ret = rproc_alloc_vring(rvdev, i); - if (ret) - goto unwind_vring_allocations; - } - list_add_tail(&rvdev->node, &rproc->rvdevs); - rvdev->subdev.start = rproc_vdev_do_start; - rvdev->subdev.stop = rproc_vdev_do_stop; - - rproc_add_subdev(rproc, &rvdev->subdev); - - return 0; - -unwind_vring_allocations: - for (i--; i >= 0; i--) - rproc_free_vring(&rvdev->vring[i]); -free_rvdev: - device_unregister(&rvdev->dev); - return ret; + return rproc_rvdev_add_device(rvdev); } void rproc_vdev_release(struct kref *ref) { struct rproc_vdev *rvdev = container_of(ref, struct rproc_vdev, refcount); - struct rproc_vring *rvring; - struct rproc *rproc = rvdev->rproc; - int id; - - for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) { - rvring = &rvdev->vring[id]; - rproc_free_vring(rvring); - } - rproc_remove_subdev(rproc, &rvdev->subdev); + rproc_rvdev_remove_device(rvdev); list_del(&rvdev->node); - device_unregister(&rvdev->dev); } /** -- 2.17.1