drivers/uio/uio.c
Source file repositories/reference/linux-study-clean/drivers/uio/uio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/uio/uio.c- Extension
.c- Size
- 24960 bytes
- Lines
- 1156
- Domain
- Driver Families
- Bucket
- drivers/uio
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/module.hlinux/init.hlinux/poll.hlinux/device.hlinux/slab.hlinux/mm.hlinux/idr.hlinux/sched/signal.hlinux/string.hlinux/kobject.hlinux/cdev.hlinux/uio_driver.hlinux/dma-mapping.h
Detected Declarations
struct uio_mapstruct map_sysfs_entrystruct uio_portiostruct portio_sysfs_entrystruct uio_listenerfunction map_name_showfunction map_addr_showfunction map_size_showfunction map_offset_showfunction map_releasefunction map_type_showfunction portio_name_showfunction portio_start_showfunction portio_size_showfunction portio_porttype_showfunction portio_releasefunction portio_type_showfunction name_showfunction version_showfunction event_showfunction uio_dev_add_attributesfunction uio_dev_del_attributesfunction uio_get_minorfunction uio_free_minorfunction uio_event_notifyfunction uio_interrupt_handlerfunction uio_interrupt_threadfunction uio_openfunction uio_fasyncfunction uio_releasefunction uio_pollfunction uio_readfunction uio_writefunction uio_find_mem_indexfunction uio_vma_faultfunction uio_mmap_logicalfunction uio_mmap_physicalfunction uio_mmap_dma_coherentfunction uio_mmapfunction uio_major_initfunction uio_major_cleanupfunction init_uio_classfunction release_uio_classfunction uio_device_releasefunction __uio_register_devicefunction devm_uio_unregister_devicefunction __devm_uio_register_devicefunction uio_unregister_device
Annotated Snippet
static const struct file_operations uio_fops;
/* Protect idr accesses */
static DEFINE_MUTEX(minor_lock);
/*
* attributes
*/
struct uio_map {
struct kobject kobj;
struct uio_mem *mem;
};
#define to_map(map) container_of(map, struct uio_map, kobj)
static ssize_t map_name_show(struct uio_mem *mem, char *buf)
{
if (unlikely(!mem->name))
mem->name = "";
return sprintf(buf, "%s\n", mem->name);
}
static ssize_t map_addr_show(struct uio_mem *mem, char *buf)
{
return sprintf(buf, "%pa\n", &mem->addr);
}
static ssize_t map_size_show(struct uio_mem *mem, char *buf)
{
return sprintf(buf, "%pa\n", &mem->size);
}
static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
{
return sprintf(buf, "0x%llx\n", (unsigned long long)mem->offs);
}
struct map_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct uio_mem *, char *);
ssize_t (*store)(struct uio_mem *, const char *, size_t);
};
static struct map_sysfs_entry name_attribute =
__ATTR(name, S_IRUGO, map_name_show, NULL);
static struct map_sysfs_entry addr_attribute =
__ATTR(addr, S_IRUGO, map_addr_show, NULL);
static struct map_sysfs_entry size_attribute =
__ATTR(size, S_IRUGO, map_size_show, NULL);
static struct map_sysfs_entry offset_attribute =
__ATTR(offset, S_IRUGO, map_offset_show, NULL);
static struct attribute *map_attrs[] = {
&name_attribute.attr,
&addr_attribute.attr,
&size_attribute.attr,
&offset_attribute.attr,
NULL, /* need to NULL terminate the list of attributes */
};
ATTRIBUTE_GROUPS(map);
static void map_release(struct kobject *kobj)
{
struct uio_map *map = to_map(kobj);
kfree(map);
}
static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
struct uio_map *map = to_map(kobj);
struct uio_mem *mem = map->mem;
struct map_sysfs_entry *entry;
entry = container_of(attr, struct map_sysfs_entry, attr);
if (!entry->show)
return -EIO;
return entry->show(mem, buf);
}
static const struct sysfs_ops map_sysfs_ops = {
.show = map_type_show,
};
static const struct kobj_type map_attr_type = {
.release = map_release,
.sysfs_ops = &map_sysfs_ops,
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/poll.h`, `linux/device.h`, `linux/slab.h`, `linux/mm.h`, `linux/idr.h`, `linux/sched/signal.h`.
- Detected declarations: `struct uio_map`, `struct map_sysfs_entry`, `struct uio_portio`, `struct portio_sysfs_entry`, `struct uio_listener`, `function map_name_show`, `function map_addr_show`, `function map_size_show`, `function map_offset_show`, `function map_release`.
- Atlas domain: Driver Families / drivers/uio.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.