Skip to content

Commit 36fc349

Browse files
committed
ALSA: doc: Update description for the new PCM copy ops
Update the documentation about the PCM copy callbacks. The update was kept minimalistic, just correcting the use of copy_user ops with the single copy ops, and drop/update the text mentioning the copy_kernel. Link: https://lore.kernel.org/r/20230815190136.8987-24-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 9bebd65 commit 36fc349

1 file changed

Lines changed: 19 additions & 39 deletions

File tree

Documentation/sound/kernel-api/writing-an-alsa-driver.rst

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,8 +2018,8 @@ sleeping poll threads, etc.
20182018

20192019
This callback is also atomic by default.
20202020

2021-
copy_user, copy_kernel and fill_silence ops
2022-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021+
copy and fill_silence ops
2022+
~~~~~~~~~~~~~~~~~~~~~~~~~
20232023

20242024
These callbacks are not mandatory, and can be omitted in most cases.
20252025
These callbacks are used when the hardware buffer cannot be in the
@@ -3444,8 +3444,8 @@ external hardware buffer in interrupts (or in tasklets, preferably).
34443444

34453445
The first case works fine if the external hardware buffer is large
34463446
enough. This method doesn't need any extra buffers and thus is more
3447-
efficient. You need to define the ``copy_user`` and ``copy_kernel``
3448-
callbacks for the data transfer, in addition to the ``fill_silence``
3447+
efficient. You need to define the ``copy`` callback
3448+
for the data transfer, in addition to the ``fill_silence``
34493449
callback for playback. However, there is a drawback: it cannot be
34503450
mmapped. The examples are GUS's GF1 PCM or emu8000's wavetable PCM.
34513451

@@ -3458,22 +3458,22 @@ Another case is when the chip uses a PCI memory-map region for the
34583458
buffer instead of the host memory. In this case, mmap is available only
34593459
on certain architectures like the Intel one. In non-mmap mode, the data
34603460
cannot be transferred as in the normal way. Thus you need to define the
3461-
``copy_user``, ``copy_kernel`` and ``fill_silence`` callbacks as well,
3461+
``copy`` and ``fill_silence`` callbacks as well,
34623462
as in the cases above. Examples are found in ``rme32.c`` and
34633463
``rme96.c``.
34643464

3465-
The implementation of the ``copy_user``, ``copy_kernel`` and
3465+
The implementation of the ``copy`` and
34663466
``silence`` callbacks depends upon whether the hardware supports
3467-
interleaved or non-interleaved samples. The ``copy_user`` callback is
3467+
interleaved or non-interleaved samples. The ``copy`` callback is
34683468
defined like below, a bit differently depending on whether the direction
34693469
is playback or capture::
34703470

3471-
static int playback_copy_user(struct snd_pcm_substream *substream,
3471+
static int playback_copy(struct snd_pcm_substream *substream,
34723472
int channel, unsigned long pos,
3473-
void __user *src, unsigned long count);
3474-
static int capture_copy_user(struct snd_pcm_substream *substream,
3473+
struct iov_iter *src, unsigned long count);
3474+
static int capture_copy(struct snd_pcm_substream *substream,
34753475
int channel, unsigned long pos,
3476-
void __user *dst, unsigned long count);
3476+
struct iov_iter *dst, unsigned long count);
34773477

34783478
In the case of interleaved samples, the second argument (``channel``) is
34793479
not used. The third argument (``pos``) specifies the position in bytes.
@@ -3490,18 +3490,17 @@ of data (``count``) at the specified pointer (``src``) to the specified
34903490
offset (``pos``) in the hardware buffer. When coded like memcpy-like
34913491
way, the copy would look like::
34923492

3493-
my_memcpy_from_user(my_buffer + pos, src, count);
3493+
my_memcpy_from_iter(my_buffer + pos, src, count);
34943494

34953495
For the capture direction, you copy the given amount of data (``count``)
34963496
at the specified offset (``pos``) in the hardware buffer to the
34973497
specified pointer (``dst``)::
34983498

3499-
my_memcpy_to_user(dst, my_buffer + pos, count);
3499+
my_memcpy_to_iter(dst, my_buffer + pos, count);
35003500

3501-
Here the functions are named ``from_user`` and ``to_user`` because
3502-
it's the user-space buffer that is passed to these callbacks. That
3503-
is, the callback is supposed to copy data from/to the user-space
3504-
directly to/from the hardware buffer.
3501+
The given ``src`` or ``dst`` a struct iov_iter pointer containing the
3502+
pointer and the size. Use the existing helpers to copy or access the
3503+
data as defined in ``linux/uio.h``.
35053504

35063505
Careful readers might notice that these callbacks receive the
35073506
arguments in bytes, not in frames like other callbacks. It's because
@@ -3519,36 +3518,17 @@ the given user-space buffer, but only for the given channel. For
35193518
details, please check ``isa/gus/gus_pcm.c`` or ``pci/rme9652/rme9652.c``
35203519
as examples.
35213520

3522-
The above callbacks are the copies from/to the user-space buffer. There
3523-
are some cases where we want to copy from/to the kernel-space buffer
3524-
instead. In such a case, the ``copy_kernel`` callback is called. It'd
3525-
look like::
3526-
3527-
static int playback_copy_kernel(struct snd_pcm_substream *substream,
3528-
int channel, unsigned long pos,
3529-
void *src, unsigned long count);
3530-
static int capture_copy_kernel(struct snd_pcm_substream *substream,
3531-
int channel, unsigned long pos,
3532-
void *dst, unsigned long count);
3533-
3534-
As found easily, the only difference is that the buffer pointer is
3535-
without a ``__user`` prefix; that is, a kernel-buffer pointer is passed
3536-
in the fourth argument. Correspondingly, the implementation would be
3537-
a version without the user-copy, such as::
3538-
3539-
my_memcpy(my_buffer + pos, src, count);
3540-
35413521
Usually for the playback, another callback ``fill_silence`` is
35423522
defined. It's implemented in a similar way as the copy callbacks
35433523
above::
35443524

35453525
static int silence(struct snd_pcm_substream *substream, int channel,
35463526
unsigned long pos, unsigned long count);
35473527

3548-
The meanings of arguments are the same as in the ``copy_user`` and
3549-
``copy_kernel`` callbacks, although there is no buffer pointer
3528+
The meanings of arguments are the same as in the ``copy`` callback,
3529+
although there is no buffer pointer
35503530
argument. In the case of interleaved samples, the channel argument has
3551-
no meaning, as for the ``copy_*`` callbacks.
3531+
no meaning, as for the ``copy`` callback.
35523532

35533533
The role of the ``fill_silence`` callback is to set the given amount
35543534
(``count``) of silence data at the specified offset (``pos``) in the

0 commit comments

Comments
 (0)