drivers/staging/greybus/fw-management.c
Source file repositories/reference/linux-study-clean/drivers/staging/greybus/fw-management.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/greybus/fw-management.c- Extension
.c- Size
- 18387 bytes
- Lines
- 706
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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.
- 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/cdev.hlinux/completion.hlinux/firmware.hlinux/fs.hlinux/idr.hlinux/ioctl.hlinux/uaccess.hlinux/greybus.hfirmware.hgreybus_firmware.h
Detected Declarations
struct fw_mgmtfunction fw_mgmt_kref_releasefunction referencefunction list_for_each_entryfunction fw_mgmt_interface_fw_version_operationfunction fw_mgmt_load_and_validate_operationfunction fw_mgmt_interface_fw_loaded_operationfunction fw_mgmt_backend_fw_version_operationfunction fw_mgmt_backend_fw_update_operationfunction fw_mgmt_backend_fw_updated_operationfunction fw_mgmt_openfunction fw_mgmt_releasefunction fw_mgmt_ioctlfunction fw_mgmt_ioctl_unlockedfunction gb_fw_mgmt_request_handlerfunction gb_fw_mgmt_connection_initfunction gb_fw_mgmt_connection_exitfunction fw_mgmt_initfunction fw_mgmt_exit
Annotated Snippet
static const struct file_operations fw_mgmt_fops = {
.owner = THIS_MODULE,
.open = fw_mgmt_open,
.release = fw_mgmt_release,
.unlocked_ioctl = fw_mgmt_ioctl_unlocked,
};
int gb_fw_mgmt_request_handler(struct gb_operation *op)
{
u8 type = op->type;
switch (type) {
case GB_FW_MGMT_TYPE_LOADED_FW:
return fw_mgmt_interface_fw_loaded_operation(op);
case GB_FW_MGMT_TYPE_BACKEND_FW_UPDATED:
return fw_mgmt_backend_fw_updated_operation(op);
default:
dev_err(&op->connection->bundle->dev,
"unsupported request: %u\n", type);
return -EINVAL;
}
}
int gb_fw_mgmt_connection_init(struct gb_connection *connection)
{
struct fw_mgmt *fw_mgmt;
int ret, minor;
if (!connection)
return 0;
fw_mgmt = kzalloc_obj(*fw_mgmt);
if (!fw_mgmt)
return -ENOMEM;
fw_mgmt->parent = &connection->bundle->dev;
fw_mgmt->timeout_jiffies = msecs_to_jiffies(FW_MGMT_TIMEOUT_MS);
fw_mgmt->connection = connection;
gb_connection_set_data(connection, fw_mgmt);
init_completion(&fw_mgmt->completion);
ida_init(&fw_mgmt->id_map);
mutex_init(&fw_mgmt->mutex);
kref_init(&fw_mgmt->kref);
mutex_lock(&list_mutex);
list_add(&fw_mgmt->node, &fw_mgmt_list);
mutex_unlock(&list_mutex);
ret = gb_connection_enable(connection);
if (ret)
goto err_list_del;
minor = ida_alloc_max(&fw_mgmt_minors_map, NUM_MINORS - 1, GFP_KERNEL);
if (minor < 0) {
ret = minor;
goto err_connection_disable;
}
/* Add a char device to allow userspace to interact with fw-mgmt */
fw_mgmt->dev_num = MKDEV(MAJOR(fw_mgmt_dev_num), minor);
cdev_init(&fw_mgmt->cdev, &fw_mgmt_fops);
ret = cdev_add(&fw_mgmt->cdev, fw_mgmt->dev_num, 1);
if (ret)
goto err_remove_ida;
/* Add a soft link to the previously added char-dev within the bundle */
fw_mgmt->class_device = device_create(&fw_mgmt_class, fw_mgmt->parent,
fw_mgmt->dev_num, NULL,
"gb-fw-mgmt-%d", minor);
if (IS_ERR(fw_mgmt->class_device)) {
ret = PTR_ERR(fw_mgmt->class_device);
goto err_del_cdev;
}
return 0;
err_del_cdev:
cdev_del(&fw_mgmt->cdev);
err_remove_ida:
ida_free(&fw_mgmt_minors_map, minor);
err_connection_disable:
gb_connection_disable(connection);
err_list_del:
mutex_lock(&list_mutex);
list_del(&fw_mgmt->node);
mutex_unlock(&list_mutex);
put_fw_mgmt(fw_mgmt);
Annotation
- Immediate include surface: `linux/cdev.h`, `linux/completion.h`, `linux/firmware.h`, `linux/fs.h`, `linux/idr.h`, `linux/ioctl.h`, `linux/uaccess.h`, `linux/greybus.h`.
- Detected declarations: `struct fw_mgmt`, `function fw_mgmt_kref_release`, `function reference`, `function list_for_each_entry`, `function fw_mgmt_interface_fw_version_operation`, `function fw_mgmt_load_and_validate_operation`, `function fw_mgmt_interface_fw_loaded_operation`, `function fw_mgmt_backend_fw_version_operation`, `function fw_mgmt_backend_fw_update_operation`, `function fw_mgmt_backend_fw_updated_operation`.
- Atlas domain: Driver Families / drivers/staging.
- 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.
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.