[Spice-devel] [RFC linux vdagent] Add POC for getting xrandr output from monitor ID

Gerd Hoffmann kraxel at redhat.com
Tue Nov 13 08:04:19 UTC 2018


  Hi,

> To look up a PCI device by address, I could use the /sys filesystem. So
> for pci/0000/02.0, I would translate the domain 0000 into the
> filesystem path '/sys/devices/pci0000:00/' assuming bus '00'?  And then
> look inside that directory for the the path '0000:00:02.0'. And then
> look for a path named 'drm' within that directory to determine whether
> it's a drm card or not? Is the existence of the 'drm' directory the
> thing that we should use to determine whether this is a drm card? 

Typically yes, except virtio-gpu which has an additional virtio level,
i.e. /sys/devices/pci0000:00/0000:00:02.0/virtio<n>/drm.

> Or a slightly more complicated example (based on my laptop): Let's look
> for this device:
> 
> 02:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 940MX] (rev
> a2)
> 
> So it's device 00.0 on bus 02. Here's the first part of lspci -t:
> -[0000:00]-+-00.0
>            +-01.0-[01]--
>            +-01.2-[02]----00.0
> 
> So it's attached to the PCI bridge at 01.2. Since the bus number ('02')
> is not a part of our device address format, we would only be provided
> the following address: pci/0000/01.2/00.0
> 
> From this we can look for the PCI bridge at path
> /sys/devices/pci0000:00/0000:00:01.2. Within this directory, we can
> look for a path of ... it's unclear because we're not provided the bus
> number, so we can't necessarily construct the path '0000:02:00.0' that
> represents this device. We could simply look for files within the
> directory that end with '00.0' and just assume that the one we find is
> the correct one. But that doesn't seem cleaner and more elegant to me.

You can translate the path into a sysfs shell globbing pattern, then
feed that into glob (see "man glob").

For "pci/0000/01.2/00.0" the glob pattern would be
"/sys/devices/pci0000:*/*:01.2/*:00.0"

HTH,
  Gerd



More information about the Spice-devel mailing list