Giter Site home page Giter Site logo

synapticsmst: Add udev support about fwupd HOT 6 CLOSED

fwupd avatar fwupd commented on June 26, 2024
synapticsmst: Add udev support

from fwupd.

Comments (6)

hughsie avatar hughsie commented on June 26, 2024

I would much perfer using udev for getting the device nodes! Thanks for looking into this.

from fwupd.

superm1 avatar superm1 commented on June 26, 2024

Yeah me too. I'm not yet sure if udev will actually indicate the drm-dp-aux node to use, but at least using that to figure out when to run re-enumeration sounds better.

from fwupd.

hughsie avatar hughsie commented on June 26, 2024

g_udev_device_get_device_file() should give you the node to use, although you might have to walk up to the parent device (or grandparent) -- I think one of the other plugins (logitech?) does this already.

from fwupd.

superm1 avatar superm1 commented on June 26, 2024

I've done some experimenting with what info can be gleamed from udev, but it's still not perfect, or even much better than what you get from walking the sysfs directory for drm_dp_aux nodes.

Plugging in a dock with no monitors here's everything that udev will spit out:

# udevadm monitor
KERNEL[638595.584753] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0 (pci)
UDEV  [638595.585608] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0 (pci)
KERNEL[638595.596185] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/pci_bus/0000:07 (pci_bus)
KERNEL[638595.596504] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0 (pci)
KERNEL[638595.596964] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:01.0 (pci)
UDEV  [638595.597072] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/pci_bus/0000:07 (pci_bus)
KERNEL[638595.597135] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0 (pci)
KERNEL[638595.597287] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0/pci_bus/0000:08 (pci_bus)
KERNEL[638595.597374] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:01.0/pci_bus/0000:09 (pci_bus)
KERNEL[638595.597483] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/pci_bus/0000:3e (pci_bus)
UDEV  [638595.597768] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0 (pci)
KERNEL[638595.597888] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0 (pci)
UDEV  [638595.598003] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0 (pci)
UDEV  [638595.598232] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:01.0 (pci)
UDEV  [638595.598273] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0/pci_bus/0000:08 (pci_bus)
KERNEL[638595.598369] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:06:00.0:pcie108 (pci_express)
KERNEL[638595.598632] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0/0000:07:00.0:pcie208 (pci_express)
UDEV  [638595.598730] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/pci_bus/0000:3e (pci_bus)
UDEV  [638595.598884] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:01.0/pci_bus/0000:09 (pci_bus)
KERNEL[638595.598902] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:01.0/0000:07:01.0:pcie208 (pci_express)
KERNEL[638595.599154] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:07:02.0:pcie208 (pci_express)
UDEV  [638595.600059] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0 (pci)
UDEV  [638595.600081] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:07:02.0:pcie208 (pci_express)
UDEV  [638595.600094] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:01.0/0000:07:01.0:pcie208 (pci_express)
UDEV  [638595.600106] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0/0000:07:00.0:pcie208 (pci_express)
UDEV  [638595.600321] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:06:00.0:pcie108 (pci_express)
KERNEL[638595.601057] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3 (usb)
KERNEL[638595.601092] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-0:1.0 (usb)
KERNEL[638595.601325] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4 (usb)
KERNEL[638595.601361] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-0:1.0 (usb)
UDEV  [638596.113240] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4 (usb)
UDEV  [638596.113615] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3 (usb)
UDEV  [638596.117491] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-0:1.0 (usb)
UDEV  [638596.118182] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-0:1.0 (usb)
KERNEL[638596.264835] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1 (usb)
KERNEL[638596.265505] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1:1.0 (usb)
KERNEL[638596.524687] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1 (usb)
KERNEL[638596.525196] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1:1.0 (usb)
KERNEL[638596.629397] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2 (usb)
KERNEL[638596.630368] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.0 (usb)
KERNEL[638596.631548] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.1 (usb)
KERNEL[638596.631746] remove   /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.0 (usb)
KERNEL[638596.631818] remove   /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.1 (usb)
KERNEL[638596.633706] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0 (usb)
UDEV  [638596.789032] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1 (usb)
UDEV  [638596.792293] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1:1.0 (usb)
KERNEL[638596.792557] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/eth0 (net)
KERNEL[638596.792610] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/eth0/queues/rx-0 (queues)
KERNEL[638596.792642] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/eth0/queues/tx-0 (queues)
KERNEL[638596.992313] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5 (usb)
KERNEL[638596.993853] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0 (usb)
UDEV  [638597.040679] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1 (usb)
UDEV  [638597.045810] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1:1.0 (usb)
UDEV  [638597.334612] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2 (usb)
UDEV  [638597.339468] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.1 (usb)
UDEV  [638597.339526] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.0 (usb)
UDEV  [638597.340423] remove   /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.1 (usb)
UDEV  [638597.340447] remove   /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:2.0 (usb)
KERNEL[638597.853167] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1 (sound)
KERNEL[638597.853386] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/controlC1 (sound)
KERNEL[638597.853599] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/pcmC1D0p (sound)
KERNEL[638597.853816] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/pcmC1D0c (sound)
KERNEL[638597.853934] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/pcmC1D1p (sound)
KERNEL[638597.854117] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.1 (usb)
KERNEL[638597.854181] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.2 (usb)
KERNEL[638597.854268] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.3 (usb)
UDEV  [638598.504461] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0 (usb)
KERNEL[638598.506432] move     /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/enx204747f56b17 (net)
UDEV  [638598.544373] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/enx204747f56b17 (net)
UDEV  [638598.550785] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/eth0/queues/rx-0 (queues)
UDEV  [638598.551207] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/eth0/queues/tx-0 (queues)
UDEV  [638598.551864] move     /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb4/4-1/4-1.2/4-1.2:1.0/net/enx204747f56b17 (net)
UDEV  [638599.024980] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5 (usb)
UDEV  [638599.030186] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.1 (usb)
UDEV  [638599.030248] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.2 (usb)
UDEV  [638599.030286] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0 (usb)
UDEV  [638599.030307] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.3 (usb)
UDEV  [638599.030935] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1 (sound)
KERNEL[638599.033226] change   /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1 (sound)
UDEV  [638599.033408] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/pcmC1D0p (sound)
UDEV  [638599.033435] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/pcmC1D0c (sound)
UDEV  [638599.033686] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/pcmC1D1p (sound)
UDEV  [638599.037660] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1/controlC1 (sound)
UDEV  [638599.038729] change   /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.5/3-1.5:1.0/sound/card1 (sound)
KERNEL[638599.686995] change   /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[638599.693093] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [638599.693835] change   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
KERNEL[638599.724278] add      /module/thinkpad_acpi (module)
UDEV  [638599.725062] add      /module/thinkpad_acpi (module)
KERNEL[638599.744377] remove   /module/thinkpad_acpi (module)
UDEV  [638599.745064] remove   /module/thinkpad_acpi (module)
UDEV  [638600.370563] change   /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/AC (power_supply)

