--- ../alsa-kernel/core/pcm_native.c	2005-05-18 22:44:22.000000000 +0200
+++ pcm_native.c	2005-05-22 14:41:29.000000000 +0200
@@ -1,3 +1,4 @@
+#define __NO_VERSION__
 /*
  *  Digital Audio (PCM) abstract layer
  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
@@ -2747,6 +2748,9 @@
 	snd_pcm_runtime_t *runtime;
 	snd_pcm_sframes_t result;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
+	up(&file->f_dentry->d_inode->i_sem);
+#endif
 	pcm_file = file->private_data;
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, result = -ENXIO; goto end);
@@ -2764,9 +2768,13 @@
 	if (result > 0)
 		result = frames_to_bytes(runtime, result);
  end:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
+	down(&file->f_dentry->d_inode->i_sem);
+#endif
 	return result;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 44)
 static ssize_t snd_pcm_readv(struct file *file, const struct iovec *_vector,
 			     unsigned long count, loff_t * offset)
 
@@ -2813,6 +2821,9 @@
 	void __user **bufs;
 	snd_pcm_uframes_t frames;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
+	up(&file->f_dentry->d_inode->i_sem);
+#endif
 	pcm_file = file->private_data;
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, result = -ENXIO; goto end);
@@ -2837,8 +2848,12 @@
 		result = frames_to_bytes(runtime, result);
 	kfree(bufs);
  end:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
+	down(&file->f_dentry->d_inode->i_sem);
+#endif
 	return result;
 }
+#endif
 
 static unsigned int snd_pcm_playback_poll(struct file *file, poll_table * wait)
 {
@@ -2924,6 +2939,17 @@
  * mmap support
  */
 
+#ifndef VM_RESERVED
+#ifndef LINUX_2_2
+static int snd_pcm_mmap_swapout(struct page * page, struct file * file)
+#else
+static int snd_pcm_mmap_swapout(struct vm_area_struct * area, struct page * page)
+#endif
+{
+	return 0;
+}
+#endif
+
 /*
  * Only on coherent architectures, we can mmap the status and the control records
  * for effcient data transfer.  On others, we have to use HWSYNC ioctl...
@@ -2932,7 +2958,13 @@
 /*
  * mmap status record
  */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 static struct page * snd_pcm_mmap_status_nopage(struct vm_area_struct *area, unsigned long address, int *type)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
+static struct page * snd_pcm_mmap_status_nopage(struct vm_area_struct *area, unsigned long address, int no_share)
+#else
+static unsigned long snd_pcm_mmap_status_nopage(struct vm_area_struct *area, unsigned long address, int no_share)
+#endif
 {
 	snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data;
 	snd_pcm_runtime_t *runtime;
@@ -2944,9 +2976,15 @@
 	page = virt_to_page(runtime->status);
 	if (!PageReserved(page))
 		get_page(page);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 	if (type)
 		*type = VM_FAULT_MINOR;
+#endif
+#ifndef LINUX_2_2
 	return page;
+#else
+	return page_address(page);
+#endif
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_status =
@@ -2967,15 +3005,27 @@
 	if (size != PAGE_ALIGN(sizeof(snd_pcm_mmap_status_t)))
 		return -EINVAL;
 	area->vm_ops = &snd_pcm_vm_ops_status;
+#ifndef LINUX_2_2
 	area->vm_private_data = substream;
+#else
+	area->vm_private_data = (long)substream;
+#endif
+#ifdef VM_RESERVED
 	area->vm_flags |= VM_RESERVED;
+#endif
 	return 0;
 }
 
 /*
  * mmap control record
  */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 static struct page * snd_pcm_mmap_control_nopage(struct vm_area_struct *area, unsigned long address, int *type)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
