OSDN Git Service

topology: Support configuring physical DAIs by C API
[android-x86/external-alsa-lib.git] / include / local.h
1 /*
2  *  ALSA lib - local header file
3  *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4  *
5  *
6  *   This library is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 of
9  *   the License, or (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21
22 #ifndef __LOCAL_H
23 #define __LOCAL_H
24
25 #include "config.h"
26
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <fcntl.h>
32 #include <assert.h>
33 #ifdef HAVE_ENDIAN_H
34 #include <endian.h>
35 #elif defined(HAVE_SYS_ENDIAN_H)
36 #include <sys/endian.h>
37 #ifndef __BYTE_ORDER
38 #define __BYTE_ORDER BYTE_ORDER
39 #endif
40 #ifndef __LITTLE_ENDIAN
41 #define __LITTLE_ENDIAN LITTLE_ENDIAN
42 #endif
43 #ifndef __BIG_ENDIAN
44 #define __BIG_ENDIAN BIG_ENDIAN
45 #endif
46 #else
47 #error Header defining endianness not defined
48 #endif
49 #include <stdarg.h>
50 #include <sys/poll.h>
51 #include <sys/types.h>
52 #include <errno.h>
53 #if defined(__linux__)
54 #include <linux/types.h>
55 #include <linux/ioctl.h>
56 #else
57 #include "type_compat.h"
58 #endif
59
60 #ifdef SUPPORT_RESMGR
61 #include <resmgr.h>
62 #endif
63 #ifdef HAVE_LIBDL
64 #include <dlfcn.h>
65 #else
66 #define RTLD_NOW        0
67 #endif
68
69 #if __BYTE_ORDER == __LITTLE_ENDIAN
70 #define SND_LITTLE_ENDIAN
71 #define SNDRV_LITTLE_ENDIAN
72 #elif __BYTE_ORDER == __BIG_ENDIAN
73 #define SND_BIG_ENDIAN
74 #define SNDRV_BIG_ENDIAN
75 #else
76 #error "Unsupported endian..."
77 #endif
78
79 #define _snd_config_iterator list_head
80 #define _snd_interval snd_interval
81 #define _snd_pcm_info snd_pcm_info
82 #define _snd_pcm_hw_params snd_pcm_hw_params
83 #define _snd_pcm_sw_params snd_pcm_sw_params
84 #define _snd_pcm_status snd_pcm_status
85
86 #define _snd_ctl_card_info snd_ctl_card_info
87 #define _snd_ctl_elem_id snd_ctl_elem_id
88 #define _snd_ctl_elem_list snd_ctl_elem_list
89 #define _snd_ctl_elem_info snd_ctl_elem_info
90 #define _snd_ctl_elem_value snd_ctl_elem_value
91 #define _snd_ctl_event snd_ctl_event
92
93 #define _snd_rawmidi_info snd_rawmidi_info
94 #define _snd_rawmidi_params snd_rawmidi_params
95 #define _snd_rawmidi_status snd_rawmidi_status
96
97 #define _snd_hwdep_info snd_hwdep_info
98 #define _snd_hwdep_dsp_status snd_hwdep_dsp_status
99 #define _snd_hwdep_dsp_image snd_hwdep_dsp_image
100
101 #define _snd_seq_queue_tempo snd_seq_queue_tempo
102 #define _snd_seq_client_info snd_seq_client_info
103 #define _snd_seq_port_info snd_seq_port_info
104 #define _snd_seq_system_info snd_seq_system_info
105 #define _snd_seq_queue_info snd_seq_queue_info
106 #define _snd_seq_queue_status snd_seq_queue_status
107 #define _snd_seq_queue_timer snd_seq_queue_timer
108 #define _snd_seq_port_subscribe snd_seq_port_subscribe
109 #define _snd_seq_query_subscribe snd_seq_query_subs
110 #define _snd_seq_client_pool snd_seq_client_pool
111 #define _snd_seq_remove_events snd_seq_remove_events
112
113 #define _snd_timer_id snd_timer_id
114 #define _snd_timer_ginfo snd_timer_ginfo
115 #define _snd_timer_gparams snd_timer_gparams
116 #define _snd_timer_gstatus snd_timer_gstatus
117 #define _snd_timer_select snd_timer_select
118 #define _snd_timer_info snd_timer_info
119 #define _snd_timer_params snd_timer_params
120 #define _snd_timer_status snd_timer_status
121
122 #define ALSA_LIBRARY_BUILD
123
124 /* rename some types for avoiding conflicts with alsalib's definitions */
125 #define snd_aes_iec958          sndrv_aes_iec958
126 #define snd_pcm_uframes_t       sndrv_pcm_uframes_t
127 #define snd_pcm_sframes_t       sndrv_pcm_sframes_t
128 #define snd_pcm_access_t        sndrv_pcm_access_t
129 #define snd_pcm_format_t        sndrv_pcm_format_t
130 #define snd_pcm_subformat_t     sndrv_pcm_subformat_t
131 #define snd_pcm_state_t         sndrv_pcm_state_t
132 #define snd_interval            sndrv_interval
133 #define snd_mask                sndrv_mask
134 #define snd_ctl_elem_type_t     sndrv_ctl_elem_type_t
135 #define snd_ctl_elem_iface_t    sndrv_ctl_elem_iface_t
136 #define snd_ctl_tlv             sndrv_ctl_tlv
137
138 /* kill and replace kernel-specific types */
139 #ifndef __user
140 #define __user
141 #endif
142 #ifndef __force
143 #define __force
144 #endif
145
146 #include <sound/asound.h>
147
148 /* take back superfluous renames; some can be kept as is */
149 #undef snd_aes_iec958
150 #undef snd_pcm_uframes_t
151 #undef snd_pcm_sframes_t
152 #undef snd_pcm_access_t
153 #undef snd_pcm_format_t
154 #undef snd_pcm_subformat_t
155 #undef snd_pcm_state_t
156 #undef snd_ctl_elem_type_t
157 #undef snd_ctl_elem_iface_t
158
159 #include <sound/asoundef.h>
160 #include "alsa-symbols.h"
161 #include "version.h"
162 #include "global.h"
163 #include "input.h"
164 #include "output.h"
165 #include "error.h"
166 #include "conf.h"
167 #include "pcm.h"
168 #include "pcm_plugin.h"
169 #include "rawmidi.h"
170 #include "timer.h"
171 #include "hwdep.h"
172 #include "control.h"
173 #include "mixer.h"
174 #include "seq_event.h"
175 #include "seq.h"
176
177 /* rename some types for avoiding conflicts with alsalib's definitions */
178 #define snd_seq_addr            sndrv_seq_addr
179 #define snd_seq_tick_time_t     sndrv_seq_tick_time_t
180 #define snd_seq_real_time       sndrv_seq_real_time
181 #define snd_seq_timestamp       sndrv_seq_timestamp
182 #define snd_seq_event_type_t    sndrv_seq_event_type_t
183 #define snd_seq_event           sndrv_seq_event
184 #define snd_seq_connect         sndrv_seq_connect
185 #define snd_seq_ev_note         sndrv_seq_ev_note
186 #define snd_seq_ev_ctrl         sndrv_seq_ev_ctrl
187 #define snd_seq_ev_raw8         sndrv_seq_ev_raw8
188 #define snd_seq_ev_raw32        sndrv_seq_ev_raw32
189 #define snd_seq_ev_ext          sndrv_seq_ev_ext
190 #define snd_seq_result          sndrv_seq_result
191 #define snd_seq_queue_skew      sndrv_seq_queue_skew
192 #define snd_seq_ev_queue_control        sndrv_seq_ev_queue_control
193 #define snd_seq_client_t        sndrv_seq_client_t
194 #define snd_seq_client_type_t   sndrv_seq_client_type_t
195
196 #include <sound/asequencer.h>
197
198 /* take back some renames */
199 #undef snd_seq_client_t
200 #undef snd_seq_client_type_t
201
202 #include "seqmid.h"
203 #include "seq_midi_event.h"
204 #include "list.h"
205
206 struct _snd_async_handler {
207         enum {
208                 SND_ASYNC_HANDLER_GENERIC,
209                 SND_ASYNC_HANDLER_CTL,
210                 SND_ASYNC_HANDLER_PCM,
211                 SND_ASYNC_HANDLER_TIMER,
212         } type;
213         int fd;
214         union {
215                 snd_ctl_t *ctl;
216                 snd_pcm_t *pcm;
217                 snd_timer_t *timer;
218         } u;
219         snd_async_callback_t callback;
220         void *private_data;
221         struct list_head glist;
222         struct list_head hlist;
223 };
224
225 typedef enum _snd_set_mode {
226         SND_CHANGE,
227         SND_TRY,
228         SND_TEST,
229 } snd_set_mode_t;
230
231 size_t page_align(size_t size);
232 size_t page_size(void);
233 size_t page_ptr(size_t object_offset, size_t object_size, size_t *offset, size_t *mmap_offset);
234
235 int safe_strtol(const char *str, long *val);
236
237 int snd_send_fd(int sock, void *data, size_t len, int fd);
238 int snd_receive_fd(int sock, void *data, size_t len, int *fd);
239
240 /*
241  * error messages
242  */
243 #ifndef NDEBUG
244 #define CHECK_SANITY(x) x
245 extern snd_lib_error_handler_t snd_err_msg;
246 #define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __FUNCTION__, 0, ##args)
247 #define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __FUNCTION__, errno, ##args)
248 #else
249 #define CHECK_SANITY(x) 0 /* not evaluated */
250 #define SNDMSG(args...) /* nop */
251 #define SYSMSG(args...) /* nop */
252 #endif
253
254 /*
255  */
256 #define HAVE_GNU_LD
257 #define HAVE_ELF
258 #define HAVE_ASM_PREVIOUS_DIRECTIVE
259
260 /* Stolen from libc-symbols.h in GNU glibc */
261
262 /* When a reference to SYMBOL is encountered, the linker will emit a
263    warning message MSG.  */
264
265 #define ASM_NAME(name) __SYMBOL_PREFIX name
266
267 #ifdef HAVE_GNU_LD
268 # ifdef HAVE_ELF
269
270 /* We want the .gnu.warning.SYMBOL section to be unallocated.  */
271 #  ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
272 #   define __make_section_unallocated(section_string)   \
273   asm (".section " section_string "\n\t.previous");
274 #  elif defined HAVE_ASM_POPSECTION_DIRECTIVE
275 #   define __make_section_unallocated(section_string)   \
276   asm (".pushsection " section_string "\n\t.popsection");
277 #  else
278 #   define __make_section_unallocated(section_string)
279 #  endif
280
281 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
282    section attributes on what looks like a comment to the assembler.  */
283 #  ifdef HAVE_SECTION_QUOTES
284 #   define link_warning(symbol, msg) \
285   __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
286   static const char __evoke_link_warning_##symbol[]     \
287     __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\"\n\t#\""))) = msg;
288 #  else
289 #   define link_warning(symbol, msg) \
290   __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
291   static const char __evoke_link_warning_##symbol[]     \
292     __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\n\t#"))) = msg;
293 #  endif
294 # else
295 #  define link_warning(symbol, msg)             \
296   asm (".stabs \"" msg "\",30,0,0,0\n\t"        \
297        ".stabs \"" ASM_NAME(#symbol) "\",1,0,0,0\n");
298 # endif
299 #else
300 /* We will never be heard; they will all die horribly.  */
301 # define link_warning(symbol, msg)
302 #endif
303
304 static inline int snd_open_device(const char *filename, int fmode)
305 {
306         int fd;
307
308 #ifdef O_CLOEXEC
309         fmode |= O_CLOEXEC;
310 #endif
311         fd = open(filename, fmode);
312
313 /* open with resmgr */
314 #ifdef SUPPORT_RESMGR
315         if (fd < 0) {
316                 if (errno == EAGAIN || errno == EBUSY)
317                         return fd;
318                 if (! access(filename, F_OK))
319                         fd = rsm_open_device(filename, fmode);
320         }
321 #endif
322         if (fd >= 0)
323                 fcntl(fd, F_SETFD, FD_CLOEXEC);
324         return fd;
325 }
326
327 /* make local functions really local */
328 #define snd_dlobj_cache_get \
329         snd1_dlobj_cache_get
330 #define snd_dlobj_cache_put \
331         snd1_dlobj_cache_put
332 #define snd_dlobj_cache_cleanup \
333         snd1_dlobj_cache_cleanup
334 #define snd_config_set_hop \
335         snd1_config_set_hop
336 #define snd_config_check_hop \
337         snd1_config_check_hop
338 #define snd_config_search_alias_hooks \
339         snd1_config_search_alias_hooks
340
341 /* dlobj cache */
342 void *snd_dlobj_cache_get(const char *lib, const char *name, const char *version, int verbose);
343 int snd_dlobj_cache_put(void *open_func);
344 void snd_dlobj_cache_cleanup(void);
345
346 /* for recursive checks */
347 void snd_config_set_hop(snd_config_t *conf, int hop);
348 int snd_config_check_hop(snd_config_t *conf);
349 #define SND_CONF_MAX_HOPS       64
350
351 int snd_config_search_alias_hooks(snd_config_t *config,
352                                   const char *base, const char *key,
353                                   snd_config_t **result);
354
355 int _snd_conf_generic_id(const char *id);
356
357 /* convenience macros */
358 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
359
360 #define container_of(ptr, type, member) ({                      \
361          const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
362         (type *)( (char *)__mptr - offsetof(type,member) );})
363
364 #endif