From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 69052A0093; Fri, 23 Dec 2022 00:25:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F59042D27; Fri, 23 Dec 2022 00:24:54 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id D363D42D24 for ; Fri, 23 Dec 2022 00:24:52 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BMGxsFQ026074; Thu, 22 Dec 2022 15:24:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=+DbWRpSymFBw1qRYVy97YhMyPUl+mgUrtAwc+WzJF9I=; b=O5GMzurLRx0N3iolyz1I3Ek0yjj4AAfGjFXVxs5UY0WnvMLmL/Q2swWIyXez37V11iZ1 mN8gfnolhFGj3SNj2BkI3tTSdMSFjtJznQbknn8YH5qIZyTFtndNngZywi1t1q9al2RC OwQfhE6GvjeGpKIsZgx2eSXbtOYRMB3+JqQeM8xHkPUVmOHb0WEygHx1Kd4jYYjBkZER XDQYN6lmIz3Kt12bQJsgHKWBGw22Aa8+XMoVqK+kY6RKz08xZeq5eGrFmkOZkUUDBo88 dzJYufd23eg6BjC4qNGsmRmsH6V52Sn+5jiNKsVqkbyskgOkqx1zbaw/krP6JGZHBOAY Sw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3mhe5runwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 15:24:52 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 22 Dec 2022 15:24:49 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 22 Dec 2022 15:24:49 -0800 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id A7F733F704E; Thu, 22 Dec 2022 15:24:47 -0800 (PST) From: Tomasz Duszynski To: , Anatoly Burakov CC: , , Tomasz Duszynski Subject: [RFC PATCH 3/7] raw/vfio_platform: add platform probe and remove Date: Fri, 23 Dec 2022 00:24:31 +0100 Message-ID: <20221222232436.643514-4-tduszynski@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com> References: <20221222232436.643514-1-tduszynski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: kCeMfbbGaO9unt7sE0uIFzk1vpFW7HiQ X-Proofpoint-ORIG-GUID: kCeMfbbGaO9unt7sE0uIFzk1vpFW7HiQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-22_10,2022-12-22_03,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add platform bus probe and remove. Signed-off-by: Tomasz Duszynski --- drivers/raw/vfio_platform/vfio_platform.c | 56 +++++++++++++++++++++++ drivers/raw/vfio_platform/vfio_platform.h | 35 ++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 drivers/raw/vfio_platform/vfio_platform.h diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c index 93558b310b..b056041892 100644 --- a/drivers/raw/vfio_platform/vfio_platform.c +++ b/drivers/raw/vfio_platform/vfio_platform.c @@ -9,9 +9,14 @@ #include #include #include +#include #include +#include +#include #include +#include "vfio_platform.h" + static struct { int container_fd; int refcnt; @@ -77,9 +82,60 @@ rte_pmd_vfio_platform_container_destroy(int container) return 0; } +static const struct rte_rawdev_ops vfio_platform_rawdev_ops = { +}; + +static int +vfio_platform_probe(struct rte_platform_device *pdev) +{ + struct rte_platform_driver *pdrv = pdev->driver; + struct vfio_platform *plat; + struct rte_rawdev *rawdev; + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + rawdev = rte_rawdev_pmd_allocate(pdev->device.name, sizeof(*plat), rte_socket_id()); + if (!rawdev) + return -ENOMEM; + + rawdev->dev_ops = &vfio_platform_rawdev_ops; + rawdev->device = &pdev->device; + rawdev->driver_name = pdrv->driver.name; + + plat = rawdev->dev_private; + plat->device = pdev; + + pdev->driver_data = plat; + + VFIO_PLATFORM_LOG(INFO, "probed %s\n", pdev->device.name); + + return 0; +} + +static int +vfio_platform_remove(struct rte_platform_device *pdev) +{ + struct rte_rawdev *rawdev; + int ret; + + rawdev = rte_rawdev_pmd_get_named_dev(pdev->device.name); + if (!rawdev) + return -ENODEV; + + ret = rte_rawdev_pmd_release(rawdev); + if (ret == 0) + VFIO_PLATFORM_LOG(INFO, "removed %s\n", pdev->device.name); + + return ret; +} + static struct rte_platform_driver vfio_platform = { + .probe = vfio_platform_probe, + .remove = vfio_platform_remove, }; RTE_PMD_REGISTER_PLATFORM(vfio_platform, vfio_platform); RTE_PMD_REGISTER_ALIAS(vfio_platform, vfio-platform); RTE_PMD_REGISTER_KMOD_DEP(vfio_platform, "vfio-platform"); +RTE_LOG_REGISTER_DEFAULT(vfio_platform_logtype, NOTICE); diff --git a/drivers/raw/vfio_platform/vfio_platform.h b/drivers/raw/vfio_platform/vfio_platform.h new file mode 100644 index 0000000000..f6b2316a26 --- /dev/null +++ b/drivers/raw/vfio_platform/vfio_platform.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell. + */ + +#ifndef _VFIO_PLATFORM_H_ +#define _VFIO_PLATFORM_H_ + +#include +#include +#include +#include + +extern int vfio_platform_logtype; + +#define VFIO_PLATFORM_LOG(level, ...) \ + rte_log(RTE_LOG_ ## level, vfio_platform_logtype, \ + RTE_FMT("vfio platform: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ + RTE_FMT_TAIL(__VA_ARGS__,))) + +struct vfio_platform_resource { + struct rte_mem_resource mem; + const char *name; +}; + +struct vfio_platform { + int dev_fd; + int group_fd; + int group; + int container; + struct rte_platform_device *device; + struct vfio_platform_resource *resource; + int num_resource; +}; + +#endif /* _VFIO_PLATFORM_H_ */ -- 2.25.1