From patchwork Thu Oct 20 02:40:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 78381 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp560524qge; Wed, 19 Oct 2016 19:40:58 -0700 (PDT) X-Received: by 10.98.158.91 with SMTP id s88mr16929990pfd.107.1476931258742; Wed, 19 Oct 2016 19:40:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si39636407pgc.26.2016.10.19.19.40.58; Wed, 19 Oct 2016 19:40:58 -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; dkim=pass header.i=@linaro.org; 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=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933993AbcJTCkj (ORCPT + 27 others); Wed, 19 Oct 2016 22:40:39 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:35117 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933871AbcJTCka (ORCPT ); Wed, 19 Oct 2016 22:40:30 -0400 Received: by mail-pf0-f174.google.com with SMTP id s8so26524042pfj.2 for ; Wed, 19 Oct 2016 19:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GmsEfzeqbwbSKQTn5qtkU0kjEigXM6cSOwev7qCnJd8=; b=ipEBPiDZYgSIReoK83b+LmjXYFwF+054Yb0yq28B2SGMUP7QXcb2YY03WLxYsFc99y 0jSuzv/GkCyn9G+nkMhodHRYTOpRCGWKoEVZjF0YlxhO1FjRVSJTeXYVp+RBK0qqaN4R /ZaUtG1qxjK+/Q8m5JHvCyfnwHbM9c1DXYspg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GmsEfzeqbwbSKQTn5qtkU0kjEigXM6cSOwev7qCnJd8=; b=QciP5ABmasDM2avIlm8UULtF5JRzqWTvCqsscxY3QKv2I/FoVt+kzN3ZqGtu9Dh9Gf 2tMZXO5D/EGOBZGQOBG8MfJA600cW4c7Co88ikmlRMSpwFlRQYR2jQuLDHHBbLM8qLwr ilvqlr1zci+VyVpkBTjCyd5ytlwEoqnqx/quWwFWmLNdFv3H6NFsGzSaGLnFZ7e/vgmE KOm+PRiSvGg9sF7aWfzgPIf91KVqC0BZZO2XChjETcIAtkF6t8eaToGptC5AwOERymjZ TA4iznvFcUGMqinQ6UAn4IoV7YbexcAC5+/ksA7FVoGNzjJMIAClBoFKXYWkzLiKHBR2 mUfg== X-Gm-Message-State: AA6/9RmAQxnFDZQ19DpjjiMI2ViyE0AvyPohkzLmJSKEhWUbhkIA1sbZ+vzfzRJsrFzfXxAn X-Received: by 10.99.62.199 with SMTP id l190mr14131731pga.156.1476931225256; Wed, 19 Oct 2016 19:40:25 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id s85sm66780616pfi.17.2016.10.19.19.40.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 19:40:23 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/11] remoteproc: virtio: Anchor vring life cycle in vdev Date: Wed, 19 Oct 2016 19:40:07 -0700 Message-Id: <1476931212-1806-7-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1476931212-1806-1-git-send-email-bjorn.andersson@linaro.org> References: <1476931212-1806-1-git-send-email-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of having the vrings being allocated and freed as they are requested by the virtio device tie their life cycle to the vdev resource. This allows us to decouple the vdev resource management from the virtio device management. Signed-off-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 20 ++++++++++++++++++++ drivers/remoteproc/remoteproc_virtio.c | 7 +------ 2 files changed, 21 insertions(+), 6 deletions(-) -- 2.5.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c978907498d0..e4509c8dd8e8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -370,6 +370,13 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, /* 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); /* it is now safe to add the virtio device */ @@ -379,6 +386,9 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, return 0; +unwind_vring_allocations: + for (i--; i >= 0; i--) + rproc_free_vring(&rvdev->vring[i]); remove_rvdev: list_del(&rvdev->node); free_rvdev: @@ -389,6 +399,16 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, void rproc_vdev_release(struct kref *ref) { struct rproc_vdev *rvdev = container_of(ref, struct rproc_vdev, refcount); + struct rproc_vring *rvring; + int id; + + for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) { + rvring = &rvdev->vring[id]; + if (!rvring->va) + continue; + + rproc_free_vring(rvring); + } list_del(&rvdev->node); kfree(rvdev); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index 0d1ad3ed149d..364411fb7734 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -79,7 +79,7 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, struct rproc_vring *rvring; struct virtqueue *vq; void *addr; - int len, size, ret; + int len, size; /* we're temporarily limited to two virtqueues per rvdev */ if (id >= ARRAY_SIZE(rvdev->vring)) @@ -88,10 +88,6 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, if (!name) return NULL; - ret = rproc_alloc_vring(rvdev, id); - if (ret) - return ERR_PTR(ret); - rvring = &rvdev->vring[id]; addr = rvring->va; len = rvring->len; @@ -130,7 +126,6 @@ static void __rproc_virtio_del_vqs(struct virtio_device *vdev) rvring = vq->priv; rvring->vq = NULL; vring_del_virtqueue(vq); - rproc_free_vring(rvring); } }