drivers/comedi/drivers/mite.c
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers/mite.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers/mite.c- Extension
.c- Size
- 27255 bytes
- Lines
- 927
- Domain
- Driver Families
- Bucket
- drivers/comedi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/slab.hlinux/log2.hlinux/comedi/comedi_pci.hmite.h
Detected Declarations
function Copyrightfunction mite_retry_limitfunction mite_drq_reqsfunction mite_fifo_sizefunction mite_device_bytes_transferredfunction mite_bytes_in_transitfunction mite_bytes_written_to_memory_lbfunction mite_bytes_written_to_memory_ubfunction mite_bytes_read_from_memory_lbfunction mite_bytes_read_from_memory_ubfunction mite_sync_input_dmafunction mite_sync_output_dmafunction mite_sync_dmafunction mite_get_statusfunction mite_ack_linkcfunction mite_donefunction mite_dma_resetfunction mite_dma_armfunction mite_dma_disarmfunction mite_prep_dmafunction mite_request_channel_in_rangefunction mite_request_channelfunction mite_release_channelfunction mite_init_ring_descriptorsfunction mite_free_dma_descsfunction mite_buf_changefunction mite_alloc_ringfunction mite_free_ringfunction mite_setupfunction mite_attachfunction mite_detachexport mite_bytes_in_transitexport mite_sync_dmaexport mite_ack_linkcexport mite_doneexport mite_dma_armexport mite_dma_disarmexport mite_prep_dmaexport mite_request_channel_in_rangeexport mite_request_channelexport mite_release_channelexport mite_init_ring_descriptorsexport mite_buf_changeexport mite_alloc_ringexport mite_free_ringexport mite_attachexport mite_detach
Annotated Snippet
if (!mite_chan->ring) {
mite_chan->ring = ring;
break;
}
mite_chan = NULL;
}
spin_unlock_irqrestore(&mite->lock, flags);
return mite_chan;
}
EXPORT_SYMBOL_GPL(mite_request_channel_in_range);
/**
* mite_request_channel() - Request a MITE dma channel.
* @mite: MITE device.
* @ring: MITE dma ring.
*/
struct mite_channel *mite_request_channel(struct mite *mite,
struct mite_ring *ring)
{
return mite_request_channel_in_range(mite, ring, 0,
mite->num_channels - 1);
}
EXPORT_SYMBOL_GPL(mite_request_channel);
/**
* mite_release_channel() - Release a MITE dma channel.
* @mite_chan: MITE dma channel.
*/
void mite_release_channel(struct mite_channel *mite_chan)
{
struct mite *mite = mite_chan->mite;
unsigned long flags;
/* spin lock to prevent races with mite_request_channel */
spin_lock_irqsave(&mite->lock, flags);
if (mite_chan->ring) {
mite_dma_disarm(mite_chan);
mite_dma_reset(mite_chan);
/*
* disable all channel's interrupts (do it after disarm/reset so
* MITE_CHCR reg isn't changed while dma is still active!)
*/
writel(CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE |
CHCR_CLR_SAR_IE | CHCR_CLR_DONE_IE |
CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE,
mite->mmio + MITE_CHCR(mite_chan->channel));
mite_chan->ring = NULL;
}
spin_unlock_irqrestore(&mite->lock, flags);
}
EXPORT_SYMBOL_GPL(mite_release_channel);
/**
* mite_init_ring_descriptors() - Initialize a MITE dma ring descriptors.
* @ring: MITE dma ring.
* @s: COMEDI subdevice.
* @nbytes: the size of the dma ring (in bytes).
*
* Initializes the ring buffer descriptors to provide correct DMA transfer
* links to the exact amount of memory required. When the ring buffer is
* allocated by mite_buf_change(), the default is to initialize the ring
* to refer to the entire DMA data buffer. A command may call this function
* later to re-initialize and shorten the amount of memory that will be
* transferred.
*/
int mite_init_ring_descriptors(struct mite_ring *ring,
struct comedi_subdevice *s,
unsigned int nbytes)
{
struct comedi_async *async = s->async;
struct mite_dma_desc *desc = NULL;
unsigned int n_full_links = nbytes >> PAGE_SHIFT;
unsigned int remainder = nbytes % PAGE_SIZE;
int i;
dev_dbg(s->device->class_dev,
"mite: init ring buffer to %u bytes\n", nbytes);
if ((n_full_links + (remainder > 0 ? 1 : 0)) > ring->n_links) {
dev_err(s->device->class_dev,
"mite: ring buffer too small for requested init\n");
return -ENOMEM;
}
/* We set the descriptors for all full links. */
for (i = 0; i < n_full_links; ++i) {
desc = &ring->descs[i];
desc->count = cpu_to_le32(PAGE_SIZE);
desc->addr = cpu_to_le32(async->buf_map->page_list[i].dma_addr);
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/log2.h`, `linux/comedi/comedi_pci.h`, `mite.h`.
- Detected declarations: `function Copyright`, `function mite_retry_limit`, `function mite_drq_reqs`, `function mite_fifo_size`, `function mite_device_bytes_transferred`, `function mite_bytes_in_transit`, `function mite_bytes_written_to_memory_lb`, `function mite_bytes_written_to_memory_ub`, `function mite_bytes_read_from_memory_lb`, `function mite_bytes_read_from_memory_ub`.
- Atlas domain: Driver Families / drivers/comedi.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.