drivers/pci/devres.c
Source file repositories/reference/linux-study-clean/drivers/pci/devres.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/devres.c- Extension
.c- Size
- 21336 bytes
- Lines
- 862
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/pci.hpci.h
Detected Declarations
struct pcim_iomap_devresstruct pcim_intx_devresstruct pcim_addr_devresenum pcim_addr_devres_typefunction pcim_addr_devres_clearfunction pcim_addr_resource_releasefunction pcim_addr_devres_freefunction pcim_addr_resources_matchfunction devm_pci_unmap_iospacefunction pci_remap_iospacefunction pci_remap_cfgspacefunction __pcim_clear_mwifunction pci_set_mwifunction mask_contains_barfunction pcim_intx_restorefunction save_orig_intxfunction pcim_intxfunction pcim_disable_devicefunction pci_enable_devicefunction pcim_pin_devicefunction pcim_iomap_releasefunction pcim_add_mapping_to_legacy_tablefunction pcim_remove_mapping_from_legacy_tablefunction pcim_remove_mapping_from_legacy_tablefunction pci_iomapfunction pci_iounmapfunction pcim_iomap_regionfunction pcim_iomap_regionfunction pcim_release_regionfunction pcim_request_regionfunction pcim_request_regionfunction pcim_release_all_regionsfunction pcim_iounmapexport devm_pci_remap_iospaceexport devm_pci_remap_cfgspaceexport devm_pci_remap_cfg_resourceexport pcim_set_mwiexport pcim_intxexport pcim_enable_deviceexport pcim_pin_deviceexport pcim_iomap_tableexport pcim_iomapexport pcim_iounmapexport pcim_iomap_regionexport pcim_iounmap_regionexport pcim_iomap_regionsexport pcim_request_regionexport pcim_request_all_regions
Annotated Snippet
struct pcim_iomap_devres {
void __iomem *table[PCI_NUM_RESOURCES];
};
/* Used to restore the old INTx state on driver detach. */
struct pcim_intx_devres {
int orig_intx;
};
enum pcim_addr_devres_type {
/* Default initializer. */
PCIM_ADDR_DEVRES_TYPE_INVALID,
/* A requested region spanning an entire BAR. */
PCIM_ADDR_DEVRES_TYPE_REGION,
/*
* A requested region spanning an entire BAR, and a mapping for
* the entire BAR.
*/
PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING,
/*
* A mapping within a BAR, either spanning the whole BAR or just a
* range. Without a requested region.
*/
PCIM_ADDR_DEVRES_TYPE_MAPPING,
};
/*
* This struct envelops IO or MEM addresses, i.e., mappings and region
* requests, because those are very frequently requested and released
* together.
*/
struct pcim_addr_devres {
enum pcim_addr_devres_type type;
void __iomem *baseaddr;
unsigned long offset;
unsigned long len;
int bar;
};
static inline void pcim_addr_devres_clear(struct pcim_addr_devres *res)
{
memset(res, 0, sizeof(*res));
res->bar = -1;
}
static void pcim_addr_resource_release(struct device *dev, void *resource_raw)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct pcim_addr_devres *res = resource_raw;
switch (res->type) {
case PCIM_ADDR_DEVRES_TYPE_REGION:
pci_release_region(pdev, res->bar);
break;
case PCIM_ADDR_DEVRES_TYPE_REGION_MAPPING:
pci_iounmap(pdev, res->baseaddr);
pci_release_region(pdev, res->bar);
break;
case PCIM_ADDR_DEVRES_TYPE_MAPPING:
pci_iounmap(pdev, res->baseaddr);
break;
default:
break;
}
}
static struct pcim_addr_devres *pcim_addr_devres_alloc(struct pci_dev *pdev)
{
struct pcim_addr_devres *res;
res = devres_alloc_node(pcim_addr_resource_release, sizeof(*res),
GFP_KERNEL, dev_to_node(&pdev->dev));
if (res)
pcim_addr_devres_clear(res);
return res;
}
/* Just for consistency and readability. */
static inline void pcim_addr_devres_free(struct pcim_addr_devres *res)
{
devres_free(res);
}
/*
* Used by devres to identify a pcim_addr_devres.
*/
static int pcim_addr_resources_match(struct device *dev,
Annotation
- Immediate include surface: `linux/device.h`, `linux/pci.h`, `pci.h`.
- Detected declarations: `struct pcim_iomap_devres`, `struct pcim_intx_devres`, `struct pcim_addr_devres`, `enum pcim_addr_devres_type`, `function pcim_addr_devres_clear`, `function pcim_addr_resource_release`, `function pcim_addr_devres_free`, `function pcim_addr_resources_match`, `function devm_pci_unmap_iospace`, `function pci_remap_iospace`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
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.