drivers/misc/ocxl/afu_irq.c
Source file repositories/reference/linux-study-clean/drivers/misc/ocxl/afu_irq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ocxl/afu_irq.c- Extension
.c- Size
- 4516 bytes
- Lines
- 213
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- 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.
- 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/interrupt.hlinux/irqdomain.hasm/pnv-ocxl.hasm/xive.hocxl_internal.htrace.h
Detected Declarations
struct afu_irqfunction ocxl_irq_offset_to_idfunction ocxl_irq_id_to_offsetfunction ocxl_irq_set_handlerfunction afu_irq_handlerfunction setup_afu_irqfunction release_afu_irqfunction ocxl_afu_irq_allocfunction afu_irq_freefunction ocxl_afu_irq_freefunction ocxl_afu_irq_free_allfunction ocxl_afu_irq_get_addrexport ocxl_irq_set_handlerexport ocxl_afu_irq_allocexport ocxl_afu_irq_freeexport ocxl_afu_irq_get_addr
Annotated Snippet
struct afu_irq {
int id;
int hw_irq;
unsigned int virq;
char *name;
irqreturn_t (*handler)(void *private);
void (*free_private)(void *private);
void *private;
};
int ocxl_irq_offset_to_id(struct ocxl_context *ctx, u64 offset)
{
return (offset - ctx->afu->irq_base_offset) >> PAGE_SHIFT;
}
u64 ocxl_irq_id_to_offset(struct ocxl_context *ctx, int irq_id)
{
return ctx->afu->irq_base_offset + (irq_id << PAGE_SHIFT);
}
int ocxl_irq_set_handler(struct ocxl_context *ctx, int irq_id,
irqreturn_t (*handler)(void *private),
void (*free_private)(void *private),
void *private)
{
struct afu_irq *irq;
int rc;
mutex_lock(&ctx->irq_lock);
irq = idr_find(&ctx->irq_idr, irq_id);
if (!irq) {
rc = -EINVAL;
goto unlock;
}
irq->handler = handler;
irq->private = private;
irq->free_private = free_private;
rc = 0;
// Fall through to unlock
unlock:
mutex_unlock(&ctx->irq_lock);
return rc;
}
EXPORT_SYMBOL_GPL(ocxl_irq_set_handler);
static irqreturn_t afu_irq_handler(int virq, void *data)
{
struct afu_irq *irq = data;
trace_ocxl_afu_irq_receive(virq);
if (irq->handler)
return irq->handler(irq->private);
return IRQ_HANDLED; // Just drop it on the ground
}
static int setup_afu_irq(struct ocxl_context *ctx, struct afu_irq *irq)
{
int rc;
irq->virq = irq_create_mapping(NULL, irq->hw_irq);
if (!irq->virq) {
pr_err("irq_create_mapping failed\n");
return -ENOMEM;
}
pr_debug("hw_irq %d mapped to virq %u\n", irq->hw_irq, irq->virq);
irq->name = kasprintf(GFP_KERNEL, "ocxl-afu-%u", irq->virq);
if (!irq->name) {
irq_dispose_mapping(irq->virq);
return -ENOMEM;
}
rc = request_irq(irq->virq, afu_irq_handler, 0, irq->name, irq);
if (rc) {
kfree(irq->name);
irq->name = NULL;
irq_dispose_mapping(irq->virq);
pr_err("request_irq failed: %d\n", rc);
return rc;
}
return 0;
}
static void release_afu_irq(struct afu_irq *irq)
{
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/irqdomain.h`, `asm/pnv-ocxl.h`, `asm/xive.h`, `ocxl_internal.h`, `trace.h`.
- Detected declarations: `struct afu_irq`, `function ocxl_irq_offset_to_id`, `function ocxl_irq_id_to_offset`, `function ocxl_irq_set_handler`, `function afu_irq_handler`, `function setup_afu_irq`, `function release_afu_irq`, `function ocxl_afu_irq_alloc`, `function afu_irq_free`, `function ocxl_afu_irq_free`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: integration 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.