[igt-dev] [PATCH i-g-t v3 1/5] lib/igt_device: Add a function to get the pci slot name

Gupta, Anshuman anshuman.gupta at intel.com
Wed Aug 9 08:12:34 UTC 2023



> -----Original Message-----
> From: Tauro, Riana <riana.tauro at intel.com>
> Sent: Wednesday, August 9, 2023 12:37 PM
> To: igt-dev at lists.freedesktop.org
> Cc: Tauro, Riana <riana.tauro at intel.com>; Gupta, Anshuman
> <anshuman.gupta at intel.com>; Dixit, Ashutosh <ashutosh.dixit at intel.com>;
> Belgaumkar, Vinay <vinay.belgaumkar at intel.com>; Nilawar, Badal
> <badal.nilawar at intel.com>; Sundaresan, Sujaritha
> <sujaritha.sundaresan at intel.com>
> Subject: [PATCH i-g-t v3 1/5] lib/igt_device: Add a function to get the pci slot
> name
> 
> The existing d3cold_allowed get/set functions in igt_pm uses igt_device_card as
> a function argument. Xe tests cannot use this function as they use pci_device.
> To have a common library function for both i915 and xe, use a common
> parameter between both igt_device_card and pci_device ie.pci_slot_name.
> 
> Add a helper function to get this pci slot name.
> 
> v2: Add justification for change in commit message (Anshuman)
> v3: assert if pci_slot_name is NULL (Anshuman)
> 
> Signed-off-by: Riana Tauro <riana.tauro at intel.com>
> Reviewed-by: Anshuman Gupta <anshuman.gupta at intel.com>
> ---
>  lib/igt_device.c | 22 ++++++++++++++++++++++  lib/igt_device.h |  1 +
>  2 files changed, 23 insertions(+)
> 
> diff --git a/lib/igt_device.c b/lib/igt_device.c index 49b771221..41007fba3
> 100644
> --- a/lib/igt_device.c
> +++ b/lib/igt_device.c
> @@ -23,6 +23,7 @@
>   */
>  #include <sys/types.h>
>  #include <fcntl.h>
> +#include <limits.h>
> 
>  #include <sys/stat.h>
>  #ifdef __linux__
> @@ -287,3 +288,24 @@ igt_device_get_pci_root_port(int fd)
> 
>  	return prev;
>  }
> +
> +/**
> + * igt_device_get_pci_slot_name:
> + * @fd: the device.
> + * @pci_slot_name: pci slot name
> + *
> + * Looks up the graphics pci device using libpciaccess
> + * and gets the slot name
> + */
> +void igt_device_get_pci_slot_name(int fd, char *pci_slot_name) {
> +	struct pci_device *pci_dev;
> +
> +	pci_dev = __igt_device_get_pci_device(fd, 0);
> +	igt_require(pci_dev);
> +
> +	snprintf(pci_slot_name, NAME_MAX, "%04x:%02x:%02x.%01x",
> +		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
> +
> +	igt_assert(pci_slot_name);
It need to be asserted before using pci_slot_name ?
Thanks,
Anshuman Gupta.
> +}
> diff --git a/lib/igt_device.h b/lib/igt_device.h index 800a0fcc3..dad7bb047
> 100644
> --- a/lib/igt_device.h
> +++ b/lib/igt_device.h
> @@ -36,4 +36,5 @@ struct pci_device *igt_device_get_pci_device(int fd);
> struct pci_device *__igt_device_get_pci_device(int fd, unsigned int vf_id);  struct
> pci_device *igt_device_get_pci_root_port(int fd);
> 
> +void igt_device_get_pci_slot_name(int fd, char *pci_slot_name);
>  #endif /* __IGT_DEVICE_H__ */
> --
> 2.40.0



More information about the igt-dev mailing list