pci_get_class(9)
π pci_get_class(9) β from the Kernel API Manual, bestie
Okay so picture this: you're deep in kernel land, you need to find a PCI device by its class, and you don't wanna write the loop yourself. That's literally this function. It's pci_get_class, and it's here to start β or keep going with β a search for a PCI device by class. π
β¨ SYNOPSIS β¨
struct pci_dev * pci_get_class (unsigned int class , struct pci_dev *from );
That's the whole vibe. Two args, one pointer back out. π«Ά
πΈ ARGUMENTS πΈ
classβ the class designation you're hunting for. You want a PCI device with this class, and this is where you say so.fromβ the previous PCI device you already found in this search, orNULLif you're starting fresh. Brand new search? PassNULL. Continuing? Pass the last one. Easy.
π¦ DESCRIPTION π¦
So what it actually does: it iterates through the list of known PCI devices. Iconic behavior, no notes. π
If a PCI device turns up with a matching class, the reference count on that device gets incremented and you get back a pointer to its device structure. Slay. You got your device.
Otherwise? NULL. That's it. That's the answer. π
Now, the search mechanics, because this is where people get caught out:
- You kick off a new search by passing
NULLas thefromargument. Fresh start, main character energy. β¨ - If
fromis notNULL, the search continues from the next device on the global list. Not the one you passed β the next one. iykyk. - And listen β the reference count for
fromis always decremented if it is notNULL. Always. Non-negotiable. So don't go thinking you get to keep that reference, because you don't. π«
Heads up bestie: that automatic decrement is the whole reason this pattern works as a loop. You hand it the last thing, it lets go of it, it gives you the next thing. Trust the process. π
π SEE ALSO π
Kernel file ./drivers/pci/search.c β go read it, it's giving source of truth. π
And the whole friend group:
pci_find_bus(9)pci_find_next_bus(9)pci_get_slot(9)pci_get_domain_bus_and_slot(9)pci_get_subsys(9)pci_get_device(9)pci_get_base_class(9)pci_dev_present(9)
β Okay that's the page!! Shoutout to ./drivers/pci for hosting, and this little love letter is dated October 2026 β go find your devices, bestie, you've got this ππ§π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms