[PATCH i-g-t v6 1/5] lib/igt_device_scan: Add support for the device filter

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Apr 8 05:44:36 UTC 2025


On Fri, Apr 04, 2025 at 06:54:17PM +0530, Soham Purkait wrote:
>      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)

Drop versioning in final version of your series.

> 
> Signed-off-by: Soham Purkait <soham.purkait at intel.com>
> ---
>  lib/igt_device_scan.c | 58 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
> 
> diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
> index 3f26a1737..ea14d8e23 100644
> --- a/lib/igt_device_scan.c
> +++ b/lib/igt_device_scan.c
> @@ -1709,6 +1709,58 @@ 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;
> +	int card = -1;
> +	(void)fcls;
> +
> +	DBG("filter device\n");
> +
> +	if (filter->data.card) {
> +		sscanf(filter->data.card, "%d", &card);
> +		if (card < 0)
> +			return &igt_devs.filtered;
> +	} else {
> +		card = -1;
> +	}

I would change this a little bit to be consistent with other
filters which assumes if you don't pass card=n it means n == 0.

Consider to introduce card=all. Add some bool like 'allcards=false',
then if there's successful 'all' string scan collect all cards like
you're doing this now for -1. Then scan card=%d, finally assuming 0
if there's filter->data.card was passed.

> +
> +	igt_list_for_each_entry(dev, &igt_devs.all, link) {
> +

Unnecessary blank line.

> +		/* 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 (!card) {
> +			struct igt_device *dup = duplicate_device(dev);
> +
> +			igt_list_add_tail(&dup->link, &igt_devs.filtered);
> +			break;
> +		}
> +		/* Include all the card */
> +		else if (card == -1) {
> +			struct igt_device *dup = duplicate_device(dev);
> +
> +			igt_list_add(&dup->link, &igt_devs.filtered);
> +		} else
> +			card--;
> +	}
> +
> +	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 +1802,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]",

.help = "device:[driver=name][,device=type][,card=%d|all]",

--
Zbigniew

> +		.detail = "find device by driver name, device type and card number\n",
> +	},
>  	{
>  		.name = NULL,
>  	},
> -- 
> 2.34.1
> 


More information about the igt-dev mailing list