Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp295098rwe; Fri, 26 Aug 2022 05:18:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5/ySCBWFFxqP+P4VMt3zt/KstRb+UcbgsbZnsg2lXeqD/x0sZPx9nth5i12ck9x8Cumgr+ X-Received: by 2002:a17:906:8a5b:b0:73d:7975:567e with SMTP id gx27-20020a1709068a5b00b0073d7975567emr5215926ejc.378.1661516335919; Fri, 26 Aug 2022 05:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661516335; cv=none; d=google.com; s=arc-20160816; b=D5hFGdFWLQcwTOY30skxMoDZfrv+jbRVrchcsT/2gt1kRIzcVawU0pbV92166MS8tH XhzWQfN6LG3+d8+tIXq/GH+nU/ZIbMptR83n6zpb7P+OErfz07cAmH8YfYD009Teuqew /JK0/3nhSxiS7KSDTsnv2oPeG0ZIqZXh8sK7WgzpBE+jbSC5W6udpzQk2tUpGmGNUTxT BEu3LX7YJjuebklsBoVJJfBlZhT/FjU4PLoOzdqllF0+2bJiWxvHk2u3dDVZ/cLmnPye 6vyjZ6Q4jEx1cW8rOHj87dG76cO/EL47nwOsxM9VLHrRvQLBbCKgcUUzfyx2/IYKRfqd 8B1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f1E5z4t9ZgWql8aV+LG0YjXvyprkoiFA1I/INZXVjH8=; b=V2sXpBgqC1l7bA1HAuf7fcTIh7Xc6ggW/7Hh/R7EihCe0GPY56figW3E8HjerUPeTv w0LLPK2cc1LPoChPdl/U4kRD0v2d6xdtsbWlQZRHnbSlnxdPxbZZ4xjcRgulrDRydSuA LhuXXN5Z6abfSrzoEPpL5LJfX8YbXak7cIGWhBDNSaMRlSGP4fBOuTpuwLskO1a9vpbl rjtCW8QgKLiBW60rCzcy5hBp+dBPFqsrzysYFF8D7b9OXvUkmoEJUt9bTjLploAWhZcW 7E8b/RJfYHDKMb8fQjlJ3iFvGVpy7AT2KMUtA6hjNFiO/VO8cnKxr6WK291u6EUq6quz T7LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=3W1hf96p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb35-20020a170907962300b0073db3cc6b05si1187648ejc.406.2022.08.26.05.18.27; Fri, 26 Aug 2022 05:18:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=3W1hf96p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242826AbiHZLxx (ORCPT + 99 others); Fri, 26 Aug 2022 07:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245494AbiHZLxg (ORCPT ); Fri, 26 Aug 2022 07:53:36 -0400 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0141CD743E; Fri, 26 Aug 2022 04:53:34 -0700 (PDT) Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27QAFsd8026046; Fri, 26 Aug 2022 13:53:26 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=f1E5z4t9ZgWql8aV+LG0YjXvyprkoiFA1I/INZXVjH8=; b=3W1hf96pYVLODeEsGvbfElxHIcBzwj4ng7538FzMR/N8uX6LsDga5f4Tw8mhQUhlT4oO d2GuHB6fcw2X0qua/HDsC3egUh9EwIXrwYOGgfwCr0E5Rp0KFoe9IjTZrDtJQlL93A4K DgHP31wbmrUWXmn3V71Xi6sBn7UQ1hgxXO7aeZViwrXR2hdZ1EGNT+qGnKJ61Y9u1jFt sy6KowzeIoFOGEd+toX7yRR+XouEzyL9QSjU0pqQP2V3FxtG/6jKgBcH1vDqpOj8YXqU uNbCWDfhhqA+b7k/IxYzntLzKqaPExU5E1dWxRymsxqGbH+rEoqKVRu8iheE4cTfnkQF cw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3j52b1297g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Aug 2022 13:53:26 +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 32102100034; Fri, 26 Aug 2022 13:53:26 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2C6EF222CA8; Fri, 26 Aug 2022 13:53:26 +0200 (CEST) Received: from localhost (10.75.127.46) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 26 Aug 2022 13:53:23 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Rob Herring , Christoph Hellwig , Stefano Stabellini , Bruce Ashfield , Subject: [PATCH v8 1/4] remoteproc: core: Introduce rproc_rvdev_add_device function Date: Fri, 26 Aug 2022 13:52:29 +0200 Message-ID: <20220826115232.2163130-2-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.24.3 In-Reply-To: <20220826115232.2163130-1-arnaud.pouliquen@foss.st.com> References: <20220826115232.2163130-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_06,2022-08-25_01,2022-06-22_01 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation of the migration of the management of rvdev in remoteproc_virtio.c, this patch spins off a new function to manage the remoteproc virtio device creation. The rproc_rvdev_add_device will be moved to remoteproc_virtio.c. The rproc_vdev_data structure is introduced to provide information for the rvdev creation. This structure allows to manage the rvdev and vrings allocation in the rproc_rvdev_add_device function. Signed-off-by: Arnaud Pouliquen Reviewed-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 145 +++++++++++++---------- drivers/remoteproc/remoteproc_internal.h | 15 +++ 2 files changed, 97 insertions(+), 63 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e5279ed9a8d7..c977e6c0bdb7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -486,74 +486,23 @@ static int copy_dma_range_map(struct device *to, struct device *from) return 0; } -/** - * rproc_handle_vdev() - handle a vdev fw resource - * @rproc: the remote processor - * @ptr: the vring resource descriptor - * @offset: offset of the resource entry - * @avail: size of available data (for sanity checking the image) - * - * This resource entry requests the host to statically register a virtio - * device (vdev), and setup everything needed to support it. It contains - * everything needed to make it possible: the virtio device id, virtio - * device features, vrings information, virtio config space, etc... - * - * Before registering the vdev, the vrings are allocated from non-cacheable - * physically contiguous memory. Currently we only support two vrings per - * remote processor (temporary limitation). We might also want to consider - * doing the vring allocation only later when ->find_vqs() is invoked, and - * then release them upon ->del_vqs(). - * - * Note: @da is currently not really handled correctly: we dynamically - * allocate it using the DMA API, ignoring requested hard coded addresses, - * and we don't take care of any required IOMMU programming. This is all - * going to be taken care of when the generic iommu-based DMA API will be - * merged. Meanwhile, statically-addressed iommu-based firmware images should - * use RSC_DEVMEM resource entries to map their required @da to the physical - * address of their base CMA region (ouch, hacky!). - * - * Return: 0 on success, or an appropriate error code otherwise - */ -static int rproc_handle_vdev(struct rproc *rproc, void *ptr, - int offset, int avail) +static struct rproc_vdev * +rproc_rvdev_add_device(struct rproc *rproc, struct rproc_vdev_data *rvdev_data) { - struct fw_rsc_vdev *rsc = ptr; - struct device *dev = &rproc->dev; struct rproc_vdev *rvdev; - int i, ret; + struct fw_rsc_vdev *rsc = rvdev_data->rsc; char name[16]; - - /* make sure resource isn't truncated */ - if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len > - avail) { - dev_err(dev, "vdev rsc is truncated\n"); - return -EINVAL; - } - - /* make sure reserved bytes are zeroes */ - if (rsc->reserved[0] || rsc->reserved[1]) { - dev_err(dev, "vdev rsc has non zero reserved bytes\n"); - return -EINVAL; - } - - dev_dbg(dev, "vdev rsc: id %d, dfeatures 0x%x, cfg len %d, %d vrings\n", - rsc->id, rsc->dfeatures, rsc->config_len, rsc->num_of_vrings); - - /* we currently support only two vrings per rvdev */ - if (rsc->num_of_vrings > ARRAY_SIZE(rvdev->vring)) { - dev_err(dev, "too many vrings: %d\n", rsc->num_of_vrings); - return -EINVAL; - } + int i, ret; rvdev = kzalloc(sizeof(*rvdev), GFP_KERNEL); if (!rvdev) - return -ENOMEM; + return ERR_PTR(-ENOMEM); kref_init(&rvdev->refcount); - rvdev->id = rsc->id; + rvdev->id = rvdev_data->id; rvdev->rproc = rproc; - rvdev->index = rproc->nb_vdev++; + rvdev->index = rvdev_data->index; /* Initialise vdev subdevice */ snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index); @@ -565,7 +514,7 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, ret = device_register(&rvdev->dev); if (ret) { put_device(&rvdev->dev); - return ret; + return ERR_PTR(ret); } ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent); @@ -578,7 +527,7 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, ret = dma_coerce_mask_and_coherent(&rvdev->dev, dma_get_mask(rproc->dev.parent)); if (ret) { - dev_warn(dev, + dev_warn(&rvdev->dev, "Failed to set DMA mask %llx. Trying to continue... (%pe)\n", dma_get_mask(rproc->dev.parent), ERR_PTR(ret)); } @@ -591,7 +540,7 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, } /* remember the resource offset*/ - rvdev->rsc_offset = offset; + rvdev->rsc_offset = rvdev_data->rsc_offset; /* allocate the vring resources */ for (i = 0; i < rsc->num_of_vrings; i++) { @@ -607,14 +556,14 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, rproc_add_subdev(rproc, &rvdev->subdev); - return 0; + return rvdev; unwind_vring_allocations: for (i--; i >= 0; i--) rproc_free_vring(&rvdev->vring[i]); free_rvdev: device_unregister(&rvdev->dev); - return ret; + return ERR_PTR(ret); } void rproc_vdev_release(struct kref *ref) @@ -634,6 +583,76 @@ void rproc_vdev_release(struct kref *ref) device_unregister(&rvdev->dev); } +/** + * rproc_handle_vdev() - handle a vdev fw resource + * @rproc: the remote processor + * @ptr: the vring resource descriptor + * @offset: offset of the resource entry + * @avail: size of available data (for sanity checking the image) + * + * This resource entry requests the host to statically register a virtio + * device (vdev), and setup everything needed to support it. It contains + * everything needed to make it possible: the virtio device id, virtio + * device features, vrings information, virtio config space, etc... + * + * Before registering the vdev, the vrings are allocated from non-cacheable + * physically contiguous memory. Currently we only support two vrings per + * remote processor (temporary limitation). We might also want to consider + * doing the vring allocation only later when ->find_vqs() is invoked, and + * then release them upon ->del_vqs(). + * + * Note: @da is currently not really handled correctly: we dynamically + * allocate it using the DMA API, ignoring requested hard coded addresses, + * and we don't take care of any required IOMMU programming. This is all + * going to be taken care of when the generic iommu-based DMA API will be + * merged. Meanwhile, statically-addressed iommu-based firmware images should + * use RSC_DEVMEM resource entries to map their required @da to the physical + * address of their base CMA region (ouch, hacky!). + * + * Return: 0 on success, or an appropriate error code otherwise + */ +static int rproc_handle_vdev(struct rproc *rproc, void *ptr, + int offset, int avail) +{ + struct fw_rsc_vdev *rsc = ptr; + struct device *dev = &rproc->dev; + struct rproc_vdev *rvdev; + struct rproc_vdev_data rvdev_data; + + /* make sure resource isn't truncated */ + if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len > + avail) { + dev_err(dev, "vdev rsc is truncated\n"); + return -EINVAL; + } + + /* make sure reserved bytes are zeroes */ + if (rsc->reserved[0] || rsc->reserved[1]) { + dev_err(dev, "vdev rsc has non zero reserved bytes\n"); + return -EINVAL; + } + + dev_dbg(dev, "vdev rsc: id %d, dfeatures 0x%x, cfg len %d, %d vrings\n", + rsc->id, rsc->dfeatures, rsc->config_len, rsc->num_of_vrings); + + /* we currently support only two vrings per rvdev */ + if (rsc->num_of_vrings > ARRAY_SIZE(rvdev->vring)) { + dev_err(dev, "too many vrings: %d\n", rsc->num_of_vrings); + return -EINVAL; + } + + rvdev_data.id = rsc->id; + rvdev_data.index = rproc->nb_vdev++; + rvdev_data.rsc_offset = offset; + rvdev_data.rsc = rsc; + + rvdev = rproc_rvdev_add_device(rproc, &rvdev_data); + if (IS_ERR(rvdev)) + return PTR_ERR(rvdev); + + return 0; +} + /** * rproc_handle_trace() - handle a shared trace buffer resource * @rproc: the remote processor diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 72d4d3d7d94d..07c503de0f95 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -24,6 +24,21 @@ struct rproc_debug_trace { struct rproc_mem_entry trace_mem; }; +/** + * struct rproc_vdev_data - remoteproc virtio device data + * @rsc_offset: offset of the vdev's resource entry + * @id: virtio device id (as in virtio_ids.h) + * @index: vdev position versus other vdev declared in resource table + * @rsc: pointer to the vdev resource entry. Valid only during vdev init as + * the resource can be cached by rproc. + */ +struct rproc_vdev_data { + u32 rsc_offset; + unsigned int id; + u32 index; + struct fw_rsc_vdev *rsc; +}; + /* from remoteproc_core.c */ void rproc_release(struct kref *kref); irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); -- 2.24.3