arch/powerpc/platforms/powernv/ocxl.c
Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/powernv/ocxl.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/platforms/powernv/ocxl.c- Extension
.c- Size
- 15374 bytes
- Lines
- 593
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
asm/pnv-ocxl.hasm/opal.hmisc/ocxl-config.hpci.h
Detected Declarations
struct actag_rangestruct npu_linkstruct spa_datafunction afunction find_dvsec_afu_ctrlfunction get_max_afu_indexfunction get_actag_countfunction list_for_each_entryfunction pnv_ocxl_fixup_actagfunction assign_fn_actagsfunction assign_actagsfunction pnv_ocxl_get_actagfunction pnv_ocxl_get_pasid_countfunction set_templ_ratefunction pnv_ocxl_get_tl_capfunction pnv_ocxl_set_tl_conffunction pnv_ocxl_get_xsl_irqfunction pnv_ocxl_unmap_xsl_regsfunction pnv_ocxl_map_xsl_regsfunction pnv_ocxl_spa_setupfunction pnv_ocxl_spa_releasefunction pnv_ocxl_spa_remove_pe_from_cachefunction pnv_ocxl_map_lparfunction pnv_ocxl_unmap_lparfunction pnv_ocxl_tlb_invalidateexport pnv_ocxl_get_actagexport pnv_ocxl_get_pasid_countexport pnv_ocxl_get_tl_capexport pnv_ocxl_set_tl_confexport pnv_ocxl_get_xsl_irqexport pnv_ocxl_unmap_xsl_regsexport pnv_ocxl_map_xsl_regsexport pnv_ocxl_spa_setupexport pnv_ocxl_spa_releaseexport pnv_ocxl_spa_remove_pe_from_cacheexport pnv_ocxl_map_lparexport pnv_ocxl_unmap_lparexport pnv_ocxl_tlb_invalidate
Annotated Snippet
struct actag_range {
u16 start;
u16 count;
};
struct npu_link {
struct list_head list;
int domain;
int bus;
int dev;
u16 fn_desired_actags[8];
struct actag_range fn_actags[8];
bool assignment_done;
};
static struct list_head links_list = LIST_HEAD_INIT(links_list);
static DEFINE_MUTEX(links_list_lock);
/*
* opencapi actags handling:
*
* When sending commands, the opencapi device references the memory
* context it's targeting with an 'actag', which is really an alias
* for a (BDF, pasid) combination. When it receives a command, the NPU
* must do a lookup of the actag to identify the memory context. The
* hardware supports a finite number of actags per link (64 for
* POWER9).
*
* The device can carry multiple functions, and each function can have
* multiple AFUs. Each AFU advertises in its config space the number
* of desired actags. The host must configure in the config space of
* the AFU how many actags the AFU is really allowed to use (which can
* be less than what the AFU desires).
*
* When a PCI function is probed by the driver, it has no visibility
* about the other PCI functions and how many actags they'd like,
* which makes it impossible to distribute actags fairly among AFUs.
*
* Unfortunately, the only way to know how many actags a function
* desires is by looking at the data for each AFU in the config space
* and add them up. Similarly, the only way to know how many actags
* all the functions of the physical device desire is by adding the
* previously computed function counts. Then we can match that against
* what the hardware supports.
*
* To get a comprehensive view, we use a 'pci fixup': at the end of
* PCI enumeration, each function counts how many actags its AFUs
* desire and we save it in a 'npu_link' structure, shared between all
* the PCI functions of a same device. Therefore, when the first
* function is probed by the driver, we can get an idea of the total
* count of desired actags for the device, and assign the actags to
* the AFUs, by pro-rating if needed.
*/
static int find_dvsec_from_pos(struct pci_dev *dev, int dvsec_id, int pos)
{
int vsec = pos;
u16 vendor, id;
while ((vsec = pci_find_next_ext_capability(dev, vsec,
OCXL_EXT_CAP_ID_DVSEC))) {
pci_read_config_word(dev, vsec + OCXL_DVSEC_VENDOR_OFFSET,
&vendor);
pci_read_config_word(dev, vsec + OCXL_DVSEC_ID_OFFSET, &id);
if (vendor == PCI_VENDOR_ID_IBM && id == dvsec_id)
return vsec;
}
return 0;
}
static int find_dvsec_afu_ctrl(struct pci_dev *dev, u8 afu_idx)
{
int vsec = 0;
u8 idx;
while ((vsec = find_dvsec_from_pos(dev, OCXL_DVSEC_AFU_CTRL_ID,
vsec))) {
pci_read_config_byte(dev, vsec + OCXL_DVSEC_AFU_CTRL_AFU_IDX,
&idx);
if (idx == afu_idx)
return vsec;
}
return 0;
}
static int get_max_afu_index(struct pci_dev *dev, int *afu_idx)
{
int pos;
u32 val;
Annotation
- Immediate include surface: `asm/pnv-ocxl.h`, `asm/opal.h`, `misc/ocxl-config.h`, `pci.h`.
- Detected declarations: `struct actag_range`, `struct npu_link`, `struct spa_data`, `function a`, `function find_dvsec_afu_ctrl`, `function get_max_afu_index`, `function get_actag_count`, `function list_for_each_entry`, `function pnv_ocxl_fixup_actag`, `function assign_fn_actags`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.