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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A700C54E58 for ; Mon, 18 Mar 2024 13:26:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AA61310F71F; Mon, 18 Mar 2024 13:26:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="kW3U8gOv"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC90310F717 for ; Mon, 18 Mar 2024 13:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710768398; x=1742304398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9zXTUvdMiCSxVcO/FPsutVr3hNjrLL4OpvWhbnF6LFc=; b=kW3U8gOvGerIOE2d9BaK49N/xSS6PobXy4deoHir/gi0aBqa/wNy2nj0 PX8DgI/KaNXjYwQ+ioDmnZLpGshXp6w0gSFznjzZN5Ojv4wA9ZfjswMAL dFhhRShcXxAlLwsFRdlEeU7EPgBlkFbgRLMy6gxecsyA5o4GDD9DMjx7f H30zKwyVzyoUKLrDCXo61jY7O3ZmTYOhSAzyFgwpStgDZ5RtQTbGJIzob cvsKKwqBYz4I2tjzUca8TAxxLcFJ71JL/DFdBulKbHy/gSkT2KsyxuiUM exLumS15GCozOcQfprbOFsQAKF8Jmb4sdu+AlusPliaRATA1hww/7ZMQu A==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="9386916" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="9386916" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 06:26:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="13501383" Received: from unknown (HELO localhost) ([10.245.246.221]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 06:26:36 -0700 From: Kamil Konieczny To: igt-dev@lists.freedesktop.org Cc: =?UTF-8?q?Dominik=20Karol=20Pi=C4=85tkowski?= , Janusz Krzysztofik , =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= , Kamil Konieczny Subject: [PATCH i-g-t v13 2/5] lib/drmtest: Introduced drm_open_driver_another Date: Mon, 18 Mar 2024 14:26:20 +0100 Message-ID: <20240318132624.110746-3-kamil.konieczny@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240318132624.110746-1-kamil.konieczny@linux.intel.com> References: <20240318132624.110746-1-kamil.konieczny@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Dominik Karol Piątkowski For user convenience, introduce drm_open_driver_another as a wrapper for __drm_open_driver_another with skip on fail. Also add counterpart to open: __drm_close_driver() with no warning for non-opened fd. v2: rebased (Kamil) v6: reword description (Janusz) v10: change assert into skip, add TODO note about atomic reset before tests starts for i915 and on exit path (Janusz) add __drm_close_driver() (Kamil) Cc: Janusz Krzysztofik Cc: "Zbigniew Kempczyński" Signed-off-by: "Dominik Karol Piątkowski" Signed-off-by: Kamil Konieczny --- lib/drmtest.c | 109 ++++++++++++++++++++++++++++++++++---------------- lib/drmtest.h | 2 + 2 files changed, 76 insertions(+), 35 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index 52b5a2020..f8810da43 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -241,6 +241,35 @@ static void modulename_to_chipset(const char *name, unsigned int *chip) } } +static const char *chipset_to_str(int chipset) +{ + switch (chipset) { + case DRIVER_INTEL: + return "intel"; + case DRIVER_V3D: + return "v3d"; + case DRIVER_VC4: + return "vc4"; + case DRIVER_VGEM: + return "vgem"; + case DRIVER_AMDGPU: + return "amdgpu"; + case DRIVER_PANFROST: + return "panfrost"; + case DRIVER_MSM: + return "msm"; + case DRIVER_XE: + return "xe"; + case DRIVER_VMWGFX: + return "vmwgfx"; + case DRIVER_ANY: + return "any"; + default: + return "other"; + } +} + + /* * Logs path of opened device. Device path opened for the first time is logged at info level, * subsequent opens (if any) are logged at debug level. @@ -563,6 +592,27 @@ int __drm_open_driver_another(int idx, int chipset) return fd; } +/** + * drm_open_driver_another: + * @idx: index of the device you are opening + * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL + * + * A wrapper for __drm_open_driver with skip on fail. + * + * Returns: + * An open DRM fd or skips + */ +int drm_open_driver_another(int idx, int chipset) +{ + int fd = __drm_open_driver_another(idx, chipset); + + igt_skip_on_f(fd < 0, "No known gpu found for chipset flags %d (%s)\n", + chipset, chipset_to_str(chipset)); + + /* TODO: for i915 and idx > 0 add atomic reset before test */ + return fd; +} + /** * __drm_open_driver: * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL @@ -643,34 +693,6 @@ static void cancel_work_at_exit_render(int sig) at_exit_drm_render_fd = -1; } -static const char *chipset_to_str(int chipset) -{ - switch (chipset) { - case DRIVER_INTEL: - return "intel"; - case DRIVER_V3D: - return "v3d"; - case DRIVER_VC4: - return "vc4"; - case DRIVER_VGEM: - return "vgem"; - case DRIVER_AMDGPU: - return "amdgpu"; - case DRIVER_PANFROST: - return "panfrost"; - case DRIVER_MSM: - return "msm"; - case DRIVER_XE: - return "xe"; - case DRIVER_VMWGFX: - return "vmwgfx"; - case DRIVER_ANY: - return "any"; - default: - return "other"; - } -} - static const char *chipset_to_vendor_str(int chipset) { return chipset == DRIVER_XE ? chipset_to_str(DRIVER_INTEL) : chipset_to_str(chipset); @@ -733,12 +755,33 @@ static bool is_valid_fd(int fd) return false; } +/** + * __drm_close_driver: + * @fd: a drm file descriptor + * + * Check the given drm file descriptor @fd is valid and if not, + * return -1. For valid fd close it and make cleanups. + * + * Returns: 0 on success or -1 on error. + */ +int __drm_close_driver(int fd) +{ + if (!is_valid_fd(fd)) + return -1; + + /* Remove xe_device from cache. */ + if (is_xe_device(fd)) + xe_device_put(fd); + + return close(fd); +} + /** * drm_close_driver: * @fd: a drm file descriptor * - * Check the given drm file descriptor @fd is valid & Close if it is - * an valid drm fd. + * Check the given drm file descriptor @fd is valid and if not issue warning. + * For valid fd close it and make cleanups. * * Returns: 0 on success or -1 on error. */ @@ -750,11 +793,7 @@ int drm_close_driver(int fd) return -1; } - /* Remove xe_device from cache. */ - if (is_xe_device(fd)) - xe_device_put(fd); - - return close(fd); + return __drm_close_driver(fd); } /** diff --git a/lib/drmtest.h b/lib/drmtest.h index 588d7da17..bbe5f252f 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -110,12 +110,14 @@ void __set_forced_driver(const char *name); int __drm_open_device(const char *name, unsigned int chipset); void drm_load_module(unsigned int chipset); +int drm_open_driver_another(int idx, int chipset); int drm_open_driver(int chipset); int drm_open_driver_master(int chipset); int drm_open_driver_render(int chipset); int __drm_open_driver_another(int idx, int chipset); int __drm_open_driver(int chipset); int __drm_open_driver_render(int chipset); +int __drm_close_driver(int fd); int drm_close_driver(int fd); int drm_reopen_driver(int fd); -- 2.42.0