drivers/uio/uio_dmem_genirq.c
Source file repositories/reference/linux-study-clean/drivers/uio/uio_dmem_genirq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/uio/uio_dmem_genirq.c- Extension
.c- Size
- 8536 bytes
- Lines
- 321
- Domain
- Driver Families
- Bucket
- drivers/uio
- 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/platform_device.hlinux/uio_driver.hlinux/spinlock.hlinux/bitops.hlinux/module.hlinux/interrupt.hlinux/platform_data/uio_dmem_genirq.hlinux/stringify.hlinux/pm_runtime.hlinux/dma-mapping.hlinux/slab.hlinux/irq.hlinux/of.hlinux/of_platform.hlinux/of_address.h
Detected Declarations
struct uio_dmem_genirq_platdatafunction uio_dmem_genirq_openfunction uio_dmem_genirq_releasefunction uio_dmem_genirq_handlerfunction uio_dmem_genirq_irqcontrolfunction uio_dmem_genirq_pm_disablefunction uio_dmem_genirq_probe
Annotated Snippet
struct uio_dmem_genirq_platdata {
struct uio_info *uioinfo;
spinlock_t lock;
unsigned long flags;
struct platform_device *pdev;
unsigned int dmem_region_start;
unsigned int num_dmem_regions;
struct mutex alloc_lock;
unsigned int refcnt;
};
/* Bits in uio_dmem_genirq_platdata.flags */
enum {
UIO_IRQ_DISABLED = 0,
};
static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode)
{
struct uio_dmem_genirq_platdata *priv = info->priv;
struct uio_mem *uiomem;
uiomem = &priv->uioinfo->mem[priv->dmem_region_start];
mutex_lock(&priv->alloc_lock);
while (!priv->refcnt && uiomem < &priv->uioinfo->mem[MAX_UIO_MAPS]) {
void *addr;
if (!uiomem->size)
break;
addr = dma_alloc_coherent(&priv->pdev->dev, uiomem->size,
&uiomem->dma_addr, GFP_KERNEL);
uiomem->addr = addr ? (uintptr_t) addr : DMEM_MAP_ERROR;
++uiomem;
}
priv->refcnt++;
mutex_unlock(&priv->alloc_lock);
/* Wait until the Runtime PM code has woken up the device */
pm_runtime_get_sync(&priv->pdev->dev);
return 0;
}
static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode)
{
struct uio_dmem_genirq_platdata *priv = info->priv;
struct uio_mem *uiomem;
/* Tell the Runtime PM code that the device has become idle */
pm_runtime_put_sync(&priv->pdev->dev);
uiomem = &priv->uioinfo->mem[priv->dmem_region_start];
mutex_lock(&priv->alloc_lock);
priv->refcnt--;
while (!priv->refcnt && uiomem < &priv->uioinfo->mem[MAX_UIO_MAPS]) {
if (!uiomem->size)
break;
if (uiomem->addr) {
dma_free_coherent(uiomem->dma_device, uiomem->size,
(void *) (uintptr_t) uiomem->addr,
uiomem->dma_addr);
}
uiomem->addr = DMEM_MAP_ERROR;
++uiomem;
}
mutex_unlock(&priv->alloc_lock);
return 0;
}
static irqreturn_t uio_dmem_genirq_handler(int irq, struct uio_info *dev_info)
{
struct uio_dmem_genirq_platdata *priv = dev_info->priv;
/* Just disable the interrupt in the interrupt controller, and
* remember the state so we can allow user space to enable it later.
*/
spin_lock(&priv->lock);
if (!__test_and_set_bit(UIO_IRQ_DISABLED, &priv->flags))
disable_irq_nosync(irq);
spin_unlock(&priv->lock);
return IRQ_HANDLED;
}
static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
{
struct uio_dmem_genirq_platdata *priv = dev_info->priv;
Annotation
- Immediate include surface: `linux/platform_device.h`, `linux/uio_driver.h`, `linux/spinlock.h`, `linux/bitops.h`, `linux/module.h`, `linux/interrupt.h`, `linux/platform_data/uio_dmem_genirq.h`, `linux/stringify.h`.
- Detected declarations: `struct uio_dmem_genirq_platdata`, `function uio_dmem_genirq_open`, `function uio_dmem_genirq_release`, `function uio_dmem_genirq_handler`, `function uio_dmem_genirq_irqcontrol`, `function uio_dmem_genirq_pm_disable`, `function uio_dmem_genirq_probe`.
- Atlas domain: Driver Families / drivers/uio.
- 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.