PCI and USB devices in the /sys/devices tree, with uevents and USB hot-plug
PCI devices live at /sys/devices/pci0000:00/<addr> and USB devices under the xHCI controller that carries their bus, below that bus's root hub usbN; /sys/bus/pci/devices and /sys/bus/usb/devices are symlinks into it, and every device has its subsystem and driver links, which is how udev learns SUBSYSTEM and DRIVER. Writing to a device's uevent now announces it with MODALIAS, PCI_ID, PRODUCT and the rest, so udevadm trigger covers them, and the USB core sends add when a device is attached and remove as it goes. The root hub is announced when the controller comes up, before anything is plugged in. Checked under QEMU: lspci and udevadm info through the links, udevadm monitor showing the kernel and udev add event for device_add usb-kbd/usb-mouse and the remove event for device_del, and a triggered add for usb1 and 1-5. Known limits: the bus-to-controller mapping is a convention (bus N is the Nth xHCI in PCI order); PCI bridges are not parents; USB interfaces and /dev/bus/usb nodes are absent; busybox's lsusb reads /dev/bus/usb and prints nothing. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EVRhxi9zpdW2uDUN4FVcao
This commit is contained in:
parent
dee3affa3b
commit
8d836c66b2
8 changed files with 526 additions and 67 deletions
|
|
@ -32,6 +32,7 @@
|
|||
#include "fs/file.h"
|
||||
#include "dev/pci.h"
|
||||
#include "dev/usb.h"
|
||||
#include "core/hwinfo.h"
|
||||
#include "xhci.h"
|
||||
|
||||
#define RING_TRBS 64 // TRBs per ring, including the link
|
||||
|
|
@ -1673,6 +1674,11 @@ xhci_probe(struct pci_dev *d)
|
|||
kinfo("xhci: no devices attached\n");
|
||||
|
||||
|
||||
// Number the bus and announce its root hub before the first port can be
|
||||
// scanned, so `usbN` is in /sys, and udev knows of it, ahead of anything
|
||||
// plugged into it.
|
||||
usb_bus_add(x);
|
||||
|
||||
// Now, and only now, turn interrupts on. The order is: claim the line
|
||||
// (which unmasks it and sets level/active-low), clear anything the
|
||||
// controller already considers pending so that it drives INTx low, and then
|
||||
|
|
|
|||
Loading…
Reference in a new issue