# Module auto-loading for PCI devices?



## Hornpipe2 (May 17, 2019)

I have several questions about hardware driver module loading.

When I run `pciconf -l -v`, I see output for the various devices in my system, like so:

```
hostb0@pci0:0:0:0:      class=0x060000 card=0x3084103c chip=0x35808086 rev=0x02 hdr=0x00
    vendor     = 'Intel Corporation'
    device     = '82852/82855 GM/GME/PM/GMV Processor to I/O Controller'
    class      = bridge
    subclass   = HOST-PCI
none0@pci0:0:0:1:       class=0x088000 card=0x3084103c chip=0x35848086 rev=0x02 hdr=0x00
    vendor     = 'Intel Corporation'
    device     = '82852/82855 GM/GME/PM/GMV Processor to I/O Controller'
    class      = base peripheral
none1@pci0:0:0:3:       class=0x088000 card=0x3084103c chip=0x35858086 rev=0x02 hdr=0x00
    vendor     = 'Intel Corporation'
    device     = '82852/82855 GM/GME/PM/GMV Processor to I/O Controller'
    class      = base peripheral
vgapci0@pci0:0:2:0:     class=0x030000 card=0x3084103c chip=0x35828086 rev=0x02 hdr=0x00
    vendor     = 'Intel Corporation'
    device     = '82852/855GM Integrated Graphics Device'
    class      = display
    subclass   = VGA
...
```

Some devices have their drivers loaded already, while others don't (those beginning with "none").  I have found some devices can have their drivers loaded at run-time by the appropriate `kldload` invocation.  For example, my motherboard SMBus was originally not supported, but by executing `kldload ichsmb` (or adding it to the `kld_list=` in /etc/rc.conf), the driver finds the hardware and changes the output line to this:

```
ichsmb0@pci0:0:31:3:    class=0x0c0500 card=0x3084103c chip=0x24c38086 rev=0x03 hdr=0x00
    vendor     = 'Intel Corporation'
    device     = '82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) SMBus Controller'
    class      = serial bus
    subclass   = SMBus
```

This leaves me with some questions:

Why aren't these drivers automatically loaded at boot?  The Realtek NIC driver is auto-loaded, for example, but the SMBus driver is not.  Why do I have to manually load some but not others?
How can I find out which drivers need loading for the undetected hardware?  For example, that "Processor to I/O Controller" listed says it has no driver, and the same with my "AC'97 Modem Controller".  How would I find the appropriate driver to load for it?
What about other drivers that don't even apply directly to PCI?  I ran `kldload acpi_wmi` and it gave me a /dev/wmistat0 with some GUID entry in it.  I would never have discovered this feature / driver without stumbling across it on a blog somewhere.
---

EDIT: It seems this is something of a topic in FreeBSD!  I found `devmatch` which tries to match undriven devices to the correct drivers, described in this BSDCan 2018 page.  And the next step, not yet written I guess, is AutoLoad to do what I want.  Watch this space, indeed.


----------



## SirDice (May 17, 2019)

Hornpipe2 said:


> The Realtek NIC driver is auto-loaded, for example, but the SMBus driver is not.


The Realtek driver is linked into the kernel, the smbus(4) driver isn't. 


Hornpipe2 said:


> Why do I have to manually load some but not others?


Some drivers are linked into the kernel while others are not. Just have a look at the GENERIC kernel configuration. Those are statically linked and don't need to be loaded.

The reason why some drivers are loaded while others are not is because some drivers are needed to get the system up and running. The GENERIC kernel has a bunch of the most common hardware drivers built-in, everything else you need will have to be loaded as a module to enable them.


----------



## mrclksr (May 17, 2019)

Hornpipe2 said:


> EDIT: It seems this is something of a topic in FreeBSD! I found  devmatch which tries to match undriven devices to the correct drivers, described in this BSDCan 2018 page. And the next step, not yet written I guess, is AutoLoad to do what I want. Watch this space, indeed.



See also sysutils/dsbdriverd (https://github.com/mrclksr/DSBDriverd).


----------

