drivers/usb/core/hcd-pci.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/hcd-pci.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/hcd-pci.c- Extension
.c- Size
- 17404 bytes
- Lines
- 653
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/pci.hlinux/usb.hlinux/usb/hcd.hasm/io.hasm/irq.hasm/machdep.hasm/pmac_feature.husb.h
Detected Declarations
function is_ohci_or_uhcifunction for_each_companionfunction ehci_pre_addfunction ehci_post_addfunction non_ehci_addfunction ehci_removefunction ehci_wait_for_companionsfunction startfunction usb_hcd_pci_probefunction usb_hcd_pci_shutdownfunction powermac_set_asicfunction powermac_set_asicfunction suspend_commonfunction resume_commonfunction hcd_pci_suspendfunction hcd_pci_freezefunction hcd_pci_suspend_noirqfunction hcd_pci_poweroff_latefunction hcd_pci_resume_noirqfunction hcd_pci_resumefunction hcd_pci_restorefunction hcd_pci_runtime_suspendfunction hcd_pci_runtime_resumeexport usb_hcd_pci_probeexport usb_hcd_pci_removeexport usb_hcd_pci_shutdownexport usb_hcd_pci_pm_ops
Annotated Snippet
* Store this function in the HCD's struct pci_driver as probe().
*
* Return: 0 if successful.
*/
int usb_hcd_pci_probe(struct pci_dev *dev, const struct hc_driver *driver)
{
struct usb_hcd *hcd;
int retval;
int hcd_irq = 0;
if (usb_disabled())
return -ENODEV;
if (!driver)
return -EINVAL;
if (pci_enable_device(dev) < 0)
return -ENODEV;
/*
* The xHCI driver has its own irq management
* make sure irq setup is not touched for xhci in generic hcd code
*/
if ((driver->flags & HCD_MASK) < HCD_USB3) {
retval = pci_alloc_irq_vectors(dev, 1, 1,
PCI_IRQ_INTX | PCI_IRQ_MSI);
if (retval < 0) {
dev_err(&dev->dev,
"Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
pci_name(dev));
retval = -ENODEV;
goto disable_pci;
}
hcd_irq = pci_irq_vector(dev, 0);
}
hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
if (!hcd) {
retval = -ENOMEM;
goto free_irq_vectors;
}
hcd->amd_resume_bug = usb_hcd_amd_resume_bug(dev, driver);
if (driver->flags & HCD_MEMORY) {
/* XHCI, EHCI, OHCI */
hcd->rsrc_start = pci_resource_start(dev, 0);
hcd->rsrc_len = pci_resource_len(dev, 0);
if (!devm_request_mem_region(&dev->dev, hcd->rsrc_start,
hcd->rsrc_len, driver->description)) {
dev_dbg(&dev->dev, "controller already in use\n");
retval = -EBUSY;
goto put_hcd;
}
hcd->regs = devm_ioremap(&dev->dev, hcd->rsrc_start,
hcd->rsrc_len);
if (hcd->regs == NULL) {
dev_dbg(&dev->dev, "error mapping memory\n");
retval = -EFAULT;
goto put_hcd;
}
} else {
/* UHCI */
int region;
for (region = 0; region < PCI_STD_NUM_BARS; region++) {
if (!(pci_resource_flags(dev, region) &
IORESOURCE_IO))
continue;
hcd->rsrc_start = pci_resource_start(dev, region);
hcd->rsrc_len = pci_resource_len(dev, region);
if (devm_request_region(&dev->dev, hcd->rsrc_start,
hcd->rsrc_len, driver->description))
break;
}
if (region == PCI_STD_NUM_BARS) {
dev_dbg(&dev->dev, "no i/o regions available\n");
retval = -EBUSY;
goto put_hcd;
}
}
pci_set_master(dev);
/* Note: dev_set_drvdata must be called while holding the rwsem */
if (dev->class == CL_EHCI) {
down_write(&companions_rwsem);
dev_set_drvdata(&dev->dev, hcd);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/pci.h`, `linux/usb.h`, `linux/usb/hcd.h`, `asm/io.h`, `asm/irq.h`, `asm/machdep.h`.
- Detected declarations: `function is_ohci_or_uhci`, `function for_each_companion`, `function ehci_pre_add`, `function ehci_post_add`, `function non_ehci_add`, `function ehci_remove`, `function ehci_wait_for_companions`, `function start`, `function usb_hcd_pci_probe`, `function usb_hcd_pci_shutdown`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.