Skip to content

Bus Drivers

opencode-agent[bot] edited this page May 10, 2026 · 2 revisions

Bus Drivers

Subsystem for enumerating and managing bus devices (PCI, USB, PCMCIA, SMBus).

Overview

JNode's Bus Drivers subsystem provides the infrastructure for discovering and managing devices on different system buses. Each bus type implements a common Bus base class and provides bus-specific protocols for device enumeration, resource allocation, and driver binding.

The system supports four bus types:

  • PCI: Primary system bus for connecting expansion cards and integrated peripherals
  • USB: Universal Serial Bus for external device connectivity
  • PCMCIA/CardBus: Legacy bus for removable cards (laptops, embedded)
  • SMBus: System Management Bus for hardware monitoring and smart battery communication

Each bus driver integrates with the DeviceManager to register discovered devices and bind appropriate drivers based on device identifiers.

Key Components

Class / File Role
core/src/driver/org/jnode/driver/bus/pci/PCIBus.java PCI bus implementation with device probing and bridge enumeration
core/src/driver/org/jnode/driver/bus/pci/PCIBusAPI.java PCI bus device lookup interface
core/src/driver/org/jnode/driver/bus/pci/PCIDriver.java PCI system driver, coordinates all PCI buses
core/src/driver/org/jnode/driver/bus/pci/PCIDevice.java PCI device representation with configuration space access
core/src/driver/org/jnode/driver/bus/usb/USBBus.java USB bus with device ID allocation
core/src/driver/org/jnode/driver/bus/usb/USBDevice.java USB device with descriptor parsing
core/src/driver/org/jnode/driver/bus/usb/USBHostControllerAPI.java Host controller hardware abstraction
core/src/driver/org/jnode/driver/bus/usb/uhci/UHCIDriver.java UHCI USB controller driver
core/src/driver/org/jnode/driver/bus/pcmcia/CardBusBus.java CardBus (PCMCIA) bus implementation
core/src/driver/org/jnode/driver/bus/pcmcia/CardBusDriver.java CardBus controller driver
core/src/driver/org/jnode/driver/bus/smbus/SMBus.java SMBus implementation with address constants
core/src/driver/org/jnode/driver/bus/smbus/SMBusControler.java SMBus controller driver
core/src/driver/org/jnode/driver/Bus.java Base class for all bus implementations

How It Works

PCI Bus Enumeration

The PCI bus driver performs a depth-first enumeration of the PCI hierarchy:

  1. Probe: PCIBus.probeDevices() scans bus device/function pairs (0-31/0-7)
  2. Configuration Access: Each present device is read via PCIDeviceConfig (configuration space)
  3. Multi-function Detection: If a device is multi-functional, each function is scanned
  4. Bridge Enumeration: PCI-to-PCI bridges trigger recursive probing of child buses
  5. Driver Binding: PCIDeviceToDriverMapper maps PCI class/code to appropriate drivers
// PCI enumeration pattern (PCIBus.java:79-100)
protected void probeDevices(List<PCIDevice> result) {
    for (int i = 0; i < MAX_UNITS; i++) {
        PCIDevice dev = createDevice(i, 0);
        if (dev != null) {
            list.add(dev);
            if (dev.getConfig().isMultiFunctional()) {
                for (int f = 1; f < MAX_FUNCTIONS; f++) {
                    dev = createDevice(i, f);
                    if (dev != null) list.add(dev);
                }
            }
        }
    }
    // Probe bridges to child buses
    for (PCIDevice dev : list) {
        if (dev.isBridge()) {
            createChildBus(dev).probeDevices(result);
        }
    }
}

USB Bus Enumeration

USB uses a tree topology with hub-based device discovery:

  1. Host Controller: USB host controller (UHCI/OHCI/EHCI) provides hardware access
  2. Root Hub: Each controller has an embedded root hub with ports
  3. Hub Polling: USBHubMonitor polls hub status for device connect/disconnect
  4. Device Address Assignment: USBBus.allocDeviceID() assigns 7-bit device addresses
  5. Descriptor Retrieval: Device descriptors are read to identify supported configurations
  6. Driver Binding: Device class/subclass matching via DeviceToDriverMapper

PCMCIA/CardBus

CardBus bridges appear as PCI devices and are enumerated through the PCI layer:

  • CardBus controller is a PCI device
  • Cards are probed as child PCI buses
  • Supports both 16-bit PCMCIA and 32-bit CardBus cards

SMBus

SMBus uses a simple address-based protocol:

  • Fixed address range for standard devices (host, batteries, chargers)
  • SMBusControler performs transactions (quick command, byte, word, block)
  • DIMM detection via DIMMDriver for memory module identification

Gotchas & Non-Obvious Behavior

  • PCI configuration space: Access requires I/O port 0xCF8/0xCFC (legacy) or MMIO (newer)
  • PCI bridges: Must enumerate child buses recursively; bridges have type-specific headers
  • USB device IDs: Limited to 127 devices per controller; ID 0 reserved
  • USB power: Hub ports may provide limited current; power management needed
  • Hot-plug: USB supports dynamic connect/disconnect; PCMCIA/CardBus vary by hardware
  • SMBus addresses: Some addresses are reserved; not all SMBus devices respond to standard protocols
  • Resource conflicts: PCI BARs must not overlap; OS must track allocated I/O and memory ranges
  • Multi-function PCI: Each function appears as separate device but shares slot resources

Related Pages

Clone this wiki locally