arch/powerpc/sysdev/msi_bitmap.c
Source file repositories/reference/linux-study-clean/arch/powerpc/sysdev/msi_bitmap.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/sysdev/msi_bitmap.c- Extension
.c- Size
- 7447 bytes
- Lines
- 274
- 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.
- 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/slab.hlinux/kernel.hlinux/kmemleak.hlinux/bitmap.hlinux/memblock.hlinux/of.hasm/msi_bitmap.hasm/setup.h
Detected Declarations
function msi_bitmap_alloc_hwirqsfunction msi_bitmap_free_hwirqsfunction msi_bitmap_reserve_hwirqfunction msi_bitmap_reserve_dt_hwirqsfunction msi_bitmap_allocfunction msi_bitmap_freefunction test_basicsfunction test_of_nodefunction msi_bitmap_selftestexport msi_bitmap_alloc_hwirqsexport msi_bitmap_free_hwirqs
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2006-2008, Michael Ellerman, IBM Corporation.
*/
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/kmemleak.h>
#include <linux/bitmap.h>
#include <linux/memblock.h>
#include <linux/of.h>
#include <asm/msi_bitmap.h>
#include <asm/setup.h>
int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)
{
unsigned long flags;
int offset, order = get_count_order(num);
spin_lock_irqsave(&bmp->lock, flags);
offset = bitmap_find_next_zero_area(bmp->bitmap, bmp->irq_count, 0,
num, (1 << order) - 1);
if (offset > bmp->irq_count)
goto err;
bitmap_set(bmp->bitmap, offset, num);
spin_unlock_irqrestore(&bmp->lock, flags);
pr_debug("msi_bitmap: allocated 0x%x at offset 0x%x\n", num, offset);
return offset;
err:
spin_unlock_irqrestore(&bmp->lock, flags);
return -ENOMEM;
}
EXPORT_SYMBOL(msi_bitmap_alloc_hwirqs);
void msi_bitmap_free_hwirqs(struct msi_bitmap *bmp, unsigned int offset,
unsigned int num)
{
unsigned long flags;
pr_debug("msi_bitmap: freeing 0x%x at offset 0x%x\n",
num, offset);
spin_lock_irqsave(&bmp->lock, flags);
bitmap_clear(bmp->bitmap, offset, num);
spin_unlock_irqrestore(&bmp->lock, flags);
}
EXPORT_SYMBOL(msi_bitmap_free_hwirqs);
void msi_bitmap_reserve_hwirq(struct msi_bitmap *bmp, unsigned int hwirq)
{
unsigned long flags;
pr_debug("msi_bitmap: reserving hwirq 0x%x\n", hwirq);
spin_lock_irqsave(&bmp->lock, flags);
bitmap_allocate_region(bmp->bitmap, hwirq, 0);
spin_unlock_irqrestore(&bmp->lock, flags);
}
/**
* msi_bitmap_reserve_dt_hwirqs - Reserve irqs specified in the device tree.
* @bmp: pointer to the MSI bitmap.
*
* Looks in the device tree to see if there is a property specifying which
* irqs can be used for MSI. If found those irqs reserved in the device tree
* are reserved in the bitmap.
*
* Returns 0 for success, < 0 if there was an error, and > 0 if no property
* was found in the device tree.
**/
int msi_bitmap_reserve_dt_hwirqs(struct msi_bitmap *bmp)
{
int i, j, len;
const u32 *p;
if (!bmp->of_node)
return 1;
p = of_get_property(bmp->of_node, "msi-available-ranges", &len);
if (!p) {
pr_debug("msi_bitmap: no msi-available-ranges property " \
"found on %pOF\n", bmp->of_node);
return 1;
}
if (len % (2 * sizeof(u32)) != 0) {
Annotation
- Immediate include surface: `linux/slab.h`, `linux/kernel.h`, `linux/kmemleak.h`, `linux/bitmap.h`, `linux/memblock.h`, `linux/of.h`, `asm/msi_bitmap.h`, `asm/setup.h`.
- Detected declarations: `function msi_bitmap_alloc_hwirqs`, `function msi_bitmap_free_hwirqs`, `function msi_bitmap_reserve_hwirq`, `function msi_bitmap_reserve_dt_hwirqs`, `function msi_bitmap_alloc`, `function msi_bitmap_free`, `function test_basics`, `function test_of_node`, `function msi_bitmap_selftest`, `export msi_bitmap_alloc_hwirqs`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.