drivers/pci/endpoint/pci-epc-mem.c
Source file repositories/reference/linux-study-clean/drivers/pci/endpoint/pci-epc-mem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/endpoint/pci-epc-mem.c- Extension
.c- Size
- 6881 bytes
- Lines
- 276
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/io.hlinux/module.hlinux/slab.hlinux/pci-epc.h
Detected Declarations
function Copyrightfunction pci_epc_multi_mem_initfunction pci_epc_mem_initfunction pci_epc_mem_exitfunction pci_epc_mem_alloc_addrfunction pci_epc_mem_free_addrexport pci_epc_multi_mem_initexport pci_epc_mem_initexport pci_epc_mem_exitexport pci_epc_mem_alloc_addrexport pci_epc_mem_free_addr
Annotated Snippet
if (!mem) {
ret = -ENOMEM;
i--;
goto err_mem;
}
bitmap = kzalloc(bitmap_size, GFP_KERNEL);
if (!bitmap) {
ret = -ENOMEM;
kfree(mem);
i--;
goto err_mem;
}
mem->window.phys_base = windows[i].phys_base;
mem->window.size = windows[i].size;
mem->window.page_size = page_size;
mem->bitmap = bitmap;
mem->pages = pages;
mutex_init(&mem->lock);
epc->windows[i] = mem;
}
epc->mem = epc->windows[0];
epc->num_windows = num_windows;
return 0;
err_mem:
for (; i >= 0; i--) {
mem = epc->windows[i];
kfree(mem->bitmap);
kfree(mem);
}
kfree(epc->windows);
return ret;
}
EXPORT_SYMBOL_GPL(pci_epc_multi_mem_init);
/**
* pci_epc_mem_init() - Initialize the pci_epc_mem structure
* @epc: the EPC device that invoked pci_epc_mem_init
* @base: Physical address of the window region
* @size: Total Size of the window region
* @page_size: Page size of the window region
*
* Invoke to initialize a single pci_epc_mem structure used by the
* endpoint functions to allocate memory for mapping the PCI host memory
*/
int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base,
size_t size, size_t page_size)
{
struct pci_epc_mem_window mem_window;
mem_window.phys_base = base;
mem_window.size = size;
mem_window.page_size = page_size;
return pci_epc_multi_mem_init(epc, &mem_window, 1);
}
EXPORT_SYMBOL_GPL(pci_epc_mem_init);
/**
* pci_epc_mem_exit() - cleanup the pci_epc_mem structure
* @epc: the EPC device that invoked pci_epc_mem_exit
*
* Invoke to cleanup the pci_epc_mem structure allocated in
* pci_epc_mem_init().
*/
void pci_epc_mem_exit(struct pci_epc *epc)
{
struct pci_epc_mem *mem;
int i;
if (!epc->num_windows)
return;
for (i = 0; i < epc->num_windows; i++) {
mem = epc->windows[i];
kfree(mem->bitmap);
kfree(mem);
}
kfree(epc->windows);
epc->windows = NULL;
epc->mem = NULL;
epc->num_windows = 0;
}
EXPORT_SYMBOL_GPL(pci_epc_mem_exit);
Annotation
- Immediate include surface: `linux/io.h`, `linux/module.h`, `linux/slab.h`, `linux/pci-epc.h`.
- Detected declarations: `function Copyright`, `function pci_epc_multi_mem_init`, `function pci_epc_mem_init`, `function pci_epc_mem_exit`, `function pci_epc_mem_alloc_addr`, `function pci_epc_mem_free_addr`, `export pci_epc_multi_mem_init`, `export pci_epc_mem_init`, `export pci_epc_mem_exit`, `export pci_epc_mem_alloc_addr`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.