drivers/irqchip/irq-loongson-pch-msi.c
Source file repositories/reference/linux-study-clean/drivers/irqchip/irq-loongson-pch-msi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/irqchip/irq-loongson-pch-msi.c- Extension
.c- Size
- 7220 bytes
- Lines
- 293
- Domain
- Driver Families
- Bucket
- drivers/irqchip
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/irqchip.hlinux/msi.hlinux/of.hlinux/of_address.hlinux/of_irq.hlinux/of_pci.hlinux/pci.hlinux/slab.hlinux/irqchip/irq-msi-lib.hirq-loongson.h
Detected Declarations
struct pch_msi_datafunction pch_msi_allocate_hwirqfunction pch_msi_free_hwirqfunction pch_msi_compose_msi_msgfunction pch_msi_parent_domain_allocfunction pch_msi_middle_domain_allocfunction pch_msi_middle_domain_freefunction pch_msi_init_domainsfunction pch_msi_initfunction pch_msi_of_initfunction pch_msi_acpi_initfunction pch_msi_acpi_init_avec
Annotated Snippet
struct pch_msi_data {
struct mutex msi_map_lock;
phys_addr_t doorbell;
u32 irq_first; /* The vector number that MSIs starts */
u32 num_irqs; /* The number of vectors for MSIs */
unsigned long *msi_map;
};
static struct fwnode_handle *pch_msi_handle[MAX_IO_PICS];
static int pch_msi_allocate_hwirq(struct pch_msi_data *priv, int num_req)
{
int first;
mutex_lock(&priv->msi_map_lock);
first = bitmap_find_free_region(priv->msi_map, priv->num_irqs,
get_count_order(num_req));
if (first < 0) {
mutex_unlock(&priv->msi_map_lock);
return -ENOSPC;
}
mutex_unlock(&priv->msi_map_lock);
return priv->irq_first + first;
}
static void pch_msi_free_hwirq(struct pch_msi_data *priv,
int hwirq, int num_req)
{
int first = hwirq - priv->irq_first;
mutex_lock(&priv->msi_map_lock);
bitmap_release_region(priv->msi_map, first, get_count_order(num_req));
mutex_unlock(&priv->msi_map_lock);
}
static void pch_msi_compose_msi_msg(struct irq_data *data,
struct msi_msg *msg)
{
struct pch_msi_data *priv = irq_data_get_irq_chip_data(data);
msg->address_hi = upper_32_bits(priv->doorbell);
msg->address_lo = lower_32_bits(priv->doorbell);
msg->data = data->hwirq;
}
static struct irq_chip middle_irq_chip = {
.name = "PCH MSI",
.irq_mask = irq_chip_mask_parent,
.irq_unmask = irq_chip_unmask_parent,
.irq_ack = irq_chip_ack_parent,
.irq_set_affinity = irq_chip_set_affinity_parent,
.irq_compose_msi_msg = pch_msi_compose_msi_msg,
};
static int pch_msi_parent_domain_alloc(struct irq_domain *domain,
unsigned int virq, int hwirq)
{
struct irq_fwspec fwspec;
fwspec.fwnode = domain->parent->fwnode;
fwspec.param_count = 1;
fwspec.param[0] = hwirq;
return irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
}
static int pch_msi_middle_domain_alloc(struct irq_domain *domain,
unsigned int virq,
unsigned int nr_irqs, void *args)
{
struct pch_msi_data *priv = domain->host_data;
int hwirq, err, i;
hwirq = pch_msi_allocate_hwirq(priv, nr_irqs);
if (hwirq < 0)
return hwirq;
for (i = 0; i < nr_irqs; i++) {
err = pch_msi_parent_domain_alloc(domain, virq + i, hwirq + i);
if (err)
goto err_hwirq;
irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
&middle_irq_chip, priv);
}
return 0;
Annotation
- Immediate include surface: `linux/irqchip.h`, `linux/msi.h`, `linux/of.h`, `linux/of_address.h`, `linux/of_irq.h`, `linux/of_pci.h`, `linux/pci.h`, `linux/slab.h`.
- Detected declarations: `struct pch_msi_data`, `function pch_msi_allocate_hwirq`, `function pch_msi_free_hwirq`, `function pch_msi_compose_msi_msg`, `function pch_msi_parent_domain_alloc`, `function pch_msi_middle_domain_alloc`, `function pch_msi_middle_domain_free`, `function pch_msi_init_domains`, `function pch_msi_init`, `function pch_msi_of_init`.
- Atlas domain: Driver Families / drivers/irqchip.
- Implementation status: source 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.