+static struct page * snd_pcm_mmap_control_nopage(struct vm_area_struct *area, unsigned long address, int no_share)
+#else
+static unsigned long snd_pcm_mmap_control_nopage(struct vm_area_struct *area, unsigned long address, int no_share)
+#endif
 {
 	snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data;
 	snd_pcm_runtime_t *runtime;
@@ -2987,9 +3037,15 @@
 	page = virt_to_page(runtime->control);
 	if (!PageReserved(page))
 		get_page(page);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 	if (type)
 		*type = VM_FAULT_MINOR;
+#endif
+#ifndef LINUX_2_2
 	return page;
+#else
+	return page_address(page);
+#endif
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_control =
@@ -3010,8 +3066,14 @@
 	if (size != PAGE_ALIGN(sizeof(snd_pcm_mmap_control_t)))
 		return -EINVAL;
 	area->vm_ops = &snd_pcm_vm_ops_control;
+#ifndef LINUX_2_2
 	area->vm_private_data = substream;
+#else
+	area->vm_private_data = (long)substream;
+#endif
+#ifdef VM_RESERVED
 	area->vm_flags |= VM_RESERVED;
+#endif
 	return 0;
 }
 #else /* ! coherent mmap */
@@ -3033,7 +3095,13 @@
 /*
  * nopage callback for mmapping a RAM page
  */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area, unsigned long address, int *type)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
+static struct page * snd_pcm_mmap_data_nopage(struct vm_area_struct *area, unsigned long address, int no_share)
+#else
+static unsigned long snd_pcm_mmap_data_nopage(struct vm_area_struct *area, unsigned long address, int no_share)
+#endif
 {
 	snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data;
 	snd_pcm_runtime_t *runtime;
@@ -3045,7 +3113,11 @@
 	if (substream == NULL)
 		return NOPAGE_OOM;
 	runtime = substream->runtime;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 25)
 	offset = area->vm_pgoff << PAGE_SHIFT;
+#else
+	offset = area->vm_offset;
+#endif
 	offset += address - area->vm_start;
 	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM);
 	dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
@@ -3061,9 +3133,15 @@
 	}
 	if (!PageReserved(page))
 		get_page(page);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 	if (type)
 		*type = VM_FAULT_MINOR;
+#endif
+#ifndef LINUX_2_2
 	return page;
+#else
+	return page_address(page);
+#endif
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_data =
@@ -3071,6 +3149,9 @@
 	.open =		snd_pcm_mmap_data_open,
 	.close =	snd_pcm_mmap_data_close,
 	.nopage =	snd_pcm_mmap_data_nopage,
+#ifndef VM_RESERVED
+	.swapout =	snd_pcm_mmap_swapout,
+#endif
 };
 
 /*
@@ -3079,8 +3160,14 @@
 static int snd_pcm_default_mmap(snd_pcm_substream_t *substream, struct vm_area_struct *area)
 {
 	area->vm_ops = &snd_pcm_vm_ops_data;
+#ifndef LINUX_2_2
 	area->vm_private_data = substream;
+#else
+	area->vm_private_data = (long)substream;
+#endif
+#ifdef VM_RESERVED
 	area->vm_flags |= VM_RESERVED;
+#endif
 	atomic_inc(&substream->runtime->mmap_count);
 	return 0;
 }
@@ -3104,14 +3191,37 @@
 	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
 #endif
 	area->vm_ops = &snd_pcm_vm_ops_data_mmio;
+#ifndef LINUX_2_2
 	area->vm_private_data = substream;
+#else
+	area->vm_private_data = (long)substream;
+#endif
 	area->vm_flags |= VM_IO;
 	size = area->vm_end - area->vm_start;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 25)
 	offset = area->vm_pgoff << PAGE_SHIFT;
+#else
+	offset = area->vm_offset;
+#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
+#define io_remap_page_range remap_page_range
+#endif
+#ifdef CONFIG_HAVE_IO_REMAP_PFN_RANGE
 	if (io_remap_pfn_range(area, area->vm_start,
 				(substream->runtime->dma_addr + offset) >> PAGE_SHIFT,
 				size, area->vm_page_prot))
 		return -EAGAIN;
+#elif defined(CONFIG_OLD_IO_REMAP_PAGE_RANGE)
+	if (io_remap_page_range(area->vm_start,
+				substream->runtime->dma_addr + offset,
+				size, area->vm_page_prot))
+		return -EAGAIN;
+#else
+	if (io_remap_page_range(area, area->vm_start,
+				substream->runtime->dma_addr + offset,
+				size, area->vm_page_prot))
+		return -EAGAIN;
+#endif
 	atomic_inc(&substream->runtime->mmap_count);
 	return 0;
 }
@@ -3145,7 +3255,11 @@
 	    runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
 		return -EINVAL;
 	size = area->vm_end - area->vm_start;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 25)
 	offset = area->vm_pgoff << PAGE_SHIFT;
+#else
+	offset = area->vm_offset;
+#endif
 	dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
 	if ((size_t)size > dma_bytes)
 		return -EINVAL;
@@ -3168,7 +3282,11 @@
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, return -ENXIO);
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 25)
 	offset = area->vm_pgoff << PAGE_SHIFT;
+#else
+	offset = area->vm_offset;
+#endif
 	switch (offset) {
 	case SNDRV_PCM_MMAP_OFFSET_STATUS:
 		if (substream->no_mmap_ctrl)
@@ -3205,12 +3323,34 @@
 /*
  * ioctl32 compat
  */