Unfortunately none of that is even remotely relevant to the drm_dp_aux_dev subsystem, so it's not a good mapping to know to re-scan any particular nodes.

Using fu-dell-tool to forcefully turn on the MST hub will get a bunch of change events in the DRM subsystem, but not in drm_dp_aux_dev.


KERNEL[638655.889405] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0/0000:08:00.0 (pci)
UDEV  [638655.892206] add      /devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:00.0/0000:08:00.0 (pci)
KERNEL[638657.084629] add      /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-3 (drm)
KERNEL[638657.084725] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
KERNEL[638657.084770] add      /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-4 (drm)
KERNEL[638657.084839] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.088992] add      /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-3 (drm)
UDEV  [638657.090987] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
KERNEL[638657.093614] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
KERNEL[638657.093686] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.094504] add      /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-4 (drm)
UDEV  [638657.096381] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.097740] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.099105] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
KERNEL[638657.100149] add      /devices/pci0000:00/0000:00:02.0/i2c-8/i2c-dev/i2c-8 (i2c-dev)
KERNEL[638657.100200] add      /devices/pci0000:00/0000:00:02.0/i2c-8 (i2c)
KERNEL[638657.100612] add      /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-5 (drm)
KERNEL[638657.100707] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
KERNEL[638657.100785] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.102394] add      /devices/pci0000:00/0000:00:02.0/i2c-8/i2c-dev/i2c-8 (i2c-dev)
UDEV  [638657.103624] add      /devices/pci0000:00/0000:00:02.0/i2c-8 (i2c)
UDEV  [638657.105805] add      /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-5 (drm)
UDEV  [638657.107428] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.109199] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
KERNEL[638657.367016] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [638657.369412] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)

The MST hub happens to be hanging off of the drm_dp_aux child of /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1 which actually wasn't even in the change list!

This is the node that the MST hub actually hangs off of in udev's DB:

P: /devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1/drm_dp_aux1
N: drm_dp_aux1
E: DEVNAME=/dev/drm_dp_aux1
E: DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1/drm_dp_aux1
E: MAJOR=245
E: MINOR=1
E: SUBSYSTEM=drm_dp_aux_dev

Given that, I'm inclined to think that the only real value in adding udev is to get change events from when monitors are plugged in to redo enumeration. Any other thoughts from your side?

from fwupd.

superm1 avatar superm1 commented on June 26, 2024

I've done more experimenting with this and don't think it's a good idea to add gudev in. The whole thing is too racy with intermingled dependencies.
Dock MST hubs won't show up until a recoldpug (from coldplug_prepare). So if you just drop gusb and look for a change event related to new display outputs, you won't know that you need to do a recoldplug when plugging in the dock.

So if you use usb to schedule a recoldplug, then you get into an endless loop of executing recoldplugs. The coldplug_prepare from usb turns on MST hubs which generates change events. By the time that the coldplug from gusb is done the coldplug from the change events will go off. Furthermore too many change events come in at once, so you need a timer to buffer them (similar to how fu-plugin-thunderbolt worked).

This is my current working patch, but I'm leaning upon just dropping it and not using gudev at all.

