@@ -727,8 +727,13 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
struct audioformat *fmt;
int ret;
+#ifdef SND_USB_USE_DEV_ALLOC
+ ret = snd_pcm_lib_malloc_pages(substream,
+ params_buffer_bytes(hw_params));
+#else
ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
+#endif
if (ret < 0)
return ret;
@@ -780,7 +785,11 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
snd_usb_endpoint_deactivate(subs->data_endpoint);
snd_usb_unlock_shutdown(subs->stream->chip);
}
+#ifdef SND_USB_USE_DEV_ALLOC
+ return snd_pcm_lib_free_pages(substream);
+#else
return snd_pcm_lib_free_vmalloc_buffer(substream);
+#endif
}
/*
@@ -1700,8 +1709,12 @@ static const struct snd_pcm_ops snd_usb_playback_ops = {
.prepare = snd_usb_pcm_prepare,
.trigger = snd_usb_substream_playback_trigger,
.pointer = snd_usb_pcm_pointer,
+#ifdef SND_USB_USE_DEV_ALLOC
+ .page = snd_pcm_sgbuf_ops_page,
+#else
.page = snd_pcm_lib_get_vmalloc_page,
.mmap = snd_pcm_lib_mmap_vmalloc,
+#endif
};
static const struct snd_pcm_ops snd_usb_capture_ops = {
@@ -1713,8 +1726,12 @@ static const struct snd_pcm_ops snd_usb_capture_ops = {
.prepare = snd_usb_pcm_prepare,
.trigger = snd_usb_substream_capture_trigger,
.pointer = snd_usb_pcm_pointer,
+#ifdef SND_USB_USE_DEV_ALLOC
+ .page = snd_pcm_sgbuf_ops_page,
+#else
.page = snd_pcm_lib_get_vmalloc_page,
.mmap = snd_pcm_lib_mmap_vmalloc,
+#endif
};
void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream)
@@ -1723,3 +1740,15 @@ void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream)
stream == SNDRV_PCM_STREAM_PLAYBACK ?
&snd_usb_playback_ops : &snd_usb_capture_ops);
}
+
+#ifdef SND_USB_USE_DEV_ALLOC
+void snd_usb_preallocate_buffer(struct snd_usb_substream *subs)
+{
+ struct snd_pcm *pcm = subs->stream->pcm;
+ struct snd_pcm_substream *s = pcm->streams[subs->direction].substream;
+ struct device *dev = subs->dev->bus->controller;
+
+ snd_pcm_lib_preallocate_pages(s, SNDRV_DMA_TYPE_DEV_SG,
+ dev, 64*1024, 512*1024);
+}
+#endif
@@ -2,6 +2,9 @@
#ifndef __USBAUDIO_PCM_H
#define __USBAUDIO_PCM_H
+/* use the standard dev alloc */
+#define SND_USB_USE_DEV_ALLOC
+
snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
unsigned int rate);
@@ -11,5 +14,10 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
struct usb_host_interface *alts,
struct audioformat *fmt);
+#ifdef SND_USB_USE_DEV_ALLOC
+void snd_usb_preallocate_buffer(struct snd_usb_substream *subs);
+#else
+#define snd_usb_preallocate_buffer(subs) /* NOP */
+#endif
#endif /* __USBAUDIO_PCM_H */
@@ -106,6 +106,8 @@ static void snd_usb_init_substream(struct snd_usb_stream *as,
subs->ep_num = fp->endpoint;
if (fp->channels > subs->channels_max)
subs->channels_max = fp->channels;
+
+ snd_usb_preallocate_buffer(subs);
}
/* kctl callbacks for usb-audio channel maps */