drivers/platform/chrome/wilco_ec/event.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/wilco_ec/event.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/wilco_ec/event.c- Extension
.c- Size
- 17269 bytes
- Lines
- 593
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/acpi.hlinux/cdev.hlinux/device.hlinux/fs.hlinux/idr.hlinux/io.hlinux/list.hlinux/module.hlinux/platform_device.hlinux/poll.hlinux/spinlock.hlinux/uaccess.hlinux/wait.h
Detected Declarations
struct ec_eventstruct ec_event_queuestruct event_device_datafunction event_queue_emptyfunction event_queue_fullfunction event_queue_freefunction enqueue_eventsfunction event_device_notifyfunction event_openfunction event_pollfunction event_readfunction event_releasefunction free_device_datafunction hangup_devicefunction event_device_probefunction event_device_removefunction event_module_initfunction event_module_exitmodule init event_module_init
Annotated Snippet
static const struct file_operations event_fops = {
.open = event_open,
.poll = event_poll,
.read = event_read,
.release = event_release,
.owner = THIS_MODULE,
};
/**
* free_device_data() - Callback to free the event_device_data structure.
* @d: The device embedded in our device data, which we have been ref counting.
*
* This is called only after event_device_remove() has been called and all
* userspace programs have called event_release() on all the open file
* descriptors.
*/
static void free_device_data(struct device *d)
{
struct event_device_data *dev_data;
dev_data = container_of(d, struct event_device_data, dev);
event_queue_free(dev_data->events);
kfree(dev_data);
}
static void hangup_device(struct event_device_data *dev_data)
{
dev_data->exist = false;
/* Wake up the waiting processes so they can close. */
wake_up_interruptible(&dev_data->wq);
put_device(&dev_data->dev);
}
/**
* event_device_probe() - Callback when creating a new device.
* @pdev: Platform device that we will be receiving events from.
*
* This finds a free minor number for the device, allocates and initializes
* some device data, and creates a new device and char dev node.
*
* The device data is freed in free_device_data(), which is called when
* %dev_data->dev is release()ed. This happens after all references to
* %dev_data->dev are dropped, which happens once both event_device_remove()
* has been called and every open()ed file descriptor has been release()ed.
*
* Return: 0 on success, negative error code on failure.
*/
static int event_device_probe(struct platform_device *pdev)
{
struct event_device_data *dev_data;
struct acpi_device *adev;
int error, minor;
adev = ACPI_COMPANION(&pdev->dev);
if (!adev)
return -ENODEV;
minor = ida_alloc_max(&event_ida, EVENT_MAX_DEV-1, GFP_KERNEL);
if (minor < 0) {
error = minor;
dev_err(&pdev->dev, "Failed to find minor number: %d\n", error);
return error;
}
dev_data = kzalloc_obj(*dev_data);
if (!dev_data) {
error = -ENOMEM;
goto free_minor;
}
/* Initialize the device data. */
platform_set_drvdata(pdev, dev_data);
dev_data->events = event_queue_new(queue_size);
if (!dev_data->events) {
kfree(dev_data);
error = -ENOMEM;
goto free_minor;
}
spin_lock_init(&dev_data->queue_lock);
init_waitqueue_head(&dev_data->wq);
dev_data->exist = true;
atomic_set(&dev_data->available, 1);
/* Initialize the device. */
dev_data->dev.devt = MKDEV(event_major, minor);
dev_data->dev.class = &event_class;
dev_data->dev.release = free_device_data;
dev_set_name(&dev_data->dev, EVENT_DEV_NAME_FMT, minor);
device_initialize(&dev_data->dev);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/cdev.h`, `linux/device.h`, `linux/fs.h`, `linux/idr.h`, `linux/io.h`, `linux/list.h`, `linux/module.h`.
- Detected declarations: `struct ec_event`, `struct ec_event_queue`, `struct event_device_data`, `function event_queue_empty`, `function event_queue_full`, `function event_queue_free`, `function enqueue_events`, `function event_device_notify`, `function event_open`, `function event_poll`.
- Atlas domain: Driver Families / drivers/platform.
- 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.