[ALSA] alsa: nopage
[pandora-kernel.git] / sound / core / pcm_native.c
index 9052348..51294dd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Digital Audio (PCM) abstract layer
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This program is free software; you can redistribute it and/or modify
@@ -595,12 +595,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
        status->trigger_tstamp = runtime->trigger_tstamp;
        if (snd_pcm_running(substream)) {
                snd_pcm_update_hw_ptr(substream);
-               if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
+               if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_MMAP)
                        status->tstamp = runtime->status->tstamp;
                else
-                       getnstimeofday(&status->tstamp);
+                       snd_pcm_gettime(runtime, &status->tstamp);
        } else
-               getnstimeofday(&status->tstamp);
+               snd_pcm_gettime(runtime, &status->tstamp);
        status->appl_ptr = runtime->control->appl_ptr;
        status->hw_ptr = runtime->status->hw_ptr;
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
@@ -688,7 +688,7 @@ static void snd_pcm_trigger_tstamp(struct snd_pcm_substream *substream)
        if (runtime->trigger_master == NULL)
                return;
        if (runtime->trigger_master == substream) {
-               getnstimeofday(&runtime->trigger_tstamp);
+               snd_pcm_gettime(runtime, &runtime->trigger_tstamp);
        } else {
                snd_pcm_trigger_tstamp(runtime->trigger_master);
                runtime->trigger_tstamp = runtime->trigger_master->runtime->trigger_tstamp;
@@ -712,26 +712,23 @@ static int snd_pcm_action_group(struct action_ops *ops,
                                struct snd_pcm_substream *substream,
                                int state, int do_lock)
 {
-       struct list_head *pos;
        struct snd_pcm_substream *s = NULL;
        struct snd_pcm_substream *s1;
        int res = 0;
 
-       snd_pcm_group_for_each(pos, substream) {
-               s = snd_pcm_group_substream_entry(pos);
+       snd_pcm_group_for_each_entry(s, substream) {
                if (do_lock && s != substream)
-                       spin_lock(&s->self_group.lock);
+                       spin_lock_nested(&s->self_group.lock,
+                                        SINGLE_DEPTH_NESTING);
                res = ops->pre_action(s, state);
                if (res < 0)
                        goto _unlock;
        }
-       snd_pcm_group_for_each(pos, substream) {
-               s = snd_pcm_group_substream_entry(pos);
+       snd_pcm_group_for_each_entry(s, substream) {
                res = ops->do_action(s, state);
                if (res < 0) {
                        if (ops->undo_action) {
-                               snd_pcm_group_for_each(pos, substream) {
-                                       s1 = snd_pcm_group_substream_entry(pos);
+                               snd_pcm_group_for_each_entry(s1, substream) {
                                        if (s1 == s) /* failed stream */
                                                break;
                                        ops->undo_action(s1, state);
@@ -741,15 +738,13 @@ static int snd_pcm_action_group(struct action_ops *ops,
                        goto _unlock;
                }
        }
-       snd_pcm_group_for_each(pos, substream) {
-               s = snd_pcm_group_substream_entry(pos);
+       snd_pcm_group_for_each_entry(s, substream) {
                ops->post_action(s, state);
        }
  _unlock:
        if (do_lock) {
                /* unlock streams */
-               snd_pcm_group_for_each(pos, substream) {
-                       s1 = snd_pcm_group_substream_entry(pos);
+               snd_pcm_group_for_each_entry(s1, substream) {
                        if (s1 != substream)
                                spin_unlock(&s1->self_group.lock);
                        if (s1 == s)    /* end */
@@ -1438,7 +1433,7 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream)
 {
        struct snd_card *card;
        struct snd_pcm_runtime *runtime;
-       struct list_head *pos;
+       struct snd_pcm_substream *s;
        int result = 0;
        int i, num_drecs;
        struct drain_rec *drec, drec_tmp, *d;
@@ -1473,8 +1468,7 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream)
 
        /* count only playback streams */
        num_drecs = 0;
-       snd_pcm_group_for_each(pos, substream) {
-               struct snd_pcm_substream *s = snd_pcm_group_substream_entry(pos);
+       snd_pcm_group_for_each_entry(s, substream) {
                runtime = s->runtime;
                if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                        d = &drec[num_drecs++];
@@ -1493,7 +1487,7 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream)
 
        snd_pcm_stream_lock_irq(substream);
        /* resume pause */
-       if (runtime->status->state == SNDRV_PCM_STATE_PAUSED)
+       if (substream->runtime->status->state == SNDRV_PCM_STATE_PAUSED)
                snd_pcm_pause(substream, 0);
 
        /* pre-start/stop - all running streams are changed to DRAINING state */
@@ -1674,7 +1668,7 @@ static void relink_to_local(struct snd_pcm_substream *substream)
 
 static int snd_pcm_unlink(struct snd_pcm_substream *substream)
 {
-       struct list_head *pos;
+       struct snd_pcm_substream *s;
        int res = 0;
 
        down_write(&snd_pcm_link_rwsem);
@@ -1686,8 +1680,8 @@ static int snd_pcm_unlink(struct snd_pcm_substream *substream)
        list_del(&substream->link_list);
        substream->group->count--;
        if (substream->group->count == 1) {     /* detach the last stream, too */
-               snd_pcm_group_for_each(pos, substream) {
-                       relink_to_local(snd_pcm_group_substream_entry(pos));
+               snd_pcm_group_for_each_entry(s, substream) {
+                       relink_to_local(s);
                        break;
                }
                kfree(substream->group);
@@ -1793,12 +1787,18 @@ static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params *params,
 static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
                                  48000, 64000, 88200, 96000, 176400, 192000 };
 
+const struct snd_pcm_hw_constraint_list snd_pcm_known_rates = {
+       .count = ARRAY_SIZE(rates),
+       .list = rates,
+};
+
 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params *params,
                                struct snd_pcm_hw_rule *rule)
 {
        struct snd_pcm_hardware *hw = rule->private;
        return snd_interval_list(hw_param_interval(params, rule->var),
-                                ARRAY_SIZE(rates), rates, hw->rates);
+                                snd_pcm_known_rates.count,
+                                snd_pcm_known_rates.list, hw->rates);
 }              
 
 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params *params,
@@ -2519,6 +2519,21 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
                return -EFAULT;
        return 0;
 }
+
+static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       int arg;
+       
+       if (get_user(arg, _arg))
+               return -EFAULT;
+       if (arg < 0 || arg > SNDRV_PCM_TSTAMP_TYPE_LAST)
+               return -EINVAL;
+       runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
+       if (arg == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
+               runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
+       return 0;
+}
                
 static int snd_pcm_common_ioctl1(struct file *file,
                                 struct snd_pcm_substream *substream,
@@ -2531,8 +2546,8 @@ static int snd_pcm_common_ioctl1(struct file *file,
                return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0;
        case SNDRV_PCM_IOCTL_INFO:
                return snd_pcm_info_user(substream, arg);
-       case SNDRV_PCM_IOCTL_TSTAMP: /* just for compatibility */
-               return 0;
+       case SNDRV_PCM_IOCTL_TTSTAMP:
+               return snd_pcm_tstamp(substream, arg);
        case SNDRV_PCM_IOCTL_HW_REFINE:
                return snd_pcm_hw_refine_user(substream, arg);
        case SNDRV_PCM_IOCTL_HW_PARAMS:
@@ -3018,26 +3033,23 @@ static unsigned int snd_pcm_capture_poll(struct file *file, poll_table * wait)
 /*
  * mmap status record
  */
-static struct page * snd_pcm_mmap_status_nopage(struct vm_area_struct *area,
-                                               unsigned long address, int *type)
+static int snd_pcm_mmap_status_fault(struct vm_area_struct *area,
+                                               struct vm_fault *vmf)
 {
        struct snd_pcm_substream *substream = area->vm_private_data;
        struct snd_pcm_runtime *runtime;
-       struct page * page;
        
        if (substream == NULL)
-               return NOPAGE_SIGBUS;
+               return VM_FAULT_SIGBUS;
        runtime = substream->runtime;
-       page = virt_to_page(runtime->status);
-       get_page(page);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       vmf->page = virt_to_page(runtime->status);
+       get_page(vmf->page);
+       return 0;
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_status =
 {
-       .nopage =       snd_pcm_mmap_status_nopage,
+       .fault =        snd_pcm_mmap_status_fault,
 };
 
 static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
@@ -3061,26 +3073,23 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file
 /*
  * mmap control record
  */
-static struct page * snd_pcm_mmap_control_nopage(struct vm_area_struct *area,
-                                                unsigned long address, int *type)
+static int snd_pcm_mmap_control_fault(struct vm_area_struct *area,
+                                               struct vm_fault *vmf)
 {
        struct snd_pcm_substream *substream = area->vm_private_data;
        struct snd_pcm_runtime *runtime;
-       struct page * page;
        
        if (substream == NULL)
-               return NOPAGE_SIGBUS;
+               return VM_FAULT_SIGBUS;
        runtime = substream->runtime;
-       page = virt_to_page(runtime->control);
-       get_page(page);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       vmf->page = virt_to_page(runtime->control);
+       get_page(vmf->page);
+       return 0;
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_control =
 {
-       .nopage =       snd_pcm_mmap_control_nopage,
+       .fault =        snd_pcm_mmap_control_fault,
 };
 
 static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file,
@@ -3117,10 +3126,10 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file
 #endif /* coherent mmap */
 
 /*
- * nopage callback for mmapping a RAM page
+ * fault callback for mmapping a RAM page
  */
-static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
-                                            unsigned long address, int *type)
+static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,
+                                               struct vm_fault *vmf)
 {
        struct snd_pcm_substream *substream = area->vm_private_data;
        struct snd_pcm_runtime *runtime;
@@ -3130,33 +3139,30 @@ static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
        size_t dma_bytes;
        
        if (substream == NULL)
-               return NOPAGE_SIGBUS;
+               return VM_FAULT_SIGBUS;
        runtime = substream->runtime;
-       offset = area->vm_pgoff << PAGE_SHIFT;
-       offset += address - area->vm_start;
-       snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_SIGBUS);
+       offset = vmf->pgoff << PAGE_SHIFT;
        dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
        if (offset > dma_bytes - PAGE_SIZE)
-               return NOPAGE_SIGBUS;
+               return VM_FAULT_SIGBUS;
        if (substream->ops->page) {
                page = substream->ops->page(substream, offset);
-               if (! page)
-                       return NOPAGE_OOM; /* XXX: is this really due to OOM? */
+               if (!page)
+                       return VM_FAULT_SIGBUS;
        } else {
                vaddr = runtime->dma_area + offset;
                page = virt_to_page(vaddr);
        }
        get_page(page);
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       vmf->page = page;
+       return 0;
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_data =
 {
        .open =         snd_pcm_mmap_data_open,
        .close =        snd_pcm_mmap_data_close,
-       .nopage =       snd_pcm_mmap_data_nopage,
+       .fault =        snd_pcm_mmap_data_fault,
 };
 
 /*