drivers/char/xillybus/xillyusb.c
Source file repositories/reference/linux-study-clean/drivers/char/xillybus/xillyusb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/xillybus/xillyusb.c- Extension
.c- Size
- 53357 bytes
- Lines
- 2304
- Domain
- Driver Families
- Bucket
- drivers/char
- 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/types.hlinux/slab.hlinux/list.hlinux/device.hlinux/module.hasm/byteorder.hlinux/io.hlinux/interrupt.hlinux/sched.hlinux/fs.hlinux/spinlock.hlinux/mutex.hlinux/workqueue.hlinux/crc32.hlinux/poll.hlinux/delay.hlinux/usb.hxillybus_class.h
Detected Declarations
struct xillyusb_devstruct xillyfifostruct xillyusb_channelstruct xillyusb_endpointstruct xillyusb_channelstruct xillybufferstruct xillyusb_devfunction fifo_writefunction fifo_readfunction fifo_writefunction xilly_copy_to_userfunction xilly_memcpyfunction fifo_initfunction fifo_mem_releasefunction endpoint_quiescefunction endpoint_deallocfunction list_for_each_safefunction voidfunction cleanup_devfunction process_bulk_infunction report_io_errorfunction safely_assign_in_fifofunction bulk_in_completerfunction bulk_out_completerfunction try_queue_bulk_infunction try_queue_bulk_outfunction bulk_out_workfunction process_in_opcodefunction process_bulk_infunction bulk_in_workfunction xillyusb_send_opcodefunction flush_downstreamfunction request_read_anythingfunction xillyusb_openfunction xillyusb_readfunction readfunction fifo_readfunction xillyusb_flushfunction xillyusb_writefunction xillyusb_releasefunction FPGAfunction xillyusb_pollfunction pollfunction xillyusb_setup_base_epsfunction setup_channelsfunction xillyusb_discoveryfunction xillyusb_probefunction xillyusb_disconnect
Annotated Snippet
static const struct file_operations xillyusb_fops = {
.owner = THIS_MODULE,
.read = xillyusb_read,
.write = xillyusb_write,
.open = xillyusb_open,
.flush = xillyusb_flush,
.release = xillyusb_release,
.llseek = xillyusb_llseek,
.poll = xillyusb_poll,
};
static int xillyusb_setup_base_eps(struct xillyusb_dev *xdev)
{
struct usb_device *udev = xdev->udev;
/* Verify that device has the two fundamental bulk in/out endpoints */
if (usb_pipe_type_check(udev, usb_sndbulkpipe(udev, MSG_EP_NUM)) ||
usb_pipe_type_check(udev, usb_rcvbulkpipe(udev, IN_EP_NUM)))
return -ENODEV;
xdev->msg_ep = endpoint_alloc(xdev, MSG_EP_NUM | USB_DIR_OUT,
bulk_out_work, 1, 2);
if (!xdev->msg_ep)
return -ENOMEM;
if (fifo_init(&xdev->msg_ep->fifo, 13)) /* 8 kiB */
goto dealloc;
xdev->msg_ep->fill_mask = -8; /* 8 bytes granularity */
xdev->in_ep = endpoint_alloc(xdev, IN_EP_NUM | USB_DIR_IN,
bulk_in_work, BUF_SIZE_ORDER, BUFNUM);
if (!xdev->in_ep)
goto dealloc;
try_queue_bulk_in(xdev->in_ep);
return 0;
dealloc:
endpoint_dealloc(xdev->msg_ep); /* Also frees FIFO mem if allocated */
xdev->msg_ep = NULL;
return -ENOMEM;
}
static int setup_channels(struct xillyusb_dev *xdev,
__le16 *chandesc,
int num_channels)
{
struct usb_device *udev = xdev->udev;
struct xillyusb_channel *chan, *new_channels;
int i;
chan = kzalloc_objs(*chan, num_channels);
if (!chan)
return -ENOMEM;
new_channels = chan;
for (i = 0; i < num_channels; i++, chan++) {
unsigned int in_desc = le16_to_cpu(*chandesc++);
unsigned int out_desc = le16_to_cpu(*chandesc++);
chan->xdev = xdev;
mutex_init(&chan->in_mutex);
mutex_init(&chan->out_mutex);
mutex_init(&chan->lock);
init_waitqueue_head(&chan->flushq);
chan->chan_idx = i;
if (in_desc & 0x80) { /* Entry is valid */
chan->readable = 1;
chan->in_synchronous = !!(in_desc & 0x40);
chan->in_seekable = !!(in_desc & 0x20);
chan->in_log2_element_size = in_desc & 0x0f;
chan->in_log2_fifo_size = ((in_desc >> 8) & 0x1f) + 16;
}
/*
* A downstream channel should never exist above index 13,
* as it would request a nonexistent BULK endpoint > 15.
* In the peculiar case that it does, it's ignored silently.
*/
if ((out_desc & 0x80) && i < 14) { /* Entry is valid */
if (usb_pipe_type_check(udev,
usb_sndbulkpipe(udev, i + 2))) {
dev_err(xdev->dev,
"Missing BULK OUT endpoint %d\n",
Annotation
- Immediate include surface: `linux/types.h`, `linux/slab.h`, `linux/list.h`, `linux/device.h`, `linux/module.h`, `asm/byteorder.h`, `linux/io.h`, `linux/interrupt.h`.
- Detected declarations: `struct xillyusb_dev`, `struct xillyfifo`, `struct xillyusb_channel`, `struct xillyusb_endpoint`, `struct xillyusb_channel`, `struct xillybuffer`, `struct xillyusb_dev`, `function fifo_write`, `function fifo_read`, `function fifo_write`.
- Atlas domain: Driver Families / drivers/char.
- 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.