drivers/greybus/es2.c
Source file repositories/reference/linux-study-clean/drivers/greybus/es2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/greybus/es2.c- Extension
.c- Size
- 34052 bytes
- Lines
- 1455
- Domain
- Driver Families
- Bucket
- drivers/greybus
- 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/kthread.hlinux/sizes.hlinux/usb.hlinux/kfifo.hlinux/debugfs.hlinux/list.hlinux/greybus.hlinux/unaligned.harpc.hgreybus_trace.h
Detected Declarations
struct es2_cport_instruct es2_ap_devstruct arpcfunction output_syncfunction ap_urb_completefunction output_asyncfunction outputfunction es2_cport_in_enablefunction es2_cport_in_disablefunction es2_arpc_in_enablefunction es2_arpc_in_disablefunction free_urbfunction Wefunction gb_message_cport_clearfunction gb_message_cport_unpackfunction message_sendfunction message_cancelfunction es2_cport_allocatefunction es2_cport_releasefunction cport_enablefunction es2_cport_connectedfunction es2_cport_flushfunction es2_cport_shutdownfunction es2_cport_quiescefunction es2_cport_clearfunction latency_tag_enablefunction latency_tag_disablefunction check_urb_statusfunction es2_destroyfunction cport_in_callbackfunction cport_out_callbackfunction arpc_freefunction list_for_each_entryfunction arpc_addfunction arpc_delfunction arpc_sendfunction arpc_syncfunction arpc_in_callbackfunction apb_log_getfunction apb_log_pollfunction apb_log_readfunction usb_log_enablefunction usb_log_disablefunction apb_log_enable_readfunction apb_log_enable_writefunction apb_get_cport_countfunction ap_probefunction ap_disconnect
Annotated Snippet
static const struct file_operations apb_log_fops = {
.read = apb_log_read,
};
static void usb_log_enable(struct es2_ap_dev *es2)
{
if (!IS_ERR_OR_NULL(es2->apb_log_task))
return;
/* get log from APB1 */
es2->apb_log_task = kthread_run(apb_log_poll, es2, "apb_log");
if (IS_ERR(es2->apb_log_task))
return;
/* XXX We will need to rename this per APB */
es2->apb_log_dentry = debugfs_create_file("apb_log", 0444,
gb_debugfs_get(), es2,
&apb_log_fops);
}
static void usb_log_disable(struct es2_ap_dev *es2)
{
if (IS_ERR_OR_NULL(es2->apb_log_task))
return;
debugfs_remove(es2->apb_log_dentry);
es2->apb_log_dentry = NULL;
kthread_stop(es2->apb_log_task);
es2->apb_log_task = NULL;
}
static ssize_t apb_log_enable_read(struct file *f, char __user *buf,
size_t count, loff_t *ppos)
{
struct es2_ap_dev *es2 = file_inode(f)->i_private;
int enable = !IS_ERR_OR_NULL(es2->apb_log_task);
char tmp_buf[3];
sprintf(tmp_buf, "%d\n", enable);
return simple_read_from_buffer(buf, count, ppos, tmp_buf, 2);
}
static ssize_t apb_log_enable_write(struct file *f, const char __user *buf,
size_t count, loff_t *ppos)
{
int enable;
ssize_t retval;
struct es2_ap_dev *es2 = file_inode(f)->i_private;
retval = kstrtoint_from_user(buf, count, 10, &enable);
if (retval)
return retval;
if (enable)
usb_log_enable(es2);
else
usb_log_disable(es2);
return count;
}
static const struct file_operations apb_log_enable_fops = {
.read = apb_log_enable_read,
.write = apb_log_enable_write,
};
static int apb_get_cport_count(struct usb_device *udev)
{
int retval;
__le16 *cport_count;
cport_count = kzalloc_obj(*cport_count);
if (!cport_count)
return -ENOMEM;
retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
GB_APB_REQUEST_CPORT_COUNT,
USB_DIR_IN | USB_TYPE_VENDOR |
USB_RECIP_INTERFACE, 0, 0, cport_count,
sizeof(*cport_count), ES2_USB_CTRL_TIMEOUT);
if (retval != sizeof(*cport_count)) {
dev_err(&udev->dev, "Cannot retrieve CPort count: %d\n",
retval);
if (retval >= 0)
retval = -EIO;
goto out;
}
Annotation
- Immediate include surface: `linux/kthread.h`, `linux/sizes.h`, `linux/usb.h`, `linux/kfifo.h`, `linux/debugfs.h`, `linux/list.h`, `linux/greybus.h`, `linux/unaligned.h`.
- Detected declarations: `struct es2_cport_in`, `struct es2_ap_dev`, `struct arpc`, `function output_sync`, `function ap_urb_complete`, `function output_async`, `function output`, `function es2_cport_in_enable`, `function es2_cport_in_disable`, `function es2_arpc_in_enable`.
- Atlas domain: Driver Families / drivers/greybus.
- 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.