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 487ECA0093; Fri, 23 Dec 2022 00:25:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5A1AD42D21; Fri, 23 Dec 2022 00:24:52 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 335AC42BB1 for ; Fri, 23 Dec 2022 00:24:50 +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 2BMGxsFP026074; Thu, 22 Dec 2022 15:24:49 -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=3HSkAC5Ok4xf9X9pPo2AK9QvpnV+4IKxOhPHtrMLJ1I=; b=MeDAe2m/ulndidJGrVrk+Cl3ZFr7JN7Yb0h1BzXghGoxm0pVfZW4OMzyZrHT+RwaNEvN DMnfHNYPVXrKlt7qaycipZJB/BYkJ/pdd69PrQDObYlBfvZWllY3cpeJLJIysPp2YWOg lLv+hF5AfUip0vT3xdT2xx/Vle1mpGcLDWzzlze8nGzMcl46KNaB2ipKsUWlyayQR1oe Ddlu7MXb08DEQ+UN94nA5YDwAzYXmrc3bJtCxyuIl6oW3VEXRMBGPkjW3N5GDgPyNP2e 8GC416oHoNGaG03NmIxRtWZsbwMXpM7091Y0JGQdd7HwrDnVP9EQ9SRItMjYzT6HcwOr vA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3mhe5runw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 15:24:49 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) 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:47 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 22 Dec 2022 15:24:47 -0800 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id B298B3F7052; Thu, 22 Dec 2022 15:24:45 -0800 (PST) From: Tomasz Duszynski To: CC: , , Tomasz Duszynski Subject: [RFC PATCH 2/7] raw/vfio_platform: add driver skeleton Date: Fri, 23 Dec 2022 00:24:30 +0100 Message-ID: <20221222232436.643514-3-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: 19Iw5qigN7sQNIQdYhRBXNkAHkTF3q0n X-Proofpoint-ORIG-GUID: 19Iw5qigN7sQNIQdYhRBXNkAHkTF3q0n 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 driver skeleton which does not do anything beyond registering driver itself to platform bus and providing means to create and destroy VFIO container. Signed-off-by: Tomasz Duszynski --- doc/guides/rawdevs/index.rst | 1 + doc/guides/rawdevs/vfio_platform.rst | 24 ++++++ drivers/raw/meson.build | 1 + drivers/raw/vfio_platform/meson.build | 16 ++++ .../raw/vfio_platform/rte_pmd_vfio_platform.h | 49 +++++++++++ drivers/raw/vfio_platform/version.map | 10 +++ drivers/raw/vfio_platform/vfio_platform.c | 85 +++++++++++++++++++ 7 files changed, 186 insertions(+) create mode 100644 doc/guides/rawdevs/vfio_platform.rst create mode 100644 drivers/raw/vfio_platform/meson.build create mode 100644 drivers/raw/vfio_platform/rte_pmd_vfio_platform.h create mode 100644 drivers/raw/vfio_platform/version.map create mode 100644 drivers/raw/vfio_platform/vfio_platform.c diff --git a/doc/guides/rawdevs/index.rst b/doc/guides/rawdevs/index.rst index f34315f051..b95c155b48 100644 --- a/doc/guides/rawdevs/index.rst +++ b/doc/guides/rawdevs/index.rst @@ -16,3 +16,4 @@ application through rawdev API. dpaa2_cmdif ifpga ntb + vfio_platform diff --git a/doc/guides/rawdevs/vfio_platform.rst b/doc/guides/rawdevs/vfio_platform.rst new file mode 100644 index 0000000000..97443a85fb --- /dev/null +++ b/doc/guides/rawdevs/vfio_platform.rst @@ -0,0 +1,24 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright(c) 2023 Marvell. + +VFIO Platform driver +==================== + +VFIO platform driver allows to configure and manage kernel VFIO platform devices. +These devices do not normally have built-in bus discovery capabilities, known +for example from PCI bus, and reside behind an IOMMU. + +Features +-------- + +Following features are available: + +- bind to devices managed by kernel vfio-platform driver +- expose device memory resources +- map/unmap DMA memory + +Requirements +------------ + +Since PMD is backed by vfio and vfio-platform kernel drivers they need to be enabled +in kernel config. diff --git a/drivers/raw/meson.build b/drivers/raw/meson.build index 05cad143fe..a3e1126c98 100644 --- a/drivers/raw/meson.build +++ b/drivers/raw/meson.build @@ -12,5 +12,6 @@ drivers = [ 'ifpga', 'ntb', 'skeleton', + 'vfio_platform', ] std_deps = ['rawdev'] diff --git a/drivers/raw/vfio_platform/meson.build b/drivers/raw/vfio_platform/meson.build new file mode 100644 index 0000000000..a03836d890 --- /dev/null +++ b/drivers/raw/vfio_platform/meson.build @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(C) 2023 Marvell. +# + +if not is_linux + build = false + reason = 'only supported on Linux' +endif + +deps += ['bus_platform', 'rawdev'] +sources = files( + 'vfio_platform.c', +) +headers = files( + 'rte_pmd_vfio_platform.h', +) diff --git a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h new file mode 100644 index 0000000000..307a20d9fc --- /dev/null +++ b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell. + */ + +#ifndef _RTE_PMD_VFIO_PLATFORM_H_ +#define _RTE_PMD_VFIO_PLATFORM_H_ + +/** + * @file + * + * VFIO platform specific structures and interface. + * + * @b EXPERIMENTAL: this API may change or be removed without prior notice + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Create a new VFIO container. + * + * @return + * container on success + * <0 on failure + */ +__rte_experimental +int +rte_pmd_vfio_platform_container_create(void); + +/** + * Destroy previously created container. + * + * @param container + * Container to destroy. + * + * @return + * 0 on success + * <0 on failure + */ +__rte_experimental +int +rte_pmd_vfio_platform_container_destroy(int container); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_PMD_VFIO_PLATFORM_H_ */ diff --git a/drivers/raw/vfio_platform/version.map b/drivers/raw/vfio_platform/version.map new file mode 100644 index 0000000000..2aea50f4c1 --- /dev/null +++ b/drivers/raw/vfio_platform/version.map @@ -0,0 +1,10 @@ +DPDK_23 { + local: *; +}; + +EXPERIMENTAL { + global: + + rte_pmd_vfio_platform_container_create; + rte_pmd_vfio_platform_container_destroy; +}; diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c new file mode 100644 index 0000000000..93558b310b --- /dev/null +++ b/drivers/raw/vfio_platform/vfio_platform.c @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +static struct { + int container_fd; + int refcnt; +} container_tbl[RTE_MAX_VFIO_CONTAINERS]; + +static int +container_next_free_index(void) +{ + int i; + + for (i = 0; i < (int)RTE_DIM(container_tbl); i++) { + if (container_tbl[i].refcnt == 0) + return i; + } + + return -1; +} + +static void +container_put(int index) +{ + + if (container_tbl[index].refcnt == 0) + return; + + if (--container_tbl[index].refcnt == 0) + rte_vfio_container_destroy(container_tbl[index].container_fd); +} + +static void +container_get(int index) +{ + container_tbl[index].refcnt++; +} + +int +rte_pmd_vfio_platform_container_create(void) +{ + int index, fd; + + fd = rte_vfio_container_create(); + if (fd < 0) + return -1; + + index = container_next_free_index(); + if (index < 0) + return -ENOSPC; + + container_tbl[index].container_fd = fd; + container_get(index); + + return index; +} + +int +rte_pmd_vfio_platform_container_destroy(int container) +{ + if ((unsigned int)container >= RTE_DIM(container_tbl)) + return -EINVAL; + + container_put(container); + + return 0; +} + +static struct rte_platform_driver vfio_platform = { +}; + +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"); -- 2.25.1