drivers/infiniband/core/ucaps.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/core/ucaps.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/core/ucaps.c- Extension
.c- Size
- 5778 bytes
- Lines
- 264
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kref.hlinux/cdev.hlinux/mutex.hlinux/file.hlinux/fs.hrdma/ib_ucaps.h
Detected Declarations
struct ib_ucapfunction ib_cleanup_ucapsfunction get_ucap_from_devtfunction get_devt_from_fdfunction ib_ucaps_initfunction ucap_dev_releasefunction ib_create_ucapfunction ib_release_ucapfunction ib_remove_ucapfunction ib_get_ucapsexport ib_create_ucapexport ib_remove_ucap
Annotated Snippet
static const struct file_operations ucaps_cdev_fops = {
.owner = THIS_MODULE,
.open = simple_open,
};
static __exit void ib_cleanup_ucaps(void)
{
mutex_lock(&ucaps_mutex);
if (!ucaps_class_is_registered) {
mutex_unlock(&ucaps_mutex);
return;
}
for (int i = RDMA_UCAP_FIRST; i < RDMA_UCAP_MAX; i++)
WARN_ON(ucaps_list[i]);
class_unregister(&ucaps_class);
ucaps_class_is_registered = false;
unregister_chrdev_region(ucaps_base_dev, RDMA_UCAP_MAX);
mutex_unlock(&ucaps_mutex);
}
static int get_ucap_from_devt(dev_t devt, u64 *idx_mask)
{
for (int type = RDMA_UCAP_FIRST; type < RDMA_UCAP_MAX; type++) {
if (ucaps_list[type] && ucaps_list[type]->dev.devt == devt) {
*idx_mask |= 1 << type;
return 0;
}
}
return -EINVAL;
}
static int get_devt_from_fd(unsigned int fd, dev_t *ret_dev)
{
CLASS(fd, f)(fd);
if (fd_empty(f) || fd_file(f)->f_op != &ucaps_cdev_fops)
return -EBADF;
*ret_dev = file_inode(fd_file(f))->i_rdev;
return 0;
}
/**
* ib_ucaps_init - Initialization required before ucap creation.
*
* Return: 0 on success, or a negative errno value on failure
*/
static int ib_ucaps_init(void)
{
int ret = 0;
if (ucaps_class_is_registered)
return ret;
ret = class_register(&ucaps_class);
if (ret)
return ret;
ret = alloc_chrdev_region(&ucaps_base_dev, 0, RDMA_UCAP_MAX,
ucaps_class.name);
if (ret < 0) {
class_unregister(&ucaps_class);
return ret;
}
ucaps_class_is_registered = true;
return 0;
}
static void ucap_dev_release(struct device *device)
{
struct ib_ucap *ucap = container_of(device, struct ib_ucap, dev);
kfree(ucap);
}
/**
* ib_create_ucap - Add a ucap character device
* @type: UCAP type
*
* Creates a ucap character device in the /dev/infiniband directory. By default,
* the device has root-only read-write access.
*
* A driver may call this multiple times with the same UCAP type. A reference
* count tracks creations and deletions.
*
Annotation
- Immediate include surface: `linux/kref.h`, `linux/cdev.h`, `linux/mutex.h`, `linux/file.h`, `linux/fs.h`, `rdma/ib_ucaps.h`.
- Detected declarations: `struct ib_ucap`, `function ib_cleanup_ucaps`, `function get_ucap_from_devt`, `function get_devt_from_fd`, `function ib_ucaps_init`, `function ucap_dev_release`, `function ib_create_ucap`, `function ib_release_ucap`, `function ib_remove_ucap`, `function ib_get_ucaps`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.