diff --git a/plugins/synapticsmst/Makefile.am b/plugins/synapticsmst/Makefile.am
index d1577e7..f12baec 100644
--- a/plugins/synapticsmst/Makefile.am
+++ b/plugins/synapticsmst/Makefile.am
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = 							\
 	$(APPSTREAM_GLIB_CFLAGS)				\
 	$(GLIB_CFLAGS)						\
+	$(GUDEV_CFLAGS)						\
 	$(GUSB_CFLAGS)						\
 	$(LIBSMBIOS_CFLAGS)					\
 	$(PIE_CFLAGS)						\
@@ -29,6 +30,7 @@ libfu_plugin_synapticsmst_la_SOURCES =				\
 
 libfu_plugin_synapticsmst_la_LIBADD =				\
 	$(GUSB_LIBS)						\
+	$(GUDEV_LIBS)						\
 	$(LIBSMBIOS_LIBS)					\
 	$(GLIB_LIBS)
 libfu_plugin_synapticsmst_la_LDFLAGS = -module -avoid-version
diff --git a/plugins/synapticsmst/fu-plugin-synapticsmst.c b/plugins/synapticsmst/fu-plugin-synapticsmst.c
index 8e18177..672e91d 100644
--- a/plugins/synapticsmst/fu-plugin-synapticsmst.c
+++ b/plugins/synapticsmst/fu-plugin-synapticsmst.c
@@ -28,9 +28,17 @@
 #include "fu-dell-common.h"
 #include "fu-plugin.h"
 #include "fu-plugin-vfuncs.h"
+#include <gudev/gudev.h>
 
+#define SYNAPTICS_RESCAN_DELAY 3000 /* ms */
 #define SYNAPTICS_FLASH_MODE_DELAY 3
 
+struct FuPluginData {
+	GUdevClient             *gudev_client;
+	guint			refresh_id;
+};
+
+
 static gboolean
 synapticsmst_common_check_supported_system (GError **error)
 {
@@ -331,6 +339,33 @@ fu_plugin_update_online (FuPlugin *plugin,
 
 	return TRUE;
 }
+static gboolean
+fu_plugin_synapticsmst_schedule_rescan_cb (gpointer user_data)
+{
+	FuPlugin *plugin = FU_PLUGIN (user_data);
+	FuPluginData *data = fu_plugin_get_data (plugin);
+
+	/* no longer valid */
+	data->refresh_id = 0;
+
+	g_debug ("Timer executed!");
+	/* rescan */
+	fu_plugin_recoldplug (plugin);
+	return FALSE;
+}
+
+static void
+fu_plugin_synapticsmst_schedule_rescan (FuPlugin *plugin)
+{
+	FuPluginData *data = fu_plugin_get_data (plugin);
+
+	/* wait for change events to settle, this will reset them */
+	if (data->refresh_id != 0)
+		g_source_remove (data->refresh_id);
+	data->refresh_id = g_timeout_add (SYNAPTICS_RESCAN_DELAY,
+					  fu_plugin_synapticsmst_schedule_rescan_cb,
+					  plugin);
+}
 
 static void
 fu_plugin_synapticsmst_redo_enumeration_cb (GUsbContext *ctx,
@@ -348,7 +383,17 @@ fu_plugin_synapticsmst_redo_enumeration_cb (GUsbContext *ctx,
 		return;
 
 	/* Request daemon to redo coldplug, this wakes up Dell devices */
-	fu_plugin_recoldplug (plugin);
+	fu_plugin_synapticsmst_schedule_rescan (plugin);
+}
+
+static void
+fu_plugin_udev_uevent_cb (GUdevClient *gudev_client,
+			  const gchar *action,
+			  GUdevDevice *udev_device,
+			  FuPlugin *plugin)
+{
+	if (g_strcmp0 (action, "change") == 0)
+		fu_plugin_synapticsmst_schedule_rescan (plugin);
 }
 
 gboolean
@@ -366,6 +411,25 @@ fu_plugin_startup (FuPlugin *plugin, GError **error)
 	return TRUE;
 }
 
+void
+fu_plugin_init (FuPlugin *plugin) {
+	FuPluginData *data = fu_plugin_alloc_data (plugin, sizeof (FuPluginData));
+	const gchar *subsystems[] = { "drm", NULL };
+
+	data->gudev_client = g_udev_client_new (subsystems);
+	g_signal_connect (data->gudev_client, "uevent",
+			  G_CALLBACK (fu_plugin_udev_uevent_cb), plugin);
+}
+
+void
+fu_plugin_destroy (FuPlugin *plugin)
+{
+	FuPluginData *data = fu_plugin_get_data (plugin);
+	if (data->refresh_id != 0)
+		g_source_remove (data->refresh_id);
+	g_object_unref (data->gudev_client);
+}
+
 gboolean
 fu_plugin_coldplug (FuPlugin *plugin, GError **error)
 {

from fwupd.

hughsie avatar hughsie commented on June 26, 2024

I think half the problem is that the g_usleep() in the prepare loop isn't allowing the mainloop to run, so you don't get signals emitted. I don't think we want to spin the main loop here, there's too much other stuff that could break. Lets leave what works in git and revisit if/when required.

from fwupd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.