drivers/rapidio/devices/rio_mport_cdev.c
Source file repositories/reference/linux-study-clean/drivers/rapidio/devices/rio_mport_cdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rapidio/devices/rio_mport_cdev.c- Extension
.c- Size
- 65929 bytes
- Lines
- 2625
- Domain
- Driver Families
- Bucket
- drivers/rapidio
- 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/kernel.hlinux/cdev.hlinux/ioctl.hlinux/uaccess.hlinux/list.hlinux/fs.hlinux/err.hlinux/net.hlinux/poll.hlinux/spinlock.hlinux/sched.hlinux/kfifo.hlinux/mm.hlinux/slab.hlinux/vmalloc.hlinux/mman.hlinux/dma-mapping.hlinux/dmaengine.hlinux/rio.hlinux/rio_ids.hlinux/rio_drv.hlinux/rio_mport_cdev.h../rio.h
Detected Declarations
struct rio_mport_mappingstruct mport_devstruct mport_cdev_privstruct rio_mport_pw_filterstruct rio_mport_db_filterstruct mport_dma_reqenum rio_mport_map_dirfunction rio_mport_maint_rdfunction rio_mport_maint_wrfunction rio_mport_create_outbound_mappingfunction rio_mport_get_outbound_mappingfunction rio_mport_obw_mapfunction rio_mport_obw_freefunction maint_hdid_setfunction maint_comptag_setfunction mport_release_def_dmafunction mport_release_dmafunction dma_req_freefunction dma_xfer_callbackfunction prep_dma_xferfunction get_dma_channelfunction put_dma_channelfunction do_dma_requestfunction rio_dma_transferfunction Otherwisefunction list_for_each_entryfunction rio_mport_transfer_ioctlfunction rio_mport_wait_for_async_dmafunction rio_mport_create_dma_mappingfunction rio_mport_alloc_dmafunction rio_mport_free_dmafunction rio_mport_transfer_ioctlfunction rio_mport_wait_for_async_dmafunction rio_mport_alloc_dmafunction rio_mport_free_dmafunction rio_mport_create_inbound_mappingfunction rio_mport_get_inbound_mappingfunction rio_mport_map_inboundfunction rio_mport_inbound_freefunction maint_port_idx_getfunction rio_mport_add_eventfunction rio_mport_doorbell_handlerfunction rio_mport_add_db_filterfunction rio_mport_delete_db_filterfunction rio_mport_remove_db_filterfunction rio_mport_match_pwfunction rio_mport_pw_handlerfunction rio_mport_add_pw_filter
Annotated Snippet
static const struct file_operations mport_fops = {
.owner = THIS_MODULE,
.open = mport_cdev_open,
.release = mport_cdev_release,
.poll = mport_cdev_poll,
.read = mport_read,
.write = mport_write,
.mmap = mport_cdev_mmap,
.fasync = mport_cdev_fasync,
.unlocked_ioctl = mport_cdev_ioctl
};
/*
* Character device management
*/
static void mport_device_release(struct device *dev)
{
struct mport_dev *md;
rmcd_debug(EXIT, "%s", dev_name(dev));
md = container_of(dev, struct mport_dev, dev);
kfree(md);
}
/*
* mport_cdev_add() - Create mport_dev from rio_mport
* @mport: RapidIO master port
*/
static struct mport_dev *mport_cdev_add(struct rio_mport *mport)
{
int ret = 0;
struct mport_dev *md;
struct rio_mport_attr attr;
md = kzalloc_obj(*md);
if (!md) {
rmcd_error("Unable allocate a device object");
return NULL;
}
md->mport = mport;
mutex_init(&md->buf_mutex);
mutex_init(&md->file_mutex);
INIT_LIST_HEAD(&md->file_list);
device_initialize(&md->dev);
md->dev.devt = MKDEV(MAJOR(dev_number), mport->id);
md->dev.class = &dev_class;
md->dev.parent = &mport->dev;
md->dev.release = mport_device_release;
dev_set_name(&md->dev, DEV_NAME "%d", mport->id);
atomic_set(&md->active, 1);
cdev_init(&md->cdev, &mport_fops);
md->cdev.owner = THIS_MODULE;
INIT_LIST_HEAD(&md->doorbells);
spin_lock_init(&md->db_lock);
INIT_LIST_HEAD(&md->portwrites);
spin_lock_init(&md->pw_lock);
INIT_LIST_HEAD(&md->mappings);
md->properties.id = mport->id;
md->properties.sys_size = mport->sys_size;
md->properties.hdid = mport->host_deviceid;
md->properties.index = mport->index;
/* The transfer_mode property will be returned through mport query
* interface
*/
#ifdef CONFIG_FSL_RIO /* for now: only on Freescale's SoCs */
md->properties.transfer_mode |= RIO_TRANSFER_MODE_MAPPED;
#else
md->properties.transfer_mode |= RIO_TRANSFER_MODE_TRANSFER;
#endif
ret = cdev_device_add(&md->cdev, &md->dev);
if (ret) {
rmcd_error("Failed to register mport %d (err=%d)",
mport->id, ret);
goto err_cdev;
}
ret = rio_query_mport(mport, &attr);
if (!ret) {
md->properties.flags = attr.flags;
md->properties.link_speed = attr.link_speed;
md->properties.link_width = attr.link_width;
md->properties.dma_max_sge = attr.dma_max_sge;
md->properties.dma_max_size = attr.dma_max_size;
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/cdev.h`, `linux/ioctl.h`, `linux/uaccess.h`, `linux/list.h`, `linux/fs.h`, `linux/err.h`.
- Detected declarations: `struct rio_mport_mapping`, `struct mport_dev`, `struct mport_cdev_priv`, `struct rio_mport_pw_filter`, `struct rio_mport_db_filter`, `struct mport_dma_req`, `enum rio_mport_map_dir`, `function rio_mport_maint_rd`, `function rio_mport_maint_wr`, `function rio_mport_create_outbound_mapping`.
- Atlas domain: Driver Families / drivers/rapidio.
- 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.