technosaurus wrote:Ibidem wrote:FYI, I've written an experimental library intended to use as a fallback/replacement for some of the features libudev offers.
Right now it only will map a device to a sysfs directory and get the PCI IDs if they're available.
Source is over at
https://github.com/idunham/libsysdev; the first port of anything to use it is
https://github.com/idunham/xf86-input-evdev, branch sysdev
The API is intended to make porting Mesa to it simple.
There's no "listen for events" code, though. I might see about something to make it easy to listen to inotify events in /dev/input and /dev/block or /dev/disk.
I may be wrong, but I think those events are handled internally -- it needs help with hot plug events such as plugging in a wireless mouse after X is running.
Might I ask what "those events" refers to in your comment?
The inotify bit is one possible way of listening for hotplug events.
Hotplugging a GPU/input device means a new device appears in /dev/dri or /dev/input, or an old one disappears; I'm figuring that we can check for that by means of an inotify watch.
As far as I can tell after skimming xorg-xserver source, there are several possible "config" backends for the X server that seem to be responsible for hotplugging; the main code for these is in config/<backend>.c, and I can't really tell exactly where they hook up or how X listens for hotplug events.
I do know config/config.c calls the setup and teardown needed for "the current config backend", and include/hotplug.h declares the functions in config/config.c.
You can build the server with any one of several config backends, or with none; wscons, udev, and HAL are the currently available backends.
Each of these will try to figure out an appropriate driver for each device, then load that driver specifying the device.
When evdev is the driver loaded, it will check whether an input device is "virtual" or not (meaning roughly "is it a pointer or keyboard, or is it something else?") so it knows whether to refuse to proceed.
The way evdev checks this is by finding the corresponding sysfs path and checking if it contains the string "LNXSYSTEM"--if evdev finds that string, it bails out.
Generating this path is currently done by libudev.
mesa somehow-or-other ends up with an fd for a DRI device (without using udev), then uses udev (or some sysfs fallback code that you must manually enable) to get the corresponding PCI ids and parses those PCI ids to determine the mesa driver.
...Ah, that's it: the udev backend installs a wakeup handler (named wakeup_handler(), of course) with RegisterBlockAndWakeupHandlers(). But I'm not sure exactly how all that works; it's a bit above my pay grade
. Perhaps udev sends a signal, perhaps it's something along the lines of select() on a socket...