sound/virtio/virtio_pcm_msg.c
Source file repositories/reference/linux-study-clean/sound/virtio/virtio_pcm_msg.c
File Facts
- System
- Linux kernel
- Corpus path
sound/virtio/virtio_pcm_msg.c- Extension
.c- Size
- 10948 bytes
- Lines
- 416
- Domain
- Driver Families
- Bucket
- sound/virtio
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
sound/pcm_params.hvirtio_card.h
Detected Declarations
struct virtio_pcm_msgenum pcm_msg_sg_indexfunction virtsnd_pcm_sg_numfunction virtsnd_pcm_sg_fromfunction virtsnd_pcm_msg_allocfunction virtsnd_pcm_msg_freefunction virtsnd_pcm_msg_sendfunction virtsnd_pcm_msg_pending_numfunction virtsnd_pcm_msg_completefunction virtsnd_pcm_notify_cbfunction virtsnd_pcm_tx_notify_cbfunction virtsnd_pcm_rx_notify_cbfunction virtsnd_pcm_ctl_msg_alloc
Annotated Snippet
struct virtio_pcm_msg {
struct virtio_pcm_substream *substream;
struct virtio_snd_pcm_xfer xfer;
struct virtio_snd_pcm_status status;
size_t length;
struct scatterlist sgs[];
};
/**
* enum pcm_msg_sg_index - Index values for the virtio_pcm_msg->sgs field in
* an I/O message.
* @PCM_MSG_SG_XFER: Element containing a virtio_snd_pcm_xfer structure.
* @PCM_MSG_SG_STATUS: Element containing a virtio_snd_pcm_status structure.
* @PCM_MSG_SG_DATA: The first element containing a data buffer.
*/
enum pcm_msg_sg_index {
PCM_MSG_SG_XFER = 0,
PCM_MSG_SG_STATUS,
PCM_MSG_SG_DATA
};
/**
* virtsnd_pcm_sg_num() - Count the number of sg-elements required to represent
* vmalloc'ed buffer.
* @data: Pointer to vmalloc'ed buffer.
* @length: Buffer size.
*
* Context: Any context.
* Return: Number of physically contiguous parts in the @data.
*/
static int virtsnd_pcm_sg_num(u8 *data, unsigned int length)
{
phys_addr_t sg_address;
unsigned int sg_length;
int num = 0;
while (length) {
struct page *pg = vmalloc_to_page(data);
phys_addr_t pg_address = page_to_phys(pg);
size_t pg_length;
pg_length = PAGE_SIZE - offset_in_page(data);
if (pg_length > length)
pg_length = length;
if (!num || sg_address + sg_length != pg_address) {
sg_address = pg_address;
sg_length = pg_length;
num++;
} else {
sg_length += pg_length;
}
data += pg_length;
length -= pg_length;
}
return num;
}
/**
* virtsnd_pcm_sg_from() - Build sg-list from vmalloc'ed buffer.
* @sgs: Preallocated sg-list to populate.
* @nsgs: The maximum number of elements in the @sgs.
* @data: Pointer to vmalloc'ed buffer.
* @length: Buffer size.
*
* Splits the buffer into physically contiguous parts and makes an sg-list of
* such parts.
*
* Context: Any context.
*/
static void virtsnd_pcm_sg_from(struct scatterlist *sgs, int nsgs, u8 *data,
unsigned int length)
{
int idx = -1;
while (length) {
struct page *pg = vmalloc_to_page(data);
size_t pg_length;
pg_length = PAGE_SIZE - offset_in_page(data);
if (pg_length > length)
pg_length = length;
if (idx == -1 ||
sg_phys(&sgs[idx]) + sgs[idx].length != page_to_phys(pg)) {
if (idx + 1 == nsgs)
break;
sg_set_page(&sgs[++idx], pg, pg_length,
Annotation
- Immediate include surface: `sound/pcm_params.h`, `virtio_card.h`.
- Detected declarations: `struct virtio_pcm_msg`, `enum pcm_msg_sg_index`, `function virtsnd_pcm_sg_num`, `function virtsnd_pcm_sg_from`, `function virtsnd_pcm_msg_alloc`, `function virtsnd_pcm_msg_free`, `function virtsnd_pcm_msg_send`, `function virtsnd_pcm_msg_pending_num`, `function virtsnd_pcm_msg_complete`, `function virtsnd_pcm_notify_cb`.
- Atlas domain: Driver Families / sound/virtio.
- Implementation status: source implementation candidate.
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.