drivers/pci/endpoint/pci-epf-core.c
Source file repositories/reference/linux-study-clean/drivers/pci/endpoint/pci-epf-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/endpoint/pci-epf-core.c- Extension
.c- Size
- 18010 bytes
- Lines
- 700
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/dma-mapping.hlinux/slab.hlinux/module.hlinux/pci-epc.hlinux/pci-epf.hlinux/pci-ep-cfs.h
Detected Declarations
function pci_epf_unbindfunction pci_epf_bindfunction pci_epf_add_vepffunction pci_epf_remove_vepffunction pci_epf_get_required_bar_sizefunction pci_epf_free_spacefunction pci_epf_alloc_spacefunction pci_epf_assign_bar_spacefunction pci_epf_remove_cfsfunction pci_epf_unregister_driverfunction pci_epf_add_cfsfunction __pci_epf_register_driverfunction pci_epf_destroyfunction pci_epf_createfunction pci_epf_align_inbound_addrfunction pci_epf_dev_releasefunction pci_epf_match_idfunction pci_epf_device_matchfunction pci_epf_device_probefunction pci_epf_device_removefunction pci_epf_initfunction pci_epf_exitmodule init pci_epf_initexport pci_epf_unbindexport pci_epf_bindexport pci_epf_add_vepfexport pci_epf_remove_vepfexport pci_epf_free_spaceexport pci_epf_alloc_spaceexport pci_epf_assign_bar_spaceexport pci_epf_unregister_driverexport __pci_epf_register_driverexport pci_epf_destroyexport pci_epf_createexport pci_epf_align_inbound_addr
Annotated Snippet
static const struct bus_type pci_epf_bus_type;
static const struct device_type pci_epf_type;
/**
* pci_epf_unbind() - Notify the function driver that the binding between the
* EPF device and EPC device has been lost
* @epf: the EPF device which has lost the binding with the EPC device
*
* Invoke to notify the function driver that the binding between the EPF device
* and EPC device has been lost.
*/
void pci_epf_unbind(struct pci_epf *epf)
{
struct pci_epf *epf_vf;
if (!epf->driver) {
dev_WARN(&epf->dev, "epf device not bound to driver\n");
return;
}
mutex_lock(&epf->lock);
list_for_each_entry(epf_vf, &epf->pci_vepf, list) {
if (epf_vf->is_bound)
epf_vf->driver->ops->unbind(epf_vf);
}
if (epf->is_bound)
epf->driver->ops->unbind(epf);
mutex_unlock(&epf->lock);
module_put(epf->driver->owner);
}
EXPORT_SYMBOL_GPL(pci_epf_unbind);
/**
* pci_epf_bind() - Notify the function driver that the EPF device has been
* bound to a EPC device
* @epf: the EPF device which has been bound to the EPC device
*
* Invoke to notify the function driver that it has been bound to a EPC device
*/
int pci_epf_bind(struct pci_epf *epf)
{
struct device *dev = &epf->dev;
struct pci_epf *epf_vf;
u8 func_no, vfunc_no;
struct pci_epc *epc;
int ret;
if (!epf->driver) {
dev_WARN(dev, "epf device not bound to driver\n");
return -EINVAL;
}
if (!try_module_get(epf->driver->owner))
return -EAGAIN;
mutex_lock(&epf->lock);
list_for_each_entry(epf_vf, &epf->pci_vepf, list) {
vfunc_no = epf_vf->vfunc_no;
if (vfunc_no < 1) {
dev_err(dev, "Invalid virtual function number\n");
ret = -EINVAL;
goto ret;
}
epc = epf->epc;
func_no = epf->func_no;
if (!IS_ERR_OR_NULL(epc)) {
if (!epc->max_vfs) {
dev_err(dev, "No support for virt function\n");
ret = -EINVAL;
goto ret;
}
if (vfunc_no > epc->max_vfs[func_no]) {
dev_err(dev, "PF%d: Exceeds max vfunc number\n",
func_no);
ret = -EINVAL;
goto ret;
}
}
epc = epf->sec_epc;
func_no = epf->sec_epc_func_no;
if (!IS_ERR_OR_NULL(epc)) {
if (!epc->max_vfs) {
dev_err(dev, "No support for virt function\n");
ret = -EINVAL;
goto ret;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/dma-mapping.h`, `linux/slab.h`, `linux/module.h`, `linux/pci-epc.h`, `linux/pci-epf.h`, `linux/pci-ep-cfs.h`.
- Detected declarations: `function pci_epf_unbind`, `function pci_epf_bind`, `function pci_epf_add_vepf`, `function pci_epf_remove_vepf`, `function pci_epf_get_required_bar_size`, `function pci_epf_free_space`, `function pci_epf_alloc_space`, `function pci_epf_assign_bar_space`, `function pci_epf_remove_cfs`, `function pci_epf_unregister_driver`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.