-#ifdef CONFIG_COMPAT
+#if defined(CONFIG_COMPAT) && defined(CONFIG_SND_HAVE_NEW_IOCTL)
 #include "pcm_compat.c"
 #else
 #define snd_pcm_ioctl_compat	NULL
 #endif
 
+#ifndef CONFIG_SND_HAVE_NEW_IOCTL
+/* need to unlock BKL to allow preemption */
+static int snd_pcm_playback_ioctl_old(struct inode *inode, struct file * file,
+				      unsigned int cmd, unsigned long arg)
+{
+	int err;
+	unlock_kernel();
+	err = snd_pcm_playback_ioctl(file, cmd, arg);
+	lock_kernel();
+	return err;
+}
+static int snd_pcm_capture_ioctl_old(struct inode *inode, struct file * file,
+				      unsigned int cmd, unsigned long arg)
+{
+	int err;
+	unlock_kernel();
+	err = snd_pcm_capture_ioctl(file, cmd, arg);
+	lock_kernel();
+	return err;
+}
+#endif
+
 /*
  *  To be removed helpers to keep binary compatibility
  */
@@ -3326,27 +3466,43 @@
  */
 
 static struct file_operations snd_pcm_f_ops_playback = {
+#ifndef LINUX_2_2
 	.owner =	THIS_MODULE,
+#endif
 	.write =	snd_pcm_write,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 44)
 	.writev =	snd_pcm_writev,
+#endif
 	.open =		snd_pcm_open,
 	.release =	snd_pcm_release,
 	.poll =		snd_pcm_playback_poll,
+#ifdef CONFIG_SND_HAVE_NEW_IOCTL
 	.unlocked_ioctl =	snd_pcm_playback_ioctl,
 	.compat_ioctl = snd_pcm_ioctl_compat,
+#else
+	.ioctl =	snd_pcm_playback_ioctl_old,
+#endif
 	.mmap =		snd_pcm_mmap,
 	.fasync =	snd_pcm_fasync,
 };
 
 static struct file_operations snd_pcm_f_ops_capture = {
+#ifndef LINUX_2_2
 	.owner =	THIS_MODULE,
+#endif
 	.read =		snd_pcm_read,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 44)
 	.readv =	snd_pcm_readv,
+#endif
 	.open =		snd_pcm_open,
 	.release =	snd_pcm_release,
 	.poll =		snd_pcm_capture_poll,
+#ifdef CONFIG_SND_HAVE_NEW_IOCTL
 	.unlocked_ioctl =	snd_pcm_capture_ioctl,
 	.compat_ioctl = snd_pcm_ioctl_compat,
+#else
+	.ioctl =	snd_pcm_capture_ioctl_old,
+#endif
 	.mmap =		snd_pcm_mmap,
 	.fasync =	snd_pcm_fasync,
 };
