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 D620DC369C2 for ; Thu, 17 Apr 2025 14:04:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 78B2110EB25; Thu, 17 Apr 2025 14:04:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="ITNIa/++"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B3EA10EB24 for ; Thu, 17 Apr 2025 14:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744898683; x=1776434683; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PZlo5UjygC1w3HGlKTpvFAVNVU66lRhpBv9xECuT+iA=; b=ITNIa/++4YcH0qTq04WKVzO47U/F3p2TtIyWX3B7wxM1xnpHDhLY5mXp qDAbjGulEsVlyWfAEF5wpj1CO2QQyVpDBgGxMcqQD2YCQiSOrBIFX+Jb5 aIgy21dK1cpptxjxXBbyRjdqvQXWLsKJCUyHC5JlwVCPfnQV6mOcW3eDo CyNWFgrNxVXzMlZ6zfmGQhhqLO5gj7OCoEVZGO7Wyey6wrG3OxD/mX84K 1ioRTcd0piTTQYPd8VQamrinVZtWqkcDMQ6uFcBRzDHVSG0hugsBj/9RO 2qkmzj2NlCcMHKgK0rxBESt2uSffzz2tC9imNaCfAV20eTZRrjpArV6os Q==; X-CSE-ConnectionGUID: 1lIxe0ctTDSnvgX0VNxnXQ== X-CSE-MsgGUID: lDaQse4DR66llUeckn5TUQ== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="45723074" X-IronPort-AV: E=Sophos;i="6.15,219,1739865600"; d="scan'208";a="45723074" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 07:03:49 -0700 X-CSE-ConnectionGUID: 3VyODO84Q8SixN9AalBtfg== X-CSE-MsgGUID: Bsv0aYIhTKKkApieUD7jXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,219,1739865600"; d="scan'208";a="153996309" Received: from psoham-nuc7i7bnh.iind.intel.com ([10.190.216.151]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 07:03:46 -0700 From: Soham Purkait To: igt-dev@lists.freedesktop.org, riana.tauro@intel.com, vinay.belgaumkar@intel.com, kamil.konieczny@intel.com, krzysztof.karas@intel.com, zbigniew.kempczynski@intel.com Cc: anshuman.gupta@intel.com, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, soham.purkait@intel.com, ashutosh.dixit@intel.com Subject: [PATCH i-g-t v8 1/5] lib/igt_device_scan: Add support for the device filter Date: Thu, 17 Apr 2025 19:29:37 +0530 Message-Id: <20250417135941.2083761-2-soham.purkait@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417135941.2083761-1-soham.purkait@intel.com> References: <20250417135941.2083761-1-soham.purkait@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" Add support for the device filter based on driver string, device type (integrated or discrete) and card number. v5 : Add device filter to filter out      matching devices.           (Zbigniew) v6 : Move device filter with Separate      commit.                     (Zbigniew) v7 : Fix interpretation of card numbering and add 'all' option for all the cards. (Zbigniew) v8 : Fix for card filter output. (Zbigniew) Signed-off-by: Soham Purkait --- lib/igt_device_scan.c | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c index 3f26a1737..3dbe06812 100644 --- a/lib/igt_device_scan.c +++ b/lib/igt_device_scan.c @@ -1709,6 +1709,71 @@ static struct igt_list_head *filter_sriov(const struct filter_class *fcls, return &igt_devs.filtered; } +/* + * Find appropriate gpu device through matching driver, device type and + * card filter arguments. + */ +static struct igt_list_head *filter_device(const struct filter_class *fcls, + const struct filter *filter) +{ + struct igt_device *dev; + bool allcards = false; + int card = 0; + (void)fcls; + + DBG("filter device\n"); + if (filter->data.card) { + char crdop[5] = {0}; + + if (sscanf(filter->data.card, "%d", &card) == 1) { + if (card < 0) + return &igt_devs.filtered; + } else { + card = 0; + if (sscanf(filter->data.card, "%4s", crdop) == 1) { + if (!strcmp(crdop, "all")) + allcards = true; + else + return &igt_devs.filtered; + } else { + return &igt_devs.filtered; + } + } + } else { + card = 0; + } + + igt_list_for_each_entry(dev, &igt_devs.all, link) { + /* Skip if 'driver' doesn't match */ + if (filter->data.driver && !strequal(filter->data.driver, dev->driver)) + continue; + + /* Skip if 'device' doesn't match */ + if (filter->data.device && !is_device_matched(dev, filter->data.device)) + continue; + + /* We get n-th card */ + if (!allcards && !card) { + struct igt_device *dup = duplicate_device(dev); + + igt_list_add_tail(&dup->link, &igt_devs.filtered); + break; + } else if (!allcards) { + card--; + } + /* Include all the cards */ + else if (allcards) { + struct igt_device *dup = duplicate_device(dev); + + igt_list_add(&dup->link, &igt_devs.filtered); + } + } + + DBG("Filter device filtered size: %d\n", igt_list_length(&igt_devs.filtered)); + + return &igt_devs.filtered; +} + static bool sys_path_valid(const struct filter_class *fcls, const struct filter *filter) { @@ -1750,6 +1815,12 @@ static struct filter_class filter_definition_list[] = { .help = "sriov:[vendor=%04x/name][,device=%04x][,card=%d][,pf=%d][,vf=%d]", .detail = "find pf or vf\n", }, + { + .name = "device", + .filter_function = filter_device, + .help = "device:[driver=name][,device=type][,card=%d|all]", + .detail = "find device by driver name, device type and card number\n", + }, { .name = NULL, }, -- 2.34.1