Hi Janusz,
On 2026-02-05 at 15:51:55 +0100, Janusz Krzysztofik wrote:
> In a short listing, lsgpu prints a sysfs path of a PCI GPU parent as a
> local attribute of a DRM device.  However, if that's a discrete GPU and
> its associated PCIe upstream bridge port has been identified, no
> information on that bridge is listed among the GPU attributes.  Follow the
> pattern used with DRM devices and also show a PCI slot of the bridge port
> as a local attribute of the discrete GPU device.
> 
> Moreover, in both short and detailed listings, local attributes intended
> for providing device names of GPU associated DRM devices and the GPU
> codename are also printed as attributes of related PCIe upstream bridge
> port, however, the DRM device names are shown as (null), and the codename
> attribute provides raw vendor:device codes of the bridge itself.  Replace
> those with PCI slot and codename of the GPU device.
> 
> v4: Free already allocated numeric codename before replacing (Sebastian),
>   - visually separate bridge specific updates of attributes already
>     populated by find_or_add_igt_device from bridge specific attribute
>     assignments.
> v2: Allocate memory to local attributes of a bridge for safety (Sebastian),
>   - merge with a formerly separate patch "lib/igt_device_scan: Don't print
>     bridge not applicable attributes" (Sebastian),
>   - no need for DEVTYPE_BRIDGE, just skip attributes if NULL.
> 
> Cc: Sebastian Brzezinka <[email protected]>
> Signed-off-by: Janusz Krzysztofik <[email protected]>

LGTM
Reviewed-by: Kamil Konieczny <[email protected]>

Regards,
Kamil

> ---
>  lib/igt_device_scan.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
> index d7ec6c2b96..fc01fc375b 100644
> --- a/lib/igt_device_scan.c
> +++ b/lib/igt_device_scan.c
> @@ -254,6 +254,8 @@ struct igt_device {
>       char *codename; /* For grouping by codename */
>       enum dev_type dev_type; /* For grouping by integrated/discrete */
>  
> +     char *pci_gpu; /* Filled for upstream bridge ports */
> +
>       struct igt_list_head link;
>  };
>  
> @@ -1068,6 +1070,12 @@ static void update_or_add_parent(struct udev *udev,
>  
>       /* override DEVTYPE_INTEGRATED so link attributes won't be omitted */
>       bridge_idev->dev_type = DEVTYPE_ALL;
> +     /* free numeric codename before overwriting with GPU codename */
> +     free(bridge_idev->codename);
> +     bridge_idev->codename = strdup(parent_idev->codename);
> +
> +     bridge_idev->pci_gpu = strdup(parent_idev->pci_slot_name);
> +     parent_idev->parent = bridge_idev;
>  }
>  
>  static struct igt_device *duplicate_device(struct igt_device *dev) {
> @@ -1239,6 +1247,7 @@ static void igt_device_free(struct igt_device *dev)
>       free(dev->device);
>       free(dev->driver);
>       free(dev->pci_slot_name);
> +     free(dev->pci_gpu);
>       igt_map_destroy(dev->attrs_map, free_key_value);
>       igt_map_destroy(dev->props_map, free_key_value);
>  }
> @@ -1335,7 +1344,11 @@ igt_devs_print_simple(struct igt_list_head *view,
>                       if (is_pci_subsystem(dev)) {
>                               _pr_simple("vendor", dev->vendor);
>                               _pr_simple("device", dev->device);
> +                             if (dev->pci_gpu)
> +                                     _pr_simple("GPU device", dev->pci_gpu);
>                               _pr_simple("codename", dev->codename);
> +                             if (dev->parent && dev->parent->pci_slot_name)
> +                                     _pr_simple("upstream port", 
> dev->parent->pci_slot_name);
>                       }
>               }
>               printf("\n");
> @@ -1488,8 +1501,12 @@ igt_devs_print_detail(struct igt_list_head *view,
>               printf("========== %s:%s ==========\n",
>                      dev->subsystem, dev->syspath);
>               if (!is_drm_subsystem(dev)) {
> -                     _print_key_value("card device", dev->drm_card);
> -                     _print_key_value("render device", dev->drm_render);
> +                     if (dev->drm_card)
> +                             _print_key_value("card device", dev->drm_card);
> +                     if (dev->drm_render)
> +                             _print_key_value("render device", 
> dev->drm_render);
> +                     if (dev->pci_gpu)
> +                             _print_key_value("GPU device", dev->pci_gpu);
>                       _print_key_value("codename", dev->codename);
>               }
>  
> -- 
> 2.52.0
> 

Reply via email to