Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1445788ybz; Thu, 16 Apr 2020 09:17:05 -0700 (PDT) X-Google-Smtp-Source: APiQypIgv1IQh9epA0NFKScw/cnueQVbfk1a3HSNWb6orZHfIf0spJyg7f+TjFHMesru2xPZjNfb X-Received: by 2002:aa7:dccd:: with SMTP id w13mr31357599edu.94.1587053824923; Thu, 16 Apr 2020 09:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587053824; cv=none; d=google.com; s=arc-20160816; b=u71fqx34S2zPXk6JywUl7GLdtcFlcELPPfLaikgug4nk07dbsKNlUvmcVADV5j5eOw HeyX4tU7c1cAmzKQYnT/RAdmfWB6iUq4E2Sttjs3tyGkWSeQcfO7DO/+2/hQhKeUVYyU BcPseZ7uKQf7GThGw+1SE8a7dXxZJQXBDaWqUcx/MY7/8FukiCJQKmwCnPbiFTgQqDMP +Fn5RRt5pg/2KDOFvBGFoSVW8YFF24bPpDZBClNaOQ/eOe9RTVT73fWQG5beAeP6umTn aMw8m8d5ekWABgrn9wJE1p07cF3XwQuEhmMSlnL8yAGoPBKV2GBJl5RhY8f6dRjetR2h 5BsQ== 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=x/YFvpKguyxR4K0R9rEA/U7cUeNFm3Fzc4388HJ8uh8=; b=uP3FVhQ6nUObO255blMqRcsQyNieXTN9iYZ1zPLrnNsCxygf2dLTx/KpmKCIayt6Zp FZhgGfFi73KbY+AZ9a1Ctwxylbi1Mo2bcB67ZlVM0oNNtNIac27UqIpqU9e01MGAjahv FL8cXYPixQSnTzQ54A0pI06IFOLrbRQt9AopeoCooGjHtAa7/a3K2kjBVKtyfF7qH/kL ZN3l+4UgZkDqL8OJizBYJAvhfIPQwgNVb+o4Jy9AzgKlDTiwQWepymqh4b/jqi+L/y8f 2VCAIlVTX71lSl+jqAmpes5fQUYzCB19UPfV+BeL2BbHsGrEoQa5zqXtES3IBjatsApq zQKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=IPix+z6b; 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 ce22si13062696edb.145.2020.04.16.09.16.41; Thu, 16 Apr 2020 09:17:04 -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=IPix+z6b; 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 S2404738AbgDPQOx (ORCPT + 99 others); Thu, 16 Apr 2020 12:14:53 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:61124 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2636521AbgDPQO2 (ORCPT ); Thu, 16 Apr 2020 12:14:28 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03GGDEcC005340; Thu, 16 Apr 2020 18:14:24 +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=x/YFvpKguyxR4K0R9rEA/U7cUeNFm3Fzc4388HJ8uh8=; b=IPix+z6bgetGW5L+Zp0JYcGILP6KJi7xFb+o9q4/8rfLr9NUaRWMAhtlYrpio5SHaDIs 6C01weLAHT4VP7NuIHu4tNaLnWxqWMizwWaQcvlg0Ut5Pcfm2IHUD8NtLO4vxtM+XVQa +F9TePZ+nEsnwnlbsCJqljZPecVNnDrF4pbOvhafYGku7TQgpm9LLpC00xCwXNafG8ZH QMOIpWGIIvvSOAsyQVMxwFnfA+WUbal3aEPBvtEjYGvbijvXrykG+KjbtGFVURgtEaky nx8VPaPda3jBC2Gnri8jE7D1nLvarrTjwr66b25eGrIWluCYydIepRG/xKOyVAJsIMS+ GA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 30dn6t3ncs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Apr 2020 18:14:24 +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 6041310002A; Thu, 16 Apr 2020 18:14:24 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 5361A2B2D2A; Thu, 16 Apr 2020 18:14:24 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 16 Apr 2020 18:14:23 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [RFC 12/18] remoteproc: Support of pre-registered virtio device Date: Thu, 16 Apr 2020 18:13:25 +0200 Message-ID: <20200416161331.7606-13-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.45] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) 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 Management of the virtio device declared in the devicetree as a sub device of the remoteproc. Instead of creating a new platform device, we parse first the rvdevs list to look for a pre-registered rvdev with an index, that matches with the vdev instance of the resource table. If no pre-registered vdev is found a new platform device is created. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 51 +++++++++++++++++----------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ecb36f64b1a0..9238aa292644 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -383,8 +383,8 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, { struct device *dev = &rproc->dev; struct rproc_vdev_data vdev_data; + struct rproc_vdev *rvdev = NULL, *tmp_rvdev; struct platform_device *pdev; - int ret; /* make sure resource isn't truncated */ if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len > @@ -399,27 +399,40 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, return -EINVAL; } - vdev_data.rsc_offset = offset; - vdev_data.rsc = rsc; - vdev_data.id = rsc->id; - vdev_data.index = rproc->nb_vdev; + /* Try to find a pre-registered rproc virtio device */ + list_for_each_entry(tmp_rvdev, &rproc->rvdevs, node) { + if (tmp_rvdev->index == rproc->nb_vdev) { + rvdev = tmp_rvdev; + break; + } + } - dev_dbg(dev, "%s: rsc_offset = %d rsc = %p id = %d\n", - __func__, vdev_data.rsc_offset, vdev_data.rsc, vdev_data.id); + if (rvdev) { + /* assign the resource offset */ + rvdev->rsc_offset = offset; + rvdev->rsc = rsc; + rvdev->id = rsc->id; - pdev = platform_device_register_data(dev, "rproc-virtio", - rproc->nb_vdev, &vdev_data, - sizeof(vdev_data)); - ret = PTR_ERR_OR_ZERO(pdev); - if (ret) { - dev_err(rproc->dev.parent, - "failed to create rproc-virtio device\n"); - return ret; + } else { + /* no rproc vdev found, register one */ + vdev_data.rsc_offset = offset; + vdev_data.rsc = rsc; + vdev_data.id = rsc->id; + vdev_data.index = rproc->nb_vdev; + + pdev = platform_device_register_data(dev, "rproc-virtio", + rproc->nb_vdev, &vdev_data, + sizeof(vdev_data)); + if (PTR_ERR_OR_ZERO(pdev)) { + dev_err(rproc->dev.parent, + "failed to create rproc-virtio device\n"); + return PTR_ERR_OR_ZERO(pdev); + } + /* register a component associated to the virtio platform */ + component_match_add_release(&pdev->dev, &rproc->match, + rproc_release_of, rproc_compare_of, + &pdev->dev); } - /* register a component associated to the virtio platform */ - component_match_add_release(&pdev->dev, &rproc->match, - rproc_release_of, rproc_compare_of, - &pdev->dev); rproc->nb_vdev++; return 0; -- 2.17.1