drivers/platform/chrome/cros_ec_debugfs.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_debugfs.c- Extension
.c- Size
- 15432 bytes
- Lines
- 581
- 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/circ_buf.hlinux/debugfs.hlinux/delay.hlinux/fs.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/poll.hlinux/sched.hlinux/slab.hlinux/wait.h
Detected Declarations
struct cros_ec_debugfsfunction cros_ec_console_log_workfunction cros_ec_console_log_openfunction cros_ec_console_log_readfunction cros_ec_console_log_pollfunction cros_ec_console_log_releasefunction cros_ec_pdinfo_readfunction cros_ec_uptime_is_supportedfunction cros_ec_uptime_readfunction ec_read_version_supportedfunction cros_ec_create_console_logfunction cros_ec_cleanup_console_logfunction cros_ec_get_panicinfofunction cros_ec_create_panicinfofunction cros_ec_debugfs_panic_eventfunction cros_ec_debugfs_probefunction cros_ec_debugfs_removefunction cros_ec_debugfs_suspendfunction cros_ec_debugfs_resume
Annotated Snippet
static const struct file_operations cros_ec_console_log_fops = {
.owner = THIS_MODULE,
.open = cros_ec_console_log_open,
.read = cros_ec_console_log_read,
.poll = cros_ec_console_log_poll,
.release = cros_ec_console_log_release,
};
static const struct file_operations cros_ec_pdinfo_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = cros_ec_pdinfo_read,
.llseek = default_llseek,
};
static const struct file_operations cros_ec_uptime_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = cros_ec_uptime_read,
.llseek = default_llseek,
};
static int ec_read_version_supported(struct cros_ec_dev *ec)
{
struct ec_params_get_cmd_versions_v1 *params;
struct ec_response_get_cmd_versions *response;
int ret;
struct cros_ec_command *msg;
msg = kzalloc(sizeof(*msg) + max(sizeof(*params), sizeof(*response)),
GFP_KERNEL);
if (!msg)
return 0;
msg->version = 1;
msg->command = EC_CMD_GET_CMD_VERSIONS + ec->cmd_offset;
msg->outsize = sizeof(*params);
msg->insize = sizeof(*response);
params = (struct ec_params_get_cmd_versions_v1 *)msg->data;
params->cmd = EC_CMD_CONSOLE_READ;
response = (struct ec_response_get_cmd_versions *)msg->data;
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg) >= 0 &&
response->version_mask & EC_VER_MASK(1);
kfree(msg);
return ret;
}
static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info)
{
struct cros_ec_dev *ec = debug_info->ec;
char *buf;
int read_params_size;
int read_response_size;
/*
* If the console log feature is not supported return silently and
* don't create the console_log entry.
*/
if (!ec_read_version_supported(ec))
return 0;
buf = devm_kzalloc(ec->dev, LOG_SIZE, GFP_KERNEL);
if (!buf)
return -ENOMEM;
read_params_size = sizeof(struct ec_params_console_read_v1);
read_response_size = ec->ec_dev->max_response;
debug_info->read_msg = devm_kzalloc(ec->dev,
sizeof(*debug_info->read_msg) +
max(read_params_size, read_response_size), GFP_KERNEL);
if (!debug_info->read_msg)
return -ENOMEM;
debug_info->read_msg->version = 1;
debug_info->read_msg->command = EC_CMD_CONSOLE_READ + ec->cmd_offset;
debug_info->read_msg->outsize = read_params_size;
debug_info->read_msg->insize = read_response_size;
debug_info->log_buffer.buf = buf;
debug_info->log_buffer.head = 0;
debug_info->log_buffer.tail = 0;
mutex_init(&debug_info->log_mutex);
debugfs_create_file("console_log", S_IFREG | 0444, debug_info->dir,
Annotation
- Immediate include surface: `linux/circ_buf.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/fs.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/platform_data/cros_ec_commands.h`.
- Detected declarations: `struct cros_ec_debugfs`, `function cros_ec_console_log_work`, `function cros_ec_console_log_open`, `function cros_ec_console_log_read`, `function cros_ec_console_log_poll`, `function cros_ec_console_log_release`, `function cros_ec_pdinfo_read`, `function cros_ec_uptime_is_supported`, `function cros_ec_uptime_read`, `function ec_read_version_supported`.
- 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.