aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2017-06-27 05:54:37 -0400
committerTakashi Iwai <tiwai@suse.de>2017-06-27 07:56:03 -0400
commitb602aa8eb1a0f52f0f9a09728b3b1c9133136656 (patch)
treefc4cb31166644316033d0a8f350a0a2b83148839 /sound/core
parent4b671f57747468d7c810caaf955f79ff1aece4d4 (diff)
ALSA: pcm: Disable only control mmap for explicit appl_ptr sync
Now that user-space (typically alsa-lib) can specify which protocol version it supports, we can optimize the kernel code depending on the reported protocol version. In this patch, we change the previous hack for enforcing the appl_ptr sync by disabling status/control mmap. Instead of forcibly disabling both mmaps, we disable only the control mmap when user-space declares the supported protocol version new enough. For older user-space, still both PCM status and control mmaps are disabled when requested by the driver due to the compatibility reason. Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/pcm_native.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 1c53d93e68f2..0d1834310531 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3388,12 +3388,23 @@ static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file)
3388{ 3388{
3389 if (pcm_file->no_compat_mmap) 3389 if (pcm_file->no_compat_mmap)
3390 return false; 3390 return false;
3391 /* Disallow the status/control mmap when SYNC_APPLPTR flag is set; 3391 /* See pcm_control_mmap_allowed() below.
3392 * Since older alsa-lib requires both status and control mmaps to be
3393 * coupled, we have to disable the status mmap for old alsa-lib, too.
3394 */
3395 if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) &&
3396 (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR))
3397 return false;
3398 return true;
3399}
3400
3401static bool pcm_control_mmap_allowed(struct snd_pcm_file *pcm_file)
3402{
3403 if (pcm_file->no_compat_mmap)
3404 return false;
3405 /* Disallow the control mmap when SYNC_APPLPTR flag is set;
3392 * it enforces the user-space to fall back to snd_pcm_sync_ptr(), 3406 * it enforces the user-space to fall back to snd_pcm_sync_ptr(),
3393 * thus it effectively assures the manual update of appl_ptr. 3407 * thus it effectively assures the manual update of appl_ptr.
3394 * In theory, it should be enough to disallow only PCM control mmap,
3395 * but since the current alsa-lib implementation requires both status
3396 * and control mmaps always paired, we have to disable both of them.
3397 */ 3408 */
3398 if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR) 3409 if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)
3399 return false; 3410 return false;
@@ -3405,6 +3416,7 @@ static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file)
3405 * don't support mmap for status and control records. 3416 * don't support mmap for status and control records.
3406 */ 3417 */
3407#define pcm_status_mmap_allowed(pcm_file) false 3418#define pcm_status_mmap_allowed(pcm_file) false
3419#define pcm_control_mmap_allowed(pcm_file) false
3408 3420
3409static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, 3421static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
3410 struct vm_area_struct *area) 3422 struct vm_area_struct *area)
@@ -3593,7 +3605,7 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
3593 return -ENXIO; 3605 return -ENXIO;
3594 return snd_pcm_mmap_status(substream, file, area); 3606 return snd_pcm_mmap_status(substream, file, area);
3595 case SNDRV_PCM_MMAP_OFFSET_CONTROL: 3607 case SNDRV_PCM_MMAP_OFFSET_CONTROL:
3596 if (!pcm_status_mmap_allowed(pcm_file)) 3608 if (!pcm_control_mmap_allowed(pcm_file))
3597 return -ENXIO; 3609 return -ENXIO;
3598 return snd_pcm_mmap_control(substream, file, area); 3610 return snd_pcm_mmap_control(substream, file, area);
3599 default: 3611 default: