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: 9385785 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 AA8A660487 for ; Thu, 20 Oct 2016 02:41:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D22D29954 for ; Thu, 20 Oct 2016 02:41:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91FA4299AE; Thu, 20 Oct 2016 02:41:58 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 32CAD29954 for ; Thu, 20 Oct 2016 02:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933321AbcJTCk0 (ORCPT ); Wed, 19 Oct 2016 22:40:26 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:33762 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757262AbcJTCkZ (ORCPT ); Wed, 19 Oct 2016 22:40:25 -0400 Received: by mail-pf0-f182.google.com with SMTP id 128so26593953pfz.0 for ; Wed, 19 Oct 2016 19:40:25 -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=i5e8MQeZG3b8qObz+XI6qVh3uAtioZEJzmRlbx7dn5WYHR4yqbuWCipKPTtX+mSgOJ vxyqMCf4ni4QCQMMmKyuYY35VVqLPkQfPH+qjXuUDPB1IVrHw3837YHyxrqvYaHo0X8k ipVB9R6Eb2NA6qRsquUiCrmYE4uzLeaCy+Lv/mw71xx0tt9C4onxF50t0/WreR00G9N8 4JA6rA6+cJbVyXzBkz0zw2h9gR8wmyT7gVMz8viSScfylIrOkL46J3e0w3qkLuQYo8CU CzcITDLZWY7LRMlVg5qwvlhS+RoEt0bMOyU3GUu3mi4UHqkO582R3zviwWhnPLymsN+4 QNvw== X-Gm-Message-State: AA6/9RmYbWEVCyeil6ThPG/38WLUsrg82afTmlE9C+pxozHqkkEh7+dxxdx31sRkB7dhSBq2 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-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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); } }