drivers/fwctl/main.c
Source file repositories/reference/linux-study-clean/drivers/fwctl/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/fwctl/main.c- Extension
.c- Size
- 10880 bytes
- Lines
- 422
- Domain
- Driver Families
- Bucket
- drivers/fwctl
- 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.
- 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/fwctl.hlinux/container_of.hlinux/fs.hlinux/module.hlinux/sizes.hlinux/slab.huapi/fwctl/fwctl.h
Detected Declarations
struct fwctl_ucmdstruct fwctl_ioctl_opfunction ucmd_respondfunction copy_to_user_zero_padfunction fwctl_cmd_infofunction fwctl_cmd_rpcfunction fwctl_fops_ioctlfunction fwctl_fops_openfunction scoped_guardfunction fwctl_destroy_uctxfunction fwctl_fops_releasefunction scoped_guardfunction fwctl_device_releasefunction _alloc_devicefunction fwctl_registerfunction fwctl_registerfunction fwctl_initfunction fwctl_exitmodule init fwctl_init
Annotated Snippet
static const struct file_operations fwctl_fops = {
.owner = THIS_MODULE,
.open = fwctl_fops_open,
.release = fwctl_fops_release,
.unlocked_ioctl = fwctl_fops_ioctl,
};
static void fwctl_device_release(struct device *device)
{
struct fwctl_device *fwctl =
container_of(device, struct fwctl_device, dev);
ida_free(&fwctl_ida, fwctl->dev.devt - fwctl_dev);
mutex_destroy(&fwctl->uctx_list_lock);
kfree(fwctl);
}
static char *fwctl_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "fwctl/%s", dev_name(dev));
}
static struct class fwctl_class = {
.name = "fwctl",
.dev_release = fwctl_device_release,
.devnode = fwctl_devnode,
};
static struct fwctl_device *
_alloc_device(struct device *parent, const struct fwctl_ops *ops, size_t size)
{
struct fwctl_device *fwctl __free(kfree) = kzalloc(size, GFP_KERNEL);
int devnum;
if (!fwctl)
return NULL;
devnum = ida_alloc_max(&fwctl_ida, FWCTL_MAX_DEVICES - 1, GFP_KERNEL);
if (devnum < 0)
return NULL;
fwctl->dev.devt = fwctl_dev + devnum;
fwctl->dev.class = &fwctl_class;
fwctl->dev.parent = parent;
init_rwsem(&fwctl->registration_lock);
mutex_init(&fwctl->uctx_list_lock);
INIT_LIST_HEAD(&fwctl->uctx_list);
device_initialize(&fwctl->dev);
return_ptr(fwctl);
}
/* Drivers use the fwctl_alloc_device() wrapper */
struct fwctl_device *_fwctl_alloc_device(struct device *parent,
const struct fwctl_ops *ops,
size_t size)
{
struct fwctl_device *fwctl __free(fwctl) =
_alloc_device(parent, ops, size);
if (!fwctl)
return NULL;
cdev_init(&fwctl->cdev, &fwctl_fops);
/*
* The driver module is protected by fwctl_register/unregister(),
* unregister won't complete until we are done with the driver's module.
*/
fwctl->cdev.owner = THIS_MODULE;
if (dev_set_name(&fwctl->dev, "fwctl%d", fwctl->dev.devt - fwctl_dev))
return NULL;
fwctl->ops = ops;
return_ptr(fwctl);
}
EXPORT_SYMBOL_NS_GPL(_fwctl_alloc_device, "FWCTL");
/**
* fwctl_register - Register a new device to the subsystem
* @fwctl: Previously allocated fwctl_device
*
* On return the device is visible through sysfs and /dev, driver ops may be
* called.
*/
int fwctl_register(struct fwctl_device *fwctl)
{
return cdev_device_add(&fwctl->cdev, &fwctl->dev);
}
Annotation
- Immediate include surface: `linux/fwctl.h`, `linux/container_of.h`, `linux/fs.h`, `linux/module.h`, `linux/sizes.h`, `linux/slab.h`, `uapi/fwctl/fwctl.h`.
- Detected declarations: `struct fwctl_ucmd`, `struct fwctl_ioctl_op`, `function ucmd_respond`, `function copy_to_user_zero_pad`, `function fwctl_cmd_info`, `function fwctl_cmd_rpc`, `function fwctl_fops_ioctl`, `function fwctl_fops_open`, `function scoped_guard`, `function fwctl_destroy_uctx`.
- Atlas domain: Driver Families / drivers/fwctl.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.