public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>,
	Petri Latvala <petri.latvala@intel.com>,
	Ayaz A Siddiqui <ayaz.siddiqui@intel.com>
Subject: [igt-dev] [PATCH i-g-t 3/4] lib/igt_device_scan: Add extra helpers for intel_gpu_top
Date: Tue, 26 May 2020 15:24:16 +0300	[thread overview]
Message-ID: <20200526122417.779145-3-arkadiusz.hiler@intel.com> (raw)
In-Reply-To: <20200526122417.779145-1-arkadiusz.hiler@intel.com>

From: Ayaz A Siddiqui <ayaz.siddiqui@intel.com>

Will be used in the next patch.

1. set_pci_slot_name(): stores PCI_SLOT_NAME from prop to device
2. igt_device_find_first_discrete_card(): try to find first discrete GPU
3. igt_devices_free(): Free device buffers created during scan

Signed-off-by: Ayaz A Siddiqui <ayaz.siddiqui@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
---
 lib/igt_device_scan.c | 80 ++++++++++++++++++++++++++++++++++++-------
 lib/igt_device_scan.h |  7 +++-
 2 files changed, 74 insertions(+), 13 deletions(-)

diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index be854b01..4daabbd9 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -164,6 +164,7 @@ struct igt_device {
 	/* For pci subsystem */
 	char *vendor;
 	char *device;
+	char *pci_slot_name;
 
 	struct igt_list_head link;
 };
@@ -337,7 +338,21 @@ static void get_attrs(struct udev_device *dev, struct igt_device *idev)
 #define is_drm_subsystem(dev)  (strequal(get_prop_subsystem(dev), "drm"))
 #define is_pci_subsystem(dev)  (strequal(get_prop_subsystem(dev), "pci"))
 
-/* Gets PCI_ID property, splits to xxxx:yyyy and stores
+/*
+ * Get PCI_SLOT_NAME property, it should be in format of
+ * xxxx:yy:zz.z
+ */
+static void set_pci_slot_name(struct igt_device *dev)
+{
+	const char *pci_slot_name = get_prop(dev, "PCI_SLOT_NAME");
+
+	if (!pci_slot_name || (strlen(pci_slot_name) != PCI_SLOT_NAME_SIZE))
+		return;
+	dev->pci_slot_name = strdup(pci_slot_name);
+}
+
+/*
+ * Gets PCI_ID property, splits to xxxx:yyyy and stores
  * xxxx to dev->vendor and yyyy to dev->device for
  * faster access.
  */
@@ -410,6 +425,45 @@ static struct igt_device *igt_device_find(const char *subsystem,
 	return NULL;
 }
 
+static void
+__copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
+{
+	if (dev->subsystem != NULL)
+		strncpy(card->subsystem, dev->subsystem,
+			sizeof(card->subsystem) - 1);
+
+	if (dev->drm_card != NULL)
+		strncpy(card->card, dev->drm_card, sizeof(card->card) - 1);
+
+	if (dev->drm_render != NULL)
+		strncpy(card->render, dev->drm_render,
+			sizeof(card->render) - 1);
+
+	if (dev->pci_slot_name != NULL)
+		strncpy(card->pci_slot_name, dev->pci_slot_name,
+			PCI_SLOT_NAME_SIZE + 1);
+}
+
+/*
+ * Iterate over all igt_devices array and find first discrete card.
+ * card->pci_slot_name will be updated only if a discrete card is present.
+ */
+void igt_device_find_first_discrete_card(struct igt_device_card *card)
+{
+	struct igt_device *dev;
+
+	igt_list_for_each_entry(dev, &igt_devs.all, link) {
+
+		if (!is_pci_subsystem(dev))
+			continue;
+
+		if ((strncmp(dev->pci_slot_name, INTEGRATED_GPU_PCI_ID, PCI_SLOT_NAME_SIZE)) != 0) {
+			__copy_dev_to_card(dev, card);
+			break;
+		}
+	}
+}
+
 static struct igt_device *igt_device_from_syspath(const char *syspath)
 {
 	struct igt_device *dev;
@@ -445,6 +499,7 @@ static void update_or_add_parent(struct udev_device *dev,
 		parent_idev = igt_device_new_from_udev(parent_dev);
 		if (is_pci_subsystem(parent_idev)) {
 			set_vendor_device(parent_idev);
+			set_pci_slot_name(parent_idev);
 		}
 		igt_list_add_tail(&parent_idev->link, &igt_devs.all);
 	}
@@ -573,10 +628,21 @@ static void igt_device_free(struct igt_device *dev)
 	free(dev->drm_render);
 	free(dev->vendor);
 	free(dev->device);
+	free(dev->pci_slot_name);
 	g_hash_table_destroy(dev->attrs_ht);
 	g_hash_table_destroy(dev->props_ht);
 }
 
