From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F28C4332F for ; Thu, 22 Dec 2022 23:25:16 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4522342686; Fri, 23 Dec 2022 00:24:56 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 276C142D17 for ; Fri, 23 Dec 2022 00:24:54 +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 2BMH0QRp027128; Thu, 22 Dec 2022 15:24:53 -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=LMPzMlCE/IxzH7lAvZPZ3+IZ8z+1Ub+rQUcJ6tRtKyQ=; b=HmmxJE0hNvdmU26xfFh+kEz9ShgjOUW2Wl7CQfba3Q0QEntJXG2Vq3QKkHH+ysUKRG9f YRW5BIV/zq9SdlOiHm16W30UGZh2rnFeuSC4R9uzm52BLzq8eEWOLTu1gUTREP+6tcHT TElDM85SEi77DoOIQrm22GbZ5V+SpDzKB1zQBwU75gDZgBe6UVjefh9+S7tagvT0vUKO OpGbiWWAhcGH26R7b4FmzN/d0v8sYRIcQUb0U74kU4zAN1PupHnFYWnS/qOUaWWn/Dbb EaqiAfAJuCZ9Vuln3wRnXouh1lo055H+HilTHlnO10ro2fVdnAz+Hg3FtdYvKt0beP1B ug== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3mhe5runxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 15:24:53 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 22 Dec 2022 15:24:51 -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:51 -0800 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id D55053F7052; Thu, 22 Dec 2022 15:24:49 -0800 (PST) From: Tomasz Duszynski To: CC: , , Tomasz Duszynski Subject: [RFC PATCH 4/7] raw/vfio_platform: support rawdev close Date: Fri, 23 Dec 2022 00:24:32 +0100 Message-ID: <20221222232436.643514-5-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: H1mDrZjWKyf7su-HwIXdD-QhZvyQMrZY X-Proofpoint-ORIG-GUID: H1mDrZjWKyf7su-HwIXdD-QhZvyQMrZY 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 support for closing raw device allocated during platform probe. Signed-off-by: Tomasz Duszynski --- drivers/raw/vfio_platform/vfio_platform.c | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c index b056041892..ae0572dc99 100644 --- a/drivers/raw/vfio_platform/vfio_platform.c +++ b/drivers/raw/vfio_platform/vfio_platform.c @@ -3,6 +3,8 @@ */ #include +#include +#include #include #include @@ -17,6 +19,8 @@ #include "vfio_platform.h" +#define VFIO_PLATFORM_SYSFS_BASE "/sys/bus/platform/devices" + static struct { int container_fd; int refcnt; @@ -52,6 +56,12 @@ container_get(int index) container_tbl[index].refcnt++; } +static int +container_fd(int index) +{ + return container_tbl[index].container_fd; +} + int rte_pmd_vfio_platform_container_create(void) { @@ -82,7 +92,46 @@ rte_pmd_vfio_platform_container_destroy(int container) return 0; } +static void +device_release_maps(struct vfio_platform *plat) +{ + struct vfio_platform_resource *res; + int i; + + for (i = 0; i < plat->num_resource; i++) { + res = &plat->resource[i]; + munmap(res->mem.addr, res->mem.len); + free((void *)(size_t)res->name); + } + + free(plat->resource); + plat->resource = NULL; + plat->num_resource = 0; +} + +static void +device_release(struct vfio_platform *plat) +{ + device_release_maps(plat); + rte_vfio_release_device(VFIO_PLATFORM_SYSFS_BASE, plat->device->name, plat->dev_fd); + rte_vfio_container_group_unbind(container_fd(plat->container), plat->group); + close(plat->group_fd); + rte_vfio_clear_group(plat->group_fd); + container_put(plat->container); +} + +static int +vfio_rawdev_dev_close(struct rte_rawdev *dev) +{ + struct vfio_platform *plat = dev->dev_private; + + device_release(plat); + + return 0; +} + static const struct rte_rawdev_ops vfio_platform_rawdev_ops = { + .dev_close = vfio_rawdev_dev_close, }; static int -- 2.25.1