From patchwork Thu Oct 20 02:40:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9385787 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 78A8960487 for ; Thu, 20 Oct 2016 02:41:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 690952993D for ; Thu, 20 Oct 2016 02:41:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E1942998F; Thu, 20 Oct 2016 02:41:59 +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 037BF2993D for ; Thu, 20 Oct 2016 02:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933835AbcJTClp (ORCPT ); Wed, 19 Oct 2016 22:41:45 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36076 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757527AbcJTCk3 (ORCPT ); Wed, 19 Oct 2016 22:40:29 -0400 Received: by mail-pf0-f170.google.com with SMTP id e6so26528203pfk.3 for ; Wed, 19 Oct 2016 19:40:28 -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=SzcUfpE9UUfp6W2GKJfEG7YjGSBC/krzhKUrligzPVc=; b=fJ5/lxPBnJf3msb+KVf3B4kFP+3qmD4cSLdkJJbWw/0RkeM3S7Lin2vCiHNEOhEUw2 pRDdzvH3PC4PKtXtMPGxxnJN74SLYJBSlQXH2Pbi3fjXgnjgxeKR9FRWw8NScyoYqBNl EfeTW5CstTkw3p4oyJNBcAKEX1Fs+cr8Mel+c= 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=SzcUfpE9UUfp6W2GKJfEG7YjGSBC/krzhKUrligzPVc=; b=gT7TTSwhrTxpmCO1hAxk3MsWmURNo0XzXXkS7OCKCh5rYrVZ3XE6KmLlpmMSbMG6d5 TXRbiNoEgrl1vVC/FrTtoJcuJBOWpRVAzzjHcrbD7fa/iLhAPg3nZ0vp5zDeQjkNPcvp KjDeE7/1cwFx2T/Sf63EvcN++zzfyxsez5YuSUr0yKrLAdfu64HHywK56biUsVADVouh OSyDL1HstLVSSMn57vXEtcfhNsnpdH8jbrFCGfTk77s7sz6Wj4yMmgU4kCef4oYJm2v+ 8Bggfk+3Q+kFM19pINNfgUfxhPpdxR6ht4XuZjY+A5i8MrZFiekOxlLRokOPEn3+PpBT h9Rg== X-Gm-Message-State: AA6/9RlAhhco95hd0yB4h+VdXMFxmsBlDuWY52cbRA/OYHUV+xaahvfUgHkcSC8+Yk+UFoNU X-Received: by 10.99.60.19 with SMTP id j19mr13892617pga.8.1476931228464; Wed, 19 Oct 2016 19:40:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 19:40:27 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/11] remoteproc: Decouple vdev resources and devices Date: Wed, 19 Oct 2016 19:40:09 -0700 Message-Id: <1476931212-1806-9-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 Represent the virtio device part of the vdev resources as remoteproc subdevices to finalize the decoupling of the virtio resource and device handling. Signed-off-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 35 ++++++++++++++++++++--------------- include/linux/remoteproc.h | 5 +++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 1d2f4b2dd05d..c242ca016496 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -296,6 +296,20 @@ void rproc_free_vring(struct rproc_vring *rvring) rsc->vring[idx].notifyid = -1; } +static int rproc_vdev_do_probe(struct rproc_subdev *subdev) +{ + struct rproc_vdev *rvdev = container_of(subdev, struct rproc_vdev, subdev); + + return rproc_add_virtio_dev(rvdev, rvdev->id); +} + +static void rproc_vdev_do_remove(struct rproc_subdev *subdev) +{ + struct rproc_vdev *rvdev = container_of(subdev, struct rproc_vdev, subdev); + + rproc_remove_virtio_dev(rvdev); +} + /** * rproc_handle_vdev() - handle a vdev fw resource * @rproc: the remote processor @@ -358,6 +372,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, kref_init(&rvdev->refcount); + rvdev->id = rsc->id; rvdev->rproc = rproc; /* parse the vrings */ @@ -382,18 +397,14 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, list_add_tail(&rvdev->node, &rproc->rvdevs); - /* it is now safe to add the virtio device */ - ret = rproc_add_virtio_dev(rvdev, rsc->id); - if (ret) - goto remove_rvdev; + rproc_add_subdev(rproc, &rvdev->subdev, + rproc_vdev_do_probe, rproc_vdev_do_remove); return 0; unwind_vring_allocations: for (i--; i >= 0; i--) rproc_free_vring(&rvdev->vring[i]); -remove_rvdev: - list_del(&rvdev->node); free_rvdev: kfree(rvdev); return ret; @@ -403,6 +414,7 @@ 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++) { @@ -413,6 +425,7 @@ void rproc_vdev_release(struct kref *ref) rproc_free_vring(rvring); } + rproc_remove_subdev(rproc, &rvdev->subdev); list_del(&rvdev->node); kfree(rvdev); } @@ -842,10 +855,8 @@ static void rproc_resource_cleanup(struct rproc *rproc) } /* clean up remote vdev entries */ - list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) { - rproc_remove_virtio_dev(rvdev); + list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) kref_put(&rvdev->refcount, rproc_vdev_release); - } } /* @@ -1505,8 +1516,6 @@ EXPORT_SYMBOL(rproc_put); */ int rproc_del(struct rproc *rproc) { - struct rproc_vdev *rvdev, *tmp; - if (!rproc) return -EINVAL; @@ -1518,10 +1527,6 @@ int rproc_del(struct rproc *rproc) if (rproc->auto_boot) rproc_shutdown(rproc); - /* clean up remote vdev entries */ - list_for_each_entry_safe(rvdev, tmp, &rproc->rvdevs, node) - rproc_remove_virtio_dev(rvdev); - /* the rproc is downref'ed as soon as it's removed from the klist */ mutex_lock(&rproc_list_mutex); list_del(&rproc->node); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index dbcd967dd2e7..ff05b88730ad 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -488,6 +488,8 @@ struct rproc_vring { /** * struct rproc_vdev - remoteproc state for a supported virtio device * @refcount: reference counter for the vdev and vring allocations + * @subdev: handle for registering the vdev as a rproc subdevice + * @id: virtio device id (as in virtio_ids.h) * @node: list node * @rproc: the rproc handle * @vdev: the virio device @@ -497,6 +499,9 @@ struct rproc_vring { struct rproc_vdev { struct kref refcount; + struct rproc_subdev subdev; + + unsigned int id; struct list_head node; struct rproc *rproc; struct virtio_device vdev;