integrity: add ima_counts_put (updated)
[safe/jmp/linux-2.6] / include / sound / pcm.h
index 7e77c0a..2389352 100644 (file)
@@ -3,7 +3,7 @@
 
 /*
  *  Digital Audio (PCM) abstract layer
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *                   Abramo Bagnara <abramo@alsa-project.org>
  *
  *
@@ -25,7 +25,9 @@
 
 #include <sound/asound.h>
 #include <sound/memalloc.h>
+#include <sound/minors.h>
 #include <linux/poll.h>
+#include <linux/mm.h>
 #include <linux/bitops.h>
 
 #define snd_pcm_substream_chip(substream) ((substream)->private_data)
@@ -55,6 +57,8 @@ struct snd_pcm_hardware {
        size_t fifo_size;               /* fifo size in bytes */
 };
 
+struct snd_pcm_substream;
+
 struct snd_pcm_ops {
        int (*open)(struct snd_pcm_substream *substream);
        int (*close)(struct snd_pcm_substream *substream);
@@ -81,7 +85,11 @@ struct snd_pcm_ops {
  *
  */
 
-#define SNDRV_PCM_DEVICES              8
+#if defined(CONFIG_SND_DYNAMIC_MINORS)
+#define SNDRV_PCM_DEVICES      (SNDRV_OS_MINORS-2)
+#else
+#define SNDRV_PCM_DEVICES      8
+#endif
 
 #define SNDRV_PCM_IOCTL1_FALSE         ((void *)0)
 #define SNDRV_PCM_IOCTL1_TRUE          ((void *)1)
@@ -90,6 +98,7 @@ struct snd_pcm_ops {
 #define SNDRV_PCM_IOCTL1_INFO          1
 #define SNDRV_PCM_IOCTL1_CHANNEL_INFO  2
 #define SNDRV_PCM_IOCTL1_GSTATE                3
+#define SNDRV_PCM_IOCTL1_FIFO_SIZE     4
 
 #define SNDRV_PCM_TRIGGER_STOP         0
 #define SNDRV_PCM_TRIGGER_START                1
@@ -190,7 +199,7 @@ struct snd_pcm_ops {
 
 struct snd_pcm_file {
        struct snd_pcm_substream *substream;
-       struct snd_pcm_file *next;
+       int no_compat_mmap;
 };
 
 struct snd_pcm_hw_rule;
@@ -260,7 +269,9 @@ struct snd_pcm_runtime {
        int overrange;
        snd_pcm_uframes_t avail_max;
        snd_pcm_uframes_t hw_ptr_base;  /* Position at buffer restart */
-       snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time*/
+       snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
+       unsigned long hw_ptr_jiffies;   /* Time when hw_ptr is updated */
+       snd_pcm_sframes_t delay;        /* extra delay; typically FIFO size */
 
        /* -- HW params -- */
        snd_pcm_access_t access;        /* access mode */
@@ -271,7 +282,6 @@ struct snd_pcm_runtime {
        snd_pcm_uframes_t period_size;  /* period size */
        unsigned int periods;           /* periods */
        snd_pcm_uframes_t buffer_size;  /* buffer size */
-       unsigned int tick_time;         /* tick time */
        snd_pcm_uframes_t min_align;    /* Min alignment for the format */
        size_t byte_align;
        unsigned int frame_bits;
@@ -283,8 +293,6 @@ struct snd_pcm_runtime {
        /* -- SW params -- */
        int tstamp_mode;                /* mmap timestamp is updated */
        unsigned int period_step;
-       unsigned int sleep_min;         /* min ticks to sleep */
-       snd_pcm_uframes_t xfer_align;   /* xfer size need to be a multiple */
        snd_pcm_uframes_t start_threshold;
        snd_pcm_uframes_t stop_threshold;
        snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
@@ -298,13 +306,11 @@ struct snd_pcm_runtime {
        union snd_pcm_sync_id sync;     /* hardware synchronization ID */
 
        /* -- mmap -- */
-       volatile struct snd_pcm_mmap_status *status;
-       volatile struct snd_pcm_mmap_control *control;
-       atomic_t mmap_count;
+       struct snd_pcm_mmap_status *status;
+       struct snd_pcm_mmap_control *control;
 
        /* -- locking / scheduling -- */
        wait_queue_head_t sleep;
-       struct timer_list tick_timer;
        struct fasync_struct *fasync;
 
        /* -- private section -- */
@@ -321,6 +327,7 @@ struct snd_pcm_runtime {
 
        /* -- timer -- */
        unsigned int timer_resolution;  /* timer resolution */
+       int tstamp_type;                /* timestamp type */
 
        /* -- DMA -- */           
        unsigned char *dma_area;        /* DMA area */
@@ -348,6 +355,7 @@ struct snd_pcm_substream {
        int number;
        char name[32];                  /* substream name */
        int stream;                     /* stream (direction) */
+       char latency_id[20];            /* latency identifier */
        size_t buffer_bytes_max;        /* limit ring buffer size */
        struct snd_dma_buffer dma_buffer;
        unsigned int dma_buf_id;
@@ -359,7 +367,6 @@ struct snd_pcm_substream {
         /* -- timer section -- */
        struct snd_timer *timer;                /* timer */
        unsigned timer_running: 1;      /* time is running */
-       spinlock_t timer_lock;
        /* -- next substream -- */
        struct snd_pcm_substream *next;
        /* -- linked substreams -- */
@@ -367,27 +374,29 @@ struct snd_pcm_substream {
        struct snd_pcm_group self_group;        /* fake group for non linked substream (with substream lock inside) */
        struct snd_pcm_group *group;            /* pointer to current group */
        /* -- assigned files -- */
-       struct snd_pcm_file *file;
-       struct file *ffile;
+       void *file;
+       int ref_count;
+       atomic_t mmap_count;
+       unsigned int f_flags;
+       void (*pcm_release)(struct snd_pcm_substream *);
 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
        /* -- OSS things -- */
        struct snd_pcm_oss_substream oss;
 #endif
+#ifdef CONFIG_SND_VERBOSE_PROCFS
        struct snd_info_entry *proc_root;
        struct snd_info_entry *proc_info_entry;
        struct snd_info_entry *proc_hw_params_entry;
        struct snd_info_entry *proc_sw_params_entry;
        struct snd_info_entry *proc_status_entry;
        struct snd_info_entry *proc_prealloc_entry;
+       struct snd_info_entry *proc_prealloc_max_entry;
+#endif
        /* misc flags */
-       unsigned int no_mmap_ctrl: 1;
+       unsigned int hw_opened: 1;
 };
 
-#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
-#define SUBSTREAM_BUSY(substream) ((substream)->file != NULL || ((substream)->oss.file != NULL))
-#else
-#define SUBSTREAM_BUSY(substream) ((substream)->file != NULL)
-#endif
+#define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
 
 
 struct snd_pcm_str {
@@ -401,29 +410,31 @@ struct snd_pcm_str {
        /* -- OSS things -- */
        struct snd_pcm_oss_stream oss;
 #endif
-       struct snd_pcm_file *files;
-       struct snd_minor *reg;
+#ifdef CONFIG_SND_VERBOSE_PROCFS
        struct snd_info_entry *proc_root;
        struct snd_info_entry *proc_info_entry;
-#ifdef CONFIG_SND_DEBUG
+#ifdef CONFIG_SND_PCM_XRUN_DEBUG
        unsigned int xrun_debug;        /* 0 = disabled, 1 = verbose, 2 = stacktrace */
        struct snd_info_entry *proc_xrun_debug_entry;
 #endif
+#endif
 };
 
 struct snd_pcm {
        struct snd_card *card;
-       unsigned int device;    /* device number */
+       struct list_head list;
+       int device; /* device number */
        unsigned int info_flags;
        unsigned short dev_class;
        unsigned short dev_subclass;
        char id[64];
        char name[80];
        struct snd_pcm_str streams[2];
-       struct semaphore open_mutex;
+       struct mutex open_mutex;
        wait_queue_head_t open_wait;
        void *private_data;
        void (*private_free) (struct snd_pcm *pcm);
+       struct device *dev; /* actual hw device this belongs to */
 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
        struct snd_pcm_oss oss;
 #endif
@@ -440,10 +451,9 @@ struct snd_pcm_notify {
  *  Registering
  */
 
-extern struct snd_pcm *snd_pcm_devices[];
-extern struct snd_minor snd_pcm_reg[2];
+extern const struct file_operations snd_pcm_f_ops[2];
 
-int snd_pcm_new(struct snd_card *card, char *id, int device,
+int snd_pcm_new(struct snd_card *card, const char *id, int device,
                int playback_count, int capture_count,
                struct snd_pcm **rpcm);
 int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
@@ -461,7 +471,6 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,
                      struct snd_pcm_info __user *info);
 int snd_pcm_status(struct snd_pcm_substream *substream,
                   struct snd_pcm_status *status);
-int snd_pcm_prepare(struct snd_pcm_substream *substream);
 int snd_pcm_start(struct snd_pcm_substream *substream);
 int snd_pcm_stop(struct snd_pcm_substream *substream, int status);
 int snd_pcm_drain_done(struct snd_pcm_substream *substream);
@@ -469,88 +478,16 @@ int snd_pcm_drain_done(struct snd_pcm_substream *substream);
 int snd_pcm_suspend(struct snd_pcm_substream *substream);
 int snd_pcm_suspend_all(struct snd_pcm *pcm);
 #endif
-int snd_pcm_kernel_playback_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
-int snd_pcm_kernel_capture_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
-int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct snd_pcm_substream **rsubstream);
+int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
+                          struct snd_pcm_substream **rsubstream);
 void snd_pcm_release_substream(struct snd_pcm_substream *substream);
+int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
+                            struct snd_pcm_substream **rsubstream);
+void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
 void snd_pcm_vma_notify_data(void *client, void *data);
 int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
 
-#if BITS_PER_LONG >= 64
-
-static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
-{
-       *rem = *n % div;
-       *n /= div;
-}
-
-#elif defined(i386)
-
-static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
-{
-       u_int32_t low, high;
-       low = *n & 0xffffffff;
-       high = *n >> 32;
-       if (high) {
-               u_int32_t high1 = high % div;
-               high /= div;
-               asm("divl %2":"=a" (low), "=d" (*rem):"rm" (div), "a" (low), "d" (high1));
-               *n = (u_int64_t)high << 32 | low;
-       } else {
-               *n = low / div;
-               *rem = low % div;
-       }
-}
-#else
-
-static inline void divl(u_int32_t high, u_int32_t low,
-                       u_int32_t div,
-                       u_int32_t *q, u_int32_t *r)
-{
-       u_int64_t n = (u_int64_t)high << 32 | low;
-       u_int64_t d = (u_int64_t)div << 31;
-       u_int32_t q1 = 0;
-       int c = 32;
-       while (n > 0xffffffffU) {
-               q1 <<= 1;
-               if (n >= d) {
-                       n -= d;
-                       q1 |= 1;
-               }
-               d >>= 1;
-               c--;
-       }
-       q1 <<= c;
-       if (n) {
-               low = n;
-               *q = q1 | (low / div);
-               *r = low % div;
-       } else {
-               *r = 0;
-               *q = q1;
-       }
-       return;
-}
-
-static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
-{
-       u_int32_t low, high;
-       low = *n & 0xffffffff;
-       high = *n >> 32;
-       if (high) {
-               u_int32_t high1 = high % div;
-               u_int32_t low1 = low;
-               high /= div;
-               divl(high1, low1, div, &low, rem);
-               *n = (u_int64_t)high << 32 | low;
-       } else {
-               *n = low / div;
-               *rem = low % div;
-       }
-}
-#endif
-
 /*
  *  PCM library
  */
@@ -596,11 +533,8 @@ do { \
        read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
 } while (0)
 
-#define snd_pcm_group_for_each(pos, substream) \
-       list_for_each(pos, &substream->group->substreams)
-
-#define snd_pcm_group_substream_entry(pos) \
-       list_entry(pos, struct snd_pcm_substream, link_list)
+#define snd_pcm_group_for_each_entry(s, substream) \
+       list_for_each_entry(s, &substream->group->substreams, link_list)
 
 static inline int snd_pcm_running(struct snd_pcm_substream *substream)
 {
@@ -787,13 +721,13 @@ static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *p
 static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
                                             snd_pcm_hw_param_t var)
 {
-       return (const struct snd_mask *)hw_param_mask((struct snd_pcm_hw_params*) params, var);
+       return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
 }
 
 static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
                                                     snd_pcm_hw_param_t var)
 {
-       return (const struct snd_interval *)hw_param_interval((struct snd_pcm_hw_params*) params, var);
+       return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
 }
 
 #define params_access(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_ACCESS))
@@ -806,7 +740,6 @@ static inline const struct snd_interval *hw_param_interval_c(const struct snd_pc
 #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min
 #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min
 #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min
-#define params_tick_time(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_TICK_TIME)->min
 
 
 int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
@@ -823,14 +756,6 @@ int snd_interval_ratnum(struct snd_interval *i,
 
 void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
 void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
-int snd_pcm_hw_param_near(struct snd_pcm_substream *substream, 
-                         struct snd_pcm_hw_params *params,
-                         snd_pcm_hw_param_t var, 
-                         unsigned int val, int *dir);
-int snd_pcm_hw_param_set(struct snd_pcm_substream *pcm,
-                        struct snd_pcm_hw_params *params,
-                        snd_pcm_hw_param_t var,
-                        unsigned int val, int dir);
 int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
 
 int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
@@ -900,7 +825,6 @@ ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
 const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
-const char *snd_pcm_format_name(snd_pcm_format_t format);
 
 void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
 void snd_pcm_set_sync(struct snd_pcm_substream *substream);
@@ -913,9 +837,6 @@ int snd_pcm_capture_xrun_check(struct snd_pcm_substream *substream);
 int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
 int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
 void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
-void snd_pcm_tick_prepare(struct snd_pcm_substream *substream);
-void snd_pcm_tick_set(struct snd_pcm_substream *substream, unsigned long ticks);
-void snd_pcm_tick_elapsed(struct snd_pcm_substream *substream);
 void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
 snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
                                    const void __user *buf,
@@ -927,7 +848,10 @@ snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
 snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
                                    void __user **bufs, snd_pcm_uframes_t frames);
 
+extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
+
 int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
+unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
 
 static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
                                              struct snd_dma_buffer *bufp)
@@ -954,6 +878,15 @@ void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
 void snd_pcm_timer_init(struct snd_pcm_substream *substream);
 void snd_pcm_timer_done(struct snd_pcm_substream *substream);
 
+static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
+                                  struct timespec *tv)
+{
+       if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
+               do_posix_clock_monotonic_gettime(tv);
+       else
+               getnstimeofday(tv);
+}
+
 /*
  *  Memory
  */
@@ -969,22 +902,42 @@ int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
 int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
 int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
 
-#define snd_pcm_substream_sgbuf(substream) ((substream)->runtime->dma_buffer_p->private_data)
-#define snd_pcm_sgbuf_pages(size) snd_sgbuf_aligned_pages(size)
-#define snd_pcm_sgbuf_get_addr(sgbuf,ofs) snd_sgbuf_get_addr(sgbuf,ofs)
-struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset);
+/*
+ * SG-buffer handling
+ */
+#define snd_pcm_substream_sgbuf(substream) \
+       ((substream)->runtime->dma_buffer_p->private_data)
+
+static inline dma_addr_t
+snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
+{
+       struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
+       return snd_sgbuf_get_addr(sg, ofs);
+}
+
+static inline void *
+snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
+{
+       struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
+       return snd_sgbuf_get_ptr(sg, ofs);
+}
+
+struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
+                                   unsigned long offset);
+unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
+                                         unsigned int ofs, unsigned int size);
 
 /* handle mmap counter - PCM mmap callback should handle this counter properly */
 static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
 {
        struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
-       atomic_inc(&substream->runtime->mmap_count);
+       atomic_inc(&substream->mmap_count);
 }
 
 static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
 {
        struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
-       atomic_dec(&substream->runtime->mmap_count);
+       atomic_dec(&substream->mmap_count);
 }
 
 /* mmap for io-memory area */
@@ -1010,4 +963,6 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
                                         (IEC958_AES1_CON_PCM_CODER<<8)|\
                                         (IEC958_AES3_CON_FS_48000<<24))
 
+#define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
+
 #endif /* __SOUND_PCM_H */