Skip to content

Commit 4b671f5

Browse files
committed
ALSA: pcm: Add an ioctl to specify the supported protocol version
We have an ioctl to inform the PCM protocol version the running kernel supports, but there is no way to know which protocol version the user-space can understand. This lack of information caused headaches in the past when we tried to extend the ABI. For example, because we couldn't guarantee the validity of the reserved bytes, we had to introduce a new ioctl SNDRV_PCM_IOCTL_STATUS_EXT for assigning a few new fields in the formerly reserved bits. If we could know that it's a new alsa-lib, we could assume the availability of the new fields, thus we could have reused the existing SNDRV_PCM_IOCTL_STATUS. In order to improve the ABI extensibility, this patch adds a new ioctl for user-space to inform its supporting protocol version to the kernel. By reporting the supported protocol from user-space, the kernel can judge which feature should be provided and which not. With the addition of the new ioctl, the PCM protocol version is bumped to 2.0.14, too. User-space checks the kernel protocol version via SNDRV_PCM_INFO_PVERSION, then it sets the supported version back via SNDRV_PCM_INFO_USER_PVERSION. Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 532a778 commit 4b671f5

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎include/sound/pcm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ struct snd_pcm_ops {
218218
struct snd_pcm_file {
219219
struct snd_pcm_substream *substream;
220220
int no_compat_mmap;
221+
unsigned int user_pversion; /* supported protocol version */
221222
};
222223

223224
struct snd_pcm_hw_rule;

‎include/uapi/sound/asound.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct snd_hwdep_dsp_image {
152152
* *
153153
*****************************************************************************/
154154

155-
#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 13)
155+
#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 14)
156156

157157
typedef unsigned long snd_pcm_uframes_t;
158158
typedef signed long snd_pcm_sframes_t;
@@ -564,6 +564,7 @@ enum {
564564
#define SNDRV_PCM_IOCTL_INFO _IOR('A', 0x01, struct snd_pcm_info)
565565
#define SNDRV_PCM_IOCTL_TSTAMP _IOW('A', 0x02, int)
566566
#define SNDRV_PCM_IOCTL_TTSTAMP _IOW('A', 0x03, int)
567+
#define SNDRV_PCM_IOCTL_USER_PVERSION _IOW('A', 0x04, int)
567568
#define SNDRV_PCM_IOCTL_HW_REFINE _IOWR('A', 0x10, struct snd_pcm_hw_params)
568569
#define SNDRV_PCM_IOCTL_HW_PARAMS _IOWR('A', 0x11, struct snd_pcm_hw_params)
569570
#define SNDRV_PCM_IOCTL_HW_FREE _IO('A', 0x12)

‎sound/core/pcm_compat.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned l
676676
case SNDRV_PCM_IOCTL_INFO:
677677
case SNDRV_PCM_IOCTL_TSTAMP:
678678
case SNDRV_PCM_IOCTL_TTSTAMP:
679+
case SNDRV_PCM_IOCTL_USER_PVERSION:
679680
case SNDRV_PCM_IOCTL_HWSYNC:
680681
case SNDRV_PCM_IOCTL_PREPARE:
681682
case SNDRV_PCM_IOCTL_RESET:

‎sound/core/pcm_native.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,8 @@ static int snd_pcm_common_ioctl(struct file *file,
27702770
struct snd_pcm_substream *substream,
27712771
unsigned int cmd, void __user *arg)
27722772
{
2773+
struct snd_pcm_file *pcm_file = file->private_data;
2774+
27732775
switch (cmd) {
27742776
case SNDRV_PCM_IOCTL_PVERSION:
27752777
return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0;
@@ -2779,6 +2781,11 @@ static int snd_pcm_common_ioctl(struct file *file,
27792781
return 0;
27802782
case SNDRV_PCM_IOCTL_TTSTAMP:
27812783
return snd_pcm_tstamp(substream, arg);
2784+
case SNDRV_PCM_IOCTL_USER_PVERSION:
2785+
if (get_user(pcm_file->user_pversion,
2786+
(unsigned int __user *)arg))
2787+
return -EFAULT;
2788+
return 0;
27822789
case SNDRV_PCM_IOCTL_HW_REFINE:
27832790
return snd_pcm_hw_refine_user(substream, arg);
27842791
case SNDRV_PCM_IOCTL_HW_PARAMS:

0 commit comments

Comments
 (0)