sound/pci/emu10k1/emu10k1_patch.c

Source file repositories/reference/linux-study-clean/sound/pci/emu10k1/emu10k1_patch.c

File Facts

System
Linux kernel
Corpus path
sound/pci/emu10k1/emu10k1_patch.c
Extension
.c
Size
4398 bytes
Lines
171
Domain
Driver Families
Bucket
sound/pci
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_SINGLESHOT) {
			sp->v.loopstart = sp->v.end + BLANK_LOOP_START;
			sp->v.loopend = sp->v.end + BLANK_LOOP_END;
		}
	}

	loop_start = sp->v.loopstart;
	loop_end = sp->v.loopend;
	loop_size = loop_end - loop_start;
	if (!loop_size)
		return -EINVAL;
	data_end = sp->v.end;

	/* recalculate offset */
	sp->v.start += BLANK_HEAD_SIZE;
	sp->v.end += BLANK_HEAD_SIZE;
	sp->v.loopstart += BLANK_HEAD_SIZE;
	sp->v.loopend += BLANK_HEAD_SIZE;

	// Automatic pre-filling of the cache does not work in the presence
	// of loops (*), and we don't want to fill it manually, as that is
	// fiddly and slow. So we unroll the loop until the loop end is
	// beyond the cache size.
	// (*) Strictly speaking, a single iteration is supported (that's
	// how it works when the playback engine runs), but handling this
	// special case is not worth it.
	unroll = 0;
	while (sp->v.loopend < 64) {
		truesize += loop_size;
		sp->v.loopstart += loop_size;
		sp->v.loopend += loop_size;
		sp->v.end += loop_size;
		unroll++;
	}

	/* try to allocate a memory block */
	blocksize = truesize << shift;
	sp->block = snd_emu10k1_synth_alloc(emu, blocksize);
	if (sp->block == NULL) {
		dev_dbg(emu->card->dev,
			"synth malloc failed (size=%d)\n", blocksize);
		/* not ENOMEM (for compatibility with OSS) */
		return -ENOSPC;
	}
	/* set the total size */
	sp->v.truesize = blocksize;

	/* write blank samples at head */
	offset = 0;
	size = BLANK_HEAD_SIZE << shift;
	snd_emu10k1_synth_memset(emu, sp->block, offset, size, fill);
	offset += size;

	/* copy provided samples */
	if (unroll && loop_end <= data_end) {
		size = loop_end << shift;
		if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size, xor))
			goto faulty;
		offset += size;

		data += loop_start << shift;
		while (--unroll > 0) {
			size = loop_size << shift;
			if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size, xor))
				goto faulty;
			offset += size;
		}

		size = (data_end - loop_start) << shift;
	} else {
		size = data_end << shift;
	}
	if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size, xor))
		goto faulty;
	offset += size;

	/* clear rest of samples (if any) */
	if (offset < blocksize)
		snd_emu10k1_synth_memset(emu, sp->block, offset, blocksize - offset, fill);

	return 0;

faulty:
	snd_emu10k1_synth_free(emu, sp->block);
	sp->block = NULL;
	return -EFAULT;
}

/*
 * free a sample block

Annotation

Implementation Notes