+void igt_devices_free(void)
+{
+	struct igt_device *dev, *tmp;
+
+	igt_list_for_each_entry_safe(dev, tmp, &igt_devs.all, link) {
+		igt_device_free(dev);
+		free(dev);
+	}
+}
+
 /**
  * igt_devices_scan
  * @force: enforce scanning devices
@@ -1196,17 +1262,7 @@ bool igt_device_card_match(const char *filter, struct igt_device_card *card)
 	/* We take first one if more than one card matches filter */
 	dev = igt_list_first_entry(&igt_devs.filtered, dev, link);
 
-	if (dev->subsystem != NULL)
-		strncpy(card->subsystem, dev->subsystem,
-			     sizeof(card->subsystem) - 1);
-
-	if (dev->drm_card != NULL)
-		strncpy(card->card, dev->drm_card,
-			     sizeof(card->card) - 1);
-
-	if (dev->drm_render != NULL)
-		strncpy(card->render, dev->drm_render,
-			     sizeof(card->render) - 1);
+	__copy_dev_to_card(dev, card);
 
 	return true;
 }
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index ad632145..16d75320 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -39,10 +39,13 @@ enum igt_devices_print_type {
 	IGT_PRINT_DETAIL,
 };
 
+#define INTEGRATED_GPU_PCI_ID "0000:00:02.0"
+#define PCI_SLOT_NAME_SIZE 12
 struct igt_device_card {
 	char subsystem[NAME_MAX];
 	char card[NAME_MAX];
 	char render[NAME_MAX];
+	char pci_slot_name[PCI_SLOT_NAME_SIZE+1];
 };
 
 void igt_devices_scan(bool force);
@@ -51,6 +54,8 @@ void igt_devices_print(enum igt_devices_print_type printtype);
 void igt_devices_print_vendors(void);
 void igt_device_print_filter_types(void);
 
+void igt_devices_free(void);
+
 /*
  * Handle device filter collection array.
  * IGT can store/retrieve filters passed by user using '--device' args.
@@ -63,7 +68,7 @@ const char *igt_device_filter_get(int num);
 
 /* Use filter to match the device and fill card structure */
 bool igt_device_card_match(const char *filter, struct igt_device_card *card);
-
+void igt_device_find_first_discrete_card(struct igt_device_card *card);
 int igt_open_card(struct igt_device_card *card);
 int igt_open_render(struct igt_device_card *card);
 
-- 
2.25.4

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2020-05-26 12:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 12:24 [igt-dev] [PATCH i-g-t 1/4] lib/igt_device_scan: Add missing Check for return value in scan_drm_devices Arkadiusz Hiler
2020-05-26 12:24 ` [igt-dev] [PATCH i-g-t 2/4] lib/igt_device_scan: Make igt_device_scan independent from igt_core Arkadiusz Hiler
2020-05-26 16:14   ` Lucas De Marchi
2020-05-27  7:48     ` Arkadiusz Hiler
2020-05-27  8:08       ` Petri Latvala
2020-05-26 12:24 ` Arkadiusz Hiler [this message]
2020-05-26 16:26   ` [igt-dev] [PATCH i-g-t 3/4] lib/igt_device_scan: Add extra helpers for intel_gpu_top Lucas De Marchi
2020-05-27  5:32     ` Siddiqui, Ayaz A
2020-05-28 10:27     ` Tvrtko Ursulin
2020-05-28 11:40       ` Arkadiusz Hiler
2020-05-26 12:24 ` [igt-dev] [PATCH i-g-t 4/4] tools/intel_gpu_top: Add support of discrete GPU and card selection Arkadiusz Hiler
2020-05-28 14:28   ` Tvrtko Ursulin
2020-05-26 13:17 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] lib/igt_device_scan: Add missing Check for return value in scan_drm_devices Patchwork
2020-05-26 16:06 ` [igt-dev] [PATCH i-g-t 1/4] " Lucas De Marchi
2020-05-26 17:38 ` [igt-dev] ✗ Fi.CI.IGT: failure for series starting with [i-g-t,1/4] " Patchwork
2020-05-28 10:47 ` [igt-dev] [PATCH i-g-t 1/4] " Mika Kuoppala
  -- strict thread matches above, loose matches on Subject: below --
2020-06-02 11:13 Arkadiusz Hiler
2020-06-02 11:13 ` [igt-dev] [PATCH i-g-t 3/4] lib/igt_device_scan: Add extra helpers for intel_gpu_top Arkadiusz Hiler
2020-06-05 12:11   ` Petri Latvala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200526122417.779145-3-arkadiusz.hiler@intel.com \
    --to=arkadiusz.hiler@intel.com \
    --cc=ayaz.siddiqui@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    --cc=tvrtko.ursulin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox