From f36a154247c2a2ddee1a48b3413da4d8d8e0cfc7 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 07:34:58 +0000 Subject: alsa-lib-1.2.3.2 base --- diff --git a/configure b/configure index 1b392f0..4434098 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for alsa-lib 1.2.1.2. +# Generated by GNU Autoconf 2.69 for alsa-lib 1.2.3.2. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -587,8 +587,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='alsa-lib' PACKAGE_TARNAME='alsa-lib' -PACKAGE_VERSION='1.2.1.2' -PACKAGE_STRING='alsa-lib 1.2.1.2' +PACKAGE_VERSION='1.2.3.2' +PACKAGE_STRING='alsa-lib 1.2.3.2' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1457,7 +1457,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures alsa-lib 1.2.1.2 to adapt to many kinds of systems. +\`configure' configures alsa-lib 1.2.3.2 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1527,7 +1527,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of alsa-lib 1.2.1.2:";; + short | recursive ) echo "Configuration of alsa-lib 1.2.3.2:";; esac cat <<\_ACEOF @@ -1688,7 +1688,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -alsa-lib configure 1.2.1.2 +alsa-lib configure 1.2.3.2 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2099,7 +2099,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by alsa-lib $as_me 1.2.1.2, which was +It was created by alsa-lib $as_me 1.2.3.2, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3037,7 +3037,7 @@ fi # Define the identity of the package. PACKAGE='alsa-lib' - VERSION='1.2.1.2' + VERSION='1.2.3.2' cat >>confdefs.h <<_ACEOF @@ -12318,9 +12318,13 @@ CC=$lt_save_CC case $host in - *-freebsd*) ;; + + *-freebsd* | *-openbsd*) ;; + *-mingw*) + LDFLAGS_NOUNDEFINED="-no-undefined" + ;; *) - for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do + for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports $possible_flags flag" >&5 $as_echo_n "checking if $CC supports $possible_flags flag... " >&6; } @@ -12351,7 +12355,7 @@ $as_echo "$ac_res" >&6; } LDFLAGS_NOUNDEFINED="$possible_flags" fi - break + if test "x$LDFLAGS_NOUNDEFINED" = "x"; then break; fi done ;; esac @@ -13501,7 +13505,10 @@ if test "$build_python" = "yes" -a "$build_mixer_pymodules" = "yes"; then pythonlibs0= pythoninc0= if test "$build_python2" != "yes"; then - pythonlibs0=$(python3-config --libs) + pythonlibs0=$(python3-config --libs --embed 2> /dev/null) + if test -z "$pythonlibs0"; then + pythonlibs0=$(python3-config --libs) + fi pythoninc0=$(python3-config --includes) fi if test -z "$pythonlibs0"; then @@ -13701,6 +13708,26 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_have_atomics" >&5 $as_echo "$gcc_have_atomics" >&6; } + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +__asm__ volatile ("" : : : "mm0"); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +$as_echo "#define HAVE_MMX \"1\"" >>confdefs.h + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + PCM_PLUGIN_LIST="copy linear route mulaw alaw adpcm rate plug multi shm file null empty share meter hooks lfloat ladspa dmix dshare dsnoop asym iec958 softvol extplug ioplug mmap_emul" build_pcm_plugin="no" @@ -14140,7 +14167,7 @@ if test ! -L "$srcdir"/include/alsa ; then ln -sf . "$srcdir"/include/alsa fi -ac_config_files="$ac_config_files Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg include/Makefile include/sound/Makefile src/Versions src/Makefile src/control/Makefile src/mixer/Makefile src/pcm/Makefile src/pcm/scopes/Makefile src/rawmidi/Makefile src/timer/Makefile src/hwdep/Makefile src/seq/Makefile src/ucm/Makefile src/alisp/Makefile src/topology/Makefile src/conf/Makefile src/conf/cards/Makefile src/conf/pcm/Makefile modules/Makefile modules/mixer/Makefile modules/mixer/simple/Makefile alsalisp/Makefile aserver/Makefile test/Makefile test/lsb/Makefile utils/Makefile utils/alsa-lib.spec utils/alsa.pc utils/alsa-topology.pc" +ac_config_files="$ac_config_files Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg include/Makefile include/sound/Makefile include/sound/uapi/Makefile src/Versions src/Makefile src/control/Makefile src/mixer/Makefile src/pcm/Makefile src/pcm/scopes/Makefile src/rawmidi/Makefile src/timer/Makefile src/hwdep/Makefile src/seq/Makefile src/ucm/Makefile src/alisp/Makefile src/topology/Makefile src/conf/Makefile src/conf/cards/Makefile src/conf/pcm/Makefile modules/Makefile modules/mixer/Makefile modules/mixer/simple/Makefile alsalisp/Makefile aserver/Makefile test/Makefile test/lsb/Makefile utils/Makefile utils/alsa-lib.spec utils/alsa.pc utils/alsa-topology.pc" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -14860,7 +14887,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by alsa-lib $as_me 1.2.1.2, which was +This file was extended by alsa-lib $as_me 1.2.3.2, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -14926,7 +14953,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -alsa-lib config.status 1.2.1.2 +alsa-lib config.status 1.2.3.2 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -15347,6 +15374,7 @@ do "doc/doxygen.cfg") CONFIG_FILES="$CONFIG_FILES doc/doxygen.cfg" ;; "include/Makefile") CONFIG_FILES="$CONFIG_FILES include/Makefile" ;; "include/sound/Makefile") CONFIG_FILES="$CONFIG_FILES include/sound/Makefile" ;; + "include/sound/uapi/Makefile") CONFIG_FILES="$CONFIG_FILES include/sound/uapi/Makefile" ;; "src/Versions") CONFIG_FILES="$CONFIG_FILES src/Versions" ;; "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;; "src/control/Makefile") CONFIG_FILES="$CONFIG_FILES src/control/Makefile" ;; @@ -16687,14 +16715,3 @@ test "$build_seq" = "yes" && echo "#include " >> include/asoundlib.h test "$build_seq" = "yes" && echo "#include " >> include/asoundlib.h test "$build_seq" = "yes" && echo "#include " >> include/asoundlib.h cat "$srcdir"/include/asoundlib-tail.h >> include/asoundlib.h - -case $host in - *-*-linux-gnu) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: Fixing libtool for -rpath problems." >&5 -$as_echo "Fixing libtool for -rpath problems." >&6; } - sed < libtool > libtool-2 \ - 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/' - mv libtool-2 libtool - chmod 755 libtool - ;; -esac diff --git a/configure.ac b/configure.ac index 119ef60..93a54c9 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(alsa-lib, 1.2.1.2) +AC_INIT(alsa-lib, 1.2.3.2) AC_CONFIG_SRCDIR([src/control/control.c]) AC_CONFIG_MACRO_DIR([m4]) @@ -423,7 +423,10 @@ if test "$build_python" = "yes" -a "$build_mixer_pymodules" = "yes"; then pythonlibs0= pythoninc0= if test "$build_python2" != "yes"; then - pythonlibs0=$(python3-config --libs) + pythonlibs0=$(python3-config --libs --embed 2> /dev/null) + if test -z "$pythonlibs0"; then + pythonlibs0=$(python3-config --libs) + fi pythoninc0=$(python3-config --includes) fi if test -z "$pythonlibs0"; then @@ -513,6 +516,13 @@ if test -z "$gcc_have_atomics"; then fi AC_MSG_RESULT($gcc_have_atomics) +dnl check mmx register for pcm_dmix_i386 + +AC_TRY_LINK([], + [__asm__ volatile ("" : : : "mm0");], + [AC_DEFINE([HAVE_MMX], "1", [MMX technology is enabled])], + []) + PCM_PLUGIN_LIST="copy linear route mulaw alaw adpcm rate plug multi shm file null empty share meter hooks lfloat ladspa dmix dshare dsnoop asym iec958 softvol extplug ioplug mmap_emul" build_pcm_plugin="no" @@ -707,7 +717,8 @@ if test ! -L "$srcdir"/include/alsa ; then fi AC_OUTPUT(Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg \ - include/Makefile include/sound/Makefile src/Versions src/Makefile \ + include/Makefile include/sound/Makefile include/sound/uapi/Makefile \ + src/Versions src/Makefile \ src/control/Makefile src/mixer/Makefile \ src/pcm/Makefile src/pcm/scopes/Makefile \ src/rawmidi/Makefile src/timer/Makefile \ @@ -764,14 +775,3 @@ test "$build_seq" = "yes" && echo "#include " >> include/asoundlib.h test "$build_seq" = "yes" && echo "#include " >> include/asoundlib.h test "$build_seq" = "yes" && echo "#include " >> include/asoundlib.h cat "$srcdir"/include/asoundlib-tail.h >> include/asoundlib.h - -dnl Taken from https://wiki.debian.org/RpathIssue -case $host in - *-*-linux-gnu) - AC_MSG_RESULT([Fixing libtool for -rpath problems.]) - sed < libtool > libtool-2 \ - 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/' - mv libtool-2 libtool - chmod 755 libtool - ;; -esac diff --git a/include/conf.h b/include/conf.h index 456b272..823ac63 100644 --- a/include/conf.h +++ b/include/conf.h @@ -139,6 +139,7 @@ int snd_config_imake_safe_string(snd_config_t **config, const char *key, const c int snd_config_imake_pointer(snd_config_t **config, const char *key, const void *ptr); snd_config_type_t snd_config_get_type(const snd_config_t *config); +int snd_config_is_array(const snd_config_t *config); int snd_config_set_id(snd_config_t *config, const char *id); int snd_config_set_integer(snd_config_t *config, long value); diff --git a/include/config.h.in b/include/config.h.in index 691d0e4..4f238c5 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -87,6 +87,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* MMX technology is enabled */ +#undef HAVE_MMX + /* Define if your pthreads implementation have PTHREAD_MUTEX_RECURSIVE */ #undef HAVE_PTHREAD_MUTEX_RECURSIVE diff --git a/include/global.h b/include/global.h index d73d333..71a1b12 100644 --- a/include/global.h +++ b/include/global.h @@ -97,6 +97,7 @@ extern struct snd_dlsym_link *snd_dlsym_start; /** \brief Returns the version of a dynamic symbol as a string. */ #define SND_DLSYM_VERSION(version) __STRING(version) +int snd_dlpath(char *path, size_t path_len, const char *name); void *snd_dlopen(const char *file, int mode, char *errbuf, size_t errbuflen); void *snd_dlsym(void *handle, const char *name, const char *version); int snd_dlclose(void *handle); diff --git a/include/local.h b/include/local.h index ea0ec32..ed6ba93 100644 --- a/include/local.h +++ b/include/local.h @@ -320,8 +320,10 @@ static inline int snd_open_device(const char *filename, int fmode) fd = rsm_open_device(filename, fmode); } #endif +#ifndef O_CLOEXEC if (fd >= 0) fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif return fd; } diff --git a/include/sound/Makefile.am b/include/sound/Makefile.am index 99c4221..ccc7d27 100644 --- a/include/sound/Makefile.am +++ b/include/sound/Makefile.am @@ -1,7 +1,9 @@ +SUBDIRS = uapi + alsasoundincludedir = ${includedir}/alsa/sound alsasoundinclude_HEADERS = asound_fm.h hdsp.h hdspm.h sb16_csp.h \ - sscape_ioctl.h emu10k1.h type_compat.h \ - asoc.h tlv.h + sscape_ioctl.h emu10k1.h asoc.h tlv.h \ + type_compat.h noinst_HEADERS = asound.h asequencer.h diff --git a/include/sound/Makefile.in b/include/sound/Makefile.in index 886bc88..caae76b 100644 --- a/include/sound/Makefile.in +++ b/include/sound/Makefile.in @@ -117,6 +117,14 @@ am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -151,6 +159,14 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(alsasoundincludedir)" HEADERS = $(alsasoundinclude_HEADERS) $(noinst_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir distdir-am am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is @@ -170,8 +186,34 @@ am__define_uniq_tagged_files = \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" ACLOCAL = @ACLOCAL@ ALSA_CONFIG_DIR = @ALSA_CONFIG_DIR@ ALSA_DEPLIBS = @ALSA_DEPLIBS@ @@ -302,13 +344,14 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +SUBDIRS = uapi alsasoundincludedir = ${includedir}/alsa/sound alsasoundinclude_HEADERS = asound_fm.h hdsp.h hdspm.h sb16_csp.h \ - sscape_ioctl.h emu10k1.h type_compat.h \ - asoc.h tlv.h + sscape_ioctl.h emu10k1.h asoc.h tlv.h \ + type_compat.h noinst_HEADERS = asound.h asequencer.h -all: all-am +all: all-recursive .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @@ -368,14 +411,61 @@ uninstall-alsasoundincludeHEADERS: files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(alsasoundincludedir)'; $(am__uninstall_files_from_dir) +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique -tags: tags-am +tags: tags-recursive TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ @@ -388,7 +478,7 @@ tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $$unique; \ fi; \ fi -ctags: ctags-am +ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) @@ -401,7 +491,7 @@ GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscopelist: cscopelist-am +cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ @@ -453,22 +543,48 @@ distdir-am: $(DISTFILES) || exit 1; \ fi; \ done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done check-am: all-am -check: check-am +check: check-recursive all-am: Makefile $(HEADERS) -installdirs: +installdirs: installdirs-recursive +installdirs-am: for dir in "$(DESTDIR)$(alsasoundincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -installcheck: installcheck-am +installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ @@ -490,87 +606,88 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -clean: clean-am +clean: clean-recursive clean-am: clean-generic clean-libtool mostlyclean-am -distclean: distclean-am +distclean: distclean-recursive -rm -f Makefile distclean-am: clean-am distclean-generic distclean-tags -dvi: dvi-am +dvi: dvi-recursive dvi-am: -html: html-am +html: html-recursive html-am: -info: info-am +info: info-recursive info-am: install-data-am: install-alsasoundincludeHEADERS -install-dvi: install-dvi-am +install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: -install-html: install-html-am +install-html: install-html-recursive install-html-am: -install-info: install-info-am +install-info: install-info-recursive install-info-am: install-man: -install-pdf: install-pdf-am +install-pdf: install-pdf-recursive install-pdf-am: -install-ps: install-ps-am +install-ps: install-ps-recursive install-ps-am: installcheck-am: -maintainer-clean: maintainer-clean-am +maintainer-clean: maintainer-clean-recursive -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic -mostlyclean: mostlyclean-am +mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-generic mostlyclean-libtool -pdf: pdf-am +pdf: pdf-recursive pdf-am: -ps: ps-am +ps: ps-recursive ps-am: uninstall-am: uninstall-alsasoundincludeHEADERS -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ - clean-libtool cscopelist-am ctags ctags-am distclean \ - distclean-generic distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install \ - install-alsasoundincludeHEADERS install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ - uninstall-alsasoundincludeHEADERS uninstall-am +.MAKE: $(am__recursive_targets) install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ + check-am clean clean-generic clean-libtool cscopelist-am ctags \ + ctags-am distclean distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-alsasoundincludeHEADERS install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs installdirs-am \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-alsasoundincludeHEADERS \ + uninstall-am .PRECIOUS: Makefile diff --git a/include/sound/asequencer.h b/include/sound/asequencer.h index a75e14e..e539a77 100644 --- a/include/sound/asequencer.h +++ b/include/sound/asequencer.h @@ -1,612 +1 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* - * Main header file for the ALSA sequencer - * Copyright (c) 1998-1999 by Frank van de Pol - * (c) 1998-1999 by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#ifndef _UAPI__SOUND_ASEQUENCER_H -#define _UAPI__SOUND_ASEQUENCER_H - -#include - -/** version of the sequencer */ -#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 2) - -/** - * definition of sequencer event types - */ - -/** system messages - * event data type = #snd_seq_result - */ -#define SNDRV_SEQ_EVENT_SYSTEM 0 -#define SNDRV_SEQ_EVENT_RESULT 1 - -/** note messages (channel specific) - * event data type = #snd_seq_ev_note - */ -#define SNDRV_SEQ_EVENT_NOTE 5 -#define SNDRV_SEQ_EVENT_NOTEON 6 -#define SNDRV_SEQ_EVENT_NOTEOFF 7 -#define SNDRV_SEQ_EVENT_KEYPRESS 8 - -/** control messages (channel specific) - * event data type = #snd_seq_ev_ctrl - */ -#define SNDRV_SEQ_EVENT_CONTROLLER 10 -#define SNDRV_SEQ_EVENT_PGMCHANGE 11 -#define SNDRV_SEQ_EVENT_CHANPRESS 12 -#define SNDRV_SEQ_EVENT_PITCHBEND 13 /**< from -8192 to 8191 */ -#define SNDRV_SEQ_EVENT_CONTROL14 14 /**< 14 bit controller value */ -#define SNDRV_SEQ_EVENT_NONREGPARAM 15 /**< 14 bit NRPN address + 14 bit unsigned value */ -#define SNDRV_SEQ_EVENT_REGPARAM 16 /**< 14 bit RPN address + 14 bit unsigned value */ - -/** synchronisation messages - * event data type = #snd_seq_ev_ctrl - */ -#define SNDRV_SEQ_EVENT_SONGPOS 20 /* Song Position Pointer with LSB and MSB values */ -#define SNDRV_SEQ_EVENT_SONGSEL 21 /* Song Select with song ID number */ -#define SNDRV_SEQ_EVENT_QFRAME 22 /* midi time code quarter frame */ -#define SNDRV_SEQ_EVENT_TIMESIGN 23 /* SMF Time Signature event */ -#define SNDRV_SEQ_EVENT_KEYSIGN 24 /* SMF Key Signature event */ - -/** timer messages - * event data type = snd_seq_ev_queue_control - */ -#define SNDRV_SEQ_EVENT_START 30 /* midi Real Time Start message */ -#define SNDRV_SEQ_EVENT_CONTINUE 31 /* midi Real Time Continue message */ -#define SNDRV_SEQ_EVENT_STOP 32 /* midi Real Time Stop message */ -#define SNDRV_SEQ_EVENT_SETPOS_TICK 33 /* set tick queue position */ -#define SNDRV_SEQ_EVENT_SETPOS_TIME 34 /* set realtime queue position */ -#define SNDRV_SEQ_EVENT_TEMPO 35 /* (SMF) Tempo event */ -#define SNDRV_SEQ_EVENT_CLOCK 36 /* midi Real Time Clock message */ -#define SNDRV_SEQ_EVENT_TICK 37 /* midi Real Time Tick message */ -#define SNDRV_SEQ_EVENT_QUEUE_SKEW 38 /* skew queue tempo */ - -/** others - * event data type = none - */ -#define SNDRV_SEQ_EVENT_TUNE_REQUEST 40 /* tune request */ -#define SNDRV_SEQ_EVENT_RESET 41 /* reset to power-on state */ -#define SNDRV_SEQ_EVENT_SENSING 42 /* "active sensing" event */ - -/** echo back, kernel private messages - * event data type = any type - */ -#define SNDRV_SEQ_EVENT_ECHO 50 /* echo event */ -#define SNDRV_SEQ_EVENT_OSS 51 /* OSS raw event */ - -/** system status messages (broadcast for subscribers) - * event data type = snd_seq_addr - */ -#define SNDRV_SEQ_EVENT_CLIENT_START 60 /* new client has connected */ -#define SNDRV_SEQ_EVENT_CLIENT_EXIT 61 /* client has left the system */ -#define SNDRV_SEQ_EVENT_CLIENT_CHANGE 62 /* client status/info has changed */ -#define SNDRV_SEQ_EVENT_PORT_START 63 /* new port was created */ -#define SNDRV_SEQ_EVENT_PORT_EXIT 64 /* port was deleted from system */ -#define SNDRV_SEQ_EVENT_PORT_CHANGE 65 /* port status/info has changed */ - -/** port connection changes - * event data type = snd_seq_connect - */ -#define SNDRV_SEQ_EVENT_PORT_SUBSCRIBED 66 /* ports connected */ -#define SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED 67 /* ports disconnected */ - -/* 70-89: synthesizer events - obsoleted */ - -/** user-defined events with fixed length - * event data type = any - */ -#define SNDRV_SEQ_EVENT_USR0 90 -#define SNDRV_SEQ_EVENT_USR1 91 -#define SNDRV_SEQ_EVENT_USR2 92 -#define SNDRV_SEQ_EVENT_USR3 93 -#define SNDRV_SEQ_EVENT_USR4 94 -#define SNDRV_SEQ_EVENT_USR5 95 -#define SNDRV_SEQ_EVENT_USR6 96 -#define SNDRV_SEQ_EVENT_USR7 97 -#define SNDRV_SEQ_EVENT_USR8 98 -#define SNDRV_SEQ_EVENT_USR9 99 - -/* 100-118: instrument layer - obsoleted */ -/* 119-129: reserved */ - -/* 130-139: variable length events - * event data type = snd_seq_ev_ext - * (SNDRV_SEQ_EVENT_LENGTH_VARIABLE must be set) - */ -#define SNDRV_SEQ_EVENT_SYSEX 130 /* system exclusive data (variable length) */ -#define SNDRV_SEQ_EVENT_BOUNCE 131 /* error event */ -/* 132-134: reserved */ -#define SNDRV_SEQ_EVENT_USR_VAR0 135 -#define SNDRV_SEQ_EVENT_USR_VAR1 136 -#define SNDRV_SEQ_EVENT_USR_VAR2 137 -#define SNDRV_SEQ_EVENT_USR_VAR3 138 -#define SNDRV_SEQ_EVENT_USR_VAR4 139 - -/* 150-151: kernel events with quote - DO NOT use in user clients */ -#define SNDRV_SEQ_EVENT_KERNEL_ERROR 150 -#define SNDRV_SEQ_EVENT_KERNEL_QUOTE 151 /* obsolete */ - -/* 152-191: reserved */ - -/* 192-254: hardware specific events */ - -/* 255: special event */ -#define SNDRV_SEQ_EVENT_NONE 255 - - -typedef unsigned char snd_seq_event_type_t; - -/** event address */ -struct snd_seq_addr { - unsigned char client; /**< Client number: 0..255, 255 = broadcast to all clients */ - unsigned char port; /**< Port within client: 0..255, 255 = broadcast to all ports */ -}; - -/** port connection */ -struct snd_seq_connect { - struct snd_seq_addr sender; - struct snd_seq_addr dest; -}; - - -#define SNDRV_SEQ_ADDRESS_UNKNOWN 253 /* unknown source */ -#define SNDRV_SEQ_ADDRESS_SUBSCRIBERS 254 /* send event to all subscribed ports */ -#define SNDRV_SEQ_ADDRESS_BROADCAST 255 /* send event to all queues/clients/ports/channels */ -#define SNDRV_SEQ_QUEUE_DIRECT 253 /* direct dispatch */ - - /* event mode flag - NOTE: only 8 bits available! */ -#define SNDRV_SEQ_TIME_STAMP_TICK (0<<0) /* timestamp in clock ticks */ -#define SNDRV_SEQ_TIME_STAMP_REAL (1<<0) /* timestamp in real time */ -#define SNDRV_SEQ_TIME_STAMP_MASK (1<<0) - -#define SNDRV_SEQ_TIME_MODE_ABS (0<<1) /* absolute timestamp */ -#define SNDRV_SEQ_TIME_MODE_REL (1<<1) /* relative to current time */ -#define SNDRV_SEQ_TIME_MODE_MASK (1<<1) - -#define SNDRV_SEQ_EVENT_LENGTH_FIXED (0<<2) /* fixed event size */ -#define SNDRV_SEQ_EVENT_LENGTH_VARIABLE (1<<2) /* variable event size */ -#define SNDRV_SEQ_EVENT_LENGTH_VARUSR (2<<2) /* variable event size - user memory space */ -#define SNDRV_SEQ_EVENT_LENGTH_MASK (3<<2) - -#define SNDRV_SEQ_PRIORITY_NORMAL (0<<4) /* normal priority */ -#define SNDRV_SEQ_PRIORITY_HIGH (1<<4) /* event should be processed before others */ -#define SNDRV_SEQ_PRIORITY_MASK (1<<4) - - - /* note event */ -struct snd_seq_ev_note { - unsigned char channel; - unsigned char note; - unsigned char velocity; - unsigned char off_velocity; /* only for SNDRV_SEQ_EVENT_NOTE */ - unsigned int duration; /* only for SNDRV_SEQ_EVENT_NOTE */ -}; - - /* controller event */ -struct snd_seq_ev_ctrl { - unsigned char channel; - unsigned char unused1, unused2, unused3; /* pad */ - unsigned int param; - signed int value; -}; - - /* generic set of bytes (12x8 bit) */ -struct snd_seq_ev_raw8 { - unsigned char d[12]; /* 8 bit value */ -}; - - /* generic set of integers (3x32 bit) */ -struct snd_seq_ev_raw32 { - unsigned int d[3]; /* 32 bit value */ -}; - - /* external stored data */ -struct snd_seq_ev_ext { - unsigned int len; /* length of data */ - void *ptr; /* pointer to data (note: maybe 64-bit) */ -} __attribute__((packed)); - -struct snd_seq_result { - int event; /* processed event type */ - int result; -}; - - -struct snd_seq_real_time { - unsigned int tv_sec; /* seconds */ - unsigned int tv_nsec; /* nanoseconds */ -}; - -typedef unsigned int snd_seq_tick_time_t; /* midi ticks */ - -union snd_seq_timestamp { - snd_seq_tick_time_t tick; - struct snd_seq_real_time time; -}; - -struct snd_seq_queue_skew { - unsigned int value; - unsigned int base; -}; - - /* queue timer control */ -struct snd_seq_ev_queue_control { - unsigned char queue; /* affected queue */ - unsigned char pad[3]; /* reserved */ - union { - signed int value; /* affected value (e.g. tempo) */ - union snd_seq_timestamp time; /* time */ - unsigned int position; /* sync position */ - struct snd_seq_queue_skew skew; - unsigned int d32[2]; - unsigned char d8[8]; - } param; -}; - - /* quoted event - inside the kernel only */ -struct snd_seq_ev_quote { - struct snd_seq_addr origin; /* original sender */ - unsigned short value; /* optional data */ - struct snd_seq_event *event; /* quoted event */ -} __attribute__((packed)); - - - /* sequencer event */ -struct snd_seq_event { - snd_seq_event_type_t type; /* event type */ - unsigned char flags; /* event flags */ - char tag; - - unsigned char queue; /* schedule queue */ - union snd_seq_timestamp time; /* schedule time */ - - - struct snd_seq_addr source; /* source address */ - struct snd_seq_addr dest; /* destination address */ - - union { /* event data... */ - struct snd_seq_ev_note note; - struct snd_seq_ev_ctrl control; - struct snd_seq_ev_raw8 raw8; - struct snd_seq_ev_raw32 raw32; - struct snd_seq_ev_ext ext; - struct snd_seq_ev_queue_control queue; - union snd_seq_timestamp time; - struct snd_seq_addr addr; - struct snd_seq_connect connect; - struct snd_seq_result result; - struct snd_seq_ev_quote quote; - } data; -}; - - -/* - * bounce event - stored as variable size data - */ -struct snd_seq_event_bounce { - int err; - struct snd_seq_event event; - /* external data follows here. */ -}; - - - /* system information */ -struct snd_seq_system_info { - int queues; /* maximum queues count */ - int clients; /* maximum clients count */ - int ports; /* maximum ports per client */ - int channels; /* maximum channels per port */ - int cur_clients; /* current clients */ - int cur_queues; /* current queues */ - char reserved[24]; -}; - - - /* system running information */ -struct snd_seq_running_info { - unsigned char client; /* client id */ - unsigned char big_endian; /* 1 = big-endian */ - unsigned char cpu_mode; /* 4 = 32bit, 8 = 64bit */ - unsigned char pad; /* reserved */ - unsigned char reserved[12]; -}; - - - /* known client numbers */ -#define SNDRV_SEQ_CLIENT_SYSTEM 0 - /* internal client numbers */ -#define SNDRV_SEQ_CLIENT_DUMMY 14 /* midi through */ -#define SNDRV_SEQ_CLIENT_OSS 15 /* oss sequencer emulator */ - - - /* client types */ -typedef int __bitwise snd_seq_client_type_t; -#define NO_CLIENT ((__force snd_seq_client_type_t) 0) -#define USER_CLIENT ((__force snd_seq_client_type_t) 1) -#define KERNEL_CLIENT ((__force snd_seq_client_type_t) 2) - - /* event filter flags */ -#define SNDRV_SEQ_FILTER_BROADCAST (1<<0) /* accept broadcast messages */ -#define SNDRV_SEQ_FILTER_MULTICAST (1<<1) /* accept multicast messages */ -#define SNDRV_SEQ_FILTER_BOUNCE (1<<2) /* accept bounce event in error */ -#define SNDRV_SEQ_FILTER_USE_EVENT (1<<31) /* use event filter */ - -struct snd_seq_client_info { - int client; /* client number to inquire */ - snd_seq_client_type_t type; /* client type */ - char name[64]; /* client name */ - unsigned int filter; /* filter flags */ - unsigned char multicast_filter[8]; /* multicast filter bitmap */ - unsigned char event_filter[32]; /* event filter bitmap */ - int num_ports; /* RO: number of ports */ - int event_lost; /* number of lost events */ - int card; /* RO: card number[kernel] */ - int pid; /* RO: pid[user] */ - char reserved[56]; /* for future use */ -}; - - -/* client pool size */ -struct snd_seq_client_pool { - int client; /* client number to inquire */ - int output_pool; /* outgoing (write) pool size */ - int input_pool; /* incoming (read) pool size */ - int output_room; /* minimum free pool size for select/blocking mode */ - int output_free; /* unused size */ - int input_free; /* unused size */ - char reserved[64]; -}; - - -/* Remove events by specified criteria */ - -#define SNDRV_SEQ_REMOVE_INPUT (1<<0) /* Flush input queues */ -#define SNDRV_SEQ_REMOVE_OUTPUT (1<<1) /* Flush output queues */ -#define SNDRV_SEQ_REMOVE_DEST (1<<2) /* Restrict by destination q:client:port */ -#define SNDRV_SEQ_REMOVE_DEST_CHANNEL (1<<3) /* Restrict by channel */ -#define SNDRV_SEQ_REMOVE_TIME_BEFORE (1<<4) /* Restrict to before time */ -#define SNDRV_SEQ_REMOVE_TIME_AFTER (1<<5) /* Restrict to time or after */ -#define SNDRV_SEQ_REMOVE_TIME_TICK (1<<6) /* Time is in ticks */ -#define SNDRV_SEQ_REMOVE_EVENT_TYPE (1<<7) /* Restrict to event type */ -#define SNDRV_SEQ_REMOVE_IGNORE_OFF (1<<8) /* Do not flush off events */ -#define SNDRV_SEQ_REMOVE_TAG_MATCH (1<<9) /* Restrict to events with given tag */ - -struct snd_seq_remove_events { - unsigned int remove_mode; /* Flags that determine what gets removed */ - - union snd_seq_timestamp time; - - unsigned char queue; /* Queue for REMOVE_DEST */ - struct snd_seq_addr dest; /* Address for REMOVE_DEST */ - unsigned char channel; /* Channel for REMOVE_DEST */ - - int type; /* For REMOVE_EVENT_TYPE */ - char tag; /* Tag for REMOVE_TAG */ - - int reserved[10]; /* To allow for future binary compatibility */ - -}; - - - /* known port numbers */ -#define SNDRV_SEQ_PORT_SYSTEM_TIMER 0 -#define SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE 1 - - /* port capabilities (32 bits) */ -#define SNDRV_SEQ_PORT_CAP_READ (1<<0) /* readable from this port */ -#define SNDRV_SEQ_PORT_CAP_WRITE (1<<1) /* writable to this port */ - -#define SNDRV_SEQ_PORT_CAP_SYNC_READ (1<<2) -#define SNDRV_SEQ_PORT_CAP_SYNC_WRITE (1<<3) - -#define SNDRV_SEQ_PORT_CAP_DUPLEX (1<<4) - -#define SNDRV_SEQ_PORT_CAP_SUBS_READ (1<<5) /* allow read subscription */ -#define SNDRV_SEQ_PORT_CAP_SUBS_WRITE (1<<6) /* allow write subscription */ -#define SNDRV_SEQ_PORT_CAP_NO_EXPORT (1<<7) /* routing not allowed */ - - /* port type */ -#define SNDRV_SEQ_PORT_TYPE_SPECIFIC (1<<0) /* hardware specific */ -#define SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC (1<<1) /* generic MIDI device */ -#define SNDRV_SEQ_PORT_TYPE_MIDI_GM (1<<2) /* General MIDI compatible device */ -#define SNDRV_SEQ_PORT_TYPE_MIDI_GS (1<<3) /* GS compatible device */ -#define SNDRV_SEQ_PORT_TYPE_MIDI_XG (1<<4) /* XG compatible device */ -#define SNDRV_SEQ_PORT_TYPE_MIDI_MT32 (1<<5) /* MT-32 compatible device */ -#define SNDRV_SEQ_PORT_TYPE_MIDI_GM2 (1<<6) /* General MIDI 2 compatible device */ - -/* other standards...*/ -#define SNDRV_SEQ_PORT_TYPE_SYNTH (1<<10) /* Synth device (no MIDI compatible - direct wavetable) */ -#define SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE (1<<11) /* Sampling device (support sample download) */ -#define SNDRV_SEQ_PORT_TYPE_SAMPLE (1<<12) /* Sampling device (sample can be downloaded at any time) */ -/*...*/ -#define SNDRV_SEQ_PORT_TYPE_HARDWARE (1<<16) /* driver for a hardware device */ -#define SNDRV_SEQ_PORT_TYPE_SOFTWARE (1<<17) /* implemented in software */ -#define SNDRV_SEQ_PORT_TYPE_SYNTHESIZER (1<<18) /* generates sound */ -#define SNDRV_SEQ_PORT_TYPE_PORT (1<<19) /* connects to other device(s) */ -#define SNDRV_SEQ_PORT_TYPE_APPLICATION (1<<20) /* application (sequencer/editor) */ - -/* misc. conditioning flags */ -#define SNDRV_SEQ_PORT_FLG_GIVEN_PORT (1<<0) -#define SNDRV_SEQ_PORT_FLG_TIMESTAMP (1<<1) -#define SNDRV_SEQ_PORT_FLG_TIME_REAL (1<<2) - -struct snd_seq_port_info { - struct snd_seq_addr addr; /* client/port numbers */ - char name[64]; /* port name */ - - unsigned int capability; /* port capability bits */ - unsigned int type; /* port type bits */ - int midi_channels; /* channels per MIDI port */ - int midi_voices; /* voices per MIDI port */ - int synth_voices; /* voices per SYNTH port */ - - int read_use; /* R/O: subscribers for output (from this port) */ - int write_use; /* R/O: subscribers for input (to this port) */ - - void *kernel; /* reserved for kernel use (must be NULL) */ - unsigned int flags; /* misc. conditioning */ - unsigned char time_queue; /* queue # for timestamping */ - char reserved[59]; /* for future use */ -}; - - -/* queue flags */ -#define SNDRV_SEQ_QUEUE_FLG_SYNC (1<<0) /* sync enabled */ - -/* queue information */ -struct snd_seq_queue_info { - int queue; /* queue id */ - - /* - * security settings, only owner of this queue can start/stop timer - * etc. if the queue is locked for other clients - */ - int owner; /* client id for owner of the queue */ - unsigned locked:1; /* timing queue locked for other queues */ - char name[64]; /* name of this queue */ - unsigned int flags; /* flags */ - char reserved[60]; /* for future use */ - -}; - -/* queue info/status */ -struct snd_seq_queue_status { - int queue; /* queue id */ - int events; /* read-only - queue size */ - snd_seq_tick_time_t tick; /* current tick */ - struct snd_seq_real_time time; /* current time */ - int running; /* running state of queue */ - int flags; /* various flags */ - char reserved[64]; /* for the future */ -}; - - -/* queue tempo */ -struct snd_seq_queue_tempo { - int queue; /* sequencer queue */ - unsigned int tempo; /* current tempo, us/tick */ - int ppq; /* time resolution, ticks/quarter */ - unsigned int skew_value; /* queue skew */ - unsigned int skew_base; /* queue skew base */ - char reserved[24]; /* for the future */ -}; - - -/* sequencer timer sources */ -#define SNDRV_SEQ_TIMER_ALSA 0 /* ALSA timer */ -#define SNDRV_SEQ_TIMER_MIDI_CLOCK 1 /* Midi Clock (CLOCK event) */ -#define SNDRV_SEQ_TIMER_MIDI_TICK 2 /* Midi Timer Tick (TICK event) */ - -/* queue timer info */ -struct snd_seq_queue_timer { - int queue; /* sequencer queue */ - int type; /* source timer type */ - union { - struct { - struct snd_timer_id id; /* ALSA's timer ID */ - unsigned int resolution; /* resolution in Hz */ - } alsa; - } u; - char reserved[64]; /* for the future use */ -}; - - -struct snd_seq_queue_client { - int queue; /* sequencer queue */ - int client; /* sequencer client */ - int used; /* queue is used with this client - (must be set for accepting events) */ - /* per client watermarks */ - char reserved[64]; /* for future use */ -}; - - -#define SNDRV_SEQ_PORT_SUBS_EXCLUSIVE (1<<0) /* exclusive connection */ -#define SNDRV_SEQ_PORT_SUBS_TIMESTAMP (1<<1) -#define SNDRV_SEQ_PORT_SUBS_TIME_REAL (1<<2) - -struct snd_seq_port_subscribe { - struct snd_seq_addr sender; /* sender address */ - struct snd_seq_addr dest; /* destination address */ - unsigned int voices; /* number of voices to be allocated (0 = don't care) */ - unsigned int flags; /* modes */ - unsigned char queue; /* input time-stamp queue (optional) */ - unsigned char pad[3]; /* reserved */ - char reserved[64]; -}; - -/* type of query subscription */ -#define SNDRV_SEQ_QUERY_SUBS_READ 0 -#define SNDRV_SEQ_QUERY_SUBS_WRITE 1 - -struct snd_seq_query_subs { - struct snd_seq_addr root; /* client/port id to be searched */ - int type; /* READ or WRITE */ - int index; /* 0..N-1 */ - int num_subs; /* R/O: number of subscriptions on this port */ - struct snd_seq_addr addr; /* R/O: result */ - unsigned char queue; /* R/O: result */ - unsigned int flags; /* R/O: result */ - char reserved[64]; /* for future use */ -}; - - -/* - * IOCTL commands - */ - -#define SNDRV_SEQ_IOCTL_PVERSION _IOR ('S', 0x00, int) -#define SNDRV_SEQ_IOCTL_CLIENT_ID _IOR ('S', 0x01, int) -#define SNDRV_SEQ_IOCTL_SYSTEM_INFO _IOWR('S', 0x02, struct snd_seq_system_info) -#define SNDRV_SEQ_IOCTL_RUNNING_MODE _IOWR('S', 0x03, struct snd_seq_running_info) - -#define SNDRV_SEQ_IOCTL_GET_CLIENT_INFO _IOWR('S', 0x10, struct snd_seq_client_info) -#define SNDRV_SEQ_IOCTL_SET_CLIENT_INFO _IOW ('S', 0x11, struct snd_seq_client_info) - -#define SNDRV_SEQ_IOCTL_CREATE_PORT _IOWR('S', 0x20, struct snd_seq_port_info) -#define SNDRV_SEQ_IOCTL_DELETE_PORT _IOW ('S', 0x21, struct snd_seq_port_info) -#define SNDRV_SEQ_IOCTL_GET_PORT_INFO _IOWR('S', 0x22, struct snd_seq_port_info) -#define SNDRV_SEQ_IOCTL_SET_PORT_INFO _IOW ('S', 0x23, struct snd_seq_port_info) - -#define SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT _IOW ('S', 0x30, struct snd_seq_port_subscribe) -#define SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT _IOW ('S', 0x31, struct snd_seq_port_subscribe) - -#define SNDRV_SEQ_IOCTL_CREATE_QUEUE _IOWR('S', 0x32, struct snd_seq_queue_info) -#define SNDRV_SEQ_IOCTL_DELETE_QUEUE _IOW ('S', 0x33, struct snd_seq_queue_info) -#define SNDRV_SEQ_IOCTL_GET_QUEUE_INFO _IOWR('S', 0x34, struct snd_seq_queue_info) -#define SNDRV_SEQ_IOCTL_SET_QUEUE_INFO _IOWR('S', 0x35, struct snd_seq_queue_info) -#define SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE _IOWR('S', 0x36, struct snd_seq_queue_info) -#define SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS _IOWR('S', 0x40, struct snd_seq_queue_status) -#define SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO _IOWR('S', 0x41, struct snd_seq_queue_tempo) -#define SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO _IOW ('S', 0x42, struct snd_seq_queue_tempo) -#define SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER _IOWR('S', 0x45, struct snd_seq_queue_timer) -#define SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER _IOW ('S', 0x46, struct snd_seq_queue_timer) -#define SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT _IOWR('S', 0x49, struct snd_seq_queue_client) -#define SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT _IOW ('S', 0x4a, struct snd_seq_queue_client) -#define SNDRV_SEQ_IOCTL_GET_CLIENT_POOL _IOWR('S', 0x4b, struct snd_seq_client_pool) -#define SNDRV_SEQ_IOCTL_SET_CLIENT_POOL _IOW ('S', 0x4c, struct snd_seq_client_pool) -#define SNDRV_SEQ_IOCTL_REMOVE_EVENTS _IOW ('S', 0x4e, struct snd_seq_remove_events) -#define SNDRV_SEQ_IOCTL_QUERY_SUBS _IOWR('S', 0x4f, struct snd_seq_query_subs) -#define SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION _IOWR('S', 0x50, struct snd_seq_port_subscribe) -#define SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT _IOWR('S', 0x51, struct snd_seq_client_info) -#define SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT _IOWR('S', 0x52, struct snd_seq_port_info) - -#endif /* _UAPI__SOUND_ASEQUENCER_H */ +#include diff --git a/include/sound/asoc.h b/include/sound/asoc.h index a74ca23..185bba8 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -1,633 +1 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -/* - * uapi/sound/asoc.h -- ALSA SoC Firmware Controls and DAPM - * - * Copyright (C) 2012 Texas Instruments Inc. - * Copyright (C) 2015 Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Simple file API to load FW that includes mixers, coefficients, DAPM graphs, - * algorithms, equalisers, DAIs, widgets etc. -*/ - -#ifndef __LINUX_UAPI_SND_ASOC_H -#define __LINUX_UAPI_SND_ASOC_H - -#include -#include - -/* - * Maximum number of channels topology kcontrol can represent. - */ -#define SND_SOC_TPLG_MAX_CHAN 8 - -/* - * Maximum number of PCM formats capability - */ -#define SND_SOC_TPLG_MAX_FORMATS 16 - -/* - * Maximum number of PCM stream configs - */ -#define SND_SOC_TPLG_STREAM_CONFIG_MAX 8 - -/* - * Maximum number of physical link's hardware configs - */ -#define SND_SOC_TPLG_HW_CONFIG_MAX 8 - -/* individual kcontrol info types - can be mixed with other types */ -#define SND_SOC_TPLG_CTL_VOLSW 1 -#define SND_SOC_TPLG_CTL_VOLSW_SX 2 -#define SND_SOC_TPLG_CTL_VOLSW_XR_SX 3 -#define SND_SOC_TPLG_CTL_ENUM 4 -#define SND_SOC_TPLG_CTL_BYTES 5 -#define SND_SOC_TPLG_CTL_ENUM_VALUE 6 -#define SND_SOC_TPLG_CTL_RANGE 7 -#define SND_SOC_TPLG_CTL_STROBE 8 - - -/* individual widget kcontrol info types - can be mixed with other types */ -#define SND_SOC_TPLG_DAPM_CTL_VOLSW 64 -#define SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE 65 -#define SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT 66 -#define SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE 67 -#define SND_SOC_TPLG_DAPM_CTL_PIN 68 - -/* DAPM widget types - add new items to the end */ -#define SND_SOC_TPLG_DAPM_INPUT 0 -#define SND_SOC_TPLG_DAPM_OUTPUT 1 -#define SND_SOC_TPLG_DAPM_MUX 2 -#define SND_SOC_TPLG_DAPM_MIXER 3 -#define SND_SOC_TPLG_DAPM_PGA 4 -#define SND_SOC_TPLG_DAPM_OUT_DRV 5 -#define SND_SOC_TPLG_DAPM_ADC 6 -#define SND_SOC_TPLG_DAPM_DAC 7 -#define SND_SOC_TPLG_DAPM_SWITCH 8 -#define SND_SOC_TPLG_DAPM_PRE 9 -#define SND_SOC_TPLG_DAPM_POST 10 -#define SND_SOC_TPLG_DAPM_AIF_IN 11 -#define SND_SOC_TPLG_DAPM_AIF_OUT 12 -#define SND_SOC_TPLG_DAPM_DAI_IN 13 -#define SND_SOC_TPLG_DAPM_DAI_OUT 14 -#define SND_SOC_TPLG_DAPM_DAI_LINK 15 -#define SND_SOC_TPLG_DAPM_BUFFER 16 -#define SND_SOC_TPLG_DAPM_SCHEDULER 17 -#define SND_SOC_TPLG_DAPM_EFFECT 18 -#define SND_SOC_TPLG_DAPM_SIGGEN 19 -#define SND_SOC_TPLG_DAPM_SRC 20 -#define SND_SOC_TPLG_DAPM_ASRC 21 -#define SND_SOC_TPLG_DAPM_ENCODER 22 -#define SND_SOC_TPLG_DAPM_DECODER 23 -#define SND_SOC_TPLG_DAPM_LAST SND_SOC_TPLG_DAPM_DECODER - -/* Header magic number and string sizes */ -#define SND_SOC_TPLG_MAGIC 0x41536F43 /* ASoC */ - -/* string sizes */ -#define SND_SOC_TPLG_NUM_TEXTS 16 - -/* ABI version */ -#define SND_SOC_TPLG_ABI_VERSION 0x5 /* current version */ -#define SND_SOC_TPLG_ABI_VERSION_MIN 0x4 /* oldest version supported */ - -/* Max size of TLV data */ -#define SND_SOC_TPLG_TLV_SIZE 32 - -/* - * File and Block header data types. - * Add new generic and vendor types to end of list. - * Generic types are handled by the core whilst vendors types are passed - * to the component drivers for handling. - */ -#define SND_SOC_TPLG_TYPE_MIXER 1 -#define SND_SOC_TPLG_TYPE_BYTES 2 -#define SND_SOC_TPLG_TYPE_ENUM 3 -#define SND_SOC_TPLG_TYPE_DAPM_GRAPH 4 -#define SND_SOC_TPLG_TYPE_DAPM_WIDGET 5 -#define SND_SOC_TPLG_TYPE_DAI_LINK 6 -#define SND_SOC_TPLG_TYPE_PCM 7 -#define SND_SOC_TPLG_TYPE_MANIFEST 8 -#define SND_SOC_TPLG_TYPE_CODEC_LINK 9 -#define SND_SOC_TPLG_TYPE_BACKEND_LINK 10 -#define SND_SOC_TPLG_TYPE_PDATA 11 -#define SND_SOC_TPLG_TYPE_DAI 12 -#define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_DAI - -/* vendor block IDs - please add new vendor types to end */ -#define SND_SOC_TPLG_TYPE_VENDOR_FW 1000 -#define SND_SOC_TPLG_TYPE_VENDOR_CONFIG 1001 -#define SND_SOC_TPLG_TYPE_VENDOR_COEFF 1002 -#define SND_SOC_TPLG_TYPEVENDOR_CODEC 1003 - -#define SND_SOC_TPLG_STREAM_PLAYBACK 0 -#define SND_SOC_TPLG_STREAM_CAPTURE 1 - -/* vendor tuple types */ -#define SND_SOC_TPLG_TUPLE_TYPE_UUID 0 -#define SND_SOC_TPLG_TUPLE_TYPE_STRING 1 -#define SND_SOC_TPLG_TUPLE_TYPE_BOOL 2 -#define SND_SOC_TPLG_TUPLE_TYPE_BYTE 3 -#define SND_SOC_TPLG_TUPLE_TYPE_WORD 4 -#define SND_SOC_TPLG_TUPLE_TYPE_SHORT 5 - -/* DAI flags */ -#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES (1 << 0) -#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) -#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2) - -/* DAI clock gating */ -#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED 0 -#define SND_SOC_TPLG_DAI_CLK_GATE_GATED 1 -#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 - -/* DAI mclk_direction */ -#define SND_SOC_TPLG_MCLK_CO 0 /* for codec, mclk is output */ -#define SND_SOC_TPLG_MCLK_CI 1 /* for codec, mclk is input */ - -/* DAI physical PCM data formats. - * Add new formats to the end of the list. - */ -#define SND_SOC_DAI_FORMAT_I2S 1 /* I2S mode */ -#define SND_SOC_DAI_FORMAT_RIGHT_J 2 /* Right Justified mode */ -#define SND_SOC_DAI_FORMAT_LEFT_J 3 /* Left Justified mode */ -#define SND_SOC_DAI_FORMAT_DSP_A 4 /* L data MSB after FRM LRC */ -#define SND_SOC_DAI_FORMAT_DSP_B 5 /* L data MSB during FRM LRC */ -#define SND_SOC_DAI_FORMAT_AC97 6 /* AC97 */ -#define SND_SOC_DAI_FORMAT_PDM 7 /* Pulse density modulation */ - -/* left and right justified also known as MSB and LSB respectively */ -#define SND_SOC_DAI_FORMAT_MSB SND_SOC_DAI_FORMAT_LEFT_J -#define SND_SOC_DAI_FORMAT_LSB SND_SOC_DAI_FORMAT_RIGHT_J - -/* DAI link flags */ -#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES (1 << 0) -#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) -#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2) -#define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP (1 << 3) - -/* DAI topology BCLK parameter - * For the backwards capability, by default codec is bclk master - */ -#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ -#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ - -/* DAI topology FSYNC parameter - * For the backwards capability, by default codec is fsync master - */ -#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ -#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ - -/* - * Block Header. - * This header precedes all object and object arrays below. - */ -struct snd_soc_tplg_hdr { - __le32 magic; /* magic number */ - __le32 abi; /* ABI version */ - __le32 version; /* optional vendor specific version details */ - __le32 type; /* SND_SOC_TPLG_TYPE_ */ - __le32 size; /* size of this structure */ - __le32 vendor_type; /* optional vendor specific type info */ - __le32 payload_size; /* data bytes, excluding this header */ - __le32 index; /* identifier for block */ - __le32 count; /* number of elements in block */ -} __attribute__((packed)); - -/* vendor tuple for uuid */ -struct snd_soc_tplg_vendor_uuid_elem { - __le32 token; - char uuid[16]; -} __attribute__((packed)); - -/* vendor tuple for a bool/byte/short/word value */ -struct snd_soc_tplg_vendor_value_elem { - __le32 token; - __le32 value; -} __attribute__((packed)); - -/* vendor tuple for string */ -struct snd_soc_tplg_vendor_string_elem { - __le32 token; - char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; -} __attribute__((packed)); - -struct snd_soc_tplg_vendor_array { - __le32 size; /* size in bytes of the array, including all elements */ - __le32 type; /* SND_SOC_TPLG_TUPLE_TYPE_ */ - __le32 num_elems; /* number of elements in array */ - union { - struct snd_soc_tplg_vendor_uuid_elem uuid[0]; - struct snd_soc_tplg_vendor_value_elem value[0]; - struct snd_soc_tplg_vendor_string_elem string[0]; - }; -} __attribute__((packed)); - -/* - * Private data. - * All topology objects may have private data that can be used by the driver or - * firmware. Core will ignore this data. - */ -struct snd_soc_tplg_private { - __le32 size; /* in bytes of private data */ - union { - char data[0]; - struct snd_soc_tplg_vendor_array array[0]; - }; -} __attribute__((packed)); - -/* - * Kcontrol TLV data. - */ -struct snd_soc_tplg_tlv_dbscale { - __le32 min; - __le32 step; - __le32 mute; -} __attribute__((packed)); - -struct snd_soc_tplg_ctl_tlv { - __le32 size; /* in bytes of this structure */ - __le32 type; /* SNDRV_CTL_TLVT_*, type of TLV */ - union { - __le32 data[SND_SOC_TPLG_TLV_SIZE]; - struct snd_soc_tplg_tlv_dbscale scale; - }; -} __attribute__((packed)); - -/* - * Kcontrol channel data - */ -struct snd_soc_tplg_channel { - __le32 size; /* in bytes of this structure */ - __le32 reg; - __le32 shift; - __le32 id; /* ID maps to Left, Right, LFE etc */ -} __attribute__((packed)); - -/* - * Genericl Operations IDs, for binding Kcontrol or Bytes ext ops - * Kcontrol ops need get/put/info. - * Bytes ext ops need get/put. - */ -struct snd_soc_tplg_io_ops { - __le32 get; - __le32 put; - __le32 info; -} __attribute__((packed)); - -/* - * kcontrol header - */ -struct snd_soc_tplg_ctl_hdr { - __le32 size; /* in bytes of this structure */ - __le32 type; - char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - __le32 access; - struct snd_soc_tplg_io_ops ops; - struct snd_soc_tplg_ctl_tlv tlv; -} __attribute__((packed)); - -/* - * Stream Capabilities - */ -struct snd_soc_tplg_stream_caps { - __le32 size; /* in bytes of this structure */ - char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - __le64 formats; /* supported formats SNDRV_PCM_FMTBIT_* */ - __le32 rates; /* supported rates SNDRV_PCM_RATE_* */ - __le32 rate_min; /* min rate */ - __le32 rate_max; /* max rate */ - __le32 channels_min; /* min channels */ - __le32 channels_max; /* max channels */ - __le32 periods_min; /* min number of periods */ - __le32 periods_max; /* max number of periods */ - __le32 period_size_min; /* min period size bytes */ - __le32 period_size_max; /* max period size bytes */ - __le32 buffer_size_min; /* min buffer size bytes */ - __le32 buffer_size_max; /* max buffer size bytes */ - __le32 sig_bits; /* number of bits of content */ -} __attribute__((packed)); - -/* - * FE or BE Stream configuration supported by SW/FW - */ -struct snd_soc_tplg_stream { - __le32 size; /* in bytes of this structure */ - char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* Name of the stream */ - __le64 format; /* SNDRV_PCM_FMTBIT_* */ - __le32 rate; /* SNDRV_PCM_RATE_* */ - __le32 period_bytes; /* size of period in bytes */ - __le32 buffer_bytes; /* size of buffer in bytes */ - __le32 channels; /* channels */ -} __attribute__((packed)); - - -/* - * Describes a physical link's runtime supported hardware config, - * i.e. hardware audio formats. - */ -struct snd_soc_tplg_hw_config { - __le32 size; /* in bytes of this structure */ - __le32 id; /* unique ID - - used to match */ - __le32 fmt; /* SND_SOC_DAI_FORMAT_ format value */ - __u8 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ - __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ - __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ - __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ - __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ - __u8 mclk_direction; /* SND_SOC_TPLG_MCLK_ value */ - __le16 reserved; /* for 32bit alignment */ - __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ - __le32 bclk_rate; /* BCLK freqency in Hz */ - __le32 fsync_rate; /* frame clock in Hz */ - __le32 tdm_slots; /* number of TDM slots in use */ - __le32 tdm_slot_width; /* width in bits for each slot */ - __le32 tx_slots; /* bit mask for active Tx slots */ - __le32 rx_slots; /* bit mask for active Rx slots */ - __le32 tx_channels; /* number of Tx channels */ - __le32 tx_chanmap[SND_SOC_TPLG_MAX_CHAN]; /* array of slot number */ - __le32 rx_channels; /* number of Rx channels */ - __le32 rx_chanmap[SND_SOC_TPLG_MAX_CHAN]; /* array of slot number */ -} __attribute__((packed)); - -/* - * Manifest. List totals for each payload type. Not used in parsing, but will - * be passed to the component driver before any other objects in order for any - * global component resource allocations. - * - * File block representation for manifest :- - * +-----------------------------------+----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+----+ - * | struct snd_soc_tplg_manifest | 1 | - * +-----------------------------------+----+ - */ -struct snd_soc_tplg_manifest { - __le32 size; /* in bytes of this structure */ - __le32 control_elems; /* number of control elements */ - __le32 widget_elems; /* number of widget elements */ - __le32 graph_elems; /* number of graph elements */ - __le32 pcm_elems; /* number of PCM elements */ - __le32 dai_link_elems; /* number of DAI link elements */ - __le32 dai_elems; /* number of physical DAI elements */ - __le32 reserved[20]; /* reserved for new ABI element types */ - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - -/* - * Mixer kcontrol. - * - * File block representation for mixer kcontrol :- - * +-----------------------------------+----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+----+ - * | struct snd_soc_tplg_mixer_control | N | - * +-----------------------------------+----+ - */ -struct snd_soc_tplg_mixer_control { - struct snd_soc_tplg_ctl_hdr hdr; - __le32 size; /* in bytes of this structure */ - __le32 min; - __le32 max; - __le32 platform_max; - __le32 invert; - __le32 num_channels; - struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - -/* - * Enumerated kcontrol - * - * File block representation for enum kcontrol :- - * +-----------------------------------+----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+----+ - * | struct snd_soc_tplg_enum_control | N | - * +-----------------------------------+----+ - */ -struct snd_soc_tplg_enum_control { - struct snd_soc_tplg_ctl_hdr hdr; - __le32 size; /* in bytes of this structure */ - __le32 num_channels; - struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; - __le32 items; - __le32 mask; - __le32 count; - char texts[SND_SOC_TPLG_NUM_TEXTS][SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - __le32 values[SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN / 4]; - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - -/* - * Bytes kcontrol - * - * File block representation for bytes kcontrol :- - * +-----------------------------------+----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+----+ - * | struct snd_soc_tplg_bytes_control | N | - * +-----------------------------------+----+ - */ -struct snd_soc_tplg_bytes_control { - struct snd_soc_tplg_ctl_hdr hdr; - __le32 size; /* in bytes of this structure */ - __le32 max; - __le32 mask; - __le32 base; - __le32 num_regs; - struct snd_soc_tplg_io_ops ext_ops; - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - -/* - * DAPM Graph Element - * - * File block representation for DAPM graph elements :- - * +-------------------------------------+----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-------------------------------------+----+ - * | struct snd_soc_tplg_dapm_graph_elem | N | - * +-------------------------------------+----+ - */ -struct snd_soc_tplg_dapm_graph_elem { - char sink[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - char control[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - char source[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; -} __attribute__((packed)); - -/* - * DAPM Widget. - * - * File block representation for DAPM widget :- - * +-------------------------------------+-----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-------------------------------------+-----+ - * | struct snd_soc_tplg_dapm_widget | N | - * +-------------------------------------+-----+ - * | struct snd_soc_tplg_enum_control | 0|1 | - * | struct snd_soc_tplg_mixer_control | 0|N | - * +-------------------------------------+-----+ - * - * Optional enum or mixer control can be appended to the end of each widget - * in the block. - */ -struct snd_soc_tplg_dapm_widget { - __le32 size; /* in bytes of this structure */ - __le32 id; /* SND_SOC_DAPM_CTL */ - char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - - __le32 reg; /* negative reg = no direct dapm */ - __le32 shift; /* bits to shift */ - __le32 mask; /* non-shifted mask */ - __le32 subseq; /* sort within widget type */ - __le32 invert; /* invert the power bit */ - __le32 ignore_suspend; /* kept enabled over suspend */ - __le16 event_flags; - __le16 event_type; - __le32 num_kcontrols; - struct snd_soc_tplg_private priv; - /* - * kcontrols that relate to this widget - * follow here after widget private data - */ -} __attribute__((packed)); - - -/* - * Describes SW/FW specific features of PCM (FE DAI & DAI link). - * - * File block representation for PCM :- - * +-----------------------------------+-----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+-----+ - * | struct snd_soc_tplg_pcm | N | - * +-----------------------------------+-----+ - */ -struct snd_soc_tplg_pcm { - __le32 size; /* in bytes of this structure */ - char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - __le32 pcm_id; /* unique ID - used to match with DAI link */ - __le32 dai_id; /* unique ID - used to match */ - __le32 playback; /* supports playback mode */ - __le32 capture; /* supports capture mode */ - __le32 compress; /* 1 = compressed; 0 = PCM */ - struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */ - __le32 num_streams; /* number of streams */ - struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */ - __le32 flag_mask; /* bitmask of flags to configure */ - __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - - -/* - * Describes the physical link runtime supported configs or params - * - * File block representation for physical link config :- - * +-----------------------------------+-----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+-----+ - * | struct snd_soc_tplg_link_config | N | - * +-----------------------------------+-----+ - */ -struct snd_soc_tplg_link_config { - __le32 size; /* in bytes of this structure */ - __le32 id; /* unique ID - used to match */ - char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */ - char stream_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* stream name - used to match */ - struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ - __le32 num_streams; /* number of streams */ - struct snd_soc_tplg_hw_config hw_config[SND_SOC_TPLG_HW_CONFIG_MAX]; /* hw configs */ - __le32 num_hw_configs; /* number of hw configs */ - __le32 default_hw_config_id; /* default hw config ID for init */ - __le32 flag_mask; /* bitmask of flags to configure */ - __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - -/* - * Describes SW/FW specific features of physical DAI. - * It can be used to configure backend DAIs for DPCM. - * - * File block representation for physical DAI :- - * +-----------------------------------+-----+ - * | struct snd_soc_tplg_hdr | 1 | - * +-----------------------------------+-----+ - * | struct snd_soc_tplg_dai | N | - * +-----------------------------------+-----+ - */ -struct snd_soc_tplg_dai { - __le32 size; /* in bytes of this structure */ - char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */ - __le32 dai_id; /* unique ID - used to match */ - __le32 playback; /* supports playback mode */ - __le32 capture; /* supports capture mode */ - struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */ - __le32 flag_mask; /* bitmask of flags to configure */ - __le32 flags; /* SND_SOC_TPLG_DAI_FLGBIT_* */ - struct snd_soc_tplg_private priv; -} __attribute__((packed)); - -/* - * Old version of ABI structs, supported for backward compatibility. - */ - -/* Manifest v4 */ -struct snd_soc_tplg_manifest_v4 { - __le32 size; /* in bytes of this structure */ - __le32 control_elems; /* number of control elements */ - __le32 widget_elems; /* number of widget elements */ - __le32 graph_elems; /* number of graph elements */ - __le32 pcm_elems; /* number of PCM elements */ - __le32 dai_link_elems; /* number of DAI link elements */ - struct snd_soc_tplg_private priv; -} __packed; - -/* Stream Capabilities v4 */ -struct snd_soc_tplg_stream_caps_v4 { - __le32 size; /* in bytes of this structure */ - char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - __le64 formats; /* supported formats SNDRV_PCM_FMTBIT_* */ - __le32 rates; /* supported rates SNDRV_PCM_RATE_* */ - __le32 rate_min; /* min rate */ - __le32 rate_max; /* max rate */ - __le32 channels_min; /* min channels */ - __le32 channels_max; /* max channels */ - __le32 periods_min; /* min number of periods */ - __le32 periods_max; /* max number of periods */ - __le32 period_size_min; /* min period size bytes */ - __le32 period_size_max; /* max period size bytes */ - __le32 buffer_size_min; /* min buffer size bytes */ - __le32 buffer_size_max; /* max buffer size bytes */ -} __packed; - -/* PCM v4 */ -struct snd_soc_tplg_pcm_v4 { - __le32 size; /* in bytes of this structure */ - char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - __le32 pcm_id; /* unique ID - used to match with DAI link */ - __le32 dai_id; /* unique ID - used to match */ - __le32 playback; /* supports playback mode */ - __le32 capture; /* supports capture mode */ - __le32 compress; /* 1 = compressed; 0 = PCM */ - struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */ - __le32 num_streams; /* number of streams */ - struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */ -} __packed; - -/* Physical link config v4 */ -struct snd_soc_tplg_link_config_v4 { - __le32 size; /* in bytes of this structure */ - __le32 id; /* unique ID - used to match */ - struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ - __le32 num_streams; /* number of streams */ -} __packed; - -#endif +#include diff --git a/include/sound/asound.h b/include/sound/asound.h index df1153c..89dd7d2 100644 --- a/include/sound/asound.h +++ b/include/sound/asound.h @@ -1,1038 +1,11 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* - * Advanced Linux Sound Architecture - ALSA - Driver - * Copyright (c) 1994-2003 by Jaroslav Kysela , - * Abramo Bagnara - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef _UAPI__SOUND_ASOUND_H -#define _UAPI__SOUND_ASOUND_H - -#if defined(__KERNEL__) || defined(__linux__) +/* workaround for building with old glibc / kernel headers */ +#ifdef __linux__ #include #else -#include -#endif - -#ifndef __KERNEL__ -#include -#include -#endif - -/* - * protocol version - */ - -#define SNDRV_PROTOCOL_VERSION(major, minor, subminor) (((major)<<16)|((minor)<<8)|(subminor)) -#define SNDRV_PROTOCOL_MAJOR(version) (((version)>>16)&0xffff) -#define SNDRV_PROTOCOL_MINOR(version) (((version)>>8)&0xff) -#define SNDRV_PROTOCOL_MICRO(version) ((version)&0xff) -#define SNDRV_PROTOCOL_INCOMPATIBLE(kversion, uversion) \ - (SNDRV_PROTOCOL_MAJOR(kversion) != SNDRV_PROTOCOL_MAJOR(uversion) || \ - (SNDRV_PROTOCOL_MAJOR(kversion) == SNDRV_PROTOCOL_MAJOR(uversion) && \ - SNDRV_PROTOCOL_MINOR(kversion) != SNDRV_PROTOCOL_MINOR(uversion))) - -/**************************************************************************** - * * - * Digital audio interface * - * * - ****************************************************************************/ - -struct snd_aes_iec958 { - unsigned char status[24]; /* AES/IEC958 channel status bits */ - unsigned char subcode[147]; /* AES/IEC958 subcode bits */ - unsigned char pad; /* nothing */ - unsigned char dig_subframe[4]; /* AES/IEC958 subframe bits */ -}; - -/**************************************************************************** - * * - * CEA-861 Audio InfoFrame. Used in HDMI and DisplayPort * - * * - ****************************************************************************/ - -struct snd_cea_861_aud_if { - unsigned char db1_ct_cc; /* coding type and channel count */ - unsigned char db2_sf_ss; /* sample frequency and size */ - unsigned char db3; /* not used, all zeros */ - unsigned char db4_ca; /* channel allocation code */ - unsigned char db5_dminh_lsv; /* downmix inhibit & level-shit values */ -}; - -/**************************************************************************** - * * - * Section for driver hardware dependent interface - /dev/snd/hw? * - * * - ****************************************************************************/ - -#define SNDRV_HWDEP_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 1) - -enum { - SNDRV_HWDEP_IFACE_OPL2 = 0, - SNDRV_HWDEP_IFACE_OPL3, - SNDRV_HWDEP_IFACE_OPL4, - SNDRV_HWDEP_IFACE_SB16CSP, /* Creative Signal Processor */ - SNDRV_HWDEP_IFACE_EMU10K1, /* FX8010 processor in EMU10K1 chip */ - SNDRV_HWDEP_IFACE_YSS225, /* Yamaha FX processor */ - SNDRV_HWDEP_IFACE_ICS2115, /* Wavetable synth */ - SNDRV_HWDEP_IFACE_SSCAPE, /* Ensoniq SoundScape ISA card (MC68EC000) */ - SNDRV_HWDEP_IFACE_VX, /* Digigram VX cards */ - SNDRV_HWDEP_IFACE_MIXART, /* Digigram miXart cards */ - SNDRV_HWDEP_IFACE_USX2Y, /* Tascam US122, US224 & US428 usb */ - SNDRV_HWDEP_IFACE_EMUX_WAVETABLE, /* EmuX wavetable */ - SNDRV_HWDEP_IFACE_BLUETOOTH, /* Bluetooth audio */ - SNDRV_HWDEP_IFACE_USX2Y_PCM, /* Tascam US122, US224 & US428 rawusb pcm */ - SNDRV_HWDEP_IFACE_PCXHR, /* Digigram PCXHR */ - SNDRV_HWDEP_IFACE_SB_RC, /* SB Extigy/Audigy2NX remote control */ - SNDRV_HWDEP_IFACE_HDA, /* HD-audio */ - SNDRV_HWDEP_IFACE_USB_STREAM, /* direct access to usb stream */ - SNDRV_HWDEP_IFACE_FW_DICE, /* TC DICE FireWire device */ - SNDRV_HWDEP_IFACE_FW_FIREWORKS, /* Echo Audio Fireworks based device */ - SNDRV_HWDEP_IFACE_FW_BEBOB, /* BridgeCo BeBoB based device */ - SNDRV_HWDEP_IFACE_FW_OXFW, /* Oxford OXFW970/971 based device */ - SNDRV_HWDEP_IFACE_FW_DIGI00X, /* Digidesign Digi 002/003 family */ - SNDRV_HWDEP_IFACE_FW_TASCAM, /* TASCAM FireWire series */ - SNDRV_HWDEP_IFACE_LINE6, /* Line6 USB processors */ - SNDRV_HWDEP_IFACE_FW_MOTU, /* MOTU FireWire series */ - SNDRV_HWDEP_IFACE_FW_FIREFACE, /* RME Fireface series */ - - /* Don't forget to change the following: */ - SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_FIREFACE -}; - -struct snd_hwdep_info { - unsigned int device; /* WR: device number */ - int card; /* R: card number */ - unsigned char id[64]; /* ID (user selectable) */ - unsigned char name[80]; /* hwdep name */ - int iface; /* hwdep interface */ - unsigned char reserved[64]; /* reserved for future */ -}; - -/* generic DSP loader */ -struct snd_hwdep_dsp_status { - unsigned int version; /* R: driver-specific version */ - unsigned char id[32]; /* R: driver-specific ID string */ - unsigned int num_dsps; /* R: number of DSP images to transfer */ - unsigned int dsp_loaded; /* R: bit flags indicating the loaded DSPs */ - unsigned int chip_ready; /* R: 1 = initialization finished */ - unsigned char reserved[16]; /* reserved for future use */ -}; - -struct snd_hwdep_dsp_image { - unsigned int index; /* W: DSP index */ - unsigned char name[64]; /* W: ID (e.g. file name) */ - unsigned char __user *image; /* W: binary image */ - size_t length; /* W: size of image in bytes */ - unsigned long driver_data; /* W: driver-specific data */ -}; - -#define SNDRV_HWDEP_IOCTL_PVERSION _IOR ('H', 0x00, int) -#define SNDRV_HWDEP_IOCTL_INFO _IOR ('H', 0x01, struct snd_hwdep_info) -#define SNDRV_HWDEP_IOCTL_DSP_STATUS _IOR('H', 0x02, struct snd_hwdep_dsp_status) -#define SNDRV_HWDEP_IOCTL_DSP_LOAD _IOW('H', 0x03, struct snd_hwdep_dsp_image) - -/***************************************************************************** - * * - * Digital Audio (PCM) interface - /dev/snd/pcm?? * - * * - *****************************************************************************/ - -#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 14) - -typedef unsigned long snd_pcm_uframes_t; -typedef signed long snd_pcm_sframes_t; - -enum { - SNDRV_PCM_CLASS_GENERIC = 0, /* standard mono or stereo device */ - SNDRV_PCM_CLASS_MULTI, /* multichannel device */ - SNDRV_PCM_CLASS_MODEM, /* software modem class */ - SNDRV_PCM_CLASS_DIGITIZER, /* digitizer class */ - /* Don't forget to change the following: */ - SNDRV_PCM_CLASS_LAST = SNDRV_PCM_CLASS_DIGITIZER, -}; - -enum { - SNDRV_PCM_SUBCLASS_GENERIC_MIX = 0, /* mono or stereo subdevices are mixed together */ - SNDRV_PCM_SUBCLASS_MULTI_MIX, /* multichannel subdevices are mixed together */ - /* Don't forget to change the following: */ - SNDRV_PCM_SUBCLASS_LAST = SNDRV_PCM_SUBCLASS_MULTI_MIX, -}; - -enum { - SNDRV_PCM_STREAM_PLAYBACK = 0, - SNDRV_PCM_STREAM_CAPTURE, - SNDRV_PCM_STREAM_LAST = SNDRV_PCM_STREAM_CAPTURE, -}; - -typedef int __bitwise snd_pcm_access_t; -#define SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ((__force snd_pcm_access_t) 0) /* interleaved mmap */ -#define SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED ((__force snd_pcm_access_t) 1) /* noninterleaved mmap */ -#define SNDRV_PCM_ACCESS_MMAP_COMPLEX ((__force snd_pcm_access_t) 2) /* complex mmap */ -#define SNDRV_PCM_ACCESS_RW_INTERLEAVED ((__force snd_pcm_access_t) 3) /* readi/writei */ -#define SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ((__force snd_pcm_access_t) 4) /* readn/writen */ -#define SNDRV_PCM_ACCESS_LAST SNDRV_PCM_ACCESS_RW_NONINTERLEAVED - -typedef int __bitwise snd_pcm_format_t; -#define SNDRV_PCM_FORMAT_S8 ((__force snd_pcm_format_t) 0) -#define SNDRV_PCM_FORMAT_U8 ((__force snd_pcm_format_t) 1) -#define SNDRV_PCM_FORMAT_S16_LE ((__force snd_pcm_format_t) 2) -#define SNDRV_PCM_FORMAT_S16_BE ((__force snd_pcm_format_t) 3) -#define SNDRV_PCM_FORMAT_U16_LE ((__force snd_pcm_format_t) 4) -#define SNDRV_PCM_FORMAT_U16_BE ((__force snd_pcm_format_t) 5) -#define SNDRV_PCM_FORMAT_S24_LE ((__force snd_pcm_format_t) 6) /* low three bytes */ -#define SNDRV_PCM_FORMAT_S24_BE ((__force snd_pcm_format_t) 7) /* low three bytes */ -#define SNDRV_PCM_FORMAT_U24_LE ((__force snd_pcm_format_t) 8) /* low three bytes */ -#define SNDRV_PCM_FORMAT_U24_BE ((__force snd_pcm_format_t) 9) /* low three bytes */ -#define SNDRV_PCM_FORMAT_S32_LE ((__force snd_pcm_format_t) 10) -#define SNDRV_PCM_FORMAT_S32_BE ((__force snd_pcm_format_t) 11) -#define SNDRV_PCM_FORMAT_U32_LE ((__force snd_pcm_format_t) 12) -#define SNDRV_PCM_FORMAT_U32_BE ((__force snd_pcm_format_t) 13) -#define SNDRV_PCM_FORMAT_FLOAT_LE ((__force snd_pcm_format_t) 14) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */ -#define SNDRV_PCM_FORMAT_FLOAT_BE ((__force snd_pcm_format_t) 15) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */ -#define SNDRV_PCM_FORMAT_FLOAT64_LE ((__force snd_pcm_format_t) 16) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */ -#define SNDRV_PCM_FORMAT_FLOAT64_BE ((__force snd_pcm_format_t) 17) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */ -#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE ((__force snd_pcm_format_t) 18) /* IEC-958 subframe, Little Endian */ -#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE ((__force snd_pcm_format_t) 19) /* IEC-958 subframe, Big Endian */ -#define SNDRV_PCM_FORMAT_MU_LAW ((__force snd_pcm_format_t) 20) -#define SNDRV_PCM_FORMAT_A_LAW ((__force snd_pcm_format_t) 21) -#define SNDRV_PCM_FORMAT_IMA_ADPCM ((__force snd_pcm_format_t) 22) -#define SNDRV_PCM_FORMAT_MPEG ((__force snd_pcm_format_t) 23) -#define SNDRV_PCM_FORMAT_GSM ((__force snd_pcm_format_t) 24) -#define SNDRV_PCM_FORMAT_S20_LE ((__force snd_pcm_format_t) 25) /* in four bytes, LSB justified */ -#define SNDRV_PCM_FORMAT_S20_BE ((__force snd_pcm_format_t) 26) /* in four bytes, LSB justified */ -#define SNDRV_PCM_FORMAT_U20_LE ((__force snd_pcm_format_t) 27) /* in four bytes, LSB justified */ -#define SNDRV_PCM_FORMAT_U20_BE ((__force snd_pcm_format_t) 28) /* in four bytes, LSB justified */ -/* gap in the numbering for a future standard linear format */ -#define SNDRV_PCM_FORMAT_SPECIAL ((__force snd_pcm_format_t) 31) -#define SNDRV_PCM_FORMAT_S24_3LE ((__force snd_pcm_format_t) 32) /* in three bytes */ -#define SNDRV_PCM_FORMAT_S24_3BE ((__force snd_pcm_format_t) 33) /* in three bytes */ -#define SNDRV_PCM_FORMAT_U24_3LE ((__force snd_pcm_format_t) 34) /* in three bytes */ -#define SNDRV_PCM_FORMAT_U24_3BE ((__force snd_pcm_format_t) 35) /* in three bytes */ -#define SNDRV_PCM_FORMAT_S20_3LE ((__force snd_pcm_format_t) 36) /* in three bytes */ -#define SNDRV_PCM_FORMAT_S20_3BE ((__force snd_pcm_format_t) 37) /* in three bytes */ -#define SNDRV_PCM_FORMAT_U20_3LE ((__force snd_pcm_format_t) 38) /* in three bytes */ -#define SNDRV_PCM_FORMAT_U20_3BE ((__force snd_pcm_format_t) 39) /* in three bytes */ -#define SNDRV_PCM_FORMAT_S18_3LE ((__force snd_pcm_format_t) 40) /* in three bytes */ -#define SNDRV_PCM_FORMAT_S18_3BE ((__force snd_pcm_format_t) 41) /* in three bytes */ -#define SNDRV_PCM_FORMAT_U18_3LE ((__force snd_pcm_format_t) 42) /* in three bytes */ -#define SNDRV_PCM_FORMAT_U18_3BE ((__force snd_pcm_format_t) 43) /* in three bytes */ -#define SNDRV_PCM_FORMAT_G723_24 ((__force snd_pcm_format_t) 44) /* 8 samples in 3 bytes */ -#define SNDRV_PCM_FORMAT_G723_24_1B ((__force snd_pcm_format_t) 45) /* 1 sample in 1 byte */ -#define SNDRV_PCM_FORMAT_G723_40 ((__force snd_pcm_format_t) 46) /* 8 Samples in 5 bytes */ -#define SNDRV_PCM_FORMAT_G723_40_1B ((__force snd_pcm_format_t) 47) /* 1 sample in 1 byte */ -#define SNDRV_PCM_FORMAT_DSD_U8 ((__force snd_pcm_format_t) 48) /* DSD, 1-byte samples DSD (x8) */ -#define SNDRV_PCM_FORMAT_DSD_U16_LE ((__force snd_pcm_format_t) 49) /* DSD, 2-byte samples DSD (x16), little endian */ -#define SNDRV_PCM_FORMAT_DSD_U32_LE ((__force snd_pcm_format_t) 50) /* DSD, 4-byte samples DSD (x32), little endian */ -#define SNDRV_PCM_FORMAT_DSD_U16_BE ((__force snd_pcm_format_t) 51) /* DSD, 2-byte samples DSD (x16), big endian */ -#define SNDRV_PCM_FORMAT_DSD_U32_BE ((__force snd_pcm_format_t) 52) /* DSD, 4-byte samples DSD (x32), big endian */ -#define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_DSD_U32_BE -#define SNDRV_PCM_FORMAT_FIRST SNDRV_PCM_FORMAT_S8 - -#ifdef SNDRV_LITTLE_ENDIAN -#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_LE -#define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_LE -#define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_LE -#define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_LE -#define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_LE -#define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_LE -#define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_LE -#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_LE -#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE -#define SNDRV_PCM_FORMAT_S20 SNDRV_PCM_FORMAT_S20_LE -#define SNDRV_PCM_FORMAT_U20 SNDRV_PCM_FORMAT_U20_LE +#include #endif -#ifdef SNDRV_BIG_ENDIAN -#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_BE -#define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_BE -#define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_BE -#define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_BE -#define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_BE -#define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_BE -#define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_BE -#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_BE -#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE -#define SNDRV_PCM_FORMAT_S20 SNDRV_PCM_FORMAT_S20_BE -#define SNDRV_PCM_FORMAT_U20 SNDRV_PCM_FORMAT_U20_BE +#ifndef __kernel_long_t +#define __kernel_long_t long #endif -typedef int __bitwise snd_pcm_subformat_t; -#define SNDRV_PCM_SUBFORMAT_STD ((__force snd_pcm_subformat_t) 0) -#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_STD - -#define SNDRV_PCM_INFO_MMAP 0x00000001 /* hardware supports mmap */ -#define SNDRV_PCM_INFO_MMAP_VALID 0x00000002 /* period data are valid during transfer */ -#define SNDRV_PCM_INFO_DOUBLE 0x00000004 /* Double buffering needed for PCM start/stop */ -#define SNDRV_PCM_INFO_BATCH 0x00000010 /* double buffering */ -#define SNDRV_PCM_INFO_SYNC_APPLPTR 0x00000020 /* need the explicit sync of appl_ptr update */ -#define SNDRV_PCM_INFO_INTERLEAVED 0x00000100 /* channels are interleaved */ -#define SNDRV_PCM_INFO_NONINTERLEAVED 0x00000200 /* channels are not interleaved */ -#define SNDRV_PCM_INFO_COMPLEX 0x00000400 /* complex frame organization (mmap only) */ -#define SNDRV_PCM_INFO_BLOCK_TRANSFER 0x00010000 /* hardware transfer block of samples */ -#define SNDRV_PCM_INFO_OVERRANGE 0x00020000 /* hardware supports ADC (capture) overrange detection */ -#define SNDRV_PCM_INFO_RESUME 0x00040000 /* hardware supports stream resume after suspend */ -#define SNDRV_PCM_INFO_PAUSE 0x00080000 /* pause ioctl is supported */ -#define SNDRV_PCM_INFO_HALF_DUPLEX 0x00100000 /* only half duplex */ -#define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */ -#define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */ -#define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000 /* period wakeup can be disabled */ -#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000 /* (Deprecated)has audio wall clock for audio/system time sync */ -#define SNDRV_PCM_INFO_HAS_LINK_ATIME 0x01000000 /* report hardware link audio time, reset on startup */ -#define SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME 0x02000000 /* report absolute hardware link audio time, not reset on startup */ -#define SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME 0x04000000 /* report estimated link audio time */ -#define SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME 0x08000000 /* report synchronized audio/system time */ - -#define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */ -#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ - - - -typedef int __bitwise snd_pcm_state_t; -#define SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0) /* stream is open */ -#define SNDRV_PCM_STATE_SETUP ((__force snd_pcm_state_t) 1) /* stream has a setup */ -#define SNDRV_PCM_STATE_PREPARED ((__force snd_pcm_state_t) 2) /* stream is ready to start */ -#define SNDRV_PCM_STATE_RUNNING ((__force snd_pcm_state_t) 3) /* stream is running */ -#define SNDRV_PCM_STATE_XRUN ((__force snd_pcm_state_t) 4) /* stream reached an xrun */ -#define SNDRV_PCM_STATE_DRAINING ((__force snd_pcm_state_t) 5) /* stream is draining */ -#define SNDRV_PCM_STATE_PAUSED ((__force snd_pcm_state_t) 6) /* stream is paused */ -#define SNDRV_PCM_STATE_SUSPENDED ((__force snd_pcm_state_t) 7) /* hardware is suspended */ -#define SNDRV_PCM_STATE_DISCONNECTED ((__force snd_pcm_state_t) 8) /* hardware is disconnected */ -#define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DISCONNECTED - -enum { - SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000, - SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000, - SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000, -}; - -union snd_pcm_sync_id { - unsigned char id[16]; - unsigned short id16[8]; - unsigned int id32[4]; -}; - -struct snd_pcm_info { - unsigned int device; /* RO/WR (control): device number */ - unsigned int subdevice; /* RO/WR (control): subdevice number */ - int stream; /* RO/WR (control): stream direction */ - int card; /* R: card number */ - unsigned char id[64]; /* ID (user selectable) */ - unsigned char name[80]; /* name of this device */ - unsigned char subname[32]; /* subdevice name */ - int dev_class; /* SNDRV_PCM_CLASS_* */ - int dev_subclass; /* SNDRV_PCM_SUBCLASS_* */ - unsigned int subdevices_count; - unsigned int subdevices_avail; - union snd_pcm_sync_id sync; /* hardware synchronization ID */ - unsigned char reserved[64]; /* reserved for future... */ -}; - -typedef int snd_pcm_hw_param_t; -#define SNDRV_PCM_HW_PARAM_ACCESS 0 /* Access type */ -#define SNDRV_PCM_HW_PARAM_FORMAT 1 /* Format */ -#define SNDRV_PCM_HW_PARAM_SUBFORMAT 2 /* Subformat */ -#define SNDRV_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_ACCESS -#define SNDRV_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_SUBFORMAT - -#define SNDRV_PCM_HW_PARAM_SAMPLE_BITS 8 /* Bits per sample */ -#define SNDRV_PCM_HW_PARAM_FRAME_BITS 9 /* Bits per frame */ -#define SNDRV_PCM_HW_PARAM_CHANNELS 10 /* Channels */ -#define SNDRV_PCM_HW_PARAM_RATE 11 /* Approx rate */ -#define SNDRV_PCM_HW_PARAM_PERIOD_TIME 12 /* Approx distance between - * interrupts in us - */ -#define SNDRV_PCM_HW_PARAM_PERIOD_SIZE 13 /* Approx frames between - * interrupts - */ -#define SNDRV_PCM_HW_PARAM_PERIOD_BYTES 14 /* Approx bytes between - * interrupts - */ -#define SNDRV_PCM_HW_PARAM_PERIODS 15 /* Approx interrupts per - * buffer - */ -#define SNDRV_PCM_HW_PARAM_BUFFER_TIME 16 /* Approx duration of buffer - * in us - */ -#define SNDRV_PCM_HW_PARAM_BUFFER_SIZE 17 /* Size of buffer in frames */ -#define SNDRV_PCM_HW_PARAM_BUFFER_BYTES 18 /* Size of buffer in bytes */ -#define SNDRV_PCM_HW_PARAM_TICK_TIME 19 /* Approx tick duration in us */ -#define SNDRV_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_SAMPLE_BITS -#define SNDRV_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_TICK_TIME - -#define SNDRV_PCM_HW_PARAMS_NORESAMPLE (1<<0) /* avoid rate resampling */ -#define SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER (1<<1) /* export buffer */ -#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP (1<<2) /* disable period wakeups */ - -struct snd_interval { - unsigned int min, max; - unsigned int openmin:1, - openmax:1, - integer:1, - empty:1; -}; - -#define SNDRV_MASK_MAX 256 - -struct snd_mask { - __u32 bits[(SNDRV_MASK_MAX+31)/32]; -}; - -struct snd_pcm_hw_params { - unsigned int flags; - struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - - SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; - struct snd_mask mres[5]; /* reserved masks */ - struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1]; - struct snd_interval ires[9]; /* reserved intervals */ - unsigned int rmask; /* W: requested masks */ - unsigned int cmask; /* R: changed masks */ - unsigned int info; /* R: Info flags for returned setup */ - unsigned int msbits; /* R: used most significant bits */ - unsigned int rate_num; /* R: rate numerator */ - unsigned int rate_den; /* R: rate denominator */ - snd_pcm_uframes_t fifo_size; /* R: chip FIFO size in frames */ - unsigned char reserved[64]; /* reserved for future */ -}; - -enum { - SNDRV_PCM_TSTAMP_NONE = 0, - SNDRV_PCM_TSTAMP_ENABLE, - SNDRV_PCM_TSTAMP_LAST = SNDRV_PCM_TSTAMP_ENABLE, -}; - -struct snd_pcm_sw_params { - int tstamp_mode; /* timestamp mode */ - unsigned int period_step; - unsigned int sleep_min; /* min ticks to sleep */ - snd_pcm_uframes_t avail_min; /* min avail frames for wakeup */ - snd_pcm_uframes_t xfer_align; /* obsolete: xfer size need to be a multiple */ - snd_pcm_uframes_t start_threshold; /* min hw_avail frames for automatic start */ - snd_pcm_uframes_t stop_threshold; /* min avail frames for automatic stop */ - snd_pcm_uframes_t silence_threshold; /* min distance from noise for silence filling */ - snd_pcm_uframes_t silence_size; /* silence block size */ - snd_pcm_uframes_t boundary; /* pointers wrap point */ - unsigned int proto; /* protocol version */ - unsigned int tstamp_type; /* timestamp type (req. proto >= 2.0.12) */ - unsigned char reserved[56]; /* reserved for future */ -}; - -struct snd_pcm_channel_info { - unsigned int channel; - __kernel_off_t offset; /* mmap offset */ - unsigned int first; /* offset to first sample in bits */ - unsigned int step; /* samples distance in bits */ -}; - -enum { - /* - * first definition for backwards compatibility only, - * maps to wallclock/link time for HDAudio playback and DEFAULT/DMA time for everything else - */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT = 0, - - /* timestamp definitions */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT = 1, /* DMA time, reported as per hw_ptr */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK = 2, /* link time reported by sample or wallclock counter, reset on startup */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE = 3, /* link time reported by sample or wallclock counter, not reset on startup */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED = 4, /* link time estimated indirectly */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED = 5, /* link time synchronized with system time */ - SNDRV_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED -}; - -struct snd_pcm_status { - snd_pcm_state_t state; /* stream state */ - struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */ - struct timespec tstamp; /* reference timestamp */ - snd_pcm_uframes_t appl_ptr; /* appl ptr */ - snd_pcm_uframes_t hw_ptr; /* hw ptr */ - snd_pcm_sframes_t delay; /* current delay in frames */ - snd_pcm_uframes_t avail; /* number of frames available */ - snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */ - snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */ - snd_pcm_state_t suspended_state; /* suspended stream state */ - __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ - struct timespec audio_tstamp; /* sample counter, wall clock, PHC or on-demand sync'ed */ - struct timespec driver_tstamp; /* useful in case reference system tstamp is reported with delay */ - __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ - unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */ -}; - -struct snd_pcm_mmap_status { - snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ - int pad1; /* Needed for 64 bit alignment */ - snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ - struct timespec tstamp; /* Timestamp */ - snd_pcm_state_t suspended_state; /* RO: suspended stream state */ - struct timespec audio_tstamp; /* from sample counter or wall clock */ -}; - -struct snd_pcm_mmap_control { - snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ - snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ -}; - -#define SNDRV_PCM_SYNC_PTR_HWSYNC (1<<0) /* execute hwsync */ -#define SNDRV_PCM_SYNC_PTR_APPL (1<<1) /* get appl_ptr from driver (r/w op) */ -#define SNDRV_PCM_SYNC_PTR_AVAIL_MIN (1<<2) /* get avail_min from driver */ - -struct snd_pcm_sync_ptr { - unsigned int flags; - union { - struct snd_pcm_mmap_status status; - unsigned char reserved[64]; - } s; - union { - struct snd_pcm_mmap_control control; - unsigned char reserved[64]; - } c; -}; - -struct snd_xferi { - snd_pcm_sframes_t result; - void __user *buf; - snd_pcm_uframes_t frames; -}; - -struct snd_xfern { - snd_pcm_sframes_t result; - void __user * __user *bufs; - snd_pcm_uframes_t frames; -}; - -enum { - SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0, /* gettimeofday equivalent */ - SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, /* posix_clock_monotonic equivalent */ - SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, /* monotonic_raw (no NTP) */ - SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, -}; - -/* channel positions */ -enum { - SNDRV_CHMAP_UNKNOWN = 0, - SNDRV_CHMAP_NA, /* N/A, silent */ - SNDRV_CHMAP_MONO, /* mono stream */ - /* this follows the alsa-lib mixer channel value + 3 */ - SNDRV_CHMAP_FL, /* front left */ - SNDRV_CHMAP_FR, /* front right */ - SNDRV_CHMAP_RL, /* rear left */ - SNDRV_CHMAP_RR, /* rear right */ - SNDRV_CHMAP_FC, /* front center */ - SNDRV_CHMAP_LFE, /* LFE */ - SNDRV_CHMAP_SL, /* side left */ - SNDRV_CHMAP_SR, /* side right */ - SNDRV_CHMAP_RC, /* rear center */ - /* new definitions */ - SNDRV_CHMAP_FLC, /* front left center */ - SNDRV_CHMAP_FRC, /* front right center */ - SNDRV_CHMAP_RLC, /* rear left center */ - SNDRV_CHMAP_RRC, /* rear right center */ - SNDRV_CHMAP_FLW, /* front left wide */ - SNDRV_CHMAP_FRW, /* front right wide */ - SNDRV_CHMAP_FLH, /* front left high */ - SNDRV_CHMAP_FCH, /* front center high */ - SNDRV_CHMAP_FRH, /* front right high */ - SNDRV_CHMAP_TC, /* top center */ - SNDRV_CHMAP_TFL, /* top front left */ - SNDRV_CHMAP_TFR, /* top front right */ - SNDRV_CHMAP_TFC, /* top front center */ - SNDRV_CHMAP_TRL, /* top rear left */ - SNDRV_CHMAP_TRR, /* top rear right */ - SNDRV_CHMAP_TRC, /* top rear center */ - /* new definitions for UAC2 */ - SNDRV_CHMAP_TFLC, /* top front left center */ - SNDRV_CHMAP_TFRC, /* top front right center */ - SNDRV_CHMAP_TSL, /* top side left */ - SNDRV_CHMAP_TSR, /* top side right */ - SNDRV_CHMAP_LLFE, /* left LFE */ - SNDRV_CHMAP_RLFE, /* right LFE */ - SNDRV_CHMAP_BC, /* bottom center */ - SNDRV_CHMAP_BLC, /* bottom left center */ - SNDRV_CHMAP_BRC, /* bottom right center */ - SNDRV_CHMAP_LAST = SNDRV_CHMAP_BRC, -}; - -#define SNDRV_CHMAP_POSITION_MASK 0xffff -#define SNDRV_CHMAP_PHASE_INVERSE (0x01 << 16) -#define SNDRV_CHMAP_DRIVER_SPEC (0x02 << 16) - -#define SNDRV_PCM_IOCTL_PVERSION _IOR('A', 0x00, int) -#define SNDRV_PCM_IOCTL_INFO _IOR('A', 0x01, struct snd_pcm_info) -#define SNDRV_PCM_IOCTL_TSTAMP _IOW('A', 0x02, int) -#define SNDRV_PCM_IOCTL_TTSTAMP _IOW('A', 0x03, int) -#define SNDRV_PCM_IOCTL_USER_PVERSION _IOW('A', 0x04, int) -#define SNDRV_PCM_IOCTL_HW_REFINE _IOWR('A', 0x10, struct snd_pcm_hw_params) -#define SNDRV_PCM_IOCTL_HW_PARAMS _IOWR('A', 0x11, struct snd_pcm_hw_params) -#define SNDRV_PCM_IOCTL_HW_FREE _IO('A', 0x12) -#define SNDRV_PCM_IOCTL_SW_PARAMS _IOWR('A', 0x13, struct snd_pcm_sw_params) -#define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status) -#define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t) -#define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22) -#define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr) -#define SNDRV_PCM_IOCTL_STATUS_EXT _IOWR('A', 0x24, struct snd_pcm_status) -#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info) -#define SNDRV_PCM_IOCTL_PREPARE _IO('A', 0x40) -#define SNDRV_PCM_IOCTL_RESET _IO('A', 0x41) -#define SNDRV_PCM_IOCTL_START _IO('A', 0x42) -#define SNDRV_PCM_IOCTL_DROP _IO('A', 0x43) -#define SNDRV_PCM_IOCTL_DRAIN _IO('A', 0x44) -#define SNDRV_PCM_IOCTL_PAUSE _IOW('A', 0x45, int) -#define SNDRV_PCM_IOCTL_REWIND _IOW('A', 0x46, snd_pcm_uframes_t) -#define SNDRV_PCM_IOCTL_RESUME _IO('A', 0x47) -#define SNDRV_PCM_IOCTL_XRUN _IO('A', 0x48) -#define SNDRV_PCM_IOCTL_FORWARD _IOW('A', 0x49, snd_pcm_uframes_t) -#define SNDRV_PCM_IOCTL_WRITEI_FRAMES _IOW('A', 0x50, struct snd_xferi) -#define SNDRV_PCM_IOCTL_READI_FRAMES _IOR('A', 0x51, struct snd_xferi) -#define SNDRV_PCM_IOCTL_WRITEN_FRAMES _IOW('A', 0x52, struct snd_xfern) -#define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern) -#define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int) -#define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61) - -/***************************************************************************** - * * - * MIDI v1.0 interface * - * * - *****************************************************************************/ - -/* - * Raw MIDI section - /dev/snd/midi?? - */ - -#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 0) - -enum { - SNDRV_RAWMIDI_STREAM_OUTPUT = 0, - SNDRV_RAWMIDI_STREAM_INPUT, - SNDRV_RAWMIDI_STREAM_LAST = SNDRV_RAWMIDI_STREAM_INPUT, -}; - -#define SNDRV_RAWMIDI_INFO_OUTPUT 0x00000001 -#define SNDRV_RAWMIDI_INFO_INPUT 0x00000002 -#define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004 - -struct snd_rawmidi_info { - unsigned int device; /* RO/WR (control): device number */ - unsigned int subdevice; /* RO/WR (control): subdevice number */ - int stream; /* WR: stream */ - int card; /* R: card number */ - unsigned int flags; /* SNDRV_RAWMIDI_INFO_XXXX */ - unsigned char id[64]; /* ID (user selectable) */ - unsigned char name[80]; /* name of device */ - unsigned char subname[32]; /* name of active or selected subdevice */ - unsigned int subdevices_count; - unsigned int subdevices_avail; - unsigned char reserved[64]; /* reserved for future use */ -}; - -struct snd_rawmidi_params { - int stream; - size_t buffer_size; /* queue size in bytes */ - size_t avail_min; /* minimum avail bytes for wakeup */ - unsigned int no_active_sensing: 1; /* do not send active sensing byte in close() */ - unsigned char reserved[16]; /* reserved for future use */ -}; - -struct snd_rawmidi_status { - int stream; - struct timespec tstamp; /* Timestamp */ - size_t avail; /* available bytes */ - size_t xruns; /* count of overruns since last status (in bytes) */ - unsigned char reserved[16]; /* reserved for future use */ -}; - -#define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int) -#define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info) -#define SNDRV_RAWMIDI_IOCTL_PARAMS _IOWR('W', 0x10, struct snd_rawmidi_params) -#define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status) -#define SNDRV_RAWMIDI_IOCTL_DROP _IOW('W', 0x30, int) -#define SNDRV_RAWMIDI_IOCTL_DRAIN _IOW('W', 0x31, int) - -/* - * Timer section - /dev/snd/timer - */ - -#define SNDRV_TIMER_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 6) - -enum { - SNDRV_TIMER_CLASS_NONE = -1, - SNDRV_TIMER_CLASS_SLAVE = 0, - SNDRV_TIMER_CLASS_GLOBAL, - SNDRV_TIMER_CLASS_CARD, - SNDRV_TIMER_CLASS_PCM, - SNDRV_TIMER_CLASS_LAST = SNDRV_TIMER_CLASS_PCM, -}; - -/* slave timer classes */ -enum { - SNDRV_TIMER_SCLASS_NONE = 0, - SNDRV_TIMER_SCLASS_APPLICATION, - SNDRV_TIMER_SCLASS_SEQUENCER, /* alias */ - SNDRV_TIMER_SCLASS_OSS_SEQUENCER, /* alias */ - SNDRV_TIMER_SCLASS_LAST = SNDRV_TIMER_SCLASS_OSS_SEQUENCER, -}; - -/* global timers (device member) */ -#define SNDRV_TIMER_GLOBAL_SYSTEM 0 -#define SNDRV_TIMER_GLOBAL_RTC 1 /* unused */ -#define SNDRV_TIMER_GLOBAL_HPET 2 -#define SNDRV_TIMER_GLOBAL_HRTIMER 3 - -/* info flags */ -#define SNDRV_TIMER_FLG_SLAVE (1<<0) /* cannot be controlled */ - -struct snd_timer_id { - int dev_class; - int dev_sclass; - int card; - int device; - int subdevice; -}; - -struct snd_timer_ginfo { - struct snd_timer_id tid; /* requested timer ID */ - unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */ - int card; /* card number */ - unsigned char id[64]; /* timer identification */ - unsigned char name[80]; /* timer name */ - unsigned long reserved0; /* reserved for future use */ - unsigned long resolution; /* average period resolution in ns */ - unsigned long resolution_min; /* minimal period resolution in ns */ - unsigned long resolution_max; /* maximal period resolution in ns */ - unsigned int clients; /* active timer clients */ - unsigned char reserved[32]; -}; - -struct snd_timer_gparams { - struct snd_timer_id tid; /* requested timer ID */ - unsigned long period_num; /* requested precise period duration (in seconds) - numerator */ - unsigned long period_den; /* requested precise period duration (in seconds) - denominator */ - unsigned char reserved[32]; -}; - -struct snd_timer_gstatus { - struct snd_timer_id tid; /* requested timer ID */ - unsigned long resolution; /* current period resolution in ns */ - unsigned long resolution_num; /* precise current period resolution (in seconds) - numerator */ - unsigned long resolution_den; /* precise current period resolution (in seconds) - denominator */ - unsigned char reserved[32]; -}; - -struct snd_timer_select { - struct snd_timer_id id; /* bind to timer ID */ - unsigned char reserved[32]; /* reserved */ -}; - -struct snd_timer_info { - unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */ - int card; /* card number */ - unsigned char id[64]; /* timer identificator */ - unsigned char name[80]; /* timer name */ - unsigned long reserved0; /* reserved for future use */ - unsigned long resolution; /* average period resolution in ns */ - unsigned char reserved[64]; /* reserved */ -}; - -#define SNDRV_TIMER_PSFLG_AUTO (1<<0) /* auto start, otherwise one-shot */ -#define SNDRV_TIMER_PSFLG_EXCLUSIVE (1<<1) /* exclusive use, precise start/stop/pause/continue */ -#define SNDRV_TIMER_PSFLG_EARLY_EVENT (1<<2) /* write early event to the poll queue */ - -struct snd_timer_params { - unsigned int flags; /* flags - SNDRV_TIMER_PSFLG_* */ - unsigned int ticks; /* requested resolution in ticks */ - unsigned int queue_size; /* total size of queue (32-1024) */ - unsigned int reserved0; /* reserved, was: failure locations */ - unsigned int filter; /* event filter (bitmask of SNDRV_TIMER_EVENT_*) */ - unsigned char reserved[60]; /* reserved */ -}; - -struct snd_timer_status { - struct timespec tstamp; /* Timestamp - last update */ - unsigned int resolution; /* current period resolution in ns */ - unsigned int lost; /* counter of master tick lost */ - unsigned int overrun; /* count of read queue overruns */ - unsigned int queue; /* used queue size */ - unsigned char reserved[64]; /* reserved */ -}; - -#define SNDRV_TIMER_IOCTL_PVERSION _IOR('T', 0x00, int) -#define SNDRV_TIMER_IOCTL_NEXT_DEVICE _IOWR('T', 0x01, struct snd_timer_id) -#define SNDRV_TIMER_IOCTL_TREAD _IOW('T', 0x02, int) -#define SNDRV_TIMER_IOCTL_GINFO _IOWR('T', 0x03, struct snd_timer_ginfo) -#define SNDRV_TIMER_IOCTL_GPARAMS _IOW('T', 0x04, struct snd_timer_gparams) -#define SNDRV_TIMER_IOCTL_GSTATUS _IOWR('T', 0x05, struct snd_timer_gstatus) -#define SNDRV_TIMER_IOCTL_SELECT _IOW('T', 0x10, struct snd_timer_select) -#define SNDRV_TIMER_IOCTL_INFO _IOR('T', 0x11, struct snd_timer_info) -#define SNDRV_TIMER_IOCTL_PARAMS _IOW('T', 0x12, struct snd_timer_params) -#define SNDRV_TIMER_IOCTL_STATUS _IOR('T', 0x14, struct snd_timer_status) -/* The following four ioctls are changed since 1.0.9 due to confliction */ -#define SNDRV_TIMER_IOCTL_START _IO('T', 0xa0) -#define SNDRV_TIMER_IOCTL_STOP _IO('T', 0xa1) -#define SNDRV_TIMER_IOCTL_CONTINUE _IO('T', 0xa2) -#define SNDRV_TIMER_IOCTL_PAUSE _IO('T', 0xa3) - -struct snd_timer_read { - unsigned int resolution; - unsigned int ticks; -}; - -enum { - SNDRV_TIMER_EVENT_RESOLUTION = 0, /* val = resolution in ns */ - SNDRV_TIMER_EVENT_TICK, /* val = ticks */ - SNDRV_TIMER_EVENT_START, /* val = resolution in ns */ - SNDRV_TIMER_EVENT_STOP, /* val = 0 */ - SNDRV_TIMER_EVENT_CONTINUE, /* val = resolution in ns */ - SNDRV_TIMER_EVENT_PAUSE, /* val = 0 */ - SNDRV_TIMER_EVENT_EARLY, /* val = 0, early event */ - SNDRV_TIMER_EVENT_SUSPEND, /* val = 0 */ - SNDRV_TIMER_EVENT_RESUME, /* val = resolution in ns */ - /* master timer events for slave timer instances */ - SNDRV_TIMER_EVENT_MSTART = SNDRV_TIMER_EVENT_START + 10, - SNDRV_TIMER_EVENT_MSTOP = SNDRV_TIMER_EVENT_STOP + 10, - SNDRV_TIMER_EVENT_MCONTINUE = SNDRV_TIMER_EVENT_CONTINUE + 10, - SNDRV_TIMER_EVENT_MPAUSE = SNDRV_TIMER_EVENT_PAUSE + 10, - SNDRV_TIMER_EVENT_MSUSPEND = SNDRV_TIMER_EVENT_SUSPEND + 10, - SNDRV_TIMER_EVENT_MRESUME = SNDRV_TIMER_EVENT_RESUME + 10, -}; - -struct snd_timer_tread { - int event; - struct timespec tstamp; - unsigned int val; -}; - -/**************************************************************************** - * * - * Section for driver control interface - /dev/snd/control? * - * * - ****************************************************************************/ - -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 7) - -struct snd_ctl_card_info { - int card; /* card number */ - int pad; /* reserved for future (was type) */ - unsigned char id[16]; /* ID of card (user selectable) */ - unsigned char driver[16]; /* Driver name */ - unsigned char name[32]; /* Short name of soundcard */ - unsigned char longname[80]; /* name + info text about soundcard */ - unsigned char reserved_[16]; /* reserved for future (was ID of mixer) */ - unsigned char mixername[80]; /* visual mixer identification */ - unsigned char components[128]; /* card components / fine identification, delimited with one space (AC97 etc..) */ -}; - -typedef int __bitwise snd_ctl_elem_type_t; -#define SNDRV_CTL_ELEM_TYPE_NONE ((__force snd_ctl_elem_type_t) 0) /* invalid */ -#define SNDRV_CTL_ELEM_TYPE_BOOLEAN ((__force snd_ctl_elem_type_t) 1) /* boolean type */ -#define SNDRV_CTL_ELEM_TYPE_INTEGER ((__force snd_ctl_elem_type_t) 2) /* integer type */ -#define SNDRV_CTL_ELEM_TYPE_ENUMERATED ((__force snd_ctl_elem_type_t) 3) /* enumerated type */ -#define SNDRV_CTL_ELEM_TYPE_BYTES ((__force snd_ctl_elem_type_t) 4) /* byte array */ -#define SNDRV_CTL_ELEM_TYPE_IEC958 ((__force snd_ctl_elem_type_t) 5) /* IEC958 (S/PDIF) setup */ -#define SNDRV_CTL_ELEM_TYPE_INTEGER64 ((__force snd_ctl_elem_type_t) 6) /* 64-bit integer type */ -#define SNDRV_CTL_ELEM_TYPE_LAST SNDRV_CTL_ELEM_TYPE_INTEGER64 - -typedef int __bitwise snd_ctl_elem_iface_t; -#define SNDRV_CTL_ELEM_IFACE_CARD ((__force snd_ctl_elem_iface_t) 0) /* global control */ -#define SNDRV_CTL_ELEM_IFACE_HWDEP ((__force snd_ctl_elem_iface_t) 1) /* hardware dependent device */ -#define SNDRV_CTL_ELEM_IFACE_MIXER ((__force snd_ctl_elem_iface_t) 2) /* virtual mixer device */ -#define SNDRV_CTL_ELEM_IFACE_PCM ((__force snd_ctl_elem_iface_t) 3) /* PCM device */ -#define SNDRV_CTL_ELEM_IFACE_RAWMIDI ((__force snd_ctl_elem_iface_t) 4) /* RawMidi device */ -#define SNDRV_CTL_ELEM_IFACE_TIMER ((__force snd_ctl_elem_iface_t) 5) /* timer device */ -#define SNDRV_CTL_ELEM_IFACE_SEQUENCER ((__force snd_ctl_elem_iface_t) 6) /* sequencer client */ -#define SNDRV_CTL_ELEM_IFACE_LAST SNDRV_CTL_ELEM_IFACE_SEQUENCER - -#define SNDRV_CTL_ELEM_ACCESS_READ (1<<0) -#define SNDRV_CTL_ELEM_ACCESS_WRITE (1<<1) -#define SNDRV_CTL_ELEM_ACCESS_READWRITE (SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE) -#define SNDRV_CTL_ELEM_ACCESS_VOLATILE (1<<2) /* control value may be changed without a notification */ -#define SNDRV_CTL_ELEM_ACCESS_TIMESTAMP (1<<3) /* when was control changed */ -#define SNDRV_CTL_ELEM_ACCESS_TLV_READ (1<<4) /* TLV read is possible */ -#define SNDRV_CTL_ELEM_ACCESS_TLV_WRITE (1<<5) /* TLV write is possible */ -#define SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE (SNDRV_CTL_ELEM_ACCESS_TLV_READ|SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) -#define SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND (1<<6) /* TLV command is possible */ -#define SNDRV_CTL_ELEM_ACCESS_INACTIVE (1<<8) /* control does actually nothing, but may be updated */ -#define SNDRV_CTL_ELEM_ACCESS_LOCK (1<<9) /* write lock */ -#define SNDRV_CTL_ELEM_ACCESS_OWNER (1<<10) /* write lock owner */ -#define SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK (1<<28) /* kernel use a TLV callback */ -#define SNDRV_CTL_ELEM_ACCESS_USER (1<<29) /* user space element */ -/* bits 30 and 31 are obsoleted (for indirect access) */ - -/* for further details see the ACPI and PCI power management specification */ -#define SNDRV_CTL_POWER_D0 0x0000 /* full On */ -#define SNDRV_CTL_POWER_D1 0x0100 /* partial On */ -#define SNDRV_CTL_POWER_D2 0x0200 /* partial On */ -#define SNDRV_CTL_POWER_D3 0x0300 /* Off */ -#define SNDRV_CTL_POWER_D3hot (SNDRV_CTL_POWER_D3|0x0000) /* Off, with power */ -#define SNDRV_CTL_POWER_D3cold (SNDRV_CTL_POWER_D3|0x0001) /* Off, without power */ - -#define SNDRV_CTL_ELEM_ID_NAME_MAXLEN 44 - -struct snd_ctl_elem_id { - unsigned int numid; /* numeric identifier, zero = invalid */ - snd_ctl_elem_iface_t iface; /* interface identifier */ - unsigned int device; /* device/client number */ - unsigned int subdevice; /* subdevice (substream) number */ - unsigned char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* ASCII name of item */ - unsigned int index; /* index of item */ -}; - -struct snd_ctl_elem_list { - unsigned int offset; /* W: first element ID to get */ - unsigned int space; /* W: count of element IDs to get */ - unsigned int used; /* R: count of element IDs set */ - unsigned int count; /* R: count of all elements */ - struct snd_ctl_elem_id __user *pids; /* R: IDs */ - unsigned char reserved[50]; -}; - -struct snd_ctl_elem_info { - struct snd_ctl_elem_id id; /* W: element ID */ - snd_ctl_elem_type_t type; /* R: value type - SNDRV_CTL_ELEM_TYPE_* */ - unsigned int access; /* R: value access (bitmask) - SNDRV_CTL_ELEM_ACCESS_* */ - unsigned int count; /* count of values */ - __kernel_pid_t owner; /* owner's PID of this control */ - union { - struct { - long min; /* R: minimum value */ - long max; /* R: maximum value */ - long step; /* R: step (0 variable) */ - } integer; - struct { - long long min; /* R: minimum value */ - long long max; /* R: maximum value */ - long long step; /* R: step (0 variable) */ - } integer64; - struct { - unsigned int items; /* R: number of items */ - unsigned int item; /* W: item number */ - char name[64]; /* R: value name */ - __u64 names_ptr; /* W: names list (ELEM_ADD only) */ - unsigned int names_length; - } enumerated; - unsigned char reserved[128]; - } value; - union { - unsigned short d[4]; /* dimensions */ - unsigned short *d_ptr; /* indirect - obsoleted */ - } dimen; - unsigned char reserved[64-4*sizeof(unsigned short)]; -}; - -struct snd_ctl_elem_value { - struct snd_ctl_elem_id id; /* W: element ID */ - unsigned int indirect: 1; /* W: indirect access - obsoleted */ - union { - union { - long value[128]; - long *value_ptr; /* obsoleted */ - } integer; - union { - long long value[64]; - long long *value_ptr; /* obsoleted */ - } integer64; - union { - unsigned int item[128]; - unsigned int *item_ptr; /* obsoleted */ - } enumerated; - union { - unsigned char data[512]; - unsigned char *data_ptr; /* obsoleted */ - } bytes; - struct snd_aes_iec958 iec958; - } value; /* RO */ - struct timespec tstamp; - unsigned char reserved[128-sizeof(struct timespec)]; -}; - -struct snd_ctl_tlv { - unsigned int numid; /* control element numeric identification */ - unsigned int length; /* in bytes aligned to 4 */ - unsigned int tlv[0]; /* first TLV */ -}; - -#define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int) -#define SNDRV_CTL_IOCTL_CARD_INFO _IOR('U', 0x01, struct snd_ctl_card_info) -#define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list) -#define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info) -#define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value) -#define SNDRV_CTL_IOCTL_ELEM_WRITE _IOWR('U', 0x13, struct snd_ctl_elem_value) -#define SNDRV_CTL_IOCTL_ELEM_LOCK _IOW('U', 0x14, struct snd_ctl_elem_id) -#define SNDRV_CTL_IOCTL_ELEM_UNLOCK _IOW('U', 0x15, struct snd_ctl_elem_id) -#define SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS _IOWR('U', 0x16, int) -#define SNDRV_CTL_IOCTL_ELEM_ADD _IOWR('U', 0x17, struct snd_ctl_elem_info) -#define SNDRV_CTL_IOCTL_ELEM_REPLACE _IOWR('U', 0x18, struct snd_ctl_elem_info) -#define SNDRV_CTL_IOCTL_ELEM_REMOVE _IOWR('U', 0x19, struct snd_ctl_elem_id) -#define SNDRV_CTL_IOCTL_TLV_READ _IOWR('U', 0x1a, struct snd_ctl_tlv) -#define SNDRV_CTL_IOCTL_TLV_WRITE _IOWR('U', 0x1b, struct snd_ctl_tlv) -#define SNDRV_CTL_IOCTL_TLV_COMMAND _IOWR('U', 0x1c, struct snd_ctl_tlv) -#define SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE _IOWR('U', 0x20, int) -#define SNDRV_CTL_IOCTL_HWDEP_INFO _IOR('U', 0x21, struct snd_hwdep_info) -#define SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE _IOR('U', 0x30, int) -#define SNDRV_CTL_IOCTL_PCM_INFO _IOWR('U', 0x31, struct snd_pcm_info) -#define SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE _IOW('U', 0x32, int) -#define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int) -#define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info) -#define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int) -#define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int) -#define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int) - -/* - * Read interface. - */ - -enum sndrv_ctl_event_type { - SNDRV_CTL_EVENT_ELEM = 0, - SNDRV_CTL_EVENT_LAST = SNDRV_CTL_EVENT_ELEM, -}; - -#define SNDRV_CTL_EVENT_MASK_VALUE (1<<0) /* element value was changed */ -#define SNDRV_CTL_EVENT_MASK_INFO (1<<1) /* element info was changed */ -#define SNDRV_CTL_EVENT_MASK_ADD (1<<2) /* element was added */ -#define SNDRV_CTL_EVENT_MASK_TLV (1<<3) /* element TLV tree was changed */ -#define SNDRV_CTL_EVENT_MASK_REMOVE (~0U) /* element was removed */ - -struct snd_ctl_event { - int type; /* event type - SNDRV_CTL_EVENT_* */ - union { - struct { - unsigned int mask; - struct snd_ctl_elem_id id; - } elem; - unsigned char data8[60]; - } data; -}; - -/* - * Control names - */ - -#define SNDRV_CTL_NAME_NONE "" -#define SNDRV_CTL_NAME_PLAYBACK "Playback " -#define SNDRV_CTL_NAME_CAPTURE "Capture " - -#define SNDRV_CTL_NAME_IEC958_NONE "" -#define SNDRV_CTL_NAME_IEC958_SWITCH "Switch" -#define SNDRV_CTL_NAME_IEC958_VOLUME "Volume" -#define SNDRV_CTL_NAME_IEC958_DEFAULT "Default" -#define SNDRV_CTL_NAME_IEC958_MASK "Mask" -#define SNDRV_CTL_NAME_IEC958_CON_MASK "Con Mask" -#define SNDRV_CTL_NAME_IEC958_PRO_MASK "Pro Mask" -#define SNDRV_CTL_NAME_IEC958_PCM_STREAM "PCM Stream" -#define SNDRV_CTL_NAME_IEC958(expl,direction,what) "IEC958 " expl SNDRV_CTL_NAME_##direction SNDRV_CTL_NAME_IEC958_##what - -#endif /* _UAPI__SOUND_ASOUND_H */ +#include diff --git a/include/sound/asound_fm.h b/include/sound/asound_fm.h index 8471f40..3e5da4d 100644 --- a/include/sound/asound_fm.h +++ b/include/sound/asound_fm.h @@ -1,135 +1 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -#ifndef __SOUND_ASOUND_FM_H -#define __SOUND_ASOUND_FM_H - -/* - * Advanced Linux Sound Architecture - ALSA - * - * Interface file between ALSA driver & user space - * Copyright (c) 1994-98 by Jaroslav Kysela , - * 4Front Technologies - * - * Direct FM control - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#define SNDRV_DM_FM_MODE_OPL2 0x00 -#define SNDRV_DM_FM_MODE_OPL3 0x01 - -struct snd_dm_fm_info { - unsigned char fm_mode; /* OPL mode, see SNDRV_DM_FM_MODE_XXX */ - unsigned char rhythm; /* percussion mode flag */ -}; - -/* - * Data structure composing an FM "note" or sound event. - */ - -struct snd_dm_fm_voice { - unsigned char op; /* operator cell (0 or 1) */ - unsigned char voice; /* FM voice (0 to 17) */ - - unsigned char am; /* amplitude modulation */ - unsigned char vibrato; /* vibrato effect */ - unsigned char do_sustain; /* sustain phase */ - unsigned char kbd_scale; /* keyboard scaling */ - unsigned char harmonic; /* 4 bits: harmonic and multiplier */ - unsigned char scale_level; /* 2 bits: decrease output freq rises */ - unsigned char volume; /* 6 bits: volume */ - - unsigned char attack; /* 4 bits: attack rate */ - unsigned char decay; /* 4 bits: decay rate */ - unsigned char sustain; /* 4 bits: sustain level */ - unsigned char release; /* 4 bits: release rate */ - - unsigned char feedback; /* 3 bits: feedback for op0 */ - unsigned char connection; /* 0 for serial, 1 for parallel */ - unsigned char left; /* stereo left */ - unsigned char right; /* stereo right */ - unsigned char waveform; /* 3 bits: waveform shape */ -}; - -/* - * This describes an FM note by its voice, octave, frequency number (10bit) - * and key on/off. - */ - -struct snd_dm_fm_note { - unsigned char voice; /* 0-17 voice channel */ - unsigned char octave; /* 3 bits: what octave to play */ - unsigned int fnum; /* 10 bits: frequency number */ - unsigned char key_on; /* set for active, clear for silent */ -}; - -/* - * FM parameters that apply globally to all voices, and thus are not "notes" - */ - -struct snd_dm_fm_params { - unsigned char am_depth; /* amplitude modulation depth (1=hi) */ - unsigned char vib_depth; /* vibrato depth (1=hi) */ - unsigned char kbd_split; /* keyboard split */ - unsigned char rhythm; /* percussion mode select */ - - /* This block is the percussion instrument data */ - unsigned char bass; - unsigned char snare; - unsigned char tomtom; - unsigned char cymbal; - unsigned char hihat; -}; - -/* - * FM mode ioctl settings - */ - -#define SNDRV_DM_FM_IOCTL_INFO _IOR('H', 0x20, struct snd_dm_fm_info) -#define SNDRV_DM_FM_IOCTL_RESET _IO ('H', 0x21) -#define SNDRV_DM_FM_IOCTL_PLAY_NOTE _IOW('H', 0x22, struct snd_dm_fm_note) -#define SNDRV_DM_FM_IOCTL_SET_VOICE _IOW('H', 0x23, struct snd_dm_fm_voice) -#define SNDRV_DM_FM_IOCTL_SET_PARAMS _IOW('H', 0x24, struct snd_dm_fm_params) -#define SNDRV_DM_FM_IOCTL_SET_MODE _IOW('H', 0x25, int) -/* for OPL3 only */ -#define SNDRV_DM_FM_IOCTL_SET_CONNECTION _IOW('H', 0x26, int) -/* SBI patch management */ -#define SNDRV_DM_FM_IOCTL_CLEAR_PATCHES _IO ('H', 0x40) - -#define SNDRV_DM_FM_OSS_IOCTL_RESET 0x20 -#define SNDRV_DM_FM_OSS_IOCTL_PLAY_NOTE 0x21 -#define SNDRV_DM_FM_OSS_IOCTL_SET_VOICE 0x22 -#define SNDRV_DM_FM_OSS_IOCTL_SET_PARAMS 0x23 -#define SNDRV_DM_FM_OSS_IOCTL_SET_MODE 0x24 -#define SNDRV_DM_FM_OSS_IOCTL_SET_OPL 0x25 - -/* - * Patch Record - fixed size for write - */ - -#define FM_KEY_SBI "SBI\032" -#define FM_KEY_2OP "2OP\032" -#define FM_KEY_4OP "4OP\032" - -struct sbi_patch { - unsigned char prog; - unsigned char bank; - char key[4]; - char name[25]; - char extension[7]; - unsigned char data[32]; -}; - -#endif /* __SOUND_ASOUND_FM_H */ +#include diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h index 042c5a6..0832f95 100644 --- a/include/sound/emu10k1.h +++ b/include/sound/emu10k1.h @@ -1,381 +1,11 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* - * Copyright (c) by Jaroslav Kysela , - * Creative Labs, Inc. - * Definitions for EMU10K1 (SB Live!) chips - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#ifndef _UAPI__SOUND_EMU10K1_H -#define _UAPI__SOUND_EMU10K1_H - -#include -#include - -/* - * ---- FX8010 ---- - */ - -#define EMU10K1_CARD_CREATIVE 0x00000000 -#define EMU10K1_CARD_EMUAPS 0x00000001 - -#define EMU10K1_FX8010_PCM_COUNT 8 - -/* - * Following definition is copied from linux/types.h to support compiling - * this header file in userspace since they are not generally available for - * uapi headers. - */ -#define __EMU10K1_DECLARE_BITMAP(name,bits) \ - unsigned long name[(bits) / (sizeof(unsigned long) * 8)] - -/* instruction set */ -#define iMAC0 0x00 /* R = A + (X * Y >> 31) ; saturation */ -#define iMAC1 0x01 /* R = A + (-X * Y >> 31) ; saturation */ -#define iMAC2 0x02 /* R = A + (X * Y >> 31) ; wraparound */ -#define iMAC3 0x03 /* R = A + (-X * Y >> 31) ; wraparound */ -#define iMACINT0 0x04 /* R = A + X * Y ; saturation */ -#define iMACINT1 0x05 /* R = A + X * Y ; wraparound (31-bit) */ -#define iACC3 0x06 /* R = A + X + Y ; saturation */ -#define iMACMV 0x07 /* R = A, acc += X * Y >> 31 */ -#define iANDXOR 0x08 /* R = (A & X) ^ Y */ -#define iTSTNEG 0x09 /* R = (A >= Y) ? X : ~X */ -#define iLIMITGE 0x0a /* R = (A >= Y) ? X : Y */ -#define iLIMITLT 0x0b /* R = (A < Y) ? X : Y */ -#define iLOG 0x0c /* R = linear_data, A (log_data), X (max_exp), Y (format_word) */ -#define iEXP 0x0d /* R = log_data, A (linear_data), X (max_exp), Y (format_word) */ -#define iINTERP 0x0e /* R = A + (X * (Y - A) >> 31) ; saturation */ -#define iSKIP 0x0f /* R = A (cc_reg), X (count), Y (cc_test) */ - -/* GPRs */ -#define FXBUS(x) (0x00 + (x)) /* x = 0x00 - 0x0f */ -#define EXTIN(x) (0x10 + (x)) /* x = 0x00 - 0x0f */ -#define EXTOUT(x) (0x20 + (x)) /* x = 0x00 - 0x0f physical outs -> FXWC low 16 bits */ -#define FXBUS2(x) (0x30 + (x)) /* x = 0x00 - 0x0f copies of fx buses for capture -> FXWC high 16 bits */ - /* NB: 0x31 and 0x32 are shared with Center/LFE on SB live 5.1 */ - -#define C_00000000 0x40 -#define C_00000001 0x41 -#define C_00000002 0x42 -#define C_00000003 0x43 -#define C_00000004 0x44 -#define C_00000008 0x45 -#define C_00000010 0x46 -#define C_00000020 0x47 -#define C_00000100 0x48 -#define C_00010000 0x49 -#define C_00080000 0x4a -#define C_10000000 0x4b -#define C_20000000 0x4c -#define C_40000000 0x4d -#define C_80000000 0x4e -#define C_7fffffff 0x4f -#define C_ffffffff 0x50 -#define C_fffffffe 0x51 -#define C_c0000000 0x52 -#define C_4f1bbcdc 0x53 -#define C_5a7ef9db 0x54 -#define C_00100000 0x55 /* ?? */ -#define GPR_ACCU 0x56 /* ACCUM, accumulator */ -#define GPR_COND 0x57 /* CCR, condition register */ -#define GPR_NOISE0 0x58 /* noise source */ -#define GPR_NOISE1 0x59 /* noise source */ -#define GPR_IRQ 0x5a /* IRQ register */ -#define GPR_DBAC 0x5b /* TRAM Delay Base Address Counter */ -#define GPR(x) (FXGPREGBASE + (x)) /* free GPRs: x = 0x00 - 0xff */ -#define ITRAM_DATA(x) (TANKMEMDATAREGBASE + 0x00 + (x)) /* x = 0x00 - 0x7f */ -#define ETRAM_DATA(x) (TANKMEMDATAREGBASE + 0x80 + (x)) /* x = 0x00 - 0x1f */ -#define ITRAM_ADDR(x) (TANKMEMADDRREGBASE + 0x00 + (x)) /* x = 0x00 - 0x7f */ -#define ETRAM_ADDR(x) (TANKMEMADDRREGBASE + 0x80 + (x)) /* x = 0x00 - 0x1f */ - -#define A_ITRAM_DATA(x) (TANKMEMDATAREGBASE + 0x00 + (x)) /* x = 0x00 - 0xbf */ -#define A_ETRAM_DATA(x) (TANKMEMDATAREGBASE + 0xc0 + (x)) /* x = 0x00 - 0x3f */ -#define A_ITRAM_ADDR(x) (TANKMEMADDRREGBASE + 0x00 + (x)) /* x = 0x00 - 0xbf */ -#define A_ETRAM_ADDR(x) (TANKMEMADDRREGBASE + 0xc0 + (x)) /* x = 0x00 - 0x3f */ -#define A_ITRAM_CTL(x) (A_TANKMEMCTLREGBASE + 0x00 + (x)) /* x = 0x00 - 0xbf */ -#define A_ETRAM_CTL(x) (A_TANKMEMCTLREGBASE + 0xc0 + (x)) /* x = 0x00 - 0x3f */ - -#define A_FXBUS(x) (0x00 + (x)) /* x = 0x00 - 0x3f FX buses */ -#define A_EXTIN(x) (0x40 + (x)) /* x = 0x00 - 0x0f physical ins */ -#define A_P16VIN(x) (0x50 + (x)) /* x = 0x00 - 0x0f p16v ins (A2 only) "EMU32 inputs" */ -#define A_EXTOUT(x) (0x60 + (x)) /* x = 0x00 - 0x1f physical outs -> A_FXWC1 0x79-7f unknown */ -#define A_FXBUS2(x) (0x80 + (x)) /* x = 0x00 - 0x1f extra outs used for EFX capture -> A_FXWC2 */ -#define A_EMU32OUTH(x) (0xa0 + (x)) /* x = 0x00 - 0x0f "EMU32_OUT_10 - _1F" - ??? */ -#define A_EMU32OUTL(x) (0xb0 + (x)) /* x = 0x00 - 0x0f "EMU32_OUT_1 - _F" - ??? */ -#define A3_EMU32IN(x) (0x160 + (x)) /* x = 0x00 - 0x3f "EMU32_IN_00 - _3F" - Only when .device = 0x0008 */ -#define A3_EMU32OUT(x) (0x1E0 + (x)) /* x = 0x00 - 0x0f "EMU32_OUT_00 - _3F" - Only when .device = 0x0008 */ -#define A_GPR(x) (A_FXGPREGBASE + (x)) - -/* cc_reg constants */ -#define CC_REG_NORMALIZED C_00000001 -#define CC_REG_BORROW C_00000002 -#define CC_REG_MINUS C_00000004 -#define CC_REG_ZERO C_00000008 -#define CC_REG_SATURATE C_00000010 -#define CC_REG_NONZERO C_00000100 - -/* FX buses */ -#define FXBUS_PCM_LEFT 0x00 -#define FXBUS_PCM_RIGHT 0x01 -#define FXBUS_PCM_LEFT_REAR 0x02 -#define FXBUS_PCM_RIGHT_REAR 0x03 -#define FXBUS_MIDI_LEFT 0x04 -#define FXBUS_MIDI_RIGHT 0x05 -#define FXBUS_PCM_CENTER 0x06 -#define FXBUS_PCM_LFE 0x07 -#define FXBUS_PCM_LEFT_FRONT 0x08 -#define FXBUS_PCM_RIGHT_FRONT 0x09 -#define FXBUS_MIDI_REVERB 0x0c -#define FXBUS_MIDI_CHORUS 0x0d -#define FXBUS_PCM_LEFT_SIDE 0x0e -#define FXBUS_PCM_RIGHT_SIDE 0x0f -#define FXBUS_PT_LEFT 0x14 -#define FXBUS_PT_RIGHT 0x15 - -/* Inputs */ -#define EXTIN_AC97_L 0x00 /* AC'97 capture channel - left */ -#define EXTIN_AC97_R 0x01 /* AC'97 capture channel - right */ -#define EXTIN_SPDIF_CD_L 0x02 /* internal S/PDIF CD - onboard - left */ -#define EXTIN_SPDIF_CD_R 0x03 /* internal S/PDIF CD - onboard - right */ -#define EXTIN_ZOOM_L 0x04 /* Zoom Video I2S - left */ -#define EXTIN_ZOOM_R 0x05 /* Zoom Video I2S - right */ -#define EXTIN_TOSLINK_L 0x06 /* LiveDrive - TOSLink Optical - left */ -#define EXTIN_TOSLINK_R 0x07 /* LiveDrive - TOSLink Optical - right */ -#define EXTIN_LINE1_L 0x08 /* LiveDrive - Line/Mic 1 - left */ -#define EXTIN_LINE1_R 0x09 /* LiveDrive - Line/Mic 1 - right */ -#define EXTIN_COAX_SPDIF_L 0x0a /* LiveDrive - Coaxial S/PDIF - left */ -#define EXTIN_COAX_SPDIF_R 0x0b /* LiveDrive - Coaxial S/PDIF - right */ -#define EXTIN_LINE2_L 0x0c /* LiveDrive - Line/Mic 2 - left */ -#define EXTIN_LINE2_R 0x0d /* LiveDrive - Line/Mic 2 - right */ - -/* Outputs */ -#define EXTOUT_AC97_L 0x00 /* AC'97 playback channel - left */ -#define EXTOUT_AC97_R 0x01 /* AC'97 playback channel - right */ -#define EXTOUT_TOSLINK_L 0x02 /* LiveDrive - TOSLink Optical - left */ -#define EXTOUT_TOSLINK_R 0x03 /* LiveDrive - TOSLink Optical - right */ -#define EXTOUT_AC97_CENTER 0x04 /* SB Live 5.1 - center */ -#define EXTOUT_AC97_LFE 0x05 /* SB Live 5.1 - LFE */ -#define EXTOUT_HEADPHONE_L 0x06 /* LiveDrive - Headphone - left */ -#define EXTOUT_HEADPHONE_R 0x07 /* LiveDrive - Headphone - right */ -#define EXTOUT_REAR_L 0x08 /* Rear channel - left */ -#define EXTOUT_REAR_R 0x09 /* Rear channel - right */ -#define EXTOUT_ADC_CAP_L 0x0a /* ADC Capture buffer - left */ -#define EXTOUT_ADC_CAP_R 0x0b /* ADC Capture buffer - right */ -#define EXTOUT_MIC_CAP 0x0c /* MIC Capture buffer */ -#define EXTOUT_AC97_REAR_L 0x0d /* SB Live 5.1 (c) 2003 - Rear Left */ -#define EXTOUT_AC97_REAR_R 0x0e /* SB Live 5.1 (c) 2003 - Rear Right */ -#define EXTOUT_ACENTER 0x11 /* Analog Center */ -#define EXTOUT_ALFE 0x12 /* Analog LFE */ - -/* Audigy Inputs */ -#define A_EXTIN_AC97_L 0x00 /* AC'97 capture channel - left */ -#define A_EXTIN_AC97_R 0x01 /* AC'97 capture channel - right */ -#define A_EXTIN_SPDIF_CD_L 0x02 /* digital CD left */ -#define A_EXTIN_SPDIF_CD_R 0x03 /* digital CD left */ -#define A_EXTIN_OPT_SPDIF_L 0x04 /* audigy drive Optical SPDIF - left */ -#define A_EXTIN_OPT_SPDIF_R 0x05 /* right */ -#define A_EXTIN_LINE2_L 0x08 /* audigy drive line2/mic2 - left */ -#define A_EXTIN_LINE2_R 0x09 /* right */ -#define A_EXTIN_ADC_L 0x0a /* Philips ADC - left */ -#define A_EXTIN_ADC_R 0x0b /* right */ -#define A_EXTIN_AUX2_L 0x0c /* audigy drive aux2 - left */ -#define A_EXTIN_AUX2_R 0x0d /* - right */ - -/* Audigiy Outputs */ -#define A_EXTOUT_FRONT_L 0x00 /* digital front left */ -#define A_EXTOUT_FRONT_R 0x01 /* right */ -#define A_EXTOUT_CENTER 0x02 /* digital front center */ -#define A_EXTOUT_LFE 0x03 /* digital front lfe */ -#define A_EXTOUT_HEADPHONE_L 0x04 /* headphone audigy drive left */ -#define A_EXTOUT_HEADPHONE_R 0x05 /* right */ -#define A_EXTOUT_REAR_L 0x06 /* digital rear left */ -#define A_EXTOUT_REAR_R 0x07 /* right */ -#define A_EXTOUT_AFRONT_L 0x08 /* analog front left */ -#define A_EXTOUT_AFRONT_R 0x09 /* right */ -#define A_EXTOUT_ACENTER 0x0a /* analog center */ -#define A_EXTOUT_ALFE 0x0b /* analog LFE */ -#define A_EXTOUT_ASIDE_L 0x0c /* analog side left - Audigy 2 ZS */ -#define A_EXTOUT_ASIDE_R 0x0d /* right - Audigy 2 ZS */ -#define A_EXTOUT_AREAR_L 0x0e /* analog rear left */ -#define A_EXTOUT_AREAR_R 0x0f /* right */ -#define A_EXTOUT_AC97_L 0x10 /* AC97 left (front) */ -#define A_EXTOUT_AC97_R 0x11 /* right */ -#define A_EXTOUT_ADC_CAP_L 0x16 /* ADC capture buffer left */ -#define A_EXTOUT_ADC_CAP_R 0x17 /* right */ -#define A_EXTOUT_MIC_CAP 0x18 /* Mic capture buffer */ - -/* Audigy constants */ -#define A_C_00000000 0xc0 -#define A_C_00000001 0xc1 -#define A_C_00000002 0xc2 -#define A_C_00000003 0xc3 -#define A_C_00000004 0xc4 -#define A_C_00000008 0xc5 -#define A_C_00000010 0xc6 -#define A_C_00000020 0xc7 -#define A_C_00000100 0xc8 -#define A_C_00010000 0xc9 -#define A_C_00000800 0xca -#define A_C_10000000 0xcb -#define A_C_20000000 0xcc -#define A_C_40000000 0xcd -#define A_C_80000000 0xce -#define A_C_7fffffff 0xcf -#define A_C_ffffffff 0xd0 -#define A_C_fffffffe 0xd1 -#define A_C_c0000000 0xd2 -#define A_C_4f1bbcdc 0xd3 -#define A_C_5a7ef9db 0xd4 -#define A_C_00100000 0xd5 -#define A_GPR_ACCU 0xd6 /* ACCUM, accumulator */ -#define A_GPR_COND 0xd7 /* CCR, condition register */ -#define A_GPR_NOISE0 0xd8 /* noise source */ -#define A_GPR_NOISE1 0xd9 /* noise source */ -#define A_GPR_IRQ 0xda /* IRQ register */ -#define A_GPR_DBAC 0xdb /* TRAM Delay Base Address Counter - internal */ -#define A_GPR_DBACE 0xde /* TRAM Delay Base Address Counter - external */ - -/* definitions for debug register */ -#define EMU10K1_DBG_ZC 0x80000000 /* zero tram counter */ -#define EMU10K1_DBG_SATURATION_OCCURED 0x02000000 /* saturation control */ -#define EMU10K1_DBG_SATURATION_ADDR 0x01ff0000 /* saturation address */ -#define EMU10K1_DBG_SINGLE_STEP 0x00008000 /* single step mode */ -#define EMU10K1_DBG_STEP 0x00004000 /* start single step */ -#define EMU10K1_DBG_CONDITION_CODE 0x00003e00 /* condition code */ -#define EMU10K1_DBG_SINGLE_STEP_ADDR 0x000001ff /* single step address */ - -/* tank memory address line */ -#ifndef __KERNEL__ -#define TANKMEMADDRREG_ADDR_MASK 0x000fffff /* 20 bit tank address field */ -#define TANKMEMADDRREG_CLEAR 0x00800000 /* Clear tank memory */ -#define TANKMEMADDRREG_ALIGN 0x00400000 /* Align read or write relative to tank access */ -#define TANKMEMADDRREG_WRITE 0x00200000 /* Write to tank memory */ -#define TANKMEMADDRREG_READ 0x00100000 /* Read from tank memory */ -#endif - -struct snd_emu10k1_fx8010_info { - unsigned int internal_tram_size; /* in samples */ - unsigned int external_tram_size; /* in samples */ - char fxbus_names[16][32]; /* names of FXBUSes */ - char extin_names[16][32]; /* names of external inputs */ - char extout_names[32][32]; /* names of external outputs */ - unsigned int gpr_controls; /* count of GPR controls */ -}; - -#define EMU10K1_GPR_TRANSLATION_NONE 0 -#define EMU10K1_GPR_TRANSLATION_TABLE100 1 -#define EMU10K1_GPR_TRANSLATION_BASS 2 -#define EMU10K1_GPR_TRANSLATION_TREBLE 3 -#define EMU10K1_GPR_TRANSLATION_ONOFF 4 - -struct snd_emu10k1_fx8010_control_gpr { - struct snd_ctl_elem_id id; /* full control ID definition */ - unsigned int vcount; /* visible count */ - unsigned int count; /* count of GPR (1..16) */ - unsigned short gpr[32]; /* GPR number(s) */ - unsigned int value[32]; /* initial values */ - unsigned int min; /* minimum range */ - unsigned int max; /* maximum range */ - unsigned int translation; /* translation type (EMU10K1_GPR_TRANSLATION*) */ - const unsigned int *tlv; -}; - -/* old ABI without TLV support */ -struct snd_emu10k1_fx8010_control_old_gpr { - struct snd_ctl_elem_id id; - unsigned int vcount; - unsigned int count; - unsigned short gpr[32]; - unsigned int value[32]; - unsigned int min; - unsigned int max; - unsigned int translation; -}; - -struct snd_emu10k1_fx8010_code { - char name[128]; - - __EMU10K1_DECLARE_BITMAP(gpr_valid, 0x200); /* bitmask of valid initializers */ - __u32 __user *gpr_map; /* initializers */ - - unsigned int gpr_add_control_count; /* count of GPR controls to add/replace */ - struct snd_emu10k1_fx8010_control_gpr __user *gpr_add_controls; /* GPR controls to add/replace */ - - unsigned int gpr_del_control_count; /* count of GPR controls to remove */ - struct snd_ctl_elem_id __user *gpr_del_controls; /* IDs of GPR controls to remove */ - - unsigned int gpr_list_control_count; /* count of GPR controls to list */ - unsigned int gpr_list_control_total; /* total count of GPR controls */ - struct snd_emu10k1_fx8010_control_gpr __user *gpr_list_controls; /* listed GPR controls */ - - __EMU10K1_DECLARE_BITMAP(tram_valid, 0x100); /* bitmask of valid initializers */ - __u32 __user *tram_data_map; /* data initializers */ - __u32 __user *tram_addr_map; /* map initializers */ - - __EMU10K1_DECLARE_BITMAP(code_valid, 1024); /* bitmask of valid instructions */ - __u32 __user *code; /* one instruction - 64 bits */ -}; - -struct snd_emu10k1_fx8010_tram { - unsigned int address; /* 31.bit == 1 -> external TRAM */ - unsigned int size; /* size in samples (4 bytes) */ - unsigned int *samples; /* pointer to samples (20-bit) */ - /* NULL->clear memory */ -}; - -struct snd_emu10k1_fx8010_pcm_rec { - unsigned int substream; /* substream number */ - unsigned int res1; /* reserved */ - unsigned int channels; /* 16-bit channels count, zero = remove this substream */ - unsigned int tram_start; /* ring buffer position in TRAM (in samples) */ - unsigned int buffer_size; /* count of buffered samples */ - unsigned short gpr_size; /* GPR containing size of ringbuffer in samples (host) */ - unsigned short gpr_ptr; /* GPR containing current pointer in the ring buffer (host = reset, FX8010) */ - unsigned short gpr_count; /* GPR containing count of samples between two interrupts (host) */ - unsigned short gpr_tmpcount; /* GPR containing current count of samples to interrupt (host = set, FX8010) */ - unsigned short gpr_trigger; /* GPR containing trigger (activate) information (host) */ - unsigned short gpr_running; /* GPR containing info if PCM is running (FX8010) */ - unsigned char pad; /* reserved */ - unsigned char etram[32]; /* external TRAM address & data (one per channel) */ - unsigned int res2; /* reserved */ -}; - -#define SNDRV_EMU10K1_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 1) - -#define SNDRV_EMU10K1_IOCTL_INFO _IOR ('H', 0x10, struct snd_emu10k1_fx8010_info) -#define SNDRV_EMU10K1_IOCTL_CODE_POKE _IOW ('H', 0x11, struct snd_emu10k1_fx8010_code) -#define SNDRV_EMU10K1_IOCTL_CODE_PEEK _IOWR('H', 0x12, struct snd_emu10k1_fx8010_code) -#define SNDRV_EMU10K1_IOCTL_TRAM_SETUP _IOW ('H', 0x20, int) -#define SNDRV_EMU10K1_IOCTL_TRAM_POKE _IOW ('H', 0x21, struct snd_emu10k1_fx8010_tram) -#define SNDRV_EMU10K1_IOCTL_TRAM_PEEK _IOWR('H', 0x22, struct snd_emu10k1_fx8010_tram) -#define SNDRV_EMU10K1_IOCTL_PCM_POKE _IOW ('H', 0x30, struct snd_emu10k1_fx8010_pcm_rec) -#define SNDRV_EMU10K1_IOCTL_PCM_PEEK _IOWR('H', 0x31, struct snd_emu10k1_fx8010_pcm_rec) -#define SNDRV_EMU10K1_IOCTL_PVERSION _IOR ('H', 0x40, int) -#define SNDRV_EMU10K1_IOCTL_STOP _IO ('H', 0x80) -#define SNDRV_EMU10K1_IOCTL_CONTINUE _IO ('H', 0x81) -#define SNDRV_EMU10K1_IOCTL_ZERO_TRAM_COUNTER _IO ('H', 0x82) -#define SNDRV_EMU10K1_IOCTL_SINGLE_STEP _IOW ('H', 0x83, int) -#define SNDRV_EMU10K1_IOCTL_DBG_READ _IOR ('H', 0x84, int) - -/* typedefs for compatibility to user-space */ +#include +#include +#ifndef __emu10k1_type_defined +#define __emu10k1_type_defined typedef struct snd_emu10k1_fx8010_info emu10k1_fx8010_info_t; typedef struct snd_emu10k1_fx8010_control_gpr emu10k1_fx8010_control_gpr_t; typedef struct snd_emu10k1_fx8010_code emu10k1_fx8010_code_t; typedef struct snd_emu10k1_fx8010_tram emu10k1_fx8010_tram_t; typedef struct snd_emu10k1_fx8010_pcm_rec emu10k1_fx8010_pcm_t; - -#endif /* _UAPI__SOUND_EMU10K1_H */ +typedef struct emu10k1_ctl_elem_id emu10k1_ctl_elem_id_t; +#endif diff --git a/include/sound/hdsp.h b/include/sound/hdsp.h index 5dc0c3d..e8f9315 100644 --- a/include/sound/hdsp.h +++ b/include/sound/hdsp.h @@ -1,105 +1,7 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -#ifndef __SOUND_HDSP_H -#define __SOUND_HDSP_H - -/* - * Copyright (C) 2003 Thomas Charbonnel (thomas@undata.org) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#define HDSP_MATRIX_MIXER_SIZE 2048 - -enum HDSP_IO_Type { - Digiface, - Multiface, - H9652, - H9632, - RPM, - Undefined, -}; - -struct hdsp_peak_rms { - __u32 input_peaks[26]; - __u32 playback_peaks[26]; - __u32 output_peaks[28]; - __u64 input_rms[26]; - __u64 playback_rms[26]; - /* These are only used for H96xx cards */ - __u64 output_rms[26]; -}; - -#define SNDRV_HDSP_IOCTL_GET_PEAK_RMS _IOR('H', 0x40, struct hdsp_peak_rms) - -struct hdsp_config_info { - unsigned char pref_sync_ref; - unsigned char wordclock_sync_check; - unsigned char spdif_sync_check; - unsigned char adatsync_sync_check; - unsigned char adat_sync_check[3]; - unsigned char spdif_in; - unsigned char spdif_out; - unsigned char spdif_professional; - unsigned char spdif_emphasis; - unsigned char spdif_nonaudio; - unsigned int spdif_sample_rate; - unsigned int system_sample_rate; - unsigned int autosync_sample_rate; - unsigned char system_clock_mode; - unsigned char clock_source; - unsigned char autosync_ref; - unsigned char line_out; - unsigned char passthru; - unsigned char da_gain; - unsigned char ad_gain; - unsigned char phone_gain; - unsigned char xlr_breakout_cable; - unsigned char analog_extension_board; -}; - -#define SNDRV_HDSP_IOCTL_GET_CONFIG_INFO _IOR('H', 0x41, struct hdsp_config_info) - -struct hdsp_firmware { - void __user *firmware_data; /* 24413 x 4 bytes */ -}; - -#define SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE _IOW('H', 0x42, struct hdsp_firmware) - -struct hdsp_version { - enum HDSP_IO_Type io_type; - unsigned short firmware_rev; -}; - -#define SNDRV_HDSP_IOCTL_GET_VERSION _IOR('H', 0x43, struct hdsp_version) - -struct hdsp_mixer { - unsigned short matrix[HDSP_MATRIX_MIXER_SIZE]; -}; - -#define SNDRV_HDSP_IOCTL_GET_MIXER _IOR('H', 0x44, struct hdsp_mixer) - -struct hdsp_9632_aeb { - int aebi; - int aebo; -}; - -#define SNDRV_HDSP_IOCTL_GET_9632_AEB _IOR('H', 0x45, struct hdsp_9632_aeb) - -/* typedefs for compatibility to user-space */ +#include +#include +#ifndef __hdsp_type_defined +#define __hdsp_type_defined typedef enum HDSP_IO_Type HDSP_IO_Type; typedef struct hdsp_peak_rms hdsp_peak_rms_t; typedef struct hdsp_config_info hdsp_config_info_t; @@ -107,5 +9,4 @@ typedef struct hdsp_firmware hdsp_firmware_t; typedef struct hdsp_version hdsp_version_t; typedef struct hdsp_mixer hdsp_mixer_t; typedef struct hdsp_9632_aeb hdsp_9632_aeb_t; - -#endif /* __SOUND_HDSP_H */ +#endif diff --git a/include/sound/hdspm.h b/include/sound/hdspm.h index a38f3f7..d9095d9 100644 --- a/include/sound/hdspm.h +++ b/include/sound/hdspm.h @@ -1,232 +1,10 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -#ifndef __SOUND_HDSPM_H -#define __SOUND_HDSPM_H -/* - * Copyright (C) 2003 Winfried Ritsch (IEM) - * based on hdsp.h from Thomas Charbonnel (thomas@undata.org) - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -/* Maximum channels is 64 even on 56Mode you have 64playbacks to matrix */ -#define HDSPM_MAX_CHANNELS 64 - -enum hdspm_io_type { - MADI, - MADIface, - AIO, - AES32, - RayDAT -}; - -enum hdspm_speed { - ss, - ds, - qs -}; - -/* -------------------- IOCTL Peak/RMS Meters -------------------- */ - -struct hdspm_peak_rms { - __u32 input_peaks[64]; - __u32 playback_peaks[64]; - __u32 output_peaks[64]; - - __u64 input_rms[64]; - __u64 playback_rms[64]; - __u64 output_rms[64]; - - __u8 speed; /* enum {ss, ds, qs} */ - int status2; -}; - -#define SNDRV_HDSPM_IOCTL_GET_PEAK_RMS \ - _IOR('H', 0x42, struct hdspm_peak_rms) - -/* ------------ CONFIG block IOCTL ---------------------- */ - -struct hdspm_config { - unsigned char pref_sync_ref; - unsigned char wordclock_sync_check; - unsigned char madi_sync_check; - unsigned int system_sample_rate; - unsigned int autosync_sample_rate; - unsigned char system_clock_mode; - unsigned char clock_source; - unsigned char autosync_ref; - unsigned char line_out; - unsigned int passthru; - unsigned int analog_out; -}; - -#define SNDRV_HDSPM_IOCTL_GET_CONFIG \ - _IOR('H', 0x41, struct hdspm_config) - -/* - * If there's a TCO (TimeCode Option) board installed, - * there are further options and status data available. - * The hdspm_ltc structure contains the current SMPTE - * timecode and some status information and can be - * obtained via SNDRV_HDSPM_IOCTL_GET_LTC or in the - * hdspm_status struct. - */ - -enum hdspm_ltc_format { - format_invalid, - fps_24, - fps_25, - fps_2997, - fps_30 -}; - -enum hdspm_ltc_frame { - frame_invalid, - drop_frame, - full_frame -}; - -enum hdspm_ltc_input_format { - ntsc, - pal, - no_video -}; - -struct hdspm_ltc { - unsigned int ltc; - - enum hdspm_ltc_format format; - enum hdspm_ltc_frame frame; - enum hdspm_ltc_input_format input_format; -}; - -#define SNDRV_HDSPM_IOCTL_GET_LTC _IOR('H', 0x46, struct hdspm_ltc) - -/* - * The status data reflects the device's current state - * as determined by the card's configuration and - * connection status. - */ - -enum hdspm_sync { - hdspm_sync_no_lock = 0, - hdspm_sync_lock = 1, - hdspm_sync_sync = 2 -}; - -enum hdspm_madi_input { - hdspm_input_optical = 0, - hdspm_input_coax = 1 -}; - -enum hdspm_madi_channel_format { - hdspm_format_ch_64 = 0, - hdspm_format_ch_56 = 1 -}; - -enum hdspm_madi_frame_format { - hdspm_frame_48 = 0, - hdspm_frame_96 = 1 -}; - -enum hdspm_syncsource { - syncsource_wc = 0, - syncsource_madi = 1, - syncsource_tco = 2, - syncsource_sync = 3, - syncsource_none = 4 -}; - -struct hdspm_status { - __u8 card_type; /* enum hdspm_io_type */ - enum hdspm_syncsource autosync_source; - - __u64 card_clock; - __u32 master_period; - - union { - struct { - __u8 sync_wc; /* enum hdspm_sync */ - __u8 sync_madi; /* enum hdspm_sync */ - __u8 sync_tco; /* enum hdspm_sync */ - __u8 sync_in; /* enum hdspm_sync */ - __u8 madi_input; /* enum hdspm_madi_input */ - __u8 channel_format; /* enum hdspm_madi_channel_format */ - __u8 frame_format; /* enum hdspm_madi_frame_format */ - } madi; - } card_specific; -}; - -#define SNDRV_HDSPM_IOCTL_GET_STATUS \ - _IOR('H', 0x47, struct hdspm_status) - -/* - * Get information about the card and its add-ons. - */ - -#define HDSPM_ADDON_TCO 1 - -struct hdspm_version { - __u8 card_type; /* enum hdspm_io_type */ - char cardname[20]; - unsigned int serial; - unsigned short firmware_rev; - int addons; -}; - -#define SNDRV_HDSPM_IOCTL_GET_VERSION _IOR('H', 0x48, struct hdspm_version) - -/* ------------- get Matrix Mixer IOCTL --------------- */ - -/* MADI mixer: 64inputs+64playback in 64outputs = 8192 => *4Byte = - * 32768 Bytes - */ - -/* organisation is 64 channelfader in a continuous memory block */ -/* equivalent to hardware definition, maybe for future feature of mmap of - * them - */ -/* each of 64 outputs has 64 infader and 64 outfader: - Ins to Outs mixer[out].in[in], Outstreams to Outs mixer[out].pb[pb] */ - -#define HDSPM_MIXER_CHANNELS HDSPM_MAX_CHANNELS - -struct hdspm_channelfader { - unsigned int in[HDSPM_MIXER_CHANNELS]; - unsigned int pb[HDSPM_MIXER_CHANNELS]; -}; - -struct hdspm_mixer { - struct hdspm_channelfader ch[HDSPM_MIXER_CHANNELS]; -}; - -struct hdspm_mixer_ioctl { - struct hdspm_mixer *mixer; -}; - -/* use indirect access due to the limit of ioctl bit size */ -#define SNDRV_HDSPM_IOCTL_GET_MIXER _IOR('H', 0x44, struct hdspm_mixer_ioctl) - -/* typedefs for compatibility to user-space */ +#include +#include +#ifndef __hdspm_type_defined +#define __hdspm_type_defined typedef struct hdspm_peak_rms hdspm_peak_rms_t; typedef struct hdspm_config_info hdspm_config_info_t; typedef struct hdspm_version hdspm_version_t; typedef struct hdspm_channelfader snd_hdspm_channelfader_t; typedef struct hdspm_mixer hdspm_mixer_t; - - #endif diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h index e648514..fd02bc5 100644 --- a/include/sound/sb16_csp.h +++ b/include/sound/sb16_csp.h @@ -1,123 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* - * Copyright (c) 1999 by Uros Bizjak - * Takashi Iwai - * - * SB16ASP/AWE32 CSP control - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#ifndef _UAPI__SOUND_SB16_CSP_H -#define _UAPI__SOUND_SB16_CSP_H - - -/* CSP modes */ -#define SNDRV_SB_CSP_MODE_NONE 0x00 -#define SNDRV_SB_CSP_MODE_DSP_READ 0x01 /* Record from DSP */ -#define SNDRV_SB_CSP_MODE_DSP_WRITE 0x02 /* Play to DSP */ -#define SNDRV_SB_CSP_MODE_QSOUND 0x04 /* QSound */ - -/* CSP load flags */ -#define SNDRV_SB_CSP_LOAD_FROMUSER 0x01 -#define SNDRV_SB_CSP_LOAD_INITBLOCK 0x02 - -/* CSP sample width */ -#define SNDRV_SB_CSP_SAMPLE_8BIT 0x01 -#define SNDRV_SB_CSP_SAMPLE_16BIT 0x02 - -/* CSP channels */ -#define SNDRV_SB_CSP_MONO 0x01 -#define SNDRV_SB_CSP_STEREO 0x02 - -/* CSP rates */ -#define SNDRV_SB_CSP_RATE_8000 0x01 -#define SNDRV_SB_CSP_RATE_11025 0x02 -#define SNDRV_SB_CSP_RATE_22050 0x04 -#define SNDRV_SB_CSP_RATE_44100 0x08 -#define SNDRV_SB_CSP_RATE_ALL 0x0f - -/* CSP running state */ -#define SNDRV_SB_CSP_ST_IDLE 0x00 -#define SNDRV_SB_CSP_ST_LOADED 0x01 -#define SNDRV_SB_CSP_ST_RUNNING 0x02 -#define SNDRV_SB_CSP_ST_PAUSED 0x04 -#define SNDRV_SB_CSP_ST_AUTO 0x08 -#define SNDRV_SB_CSP_ST_QSOUND 0x10 - -/* maximum QSound value (180 degrees right) */ -#define SNDRV_SB_CSP_QSOUND_MAX_RIGHT 0x20 - -/* maximum microcode RIFF file size */ -#define SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE 0x3000 - -/* microcode header */ -struct snd_sb_csp_mc_header { - char codec_name[16]; /* id name of codec */ - unsigned short func_req; /* requested function */ -}; - -/* microcode to be loaded */ -struct snd_sb_csp_microcode { - struct snd_sb_csp_mc_header info; - unsigned char data[SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE]; -}; - -/* start CSP with sample_width in mono/stereo */ -struct snd_sb_csp_start { - int sample_width; /* sample width, look above */ - int channels; /* channels, look above */ -}; - -/* CSP information */ -struct snd_sb_csp_info { - char codec_name[16]; /* id name of codec */ - unsigned short func_nr; /* function number */ - unsigned int acc_format; /* accepted PCM formats */ - unsigned short acc_channels; /* accepted channels */ - unsigned short acc_width; /* accepted sample width */ - unsigned short acc_rates; /* accepted sample rates */ - unsigned short csp_mode; /* CSP mode, see above */ - unsigned short run_channels; /* current channels */ - unsigned short run_width; /* current sample width */ - unsigned short version; /* version id: 0x10 - 0x1f */ - unsigned short state; /* state bits */ -}; - -/* HWDEP controls */ -/* get CSP information */ -#define SNDRV_SB_CSP_IOCTL_INFO _IOR('H', 0x10, struct snd_sb_csp_info) -/* load microcode to CSP */ -/* NOTE: struct snd_sb_csp_microcode overflows the max size (13 bits) - * defined for some architectures like MIPS, and it leads to build errors. - * (x86 and co have 14-bit size, thus it's valid, though.) - * As a workaround for skipping the size-limit check, here we don't use the - * normal _IOW() macro but _IOC() with the manual argument. - */ -#define SNDRV_SB_CSP_IOCTL_LOAD_CODE \ - _IOC(_IOC_WRITE, 'H', 0x11, sizeof(struct snd_sb_csp_microcode)) -/* unload microcode from CSP */ -#define SNDRV_SB_CSP_IOCTL_UNLOAD_CODE _IO('H', 0x12) -/* start CSP */ -#define SNDRV_SB_CSP_IOCTL_START _IOW('H', 0x13, struct snd_sb_csp_start) -/* stop CSP */ -#define SNDRV_SB_CSP_IOCTL_STOP _IO('H', 0x14) -/* pause CSP and DMA transfer */ -#define SNDRV_SB_CSP_IOCTL_PAUSE _IO('H', 0x15) -/* restart CSP and DMA transfer */ -#define SNDRV_SB_CSP_IOCTL_RESTART _IO('H', 0x16) - - -#endif /* _UAPI__SOUND_SB16_CSP_H */ +#include +#ifndef __sb16_csp_type_defined +#define __sb16_csp_type_defined +typedef struct snd_sb_csp_microcode snd_sb_csp_microcode_t; +#endif diff --git a/include/sound/sscape_ioctl.h b/include/sound/sscape_ioctl.h index c6653eb..23b48d3 100644 --- a/include/sound/sscape_ioctl.h +++ b/include/sound/sscape_ioctl.h @@ -1,21 +1 @@ -#ifndef SSCAPE_IOCTL_H -#define SSCAPE_IOCTL_H - - -struct sscape_bootblock -{ - unsigned char code[256]; - unsigned version; -}; - -#define SSCAPE_MICROCODE_SIZE 65536 - -struct sscape_microcode -{ - unsigned char *code; -}; - -#define SND_SSCAPE_LOAD_BOOTB _IOWR('P', 100, struct sscape_bootblock) -#define SND_SSCAPE_LOAD_MCODE _IOW ('P', 101, struct sscape_microcode) - -#endif +#include diff --git a/include/sound/tlv.h b/include/sound/tlv.h index 7d6d65f..e435a5f 100644 --- a/include/sound/tlv.h +++ b/include/sound/tlv.h @@ -1,117 +1 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef __UAPI_SOUND_TLV_H -#define __UAPI_SOUND_TLV_H - -#define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */ -#define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */ -#define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */ -#define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */ -#define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */ -#define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */ - -/* - * channel-mapping TLV items - * TLV length must match with num_channels - */ -#define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */ -#define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */ -#define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */ - -/* - * TLV structure is right behind the struct snd_ctl_tlv: - * unsigned int type - see SNDRV_CTL_TLVT_* - * unsigned int length - * .... data aligned to sizeof(unsigned int), use - * block_length = (length + (sizeof(unsigned int) - 1)) & - * ~(sizeof(unsigned int) - 1)) .... - */ -#define SNDRV_CTL_TLVD_ITEM(type, ...) \ - (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__ -#define SNDRV_CTL_TLVD_LENGTH(...) \ - ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ })) - -/* Accessor offsets for TLV data items */ -#define SNDRV_CTL_TLVO_TYPE 0 -#define SNDRV_CTL_TLVO_LEN 1 - -#define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \ - SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__) -#define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \ - unsigned int name[] = { \ - SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \ - } - -#define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff -#define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000 -#define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \ - SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \ - (min), \ - ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \ - ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0)) -#define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \ - unsigned int name[] = { \ - SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \ - } - -/* Accessor offsets for min, mute and step items in dB scale type TLV */ -#define SNDRV_CTL_TLVO_DB_SCALE_MIN 2 -#define SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP 3 - -/* dB scale specified with min/max values instead of step */ -#define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \ - SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB)) -#define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ - SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB)) -#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \ - unsigned int name[] = { \ - SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \ - } -#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \ - unsigned int name[] = { \ - SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ - } - -/* Accessor offsets for min, max items in db-minmax types of TLV. */ -#define SNDRV_CTL_TLVO_DB_MINMAX_MIN 2 -#define SNDRV_CTL_TLVO_DB_MINMAX_MAX 3 - -/* linear volume between min_dB and max_dB (.01dB unit) */ -#define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \ - SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB)) -#define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \ - unsigned int name[] = { \ - SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \ - } - -/* Accessor offsets for min, max items in db-linear type of TLV. */ -#define SNDRV_CTL_TLVO_DB_LINEAR_MIN 2 -#define SNDRV_CTL_TLVO_DB_LINEAR_MAX 3 - -/* dB range container: - * Items in dB range container must be ordered by their values and by their - * dB values. This implies that larger values must correspond with larger - * dB values (which is also required for all other mixer controls). - */ -/* Each item is: */ -#define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \ - SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__) -#define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \ - unsigned int name[] = { \ - SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \ - } - -#define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999 - -#endif +#include diff --git a/include/sound/type_compat.h b/include/sound/type_compat.h index e973ff3..5b765f4 100644 --- a/include/sound/type_compat.h +++ b/include/sound/type_compat.h @@ -3,12 +3,17 @@ #ifndef DOC_HIDDEN #include +#ifdef __linux__ +#include +#else typedef uint8_t __u8; typedef uint16_t __u16; typedef uint32_t __u32; +typedef uint64_t __u64; typedef int8_t __s8; typedef int16_t __s16; typedef int32_t __s32; +typedef int64_t __s64; #include #include @@ -37,6 +42,16 @@ typedef int32_t __s32; #define __be32 __u32 #define __be16 __u16 #define __be8 __u8 +#endif + +#ifndef __user +#define __user +#endif + +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif + #endif /* DOC_HIDDEN */ #endif /* __TYPE_COMPAT_H */ diff --git a/include/sound/uapi/Makefile.am b/include/sound/uapi/Makefile.am new file mode 100644 index 0000000..9919710 --- /dev/null +++ b/include/sound/uapi/Makefile.am @@ -0,0 +1,6 @@ +alsasounduapiincludedir = ${includedir}/alsa/sound/uapi + +alsasounduapiinclude_HEADERS = asound_fm.h hdsp.h hdspm.h sb16_csp.h \ + sscape_ioctl.h emu10k1.h asoc.h tlv.h + +noinst_HEADERS = asound.h asequencer.h diff --git a/include/sound/uapi/Makefile.in b/include/sound/uapi/Makefile.in new file mode 100644 index 0000000..2c08f03 --- /dev/null +++ b/include/sound/uapi/Makefile.in @@ -0,0 +1,579 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = include/sound/uapi +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(alsasounduapiinclude_HEADERS) \ + $(noinst_HEADERS) $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(alsasounduapiincludedir)" +HEADERS = $(alsasounduapiinclude_HEADERS) $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALSA_CONFIG_DIR = @ALSA_CONFIG_DIR@ +ALSA_DEPLIBS = @ALSA_DEPLIBS@ +ALSA_PKGCONF_DIR = @ALSA_PKGCONF_DIR@ +ALSA_PLUGIN_DIR = @ALSA_PLUGIN_DIR@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LDFLAGS_NOUNDEFINED = @LDFLAGS_NOUNDEFINED@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_VERSION_INFO = @LIBTOOL_VERSION_INFO@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHON_INCLUDES = @PYTHON_INCLUDES@ +PYTHON_LIBS = @PYTHON_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SND_LIB_EXTRAVER = @SND_LIB_EXTRAVER@ +SND_LIB_MAJOR = @SND_LIB_MAJOR@ +SND_LIB_MINOR = @SND_LIB_MINOR@ +SND_LIB_SUBMINOR = @SND_LIB_SUBMINOR@ +SND_LIB_VERSION = @SND_LIB_VERSION@ +STRIP = @STRIP@ +SYMBOL_PREFIX = @SYMBOL_PREFIX@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +alsasounduapiincludedir = ${includedir}/alsa/sound/uapi +alsasounduapiinclude_HEADERS = asound_fm.h hdsp.h hdspm.h sb16_csp.h \ + sscape_ioctl.h emu10k1.h asoc.h tlv.h + +noinst_HEADERS = asound.h asequencer.h +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/sound/uapi/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign include/sound/uapi/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-alsasounduapiincludeHEADERS: $(alsasounduapiinclude_HEADERS) + @$(NORMAL_INSTALL) + @list='$(alsasounduapiinclude_HEADERS)'; test -n "$(alsasounduapiincludedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(alsasounduapiincludedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(alsasounduapiincludedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(alsasounduapiincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(alsasounduapiincludedir)" || exit $$?; \ + done + +uninstall-alsasounduapiincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(alsasounduapiinclude_HEADERS)'; test -n "$(alsasounduapiincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(alsasounduapiincludedir)'; $(am__uninstall_files_from_dir) + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(alsasounduapiincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-alsasounduapiincludeHEADERS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-alsasounduapiincludeHEADERS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-libtool cscopelist-am ctags ctags-am distclean \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install \ + install-alsasounduapiincludeHEADERS install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-alsasounduapiincludeHEADERS uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/include/sound/uapi/asequencer.h b/include/sound/uapi/asequencer.h new file mode 100644 index 0000000..2d60032 --- /dev/null +++ b/include/sound/uapi/asequencer.h @@ -0,0 +1,612 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Main header file for the ALSA sequencer + * Copyright (c) 1998-1999 by Frank van de Pol + * (c) 1998-1999 by Jaroslav Kysela + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef __SOUND_ASEQUENCER_H +#define __SOUND_ASEQUENCER_H + +#include + +/** version of the sequencer */ +#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 2) + +/** + * definition of sequencer event types + */ + +/** system messages + * event data type = #snd_seq_result + */ +#define SNDRV_SEQ_EVENT_SYSTEM 0 +#define SNDRV_SEQ_EVENT_RESULT 1 + +/** note messages (channel specific) + * event data type = #snd_seq_ev_note + */ +#define SNDRV_SEQ_EVENT_NOTE 5 +#define SNDRV_SEQ_EVENT_NOTEON 6 +#define SNDRV_SEQ_EVENT_NOTEOFF 7 +#define SNDRV_SEQ_EVENT_KEYPRESS 8 + +/** control messages (channel specific) + * event data type = #snd_seq_ev_ctrl + */ +#define SNDRV_SEQ_EVENT_CONTROLLER 10 +#define SNDRV_SEQ_EVENT_PGMCHANGE 11 +#define SNDRV_SEQ_EVENT_CHANPRESS 12 +#define SNDRV_SEQ_EVENT_PITCHBEND 13 /**< from -8192 to 8191 */ +#define SNDRV_SEQ_EVENT_CONTROL14 14 /**< 14 bit controller value */ +#define SNDRV_SEQ_EVENT_NONREGPARAM 15 /**< 14 bit NRPN address + 14 bit unsigned value */ +#define SNDRV_SEQ_EVENT_REGPARAM 16 /**< 14 bit RPN address + 14 bit unsigned value */ + +/** synchronisation messages + * event data type = #snd_seq_ev_ctrl + */ +#define SNDRV_SEQ_EVENT_SONGPOS 20 /* Song Position Pointer with LSB and MSB values */ +#define SNDRV_SEQ_EVENT_SONGSEL 21 /* Song Select with song ID number */ +#define SNDRV_SEQ_EVENT_QFRAME 22 /* midi time code quarter frame */ +#define SNDRV_SEQ_EVENT_TIMESIGN 23 /* SMF Time Signature event */ +#define SNDRV_SEQ_EVENT_KEYSIGN 24 /* SMF Key Signature event */ + +/** timer messages + * event data type = snd_seq_ev_queue_control + */ +#define SNDRV_SEQ_EVENT_START 30 /* midi Real Time Start message */ +#define SNDRV_SEQ_EVENT_CONTINUE 31 /* midi Real Time Continue message */ +#define SNDRV_SEQ_EVENT_STOP 32 /* midi Real Time Stop message */ +#define SNDRV_SEQ_EVENT_SETPOS_TICK 33 /* set tick queue position */ +#define SNDRV_SEQ_EVENT_SETPOS_TIME 34 /* set realtime queue position */ +#define SNDRV_SEQ_EVENT_TEMPO 35 /* (SMF) Tempo event */ +#define SNDRV_SEQ_EVENT_CLOCK 36 /* midi Real Time Clock message */ +#define SNDRV_SEQ_EVENT_TICK 37 /* midi Real Time Tick message */ +#define SNDRV_SEQ_EVENT_QUEUE_SKEW 38 /* skew queue tempo */ + +/** others + * event data type = none + */ +#define SNDRV_SEQ_EVENT_TUNE_REQUEST 40 /* tune request */ +#define SNDRV_SEQ_EVENT_RESET 41 /* reset to power-on state */ +#define SNDRV_SEQ_EVENT_SENSING 42 /* "active sensing" event */ + +/** echo back, kernel private messages + * event data type = any type + */ +#define SNDRV_SEQ_EVENT_ECHO 50 /* echo event */ +#define SNDRV_SEQ_EVENT_OSS 51 /* OSS raw event */ + +/** system status messages (broadcast for subscribers) + * event data type = snd_seq_addr + */ +#define SNDRV_SEQ_EVENT_CLIENT_START 60 /* new client has connected */ +#define SNDRV_SEQ_EVENT_CLIENT_EXIT 61 /* client has left the system */ +#define SNDRV_SEQ_EVENT_CLIENT_CHANGE 62 /* client status/info has changed */ +#define SNDRV_SEQ_EVENT_PORT_START 63 /* new port was created */ +#define SNDRV_SEQ_EVENT_PORT_EXIT 64 /* port was deleted from system */ +#define SNDRV_SEQ_EVENT_PORT_CHANGE 65 /* port status/info has changed */ + +/** port connection changes + * event data type = snd_seq_connect + */ +#define SNDRV_SEQ_EVENT_PORT_SUBSCRIBED 66 /* ports connected */ +#define SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED 67 /* ports disconnected */ + +/* 70-89: synthesizer events - obsoleted */ + +/** user-defined events with fixed length + * event data type = any + */ +#define SNDRV_SEQ_EVENT_USR0 90 +#define SNDRV_SEQ_EVENT_USR1 91 +#define SNDRV_SEQ_EVENT_USR2 92 +#define SNDRV_SEQ_EVENT_USR3 93 +#define SNDRV_SEQ_EVENT_USR4 94 +#define SNDRV_SEQ_EVENT_USR5 95 +#define SNDRV_SEQ_EVENT_USR6 96 +#define SNDRV_SEQ_EVENT_USR7 97 +#define SNDRV_SEQ_EVENT_USR8 98 +#define SNDRV_SEQ_EVENT_USR9 99 + +/* 100-118: instrument layer - obsoleted */ +/* 119-129: reserved */ + +/* 130-139: variable length events + * event data type = snd_seq_ev_ext + * (SNDRV_SEQ_EVENT_LENGTH_VARIABLE must be set) + */ +#define SNDRV_SEQ_EVENT_SYSEX 130 /* system exclusive data (variable length) */ +#define SNDRV_SEQ_EVENT_BOUNCE 131 /* error event */ +/* 132-134: reserved */ +#define SNDRV_SEQ_EVENT_USR_VAR0 135 +#define SNDRV_SEQ_EVENT_USR_VAR1 136 +#define SNDRV_SEQ_EVENT_USR_VAR2 137 +#define SNDRV_SEQ_EVENT_USR_VAR3 138 +#define SNDRV_SEQ_EVENT_USR_VAR4 139 + +/* 150-151: kernel events with quote - DO NOT use in user clients */ +#define SNDRV_SEQ_EVENT_KERNEL_ERROR 150 +#define SNDRV_SEQ_EVENT_KERNEL_QUOTE 151 /* obsolete */ + +/* 152-191: reserved */ + +/* 192-254: hardware specific events */ + +/* 255: special event */ +#define SNDRV_SEQ_EVENT_NONE 255 + + +typedef unsigned char snd_seq_event_type_t; + +/** event address */ +struct snd_seq_addr { + unsigned char client; /**< Client number: 0..255, 255 = broadcast to all clients */ + unsigned char port; /**< Port within client: 0..255, 255 = broadcast to all ports */ +}; + +/** port connection */ +struct snd_seq_connect { + struct snd_seq_addr sender; + struct snd_seq_addr dest; +}; + + +#define SNDRV_SEQ_ADDRESS_UNKNOWN 253 /* unknown source */ +#define SNDRV_SEQ_ADDRESS_SUBSCRIBERS 254 /* send event to all subscribed ports */ +#define SNDRV_SEQ_ADDRESS_BROADCAST 255 /* send event to all queues/clients/ports/channels */ +#define SNDRV_SEQ_QUEUE_DIRECT 253 /* direct dispatch */ + + /* event mode flag - NOTE: only 8 bits available! */ +#define SNDRV_SEQ_TIME_STAMP_TICK (0<<0) /* timestamp in clock ticks */ +#define SNDRV_SEQ_TIME_STAMP_REAL (1<<0) /* timestamp in real time */ +#define SNDRV_SEQ_TIME_STAMP_MASK (1<<0) + +#define SNDRV_SEQ_TIME_MODE_ABS (0<<1) /* absolute timestamp */ +#define SNDRV_SEQ_TIME_MODE_REL (1<<1) /* relative to current time */ +#define SNDRV_SEQ_TIME_MODE_MASK (1<<1) + +#define SNDRV_SEQ_EVENT_LENGTH_FIXED (0<<2) /* fixed event size */ +#define SNDRV_SEQ_EVENT_LENGTH_VARIABLE (1<<2) /* variable event size */ +#define SNDRV_SEQ_EVENT_LENGTH_VARUSR (2<<2) /* variable event size - user memory space */ +#define SNDRV_SEQ_EVENT_LENGTH_MASK (3<<2) + +#define SNDRV_SEQ_PRIORITY_NORMAL (0<<4) /* normal priority */ +#define SNDRV_SEQ_PRIORITY_HIGH (1<<4) /* event should be processed before others */ +#define SNDRV_SEQ_PRIORITY_MASK (1<<4) + + + /* note event */ +struct snd_seq_ev_note { + unsigned char channel; + unsigned char note; + unsigned char velocity; + unsigned char off_velocity; /* only for SNDRV_SEQ_EVENT_NOTE */ + unsigned int duration; /* only for SNDRV_SEQ_EVENT_NOTE */ +}; + + /* controller event */ +struct snd_seq_ev_ctrl { + unsigned char channel; + unsigned char unused1, unused2, unused3; /* pad */ + unsigned int param; + signed int value; +}; + + /* generic set of bytes (12x8 bit) */ +struct snd_seq_ev_raw8 { + unsigned char d[12]; /* 8 bit value */ +}; + + /* generic set of integers (3x32 bit) */ +struct snd_seq_ev_raw32 { + unsigned int d[3]; /* 32 bit value */ +}; + + /* external stored data */ +struct snd_seq_ev_ext { + unsigned int len; /* length of data */ + void *ptr; /* pointer to data (note: maybe 64-bit) */ +} __attribute__((packed)); + +struct snd_seq_result { + int event; /* processed event type */ + int result; +}; + + +struct snd_seq_real_time { + unsigned int tv_sec; /* seconds */ + unsigned int tv_nsec; /* nanoseconds */ +}; + +typedef unsigned int snd_seq_tick_time_t; /* midi ticks */ + +union snd_seq_timestamp { + snd_seq_tick_time_t tick; + struct snd_seq_real_time time; +}; + +struct snd_seq_queue_skew { + unsigned int value; + unsigned int base; +}; + + /* queue timer control */ +struct snd_seq_ev_queue_control { + unsigned char queue; /* affected queue */ + unsigned char pad[3]; /* reserved */ + union { + signed int value; /* affected value (e.g. tempo) */ + union snd_seq_timestamp time; /* time */ + unsigned int position; /* sync position */ + struct snd_seq_queue_skew skew; + unsigned int d32[2]; + unsigned char d8[8]; + } param; +}; + + /* quoted event - inside the kernel only */ +struct snd_seq_ev_quote { + struct snd_seq_addr origin; /* original sender */ + unsigned short value; /* optional data */ + struct snd_seq_event *event; /* quoted event */ +} __attribute__((packed)); + + + /* sequencer event */ +struct snd_seq_event { + snd_seq_event_type_t type; /* event type */ + unsigned char flags; /* event flags */ + char tag; + + unsigned char queue; /* schedule queue */ + union snd_seq_timestamp time; /* schedule time */ + + + struct snd_seq_addr source; /* source address */ + struct snd_seq_addr dest; /* destination address */ + + union { /* event data... */ + struct snd_seq_ev_note note; + struct snd_seq_ev_ctrl control; + struct snd_seq_ev_raw8 raw8; + struct snd_seq_ev_raw32 raw32; + struct snd_seq_ev_ext ext; + struct snd_seq_ev_queue_control queue; + union snd_seq_timestamp time; + struct snd_seq_addr addr; + struct snd_seq_connect connect; + struct snd_seq_result result; + struct snd_seq_ev_quote quote; + } data; +}; + + +/* + * bounce event - stored as variable size data + */ +struct snd_seq_event_bounce { + int err; + struct snd_seq_event event; + /* external data follows here. */ +}; + + + /* system information */ +struct snd_seq_system_info { + int queues; /* maximum queues count */ + int clients; /* maximum clients count */ + int ports; /* maximum ports per client */ + int channels; /* maximum channels per port */ + int cur_clients; /* current clients */ + int cur_queues; /* current queues */ + char reserved[24]; +}; + + + /* system running information */ +struct snd_seq_running_info { + unsigned char client; /* client id */ + unsigned char big_endian; /* 1 = big-endian */ + unsigned char cpu_mode; /* 4 = 32bit, 8 = 64bit */ + unsigned char pad; /* reserved */ + unsigned char reserved[12]; +}; + + + /* known client numbers */ +#define SNDRV_SEQ_CLIENT_SYSTEM 0 + /* internal client numbers */ +#define SNDRV_SEQ_CLIENT_DUMMY 14 /* midi through */ +#define SNDRV_SEQ_CLIENT_OSS 15 /* oss sequencer emulator */ + + + /* client types */ +typedef int __bitwise snd_seq_client_type_t; +#define NO_CLIENT ((snd_seq_client_type_t) 0) +#define USER_CLIENT ((snd_seq_client_type_t) 1) +#define KERNEL_CLIENT ((snd_seq_client_type_t) 2) + + /* event filter flags */ +#define SNDRV_SEQ_FILTER_BROADCAST (1<<0) /* accept broadcast messages */ +#define SNDRV_SEQ_FILTER_MULTICAST (1<<1) /* accept multicast messages */ +#define SNDRV_SEQ_FILTER_BOUNCE (1<<2) /* accept bounce event in error */ +#define SNDRV_SEQ_FILTER_USE_EVENT (1<<31) /* use event filter */ + +struct snd_seq_client_info { + int client; /* client number to inquire */ + snd_seq_client_type_t type; /* client type */ + char name[64]; /* client name */ + unsigned int filter; /* filter flags */ + unsigned char multicast_filter[8]; /* multicast filter bitmap */ + unsigned char event_filter[32]; /* event filter bitmap */ + int num_ports; /* RO: number of ports */ + int event_lost; /* number of lost events */ + int card; /* RO: card number[kernel] */ + int pid; /* RO: pid[user] */ + char reserved[56]; /* for future use */ +}; + + +/* client pool size */ +struct snd_seq_client_pool { + int client; /* client number to inquire */ + int output_pool; /* outgoing (write) pool size */ + int input_pool; /* incoming (read) pool size */ + int output_room; /* minimum free pool size for select/blocking mode */ + int output_free; /* unused size */ + int input_free; /* unused size */ + char reserved[64]; +}; + + +/* Remove events by specified criteria */ + +#define SNDRV_SEQ_REMOVE_INPUT (1<<0) /* Flush input queues */ +#define SNDRV_SEQ_REMOVE_OUTPUT (1<<1) /* Flush output queues */ +#define SNDRV_SEQ_REMOVE_DEST (1<<2) /* Restrict by destination q:client:port */ +#define SNDRV_SEQ_REMOVE_DEST_CHANNEL (1<<3) /* Restrict by channel */ +#define SNDRV_SEQ_REMOVE_TIME_BEFORE (1<<4) /* Restrict to before time */ +#define SNDRV_SEQ_REMOVE_TIME_AFTER (1<<5) /* Restrict to time or after */ +#define SNDRV_SEQ_REMOVE_TIME_TICK (1<<6) /* Time is in ticks */ +#define SNDRV_SEQ_REMOVE_EVENT_TYPE (1<<7) /* Restrict to event type */ +#define SNDRV_SEQ_REMOVE_IGNORE_OFF (1<<8) /* Do not flush off events */ +#define SNDRV_SEQ_REMOVE_TAG_MATCH (1<<9) /* Restrict to events with given tag */ + +struct snd_seq_remove_events { + unsigned int remove_mode; /* Flags that determine what gets removed */ + + union snd_seq_timestamp time; + + unsigned char queue; /* Queue for REMOVE_DEST */ + struct snd_seq_addr dest; /* Address for REMOVE_DEST */ + unsigned char channel; /* Channel for REMOVE_DEST */ + + int type; /* For REMOVE_EVENT_TYPE */ + char tag; /* Tag for REMOVE_TAG */ + + int reserved[10]; /* To allow for future binary compatibility */ + +}; + + + /* known port numbers */ +#define SNDRV_SEQ_PORT_SYSTEM_TIMER 0 +#define SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE 1 + + /* port capabilities (32 bits) */ +#define SNDRV_SEQ_PORT_CAP_READ (1<<0) /* readable from this port */ +#define SNDRV_SEQ_PORT_CAP_WRITE (1<<1) /* writable to this port */ + +#define SNDRV_SEQ_PORT_CAP_SYNC_READ (1<<2) +#define SNDRV_SEQ_PORT_CAP_SYNC_WRITE (1<<3) + +#define SNDRV_SEQ_PORT_CAP_DUPLEX (1<<4) + +#define SNDRV_SEQ_PORT_CAP_SUBS_READ (1<<5) /* allow read subscription */ +#define SNDRV_SEQ_PORT_CAP_SUBS_WRITE (1<<6) /* allow write subscription */ +#define SNDRV_SEQ_PORT_CAP_NO_EXPORT (1<<7) /* routing not allowed */ + + /* port type */ +#define SNDRV_SEQ_PORT_TYPE_SPECIFIC (1<<0) /* hardware specific */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC (1<<1) /* generic MIDI device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_GM (1<<2) /* General MIDI compatible device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_GS (1<<3) /* GS compatible device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_XG (1<<4) /* XG compatible device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_MT32 (1<<5) /* MT-32 compatible device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_GM2 (1<<6) /* General MIDI 2 compatible device */ + +/* other standards...*/ +#define SNDRV_SEQ_PORT_TYPE_SYNTH (1<<10) /* Synth device (no MIDI compatible - direct wavetable) */ +#define SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE (1<<11) /* Sampling device (support sample download) */ +#define SNDRV_SEQ_PORT_TYPE_SAMPLE (1<<12) /* Sampling device (sample can be downloaded at any time) */ +/*...*/ +#define SNDRV_SEQ_PORT_TYPE_HARDWARE (1<<16) /* driver for a hardware device */ +#define SNDRV_SEQ_PORT_TYPE_SOFTWARE (1<<17) /* implemented in software */ +#define SNDRV_SEQ_PORT_TYPE_SYNTHESIZER (1<<18) /* generates sound */ +#define SNDRV_SEQ_PORT_TYPE_PORT (1<<19) /* connects to other device(s) */ +#define SNDRV_SEQ_PORT_TYPE_APPLICATION (1<<20) /* application (sequencer/editor) */ + +/* misc. conditioning flags */ +#define SNDRV_SEQ_PORT_FLG_GIVEN_PORT (1<<0) +#define SNDRV_SEQ_PORT_FLG_TIMESTAMP (1<<1) +#define SNDRV_SEQ_PORT_FLG_TIME_REAL (1<<2) + +struct snd_seq_port_info { + struct snd_seq_addr addr; /* client/port numbers */ + char name[64]; /* port name */ + + unsigned int capability; /* port capability bits */ + unsigned int type; /* port type bits */ + int midi_channels; /* channels per MIDI port */ + int midi_voices; /* voices per MIDI port */ + int synth_voices; /* voices per SYNTH port */ + + int read_use; /* R/O: subscribers for output (from this port) */ + int write_use; /* R/O: subscribers for input (to this port) */ + + void *kernel; /* reserved for kernel use (must be NULL) */ + unsigned int flags; /* misc. conditioning */ + unsigned char time_queue; /* queue # for timestamping */ + char reserved[59]; /* for future use */ +}; + + +/* queue flags */ +#define SNDRV_SEQ_QUEUE_FLG_SYNC (1<<0) /* sync enabled */ + +/* queue information */ +struct snd_seq_queue_info { + int queue; /* queue id */ + + /* + * security settings, only owner of this queue can start/stop timer + * etc. if the queue is locked for other clients + */ + int owner; /* client id for owner of the queue */ + unsigned locked:1; /* timing queue locked for other queues */ + char name[64]; /* name of this queue */ + unsigned int flags; /* flags */ + char reserved[60]; /* for future use */ + +}; + +/* queue info/status */ +struct snd_seq_queue_status { + int queue; /* queue id */ + int events; /* read-only - queue size */ + snd_seq_tick_time_t tick; /* current tick */ + struct snd_seq_real_time time; /* current time */ + int running; /* running state of queue */ + int flags; /* various flags */ + char reserved[64]; /* for the future */ +}; + + +/* queue tempo */ +struct snd_seq_queue_tempo { + int queue; /* sequencer queue */ + unsigned int tempo; /* current tempo, us/tick */ + int ppq; /* time resolution, ticks/quarter */ + unsigned int skew_value; /* queue skew */ + unsigned int skew_base; /* queue skew base */ + char reserved[24]; /* for the future */ +}; + + +/* sequencer timer sources */ +#define SNDRV_SEQ_TIMER_ALSA 0 /* ALSA timer */ +#define SNDRV_SEQ_TIMER_MIDI_CLOCK 1 /* Midi Clock (CLOCK event) */ +#define SNDRV_SEQ_TIMER_MIDI_TICK 2 /* Midi Timer Tick (TICK event) */ + +/* queue timer info */ +struct snd_seq_queue_timer { + int queue; /* sequencer queue */ + int type; /* source timer type */ + union { + struct { + struct snd_timer_id id; /* ALSA's timer ID */ + unsigned int resolution; /* resolution in Hz */ + } alsa; + } u; + char reserved[64]; /* for the future use */ +}; + + +struct snd_seq_queue_client { + int queue; /* sequencer queue */ + int client; /* sequencer client */ + int used; /* queue is used with this client + (must be set for accepting events) */ + /* per client watermarks */ + char reserved[64]; /* for future use */ +}; + + +#define SNDRV_SEQ_PORT_SUBS_EXCLUSIVE (1<<0) /* exclusive connection */ +#define SNDRV_SEQ_PORT_SUBS_TIMESTAMP (1<<1) +#define SNDRV_SEQ_PORT_SUBS_TIME_REAL (1<<2) + +struct snd_seq_port_subscribe { + struct snd_seq_addr sender; /* sender address */ + struct snd_seq_addr dest; /* destination address */ + unsigned int voices; /* number of voices to be allocated (0 = don't care) */ + unsigned int flags; /* modes */ + unsigned char queue; /* input time-stamp queue (optional) */ + unsigned char pad[3]; /* reserved */ + char reserved[64]; +}; + +/* type of query subscription */ +#define SNDRV_SEQ_QUERY_SUBS_READ 0 +#define SNDRV_SEQ_QUERY_SUBS_WRITE 1 + +struct snd_seq_query_subs { + struct snd_seq_addr root; /* client/port id to be searched */ + int type; /* READ or WRITE */ + int index; /* 0..N-1 */ + int num_subs; /* R/O: number of subscriptions on this port */ + struct snd_seq_addr addr; /* R/O: result */ + unsigned char queue; /* R/O: result */ + unsigned int flags; /* R/O: result */ + char reserved[64]; /* for future use */ +}; + + +/* + * IOCTL commands + */ + +#define SNDRV_SEQ_IOCTL_PVERSION _IOR ('S', 0x00, int) +#define SNDRV_SEQ_IOCTL_CLIENT_ID _IOR ('S', 0x01, int) +#define SNDRV_SEQ_IOCTL_SYSTEM_INFO _IOWR('S', 0x02, struct snd_seq_system_info) +#define SNDRV_SEQ_IOCTL_RUNNING_MODE _IOWR('S', 0x03, struct snd_seq_running_info) + +#define SNDRV_SEQ_IOCTL_GET_CLIENT_INFO _IOWR('S', 0x10, struct snd_seq_client_info) +#define SNDRV_SEQ_IOCTL_SET_CLIENT_INFO _IOW ('S', 0x11, struct snd_seq_client_info) + +#define SNDRV_SEQ_IOCTL_CREATE_PORT _IOWR('S', 0x20, struct snd_seq_port_info) +#define SNDRV_SEQ_IOCTL_DELETE_PORT _IOW ('S', 0x21, struct snd_seq_port_info) +#define SNDRV_SEQ_IOCTL_GET_PORT_INFO _IOWR('S', 0x22, struct snd_seq_port_info) +#define SNDRV_SEQ_IOCTL_SET_PORT_INFO _IOW ('S', 0x23, struct snd_seq_port_info) + +#define SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT _IOW ('S', 0x30, struct snd_seq_port_subscribe) +#define SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT _IOW ('S', 0x31, struct snd_seq_port_subscribe) + +#define SNDRV_SEQ_IOCTL_CREATE_QUEUE _IOWR('S', 0x32, struct snd_seq_queue_info) +#define SNDRV_SEQ_IOCTL_DELETE_QUEUE _IOW ('S', 0x33, struct snd_seq_queue_info) +#define SNDRV_SEQ_IOCTL_GET_QUEUE_INFO _IOWR('S', 0x34, struct snd_seq_queue_info) +#define SNDRV_SEQ_IOCTL_SET_QUEUE_INFO _IOWR('S', 0x35, struct snd_seq_queue_info) +#define SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE _IOWR('S', 0x36, struct snd_seq_queue_info) +#define SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS _IOWR('S', 0x40, struct snd_seq_queue_status) +#define SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO _IOWR('S', 0x41, struct snd_seq_queue_tempo) +#define SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO _IOW ('S', 0x42, struct snd_seq_queue_tempo) +#define SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER _IOWR('S', 0x45, struct snd_seq_queue_timer) +#define SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER _IOW ('S', 0x46, struct snd_seq_queue_timer) +#define SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT _IOWR('S', 0x49, struct snd_seq_queue_client) +#define SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT _IOW ('S', 0x4a, struct snd_seq_queue_client) +#define SNDRV_SEQ_IOCTL_GET_CLIENT_POOL _IOWR('S', 0x4b, struct snd_seq_client_pool) +#define SNDRV_SEQ_IOCTL_SET_CLIENT_POOL _IOW ('S', 0x4c, struct snd_seq_client_pool) +#define SNDRV_SEQ_IOCTL_REMOVE_EVENTS _IOW ('S', 0x4e, struct snd_seq_remove_events) +#define SNDRV_SEQ_IOCTL_QUERY_SUBS _IOWR('S', 0x4f, struct snd_seq_query_subs) +#define SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION _IOWR('S', 0x50, struct snd_seq_port_subscribe) +#define SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT _IOWR('S', 0x51, struct snd_seq_client_info) +#define SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT _IOWR('S', 0x52, struct snd_seq_port_info) + +#endif /* __SOUND_ASEQUENCER_H */ diff --git a/include/sound/uapi/asoc.h b/include/sound/uapi/asoc.h new file mode 100644 index 0000000..4efb4ec --- /dev/null +++ b/include/sound/uapi/asoc.h @@ -0,0 +1,632 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * uapi/sound/asoc.h -- ALSA SoC Firmware Controls and DAPM + * + * Copyright (C) 2012 Texas Instruments Inc. + * Copyright (C) 2015 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Simple file API to load FW that includes mixers, coefficients, DAPM graphs, + * algorithms, equalisers, DAIs, widgets etc. +*/ + +#ifndef __LINUX_UAPI_SND_ASOC_H +#define __LINUX_UAPI_SND_ASOC_H + +#include + +/* + * Maximum number of channels topology kcontrol can represent. + */ +#define SND_SOC_TPLG_MAX_CHAN 8 + +/* + * Maximum number of PCM formats capability + */ +#define SND_SOC_TPLG_MAX_FORMATS 16 + +/* + * Maximum number of PCM stream configs + */ +#define SND_SOC_TPLG_STREAM_CONFIG_MAX 8 + +/* + * Maximum number of physical link's hardware configs + */ +#define SND_SOC_TPLG_HW_CONFIG_MAX 8 + +/* individual kcontrol info types - can be mixed with other types */ +#define SND_SOC_TPLG_CTL_VOLSW 1 +#define SND_SOC_TPLG_CTL_VOLSW_SX 2 +#define SND_SOC_TPLG_CTL_VOLSW_XR_SX 3 +#define SND_SOC_TPLG_CTL_ENUM 4 +#define SND_SOC_TPLG_CTL_BYTES 5 +#define SND_SOC_TPLG_CTL_ENUM_VALUE 6 +#define SND_SOC_TPLG_CTL_RANGE 7 +#define SND_SOC_TPLG_CTL_STROBE 8 + + +/* individual widget kcontrol info types - can be mixed with other types */ +#define SND_SOC_TPLG_DAPM_CTL_VOLSW 64 +#define SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE 65 +#define SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT 66 +#define SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE 67 +#define SND_SOC_TPLG_DAPM_CTL_PIN 68 + +/* DAPM widget types - add new items to the end */ +#define SND_SOC_TPLG_DAPM_INPUT 0 +#define SND_SOC_TPLG_DAPM_OUTPUT 1 +#define SND_SOC_TPLG_DAPM_MUX 2 +#define SND_SOC_TPLG_DAPM_MIXER 3 +#define SND_SOC_TPLG_DAPM_PGA 4 +#define SND_SOC_TPLG_DAPM_OUT_DRV 5 +#define SND_SOC_TPLG_DAPM_ADC 6 +#define SND_SOC_TPLG_DAPM_DAC 7 +#define SND_SOC_TPLG_DAPM_SWITCH 8 +#define SND_SOC_TPLG_DAPM_PRE 9 +#define SND_SOC_TPLG_DAPM_POST 10 +#define SND_SOC_TPLG_DAPM_AIF_IN 11 +#define SND_SOC_TPLG_DAPM_AIF_OUT 12 +#define SND_SOC_TPLG_DAPM_DAI_IN 13 +#define SND_SOC_TPLG_DAPM_DAI_OUT 14 +#define SND_SOC_TPLG_DAPM_DAI_LINK 15 +#define SND_SOC_TPLG_DAPM_BUFFER 16 +#define SND_SOC_TPLG_DAPM_SCHEDULER 17 +#define SND_SOC_TPLG_DAPM_EFFECT 18 +#define SND_SOC_TPLG_DAPM_SIGGEN 19 +#define SND_SOC_TPLG_DAPM_SRC 20 +#define SND_SOC_TPLG_DAPM_ASRC 21 +#define SND_SOC_TPLG_DAPM_ENCODER 22 +#define SND_SOC_TPLG_DAPM_DECODER 23 +#define SND_SOC_TPLG_DAPM_LAST SND_SOC_TPLG_DAPM_DECODER + +/* Header magic number and string sizes */ +#define SND_SOC_TPLG_MAGIC 0x41536F43 /* ASoC */ + +/* string sizes */ +#define SND_SOC_TPLG_NUM_TEXTS 16 + +/* ABI version */ +#define SND_SOC_TPLG_ABI_VERSION 0x5 /* current version */ +#define SND_SOC_TPLG_ABI_VERSION_MIN 0x4 /* oldest version supported */ + +/* Max size of TLV data */ +#define SND_SOC_TPLG_TLV_SIZE 32 + +/* + * File and Block header data types. + * Add new generic and vendor types to end of list. + * Generic types are handled by the core whilst vendors types are passed + * to the component drivers for handling. + */ +#define SND_SOC_TPLG_TYPE_MIXER 1 +#define SND_SOC_TPLG_TYPE_BYTES 2 +#define SND_SOC_TPLG_TYPE_ENUM 3 +#define SND_SOC_TPLG_TYPE_DAPM_GRAPH 4 +#define SND_SOC_TPLG_TYPE_DAPM_WIDGET 5 +#define SND_SOC_TPLG_TYPE_DAI_LINK 6 +#define SND_SOC_TPLG_TYPE_PCM 7 +#define SND_SOC_TPLG_TYPE_MANIFEST 8 +#define SND_SOC_TPLG_TYPE_CODEC_LINK 9 +#define SND_SOC_TPLG_TYPE_BACKEND_LINK 10 +#define SND_SOC_TPLG_TYPE_PDATA 11 +#define SND_SOC_TPLG_TYPE_DAI 12 +#define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_DAI + +/* vendor block IDs - please add new vendor types to end */ +#define SND_SOC_TPLG_TYPE_VENDOR_FW 1000 +#define SND_SOC_TPLG_TYPE_VENDOR_CONFIG 1001 +#define SND_SOC_TPLG_TYPE_VENDOR_COEFF 1002 +#define SND_SOC_TPLG_TYPEVENDOR_CODEC 1003 + +#define SND_SOC_TPLG_STREAM_PLAYBACK 0 +#define SND_SOC_TPLG_STREAM_CAPTURE 1 + +/* vendor tuple types */ +#define SND_SOC_TPLG_TUPLE_TYPE_UUID 0 +#define SND_SOC_TPLG_TUPLE_TYPE_STRING 1 +#define SND_SOC_TPLG_TUPLE_TYPE_BOOL 2 +#define SND_SOC_TPLG_TUPLE_TYPE_BYTE 3 +#define SND_SOC_TPLG_TUPLE_TYPE_WORD 4 +#define SND_SOC_TPLG_TUPLE_TYPE_SHORT 5 + +/* DAI flags */ +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES (1 << 0) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2) + +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED 0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED 1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + +/* DAI mclk_direction */ +#define SND_SOC_TPLG_MCLK_CO 0 /* for codec, mclk is output */ +#define SND_SOC_TPLG_MCLK_CI 1 /* for codec, mclk is input */ + +/* DAI physical PCM data formats. + * Add new formats to the end of the list. + */ +#define SND_SOC_DAI_FORMAT_I2S 1 /* I2S mode */ +#define SND_SOC_DAI_FORMAT_RIGHT_J 2 /* Right Justified mode */ +#define SND_SOC_DAI_FORMAT_LEFT_J 3 /* Left Justified mode */ +#define SND_SOC_DAI_FORMAT_DSP_A 4 /* L data MSB after FRM LRC */ +#define SND_SOC_DAI_FORMAT_DSP_B 5 /* L data MSB during FRM LRC */ +#define SND_SOC_DAI_FORMAT_AC97 6 /* AC97 */ +#define SND_SOC_DAI_FORMAT_PDM 7 /* Pulse density modulation */ + +/* left and right justified also known as MSB and LSB respectively */ +#define SND_SOC_DAI_FORMAT_MSB SND_SOC_DAI_FORMAT_LEFT_J +#define SND_SOC_DAI_FORMAT_LSB SND_SOC_DAI_FORMAT_RIGHT_J + +/* DAI link flags */ +#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES (1 << 0) +#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) +#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2) +#define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP (1 << 3) + +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + +/* + * Block Header. + * This header precedes all object and object arrays below. + */ +struct snd_soc_tplg_hdr { + __le32 magic; /* magic number */ + __le32 abi; /* ABI version */ + __le32 version; /* optional vendor specific version details */ + __le32 type; /* SND_SOC_TPLG_TYPE_ */ + __le32 size; /* size of this structure */ + __le32 vendor_type; /* optional vendor specific type info */ + __le32 payload_size; /* data bytes, excluding this header */ + __le32 index; /* identifier for block */ + __le32 count; /* number of elements in block */ +} __attribute__((packed)); + +/* vendor tuple for uuid */ +struct snd_soc_tplg_vendor_uuid_elem { + __le32 token; + char uuid[16]; +} __attribute__((packed)); + +/* vendor tuple for a bool/byte/short/word value */ +struct snd_soc_tplg_vendor_value_elem { + __le32 token; + __le32 value; +} __attribute__((packed)); + +/* vendor tuple for string */ +struct snd_soc_tplg_vendor_string_elem { + __le32 token; + char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; +} __attribute__((packed)); + +struct snd_soc_tplg_vendor_array { + __le32 size; /* size in bytes of the array, including all elements */ + __le32 type; /* SND_SOC_TPLG_TUPLE_TYPE_ */ + __le32 num_elems; /* number of elements in array */ + union { + struct snd_soc_tplg_vendor_uuid_elem uuid[0]; + struct snd_soc_tplg_vendor_value_elem value[0]; + struct snd_soc_tplg_vendor_string_elem string[0]; + }; +} __attribute__((packed)); + +/* + * Private data. + * All topology objects may have private data that can be used by the driver or + * firmware. Core will ignore this data. + */ +struct snd_soc_tplg_private { + __le32 size; /* in bytes of private data */ + union { + char data[0]; + struct snd_soc_tplg_vendor_array array[0]; + }; +} __attribute__((packed)); + +/* + * Kcontrol TLV data. + */ +struct snd_soc_tplg_tlv_dbscale { + __le32 min; + __le32 step; + __le32 mute; +} __attribute__((packed)); + +struct snd_soc_tplg_ctl_tlv { + __le32 size; /* in bytes of this structure */ + __le32 type; /* SNDRV_CTL_TLVT_*, type of TLV */ + union { + __le32 data[SND_SOC_TPLG_TLV_SIZE]; + struct snd_soc_tplg_tlv_dbscale scale; + }; +} __attribute__((packed)); + +/* + * Kcontrol channel data + */ +struct snd_soc_tplg_channel { + __le32 size; /* in bytes of this structure */ + __le32 reg; + __le32 shift; + __le32 id; /* ID maps to Left, Right, LFE etc */ +} __attribute__((packed)); + +/* + * Genericl Operations IDs, for binding Kcontrol or Bytes ext ops + * Kcontrol ops need get/put/info. + * Bytes ext ops need get/put. + */ +struct snd_soc_tplg_io_ops { + __le32 get; + __le32 put; + __le32 info; +} __attribute__((packed)); + +/* + * kcontrol header + */ +struct snd_soc_tplg_ctl_hdr { + __le32 size; /* in bytes of this structure */ + __le32 type; + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + __le32 access; + struct snd_soc_tplg_io_ops ops; + struct snd_soc_tplg_ctl_tlv tlv; +} __attribute__((packed)); + +/* + * Stream Capabilities + */ +struct snd_soc_tplg_stream_caps { + __le32 size; /* in bytes of this structure */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + __le64 formats; /* supported formats SNDRV_PCM_FMTBIT_* */ + __le32 rates; /* supported rates SNDRV_PCM_RATE_* */ + __le32 rate_min; /* min rate */ + __le32 rate_max; /* max rate */ + __le32 channels_min; /* min channels */ + __le32 channels_max; /* max channels */ + __le32 periods_min; /* min number of periods */ + __le32 periods_max; /* max number of periods */ + __le32 period_size_min; /* min period size bytes */ + __le32 period_size_max; /* max period size bytes */ + __le32 buffer_size_min; /* min buffer size bytes */ + __le32 buffer_size_max; /* max buffer size bytes */ + __le32 sig_bits; /* number of bits of content */ +} __attribute__((packed)); + +/* + * FE or BE Stream configuration supported by SW/FW + */ +struct snd_soc_tplg_stream { + __le32 size; /* in bytes of this structure */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* Name of the stream */ + __le64 format; /* SNDRV_PCM_FMTBIT_* */ + __le32 rate; /* SNDRV_PCM_RATE_* */ + __le32 period_bytes; /* size of period in bytes */ + __le32 buffer_bytes; /* size of buffer in bytes */ + __le32 channels; /* channels */ +} __attribute__((packed)); + + +/* + * Describes a physical link's runtime supported hardware config, + * i.e. hardware audio formats. + */ +struct snd_soc_tplg_hw_config { + __le32 size; /* in bytes of this structure */ + __le32 id; /* unique ID - - used to match */ + __le32 fmt; /* SND_SOC_DAI_FORMAT_ format value */ + __u8 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ + __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ + __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ + __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ + __u8 mclk_direction; /* SND_SOC_TPLG_MCLK_ value */ + __le16 reserved; /* for 32bit alignment */ + __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ + __le32 bclk_rate; /* BCLK freqency in Hz */ + __le32 fsync_rate; /* frame clock in Hz */ + __le32 tdm_slots; /* number of TDM slots in use */ + __le32 tdm_slot_width; /* width in bits for each slot */ + __le32 tx_slots; /* bit mask for active Tx slots */ + __le32 rx_slots; /* bit mask for active Rx slots */ + __le32 tx_channels; /* number of Tx channels */ + __le32 tx_chanmap[SND_SOC_TPLG_MAX_CHAN]; /* array of slot number */ + __le32 rx_channels; /* number of Rx channels */ + __le32 rx_chanmap[SND_SOC_TPLG_MAX_CHAN]; /* array of slot number */ +} __attribute__((packed)); + +/* + * Manifest. List totals for each payload type. Not used in parsing, but will + * be passed to the component driver before any other objects in order for any + * global component resource allocations. + * + * File block representation for manifest :- + * +-----------------------------------+----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+----+ + * | struct snd_soc_tplg_manifest | 1 | + * +-----------------------------------+----+ + */ +struct snd_soc_tplg_manifest { + __le32 size; /* in bytes of this structure */ + __le32 control_elems; /* number of control elements */ + __le32 widget_elems; /* number of widget elements */ + __le32 graph_elems; /* number of graph elements */ + __le32 pcm_elems; /* number of PCM elements */ + __le32 dai_link_elems; /* number of DAI link elements */ + __le32 dai_elems; /* number of physical DAI elements */ + __le32 reserved[20]; /* reserved for new ABI element types */ + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* + * Mixer kcontrol. + * + * File block representation for mixer kcontrol :- + * +-----------------------------------+----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+----+ + * | struct snd_soc_tplg_mixer_control | N | + * +-----------------------------------+----+ + */ +struct snd_soc_tplg_mixer_control { + struct snd_soc_tplg_ctl_hdr hdr; + __le32 size; /* in bytes of this structure */ + __le32 min; + __le32 max; + __le32 platform_max; + __le32 invert; + __le32 num_channels; + struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* + * Enumerated kcontrol + * + * File block representation for enum kcontrol :- + * +-----------------------------------+----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+----+ + * | struct snd_soc_tplg_enum_control | N | + * +-----------------------------------+----+ + */ +struct snd_soc_tplg_enum_control { + struct snd_soc_tplg_ctl_hdr hdr; + __le32 size; /* in bytes of this structure */ + __le32 num_channels; + struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; + __le32 items; + __le32 mask; + __le32 count; + char texts[SND_SOC_TPLG_NUM_TEXTS][SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + __le32 values[SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN / 4]; + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* + * Bytes kcontrol + * + * File block representation for bytes kcontrol :- + * +-----------------------------------+----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+----+ + * | struct snd_soc_tplg_bytes_control | N | + * +-----------------------------------+----+ + */ +struct snd_soc_tplg_bytes_control { + struct snd_soc_tplg_ctl_hdr hdr; + __le32 size; /* in bytes of this structure */ + __le32 max; + __le32 mask; + __le32 base; + __le32 num_regs; + struct snd_soc_tplg_io_ops ext_ops; + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* + * DAPM Graph Element + * + * File block representation for DAPM graph elements :- + * +-------------------------------------+----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-------------------------------------+----+ + * | struct snd_soc_tplg_dapm_graph_elem | N | + * +-------------------------------------+----+ + */ +struct snd_soc_tplg_dapm_graph_elem { + char sink[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char control[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char source[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; +} __attribute__((packed)); + +/* + * DAPM Widget. + * + * File block representation for DAPM widget :- + * +-------------------------------------+-----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-------------------------------------+-----+ + * | struct snd_soc_tplg_dapm_widget | N | + * +-------------------------------------+-----+ + * | struct snd_soc_tplg_enum_control | 0|1 | + * | struct snd_soc_tplg_mixer_control | 0|N | + * +-------------------------------------+-----+ + * + * Optional enum or mixer control can be appended to the end of each widget + * in the block. + */ +struct snd_soc_tplg_dapm_widget { + __le32 size; /* in bytes of this structure */ + __le32 id; /* SND_SOC_DAPM_CTL */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + + __le32 reg; /* negative reg = no direct dapm */ + __le32 shift; /* bits to shift */ + __le32 mask; /* non-shifted mask */ + __le32 subseq; /* sort within widget type */ + __le32 invert; /* invert the power bit */ + __le32 ignore_suspend; /* kept enabled over suspend */ + __le16 event_flags; + __le16 event_type; + __le32 num_kcontrols; + struct snd_soc_tplg_private priv; + /* + * kcontrols that relate to this widget + * follow here after widget private data + */ +} __attribute__((packed)); + + +/* + * Describes SW/FW specific features of PCM (FE DAI & DAI link). + * + * File block representation for PCM :- + * +-----------------------------------+-----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+-----+ + * | struct snd_soc_tplg_pcm | N | + * +-----------------------------------+-----+ + */ +struct snd_soc_tplg_pcm { + __le32 size; /* in bytes of this structure */ + char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + __le32 pcm_id; /* unique ID - used to match with DAI link */ + __le32 dai_id; /* unique ID - used to match */ + __le32 playback; /* supports playback mode */ + __le32 capture; /* supports capture mode */ + __le32 compress; /* 1 = compressed; 0 = PCM */ + struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */ + __le32 num_streams; /* number of streams */ + struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */ + __le32 flag_mask; /* bitmask of flags to configure */ + __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + + +/* + * Describes the physical link runtime supported configs or params + * + * File block representation for physical link config :- + * +-----------------------------------+-----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+-----+ + * | struct snd_soc_tplg_link_config | N | + * +-----------------------------------+-----+ + */ +struct snd_soc_tplg_link_config { + __le32 size; /* in bytes of this structure */ + __le32 id; /* unique ID - used to match */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */ + char stream_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* stream name - used to match */ + struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ + __le32 num_streams; /* number of streams */ + struct snd_soc_tplg_hw_config hw_config[SND_SOC_TPLG_HW_CONFIG_MAX]; /* hw configs */ + __le32 num_hw_configs; /* number of hw configs */ + __le32 default_hw_config_id; /* default hw config ID for init */ + __le32 flag_mask; /* bitmask of flags to configure */ + __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* + * Describes SW/FW specific features of physical DAI. + * It can be used to configure backend DAIs for DPCM. + * + * File block representation for physical DAI :- + * +-----------------------------------+-----+ + * | struct snd_soc_tplg_hdr | 1 | + * +-----------------------------------+-----+ + * | struct snd_soc_tplg_dai | N | + * +-----------------------------------+-----+ + */ +struct snd_soc_tplg_dai { + __le32 size; /* in bytes of this structure */ + char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */ + __le32 dai_id; /* unique ID - used to match */ + __le32 playback; /* supports playback mode */ + __le32 capture; /* supports capture mode */ + struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */ + __le32 flag_mask; /* bitmask of flags to configure */ + __le32 flags; /* SND_SOC_TPLG_DAI_FLGBIT_* */ + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* + * Old version of ABI structs, supported for backward compatibility. + */ + +/* Manifest v4 */ +struct snd_soc_tplg_manifest_v4 { + __le32 size; /* in bytes of this structure */ + __le32 control_elems; /* number of control elements */ + __le32 widget_elems; /* number of widget elements */ + __le32 graph_elems; /* number of graph elements */ + __le32 pcm_elems; /* number of PCM elements */ + __le32 dai_link_elems; /* number of DAI link elements */ + struct snd_soc_tplg_private priv; +} __attribute__((packed)); + +/* Stream Capabilities v4 */ +struct snd_soc_tplg_stream_caps_v4 { + __le32 size; /* in bytes of this structure */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + __le64 formats; /* supported formats SNDRV_PCM_FMTBIT_* */ + __le32 rates; /* supported rates SNDRV_PCM_RATE_* */ + __le32 rate_min; /* min rate */ + __le32 rate_max; /* max rate */ + __le32 channels_min; /* min channels */ + __le32 channels_max; /* max channels */ + __le32 periods_min; /* min number of periods */ + __le32 periods_max; /* max number of periods */ + __le32 period_size_min; /* min period size bytes */ + __le32 period_size_max; /* max period size bytes */ + __le32 buffer_size_min; /* min buffer size bytes */ + __le32 buffer_size_max; /* max buffer size bytes */ +} __attribute__((packed)); + +/* PCM v4 */ +struct snd_soc_tplg_pcm_v4 { + __le32 size; /* in bytes of this structure */ + char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + __le32 pcm_id; /* unique ID - used to match with DAI link */ + __le32 dai_id; /* unique ID - used to match */ + __le32 playback; /* supports playback mode */ + __le32 capture; /* supports capture mode */ + __le32 compress; /* 1 = compressed; 0 = PCM */ + struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */ + __le32 num_streams; /* number of streams */ + struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */ +} __attribute__((packed)); + +/* Physical link config v4 */ +struct snd_soc_tplg_link_config_v4 { + __le32 size; /* in bytes of this structure */ + __le32 id; /* unique ID - used to match */ + struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ + __le32 num_streams; /* number of streams */ +} __attribute__((packed)); + +#endif diff --git a/include/sound/uapi/asound.h b/include/sound/uapi/asound.h new file mode 100644 index 0000000..ec610c2 --- /dev/null +++ b/include/sound/uapi/asound.h @@ -0,0 +1,1133 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Advanced Linux Sound Architecture - ALSA - Driver + * Copyright (c) 1994-2003 by Jaroslav Kysela , + * Abramo Bagnara + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef __SOUND_ASOUND_H +#define __SOUND_ASOUND_H + +#if defined(__KERNEL__) || defined(__linux__) +#include +#include +#else +#include +#include +#endif + +#include +#include + +/* + * protocol version + */ + +#define SNDRV_PROTOCOL_VERSION(major, minor, subminor) (((major)<<16)|((minor)<<8)|(subminor)) +#define SNDRV_PROTOCOL_MAJOR(version) (((version)>>16)&0xffff) +#define SNDRV_PROTOCOL_MINOR(version) (((version)>>8)&0xff) +#define SNDRV_PROTOCOL_MICRO(version) ((version)&0xff) +#define SNDRV_PROTOCOL_INCOMPATIBLE(kversion, uversion) \ + (SNDRV_PROTOCOL_MAJOR(kversion) != SNDRV_PROTOCOL_MAJOR(uversion) || \ + (SNDRV_PROTOCOL_MAJOR(kversion) == SNDRV_PROTOCOL_MAJOR(uversion) && \ + SNDRV_PROTOCOL_MINOR(kversion) != SNDRV_PROTOCOL_MINOR(uversion))) + +/**************************************************************************** + * * + * Digital audio interface * + * * + ****************************************************************************/ + +struct snd_aes_iec958 { + unsigned char status[24]; /* AES/IEC958 channel status bits */ + unsigned char subcode[147]; /* AES/IEC958 subcode bits */ + unsigned char pad; /* nothing */ + unsigned char dig_subframe[4]; /* AES/IEC958 subframe bits */ +}; + +/**************************************************************************** + * * + * CEA-861 Audio InfoFrame. Used in HDMI and DisplayPort * + * * + ****************************************************************************/ + +struct snd_cea_861_aud_if { + unsigned char db1_ct_cc; /* coding type and channel count */ + unsigned char db2_sf_ss; /* sample frequency and size */ + unsigned char db3; /* not used, all zeros */ + unsigned char db4_ca; /* channel allocation code */ + unsigned char db5_dminh_lsv; /* downmix inhibit & level-shit values */ +}; + +/**************************************************************************** + * * + * Section for driver hardware dependent interface - /dev/snd/hw? * + * * + ****************************************************************************/ + +#define SNDRV_HWDEP_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 1) + +enum { + SNDRV_HWDEP_IFACE_OPL2 = 0, + SNDRV_HWDEP_IFACE_OPL3, + SNDRV_HWDEP_IFACE_OPL4, + SNDRV_HWDEP_IFACE_SB16CSP, /* Creative Signal Processor */ + SNDRV_HWDEP_IFACE_EMU10K1, /* FX8010 processor in EMU10K1 chip */ + SNDRV_HWDEP_IFACE_YSS225, /* Yamaha FX processor */ + SNDRV_HWDEP_IFACE_ICS2115, /* Wavetable synth */ + SNDRV_HWDEP_IFACE_SSCAPE, /* Ensoniq SoundScape ISA card (MC68EC000) */ + SNDRV_HWDEP_IFACE_VX, /* Digigram VX cards */ + SNDRV_HWDEP_IFACE_MIXART, /* Digigram miXart cards */ + SNDRV_HWDEP_IFACE_USX2Y, /* Tascam US122, US224 & US428 usb */ + SNDRV_HWDEP_IFACE_EMUX_WAVETABLE, /* EmuX wavetable */ + SNDRV_HWDEP_IFACE_BLUETOOTH, /* Bluetooth audio */ + SNDRV_HWDEP_IFACE_USX2Y_PCM, /* Tascam US122, US224 & US428 rawusb pcm */ + SNDRV_HWDEP_IFACE_PCXHR, /* Digigram PCXHR */ + SNDRV_HWDEP_IFACE_SB_RC, /* SB Extigy/Audigy2NX remote control */ + SNDRV_HWDEP_IFACE_HDA, /* HD-audio */ + SNDRV_HWDEP_IFACE_USB_STREAM, /* direct access to usb stream */ + SNDRV_HWDEP_IFACE_FW_DICE, /* TC DICE FireWire device */ + SNDRV_HWDEP_IFACE_FW_FIREWORKS, /* Echo Audio Fireworks based device */ + SNDRV_HWDEP_IFACE_FW_BEBOB, /* BridgeCo BeBoB based device */ + SNDRV_HWDEP_IFACE_FW_OXFW, /* Oxford OXFW970/971 based device */ + SNDRV_HWDEP_IFACE_FW_DIGI00X, /* Digidesign Digi 002/003 family */ + SNDRV_HWDEP_IFACE_FW_TASCAM, /* TASCAM FireWire series */ + SNDRV_HWDEP_IFACE_LINE6, /* Line6 USB processors */ + SNDRV_HWDEP_IFACE_FW_MOTU, /* MOTU FireWire series */ + SNDRV_HWDEP_IFACE_FW_FIREFACE, /* RME Fireface series */ + + /* Don't forget to change the following: */ + SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_FIREFACE +}; + +struct snd_hwdep_info { + unsigned int device; /* WR: device number */ + int card; /* R: card number */ + unsigned char id[64]; /* ID (user selectable) */ + unsigned char name[80]; /* hwdep name */ + int iface; /* hwdep interface */ + unsigned char reserved[64]; /* reserved for future */ +}; + +/* generic DSP loader */ +struct snd_hwdep_dsp_status { + unsigned int version; /* R: driver-specific version */ + unsigned char id[32]; /* R: driver-specific ID string */ + unsigned int num_dsps; /* R: number of DSP images to transfer */ + unsigned int dsp_loaded; /* R: bit flags indicating the loaded DSPs */ + unsigned int chip_ready; /* R: 1 = initialization finished */ + unsigned char reserved[16]; /* reserved for future use */ +}; + +struct snd_hwdep_dsp_image { + unsigned int index; /* W: DSP index */ + unsigned char name[64]; /* W: ID (e.g. file name) */ + unsigned char *image; /* W: binary image */ + size_t length; /* W: size of image in bytes */ + unsigned long driver_data; /* W: driver-specific data */ +}; + +#define SNDRV_HWDEP_IOCTL_PVERSION _IOR ('H', 0x00, int) +#define SNDRV_HWDEP_IOCTL_INFO _IOR ('H', 0x01, struct snd_hwdep_info) +#define SNDRV_HWDEP_IOCTL_DSP_STATUS _IOR('H', 0x02, struct snd_hwdep_dsp_status) +#define SNDRV_HWDEP_IOCTL_DSP_LOAD _IOW('H', 0x03, struct snd_hwdep_dsp_image) + +/***************************************************************************** + * * + * Digital Audio (PCM) interface - /dev/snd/pcm?? * + * * + *****************************************************************************/ + +#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 15) + +typedef unsigned long snd_pcm_uframes_t; +typedef signed long snd_pcm_sframes_t; + +enum { + SNDRV_PCM_CLASS_GENERIC = 0, /* standard mono or stereo device */ + SNDRV_PCM_CLASS_MULTI, /* multichannel device */ + SNDRV_PCM_CLASS_MODEM, /* software modem class */ + SNDRV_PCM_CLASS_DIGITIZER, /* digitizer class */ + /* Don't forget to change the following: */ + SNDRV_PCM_CLASS_LAST = SNDRV_PCM_CLASS_DIGITIZER, +}; + +enum { + SNDRV_PCM_SUBCLASS_GENERIC_MIX = 0, /* mono or stereo subdevices are mixed together */ + SNDRV_PCM_SUBCLASS_MULTI_MIX, /* multichannel subdevices are mixed together */ + /* Don't forget to change the following: */ + SNDRV_PCM_SUBCLASS_LAST = SNDRV_PCM_SUBCLASS_MULTI_MIX, +}; + +enum { + SNDRV_PCM_STREAM_PLAYBACK = 0, + SNDRV_PCM_STREAM_CAPTURE, + SNDRV_PCM_STREAM_LAST = SNDRV_PCM_STREAM_CAPTURE, +}; + +typedef int __bitwise snd_pcm_access_t; +#define SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ((snd_pcm_access_t) 0) /* interleaved mmap */ +#define SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED ((snd_pcm_access_t) 1) /* noninterleaved mmap */ +#define SNDRV_PCM_ACCESS_MMAP_COMPLEX ((snd_pcm_access_t) 2) /* complex mmap */ +#define SNDRV_PCM_ACCESS_RW_INTERLEAVED ((snd_pcm_access_t) 3) /* readi/writei */ +#define SNDRV_PCM_ACCESS_RW_NONINTERLEAVED ((snd_pcm_access_t) 4) /* readn/writen */ +#define SNDRV_PCM_ACCESS_LAST SNDRV_PCM_ACCESS_RW_NONINTERLEAVED + +typedef int __bitwise snd_pcm_format_t; +#define SNDRV_PCM_FORMAT_S8 ((snd_pcm_format_t) 0) +#define SNDRV_PCM_FORMAT_U8 ((snd_pcm_format_t) 1) +#define SNDRV_PCM_FORMAT_S16_LE ((snd_pcm_format_t) 2) +#define SNDRV_PCM_FORMAT_S16_BE ((snd_pcm_format_t) 3) +#define SNDRV_PCM_FORMAT_U16_LE ((snd_pcm_format_t) 4) +#define SNDRV_PCM_FORMAT_U16_BE ((snd_pcm_format_t) 5) +#define SNDRV_PCM_FORMAT_S24_LE ((snd_pcm_format_t) 6) /* low three bytes */ +#define SNDRV_PCM_FORMAT_S24_BE ((snd_pcm_format_t) 7) /* low three bytes */ +#define SNDRV_PCM_FORMAT_U24_LE ((snd_pcm_format_t) 8) /* low three bytes */ +#define SNDRV_PCM_FORMAT_U24_BE ((snd_pcm_format_t) 9) /* low three bytes */ +#define SNDRV_PCM_FORMAT_S32_LE ((snd_pcm_format_t) 10) +#define SNDRV_PCM_FORMAT_S32_BE ((snd_pcm_format_t) 11) +#define SNDRV_PCM_FORMAT_U32_LE ((snd_pcm_format_t) 12) +#define SNDRV_PCM_FORMAT_U32_BE ((snd_pcm_format_t) 13) +#define SNDRV_PCM_FORMAT_FLOAT_LE ((snd_pcm_format_t) 14) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */ +#define SNDRV_PCM_FORMAT_FLOAT_BE ((snd_pcm_format_t) 15) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */ +#define SNDRV_PCM_FORMAT_FLOAT64_LE ((snd_pcm_format_t) 16) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */ +#define SNDRV_PCM_FORMAT_FLOAT64_BE ((snd_pcm_format_t) 17) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */ +#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE ((snd_pcm_format_t) 18) /* IEC-958 subframe, Little Endian */ +#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE ((snd_pcm_format_t) 19) /* IEC-958 subframe, Big Endian */ +#define SNDRV_PCM_FORMAT_MU_LAW ((snd_pcm_format_t) 20) +#define SNDRV_PCM_FORMAT_A_LAW ((snd_pcm_format_t) 21) +#define SNDRV_PCM_FORMAT_IMA_ADPCM ((snd_pcm_format_t) 22) +#define SNDRV_PCM_FORMAT_MPEG ((snd_pcm_format_t) 23) +#define SNDRV_PCM_FORMAT_GSM ((snd_pcm_format_t) 24) +#define SNDRV_PCM_FORMAT_S20_LE ((snd_pcm_format_t) 25) /* in four bytes, LSB justified */ +#define SNDRV_PCM_FORMAT_S20_BE ((snd_pcm_format_t) 26) /* in four bytes, LSB justified */ +#define SNDRV_PCM_FORMAT_U20_LE ((snd_pcm_format_t) 27) /* in four bytes, LSB justified */ +#define SNDRV_PCM_FORMAT_U20_BE ((snd_pcm_format_t) 28) /* in four bytes, LSB justified */ +/* gap in the numbering for a future standard linear format */ +#define SNDRV_PCM_FORMAT_SPECIAL ((snd_pcm_format_t) 31) +#define SNDRV_PCM_FORMAT_S24_3LE ((snd_pcm_format_t) 32) /* in three bytes */ +#define SNDRV_PCM_FORMAT_S24_3BE ((snd_pcm_format_t) 33) /* in three bytes */ +#define SNDRV_PCM_FORMAT_U24_3LE ((snd_pcm_format_t) 34) /* in three bytes */ +#define SNDRV_PCM_FORMAT_U24_3BE ((snd_pcm_format_t) 35) /* in three bytes */ +#define SNDRV_PCM_FORMAT_S20_3LE ((snd_pcm_format_t) 36) /* in three bytes */ +#define SNDRV_PCM_FORMAT_S20_3BE ((snd_pcm_format_t) 37) /* in three bytes */ +#define SNDRV_PCM_FORMAT_U20_3LE ((snd_pcm_format_t) 38) /* in three bytes */ +#define SNDRV_PCM_FORMAT_U20_3BE ((snd_pcm_format_t) 39) /* in three bytes */ +#define SNDRV_PCM_FORMAT_S18_3LE ((snd_pcm_format_t) 40) /* in three bytes */ +#define SNDRV_PCM_FORMAT_S18_3BE ((snd_pcm_format_t) 41) /* in three bytes */ +#define SNDRV_PCM_FORMAT_U18_3LE ((snd_pcm_format_t) 42) /* in three bytes */ +#define SNDRV_PCM_FORMAT_U18_3BE ((snd_pcm_format_t) 43) /* in three bytes */ +#define SNDRV_PCM_FORMAT_G723_24 ((snd_pcm_format_t) 44) /* 8 samples in 3 bytes */ +#define SNDRV_PCM_FORMAT_G723_24_1B ((snd_pcm_format_t) 45) /* 1 sample in 1 byte */ +#define SNDRV_PCM_FORMAT_G723_40 ((snd_pcm_format_t) 46) /* 8 Samples in 5 bytes */ +#define SNDRV_PCM_FORMAT_G723_40_1B ((snd_pcm_format_t) 47) /* 1 sample in 1 byte */ +#define SNDRV_PCM_FORMAT_DSD_U8 ((snd_pcm_format_t) 48) /* DSD, 1-byte samples DSD (x8) */ +#define SNDRV_PCM_FORMAT_DSD_U16_LE ((snd_pcm_format_t) 49) /* DSD, 2-byte samples DSD (x16), little endian */ +#define SNDRV_PCM_FORMAT_DSD_U32_LE ((snd_pcm_format_t) 50) /* DSD, 4-byte samples DSD (x32), little endian */ +#define SNDRV_PCM_FORMAT_DSD_U16_BE ((snd_pcm_format_t) 51) /* DSD, 2-byte samples DSD (x16), big endian */ +#define SNDRV_PCM_FORMAT_DSD_U32_BE ((snd_pcm_format_t) 52) /* DSD, 4-byte samples DSD (x32), big endian */ +#define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_DSD_U32_BE +#define SNDRV_PCM_FORMAT_FIRST SNDRV_PCM_FORMAT_S8 + +#ifdef SNDRV_LITTLE_ENDIAN +#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_LE +#define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_LE +#define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_LE +#define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_LE +#define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_LE +#define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_LE +#define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_LE +#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_LE +#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE +#define SNDRV_PCM_FORMAT_S20 SNDRV_PCM_FORMAT_S20_LE +#define SNDRV_PCM_FORMAT_U20 SNDRV_PCM_FORMAT_U20_LE +#endif +#ifdef SNDRV_BIG_ENDIAN +#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_BE +#define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_BE +#define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_BE +#define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_BE +#define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_BE +#define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_BE +#define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_BE +#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_BE +#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE +#define SNDRV_PCM_FORMAT_S20 SNDRV_PCM_FORMAT_S20_BE +#define SNDRV_PCM_FORMAT_U20 SNDRV_PCM_FORMAT_U20_BE +#endif + +typedef int __bitwise snd_pcm_subformat_t; +#define SNDRV_PCM_SUBFORMAT_STD ((snd_pcm_subformat_t) 0) +#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_STD + +#define SNDRV_PCM_INFO_MMAP 0x00000001 /* hardware supports mmap */ +#define SNDRV_PCM_INFO_MMAP_VALID 0x00000002 /* period data are valid during transfer */ +#define SNDRV_PCM_INFO_DOUBLE 0x00000004 /* Double buffering needed for PCM start/stop */ +#define SNDRV_PCM_INFO_BATCH 0x00000010 /* double buffering */ +#define SNDRV_PCM_INFO_SYNC_APPLPTR 0x00000020 /* need the explicit sync of appl_ptr update */ +#define SNDRV_PCM_INFO_INTERLEAVED 0x00000100 /* channels are interleaved */ +#define SNDRV_PCM_INFO_NONINTERLEAVED 0x00000200 /* channels are not interleaved */ +#define SNDRV_PCM_INFO_COMPLEX 0x00000400 /* complex frame organization (mmap only) */ +#define SNDRV_PCM_INFO_BLOCK_TRANSFER 0x00010000 /* hardware transfer block of samples */ +#define SNDRV_PCM_INFO_OVERRANGE 0x00020000 /* hardware supports ADC (capture) overrange detection */ +#define SNDRV_PCM_INFO_RESUME 0x00040000 /* hardware supports stream resume after suspend */ +#define SNDRV_PCM_INFO_PAUSE 0x00080000 /* pause ioctl is supported */ +#define SNDRV_PCM_INFO_HALF_DUPLEX 0x00100000 /* only half duplex */ +#define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */ +#define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */ +#define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000 /* period wakeup can be disabled */ +#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000 /* (Deprecated)has audio wall clock for audio/system time sync */ +#define SNDRV_PCM_INFO_HAS_LINK_ATIME 0x01000000 /* report hardware link audio time, reset on startup */ +#define SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME 0x02000000 /* report absolute hardware link audio time, not reset on startup */ +#define SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME 0x04000000 /* report estimated link audio time */ +#define SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME 0x08000000 /* report synchronized audio/system time */ + +#define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */ +#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ + +#if (__BITS_PER_LONG == 32 && defined(__USE_TIME_BITS64)) || defined __KERNEL__ +#define __SND_STRUCT_TIME64 +#endif + +typedef int __bitwise snd_pcm_state_t; +#define SNDRV_PCM_STATE_OPEN ((snd_pcm_state_t) 0) /* stream is open */ +#define SNDRV_PCM_STATE_SETUP ((snd_pcm_state_t) 1) /* stream has a setup */ +#define SNDRV_PCM_STATE_PREPARED ((snd_pcm_state_t) 2) /* stream is ready to start */ +#define SNDRV_PCM_STATE_RUNNING ((snd_pcm_state_t) 3) /* stream is running */ +#define SNDRV_PCM_STATE_XRUN ((snd_pcm_state_t) 4) /* stream reached an xrun */ +#define SNDRV_PCM_STATE_DRAINING ((snd_pcm_state_t) 5) /* stream is draining */ +#define SNDRV_PCM_STATE_PAUSED ((snd_pcm_state_t) 6) /* stream is paused */ +#define SNDRV_PCM_STATE_SUSPENDED ((snd_pcm_state_t) 7) /* hardware is suspended */ +#define SNDRV_PCM_STATE_DISCONNECTED ((snd_pcm_state_t) 8) /* hardware is disconnected */ +#define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DISCONNECTED + +enum { + SNDRV_PCM_MMAP_OFFSET_DATA = 0x00000000, + SNDRV_PCM_MMAP_OFFSET_STATUS_OLD = 0x80000000, + SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD = 0x81000000, + SNDRV_PCM_MMAP_OFFSET_STATUS_NEW = 0x82000000, + SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW = 0x83000000, +#ifdef __SND_STRUCT_TIME64 + SNDRV_PCM_MMAP_OFFSET_STATUS = SNDRV_PCM_MMAP_OFFSET_STATUS_NEW, + SNDRV_PCM_MMAP_OFFSET_CONTROL = SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW, +#else + SNDRV_PCM_MMAP_OFFSET_STATUS = SNDRV_PCM_MMAP_OFFSET_STATUS_OLD, + SNDRV_PCM_MMAP_OFFSET_CONTROL = SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD, +#endif +}; + +union snd_pcm_sync_id { + unsigned char id[16]; + unsigned short id16[8]; + unsigned int id32[4]; +}; + +struct snd_pcm_info { + unsigned int device; /* RO/WR (control): device number */ + unsigned int subdevice; /* RO/WR (control): subdevice number */ + int stream; /* RO/WR (control): stream direction */ + int card; /* R: card number */ + unsigned char id[64]; /* ID (user selectable) */ + unsigned char name[80]; /* name of this device */ + unsigned char subname[32]; /* subdevice name */ + int dev_class; /* SNDRV_PCM_CLASS_* */ + int dev_subclass; /* SNDRV_PCM_SUBCLASS_* */ + unsigned int subdevices_count; + unsigned int subdevices_avail; + union snd_pcm_sync_id sync; /* hardware synchronization ID */ + unsigned char reserved[64]; /* reserved for future... */ +}; + +typedef int snd_pcm_hw_param_t; +#define SNDRV_PCM_HW_PARAM_ACCESS 0 /* Access type */ +#define SNDRV_PCM_HW_PARAM_FORMAT 1 /* Format */ +#define SNDRV_PCM_HW_PARAM_SUBFORMAT 2 /* Subformat */ +#define SNDRV_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_ACCESS +#define SNDRV_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_SUBFORMAT + +#define SNDRV_PCM_HW_PARAM_SAMPLE_BITS 8 /* Bits per sample */ +#define SNDRV_PCM_HW_PARAM_FRAME_BITS 9 /* Bits per frame */ +#define SNDRV_PCM_HW_PARAM_CHANNELS 10 /* Channels */ +#define SNDRV_PCM_HW_PARAM_RATE 11 /* Approx rate */ +#define SNDRV_PCM_HW_PARAM_PERIOD_TIME 12 /* Approx distance between + * interrupts in us + */ +#define SNDRV_PCM_HW_PARAM_PERIOD_SIZE 13 /* Approx frames between + * interrupts + */ +#define SNDRV_PCM_HW_PARAM_PERIOD_BYTES 14 /* Approx bytes between + * interrupts + */ +#define SNDRV_PCM_HW_PARAM_PERIODS 15 /* Approx interrupts per + * buffer + */ +#define SNDRV_PCM_HW_PARAM_BUFFER_TIME 16 /* Approx duration of buffer + * in us + */ +#define SNDRV_PCM_HW_PARAM_BUFFER_SIZE 17 /* Size of buffer in frames */ +#define SNDRV_PCM_HW_PARAM_BUFFER_BYTES 18 /* Size of buffer in bytes */ +#define SNDRV_PCM_HW_PARAM_TICK_TIME 19 /* Approx tick duration in us */ +#define SNDRV_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_SAMPLE_BITS +#define SNDRV_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_TICK_TIME + +#define SNDRV_PCM_HW_PARAMS_NORESAMPLE (1<<0) /* avoid rate resampling */ +#define SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER (1<<1) /* export buffer */ +#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP (1<<2) /* disable period wakeups */ + +struct snd_interval { + unsigned int min, max; + unsigned int openmin:1, + openmax:1, + integer:1, + empty:1; +}; + +#define SNDRV_MASK_MAX 256 + +struct snd_mask { + __u32 bits[(SNDRV_MASK_MAX+31)/32]; +}; + +struct snd_pcm_hw_params { + unsigned int flags; + struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - + SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; + struct snd_mask mres[5]; /* reserved masks */ + struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - + SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1]; + struct snd_interval ires[9]; /* reserved intervals */ + unsigned int rmask; /* W: requested masks */ + unsigned int cmask; /* R: changed masks */ + unsigned int info; /* R: Info flags for returned setup */ + unsigned int msbits; /* R: used most significant bits */ + unsigned int rate_num; /* R: rate numerator */ + unsigned int rate_den; /* R: rate denominator */ + snd_pcm_uframes_t fifo_size; /* R: chip FIFO size in frames */ + unsigned char reserved[64]; /* reserved for future */ +}; + +enum { + SNDRV_PCM_TSTAMP_NONE = 0, + SNDRV_PCM_TSTAMP_ENABLE, + SNDRV_PCM_TSTAMP_LAST = SNDRV_PCM_TSTAMP_ENABLE, +}; + +struct snd_pcm_sw_params { + int tstamp_mode; /* timestamp mode */ + unsigned int period_step; + unsigned int sleep_min; /* min ticks to sleep */ + snd_pcm_uframes_t avail_min; /* min avail frames for wakeup */ + snd_pcm_uframes_t xfer_align; /* obsolete: xfer size need to be a multiple */ + snd_pcm_uframes_t start_threshold; /* min hw_avail frames for automatic start */ + snd_pcm_uframes_t stop_threshold; /* min avail frames for automatic stop */ + snd_pcm_uframes_t silence_threshold; /* min distance from noise for silence filling */ + snd_pcm_uframes_t silence_size; /* silence block size */ + snd_pcm_uframes_t boundary; /* pointers wrap point */ + unsigned int proto; /* protocol version */ + unsigned int tstamp_type; /* timestamp type (req. proto >= 2.0.12) */ + unsigned char reserved[56]; /* reserved for future */ +}; + +struct snd_pcm_channel_info { + unsigned int channel; + __kernel_off_t offset; /* mmap offset */ + unsigned int first; /* offset to first sample in bits */ + unsigned int step; /* samples distance in bits */ +}; + +enum { + /* + * first definition for backwards compatibility only, + * maps to wallclock/link time for HDAudio playback and DEFAULT/DMA time for everything else + */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT = 0, + + /* timestamp definitions */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT = 1, /* DMA time, reported as per hw_ptr */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK = 2, /* link time reported by sample or wallclock counter, reset on startup */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE = 3, /* link time reported by sample or wallclock counter, not reset on startup */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED = 4, /* link time estimated indirectly */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED = 5, /* link time synchronized with system time */ + SNDRV_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED +}; + +/* explicit padding avoids incompatibility between i386 and x86-64 */ +typedef struct { unsigned char pad[sizeof(time_t) - sizeof(int)]; } __time_pad; + +struct snd_pcm_status { + snd_pcm_state_t state; /* stream state */ + __time_pad pad1; /* align to timespec */ + struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */ + struct timespec tstamp; /* reference timestamp */ + snd_pcm_uframes_t appl_ptr; /* appl ptr */ + snd_pcm_uframes_t hw_ptr; /* hw ptr */ + snd_pcm_sframes_t delay; /* current delay in frames */ + snd_pcm_uframes_t avail; /* number of frames available */ + snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */ + snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */ + snd_pcm_state_t suspended_state; /* suspended stream state */ + __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ + struct timespec audio_tstamp; /* sample counter, wall clock, PHC or on-demand sync'ed */ + struct timespec driver_tstamp; /* useful in case reference system tstamp is reported with delay */ + __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ + unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */ +}; + +/* + * For mmap operations, we need the 64-bit layout, both for compat mode, + * and for y2038 compatibility. For 64-bit applications, the two definitions + * are identical, so we keep the traditional version. + */ +#ifdef __SND_STRUCT_TIME64 +#define __snd_pcm_mmap_status64 snd_pcm_mmap_status +#define __snd_pcm_mmap_control64 snd_pcm_mmap_control +#define __snd_pcm_sync_ptr64 snd_pcm_sync_ptr +#define __snd_timespec64 timespec +struct __snd_timespec { + __s32 tv_sec; + __s32 tv_nsec; +}; +#else +#define __snd_pcm_mmap_status snd_pcm_mmap_status +#define __snd_pcm_mmap_control snd_pcm_mmap_control +#define __snd_pcm_sync_ptr snd_pcm_sync_ptr +#define __snd_timespec timespec +struct __snd_timespec64 { + __s64 tv_sec; + __s64 tv_nsec; +}; + +#endif + +struct __snd_pcm_mmap_status { + snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ + int pad1; /* Needed for 64 bit alignment */ + snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ + struct __snd_timespec tstamp; /* Timestamp */ + snd_pcm_state_t suspended_state; /* RO: suspended stream state */ + struct __snd_timespec audio_tstamp; /* from sample counter or wall clock */ +}; + +struct __snd_pcm_mmap_control { + snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ + snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ +}; + +#define SNDRV_PCM_SYNC_PTR_HWSYNC (1<<0) /* execute hwsync */ +#define SNDRV_PCM_SYNC_PTR_APPL (1<<1) /* get appl_ptr from driver (r/w op) */ +#define SNDRV_PCM_SYNC_PTR_AVAIL_MIN (1<<2) /* get avail_min from driver */ + +struct __snd_pcm_sync_ptr { + unsigned int flags; + union { + struct __snd_pcm_mmap_status status; + unsigned char reserved[64]; + } s; + union { + struct __snd_pcm_mmap_control control; + unsigned char reserved[64]; + } c; +}; + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN) +typedef char __pad_before_uframe[sizeof(__u64) - sizeof(snd_pcm_uframes_t)]; +typedef char __pad_after_uframe[0]; +#endif + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) +typedef char __pad_before_uframe[0]; +typedef char __pad_after_uframe[sizeof(__u64) - sizeof(snd_pcm_uframes_t)]; +#endif + +struct __snd_pcm_mmap_status64 { + snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ + __u32 pad1; /* Needed for 64 bit alignment */ + __pad_before_uframe __pad1; + snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ + __pad_after_uframe __pad2; + struct __snd_timespec64 tstamp; /* Timestamp */ + snd_pcm_state_t suspended_state;/* RO: suspended stream state */ + __u32 pad3; /* Needed for 64 bit alignment */ + struct __snd_timespec64 audio_tstamp; /* sample counter or wall clock */ +}; + +struct __snd_pcm_mmap_control64 { + __pad_before_uframe __pad1; + snd_pcm_uframes_t appl_ptr; /* RW: appl ptr (0...boundary-1) */ + __pad_before_uframe __pad2; + + __pad_before_uframe __pad3; + snd_pcm_uframes_t avail_min; /* RW: min available frames for wakeup */ + __pad_after_uframe __pad4; +}; + +struct __snd_pcm_sync_ptr64 { + __u32 flags; + __u32 pad1; + union { + struct __snd_pcm_mmap_status64 status; + unsigned char reserved[64]; + } s; + union { + struct __snd_pcm_mmap_control64 control; + unsigned char reserved[64]; + } c; +}; + +struct snd_xferi { + snd_pcm_sframes_t result; + void *buf; + snd_pcm_uframes_t frames; +}; + +struct snd_xfern { + snd_pcm_sframes_t result; + void * *bufs; + snd_pcm_uframes_t frames; +}; + +enum { + SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0, /* gettimeofday equivalent */ + SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, /* posix_clock_monotonic equivalent */ + SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, /* monotonic_raw (no NTP) */ + SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, +}; + +/* channel positions */ +enum { + SNDRV_CHMAP_UNKNOWN = 0, + SNDRV_CHMAP_NA, /* N/A, silent */ + SNDRV_CHMAP_MONO, /* mono stream */ + /* this follows the alsa-lib mixer channel value + 3 */ + SNDRV_CHMAP_FL, /* front left */ + SNDRV_CHMAP_FR, /* front right */ + SNDRV_CHMAP_RL, /* rear left */ + SNDRV_CHMAP_RR, /* rear right */ + SNDRV_CHMAP_FC, /* front center */ + SNDRV_CHMAP_LFE, /* LFE */ + SNDRV_CHMAP_SL, /* side left */ + SNDRV_CHMAP_SR, /* side right */ + SNDRV_CHMAP_RC, /* rear center */ + /* new definitions */ + SNDRV_CHMAP_FLC, /* front left center */ + SNDRV_CHMAP_FRC, /* front right center */ + SNDRV_CHMAP_RLC, /* rear left center */ + SNDRV_CHMAP_RRC, /* rear right center */ + SNDRV_CHMAP_FLW, /* front left wide */ + SNDRV_CHMAP_FRW, /* front right wide */ + SNDRV_CHMAP_FLH, /* front left high */ + SNDRV_CHMAP_FCH, /* front center high */ + SNDRV_CHMAP_FRH, /* front right high */ + SNDRV_CHMAP_TC, /* top center */ + SNDRV_CHMAP_TFL, /* top front left */ + SNDRV_CHMAP_TFR, /* top front right */ + SNDRV_CHMAP_TFC, /* top front center */ + SNDRV_CHMAP_TRL, /* top rear left */ + SNDRV_CHMAP_TRR, /* top rear right */ + SNDRV_CHMAP_TRC, /* top rear center */ + /* new definitions for UAC2 */ + SNDRV_CHMAP_TFLC, /* top front left center */ + SNDRV_CHMAP_TFRC, /* top front right center */ + SNDRV_CHMAP_TSL, /* top side left */ + SNDRV_CHMAP_TSR, /* top side right */ + SNDRV_CHMAP_LLFE, /* left LFE */ + SNDRV_CHMAP_RLFE, /* right LFE */ + SNDRV_CHMAP_BC, /* bottom center */ + SNDRV_CHMAP_BLC, /* bottom left center */ + SNDRV_CHMAP_BRC, /* bottom right center */ + SNDRV_CHMAP_LAST = SNDRV_CHMAP_BRC, +}; + +#define SNDRV_CHMAP_POSITION_MASK 0xffff +#define SNDRV_CHMAP_PHASE_INVERSE (0x01 << 16) +#define SNDRV_CHMAP_DRIVER_SPEC (0x02 << 16) + +#define SNDRV_PCM_IOCTL_PVERSION _IOR('A', 0x00, int) +#define SNDRV_PCM_IOCTL_INFO _IOR('A', 0x01, struct snd_pcm_info) +#define SNDRV_PCM_IOCTL_TSTAMP _IOW('A', 0x02, int) +#define SNDRV_PCM_IOCTL_TTSTAMP _IOW('A', 0x03, int) +#define SNDRV_PCM_IOCTL_USER_PVERSION _IOW('A', 0x04, int) +#define SNDRV_PCM_IOCTL_HW_REFINE _IOWR('A', 0x10, struct snd_pcm_hw_params) +#define SNDRV_PCM_IOCTL_HW_PARAMS _IOWR('A', 0x11, struct snd_pcm_hw_params) +#define SNDRV_PCM_IOCTL_HW_FREE _IO('A', 0x12) +#define SNDRV_PCM_IOCTL_SW_PARAMS _IOWR('A', 0x13, struct snd_pcm_sw_params) +#define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status) +#define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t) +#define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22) +#define __SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct __snd_pcm_sync_ptr) +#define __SNDRV_PCM_IOCTL_SYNC_PTR64 _IOWR('A', 0x23, struct __snd_pcm_sync_ptr64) +#define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr) +#define SNDRV_PCM_IOCTL_STATUS_EXT _IOWR('A', 0x24, struct snd_pcm_status) +#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info) +#define SNDRV_PCM_IOCTL_PREPARE _IO('A', 0x40) +#define SNDRV_PCM_IOCTL_RESET _IO('A', 0x41) +#define SNDRV_PCM_IOCTL_START _IO('A', 0x42) +#define SNDRV_PCM_IOCTL_DROP _IO('A', 0x43) +#define SNDRV_PCM_IOCTL_DRAIN _IO('A', 0x44) +#define SNDRV_PCM_IOCTL_PAUSE _IOW('A', 0x45, int) +#define SNDRV_PCM_IOCTL_REWIND _IOW('A', 0x46, snd_pcm_uframes_t) +#define SNDRV_PCM_IOCTL_RESUME _IO('A', 0x47) +#define SNDRV_PCM_IOCTL_XRUN _IO('A', 0x48) +#define SNDRV_PCM_IOCTL_FORWARD _IOW('A', 0x49, snd_pcm_uframes_t) +#define SNDRV_PCM_IOCTL_WRITEI_FRAMES _IOW('A', 0x50, struct snd_xferi) +#define SNDRV_PCM_IOCTL_READI_FRAMES _IOR('A', 0x51, struct snd_xferi) +#define SNDRV_PCM_IOCTL_WRITEN_FRAMES _IOW('A', 0x52, struct snd_xfern) +#define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern) +#define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int) +#define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61) + +/***************************************************************************** + * * + * MIDI v1.0 interface * + * * + *****************************************************************************/ + +/* + * Raw MIDI section - /dev/snd/midi?? + */ + +#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 1) + +enum { + SNDRV_RAWMIDI_STREAM_OUTPUT = 0, + SNDRV_RAWMIDI_STREAM_INPUT, + SNDRV_RAWMIDI_STREAM_LAST = SNDRV_RAWMIDI_STREAM_INPUT, +}; + +#define SNDRV_RAWMIDI_INFO_OUTPUT 0x00000001 +#define SNDRV_RAWMIDI_INFO_INPUT 0x00000002 +#define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004 + +struct snd_rawmidi_info { + unsigned int device; /* RO/WR (control): device number */ + unsigned int subdevice; /* RO/WR (control): subdevice number */ + int stream; /* WR: stream */ + int card; /* R: card number */ + unsigned int flags; /* SNDRV_RAWMIDI_INFO_XXXX */ + unsigned char id[64]; /* ID (user selectable) */ + unsigned char name[80]; /* name of device */ + unsigned char subname[32]; /* name of active or selected subdevice */ + unsigned int subdevices_count; + unsigned int subdevices_avail; + unsigned char reserved[64]; /* reserved for future use */ +}; + +struct snd_rawmidi_params { + int stream; + size_t buffer_size; /* queue size in bytes */ + size_t avail_min; /* minimum avail bytes for wakeup */ + unsigned int no_active_sensing: 1; /* do not send active sensing byte in close() */ + unsigned char reserved[16]; /* reserved for future use */ +}; + +struct snd_rawmidi_status { + int stream; + __time_pad pad1; + struct timespec tstamp; /* Timestamp */ + size_t avail; /* available bytes */ + size_t xruns; /* count of overruns since last status (in bytes) */ + unsigned char reserved[16]; /* reserved for future use */ +}; + +#define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int) +#define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info) +#define SNDRV_RAWMIDI_IOCTL_PARAMS _IOWR('W', 0x10, struct snd_rawmidi_params) +#define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status) +#define SNDRV_RAWMIDI_IOCTL_DROP _IOW('W', 0x30, int) +#define SNDRV_RAWMIDI_IOCTL_DRAIN _IOW('W', 0x31, int) + +/* + * Timer section - /dev/snd/timer + */ + +#define SNDRV_TIMER_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 7) + +enum { + SNDRV_TIMER_CLASS_NONE = -1, + SNDRV_TIMER_CLASS_SLAVE = 0, + SNDRV_TIMER_CLASS_GLOBAL, + SNDRV_TIMER_CLASS_CARD, + SNDRV_TIMER_CLASS_PCM, + SNDRV_TIMER_CLASS_LAST = SNDRV_TIMER_CLASS_PCM, +}; + +/* slave timer classes */ +enum { + SNDRV_TIMER_SCLASS_NONE = 0, + SNDRV_TIMER_SCLASS_APPLICATION, + SNDRV_TIMER_SCLASS_SEQUENCER, /* alias */ + SNDRV_TIMER_SCLASS_OSS_SEQUENCER, /* alias */ + SNDRV_TIMER_SCLASS_LAST = SNDRV_TIMER_SCLASS_OSS_SEQUENCER, +}; + +/* global timers (device member) */ +#define SNDRV_TIMER_GLOBAL_SYSTEM 0 +#define SNDRV_TIMER_GLOBAL_RTC 1 /* unused */ +#define SNDRV_TIMER_GLOBAL_HPET 2 +#define SNDRV_TIMER_GLOBAL_HRTIMER 3 + +/* info flags */ +#define SNDRV_TIMER_FLG_SLAVE (1<<0) /* cannot be controlled */ + +struct snd_timer_id { + int dev_class; + int dev_sclass; + int card; + int device; + int subdevice; +}; + +struct snd_timer_ginfo { + struct snd_timer_id tid; /* requested timer ID */ + unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */ + int card; /* card number */ + unsigned char id[64]; /* timer identification */ + unsigned char name[80]; /* timer name */ + unsigned long reserved0; /* reserved for future use */ + unsigned long resolution; /* average period resolution in ns */ + unsigned long resolution_min; /* minimal period resolution in ns */ + unsigned long resolution_max; /* maximal period resolution in ns */ + unsigned int clients; /* active timer clients */ + unsigned char reserved[32]; +}; + +struct snd_timer_gparams { + struct snd_timer_id tid; /* requested timer ID */ + unsigned long period_num; /* requested precise period duration (in seconds) - numerator */ + unsigned long period_den; /* requested precise period duration (in seconds) - denominator */ + unsigned char reserved[32]; +}; + +struct snd_timer_gstatus { + struct snd_timer_id tid; /* requested timer ID */ + unsigned long resolution; /* current period resolution in ns */ + unsigned long resolution_num; /* precise current period resolution (in seconds) - numerator */ + unsigned long resolution_den; /* precise current period resolution (in seconds) - denominator */ + unsigned char reserved[32]; +}; + +struct snd_timer_select { + struct snd_timer_id id; /* bind to timer ID */ + unsigned char reserved[32]; /* reserved */ +}; + +struct snd_timer_info { + unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */ + int card; /* card number */ + unsigned char id[64]; /* timer identificator */ + unsigned char name[80]; /* timer name */ + unsigned long reserved0; /* reserved for future use */ + unsigned long resolution; /* average period resolution in ns */ + unsigned char reserved[64]; /* reserved */ +}; + +#define SNDRV_TIMER_PSFLG_AUTO (1<<0) /* auto start, otherwise one-shot */ +#define SNDRV_TIMER_PSFLG_EXCLUSIVE (1<<1) /* exclusive use, precise start/stop/pause/continue */ +#define SNDRV_TIMER_PSFLG_EARLY_EVENT (1<<2) /* write early event to the poll queue */ + +struct snd_timer_params { + unsigned int flags; /* flags - SNDRV_TIMER_PSFLG_* */ + unsigned int ticks; /* requested resolution in ticks */ + unsigned int queue_size; /* total size of queue (32-1024) */ + unsigned int reserved0; /* reserved, was: failure locations */ + unsigned int filter; /* event filter (bitmask of SNDRV_TIMER_EVENT_*) */ + unsigned char reserved[60]; /* reserved */ +}; + +struct snd_timer_status { + struct timespec tstamp; /* Timestamp - last update */ + unsigned int resolution; /* current period resolution in ns */ + unsigned int lost; /* counter of master tick lost */ + unsigned int overrun; /* count of read queue overruns */ + unsigned int queue; /* used queue size */ + unsigned char reserved[64]; /* reserved */ +}; + +#define SNDRV_TIMER_IOCTL_PVERSION _IOR('T', 0x00, int) +#define SNDRV_TIMER_IOCTL_NEXT_DEVICE _IOWR('T', 0x01, struct snd_timer_id) +#define SNDRV_TIMER_IOCTL_TREAD_OLD _IOW('T', 0x02, int) +#define SNDRV_TIMER_IOCTL_GINFO _IOWR('T', 0x03, struct snd_timer_ginfo) +#define SNDRV_TIMER_IOCTL_GPARAMS _IOW('T', 0x04, struct snd_timer_gparams) +#define SNDRV_TIMER_IOCTL_GSTATUS _IOWR('T', 0x05, struct snd_timer_gstatus) +#define SNDRV_TIMER_IOCTL_SELECT _IOW('T', 0x10, struct snd_timer_select) +#define SNDRV_TIMER_IOCTL_INFO _IOR('T', 0x11, struct snd_timer_info) +#define SNDRV_TIMER_IOCTL_PARAMS _IOW('T', 0x12, struct snd_timer_params) +#define SNDRV_TIMER_IOCTL_STATUS _IOR('T', 0x14, struct snd_timer_status) +/* The following four ioctls are changed since 1.0.9 due to confliction */ +#define SNDRV_TIMER_IOCTL_START _IO('T', 0xa0) +#define SNDRV_TIMER_IOCTL_STOP _IO('T', 0xa1) +#define SNDRV_TIMER_IOCTL_CONTINUE _IO('T', 0xa2) +#define SNDRV_TIMER_IOCTL_PAUSE _IO('T', 0xa3) +#define SNDRV_TIMER_IOCTL_TREAD64 _IOW('T', 0xa4, int) + +#if __BITS_PER_LONG == 64 +#define SNDRV_TIMER_IOCTL_TREAD SNDRV_TIMER_IOCTL_TREAD_OLD +#else +#define SNDRV_TIMER_IOCTL_TREAD ((sizeof(__kernel_long_t) >= sizeof(time_t)) ? \ + SNDRV_TIMER_IOCTL_TREAD_OLD : \ + SNDRV_TIMER_IOCTL_TREAD64) +#endif + +struct snd_timer_read { + unsigned int resolution; + unsigned int ticks; +}; + +enum { + SNDRV_TIMER_EVENT_RESOLUTION = 0, /* val = resolution in ns */ + SNDRV_TIMER_EVENT_TICK, /* val = ticks */ + SNDRV_TIMER_EVENT_START, /* val = resolution in ns */ + SNDRV_TIMER_EVENT_STOP, /* val = 0 */ + SNDRV_TIMER_EVENT_CONTINUE, /* val = resolution in ns */ + SNDRV_TIMER_EVENT_PAUSE, /* val = 0 */ + SNDRV_TIMER_EVENT_EARLY, /* val = 0, early event */ + SNDRV_TIMER_EVENT_SUSPEND, /* val = 0 */ + SNDRV_TIMER_EVENT_RESUME, /* val = resolution in ns */ + /* master timer events for slave timer instances */ + SNDRV_TIMER_EVENT_MSTART = SNDRV_TIMER_EVENT_START + 10, + SNDRV_TIMER_EVENT_MSTOP = SNDRV_TIMER_EVENT_STOP + 10, + SNDRV_TIMER_EVENT_MCONTINUE = SNDRV_TIMER_EVENT_CONTINUE + 10, + SNDRV_TIMER_EVENT_MPAUSE = SNDRV_TIMER_EVENT_PAUSE + 10, + SNDRV_TIMER_EVENT_MSUSPEND = SNDRV_TIMER_EVENT_SUSPEND + 10, + SNDRV_TIMER_EVENT_MRESUME = SNDRV_TIMER_EVENT_RESUME + 10, +}; + +struct snd_timer_tread { + int event; + __time_pad pad1; + struct timespec tstamp; + unsigned int val; + __time_pad pad2; +}; + +/**************************************************************************** + * * + * Section for driver control interface - /dev/snd/control? * + * * + ****************************************************************************/ + +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 8) + +struct snd_ctl_card_info { + int card; /* card number */ + int pad; /* reserved for future (was type) */ + unsigned char id[16]; /* ID of card (user selectable) */ + unsigned char driver[16]; /* Driver name */ + unsigned char name[32]; /* Short name of soundcard */ + unsigned char longname[80]; /* name + info text about soundcard */ + unsigned char reserved_[16]; /* reserved for future (was ID of mixer) */ + unsigned char mixername[80]; /* visual mixer identification */ + unsigned char components[128]; /* card components / fine identification, delimited with one space (AC97 etc..) */ +}; + +typedef int __bitwise snd_ctl_elem_type_t; +#define SNDRV_CTL_ELEM_TYPE_NONE ((snd_ctl_elem_type_t) 0) /* invalid */ +#define SNDRV_CTL_ELEM_TYPE_BOOLEAN ((snd_ctl_elem_type_t) 1) /* boolean type */ +#define SNDRV_CTL_ELEM_TYPE_INTEGER ((snd_ctl_elem_type_t) 2) /* integer type */ +#define SNDRV_CTL_ELEM_TYPE_ENUMERATED ((snd_ctl_elem_type_t) 3) /* enumerated type */ +#define SNDRV_CTL_ELEM_TYPE_BYTES ((snd_ctl_elem_type_t) 4) /* byte array */ +#define SNDRV_CTL_ELEM_TYPE_IEC958 ((snd_ctl_elem_type_t) 5) /* IEC958 (S/PDIF) setup */ +#define SNDRV_CTL_ELEM_TYPE_INTEGER64 ((snd_ctl_elem_type_t) 6) /* 64-bit integer type */ +#define SNDRV_CTL_ELEM_TYPE_LAST SNDRV_CTL_ELEM_TYPE_INTEGER64 + +typedef int __bitwise snd_ctl_elem_iface_t; +#define SNDRV_CTL_ELEM_IFACE_CARD ((snd_ctl_elem_iface_t) 0) /* global control */ +#define SNDRV_CTL_ELEM_IFACE_HWDEP ((snd_ctl_elem_iface_t) 1) /* hardware dependent device */ +#define SNDRV_CTL_ELEM_IFACE_MIXER ((snd_ctl_elem_iface_t) 2) /* virtual mixer device */ +#define SNDRV_CTL_ELEM_IFACE_PCM ((snd_ctl_elem_iface_t) 3) /* PCM device */ +#define SNDRV_CTL_ELEM_IFACE_RAWMIDI ((snd_ctl_elem_iface_t) 4) /* RawMidi device */ +#define SNDRV_CTL_ELEM_IFACE_TIMER ((snd_ctl_elem_iface_t) 5) /* timer device */ +#define SNDRV_CTL_ELEM_IFACE_SEQUENCER ((snd_ctl_elem_iface_t) 6) /* sequencer client */ +#define SNDRV_CTL_ELEM_IFACE_LAST SNDRV_CTL_ELEM_IFACE_SEQUENCER + +#define SNDRV_CTL_ELEM_ACCESS_READ (1<<0) +#define SNDRV_CTL_ELEM_ACCESS_WRITE (1<<1) +#define SNDRV_CTL_ELEM_ACCESS_READWRITE (SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE) +#define SNDRV_CTL_ELEM_ACCESS_VOLATILE (1<<2) /* control value may be changed without a notification */ +// (1 << 3) is unused. +#define SNDRV_CTL_ELEM_ACCESS_TLV_READ (1<<4) /* TLV read is possible */ +#define SNDRV_CTL_ELEM_ACCESS_TLV_WRITE (1<<5) /* TLV write is possible */ +#define SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE (SNDRV_CTL_ELEM_ACCESS_TLV_READ|SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) +#define SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND (1<<6) /* TLV command is possible */ +#define SNDRV_CTL_ELEM_ACCESS_INACTIVE (1<<8) /* control does actually nothing, but may be updated */ +#define SNDRV_CTL_ELEM_ACCESS_LOCK (1<<9) /* write lock */ +#define SNDRV_CTL_ELEM_ACCESS_OWNER (1<<10) /* write lock owner */ +#define SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK (1<<28) /* kernel use a TLV callback */ +#define SNDRV_CTL_ELEM_ACCESS_USER (1<<29) /* user space element */ +/* bits 30 and 31 are obsoleted (for indirect access) */ + +/* for further details see the ACPI and PCI power management specification */ +#define SNDRV_CTL_POWER_D0 0x0000 /* full On */ +#define SNDRV_CTL_POWER_D1 0x0100 /* partial On */ +#define SNDRV_CTL_POWER_D2 0x0200 /* partial On */ +#define SNDRV_CTL_POWER_D3 0x0300 /* Off */ +#define SNDRV_CTL_POWER_D3hot (SNDRV_CTL_POWER_D3|0x0000) /* Off, with power */ +#define SNDRV_CTL_POWER_D3cold (SNDRV_CTL_POWER_D3|0x0001) /* Off, without power */ + +#define SNDRV_CTL_ELEM_ID_NAME_MAXLEN 44 + +struct snd_ctl_elem_id { + unsigned int numid; /* numeric identifier, zero = invalid */ + snd_ctl_elem_iface_t iface; /* interface identifier */ + unsigned int device; /* device/client number */ + unsigned int subdevice; /* subdevice (substream) number */ + unsigned char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* ASCII name of item */ + unsigned int index; /* index of item */ +}; + +struct snd_ctl_elem_list { + unsigned int offset; /* W: first element ID to get */ + unsigned int space; /* W: count of element IDs to get */ + unsigned int used; /* R: count of element IDs set */ + unsigned int count; /* R: count of all elements */ + struct snd_ctl_elem_id *pids; /* R: IDs */ + unsigned char reserved[50]; +}; + +struct snd_ctl_elem_info { + struct snd_ctl_elem_id id; /* W: element ID */ + snd_ctl_elem_type_t type; /* R: value type - SNDRV_CTL_ELEM_TYPE_* */ + unsigned int access; /* R: value access (bitmask) - SNDRV_CTL_ELEM_ACCESS_* */ + unsigned int count; /* count of values */ + __kernel_pid_t owner; /* owner's PID of this control */ + union { + struct { + long min; /* R: minimum value */ + long max; /* R: maximum value */ + long step; /* R: step (0 variable) */ + } integer; + struct { + long long min; /* R: minimum value */ + long long max; /* R: maximum value */ + long long step; /* R: step (0 variable) */ + } integer64; + struct { + unsigned int items; /* R: number of items */ + unsigned int item; /* W: item number */ + char name[64]; /* R: value name */ + __u64 names_ptr; /* W: names list (ELEM_ADD only) */ + unsigned int names_length; + } enumerated; + unsigned char reserved[128]; + } value; + unsigned char reserved[64]; +}; + +struct snd_ctl_elem_value { + struct snd_ctl_elem_id id; /* W: element ID */ + unsigned int indirect: 1; /* W: indirect access - obsoleted */ + union { + union { + long value[128]; + long *value_ptr; /* obsoleted */ + } integer; + union { + long long value[64]; + long long *value_ptr; /* obsoleted */ + } integer64; + union { + unsigned int item[128]; + unsigned int *item_ptr; /* obsoleted */ + } enumerated; + union { + unsigned char data[512]; + unsigned char *data_ptr; /* obsoleted */ + } bytes; + struct snd_aes_iec958 iec958; + } value; /* RO */ + unsigned char reserved[128]; +}; + +struct snd_ctl_tlv { + unsigned int numid; /* control element numeric identification */ + unsigned int length; /* in bytes aligned to 4 */ + unsigned int tlv[0]; /* first TLV */ +}; + +#define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int) +#define SNDRV_CTL_IOCTL_CARD_INFO _IOR('U', 0x01, struct snd_ctl_card_info) +#define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list) +#define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info) +#define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value) +#define SNDRV_CTL_IOCTL_ELEM_WRITE _IOWR('U', 0x13, struct snd_ctl_elem_value) +#define SNDRV_CTL_IOCTL_ELEM_LOCK _IOW('U', 0x14, struct snd_ctl_elem_id) +#define SNDRV_CTL_IOCTL_ELEM_UNLOCK _IOW('U', 0x15, struct snd_ctl_elem_id) +#define SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS _IOWR('U', 0x16, int) +#define SNDRV_CTL_IOCTL_ELEM_ADD _IOWR('U', 0x17, struct snd_ctl_elem_info) +#define SNDRV_CTL_IOCTL_ELEM_REPLACE _IOWR('U', 0x18, struct snd_ctl_elem_info) +#define SNDRV_CTL_IOCTL_ELEM_REMOVE _IOWR('U', 0x19, struct snd_ctl_elem_id) +#define SNDRV_CTL_IOCTL_TLV_READ _IOWR('U', 0x1a, struct snd_ctl_tlv) +#define SNDRV_CTL_IOCTL_TLV_WRITE _IOWR('U', 0x1b, struct snd_ctl_tlv) +#define SNDRV_CTL_IOCTL_TLV_COMMAND _IOWR('U', 0x1c, struct snd_ctl_tlv) +#define SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE _IOWR('U', 0x20, int) +#define SNDRV_CTL_IOCTL_HWDEP_INFO _IOR('U', 0x21, struct snd_hwdep_info) +#define SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE _IOR('U', 0x30, int) +#define SNDRV_CTL_IOCTL_PCM_INFO _IOWR('U', 0x31, struct snd_pcm_info) +#define SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE _IOW('U', 0x32, int) +#define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int) +#define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info) +#define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int) +#define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int) +#define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int) + +/* + * Read interface. + */ + +enum sndrv_ctl_event_type { + SNDRV_CTL_EVENT_ELEM = 0, + SNDRV_CTL_EVENT_LAST = SNDRV_CTL_EVENT_ELEM, +}; + +#define SNDRV_CTL_EVENT_MASK_VALUE (1<<0) /* element value was changed */ +#define SNDRV_CTL_EVENT_MASK_INFO (1<<1) /* element info was changed */ +#define SNDRV_CTL_EVENT_MASK_ADD (1<<2) /* element was added */ +#define SNDRV_CTL_EVENT_MASK_TLV (1<<3) /* element TLV tree was changed */ +#define SNDRV_CTL_EVENT_MASK_REMOVE (~0U) /* element was removed */ + +struct snd_ctl_event { + int type; /* event type - SNDRV_CTL_EVENT_* */ + union { + struct { + unsigned int mask; + struct snd_ctl_elem_id id; + } elem; + unsigned char data8[60]; + } data; +}; + +/* + * Control names + */ + +#define SNDRV_CTL_NAME_NONE "" +#define SNDRV_CTL_NAME_PLAYBACK "Playback " +#define SNDRV_CTL_NAME_CAPTURE "Capture " + +#define SNDRV_CTL_NAME_IEC958_NONE "" +#define SNDRV_CTL_NAME_IEC958_SWITCH "Switch" +#define SNDRV_CTL_NAME_IEC958_VOLUME "Volume" +#define SNDRV_CTL_NAME_IEC958_DEFAULT "Default" +#define SNDRV_CTL_NAME_IEC958_MASK "Mask" +#define SNDRV_CTL_NAME_IEC958_CON_MASK "Con Mask" +#define SNDRV_CTL_NAME_IEC958_PRO_MASK "Pro Mask" +#define SNDRV_CTL_NAME_IEC958_PCM_STREAM "PCM Stream" +#define SNDRV_CTL_NAME_IEC958(expl,direction,what) "IEC958 " expl SNDRV_CTL_NAME_##direction SNDRV_CTL_NAME_IEC958_##what + +#endif /* __SOUND_ASOUND_H */ diff --git a/include/sound/uapi/asound_fm.h b/include/sound/uapi/asound_fm.h new file mode 100644 index 0000000..8471f40 --- /dev/null +++ b/include/sound/uapi/asound_fm.h @@ -0,0 +1,135 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef __SOUND_ASOUND_FM_H +#define __SOUND_ASOUND_FM_H + +/* + * Advanced Linux Sound Architecture - ALSA + * + * Interface file between ALSA driver & user space + * Copyright (c) 1994-98 by Jaroslav Kysela , + * 4Front Technologies + * + * Direct FM control + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#define SNDRV_DM_FM_MODE_OPL2 0x00 +#define SNDRV_DM_FM_MODE_OPL3 0x01 + +struct snd_dm_fm_info { + unsigned char fm_mode; /* OPL mode, see SNDRV_DM_FM_MODE_XXX */ + unsigned char rhythm; /* percussion mode flag */ +}; + +/* + * Data structure composing an FM "note" or sound event. + */ + +struct snd_dm_fm_voice { + unsigned char op; /* operator cell (0 or 1) */ + unsigned char voice; /* FM voice (0 to 17) */ + + unsigned char am; /* amplitude modulation */ + unsigned char vibrato; /* vibrato effect */ + unsigned char do_sustain; /* sustain phase */ + unsigned char kbd_scale; /* keyboard scaling */ + unsigned char harmonic; /* 4 bits: harmonic and multiplier */ + unsigned char scale_level; /* 2 bits: decrease output freq rises */ + unsigned char volume; /* 6 bits: volume */ + + unsigned char attack; /* 4 bits: attack rate */ + unsigned char decay; /* 4 bits: decay rate */ + unsigned char sustain; /* 4 bits: sustain level */ + unsigned char release; /* 4 bits: release rate */ + + unsigned char feedback; /* 3 bits: feedback for op0 */ + unsigned char connection; /* 0 for serial, 1 for parallel */ + unsigned char left; /* stereo left */ + unsigned char right; /* stereo right */ + unsigned char waveform; /* 3 bits: waveform shape */ +}; + +/* + * This describes an FM note by its voice, octave, frequency number (10bit) + * and key on/off. + */ + +struct snd_dm_fm_note { + unsigned char voice; /* 0-17 voice channel */ + unsigned char octave; /* 3 bits: what octave to play */ + unsigned int fnum; /* 10 bits: frequency number */ + unsigned char key_on; /* set for active, clear for silent */ +}; + +/* + * FM parameters that apply globally to all voices, and thus are not "notes" + */ + +struct snd_dm_fm_params { + unsigned char am_depth; /* amplitude modulation depth (1=hi) */ + unsigned char vib_depth; /* vibrato depth (1=hi) */ + unsigned char kbd_split; /* keyboard split */ + unsigned char rhythm; /* percussion mode select */ + + /* This block is the percussion instrument data */ + unsigned char bass; + unsigned char snare; + unsigned char tomtom; + unsigned char cymbal; + unsigned char hihat; +}; + +/* + * FM mode ioctl settings + */ + +#define SNDRV_DM_FM_IOCTL_INFO _IOR('H', 0x20, struct snd_dm_fm_info) +#define SNDRV_DM_FM_IOCTL_RESET _IO ('H', 0x21) +#define SNDRV_DM_FM_IOCTL_PLAY_NOTE _IOW('H', 0x22, struct snd_dm_fm_note) +#define SNDRV_DM_FM_IOCTL_SET_VOICE _IOW('H', 0x23, struct snd_dm_fm_voice) +#define SNDRV_DM_FM_IOCTL_SET_PARAMS _IOW('H', 0x24, struct snd_dm_fm_params) +#define SNDRV_DM_FM_IOCTL_SET_MODE _IOW('H', 0x25, int) +/* for OPL3 only */ +#define SNDRV_DM_FM_IOCTL_SET_CONNECTION _IOW('H', 0x26, int) +/* SBI patch management */ +#define SNDRV_DM_FM_IOCTL_CLEAR_PATCHES _IO ('H', 0x40) + +#define SNDRV_DM_FM_OSS_IOCTL_RESET 0x20 +#define SNDRV_DM_FM_OSS_IOCTL_PLAY_NOTE 0x21 +#define SNDRV_DM_FM_OSS_IOCTL_SET_VOICE 0x22 +#define SNDRV_DM_FM_OSS_IOCTL_SET_PARAMS 0x23 +#define SNDRV_DM_FM_OSS_IOCTL_SET_MODE 0x24 +#define SNDRV_DM_FM_OSS_IOCTL_SET_OPL 0x25 + +/* + * Patch Record - fixed size for write + */ + +#define FM_KEY_SBI "SBI\032" +#define FM_KEY_2OP "2OP\032" +#define FM_KEY_4OP "4OP\032" + +struct sbi_patch { + unsigned char prog; + unsigned char bank; + char key[4]; + char name[25]; + char extension[7]; + unsigned char data[32]; +}; + +#endif /* __SOUND_ASOUND_FM_H */ diff --git a/include/sound/uapi/emu10k1.h b/include/sound/uapi/emu10k1.h new file mode 100644 index 0000000..78d794c --- /dev/null +++ b/include/sound/uapi/emu10k1.h @@ -0,0 +1,387 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Copyright (c) by Jaroslav Kysela , + * Creative Labs, Inc. + * Definitions for EMU10K1 (SB Live!) chips + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef __SOUND_EMU10K1_H +#define __SOUND_EMU10K1_H + +#ifdef __linux__ +#include +#endif + +/* + * ---- FX8010 ---- + */ + +#define EMU10K1_CARD_CREATIVE 0x00000000 +#define EMU10K1_CARD_EMUAPS 0x00000001 + +#define EMU10K1_FX8010_PCM_COUNT 8 + +/* + * Following definition is copied from linux/types.h to support compiling + * this header file in userspace since they are not generally available for + * uapi headers. + */ +#define __EMU10K1_DECLARE_BITMAP(name,bits) \ + unsigned long name[(bits) / (sizeof(unsigned long) * 8)] + +/* instruction set */ +#define iMAC0 0x00 /* R = A + (X * Y >> 31) ; saturation */ +#define iMAC1 0x01 /* R = A + (-X * Y >> 31) ; saturation */ +#define iMAC2 0x02 /* R = A + (X * Y >> 31) ; wraparound */ +#define iMAC3 0x03 /* R = A + (-X * Y >> 31) ; wraparound */ +#define iMACINT0 0x04 /* R = A + X * Y ; saturation */ +#define iMACINT1 0x05 /* R = A + X * Y ; wraparound (31-bit) */ +#define iACC3 0x06 /* R = A + X + Y ; saturation */ +#define iMACMV 0x07 /* R = A, acc += X * Y >> 31 */ +#define iANDXOR 0x08 /* R = (A & X) ^ Y */ +#define iTSTNEG 0x09 /* R = (A >= Y) ? X : ~X */ +#define iLIMITGE 0x0a /* R = (A >= Y) ? X : Y */ +#define iLIMITLT 0x0b /* R = (A < Y) ? X : Y */ +#define iLOG 0x0c /* R = linear_data, A (log_data), X (max_exp), Y (format_word) */ +#define iEXP 0x0d /* R = log_data, A (linear_data), X (max_exp), Y (format_word) */ +#define iINTERP 0x0e /* R = A + (X * (Y - A) >> 31) ; saturation */ +#define iSKIP 0x0f /* R = A (cc_reg), X (count), Y (cc_test) */ + +/* GPRs */ +#define FXBUS(x) (0x00 + (x)) /* x = 0x00 - 0x0f */ +#define EXTIN(x) (0x10 + (x)) /* x = 0x00 - 0x0f */ +#define EXTOUT(x) (0x20 + (x)) /* x = 0x00 - 0x0f physical outs -> FXWC low 16 bits */ +#define FXBUS2(x) (0x30 + (x)) /* x = 0x00 - 0x0f copies of fx buses for capture -> FXWC high 16 bits */ + /* NB: 0x31 and 0x32 are shared with Center/LFE on SB live 5.1 */ + +#define C_00000000 0x40 +#define C_00000001 0x41 +#define C_00000002 0x42 +#define C_00000003 0x43 +#define C_00000004 0x44 +#define C_00000008 0x45 +#define C_00000010 0x46 +#define C_00000020 0x47 +#define C_00000100 0x48 +#define C_00010000 0x49 +#define C_00080000 0x4a +#define C_10000000 0x4b +#define C_20000000 0x4c +#define C_40000000 0x4d +#define C_80000000 0x4e +#define C_7fffffff 0x4f +#define C_ffffffff 0x50 +#define C_fffffffe 0x51 +#define C_c0000000 0x52 +#define C_4f1bbcdc 0x53 +#define C_5a7ef9db 0x54 +#define C_00100000 0x55 /* ?? */ +#define GPR_ACCU 0x56 /* ACCUM, accumulator */ +#define GPR_COND 0x57 /* CCR, condition register */ +#define GPR_NOISE0 0x58 /* noise source */ +#define GPR_NOISE1 0x59 /* noise source */ +#define GPR_IRQ 0x5a /* IRQ register */ +#define GPR_DBAC 0x5b /* TRAM Delay Base Address Counter */ +#define GPR(x) (FXGPREGBASE + (x)) /* free GPRs: x = 0x00 - 0xff */ +#define ITRAM_DATA(x) (TANKMEMDATAREGBASE + 0x00 + (x)) /* x = 0x00 - 0x7f */ +#define ETRAM_DATA(x) (TANKMEMDATAREGBASE + 0x80 + (x)) /* x = 0x00 - 0x1f */ +#define ITRAM_ADDR(x) (TANKMEMADDRREGBASE + 0x00 + (x)) /* x = 0x00 - 0x7f */ +#define ETRAM_ADDR(x) (TANKMEMADDRREGBASE + 0x80 + (x)) /* x = 0x00 - 0x1f */ + +#define A_ITRAM_DATA(x) (TANKMEMDATAREGBASE + 0x00 + (x)) /* x = 0x00 - 0xbf */ +#define A_ETRAM_DATA(x) (TANKMEMDATAREGBASE + 0xc0 + (x)) /* x = 0x00 - 0x3f */ +#define A_ITRAM_ADDR(x) (TANKMEMADDRREGBASE + 0x00 + (x)) /* x = 0x00 - 0xbf */ +#define A_ETRAM_ADDR(x) (TANKMEMADDRREGBASE + 0xc0 + (x)) /* x = 0x00 - 0x3f */ +#define A_ITRAM_CTL(x) (A_TANKMEMCTLREGBASE + 0x00 + (x)) /* x = 0x00 - 0xbf */ +#define A_ETRAM_CTL(x) (A_TANKMEMCTLREGBASE + 0xc0 + (x)) /* x = 0x00 - 0x3f */ + +#define A_FXBUS(x) (0x00 + (x)) /* x = 0x00 - 0x3f FX buses */ +#define A_EXTIN(x) (0x40 + (x)) /* x = 0x00 - 0x0f physical ins */ +#define A_P16VIN(x) (0x50 + (x)) /* x = 0x00 - 0x0f p16v ins (A2 only) "EMU32 inputs" */ +#define A_EXTOUT(x) (0x60 + (x)) /* x = 0x00 - 0x1f physical outs -> A_FXWC1 0x79-7f unknown */ +#define A_FXBUS2(x) (0x80 + (x)) /* x = 0x00 - 0x1f extra outs used for EFX capture -> A_FXWC2 */ +#define A_EMU32OUTH(x) (0xa0 + (x)) /* x = 0x00 - 0x0f "EMU32_OUT_10 - _1F" - ??? */ +#define A_EMU32OUTL(x) (0xb0 + (x)) /* x = 0x00 - 0x0f "EMU32_OUT_1 - _F" - ??? */ +#define A3_EMU32IN(x) (0x160 + (x)) /* x = 0x00 - 0x3f "EMU32_IN_00 - _3F" - Only when .device = 0x0008 */ +#define A3_EMU32OUT(x) (0x1E0 + (x)) /* x = 0x00 - 0x0f "EMU32_OUT_00 - _3F" - Only when .device = 0x0008 */ +#define A_GPR(x) (A_FXGPREGBASE + (x)) + +/* cc_reg constants */ +#define CC_REG_NORMALIZED C_00000001 +#define CC_REG_BORROW C_00000002 +#define CC_REG_MINUS C_00000004 +#define CC_REG_ZERO C_00000008 +#define CC_REG_SATURATE C_00000010 +#define CC_REG_NONZERO C_00000100 + +/* FX buses */ +#define FXBUS_PCM_LEFT 0x00 +#define FXBUS_PCM_RIGHT 0x01 +#define FXBUS_PCM_LEFT_REAR 0x02 +#define FXBUS_PCM_RIGHT_REAR 0x03 +#define FXBUS_MIDI_LEFT 0x04 +#define FXBUS_MIDI_RIGHT 0x05 +#define FXBUS_PCM_CENTER 0x06 +#define FXBUS_PCM_LFE 0x07 +#define FXBUS_PCM_LEFT_FRONT 0x08 +#define FXBUS_PCM_RIGHT_FRONT 0x09 +#define FXBUS_MIDI_REVERB 0x0c +#define FXBUS_MIDI_CHORUS 0x0d +#define FXBUS_PCM_LEFT_SIDE 0x0e +#define FXBUS_PCM_RIGHT_SIDE 0x0f +#define FXBUS_PT_LEFT 0x14 +#define FXBUS_PT_RIGHT 0x15 + +/* Inputs */ +#define EXTIN_AC97_L 0x00 /* AC'97 capture channel - left */ +#define EXTIN_AC97_R 0x01 /* AC'97 capture channel - right */ +#define EXTIN_SPDIF_CD_L 0x02 /* internal S/PDIF CD - onboard - left */ +#define EXTIN_SPDIF_CD_R 0x03 /* internal S/PDIF CD - onboard - right */ +#define EXTIN_ZOOM_L 0x04 /* Zoom Video I2S - left */ +#define EXTIN_ZOOM_R 0x05 /* Zoom Video I2S - right */ +#define EXTIN_TOSLINK_L 0x06 /* LiveDrive - TOSLink Optical - left */ +#define EXTIN_TOSLINK_R 0x07 /* LiveDrive - TOSLink Optical - right */ +#define EXTIN_LINE1_L 0x08 /* LiveDrive - Line/Mic 1 - left */ +#define EXTIN_LINE1_R 0x09 /* LiveDrive - Line/Mic 1 - right */ +#define EXTIN_COAX_SPDIF_L 0x0a /* LiveDrive - Coaxial S/PDIF - left */ +#define EXTIN_COAX_SPDIF_R 0x0b /* LiveDrive - Coaxial S/PDIF - right */ +#define EXTIN_LINE2_L 0x0c /* LiveDrive - Line/Mic 2 - left */ +#define EXTIN_LINE2_R 0x0d /* LiveDrive - Line/Mic 2 - right */ + +/* Outputs */ +#define EXTOUT_AC97_L 0x00 /* AC'97 playback channel - left */ +#define EXTOUT_AC97_R 0x01 /* AC'97 playback channel - right */ +#define EXTOUT_TOSLINK_L 0x02 /* LiveDrive - TOSLink Optical - left */ +#define EXTOUT_TOSLINK_R 0x03 /* LiveDrive - TOSLink Optical - right */ +#define EXTOUT_AC97_CENTER 0x04 /* SB Live 5.1 - center */ +#define EXTOUT_AC97_LFE 0x05 /* SB Live 5.1 - LFE */ +#define EXTOUT_HEADPHONE_L 0x06 /* LiveDrive - Headphone - left */ +#define EXTOUT_HEADPHONE_R 0x07 /* LiveDrive - Headphone - right */ +#define EXTOUT_REAR_L 0x08 /* Rear channel - left */ +#define EXTOUT_REAR_R 0x09 /* Rear channel - right */ +#define EXTOUT_ADC_CAP_L 0x0a /* ADC Capture buffer - left */ +#define EXTOUT_ADC_CAP_R 0x0b /* ADC Capture buffer - right */ +#define EXTOUT_MIC_CAP 0x0c /* MIC Capture buffer */ +#define EXTOUT_AC97_REAR_L 0x0d /* SB Live 5.1 (c) 2003 - Rear Left */ +#define EXTOUT_AC97_REAR_R 0x0e /* SB Live 5.1 (c) 2003 - Rear Right */ +#define EXTOUT_ACENTER 0x11 /* Analog Center */ +#define EXTOUT_ALFE 0x12 /* Analog LFE */ + +/* Audigy Inputs */ +#define A_EXTIN_AC97_L 0x00 /* AC'97 capture channel - left */ +#define A_EXTIN_AC97_R 0x01 /* AC'97 capture channel - right */ +#define A_EXTIN_SPDIF_CD_L 0x02 /* digital CD left */ +#define A_EXTIN_SPDIF_CD_R 0x03 /* digital CD left */ +#define A_EXTIN_OPT_SPDIF_L 0x04 /* audigy drive Optical SPDIF - left */ +#define A_EXTIN_OPT_SPDIF_R 0x05 /* right */ +#define A_EXTIN_LINE2_L 0x08 /* audigy drive line2/mic2 - left */ +#define A_EXTIN_LINE2_R 0x09 /* right */ +#define A_EXTIN_ADC_L 0x0a /* Philips ADC - left */ +#define A_EXTIN_ADC_R 0x0b /* right */ +#define A_EXTIN_AUX2_L 0x0c /* audigy drive aux2 - left */ +#define A_EXTIN_AUX2_R 0x0d /* - right */ + +/* Audigiy Outputs */ +#define A_EXTOUT_FRONT_L 0x00 /* digital front left */ +#define A_EXTOUT_FRONT_R 0x01 /* right */ +#define A_EXTOUT_CENTER 0x02 /* digital front center */ +#define A_EXTOUT_LFE 0x03 /* digital front lfe */ +#define A_EXTOUT_HEADPHONE_L 0x04 /* headphone audigy drive left */ +#define A_EXTOUT_HEADPHONE_R 0x05 /* right */ +#define A_EXTOUT_REAR_L 0x06 /* digital rear left */ +#define A_EXTOUT_REAR_R 0x07 /* right */ +#define A_EXTOUT_AFRONT_L 0x08 /* analog front left */ +#define A_EXTOUT_AFRONT_R 0x09 /* right */ +#define A_EXTOUT_ACENTER 0x0a /* analog center */ +#define A_EXTOUT_ALFE 0x0b /* analog LFE */ +#define A_EXTOUT_ASIDE_L 0x0c /* analog side left - Audigy 2 ZS */ +#define A_EXTOUT_ASIDE_R 0x0d /* right - Audigy 2 ZS */ +#define A_EXTOUT_AREAR_L 0x0e /* analog rear left */ +#define A_EXTOUT_AREAR_R 0x0f /* right */ +#define A_EXTOUT_AC97_L 0x10 /* AC97 left (front) */ +#define A_EXTOUT_AC97_R 0x11 /* right */ +#define A_EXTOUT_ADC_CAP_L 0x16 /* ADC capture buffer left */ +#define A_EXTOUT_ADC_CAP_R 0x17 /* right */ +#define A_EXTOUT_MIC_CAP 0x18 /* Mic capture buffer */ + +/* Audigy constants */ +#define A_C_00000000 0xc0 +#define A_C_00000001 0xc1 +#define A_C_00000002 0xc2 +#define A_C_00000003 0xc3 +#define A_C_00000004 0xc4 +#define A_C_00000008 0xc5 +#define A_C_00000010 0xc6 +#define A_C_00000020 0xc7 +#define A_C_00000100 0xc8 +#define A_C_00010000 0xc9 +#define A_C_00000800 0xca +#define A_C_10000000 0xcb +#define A_C_20000000 0xcc +#define A_C_40000000 0xcd +#define A_C_80000000 0xce +#define A_C_7fffffff 0xcf +#define A_C_ffffffff 0xd0 +#define A_C_fffffffe 0xd1 +#define A_C_c0000000 0xd2 +#define A_C_4f1bbcdc 0xd3 +#define A_C_5a7ef9db 0xd4 +#define A_C_00100000 0xd5 +#define A_GPR_ACCU 0xd6 /* ACCUM, accumulator */ +#define A_GPR_COND 0xd7 /* CCR, condition register */ +#define A_GPR_NOISE0 0xd8 /* noise source */ +#define A_GPR_NOISE1 0xd9 /* noise source */ +#define A_GPR_IRQ 0xda /* IRQ register */ +#define A_GPR_DBAC 0xdb /* TRAM Delay Base Address Counter - internal */ +#define A_GPR_DBACE 0xde /* TRAM Delay Base Address Counter - external */ + +/* definitions for debug register */ +#define EMU10K1_DBG_ZC 0x80000000 /* zero tram counter */ +#define EMU10K1_DBG_SATURATION_OCCURED 0x02000000 /* saturation control */ +#define EMU10K1_DBG_SATURATION_ADDR 0x01ff0000 /* saturation address */ +#define EMU10K1_DBG_SINGLE_STEP 0x00008000 /* single step mode */ +#define EMU10K1_DBG_STEP 0x00004000 /* start single step */ +#define EMU10K1_DBG_CONDITION_CODE 0x00003e00 /* condition code */ +#define EMU10K1_DBG_SINGLE_STEP_ADDR 0x000001ff /* single step address */ + +/* tank memory address line */ +#define TANKMEMADDRREG_ADDR_MASK 0x000fffff /* 20 bit tank address field */ +#define TANKMEMADDRREG_CLEAR 0x00800000 /* Clear tank memory */ +#define TANKMEMADDRREG_ALIGN 0x00400000 /* Align read or write relative to tank access */ +#define TANKMEMADDRREG_WRITE 0x00200000 /* Write to tank memory */ +#define TANKMEMADDRREG_READ 0x00100000 /* Read from tank memory */ + +struct snd_emu10k1_fx8010_info { + unsigned int internal_tram_size; /* in samples */ + unsigned int external_tram_size; /* in samples */ + char fxbus_names[16][32]; /* names of FXBUSes */ + char extin_names[16][32]; /* names of external inputs */ + char extout_names[32][32]; /* names of external outputs */ + unsigned int gpr_controls; /* count of GPR controls */ +}; + +#define EMU10K1_GPR_TRANSLATION_NONE 0 +#define EMU10K1_GPR_TRANSLATION_TABLE100 1 +#define EMU10K1_GPR_TRANSLATION_BASS 2 +#define EMU10K1_GPR_TRANSLATION_TREBLE 3 +#define EMU10K1_GPR_TRANSLATION_ONOFF 4 + +enum emu10k1_ctl_elem_iface { + EMU10K1_CTL_ELEM_IFACE_MIXER = 2, /* virtual mixer device */ + EMU10K1_CTL_ELEM_IFACE_PCM = 3, /* PCM device */ +}; + +struct emu10k1_ctl_elem_id { + unsigned int pad; /* don't use */ + int iface; /* interface identifier */ + unsigned int device; /* device/client number */ + unsigned int subdevice; /* subdevice (substream) number */ + unsigned char name[44]; /* ASCII name of item */ + unsigned int index; /* index of item */ +}; + +struct snd_emu10k1_fx8010_control_gpr { + struct emu10k1_ctl_elem_id id; /* full control ID definition */ + unsigned int vcount; /* visible count */ + unsigned int count; /* count of GPR (1..16) */ + unsigned short gpr[32]; /* GPR number(s) */ + unsigned int value[32]; /* initial values */ + unsigned int min; /* minimum range */ + unsigned int max; /* maximum range */ + unsigned int translation; /* translation type (EMU10K1_GPR_TRANSLATION*) */ + const unsigned int *tlv; +}; + +/* old ABI without TLV support */ +struct snd_emu10k1_fx8010_control_old_gpr { + struct emu10k1_ctl_elem_id id; + unsigned int vcount; + unsigned int count; + unsigned short gpr[32]; + unsigned int value[32]; + unsigned int min; + unsigned int max; + unsigned int translation; +}; + +struct snd_emu10k1_fx8010_code { + char name[128]; + + __EMU10K1_DECLARE_BITMAP(gpr_valid, 0x200); /* bitmask of valid initializers */ + __u32 *gpr_map; /* initializers */ + + unsigned int gpr_add_control_count; /* count of GPR controls to add/replace */ + struct snd_emu10k1_fx8010_control_gpr *gpr_add_controls; /* GPR controls to add/replace */ + + unsigned int gpr_del_control_count; /* count of GPR controls to remove */ + struct emu10k1_ctl_elem_id *gpr_del_controls; /* IDs of GPR controls to remove */ + + unsigned int gpr_list_control_count; /* count of GPR controls to list */ + unsigned int gpr_list_control_total; /* total count of GPR controls */ + struct snd_emu10k1_fx8010_control_gpr *gpr_list_controls; /* listed GPR controls */ + + __EMU10K1_DECLARE_BITMAP(tram_valid, 0x100); /* bitmask of valid initializers */ + __u32 *tram_data_map; /* data initializers */ + __u32 *tram_addr_map; /* map initializers */ + + __EMU10K1_DECLARE_BITMAP(code_valid, 1024); /* bitmask of valid instructions */ + __u32 *code; /* one instruction - 64 bits */ +}; + +struct snd_emu10k1_fx8010_tram { + unsigned int address; /* 31.bit == 1 -> external TRAM */ + unsigned int size; /* size in samples (4 bytes) */ + unsigned int *samples; /* pointer to samples (20-bit) */ + /* NULL->clear memory */ +}; + +struct snd_emu10k1_fx8010_pcm_rec { + unsigned int substream; /* substream number */ + unsigned int res1; /* reserved */ + unsigned int channels; /* 16-bit channels count, zero = remove this substream */ + unsigned int tram_start; /* ring buffer position in TRAM (in samples) */ + unsigned int buffer_size; /* count of buffered samples */ + unsigned short gpr_size; /* GPR containing size of ringbuffer in samples (host) */ + unsigned short gpr_ptr; /* GPR containing current pointer in the ring buffer (host = reset, FX8010) */ + unsigned short gpr_count; /* GPR containing count of samples between two interrupts (host) */ + unsigned short gpr_tmpcount; /* GPR containing current count of samples to interrupt (host = set, FX8010) */ + unsigned short gpr_trigger; /* GPR containing trigger (activate) information (host) */ + unsigned short gpr_running; /* GPR containing info if PCM is running (FX8010) */ + unsigned char pad; /* reserved */ + unsigned char etram[32]; /* external TRAM address & data (one per channel) */ + unsigned int res2; /* reserved */ +}; + +#define SNDRV_EMU10K1_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 1) + +#define SNDRV_EMU10K1_IOCTL_INFO _IOR ('H', 0x10, struct snd_emu10k1_fx8010_info) +#define SNDRV_EMU10K1_IOCTL_CODE_POKE _IOW ('H', 0x11, struct snd_emu10k1_fx8010_code) +#define SNDRV_EMU10K1_IOCTL_CODE_PEEK _IOWR('H', 0x12, struct snd_emu10k1_fx8010_code) +#define SNDRV_EMU10K1_IOCTL_TRAM_SETUP _IOW ('H', 0x20, int) +#define SNDRV_EMU10K1_IOCTL_TRAM_POKE _IOW ('H', 0x21, struct snd_emu10k1_fx8010_tram) +#define SNDRV_EMU10K1_IOCTL_TRAM_PEEK _IOWR('H', 0x22, struct snd_emu10k1_fx8010_tram) +#define SNDRV_EMU10K1_IOCTL_PCM_POKE _IOW ('H', 0x30, struct snd_emu10k1_fx8010_pcm_rec) +#define SNDRV_EMU10K1_IOCTL_PCM_PEEK _IOWR('H', 0x31, struct snd_emu10k1_fx8010_pcm_rec) +#define SNDRV_EMU10K1_IOCTL_PVERSION _IOR ('H', 0x40, int) +#define SNDRV_EMU10K1_IOCTL_STOP _IO ('H', 0x80) +#define SNDRV_EMU10K1_IOCTL_CONTINUE _IO ('H', 0x81) +#define SNDRV_EMU10K1_IOCTL_ZERO_TRAM_COUNTER _IO ('H', 0x82) +#define SNDRV_EMU10K1_IOCTL_SINGLE_STEP _IOW ('H', 0x83, int) +#define SNDRV_EMU10K1_IOCTL_DBG_READ _IOR ('H', 0x84, int) + +#endif /* __SOUND_EMU10K1_H */ diff --git a/include/sound/uapi/hdsp.h b/include/sound/uapi/hdsp.h new file mode 100644 index 0000000..b8df62b --- /dev/null +++ b/include/sound/uapi/hdsp.h @@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef __SOUND_HDSP_H +#define __SOUND_HDSP_H + +/* + * Copyright (C) 2003 Thomas Charbonnel (thomas@undata.org) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifdef __linux__ +#include +#endif + +#define HDSP_MATRIX_MIXER_SIZE 2048 + +enum HDSP_IO_Type { + Digiface, + Multiface, + H9652, + H9632, + RPM, + Undefined, +}; + +struct hdsp_peak_rms { + __u32 input_peaks[26]; + __u32 playback_peaks[26]; + __u32 output_peaks[28]; + __u64 input_rms[26]; + __u64 playback_rms[26]; + /* These are only used for H96xx cards */ + __u64 output_rms[26]; +}; + +#define SNDRV_HDSP_IOCTL_GET_PEAK_RMS _IOR('H', 0x40, struct hdsp_peak_rms) + +struct hdsp_config_info { + unsigned char pref_sync_ref; + unsigned char wordclock_sync_check; + unsigned char spdif_sync_check; + unsigned char adatsync_sync_check; + unsigned char adat_sync_check[3]; + unsigned char spdif_in; + unsigned char spdif_out; + unsigned char spdif_professional; + unsigned char spdif_emphasis; + unsigned char spdif_nonaudio; + unsigned int spdif_sample_rate; + unsigned int system_sample_rate; + unsigned int autosync_sample_rate; + unsigned char system_clock_mode; + unsigned char clock_source; + unsigned char autosync_ref; + unsigned char line_out; + unsigned char passthru; + unsigned char da_gain; + unsigned char ad_gain; + unsigned char phone_gain; + unsigned char xlr_breakout_cable; + unsigned char analog_extension_board; +}; + +#define SNDRV_HDSP_IOCTL_GET_CONFIG_INFO _IOR('H', 0x41, struct hdsp_config_info) + +struct hdsp_firmware { + void *firmware_data; /* 24413 x 4 bytes */ +}; + +#define SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE _IOW('H', 0x42, struct hdsp_firmware) + +struct hdsp_version { + enum HDSP_IO_Type io_type; + unsigned short firmware_rev; +}; + +#define SNDRV_HDSP_IOCTL_GET_VERSION _IOR('H', 0x43, struct hdsp_version) + +struct hdsp_mixer { + unsigned short matrix[HDSP_MATRIX_MIXER_SIZE]; +}; + +#define SNDRV_HDSP_IOCTL_GET_MIXER _IOR('H', 0x44, struct hdsp_mixer) + +struct hdsp_9632_aeb { + int aebi; + int aebo; +}; + +#define SNDRV_HDSP_IOCTL_GET_9632_AEB _IOR('H', 0x45, struct hdsp_9632_aeb) + +#endif /* __SOUND_HDSP_H */ diff --git a/include/sound/uapi/hdspm.h b/include/sound/uapi/hdspm.h new file mode 100644 index 0000000..14af3d0 --- /dev/null +++ b/include/sound/uapi/hdspm.h @@ -0,0 +1,226 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef __SOUND_HDSPM_H +#define __SOUND_HDSPM_H +/* + * Copyright (C) 2003 Winfried Ritsch (IEM) + * based on hdsp.h from Thomas Charbonnel (thomas@undata.org) + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifdef __linux__ +#include +#endif + +/* Maximum channels is 64 even on 56Mode you have 64playbacks to matrix */ +#define HDSPM_MAX_CHANNELS 64 + +enum hdspm_io_type { + MADI, + MADIface, + AIO, + AES32, + RayDAT +}; + +enum hdspm_speed { + ss, + ds, + qs +}; + +/* -------------------- IOCTL Peak/RMS Meters -------------------- */ + +struct hdspm_peak_rms { + __u32 input_peaks[64]; + __u32 playback_peaks[64]; + __u32 output_peaks[64]; + + __u64 input_rms[64]; + __u64 playback_rms[64]; + __u64 output_rms[64]; + + __u8 speed; /* enum {ss, ds, qs} */ + int status2; +}; + +#define SNDRV_HDSPM_IOCTL_GET_PEAK_RMS \ + _IOR('H', 0x42, struct hdspm_peak_rms) + +/* ------------ CONFIG block IOCTL ---------------------- */ + +struct hdspm_config { + unsigned char pref_sync_ref; + unsigned char wordclock_sync_check; + unsigned char madi_sync_check; + unsigned int system_sample_rate; + unsigned int autosync_sample_rate; + unsigned char system_clock_mode; + unsigned char clock_source; + unsigned char autosync_ref; + unsigned char line_out; + unsigned int passthru; + unsigned int analog_out; +}; + +#define SNDRV_HDSPM_IOCTL_GET_CONFIG \ + _IOR('H', 0x41, struct hdspm_config) + +/* + * If there's a TCO (TimeCode Option) board installed, + * there are further options and status data available. + * The hdspm_ltc structure contains the current SMPTE + * timecode and some status information and can be + * obtained via SNDRV_HDSPM_IOCTL_GET_LTC or in the + * hdspm_status struct. + */ + +enum hdspm_ltc_format { + format_invalid, + fps_24, + fps_25, + fps_2997, + fps_30 +}; + +enum hdspm_ltc_frame { + frame_invalid, + drop_frame, + full_frame +}; + +enum hdspm_ltc_input_format { + ntsc, + pal, + no_video +}; + +struct hdspm_ltc { + unsigned int ltc; + + enum hdspm_ltc_format format; + enum hdspm_ltc_frame frame; + enum hdspm_ltc_input_format input_format; +}; + +#define SNDRV_HDSPM_IOCTL_GET_LTC _IOR('H', 0x46, struct hdspm_ltc) + +/* + * The status data reflects the device's current state + * as determined by the card's configuration and + * connection status. + */ + +enum hdspm_sync { + hdspm_sync_no_lock = 0, + hdspm_sync_lock = 1, + hdspm_sync_sync = 2 +}; + +enum hdspm_madi_input { + hdspm_input_optical = 0, + hdspm_input_coax = 1 +}; + +enum hdspm_madi_channel_format { + hdspm_format_ch_64 = 0, + hdspm_format_ch_56 = 1 +}; + +enum hdspm_madi_frame_format { + hdspm_frame_48 = 0, + hdspm_frame_96 = 1 +}; + +enum hdspm_syncsource { + syncsource_wc = 0, + syncsource_madi = 1, + syncsource_tco = 2, + syncsource_sync = 3, + syncsource_none = 4 +}; + +struct hdspm_status { + __u8 card_type; /* enum hdspm_io_type */ + enum hdspm_syncsource autosync_source; + + __u64 card_clock; + __u32 master_period; + + union { + struct { + __u8 sync_wc; /* enum hdspm_sync */ + __u8 sync_madi; /* enum hdspm_sync */ + __u8 sync_tco; /* enum hdspm_sync */ + __u8 sync_in; /* enum hdspm_sync */ + __u8 madi_input; /* enum hdspm_madi_input */ + __u8 channel_format; /* enum hdspm_madi_channel_format */ + __u8 frame_format; /* enum hdspm_madi_frame_format */ + } madi; + } card_specific; +}; + +#define SNDRV_HDSPM_IOCTL_GET_STATUS \ + _IOR('H', 0x47, struct hdspm_status) + +/* + * Get information about the card and its add-ons. + */ + +#define HDSPM_ADDON_TCO 1 + +struct hdspm_version { + __u8 card_type; /* enum hdspm_io_type */ + char cardname[20]; + unsigned int serial; + unsigned short firmware_rev; + int addons; +}; + +#define SNDRV_HDSPM_IOCTL_GET_VERSION _IOR('H', 0x48, struct hdspm_version) + +/* ------------- get Matrix Mixer IOCTL --------------- */ + +/* MADI mixer: 64inputs+64playback in 64outputs = 8192 => *4Byte = + * 32768 Bytes + */ + +/* organisation is 64 channelfader in a continuous memory block */ +/* equivalent to hardware definition, maybe for future feature of mmap of + * them + */ +/* each of 64 outputs has 64 infader and 64 outfader: + Ins to Outs mixer[out].in[in], Outstreams to Outs mixer[out].pb[pb] */ + +#define HDSPM_MIXER_CHANNELS HDSPM_MAX_CHANNELS + +struct hdspm_channelfader { + unsigned int in[HDSPM_MIXER_CHANNELS]; + unsigned int pb[HDSPM_MIXER_CHANNELS]; +}; + +struct hdspm_mixer { + struct hdspm_channelfader ch[HDSPM_MIXER_CHANNELS]; +}; + +struct hdspm_mixer_ioctl { + struct hdspm_mixer *mixer; +}; + +/* use indirect access due to the limit of ioctl bit size */ +#define SNDRV_HDSPM_IOCTL_GET_MIXER _IOR('H', 0x44, struct hdspm_mixer_ioctl) + +#endif diff --git a/include/sound/uapi/sb16_csp.h b/include/sound/uapi/sb16_csp.h new file mode 100644 index 0000000..55db0b4 --- /dev/null +++ b/include/sound/uapi/sb16_csp.h @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Copyright (c) 1999 by Uros Bizjak + * Takashi Iwai + * + * SB16ASP/AWE32 CSP control + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef __SOUND_SB16_CSP_H +#define __SOUND_SB16_CSP_H + + +/* CSP modes */ +#define SNDRV_SB_CSP_MODE_NONE 0x00 +#define SNDRV_SB_CSP_MODE_DSP_READ 0x01 /* Record from DSP */ +#define SNDRV_SB_CSP_MODE_DSP_WRITE 0x02 /* Play to DSP */ +#define SNDRV_SB_CSP_MODE_QSOUND 0x04 /* QSound */ + +/* CSP load flags */ +#define SNDRV_SB_CSP_LOAD_FROMUSER 0x01 +#define SNDRV_SB_CSP_LOAD_INITBLOCK 0x02 + +/* CSP sample width */ +#define SNDRV_SB_CSP_SAMPLE_8BIT 0x01 +#define SNDRV_SB_CSP_SAMPLE_16BIT 0x02 + +/* CSP channels */ +#define SNDRV_SB_CSP_MONO 0x01 +#define SNDRV_SB_CSP_STEREO 0x02 + +/* CSP rates */ +#define SNDRV_SB_CSP_RATE_8000 0x01 +#define SNDRV_SB_CSP_RATE_11025 0x02 +#define SNDRV_SB_CSP_RATE_22050 0x04 +#define SNDRV_SB_CSP_RATE_44100 0x08 +#define SNDRV_SB_CSP_RATE_ALL 0x0f + +/* CSP running state */ +#define SNDRV_SB_CSP_ST_IDLE 0x00 +#define SNDRV_SB_CSP_ST_LOADED 0x01 +#define SNDRV_SB_CSP_ST_RUNNING 0x02 +#define SNDRV_SB_CSP_ST_PAUSED 0x04 +#define SNDRV_SB_CSP_ST_AUTO 0x08 +#define SNDRV_SB_CSP_ST_QSOUND 0x10 + +/* maximum QSound value (180 degrees right) */ +#define SNDRV_SB_CSP_QSOUND_MAX_RIGHT 0x20 + +/* maximum microcode RIFF file size */ +#define SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE 0x3000 + +/* microcode header */ +struct snd_sb_csp_mc_header { + char codec_name[16]; /* id name of codec */ + unsigned short func_req; /* requested function */ +}; + +/* microcode to be loaded */ +struct snd_sb_csp_microcode { + struct snd_sb_csp_mc_header info; + unsigned char data[SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE]; +}; + +/* start CSP with sample_width in mono/stereo */ +struct snd_sb_csp_start { + int sample_width; /* sample width, look above */ + int channels; /* channels, look above */ +}; + +/* CSP information */ +struct snd_sb_csp_info { + char codec_name[16]; /* id name of codec */ + unsigned short func_nr; /* function number */ + unsigned int acc_format; /* accepted PCM formats */ + unsigned short acc_channels; /* accepted channels */ + unsigned short acc_width; /* accepted sample width */ + unsigned short acc_rates; /* accepted sample rates */ + unsigned short csp_mode; /* CSP mode, see above */ + unsigned short run_channels; /* current channels */ + unsigned short run_width; /* current sample width */ + unsigned short version; /* version id: 0x10 - 0x1f */ + unsigned short state; /* state bits */ +}; + +/* HWDEP controls */ +/* get CSP information */ +#define SNDRV_SB_CSP_IOCTL_INFO _IOR('H', 0x10, struct snd_sb_csp_info) +/* load microcode to CSP */ +/* NOTE: struct snd_sb_csp_microcode overflows the max size (13 bits) + * defined for some architectures like MIPS, and it leads to build errors. + * (x86 and co have 14-bit size, thus it's valid, though.) + * As a workaround for skipping the size-limit check, here we don't use the + * normal _IOW() macro but _IOC() with the manual argument. + */ +#define SNDRV_SB_CSP_IOCTL_LOAD_CODE \ + _IOC(_IOC_WRITE, 'H', 0x11, sizeof(struct snd_sb_csp_microcode)) +/* unload microcode from CSP */ +#define SNDRV_SB_CSP_IOCTL_UNLOAD_CODE _IO('H', 0x12) +/* start CSP */ +#define SNDRV_SB_CSP_IOCTL_START _IOW('H', 0x13, struct snd_sb_csp_start) +/* stop CSP */ +#define SNDRV_SB_CSP_IOCTL_STOP _IO('H', 0x14) +/* pause CSP and DMA transfer */ +#define SNDRV_SB_CSP_IOCTL_PAUSE _IO('H', 0x15) +/* restart CSP and DMA transfer */ +#define SNDRV_SB_CSP_IOCTL_RESTART _IO('H', 0x16) + + +#endif /* __SOUND_SB16_CSP_H */ diff --git a/include/sound/uapi/sscape_ioctl.h b/include/sound/uapi/sscape_ioctl.h new file mode 100644 index 0000000..c6653eb --- /dev/null +++ b/include/sound/uapi/sscape_ioctl.h @@ -0,0 +1,21 @@ +#ifndef SSCAPE_IOCTL_H +#define SSCAPE_IOCTL_H + + +struct sscape_bootblock +{ + unsigned char code[256]; + unsigned version; +}; + +#define SSCAPE_MICROCODE_SIZE 65536 + +struct sscape_microcode +{ + unsigned char *code; +}; + +#define SND_SSCAPE_LOAD_BOOTB _IOWR('P', 100, struct sscape_bootblock) +#define SND_SSCAPE_LOAD_MCODE _IOW ('P', 101, struct sscape_microcode) + +#endif diff --git a/include/sound/uapi/tlv.h b/include/sound/uapi/tlv.h new file mode 100644 index 0000000..7d6d65f --- /dev/null +++ b/include/sound/uapi/tlv.h @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __UAPI_SOUND_TLV_H +#define __UAPI_SOUND_TLV_H + +#define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */ +#define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */ +#define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */ +#define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */ +#define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */ +#define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */ + +/* + * channel-mapping TLV items + * TLV length must match with num_channels + */ +#define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */ +#define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */ +#define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */ + +/* + * TLV structure is right behind the struct snd_ctl_tlv: + * unsigned int type - see SNDRV_CTL_TLVT_* + * unsigned int length + * .... data aligned to sizeof(unsigned int), use + * block_length = (length + (sizeof(unsigned int) - 1)) & + * ~(sizeof(unsigned int) - 1)) .... + */ +#define SNDRV_CTL_TLVD_ITEM(type, ...) \ + (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__ +#define SNDRV_CTL_TLVD_LENGTH(...) \ + ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ })) + +/* Accessor offsets for TLV data items */ +#define SNDRV_CTL_TLVO_TYPE 0 +#define SNDRV_CTL_TLVO_LEN 1 + +#define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__) +#define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \ + } + +#define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff +#define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000 +#define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \ + (min), \ + ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \ + ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0)) +#define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \ + } + +/* Accessor offsets for min, mute and step items in dB scale type TLV */ +#define SNDRV_CTL_TLVO_DB_SCALE_MIN 2 +#define SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP 3 + +/* dB scale specified with min/max values instead of step */ +#define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB)) +#define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB)) +#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \ + } +#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ + } + +/* Accessor offsets for min, max items in db-minmax types of TLV. */ +#define SNDRV_CTL_TLVO_DB_MINMAX_MIN 2 +#define SNDRV_CTL_TLVO_DB_MINMAX_MAX 3 + +/* linear volume between min_dB and max_dB (.01dB unit) */ +#define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB)) +#define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \ + } + +/* Accessor offsets for min, max items in db-linear type of TLV. */ +#define SNDRV_CTL_TLVO_DB_LINEAR_MIN 2 +#define SNDRV_CTL_TLVO_DB_LINEAR_MAX 3 + +/* dB range container: + * Items in dB range container must be ordered by their values and by their + * dB values. This implies that larger values must correspond with larger + * dB values (which is also required for all other mixer controls). + */ +/* Each item is: */ +#define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__) +#define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \ + } + +#define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999 + +#endif diff --git a/include/topology.h b/include/topology.h index 27da730..1f52e66 100644 --- a/include/topology.h +++ b/include/topology.h @@ -771,6 +771,16 @@ enum snd_tplg_type { /** Fit for all user cases */ #define SND_TPLG_INDEX_ALL 0 +/** Flags for the snd_tplg_create */ +#define SND_TPLG_CREATE_VERBOSE (1<<0) /*!< Verbose output */ +#define SND_TPLG_CREATE_DAPM_NOSORT (1<<1) /*!< Do not sort DAPM objects by index */ + +/** + * \brief Return the version of the topology library. + * \return A static string with the version number. + */ +const char *snd_tplg_version(void); + /** * \brief Create a new topology parser instance. * \return New topology parser instance @@ -778,12 +788,27 @@ enum snd_tplg_type { snd_tplg_t *snd_tplg_new(void); /** + * \brief Create a new topology parser instance. + * \return New topology parser instance + */ +snd_tplg_t *snd_tplg_create(int flags); + +/** * \brief Free a topology parser instance. * \param tplg Topology parser instance */ void snd_tplg_free(snd_tplg_t *tplg); /** + * \brief Load topology from the text buffer. + * \param tplg Topology instance. + * \param buf Text buffer. + * \param size Text buffer size in bytes. + * \return Zero on success, otherwise a negative error code + */ +int snd_tplg_load(snd_tplg_t *tplg, const char *buf, size_t size); + +/** * \brief Parse and build topology text file into binary file. * \param tplg Topology instance. * \param infile Topology text input file to be parsed @@ -791,7 +816,7 @@ void snd_tplg_free(snd_tplg_t *tplg); * \return Zero on success, otherwise a negative error code */ int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile, - const char *outfile); + const char *outfile); /** * \brief Enable verbose reporting of binary file output @@ -860,7 +885,10 @@ struct snd_tplg_ctl_template { const char *name; /*!< Control name */ int access; /*!< Control access */ struct snd_tplg_io_ops_template ops; /*!< operations */ - struct snd_tplg_tlv_template *tlv; /*!< non NULL means we have TLV data */ + union { + struct snd_tplg_tlv_template *tlv; /*!< non NULL means we have TLV data */ + struct snd_tplg_tlv_dbscale_template *tlv_scale; /*!< scale TLV data */ + }; }; /** \struct snd_tplg_mixer_template @@ -1090,6 +1118,15 @@ int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); int snd_tplg_build(snd_tplg_t *tplg, const char *outfile); /** + * \brief Build all registered topology data into memory. + * \param tplg Topology instance. + * \param bin Binary topology output buffer (malloc). + * \param size Binary topology output buffer size in bytes. + * \return Zero on success, otherwise a negative error code + */ +int snd_tplg_build_bin(snd_tplg_t *tplg, void **bin, size_t *size); + +/** * \brief Attach private data to topology manifest. * \param tplg Topology instance. * \param data Private data. @@ -1106,6 +1143,30 @@ int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len); */ int snd_tplg_set_version(snd_tplg_t *tplg, unsigned int version); +/* + * Flags for the snd_tplg_save() + */ +#define SND_TPLG_SAVE_SORT (1<<0) /*!< sort identifiers */ +#define SND_TPLG_SAVE_GROUPS (1<<1) /*!< create the structure by group index */ +#define SND_TPLG_SAVE_NOCHECK (1<<16) /*!< unchecked output for debugging */ + +/** + * \brief Save the topology to the text configuration string. + * \param tplg Topology instance. + * \param dst A pointer to string with result (malloc). + * \return Zero on success, otherwise a negative error code + */ +int snd_tplg_save(snd_tplg_t *tplg, char **dst, int flags); + +/** + * \brief Decode the binary topology contents. + * \param tplg Topology instance. + * \param bin Binary topology input buffer. + * \param size Binary topology input buffer size. + * \return Zero on success, otherwise a negative error code + */ +int snd_tplg_decode(snd_tplg_t *tplg, void *bin, size_t size, int dflags); + /* \} */ #ifdef __cplusplus diff --git a/include/use-case.h b/include/use-case.h index 8e7e838..2363c3e 100644 --- a/include/use-case.h +++ b/include/use-case.h @@ -114,10 +114,25 @@ extern "C" { * * Physical system devices the render and capture audio. Devices can be OR'ed * together to support audio on simultaneous devices. + * + * If multiple devices with the same name exists, the number suffixes should + * be added to these names like HDMI1,HDMI2,HDMI3 etc. No number gaps are + * allowed. The names with numbers must be continuous. It is allowed to put + * a whitespace between name and index (like 'Line 1') for the better + * readability. The device names 'Line 1' and 'Line1' are equal for + * this purpose. + * + * If EnableSequence/DisableSequence controls independent paths in the hardware + * it is also recommended to split playback and capture UCM devices and use + * the number suffixes. Example use case: Use the integrated microphone + * in the laptop instead the microphone in headphones. + * + * The preference of the devices is determined by the priority value. */ #define SND_USE_CASE_DEV_NONE "None" /**< None Device */ #define SND_USE_CASE_DEV_SPEAKER "Speaker" /**< Speaker Device */ #define SND_USE_CASE_DEV_LINE "Line" /**< Line Device */ +#define SND_USE_CASE_DEV_MIC "Mic" /**< Microphone Device */ #define SND_USE_CASE_DEV_HEADPHONES "Headphones" /**< Headphones Device */ #define SND_USE_CASE_DEV_HEADSET "Headset" /**< Headset Device */ #define SND_USE_CASE_DEV_HANDSET "Handset" /**< Handset Device */ @@ -125,6 +140,7 @@ extern "C" { #define SND_USE_CASE_DEV_EARPIECE "Earpiece" /**< Earpiece Device */ #define SND_USE_CASE_DEV_SPDIF "SPDIF" /**< SPDIF Device */ #define SND_USE_CASE_DEV_HDMI "HDMI" /**< HDMI Device */ +#define SND_USE_CASE_DEV_USB "USB" /**< USB Device (multifunctional) */ /* add new devices to end of list */ @@ -134,6 +150,13 @@ extern "C" { * The use case modifier allows runtime configuration changes to deal with * asynchronous events. * + * If multiple modifiers with the same name exists, the number suffixes should + * be added to these names like 'Echo Reference 1','Echo Reference 2' etc. + * No number gaps are allowed. The names with numbers must be continuous. + * It is allowed to put a whitespace between name and index for the better + * readability. The modifier names 'Something 1' and 'Something1' are equal + * for this purpose. + * * e.g. to record a voice call :- * 1. Set verb to SND_USE_CASE_VERB_VOICECALL (for voice call) * 2. Set modifier SND_USE_CASE_MOD_CAPTURE_VOICE when capture required. @@ -206,6 +229,7 @@ int snd_use_case_free_list(const char *list[], int items); * - _enadevs - get list of enabled devices * - _enamods - get list of enabled modifiers * + * - _identifiers/{modifier}|{device}[/{verb}] - list of value identifiers * - _supporteddevs/{modifier}|{device}[/{verb}] - list of supported devices * - _conflictingdevs/{modifier}|{device}[/{verb}] - list of conflicting devices * @@ -259,8 +283,17 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, * "=Variable/Modifier/Verb" * * Recommended names for values: + * - Linked + * - value "True" or "1" (case insensitive) + * - this is a linked UCM card + * - don't use this UCM card, because the other UCM card refers devices + * - valid only in the ValueDefaults section (query '=Linked') * - TQ * - Tone Quality + * - Priority + * - priority value (1-10000), higher value means higher priority + * - valid only for verbs + * - for devices - PlaybackPriority and CapturePriority * - PlaybackPCM * - full PCM playback device name * - PlaybackPCMIsDummy @@ -288,7 +321,7 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, * - playback control switch identifier string * - can be parsed using snd_use_case_parse_ctl_elem_id() * - PlaybackPriority - * - priority value (1-10000), default value is 100, higher value means lower priority + * - priority value (1-10000), higher value means higher priority * - CaptureRate * - capture device sample rate * - CaptureChannels @@ -302,7 +335,7 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, * - capture control switch identifier string * - can be parsed using snd_use_case_parse_ctl_elem_id() * - CapturePriority - * - priority value (1-10000), default value is 100, higher value means lower priority + * - priority value (1-10000), higher value means higher priority * - PlaybackMixer * - name of playback mixer * - PlaybackMixerElem @@ -310,6 +343,7 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, * - can be parsed using snd_use_case_parse_selem_id() * - PlaybackMasterElem * - mixer element playback identifier for the master control + * - can be parsed using snd_use_case_parse_selem_id() * - PlaybackMasterType * - type of the master volume control * - Valid values: "soft" (software attenuation) @@ -320,30 +354,38 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, * - can be parsed using snd_use_case_parse_selem_id() * - CaptureMasterElem * - mixer element playback identifier for the master control + * - can be parsed using snd_use_case_parse_selem_id() * - CaptureMasterType * - type of the master volume control * - Valid values: "soft" (software attenuation) * - EDIDFile * - Path to EDID file for HDMI devices - * - JackControl, JackDev, JackHWMute - * - Jack information for a device. The jack status can be reported via - * a kcontrol and/or via an input device. **JackControl** is the - * kcontrol name of the jack, and **JackDev** is the input device id of - * the jack (if the full input device path is /dev/input/by-id/foo, the - * JackDev value should be "foo"). UCM configuration files should - * contain both JackControl and JackDev when possible, because - * applications are likely to support only one or the other. - * - * If **JackHWMute** is set, it indicates that when the jack is plugged - * in, the hardware automatically mutes some other device(s). The - * JackHWMute value is a space-separated list of device names (this - * isn't compatible with device names with spaces in them, so don't use - * such device names!). Note that JackHWMute should be used only when - * the hardware enforces the automatic muting. If the hardware doesn't - * enforce any muting, it may still be tempting to set JackHWMute to - * trick upper software layers to e.g. automatically mute speakers when - * headphones are plugged in, but that's application policy - * configuration that doesn't belong to UCM configuration files. + * - JackCTL + * - jack control device name + * - JackControl + * - jack control identificator + * - can be parsed using snd_use_case_parse_ctl_elem_id() + * - UCM configuration files should contain both JackControl and JackDev + * when possible, because applications are likely to support only one + * or the other + * - JackDev + * - the input device id of the jack (if the full input device path is + * /dev/input/by-id/foo, the JackDev value should be "foo") + * - UCM configuration files should contain both JackControl and JackDev + * when possible, because applications are likely to support only one + * or the other + * - JackHWMute + * If this value is set, it indicates that when the jack is plugged + * in, the hardware automatically mutes some other device(s). The + * value is a space-separated list of device names. If the device + * name contains space, it must be enclosed to ' or ", e.g.: + * JackHWMute "'Dock Headphone' Headphone" + * Note that JackHWMute should be used only when the hardware enforces + * the automatic muting. If the hardware doesn't enforce any muting, it + * may still be tempting to set JackHWMute to trick upper software layers + * to e.g. automatically mute speakers when headphones are plugged in, + * but that's application policy configuration that doesn't belong + * to UCM configuration files. * - MinBufferLevel * - This is used on platform where reported buffer level is not accurate. * E.g. "512", which holds 512 samples in device buffer. Note: this will @@ -376,6 +418,8 @@ int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr, * \return Zero if success, otherwise a negative error code * * Known identifiers: + * - _boot - execute the boot sequence (value = NULL) + * - _defaults - execute the 'defaults' sequence (value = NULL) * - _verb - set current verb = value * - _enadev - enable given device = value * - _disdev - disable given device = value diff --git a/include/version.h b/include/version.h index 56c7589..44f97e1 100644 --- a/include/version.h +++ b/include/version.h @@ -4,12 +4,12 @@ #define SND_LIB_MAJOR 1 /**< major number of library version */ #define SND_LIB_MINOR 2 /**< minor number of library version */ -#define SND_LIB_SUBMINOR 1 /**< subminor number of library version */ +#define SND_LIB_SUBMINOR 3 /**< subminor number of library version */ #define SND_LIB_EXTRAVER 1000000 /**< extra version number, used mainly for betas */ /** library version */ #define SND_LIB_VERSION ((SND_LIB_MAJOR<<16)|\ (SND_LIB_MINOR<<8)|\ SND_LIB_SUBMINOR) /** library version (string) */ -#define SND_LIB_VERSION_STR "1.2.1.2" +#define SND_LIB_VERSION_STR "1.2.3.2" diff --git a/libtool b/libtool index a5f660d..cb0bb03 100755 --- a/libtool +++ b/libtool @@ -1,5 +1,5 @@ #! /bin/sh -# Generated automatically by config.status (alsa-lib) 1.2.1.2 +# Generated automatically by config.status (alsa-lib) 1.2.3.2 # Libtool was configured on host e010f88cea4a: # NOTE: Changes made to this file will be lost: look at ltmain.sh. @@ -379,7 +379,7 @@ no_undefined_flag="" # Flag to hardcode $libdir into a binary during linking. # This must work even if $libdir does not exist -hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ " +hardcode_libdir_flag_spec="\$wl-rpath \$wl\$libdir" # Whether we need a single "-rpath" flag with a separated argument. hardcode_libdir_separator="" diff --git a/m4/attributes.m4 b/m4/attributes.m4 index e86456a..3d9c256 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -1,6 +1,6 @@ dnl Macros to check the presence of generic (non-typed) symbols. -dnl Copyright (c) 2006-2007 Diego Pettenò -dnl Copyright (c) 2006-2007 xine project +dnl Copyright (c) 2006-2008 Diego Pettenò +dnl Copyright (c) 2006-2008 xine project dnl dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ dnl License when using or distributing such scripts, even though portions dnl of the text of the Macro appear in them. The GNU General Public dnl License (GPL) does govern all other use of the material that dnl constitutes the Autoconf Macro. -dnl +dnl dnl This special exception to the GPL applies to versions of the dnl Autoconf Macro released by this project. When you make and dnl distribute a modified version of the Autoconf Macro, you may extend @@ -39,7 +39,7 @@ AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [ AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]), [ac_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $1" - AC_COMPILE_IFELSE([int a;], + AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a;])], [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"], [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"]) CFLAGS="$ac_save_CFLAGS" @@ -71,7 +71,7 @@ AC_DEFUN([CC_CHECK_CFLAG_APPEND], [ ) AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], - [CFLAGS="$CFLAGS $1"; $2], [$3]) + [CFLAGS="$CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3]) ]) dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not]) @@ -89,7 +89,7 @@ AC_DEFUN([CC_CHECK_LDFLAGS], [ AS_TR_SH([cc_cv_ldflags_$1]), [ac_save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS $1" - AC_LINK_IFELSE([int main() { return 1; }], + AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])], [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) LDFLAGS="$ac_save_LDFLAGS" @@ -109,14 +109,21 @@ AC_DEFUN([CC_NOUNDEFINED], [ dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads dnl are requested, as different implementations are present; to avoid problems dnl use -Wl,-z,defs only for those platform not behaving this way. - *-freebsd*) ;; + dnl + dnl MinGW platforms: for libraries required -no-undefined, + dnl use it only for libraries in mingw32-w64 + + *-freebsd* | *-openbsd*) ;; + *-mingw*) + LDFLAGS_NOUNDEFINED="-no-undefined" + ;; *) dnl First of all check for the --no-undefined variant of GNU ld. This allows dnl for a much more readable commandline, so that people can understand what dnl it does without going to look for what the heck -z defs does. - for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do + for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) - break + if test "x$LDFLAGS_NOUNDEFINED" = "x"; then break; fi done ;; esac @@ -147,7 +154,7 @@ AC_DEFUN([CC_CHECK_ATTRIBUTE], [ AS_TR_SH([cc_cv_attribute_$1]), [ac_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $cc_cv_werror" - AC_COMPILE_IFELSE([$3], + AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"], [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"]) CFLAGS="$ac_save_CFLAGS" @@ -257,7 +264,7 @@ AC_DEFUN([CC_FLAG_VISIBILITY], [ cc_cv_flag_visibility='yes', cc_cv_flag_visibility='no') CFLAGS="$cc_flag_visibility_save_CFLAGS"]) - + AS_IF([test "x$cc_cv_flag_visibility" = "xyes"], [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1, [Define this if the compiler supports the -fvisibility flag]) @@ -295,11 +302,11 @@ AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ [ac_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $cc_cv_werror" for cc_attribute_align_try in 64 32 16 8 4 2; do - AC_COMPILE_IFELSE([ + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ int main() { static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0; return c; - }], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) + }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) done CFLAGS="$ac_save_CFLAGS" ]) diff --git a/modules/mixer/simple/python.c b/modules/mixer/simple/python.c index 3a627ab..8a7264d 100644 --- a/modules/mixer/simple/python.c +++ b/modules/mixer/simple/python.c @@ -21,6 +21,7 @@ #include "Python.h" #include +#include #include "config.h" #include "asoundlib.h" #include "mixer_abst.h" @@ -36,7 +37,7 @@ struct python_priv { PyObject *py_mixer; }; -#define SCRIPT ALSA_PLUGIN_DIR "/smixer/python/main.py" +#define SCRIPT "smixer/python/main.py" struct pymelem { PyObject_HEAD @@ -1110,6 +1111,7 @@ int alsa_mixer_simple_finit(snd_mixer_class_t *class, FILE *fp; const char *file; PyObject *obj, *py_mod; + char path[PATH_MAX]; priv = calloc(1, sizeof(*priv)); if (priv == NULL) @@ -1119,8 +1121,10 @@ int alsa_mixer_simple_finit(snd_mixer_class_t *class, snd_mixer_sbasic_set_private_free(class, alsa_mixer_simple_free); file = getenv("ALSA_MIXER_SIMPLE_MPYTHON"); - if (file == NULL) - file = SCRIPT; + if (file == NULL) { + snd_dlpath(path, sizeof(path), SCRIPT); + file = path; + } fp = fopen(file, "r"); if (fp == NULL) { diff --git a/modules/mixer/simple/sbasedl.c b/modules/mixer/simple/sbasedl.c index d8cbf0f..a1b33cc 100644 --- a/modules/mixer/simple/sbasedl.c +++ b/modules/mixer/simple/sbasedl.c @@ -33,7 +33,7 @@ #include "mixer_abst.h" #include "sbase.h" -#define SO_PATH ALSA_PLUGIN_DIR "/smixer" +#define SO_PATH "smixer" int mixer_simple_basic_dlopen(snd_mixer_class_t *class, bclass_base_ops_t **ops) diff --git a/src/conf.c b/src/conf.c index e430650..8518f90 100644 --- a/src/conf.c +++ b/src/conf.c @@ -416,6 +416,7 @@ beginning:

#include "local.h" #include +#include #include #include #include @@ -443,7 +444,7 @@ struct _snd_config { const void *ptr; struct { struct list_head fields; - int join; + bool join; } compound; } u; struct list_head list; @@ -874,6 +875,21 @@ static int get_nonwhite(input_t *input) } } +static inline int get_hexachar(input_t *input) +{ + int c, num = 0; + + c = get_char(input); + if (c >= '0' && c <= '9') num |= (c - '0') << 4; + else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 4; + else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 4; + c = get_char(input); + if (c >= '0' && c <= '9') num |= (c - '0') << 0; + else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 0; + else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 0; + return c; +} + static int get_quotedchar(input_t *input) { int c; @@ -891,6 +907,8 @@ static int get_quotedchar(input_t *input) return '\r'; case 'f': return '\f'; + case 'x': + return get_hexachar(input); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { @@ -1226,7 +1244,7 @@ static int parse_value(snd_config_t **_n, snd_config_t *parent, input_t *input, static int parse_defs(snd_config_t *parent, input_t *input, int skip, int override); static int parse_array_defs(snd_config_t *farther, input_t *input, int skip, int override); -static int parse_array_def(snd_config_t *parent, input_t *input, int idx, int skip, int override) +static int parse_array_def(snd_config_t *parent, input_t *input, int *idx, int skip, int override) { char *id = NULL; int c; @@ -1234,8 +1252,21 @@ static int parse_array_def(snd_config_t *parent, input_t *input, int idx, int sk snd_config_t *n = NULL; if (!skip) { + snd_config_t *g; char static_id[12]; - snprintf(static_id, sizeof(static_id), "%i", idx); + while (1) { + snprintf(static_id, sizeof(static_id), "%i", *idx); + if (_snd_config_search(parent, static_id, -1, &g) == 0) { + if (override) { + snd_config_delete(n); + } else { + /* merge */ + (*idx)++; + continue; + } + } + break; + } id = strdup(static_id); if (id == NULL) return -ENOMEM; @@ -1306,9 +1337,10 @@ static int parse_array_defs(snd_config_t *parent, input_t *input, int skip, int unget_char(c, input); if (c == ']') return 0; - err = parse_array_def(parent, input, idx++, skip, override); + err = parse_array_def(parent, input, &idx, skip, override); if (err < 0) return err; + idx++; } return 0; } @@ -1362,7 +1394,7 @@ static int parse_def(snd_config_t *parent, input_t *input, int skip, int overrid SNDERR("%s is not a compound", id); return -EINVAL; } - n->u.compound.join = 1; + n->u.compound.join = true; parent = n; free(id); continue; @@ -1377,7 +1409,7 @@ static int parse_def(snd_config_t *parent, input_t *input, int skip, int overrid err = _snd_config_make_add(&n, &id, SND_CONFIG_TYPE_COMPOUND, parent); if (err < 0) goto __end; - n->u.compound.join = 1; + n->u.compound.join = true; parent = n; } if (c == '=') { @@ -1500,6 +1532,8 @@ static void string_print(char *str, int id, snd_output_t *out) case '.': case '{': case '}': + case '[': + case ']': case '\'': case '"': goto quoted; @@ -1750,6 +1784,45 @@ snd_config_type_t snd_config_get_type(const snd_config_t *config) return config->type; } +static int check_array_item(const char *id, int index) +{ + const char *p; + long val; + + for (p = id; *p; p++) { + if (*p < '0' || *p > '9') + return 0; + } + + if (safe_strtol(id, &val)) + return 0; + return val == index; +} + +/** + * \brief Returns if the compound is an array. + * \param config Handle to the configuration node. + * \return A positive value when true, zero when false, otherwise a negative error code. + */ +int snd_config_is_array(const snd_config_t *config) +{ + int idx; + snd_config_iterator_t i, next; + snd_config_t *node; + + assert(config); + if (config->type != SND_CONFIG_TYPE_COMPOUND) + return -EINVAL; + idx = 0; + snd_config_for_each(i, next, config) { + node = snd_config_iterator_entry(i); + if (!check_array_item(node->id, idx)) + return 0; + idx++; + } + return 1; +} + /** * \brief Returns the id of a configuration node. * \param[in] config Handle to the configuration node. @@ -3746,6 +3819,63 @@ static int config_file_open(snd_config_t *root, const char *filename) return err; } +static int config_file_load(snd_config_t *root, const char *fn, int errors) +{ + struct stat st; + struct dirent **namelist; + int err, n; + + if (!errors && access(fn, R_OK) < 0) + return 1; + if (stat(fn, &st) < 0) { + SNDERR("cannot stat file/directory %s", fn); + return 1; + } + if (!S_ISDIR(st.st_mode)) + return config_file_open(root, fn); +#ifndef DOC_HIDDEN +#if defined(_GNU_SOURCE) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__sun) && !defined(ANDROID) +#define SORTFUNC versionsort +#else +#define SORTFUNC alphasort +#endif +#endif + n = scandir(fn, &namelist, config_filename_filter, SORTFUNC); + if (n > 0) { + int j; + err = 0; + for (j = 0; j < n; ++j) { + if (err >= 0) { + int sl = strlen(fn) + strlen(namelist[j]->d_name) + 2; + char *filename = malloc(sl); + snprintf(filename, sl, "%s/%s", fn, namelist[j]->d_name); + filename[sl-1] = '\0'; + + err = config_file_open(root, filename); + free(filename); + } + free(namelist[j]); + } + free(namelist); + if (err < 0) + return err; + } + return 0; +} + +static int config_file_load_user(snd_config_t *root, const char *fn, int errors) +{ + char *fn2; + int err; + + err = snd_user_file(fn, &fn2); + if (err < 0) + return config_file_load(root, fn, errors); + err = config_file_load(root, fn2, errors); + free(fn2); + return err; +} + /** * \brief Loads and parses the given configurations files. * \param[in] root Handle to the root configuration node. @@ -3762,8 +3892,7 @@ int snd_config_hook_load(snd_config_t *root, snd_config_t *config, snd_config_t { snd_config_t *n; snd_config_iterator_t i, next; - struct finfo *fi = NULL; - int err, idx = 0, fi_count = 0, errors = 1, hit; + int err, idx = 0, errors = 1, hit; assert(root && dst); if ((err = snd_config_search(config, "errors", &n)) >= 0) { @@ -3790,20 +3919,6 @@ int snd_config_hook_load(snd_config_t *root, snd_config_t *config, snd_config_t SNDERR("Invalid type for field filenames"); goto _err; } - snd_config_for_each(i, next, n) { - snd_config_t *c = snd_config_iterator_entry(i); - const char *str; - if ((err = snd_config_get_string(c, &str)) < 0) { - SNDERR("Field %s is not a string", c->id); - goto _err; - } - fi_count++; - } - fi = calloc(fi_count, sizeof(*fi)); - if (fi == NULL) { - err = -ENOMEM; - goto _err; - } do { hit = 0; snd_config_for_each(i, next, n) { @@ -3817,67 +3932,35 @@ int snd_config_hook_load(snd_config_t *root, snd_config_t *config, snd_config_t goto _err; } if (i == idx) { - char *name; + char *name, *name2, *remain; if ((err = snd_config_get_ascii(n, &name)) < 0) goto _err; - if ((err = snd_user_file(name, &fi[idx].name)) < 0) - fi[idx].name = name; - else - free(name); + name2 = name; + remain = strstr(name, "|||"); + while (1) { + if (remain) { + *remain = '\0'; + remain += 3; + } + err = config_file_load_user(root, name2, errors); + if (err < 0) + goto _err; + if (err == 0) /* first hit wins */ + break; + if (!remain) + break; + name2 = remain; + remain = strstr(remain, "|||"); + } + free(name); idx++; hit = 1; } } } while (hit); - for (idx = 0; idx < fi_count; idx++) { - struct stat st; - if (!errors && access(fi[idx].name, R_OK) < 0) - continue; - if (stat(fi[idx].name, &st) < 0) { - SNDERR("cannot stat file/directory %s", fi[idx].name); - continue; - } - if (S_ISDIR(st.st_mode)) { - struct dirent **namelist; - int n; - -#ifndef DOC_HIDDEN -#if defined(_GNU_SOURCE) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__sun) && !defined(ANDROID) -#define SORTFUNC versionsort -#else -#define SORTFUNC alphasort -#endif -#endif - n = scandir(fi[idx].name, &namelist, config_filename_filter, SORTFUNC); - if (n > 0) { - int j; - err = 0; - for (j = 0; j < n; ++j) { - if (err >= 0) { - int sl = strlen(fi[idx].name) + strlen(namelist[j]->d_name) + 2; - char *filename = malloc(sl); - snprintf(filename, sl, "%s/%s", fi[idx].name, namelist[j]->d_name); - filename[sl-1] = '\0'; - - err = config_file_open(root, filename); - free(filename); - } - free(namelist[j]); - } - free(namelist); - if (err < 0) - goto _err; - } - } else if ((err = config_file_open(root, fi[idx].name)) < 0) - goto _err; - } *dst = NULL; err = 0; _err: - if (fi) - for (idx = 0; idx < fi_count; idx++) - free(fi[idx].name); - free(fi); snd_config_delete(n); return err; } diff --git a/src/conf/alsa.conf b/src/conf/alsa.conf index 0998058..a04173a 100644 --- a/src/conf/alsa.conf +++ b/src/conf/alsa.conf @@ -8,9 +8,23 @@ { func load files [ + "/usr/etc/alsa/conf.d" "/etc/alsa/conf.d" - "/etc/asound.conf" + "/etc/asound.conf|||/usr/etc/asound.conf" "~/.asoundrc" + { + @func concat + strings [ + { + @func getenv + vars [ + XDG_CONFIG_HOME + ] + default "~/.config" + } + "/alsa/asoundrc" + ] + } ] errors false } @@ -69,10 +83,11 @@ defaults.pcm.minperiodtime 5000 # in us defaults.pcm.ipc_key 5678293 defaults.pcm.ipc_gid audio defaults.pcm.ipc_perm 0660 +defaults.pcm.tstamp_type default defaults.pcm.dmix.max_periods 0 defaults.pcm.dmix.channels 2 defaults.pcm.dmix.rate 48000 -defaults.pcm.dmix.format "unchanged" +defaults.pcm.dmix.format unchanged defaults.pcm.dmix.card defaults.pcm.card defaults.pcm.dmix.device defaults.pcm.device defaults.pcm.dsnoop.card defaults.pcm.card @@ -101,9 +116,8 @@ defaults.pcm.iec958.card defaults.pcm.card defaults.pcm.iec958.device defaults.pcm.device defaults.pcm.modem.card defaults.pcm.card defaults.pcm.modem.device defaults.pcm.device -# truncate files via file or tee PCM -defaults.pcm.file_format "raw" -defaults.pcm.file_truncate true +defaults.pcm.file_format raw +defaults.pcm.file_truncate true # truncate files via file or tee PCM defaults.rawmidi.card 0 defaults.rawmidi.device 0 defaults.rawmidi.subdevice -1 @@ -119,29 +133,6 @@ defaults.timer.subdevice 0 # PCM interface # -# redirect to load-on-demand extended pcm definitions -pcm.cards cards.pcm - -pcm.default cards.pcm.default -pcm.sysdefault cards.pcm.default -pcm.front cards.pcm.front -pcm.rear cards.pcm.rear -pcm.center_lfe cards.pcm.center_lfe -pcm.side cards.pcm.side -pcm.surround21 cards.pcm.surround21 -pcm.surround40 cards.pcm.surround40 -pcm.surround41 cards.pcm.surround41 -pcm.surround50 cards.pcm.surround50 -pcm.surround51 cards.pcm.surround51 -pcm.surround71 cards.pcm.surround71 -pcm.iec958 cards.pcm.iec958 -pcm.spdif iec958 -pcm.hdmi cards.pcm.hdmi -pcm.dmix cards.pcm.dmix -pcm.dsnoop cards.pcm.dsnoop -pcm.modem cards.pcm.modem -pcm.phoneline cards.pcm.phoneline - pcm.hw { @args [ CARD DEV SUBDEV ] @args.CARD { @@ -323,6 +314,29 @@ pcm.null { } } +# redirect to load-on-demand extended pcm definitions +pcm.cards cards.pcm + +pcm.default cards.pcm.default +pcm.sysdefault cards.pcm.default +pcm.front cards.pcm.front +pcm.rear cards.pcm.rear +pcm.center_lfe cards.pcm.center_lfe +pcm.side cards.pcm.side +pcm.surround21 cards.pcm.surround21 +pcm.surround40 cards.pcm.surround40 +pcm.surround41 cards.pcm.surround41 +pcm.surround50 cards.pcm.surround50 +pcm.surround51 cards.pcm.surround51 +pcm.surround71 cards.pcm.surround71 +pcm.iec958 cards.pcm.iec958 +pcm.spdif iec958 +pcm.hdmi cards.pcm.hdmi +pcm.dmix cards.pcm.dmix +pcm.dsnoop cards.pcm.dsnoop +pcm.modem cards.pcm.modem +pcm.phoneline cards.pcm.phoneline + # # Control interface # diff --git a/src/conf/cards/USB-Audio.conf b/src/conf/cards/USB-Audio.conf index 1c67793..01664ab 100644 --- a/src/conf/cards/USB-Audio.conf +++ b/src/conf/cards/USB-Audio.conf @@ -39,10 +39,14 @@ USB-Audio.pcm.iec958_device { # "NoiseBlaster 3000" 42 "USB Sound Blaster HD" 1 "Xonar U7" 1 - + "ASUS XONAR U5" 1 + "XONAR U5" 1 + "XONAR SOUND CARD" 1 + # The below don't have digital in/out, so prevent them from being opened. "Andrea PureAudio USB-SA Headset" 999 "Blue Snowball" 999 + "C-Media USB Headphone Set" 999 "HP Digital Stereo Headset" 999 "GN 9330" 999 "Logitech Speaker Lapdesk N700" 999 @@ -58,6 +62,8 @@ USB-Audio.pcm.iec958_device { "Scarlett 2i4 USB" 999 "Sennheiser USB headset" 999 "SWTOR Gaming Headset by Razer" 999 + "Thunderbolt Dock Audio Headset" 999 + "Thunderbolt Dock Audio Module" 999 "USB Device 0x46d_0x821" 999 "USB Device 0x46d_0x992" 999 "WD15 Dock" 999 diff --git a/src/conf/pcm/dmix.conf b/src/conf/pcm/dmix.conf index 7fa5c8b..50e573d 100644 --- a/src/conf/pcm/dmix.conf +++ b/src/conf/pcm/dmix.conf @@ -56,6 +56,10 @@ pcm.!dmix { @func refer name defaults.pcm.ipc_perm } + tstamp_type { + @func refer + name defaults.pcm.tstamp_type + } slave { pcm { type hw diff --git a/src/conf/pcm/dsnoop.conf b/src/conf/pcm/dsnoop.conf index abbd44f..f4336e5 100644 --- a/src/conf/pcm/dsnoop.conf +++ b/src/conf/pcm/dsnoop.conf @@ -49,6 +49,10 @@ pcm.!dsnoop { @func refer name defaults.pcm.ipc_perm } + tstamp_type { + @func refer + name defaults.pcm.tstamp_type + } slave { pcm { type hw diff --git a/src/conf/pcm/front.conf b/src/conf/pcm/front.conf index 7aff0cb..a5839b3 100644 --- a/src/conf/pcm/front.conf +++ b/src/conf/pcm/front.conf @@ -52,7 +52,9 @@ pcm.!front { @func refer name defaults.namehint.basic } - description "Front speakers" - device $DEV + description "Front output / input" + device_output $DEV + device_input $DEV + omit_noargs true } } diff --git a/src/conf/pcm/iec958.conf b/src/conf/pcm/iec958.conf index ac139b5..2b084d6 100644 --- a/src/conf/pcm/iec958.conf +++ b/src/conf/pcm/iec958.conf @@ -78,6 +78,6 @@ pcm.!iec958 { name defaults.namehint.basic } description "IEC958 (S/PDIF) Digital Audio Output" - device $DEV + device_output $DEV } } diff --git a/src/conf/pcm/surround21.conf b/src/conf/pcm/surround21.conf index 1cf1b7a..ad19507 100644 --- a/src/conf/pcm/surround21.conf +++ b/src/conf/pcm/surround21.conf @@ -57,5 +57,6 @@ pcm.!surround21 { hint { description "2.1 Surround output to Front and Subwoofer speakers" device_output $DEV + omit_noargs true } } diff --git a/src/conf/pcm/surround40.conf b/src/conf/pcm/surround40.conf index 9788ad4..7c61502 100644 --- a/src/conf/pcm/surround40.conf +++ b/src/conf/pcm/surround40.conf @@ -55,5 +55,6 @@ pcm.!surround40 { hint { description "4.0 Surround output to Front and Rear speakers" device_output $DEV + omit_noargs true } } diff --git a/src/conf/pcm/surround41.conf b/src/conf/pcm/surround41.conf index 7b4ef3b..cb6c044 100644 --- a/src/conf/pcm/surround41.conf +++ b/src/conf/pcm/surround41.conf @@ -61,5 +61,6 @@ pcm.!surround41 { hint { description "4.1 Surround output to Front, Rear and Subwoofer speakers" device_output $DEV + omit_noargs true } } diff --git a/src/conf/pcm/surround50.conf b/src/conf/pcm/surround50.conf index 7d9a9e7..70d5406 100644 --- a/src/conf/pcm/surround50.conf +++ b/src/conf/pcm/surround50.conf @@ -61,5 +61,6 @@ pcm.!surround50 { hint { description "5.0 Surround output to Front, Center and Rear speakers" device_output $DEV + omit_noargs true } } diff --git a/src/conf/pcm/surround51.conf b/src/conf/pcm/surround51.conf index e67f007..d0236e4 100644 --- a/src/conf/pcm/surround51.conf +++ b/src/conf/pcm/surround51.conf @@ -57,5 +57,6 @@ pcm.!surround51 { hint { description "5.1 Surround output to Front, Center, Rear and Subwoofer speakers" device_output $DEV + omit_noargs true } } diff --git a/src/conf/pcm/surround71.conf b/src/conf/pcm/surround71.conf index a26c3f3..66792dd 100644 --- a/src/conf/pcm/surround71.conf +++ b/src/conf/pcm/surround71.conf @@ -59,5 +59,6 @@ pcm.!surround71 { hint { description "7.1 Surround output to Front, Center, Side, Rear and Woofer speakers" device_output $DEV + omit_noargs true } } diff --git a/src/control/control.c b/src/control/control.c index 3365015..19528ae 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -303,6 +303,7 @@ int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info) return ctl->ops->element_info(ctl, info); } +#if 0 /* deprecated */ static bool validate_element_member_dimension(snd_ctl_elem_info_t *info) { unsigned int members; @@ -328,6 +329,9 @@ static bool validate_element_member_dimension(snd_ctl_elem_info_t *info) return members == info->count; } +#else /* deprecated */ +#define validate_element_member_dimension(info) true +#endif /* deprecated */ /** * \brief Create and add some user-defined control elements of integer type. @@ -1333,13 +1337,13 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name, build_in++; } if (*build_in == NULL) { - buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32); + buf1 = malloc(strlen(str) + 32); if (buf1 == NULL) { err = -ENOMEM; goto _err; } lib = buf1; - sprintf(buf1, "%s/libasound_module_ctl_%s.so", ALSA_PLUGIN_DIR, str); + sprintf(buf1, "libasound_module_ctl_%s.so", str); } } #ifndef PIC @@ -2510,11 +2514,12 @@ const char *snd_ctl_elem_info_get_item_name(const snd_ctl_elem_info_t *obj) * #snd_ctl_elem_info_get_dimensions is deprecated without any replacement. */ #ifndef DOXYGEN -EXPORT_SYMBOL int INTERNAL(snd_ctl_elem_info_get_dimensions)(const snd_ctl_elem_info_t *obj) +EXPORT_SYMBOL int INTERNAL(snd_ctl_elem_info_get_dimensions)(const snd_ctl_elem_info_t *obj ATTRIBUTE_UNUSED) #else int snd_ctl_elem_info_get_dimensions(const snd_ctl_elem_info_t *obj) #endif { +#if 0 /* deprecated */ int i; assert(obj); @@ -2522,6 +2527,9 @@ int snd_ctl_elem_info_get_dimensions(const snd_ctl_elem_info_t *obj) if (obj->dimen.d[i]) break; return i + 1; +#else + return -EINVAL; +#endif } use_default_symbol_version(__snd_ctl_elem_info_get_dimensions, snd_ctl_elem_info_get_dimensions, ALSA_0.9.3); @@ -2535,15 +2543,19 @@ use_default_symbol_version(__snd_ctl_elem_info_get_dimensions, snd_ctl_elem_info * #snd_ctl_elem_info_get_dimension is deprecated without any replacement. */ #ifndef DOXYGEN -EXPORT_SYMBOL int INTERNAL(snd_ctl_elem_info_get_dimension)(const snd_ctl_elem_info_t *obj, unsigned int idx) +EXPORT_SYMBOL int INTERNAL(snd_ctl_elem_info_get_dimension)(const snd_ctl_elem_info_t *obj ATTRIBUTE_UNUSED, unsigned int idx ATTRIBUTE_UNUSED) #else int snd_ctl_elem_info_get_dimension(const snd_ctl_elem_info_t *obj, unsigned int idx) #endif { +#if 0 /* deprecated */ assert(obj); if (idx > 3) return 0; return obj->dimen.d[idx]; +#else /* deprecated */ + return -EINVAL; +#endif /* deprecated */ } use_default_symbol_version(__snd_ctl_elem_info_get_dimension, snd_ctl_elem_info_get_dimension, ALSA_0.9.3); @@ -2565,9 +2577,10 @@ use_default_symbol_version(__snd_ctl_elem_info_get_dimension, snd_ctl_elem_info_ * \deprecated Since 1.1.5 * #snd_ctl_elem_info_set_dimension is deprecated without any replacement. */ -int snd_ctl_elem_info_set_dimension(snd_ctl_elem_info_t *info, - const int dimension[4]) +int snd_ctl_elem_info_set_dimension(snd_ctl_elem_info_t *info ATTRIBUTE_UNUSED, + const int dimension[4] ATTRIBUTE_UNUSED) { +#if 0 /* deprecated */ unsigned int i; if (info == NULL) @@ -2581,6 +2594,9 @@ int snd_ctl_elem_info_set_dimension(snd_ctl_elem_info_t *info, } return 0; +#else /* deprecated */ + return -EINVAL; +#endif /* deprecated */ } /** diff --git a/src/control/ctlparse.c b/src/control/ctlparse.c index b0bb5ee..ee1e060 100644 --- a/src/control/ctlparse.c +++ b/src/control/ctlparse.c @@ -33,17 +33,20 @@ /* Function to convert from percentage to volume. val = percentage */ -#ifdef HAVE_SOFT_FLOAT -static inline long int convert_prange1(long val, long min, long max) +static inline long int convert_prange1(long perc, long min, long max) { - long temp = val * (max - min); - return temp / 100 + min + ((temp % 100) == 0 ? 0 : 1); -} -#else + long tmp; -#define convert_prange1(val, min, max) \ - ceil((val) * ((max) - (min)) * 0.01 + (min)) +#ifdef HAVE_SOFT_FLOAT + tmp = perc * (max - min); + tmp = tmp / 100 + ((tmp % 100) < 50 ? 0 : 1); +#else + tmp = rint((double)perc * (double)(max - min) * 0.01); #endif + if (tmp == 0 && perc > 0) + tmp++; + return tmp + min; +} #define check_range(val, min, max) \ ((val < min) ? (min) : ((val > max) ? (max) : (val))) @@ -301,6 +304,25 @@ static int get_ctl_enum_item_index(snd_ctl_t *handle, return -1; } +static unsigned int get_ctl_type_max_elements(snd_ctl_elem_type_t type) +{ + struct snd_ctl_elem_value value; + + switch (type) { + case SND_CTL_ELEM_TYPE_BOOLEAN: + case SND_CTL_ELEM_TYPE_INTEGER: + return ARRAY_SIZE(value.value.integer.value); + case SND_CTL_ELEM_TYPE_INTEGER64: + return ARRAY_SIZE(value.value.integer64.value); + case SND_CTL_ELEM_TYPE_ENUMERATED: + return ARRAY_SIZE(value.value.enumerated.item); + case SND_CTL_ELEM_TYPE_BYTES: + return ARRAY_SIZE(value.value.bytes.data); + default: + return 0; + } +} + /** * \brief parse ASCII string as CTL element value * \param handle CTL handle @@ -328,8 +350,11 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle, type = snd_ctl_elem_info_get_type(info); count = snd_ctl_elem_info_get_count(info); snd_ctl_elem_value_set_id(dst, &myid); + + if (count > get_ctl_type_max_elements(type)) + count = get_ctl_type_max_elements(type); - for (idx = 0; idx < count && idx < 128 && ptr && *ptr; idx++) { + for (idx = 0; idx < count && ptr && *ptr; idx++) { if (*ptr == ',') goto skip; switch (type) { diff --git a/src/control/namehint.c b/src/control/namehint.c index 808df6b..e4f696a 100644 --- a/src/control/namehint.c +++ b/src/control/namehint.c @@ -78,6 +78,31 @@ static int hint_list_add(struct hint_list *list, return 0; } +/** + * Add a namehint from string given in a user configuration file + */ +static int hint_list_add_custom(struct hint_list *list, + const char *entry) +{ + int err; + const char *sep; + char *name; + + assert(entry); + + sep = strchr(entry, '|'); + if (sep == NULL) + return hint_list_add(list, entry, NULL); + + name = strndup(entry, sep - entry); + if (name == NULL) + return -ENOMEM; + + err = hint_list_add(list, name, sep + 1); + free(name); + return err; +} + static void zero_handler(const char *file ATTRIBUTE_UNUSED, int line ATTRIBUTE_UNUSED, const char *function ATTRIBUTE_UNUSED, @@ -270,8 +295,6 @@ static int try_config(snd_config_t *config, if (snd_config_search(cfg1, "type", &cfg) >= 0 && snd_config_get_string(cfg, &str) >= 0 && strcmp(str, "hw") == 0) { - list->device_input = -1; - list->device_output = -1; if (snd_config_search(cfg1, "device", &cfg) >= 0) { if (snd_config_get_integer(cfg, &dev) < 0) { SNDERR("(%s) device must be an integer", buf); @@ -287,10 +310,14 @@ static int try_config(snd_config_t *config, err = -EINVAL; goto __cleanup; } + if (list->card < 0 && + snd_config_search(cfg, "omit_noargs", &n) >= 0 && + snd_config_get_bool(n) > 0) + goto __skip_add; if (level == 1 && snd_config_search(cfg, "show", &n) >= 0 && snd_config_get_bool(n) <= 0) - goto __skip_add; + goto __skip_add; if (buf1 == NULL && snd_config_search(cfg, "description", &n) >= 0 && snd_config_get_string(n, &str) >= 0) { @@ -348,6 +375,13 @@ static int try_config(snd_config_t *config, goto __cleanup; if (snd_config_search(res, "@args", &cfg) >= 0) { snd_config_for_each(i, next, cfg) { + /* skip the argument list */ + if (snd_config_get_id(snd_config_iterator_entry(i), &str) < 0) + continue; + while (*str && *str >= '0' && *str <= '9') str++; + if (*str == '\0') + continue; + /* the argument definition must have the default */ if (snd_config_search(snd_config_iterator_entry(i), "default", NULL) < 0) { err = -EINVAL; @@ -534,10 +568,10 @@ static int add_software_devices(snd_config_t *config, snd_config_t *rw_config, * User-defined hints are gathered from namehint.IFACE tree like: * * - * namehint.pcm {
+ * namehint.pcm [
* myfile "file:FILE=/tmp/soundwave.raw|Save sound output to /tmp/soundwave.raw"
- * myplug "plug:front:Do all conversions for front speakers"
- * } + * myplug "plug:front|Do all conversions for front speakers"
+ * ] *
* * Note: The device description is separated with '|' char. @@ -617,7 +651,7 @@ int snd_device_name_hint(int card, const char *iface, void ***hints) if (snd_config_get_string(snd_config_iterator_entry(i), &str) < 0) continue; - err = hint_list_add(&list, str, NULL); + err = hint_list_add_custom(&list, str); if (err < 0) goto __error; } diff --git a/src/control/tlv.c b/src/control/tlv.c index d6944b5..d5044eb 100644 --- a/src/control/tlv.c +++ b/src/control/tlv.c @@ -286,7 +286,8 @@ int snd_tlv_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax, * \param db_gain the dB gain to convert (in 0.01dB unit) * \param value the pointer to store the converted raw volume value * \param xdir the direction for round-up. The value is round up - * when this is positive. + * when this is positive. A negative value means round down. + * Zero means round-up to nearest. * \return 0 if successful, or a negative error code */ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax, @@ -346,6 +347,8 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax, long v = (db_gain - min) * (rangemax - rangemin); if (xdir > 0) v += (max - min) - 1; + else if (xdir == 0) + v += ((max - min) + 1) / 2; v = v / (max - min) + rangemin; *value = v; } @@ -368,6 +371,8 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax, long v = (db_gain - min) * (rangemax - rangemin); if (xdir > 0) v += (max - min) - 1; + else if (xdir == 0) + v += ((max - min) + 1) / 2; v = v / (max - min) + rangemin; *value = v; } @@ -392,6 +397,8 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax, v = (v - vmin) * (rangemax - rangemin) / (vmax - vmin); if (xdir > 0) v = ceil(v); + else if (xdir == 0) + v = lrint(v); *value = (long)v + rangemin; } return 0; diff --git a/src/dlmisc.c b/src/dlmisc.c index 8c8f3ff..1a60e0d 100644 --- a/src/dlmisc.c +++ b/src/dlmisc.c @@ -32,12 +32,75 @@ #ifdef HAVE_LIBPTHREAD #include #endif +#include + +#if defined(HAVE_LIBDL) && defined(__GLIBC__) && !defined(__UCLIBC__) +#define DL_ORIGIN_AVAILABLE 1 +#endif #ifndef DOC_HIDDEN #ifndef PIC struct snd_dlsym_link *snd_dlsym_start = NULL; #endif +#ifdef DL_ORIGIN_AVAILABLE +static int snd_libdir_plugin_dir_set = 0; +static char *snd_libdir_origin = NULL; +#endif +#endif + +#if defined(DL_ORIGIN_AVAILABLE) && defined(HAVE_LIBPTHREAD) +static pthread_mutex_t snd_dlpath_mutex = PTHREAD_MUTEX_INITIALIZER; + +static inline void snd_dlpath_lock(void) +{ + pthread_mutex_lock(&snd_dlpath_mutex); +} + +static inline void snd_dlpath_unlock(void) +{ + pthread_mutex_unlock(&snd_dlpath_mutex); +} +#else +static inline void snd_dlpath_lock(void) {} +static inline void snd_dlpath_unlock(void) {} +#endif + +/** + * + * \brief Compose the dynamic path + * \param path Returned path (string) + * \param path_len Returned path max size (with trailing zero) + * \param name Plugin name (relative) + * \return Zero on success, otherwise a negative error code + */ +int snd_dlpath(char *path, size_t path_len, const char *name) +{ +#ifdef DL_ORIGIN_AVAILABLE + snd_dlpath_lock(); + if (!snd_libdir_plugin_dir_set) { + struct link_map *links; + Dl_info info; + char origin[PATH_MAX]; + if (dladdr1(&snd_dlpath, &info, (void**)&links, RTLD_DL_LINKMAP) == 0) + links = NULL; + if (links != NULL && dlinfo(links, RTLD_DI_ORIGIN, origin) == 0) { + snprintf(path, path_len, "%s/alsa-lib", origin); + if (access(path, X_OK) == 0) + snd_libdir_origin = strdup(origin); + } + snd_libdir_plugin_dir_set = 1; + } + if (snd_libdir_origin) { + snprintf(path, path_len, "%s/alsa-lib/%s", snd_libdir_origin, name); + } else { + snprintf(path, path_len, "%s/%s", ALSA_PLUGIN_DIR, name); + } + snd_dlpath_unlock(); +#else + snprintf(path, path_len, "%s/%s", ALSA_PLUGIN_DIR, name); #endif + return 0; +} /** * \brief Opens a dynamic library - ALSA wrapper for \c dlopen. @@ -79,14 +142,12 @@ void *snd_dlopen(const char *name, int mode, char *errbuf, size_t errbuflen) * via ld.so.conf. */ void *handle = NULL; - char *filename = NULL; + const char *filename = NULL; + char path[PATH_MAX]; if (name && name[0] != '/') { - filename = alloca(sizeof(ALSA_PLUGIN_DIR) + 1 + strlen(name) + 1); - if (filename) { - strcpy(filename, ALSA_PLUGIN_DIR); - strcat(filename, "/"); - strcat(filename, name); + if (snd_dlpath(path, sizeof(path), name) == 0) { + filename = path; handle = dlopen(filename, mode); if (!handle) { /* if the filename exists and cannot be opened */ @@ -97,6 +158,7 @@ void *snd_dlopen(const char *name, int mode, char *errbuf, size_t errbuflen) } } if (!handle) { + filename = name; handle = dlopen(name, mode); if (!handle) goto errpath; @@ -385,7 +447,13 @@ void snd_dlobj_cache_cleanup(void) free((void *)c->lib); /* shut up gcc warning */ free(c); } - snd_dlobj_unlock(); +#ifdef DL_ORIGIN_AVAILABLE + snd_dlpath_lock(); + snd_libdir_plugin_dir_set = 0; + free(snd_libdir_origin); + snd_libdir_origin = NULL; + snd_dlpath_unlock(); +#endif } #endif diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index 8205647..b1af994 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -767,7 +767,7 @@ int snd_mixer_wait(snd_mixer_t *mixer, int timeout) if (count < 0) return count; if ((unsigned int) count > sizeof(spfds) / sizeof(spfds[0])) { - pfds = malloc(count * sizeof(*pfds)); + pfds = alloca(count * sizeof(*pfds)); if (!pfds) return -ENOMEM; err = snd_mixer_poll_descriptors(mixer, pfds, diff --git a/src/mixer/simple.c b/src/mixer/simple.c index 2861d97..571fa66 100644 --- a/src/mixer/simple.c +++ b/src/mixer/simple.c @@ -376,7 +376,8 @@ int snd_mixer_selem_ask_playback_vol_dB(snd_mixer_elem_t *elem, long value, long * \brief Return corresponding integer playback volume for given dB value for a mixer simple element * \param elem Mixer simple element handle * \param value value to be converted to dB range - * \param dir rounding mode - rounds up if dir > 0, otherwise rounds down + * \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0, + * rounds down if dir < 0 * \param dBvalue pointer to returned dB value * \return 0 on success otherwise a negative error code */ @@ -454,7 +455,8 @@ int snd_mixer_selem_set_playback_volume(snd_mixer_elem_t *elem, snd_mixer_selem_ * \param elem Mixer simple element handle * \param channel mixer simple element channel identifier * \param value control value in dB * 100 - * \param dir rounding mode - rounds up if dir > 0, otherwise rounds down + * \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0, + * rounds down if dir < 0 * \return 0 on success otherwise a negative error code */ int snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir) @@ -491,7 +493,8 @@ int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t *elem, long value) * \brief Set value in dB of playback volume control for all channels of a mixer simple element * \param elem Mixer simple element handle * \param value control value in dB * 100 - * \param dir rounding mode - rounds up if dir > 0, otherwise rounds down + * \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0, + * rounds down if dir < 0 * \return 0 on success otherwise a negative error code */ int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, long value, int dir) @@ -706,7 +709,8 @@ int snd_mixer_selem_ask_capture_vol_dB(snd_mixer_elem_t *elem, long value, long * \param elem Mixer simple element handle * \param dBvalue dB value to be converted to integer range * \param value pointer to returned integer value - * \param dir rounding mode - rounds up if dir > 0, otherwise rounds down + * \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0, + * rounds down if dir < 0 * \return 0 on success otherwise a negative error code */ int snd_mixer_selem_ask_capture_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value) @@ -777,7 +781,8 @@ int snd_mixer_selem_set_capture_volume(snd_mixer_elem_t *elem, snd_mixer_selem_c * \param elem Mixer simple element handle * \param channel mixer simple element channel identifier * \param value control value in dB * 100 - * \param dir rounding mode - rounds up if dir > 0, otherwise rounds down + * \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0, + * rounds down if dir < 0 * \return 0 on success otherwise a negative error code */ int snd_mixer_selem_set_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir) @@ -814,7 +819,8 @@ int snd_mixer_selem_set_capture_volume_all(snd_mixer_elem_t *elem, long value) * \brief Set value in dB of capture volume control for all channels of a mixer simple element * \param elem Mixer simple element handle * \param value control value in dB * 100 - * \param dir rounding mode - rounds up if dir > 0, otherwise rounds down + * \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0, + * rounds down if dir < 0 * \return 0 on success otherwise a negative error code */ int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, long value, int dir) diff --git a/src/mixer/simple_abst.c b/src/mixer/simple_abst.c index 9c61cb5..4dcc4cc 100644 --- a/src/mixer/simple_abst.c +++ b/src/mixer/simple_abst.c @@ -40,7 +40,7 @@ #ifndef DOC_HIDDEN -#define SO_PATH ALSA_PLUGIN_DIR "/smixer" +#define SO_PATH "smixer" typedef struct _class_priv { char *device; diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 1064044..06a48f4 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -284,7 +284,7 @@ supports resume and the snd_pcm_prepare() call can be ommited. \par -EBADFD This error means that the device is in a bad state. It means that -the handskahe between application and alsa-lib is corrupted. +the handshake between application and alsa-lib is corrupted. \par -ENOTTY, -ENODEV @@ -292,6 +292,19 @@ This error can happen when device is physically removed (for example some hotplug devices like USB or PCMCIA, CardBus or ExpressCard can be removed on the fly). +\par -ENODATA + +This error can happen if the device data transfer is dependent on +an external condition and that condition is not met. For example, +PCM device for echo reference as described by SND_USE_CASE_MOD_ECHO_REF +UCM token, may return -ENODATA if the linked playback stream has not been +started. + +There is no defined recovery or event mechanism to signal the data / link +availability at the moment. The PCM must be completely restarted until +the mechanism is designed. The #snd_pcm_recover() function cannot be +used for this. + \section pcm_params Managing parameters The ALSA PCM device uses two groups of PCM related parameters. The hardware @@ -680,7 +693,8 @@ static int pcm_state_to_error(snd_pcm_state_t state) P_STATE(DRAINING)) /* check whether the PCM is in the unexpected state */ -static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states) +static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states, + unsigned int noop_states) { snd_pcm_state_t state; int err; @@ -688,6 +702,8 @@ static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states) if (pcm->own_state_check) return 0; /* don't care, the plugin checks by itself */ state = snd_pcm_state(pcm); + if (noop_states & (1U << state)) + return 1; /* OK, return immediately */ if (supported_states & (1U << state)) return 0; /* OK */ err = pcm_state_to_error(state); @@ -1206,7 +1222,7 @@ int snd_pcm_prepare(snd_pcm_t *pcm) SNDMSG("PCM not set up"); return -EIO; } - err = bad_pcm_state(pcm, ~P_STATE(DISCONNECTED)); + err = bad_pcm_state(pcm, ~P_STATE(DISCONNECTED), 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1261,7 +1277,7 @@ int snd_pcm_start(snd_pcm_t *pcm) SNDMSG("PCM not set up"); return -EIO; } - err = bad_pcm_state(pcm, P_STATE(PREPARED)); + err = bad_pcm_state(pcm, P_STATE(PREPARED), 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1293,7 +1309,7 @@ int snd_pcm_drop(snd_pcm_t *pcm) return -EIO; } err = bad_pcm_state(pcm, P_STATE_RUNNABLE | P_STATE(SETUP) | - P_STATE(SUSPENDED)); + P_STATE(SUSPENDED), 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1329,9 +1345,11 @@ int snd_pcm_drain(snd_pcm_t *pcm) SNDMSG("PCM not set up"); return -EIO; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE | P_STATE(SETUP), P_STATE(SETUP)); if (err < 0) return err; + if (err == 1) + return 0; /* lock handled in the callback */ if (pcm->fast_ops->drain) err = pcm->fast_ops->drain(pcm->fast_op_arg); @@ -1361,7 +1379,7 @@ int snd_pcm_pause(snd_pcm_t *pcm, int enable) SNDMSG("PCM not set up"); return -EIO; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1394,7 +1412,7 @@ snd_pcm_sframes_t snd_pcm_rewindable(snd_pcm_t *pcm) SNDMSG("PCM not set up"); return -EIO; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1427,7 +1445,7 @@ snd_pcm_sframes_t snd_pcm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames) } if (frames == 0) return 0; - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1460,7 +1478,7 @@ snd_pcm_sframes_t snd_pcm_forwardable(snd_pcm_t *pcm) SNDMSG("PCM not set up"); return -EIO; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1497,7 +1515,7 @@ snd_pcm_sframes_t snd_pcm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames) } if (frames == 0) return 0; - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -1543,7 +1561,7 @@ snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_ufr SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access)); return -EINVAL; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; return _snd_pcm_writei(pcm, buffer, size); @@ -1582,7 +1600,7 @@ snd_pcm_sframes_t snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access)); return -EINVAL; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; return _snd_pcm_writen(pcm, bufs, size); @@ -1621,7 +1639,7 @@ snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access)); return -EINVAL; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; return _snd_pcm_readi(pcm, buffer, size); @@ -1660,7 +1678,7 @@ snd_pcm_sframes_t snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t s SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access)); return -EINVAL; } - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; return _snd_pcm_readn(pcm, bufs, size); @@ -2573,13 +2591,13 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name, build_in++; } if (*build_in == NULL) { - buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32); + buf1 = malloc(strlen(str) + 32); if (buf1 == NULL) { err = -ENOMEM; goto _err; } lib = buf1; - sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str); + sprintf(buf1, "libasound_module_pcm_%s.so", str); } } #ifndef PIC @@ -2745,6 +2763,7 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); #endif pthread_mutex_init(&pcm->lock, &attr); + pthread_mutexattr_destroy(&attr); /* use locking as default; * each plugin may suppress this in its open call */ @@ -7189,7 +7208,7 @@ int snd_pcm_mmap_begin(snd_pcm_t *pcm, { int err; - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); @@ -7294,7 +7313,7 @@ snd_pcm_sframes_t snd_pcm_mmap_commit(snd_pcm_t *pcm, snd_pcm_sframes_t result; int err; - err = bad_pcm_state(pcm, P_STATE_RUNNABLE); + err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0); if (err < 0) return err; snd_pcm_lock(pcm->fast_op_arg); diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 54d9900..6653409 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -929,10 +929,14 @@ int snd_pcm_direct_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) return err; if (dshare->var_periodsize) { /* more tolerant settings... */ - if (dshare->shmptr->hw.buffer_size.max / 2 > period_size.max) + if (dshare->shmptr->hw.buffer_size.max / 2 > period_size.max) { period_size.max = dshare->shmptr->hw.buffer_size.max / 2; - if (dshare->shmptr->hw.buffer_time.max / 2 > period_time.max) + period_size.openmax = dshare->shmptr->hw.buffer_size.openmax; + } + if (dshare->shmptr->hw.buffer_time.max / 2 > period_time.max) { period_time.max = dshare->shmptr->hw.buffer_time.max / 2; + period_time.openmax = dshare->shmptr->hw.buffer_time.openmax; + } } err = hw_param_interval_refine_one(params, SND_PCM_HW_PARAM_PERIOD_SIZE, @@ -991,8 +995,11 @@ int snd_pcm_direct_hw_free(snd_pcm_t *pcm ATTRIBUTE_UNUSED) return 0; } -int snd_pcm_direct_sw_params(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t * params ATTRIBUTE_UNUSED) +int snd_pcm_direct_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) { + if (params->tstamp_type != pcm->tstamp_type) + return -EINVAL; + /* values are cached in the pcm structure */ return 0; } @@ -1318,6 +1325,15 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str return ret; } + if (dmix->tstamp_type != -1) { + ret = snd_pcm_sw_params_set_tstamp_type(spcm, &sw_params, + dmix->tstamp_type); + if (ret < 0) { + SNDERR("unable to set tstamp type"); + return ret; + } + } + if (dmix->type != SND_PCM_TYPE_DMIX && dmix->type != SND_PCM_TYPE_DSHARE) goto __skip_silencing; @@ -1878,6 +1894,7 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf, rec->var_periodsize = 0; rec->direct_memory_access = 1; rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_AUTO; + rec->tstamp_type = -1; /* read defaults */ if (snd_config_search(root, "defaults.pcm.dmix_max_periods", &n) >= 0) { @@ -1941,6 +1958,27 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf, continue; } + if (strcmp(id, "tstamp_type") == 0) { + const char *str; + err = snd_config_get_string(n, &str); + if (err < 0) { + SNDERR("Invalid type for %s", id); + return -EINVAL; + } + if (strcmp(str, "default") == 0) + rec->tstamp_type = -1; + else if (strcmp(str, "gettimeofday") == 0) + rec->tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY; + else if (strcmp(str, "monotonic") == 0) + rec->tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC; + else if (strcmp(str, "monotonic_raw") == 0) + rec->tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW; + else { + SNDERR("The field tstamp_type is invalid : %s", str); + return -EINVAL; + } + continue; + } if (strcmp(id, "ipc_gid") == 0) { char *group; char *endp; diff --git a/src/pcm/pcm_direct.h b/src/pcm/pcm_direct.h index 221edbe..8a23697 100644 --- a/src/pcm/pcm_direct.h +++ b/src/pcm/pcm_direct.h @@ -173,6 +173,7 @@ struct snd_pcm_direct { unsigned int recoveries; /* mirror of executed recoveries on slave */ int direct_memory_access; /* use arch-optimized buffer RW */ snd_pcm_direct_hw_ptr_alignment_t hw_ptr_alignment; + int tstamp_type; /* cached from conf, can be -1(default) on top of real types */ union { struct { int shmid_sum; /* IPC global sum ring buffer memory identification */ @@ -357,6 +358,7 @@ struct snd_pcm_direct_open_conf { int var_periodsize; int direct_memory_access; snd_pcm_direct_hw_ptr_alignment_t hw_ptr_alignment; + int tstamp_type; snd_config_t *slave; snd_config_t *bindings; }; diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c index d533f40..843fa31 100644 --- a/src/pcm/pcm_dmix.c +++ b/src/pcm/pcm_dmix.c @@ -1038,6 +1038,7 @@ int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name, dmix->ipc_key = opts->ipc_key; dmix->ipc_perm = opts->ipc_perm; dmix->ipc_gid = opts->ipc_gid; + dmix->tstamp_type = opts->tstamp_type; dmix->semid = -1; dmix->shmid = -1; @@ -1237,6 +1238,9 @@ pcm.name { # roundup # rounddown # auto (default) + tstamp_type STR # timestamp type + # STR can be one of the below strings : + # default, gettimeofday, monotonic, monotonic_raw slave STR # or slave { # Slave definition diff --git a/src/pcm/pcm_dmix_i386.h b/src/pcm/pcm_dmix_i386.h index 2778cb1..8dcba3d 100644 --- a/src/pcm/pcm_dmix_i386.h +++ b/src/pcm/pcm_dmix_i386.h @@ -26,6 +26,10 @@ * */ +#if defined(__GNUC__) && __GNUC__ < 5 && defined(__PIC__) +# define BOUNDED_EBX +#endif + /* * for plain i386 */ @@ -34,8 +38,9 @@ static void MIX_AREAS_16(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_EBX unsigned int old_ebx; - +#endif /* * ESI - src * EDI - dst @@ -46,15 +51,16 @@ static void MIX_AREAS_16(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovl %%ebx, %7\n" /* ebx is GOT pointer (-fPIC) */ +#ifdef BOUNDED_EBX + "\tmovl %%ebx, %[old_ebx]\n" /* ebx is GOT pointer (-fPIC) */ +#endif /* * initialization, load ESI, EDI, EBX registers */ - "\tmovl %1, %%edi\n" - "\tmovl %2, %%esi\n" - "\tmovl %3, %%ebx\n" - "\tcmpl $0, %0\n" + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" + "\tcmpl $0, %[size]\n" "\tjnz 2f\n" "\tjmp 7f\n" @@ -64,9 +70,9 @@ static void MIX_AREAS_16(unsigned int size, */ "\t.p2align 4,,15\n" "1:" - "\tadd %4, %%edi\n" - "\tadd %5, %%esi\n" - "\tadd %6, %%ebx\n" + "\tadd %[dst_step], %%edi\n" + "\tadd %[src_step], %%esi\n" + "\tadd %[sum_step], %%ebx\n" /* * sample = *src; @@ -108,7 +114,7 @@ static void MIX_AREAS_16(unsigned int size, /* * while (size-- > 0) */ - "\tdecl %0\n" + "\tdecl %[size]\n" "\tjnz 1b\n" "\tjmp 7f\n" @@ -122,7 +128,7 @@ static void MIX_AREAS_16(unsigned int size, "\tmovw $0x7fff, (%%edi)\n" "\tcmpl %%ecx,(%%ebx)\n" "\tjnz 4b\n" - "\tdecl %0\n" + "\tdecl %[size]\n" "\tjnz 1b\n" "\tjmp 7f\n" @@ -136,17 +142,24 @@ static void MIX_AREAS_16(unsigned int size, "\tmovw $-0x8000, (%%edi)\n" "\tcmpl %%ecx, (%%ebx)\n" "\tjnz 4b\n" - "\tdecl %0\n" + "\tdecl %[size]\n" "\tjnz 1b\n" - - "7:" - "\tmovl %7, %%ebx\n" /* ebx is GOT pointer (-fPIC) */ - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_ebx) - : "esi", "edi", "edx", "ecx", "eax" + "7:" +#ifdef BOUNDED_EBX + "\tmovl %[old_ebx], %%ebx\n" /* ebx is GOT pointer (-fPIC) */ +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_EBX + , [old_ebx] "=m" (old_ebx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "esi", "edi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_EBX + , "ebx" +#endif ); } @@ -158,8 +171,9 @@ static void MIX_AREAS_16_MMX(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_EBX unsigned int old_ebx; - +#endif /* * ESI - src * EDI - dst @@ -170,23 +184,24 @@ static void MIX_AREAS_16_MMX(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovl %%ebx, %7\n" /* ebx is GOT pointer (-fPIC) */ +#ifdef BOUNDED_EBX + "\tmovl %%ebx, %[old_ebx]\n" /* ebx is GOT pointer (-fPIC) */ +#endif /* * initialization, load ESI, EDI, EBX registers */ - "\tmovl %1, %%edi\n" - "\tmovl %2, %%esi\n" - "\tmovl %3, %%ebx\n" - "\tcmpl $0, %0\n" + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" + "\tcmpl $0, %[size]\n" "\tjnz 2f\n" "\tjmp 5f\n" "\t.p2align 4,,15\n" "1:" - "\tadd %4, %%edi\n" - "\tadd %5, %%esi\n" - "\tadd %6, %%ebx\n" + "\tadd %[dst_step], %%edi\n" + "\tadd %[src_step], %%esi\n" + "\tadd %[sum_step], %%ebx\n" "2:" /* @@ -226,17 +241,30 @@ static void MIX_AREAS_16_MMX(unsigned int size, /* * while (size-- > 0) */ - "\tdecl %0\n" + "\tdecl %[size]\n" "\tjnz 1b\n" "\temms\n" "5:" - "\tmovl %7, %%ebx\n" /* ebx is GOT pointer (-fPIC) */ - - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_ebx) - : "esi", "edi", "edx", "ecx", "eax" +#ifdef BOUNDED_EBX + "\tmovl %[old_ebx], %%ebx\n" /* ebx is GOT pointer (-fPIC) */ +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_EBX + , [old_ebx] "=m" (old_ebx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "esi", "edi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_EBX + , "ebx" +#endif +#ifdef HAVE_MMX + , "mm0" +#else + , "st", "st(1)", "st(2)", "st(3)", + "st(4)", "st(5)", "st(6)", "st(7)" +#endif ); } @@ -248,8 +276,9 @@ static void MIX_AREAS_32(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_EBX unsigned int old_ebx; - +#endif /* * ESI - src * EDI - dst @@ -260,15 +289,16 @@ static void MIX_AREAS_32(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovl %%ebx, %7\n" /* ebx is GOT pointer (-fPIC) */ +#ifdef BOUNDED_EBX + "\tmovl %%ebx, %[old_ebx]\n" /* ebx is GOT pointer (-fPIC) */ +#endif /* * initialization, load ESI, EDI, EBX registers */ - "\tmovl %1, %%edi\n" - "\tmovl %2, %%esi\n" - "\tmovl %3, %%ebx\n" - "\tcmpl $0, %0\n" + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" + "\tcmpl $0, %[size]\n" "\tjnz 1f\n" "\tjmp 6f\n" @@ -335,21 +365,28 @@ static void MIX_AREAS_32(unsigned int size, /* * while (size-- > 0) */ - "\tdecl %0\n" + "\tdecl %[size]\n" "\tjz 6f\n" - "\tadd %4, %%edi\n" - "\tadd %5, %%esi\n" - "\tadd %6, %%ebx\n" + "\tadd %[dst_step], %%edi\n" + "\tadd %[src_step], %%esi\n" + "\tadd %[sum_step], %%ebx\n" "\tjmp 1b\n" - - "6:" - "\tmovl %7, %%ebx\n" /* ebx is GOT pointer (-fPIC) */ - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_ebx) - : "esi", "edi", "edx", "ecx", "eax" + "6:" +#ifdef BOUNDED_EBX + "\tmovl %[old_ebx], %%ebx\n" /* ebx is GOT pointer (-fPIC) */ +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_EBX + , [old_ebx] "=m" (old_ebx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "esi", "edi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_EBX + , "ebx" +#endif ); } @@ -361,8 +398,9 @@ static void MIX_AREAS_24(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_EBX unsigned int old_ebx; - +#endif /* * ESI - src * EDI - dst @@ -373,15 +411,16 @@ static void MIX_AREAS_24(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovl %%ebx, %7\n" /* ebx is GOT pointer (-fPIC) */ +#ifdef BOUNDED_EBX + "\tmovl %%ebx, %[old_ebx]\n" /* ebx is GOT pointer (-fPIC) */ +#endif /* * initialization, load ESI, EDI, EBX registers */ - "\tmovl %1, %%edi\n" - "\tmovl %2, %%esi\n" - "\tmovl %3, %%ebx\n" - "\tcmpl $0, %0\n" + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" + "\tcmpl $0, %[size]\n" "\tjnz 1f\n" "\tjmp 6f\n" @@ -441,21 +480,28 @@ static void MIX_AREAS_24(unsigned int size, /* * while (size-- > 0) */ - "\tdecl %0\n" + "\tdecl %[size]\n" "\tjz 6f\n" - "\tadd %4, %%edi\n" - "\tadd %5, %%esi\n" - "\tadd %6, %%ebx\n" + "\tadd %[dst_step], %%edi\n" + "\tadd %[src_step], %%esi\n" + "\tadd %[sum_step], %%ebx\n" "\tjmp 1b\n" - - "6:" - "\tmovl %7, %%ebx\n" /* ebx is GOT pointer (-fPIC) */ - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_ebx) - : "esi", "edi", "edx", "ecx", "eax" + "6:" +#ifdef BOUNDED_EBX + "\tmovl %[old_ebx], %%ebx\n" /* ebx is GOT pointer (-fPIC) */ +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_EBX + , [old_ebx] "=m" (old_ebx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "esi", "edi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_EBX + , "ebx" +#endif ); } @@ -467,8 +513,9 @@ static void MIX_AREAS_24_CMOV(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_EBX unsigned int old_ebx; - +#endif /* * ESI - src * EDI - dst @@ -479,15 +526,16 @@ static void MIX_AREAS_24_CMOV(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovl %%ebx, %7\n" /* ebx is GOT pointer (-fPIC) */ +#ifdef BOUNDED_EBX + "\tmovl %%ebx, %[old_ebx]\n" /* ebx is GOT pointer (-fPIC) */ +#endif /* * initialization, load ESI, EDI, EBX registers */ - "\tmovl %1, %%edi\n" - "\tmovl %2, %%esi\n" - "\tmovl %3, %%ebx\n" - "\tcmpl $0, %0\n" + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" + "\tcmpl $0, %[size]\n" "\tjz 6f\n" "\t.p2align 4,,15\n" @@ -541,19 +589,30 @@ static void MIX_AREAS_24_CMOV(unsigned int size, /* * while (size-- > 0) */ - "\tadd %4, %%edi\n" - "\tadd %5, %%esi\n" - "\tadd %6, %%ebx\n" - "\tdecl %0\n" + "\tadd %[dst_step], %%edi\n" + "\tadd %[src_step], %%esi\n" + "\tadd %[sum_step], %%ebx\n" + "\tdecl %[size]\n" "\tjnz 1b\n" - - "6:" - "\tmovl %7, %%ebx\n" /* ebx is GOT pointer (-fPIC) */ - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_ebx) - : "esi", "edi", "edx", "ecx", "eax" + "6:" +#ifdef BOUNDED_EBX + "\tmovl %[old_ebx], %%ebx\n" /* ebx is GOT pointer (-fPIC) */ +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_EBX + , [old_ebx] "=m" (old_ebx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "esi", "edi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_EBX + , "ebx" +#endif ); } + +#ifdef BOUNDED_EBX +# undef BOUNDED_EBX +#endif diff --git a/src/pcm/pcm_dmix_x86_64.h b/src/pcm/pcm_dmix_x86_64.h index 1ef608a..1932be3 100644 --- a/src/pcm/pcm_dmix_x86_64.h +++ b/src/pcm/pcm_dmix_x86_64.h @@ -27,6 +27,10 @@ * */ +#if defined(__GNUC__) && __GNUC__ < 5 && defined(__PIC__) +# define BOUNDED_RBX +#endif + /* * MMX optimized */ @@ -35,8 +39,9 @@ static void MIX_AREAS_16(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_RBX unsigned long long old_rbx; - +#endif /* * RSI - src * RDI - dst @@ -47,19 +52,26 @@ static void MIX_AREAS_16(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovq %%rbx, %7\n" +#ifdef BOUNDED_RBX + "\tmovq %%rbx, %[old_rbx]\n" +#endif /* * initialization, load RSI, RDI, RBX registers */ - "\tmovq %1, %%rdi\n" - "\tmovq %2, %%rsi\n" - "\tmovq %3, %%rbx\n" +#ifndef _ILP32 + "\tmovq %[dst], %%rdi\n" + "\tmovq %[src], %%rsi\n" + "\tmovq %[sum], %%rbx\n" +#else + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" +#endif /* * while (size-- > 0) { */ - "\tcmpl $0, %0\n" + "\tcmpl $0, %[size]\n" "jz 6f\n" "\t.p2align 4,,15\n" @@ -103,22 +115,41 @@ static void MIX_AREAS_16(unsigned int size, /* * while (size-- > 0) */ - "\tadd %4, %%rdi\n" - "\tadd %5, %%rsi\n" - "\tadd %6, %%rbx\n" - "\tdecl %0\n" +#ifndef _ILP32 + "\taddq %[dst_step], %%rdi\n" + "\taddq %[src_step], %%rsi\n" + "\taddq %[sum_step], %%rbx\n" +#else + "\taddl %[dst_step], %%edi\n" + "\taddl %[src_step], %%esi\n" + "\taddl %[sum_step], %%ebx\n" +#endif + "\tdecl %[size]\n" "\tjnz 1b\n" "6:" - - "\temms\n" - "\tmovq %7, %%rbx\n" - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_rbx) - : "rsi", "rdi", "edx", "ecx", "eax" + "\temms\n" +#ifdef BOUNDED_RBX + "\tmovq %[old_rbx], %%rbx\n" +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_RBX + , [old_rbx] "=m" (old_rbx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "rsi", "rdi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_RBX + , "rbx" +#endif +#ifdef HAVE_MMX + , "mm0" +#else + , "st", "st(1)", "st(2)", "st(3)", + "st(4)", "st(5)", "st(6)", "st(7)" +#endif ); } @@ -130,8 +161,9 @@ static void MIX_AREAS_32(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_RBX unsigned long long old_rbx; - +#endif /* * RSI - src * RDI - dst @@ -142,19 +174,26 @@ static void MIX_AREAS_32(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovq %%rbx, %7\n" +#ifdef BOUNDED_RBX + "\tmovq %%rbx, %[old_rbx]\n" +#endif /* - * initialization, load ESI, EDI, EBX registers + * initialization, load RSI, RDI, RBX registers */ - "\tmovq %1, %%rdi\n" - "\tmovq %2, %%rsi\n" - "\tmovq %3, %%rbx\n" +#ifndef _ILP32 + "\tmovq %[dst], %%rdi\n" + "\tmovq %[src], %%rsi\n" + "\tmovq %[sum], %%rbx\n" +#else + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" +#endif /* * while (size-- > 0) { */ - "\tcmpl $0, %0\n" + "\tcmpl $0, %[size]\n" "jz 6f\n" "\t.p2align 4,,15\n" @@ -220,20 +259,33 @@ static void MIX_AREAS_32(unsigned int size, /* * while (size-- > 0) */ - "\tadd %4, %%rdi\n" - "\tadd %5, %%rsi\n" - "\tadd %6, %%rbx\n" - "\tdecl %0\n" +#ifndef _ILP32 + "\taddq %[dst_step], %%rdi\n" + "\taddq %[src_step], %%rsi\n" + "\taddq %[sum_step], %%rbx\n" +#else + "\taddl %[dst_step], %%edi\n" + "\taddl %[src_step], %%esi\n" + "\taddl %[sum_step], %%ebx\n" +#endif + "\tdecl %[size]\n" "\tjnz 1b\n" - - "6:" - "\tmovq %7, %%rbx\n" - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_rbx) - : "rsi", "rdi", "edx", "ecx", "eax" + "6:" +#ifdef BOUNDED_RBX + "\tmovq %[old_rbx], %%rbx\n" +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_RBX + , [old_rbx] "=m" (old_rbx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "rsi", "rdi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_RBX + , "rbx" +#endif ); } @@ -245,8 +297,9 @@ static void MIX_AREAS_24(unsigned int size, volatile signed int *sum, size_t dst_step, size_t src_step, size_t sum_step) { +#ifdef BOUNDED_RBX unsigned long long old_rbx; - +#endif /* * RSI - src * RDI - dst @@ -257,19 +310,26 @@ static void MIX_AREAS_24(unsigned int size, */ __asm__ __volatile__ ( "\n" - - "\tmovq %%rbx, %7\n" +#ifdef BOUNDED_RBX + "\tmovq %%rbx, %[old_rbx]\n" +#endif /* - * initialization, load ESI, EDI, EBX registers + * initialization, load RSI, RDI, RBX registers */ - "\tmovq %1, %%rdi\n" - "\tmovq %2, %%rsi\n" - "\tmovq %3, %%rbx\n" +#ifndef _ILP32 + "\tmovq %[dst], %%rdi\n" + "\tmovq %[src], %%rsi\n" + "\tmovq %[sum], %%rbx\n" +#else + "\tmovl %[dst], %%edi\n" + "\tmovl %[src], %%esi\n" + "\tmovl %[sum], %%ebx\n" +#endif /* * while (size-- > 0) { */ - "\tcmpl $0, %0\n" + "\tcmpl $0, %[size]\n" "jz 6f\n" "\t.p2align 4,,15\n" @@ -316,26 +376,43 @@ static void MIX_AREAS_24(unsigned int size, "\tmovw %%ax, (%%rdi)\n" "\tshrl $16, %%eax\n" "\tmovb %%al, 2(%%rdi)\n" - + "\tcmpl %%ecx, (%%rbx)\n" "\tjnz 3b\n" /* * while (size-- > 0) */ - "\tadd %4, %%rdi\n" - "\tadd %5, %%rsi\n" - "\tadd %6, %%rbx\n" - "\tdecl %0\n" +#ifndef _ILP32 + "\taddq %[dst_step], %%rdi\n" + "\taddq %[src_step], %%rsi\n" + "\taddq %[sum_step], %%rbx\n" +#else + "\taddl %[dst_step], %%edi\n" + "\taddl %[src_step], %%esi\n" + "\taddl %[sum_step], %%ebx\n" +#endif + "\tdecl %[size]\n" "\tjnz 1b\n" - - "6:" - "\tmovq %7, %%rbx\n" - : /* no output regs */ - : "m" (size), "m" (dst), "m" (src), - "m" (sum), "m" (dst_step), "m" (src_step), - "m" (sum_step), "m" (old_rbx) - : "rsi", "rdi", "edx", "ecx", "eax" + "6:" +#ifdef BOUNDED_RBX + "\tmovq %[old_rbx], %%rbx\n" +#endif + : [size] "+&rm" (size) +#ifdef BOUNDED_RBX + , [old_rbx] "=m" (old_rbx) +#endif + : [dst] "m" (dst), [src] "m" (src), [sum] "m" (sum), + [dst_step] "im" (dst_step), [src_step] "im" (src_step), + [sum_step] "im" (sum_step) + : "rsi", "rdi", "edx", "ecx", "eax", "memory", "cc" +#ifndef BOUNDED_RBX + , "rbx" +#endif ); } + +#ifdef BOUNDED_RBX +# undef BOUNDED_RBX +#endif diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index 59448cf..6a99452 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -723,6 +723,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name, dshare->ipc_key = opts->ipc_key; dshare->ipc_perm = opts->ipc_perm; dshare->ipc_gid = opts->ipc_gid; + dshare->tstamp_type = opts->tstamp_type; dshare->semid = -1; dshare->shmid = -1; @@ -929,6 +930,9 @@ pcm.name { # roundup # rounddown # auto (default) + tstamp_type STR # timestamp type + # STR can be one of the below strings : + # default, gettimeofday, monotonic, monotonic_raw slave STR # or slave { # Slave definition diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c index 24f472c..7904314 100644 --- a/src/pcm/pcm_dsnoop.c +++ b/src/pcm/pcm_dsnoop.c @@ -165,7 +165,7 @@ static int snd_pcm_dsnoop_sync_ptr(snd_pcm_t *pcm) // printf("sync ptr diff = %li\n", diff); if (pcm->stop_threshold >= pcm->boundary) /* don't care */ return 0; - if ((avail = snd_pcm_mmap_capture_hw_avail(pcm)) >= pcm->stop_threshold) { + if ((avail = snd_pcm_mmap_capture_avail(pcm)) >= pcm->stop_threshold) { gettimestamp(&dsnoop->trigger_tstamp, pcm->tstamp_type); dsnoop->state = SND_PCM_STATE_XRUN; dsnoop->avail_max = avail; @@ -241,7 +241,7 @@ static int snd_pcm_dsnoop_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) /* Fall through */ case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_SUSPENDED: - *delayp = snd_pcm_mmap_capture_hw_avail(pcm); + *delayp = snd_pcm_mmap_capture_avail(pcm); return 0; case SNDRV_PCM_STATE_XRUN: return -EPIPE; @@ -352,7 +352,7 @@ static int snd_pcm_dsnoop_pause(snd_pcm_t *pcm ATTRIBUTE_UNUSED, int enable ATTR static snd_pcm_sframes_t snd_pcm_dsnoop_rewindable(snd_pcm_t *pcm) { - return snd_pcm_mmap_capture_hw_avail(pcm); + return snd_pcm_mmap_capture_hw_rewindable(pcm); } static snd_pcm_sframes_t snd_pcm_dsnoop_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames) @@ -591,6 +591,7 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name, dsnoop->ipc_key = opts->ipc_key; dsnoop->ipc_perm = opts->ipc_perm; dsnoop->ipc_gid = opts->ipc_gid; + dsnoop->tstamp_type = opts->tstamp_type; dsnoop->semid = -1; dsnoop->shmid = -1; @@ -780,6 +781,9 @@ pcm.name { # roundup # rounddown # auto (default) + tstamp_type STR # timestamp type + # STR can be one of the below strings : + # default, gettimeofday, monotonic, monotonic_raw slave STR # or slave { # Slave definition diff --git a/src/pcm/pcm_extplug.c b/src/pcm/pcm_extplug.c index 94002dc..99455d9 100644 --- a/src/pcm/pcm_extplug.c +++ b/src/pcm/pcm_extplug.c @@ -732,6 +732,7 @@ int snd_pcm_extplug_create(snd_pcm_extplug_t *extplug, const char *name, pcm->private_data = ext; pcm->poll_fd = spcm->poll_fd; pcm->poll_events = spcm->poll_events; + pcm->tstamp_type = spcm->tstamp_type; snd_pcm_set_hw_ptr(pcm, &ext->plug.hw_ptr, -1, 0); snd_pcm_set_appl_ptr(pcm, &ext->plug.appl_ptr, -1, 0); diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 05ed935..aae58ed 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -480,6 +480,13 @@ static inline int snd_pcm_check_error(snd_pcm_t *pcm, int err) return err; } +/** + * \retval number of frames available to the application for playback + * + * This is how far ahead the hardware position in the ring buffer is, + * compared to the application position. ie. for playback it's the + * number of frames in the empty part of the ring buffer. + */ static inline snd_pcm_uframes_t __snd_pcm_playback_avail(snd_pcm_t *pcm, const snd_pcm_uframes_t hw_ptr, const snd_pcm_uframes_t appl_ptr) @@ -498,6 +505,13 @@ static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm) return __snd_pcm_playback_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr); } +/* + * \retval number of frames available to the application for capture + * + * This is how far ahead the hardware position in the ring buffer is + * compared to the application position. ie. for capture, it's the + * number of frames in the filled part of the ring buffer. + */ static inline snd_pcm_uframes_t __snd_pcm_capture_avail(snd_pcm_t *pcm, const snd_pcm_uframes_t hw_ptr, const snd_pcm_uframes_t appl_ptr) @@ -529,11 +543,21 @@ static inline snd_pcm_uframes_t snd_pcm_mmap_avail(snd_pcm_t *pcm) return __snd_pcm_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr); } +/* + * \retval number of frames available to the hardware for playback + * + * ie. the filled part of the ring buffer + */ static inline snd_pcm_sframes_t snd_pcm_mmap_playback_hw_avail(snd_pcm_t *pcm) { return pcm->buffer_size - snd_pcm_mmap_playback_avail(pcm); } +/* + * \retval number of frames available to the hardware for capture + * + * ie. the empty part of the ring buffer. + */ static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_avail(snd_pcm_t *pcm) { return pcm->buffer_size - snd_pcm_mmap_capture_avail(pcm); @@ -582,14 +606,20 @@ static inline snd_pcm_uframes_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm) return *pcm->hw.ptr % pcm->buffer_size; } +/* + * \retval number of frames pending from application to hardware + */ static inline snd_pcm_uframes_t snd_pcm_mmap_playback_delay(snd_pcm_t *pcm) { return snd_pcm_mmap_playback_hw_avail(pcm); } +/* + * \retval number of frames pending from hardware to application + */ static inline snd_pcm_uframes_t snd_pcm_mmap_capture_delay(snd_pcm_t *pcm) { - return snd_pcm_mmap_capture_hw_avail(pcm); + return snd_pcm_mmap_capture_avail(pcm); } static inline snd_pcm_sframes_t snd_pcm_mmap_delay(snd_pcm_t *pcm) @@ -928,6 +958,8 @@ int INTERNAL(snd_pcm_hw_params_set_buffer_size_last)(snd_pcm_t *pcm, snd_pcm_hw_ int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val); int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val); +int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val); +int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val); int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val); int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val); int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val); diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index fdcaa8d..5bf7dbb 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -1051,6 +1051,7 @@ static int snd_pcm_rate_drain(snd_pcm_t *pcm) /* commit the remaining fraction (if any) */ snd_pcm_uframes_t size, ofs, saved_avail_min; snd_pcm_sw_params_t sw_params; + int commit_err = 0; __snd_pcm_lock(pcm); /* temporarily set avail_min to one */ @@ -1060,6 +1061,8 @@ static int snd_pcm_rate_drain(snd_pcm_t *pcm) snd_pcm_sw_params(rate->gen.slave, &sw_params); size = rate->appl_ptr - rate->last_commit_ptr; + if (size > pcm->boundary) + size -= pcm->boundary; ofs = rate->last_commit_ptr % pcm->buffer_size; while (size > 0) { snd_pcm_uframes_t psize, spsize; @@ -1077,14 +1080,29 @@ static int snd_pcm_rate_drain(snd_pcm_t *pcm) if (! spsize) break; } - snd_pcm_rate_commit_area(pcm, rate, ofs, + commit_err = snd_pcm_rate_commit_area(pcm, rate, ofs, psize, spsize); + if (commit_err == 1) { + rate->last_commit_ptr += psize; + if (rate->last_commit_ptr >= pcm->boundary) + rate->last_commit_ptr = 0; + } else if (commit_err == 0) { + if (pcm->mode & SND_PCM_NONBLOCK) { + commit_err = -EAGAIN; + break; + } + continue; + } else + break; + ofs = (ofs + psize) % pcm->buffer_size; size -= psize; } sw_params.avail_min = saved_avail_min; snd_pcm_sw_params(rate->gen.slave, &sw_params); __snd_pcm_unlock(pcm); + if (commit_err < 0) + return commit_err; } return snd_pcm_drain(rate->gen.slave); } @@ -1263,7 +1281,7 @@ static const char *const default_rate_plugins[] = { static int rate_open_func(snd_pcm_rate_t *rate, const char *type, const snd_config_t *converter_conf, int verbose) { - char open_name[64], open_conf_name[64], lib_name[128], *lib = NULL; + char open_name[64], open_conf_name[64], lib_name[64], *lib = NULL; snd_pcm_rate_open_func_t open_func; snd_pcm_rate_open_conf_func_t open_conf_func; int err; @@ -1272,7 +1290,7 @@ static int rate_open_func(snd_pcm_rate_t *rate, const char *type, const snd_conf snprintf(open_conf_name, sizeof(open_conf_name), "_snd_pcm_rate_%s_open_conf", type); if (!is_builtin_plugin(type)) { snprintf(lib_name, sizeof(lib_name), - "%s/libasound_module_rate_%s.so", ALSA_PLUGIN_DIR, type); + "libasound_module_rate_%s.so", type); lib = lib_name; } diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c index bbcc611..d3e5f3f 100644 --- a/src/pcm/pcm_route.c +++ b/src/pcm/pcm_route.c @@ -104,6 +104,7 @@ typedef struct { int schannels; snd_pcm_route_params_t params; snd_pcm_chmap_t *chmap; + snd_pcm_chmap_query_t **chmap_override; } snd_pcm_route_t; #endif /* DOC_HIDDEN */ @@ -441,6 +442,7 @@ static int snd_pcm_route_close(snd_pcm_t *pcm) free(params->dsts); } free(route->chmap); + snd_pcm_free_chmaps(route->chmap_override); return snd_pcm_generic_close(pcm); } @@ -634,6 +636,9 @@ static snd_pcm_chmap_t *snd_pcm_route_get_chmap(snd_pcm_t *pcm) snd_pcm_chmap_t *map, *slave_map; unsigned int src, dst, nsrcs; + if (route->chmap_override) + return _snd_pcm_choose_fixed_chmap(pcm, route->chmap_override); + slave_map = snd_pcm_generic_get_chmap(pcm); if (!slave_map) return NULL; @@ -660,8 +665,14 @@ static snd_pcm_chmap_t *snd_pcm_route_get_chmap(snd_pcm_t *pcm) static snd_pcm_chmap_query_t **snd_pcm_route_query_chmaps(snd_pcm_t *pcm) { + snd_pcm_route_t *route = pcm->private_data; snd_pcm_chmap_query_t **maps; - snd_pcm_chmap_t *map = snd_pcm_route_get_chmap(pcm); + snd_pcm_chmap_t *map; + + if (route->chmap_override) + return _snd_pcm_copy_chmap_query(route->chmap_override); + + map = snd_pcm_route_get_chmap(pcm); if (!map) return NULL; maps = _snd_pcm_make_single_query_chmaps(map); @@ -818,10 +829,10 @@ err: return -EINVAL; } -static int find_matching_chmap(snd_pcm_t *spcm, snd_pcm_chmap_t *tt_chmap, +static int find_matching_chmap(snd_pcm_chmap_query_t **chmaps, + snd_pcm_chmap_t *tt_chmap, snd_pcm_chmap_t **found_chmap, int *schannels) { - snd_pcm_chmap_query_t** chmaps = snd_pcm_query_chmaps(spcm); int i; *found_chmap = NULL; @@ -854,7 +865,6 @@ static int find_matching_chmap(snd_pcm_t *spcm, snd_pcm_chmap_t *tt_chmap, int size = sizeof(snd_pcm_chmap_t) + c->channels * sizeof(unsigned int); *found_chmap = malloc(size); if (!*found_chmap) { - snd_pcm_free_chmaps(chmaps); return -ENOMEM; } memcpy(*found_chmap, c, size); @@ -863,8 +873,6 @@ static int find_matching_chmap(snd_pcm_t *spcm, snd_pcm_chmap_t *tt_chmap, } } - snd_pcm_free_chmaps(chmaps); - if (*found_chmap == NULL) { SNDERR("Found no matching channel map"); return -EINVAL; @@ -1252,6 +1260,7 @@ pcm.name { SCHANNEL REAL # route value (0.0 - 1.0) } } + [chmap MAP] # Override channel maps; MAP is a string array } \endcode @@ -1292,6 +1301,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name, snd_pcm_route_ttable_entry_t *ttable = NULL; unsigned int csize, ssize; unsigned int cused, sused; + snd_pcm_chmap_query_t **chmaps = NULL; snd_config_for_each(i, next, conf) { snd_config_t *n = snd_config_iterator_entry(i); const char *id; @@ -1306,31 +1316,45 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name, if (strcmp(id, "ttable") == 0) { if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { SNDERR("Invalid type for %s", id); + snd_pcm_free_chmaps(chmaps); return -EINVAL; } tt = n; continue; } + if (strcmp(id, "chmap") == 0) { + chmaps = _snd_pcm_parse_config_chmaps(n); + if (!chmaps) { + SNDERR("Invalid channel map for %s", id); + return -EINVAL; + } + continue; + } SNDERR("Unknown field %s", id); return -EINVAL; } if (!slave) { SNDERR("slave is not defined"); + snd_pcm_free_chmaps(chmaps); return -EINVAL; } if (!tt) { SNDERR("ttable is not defined"); + snd_pcm_free_chmaps(chmaps); return -EINVAL; } err = snd_pcm_slave_conf(root, slave, &sconf, 2, SND_PCM_HW_PARAM_FORMAT, 0, &sformat, SND_PCM_HW_PARAM_CHANNELS, 0, &schannels); - if (err < 0) + if (err < 0) { + snd_pcm_free_chmaps(chmaps); return err; + } if (sformat != SND_PCM_FORMAT_UNKNOWN && snd_pcm_format_linear(sformat) != 1) { snd_config_delete(sconf); SNDERR("slave format is not linear"); + snd_pcm_free_chmaps(chmaps); return -EINVAL; } @@ -1345,13 +1369,19 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name, if (err < 0) { free(tt_chmap); free(ttable); + snd_pcm_free_chmaps(chmaps); return err; } if (tt_chmap) { - err = find_matching_chmap(spcm, tt_chmap, &chmap, &schannels); + if (!chmaps) + chmaps = snd_pcm_query_chmaps(spcm); + if (chmaps) + err = find_matching_chmap(chmaps, tt_chmap, &chmap, + &schannels); free(tt_chmap); - if (err < 0) { + if (chmaps && err < 0) { + snd_pcm_free_chmaps(chmaps); snd_pcm_close(spcm); return err; } @@ -1360,12 +1390,14 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name, err = _snd_pcm_route_determine_ttable(tt, &csize, &ssize, chmap); if (err < 0) { free(chmap); + snd_pcm_free_chmaps(chmaps); snd_pcm_close(spcm); return err; } ttable = malloc(csize * ssize * sizeof(snd_pcm_route_ttable_entry_t)); if (ttable == NULL) { free(chmap); + snd_pcm_free_chmaps(chmaps); snd_pcm_close(spcm); return -ENOMEM; } @@ -1374,6 +1406,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name, if (err < 0) { free(chmap); free(ttable); + snd_pcm_free_chmaps(chmaps); snd_pcm_close(spcm); return err; } @@ -1385,9 +1418,13 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name, free(ttable); if (err < 0) { free(chmap); + snd_pcm_free_chmaps(chmaps); snd_pcm_close(spcm); } else { - ((snd_pcm_route_t*) (*pcmp)->private_data)->chmap = chmap; + snd_pcm_route_t *route = (*pcmp)->private_data; + + route->chmap = chmap; + route->chmap_override = chmaps; } return err; diff --git a/src/topology/Makefile.am b/src/topology/Makefile.am index 9dc472d..9f48891 100644 --- a/src/topology/Makefile.am +++ b/src/topology/Makefile.am @@ -27,7 +27,10 @@ libatopology_la_SOURCES =\ text.c \ channel.c \ ops.c \ - elem.c + elem.c \ + save.c \ + decoder.c \ + log.c noinst_HEADERS = tplg_local.h diff --git a/src/topology/Makefile.in b/src/topology/Makefile.in index 54c40a6..4476f29 100644 --- a/src/topology/Makefile.in +++ b/src/topology/Makefile.in @@ -135,7 +135,8 @@ am__installdirs = "$(DESTDIR)$(libdir)" LTLIBRARIES = $(lib_LTLIBRARIES) libatopology_la_DEPENDENCIES = ../libasound.la am_libatopology_la_OBJECTS = parser.lo builder.lo ctl.lo dapm.lo \ - pcm.lo data.lo text.lo channel.lo ops.lo elem.lo + pcm.lo data.lo text.lo channel.lo ops.lo elem.lo save.lo \ + decoder.lo log.lo libatopology_la_OBJECTS = $(am_libatopology_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -162,9 +163,9 @@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/builder.Plo ./$(DEPDIR)/channel.Plo \ ./$(DEPDIR)/ctl.Plo ./$(DEPDIR)/dapm.Plo ./$(DEPDIR)/data.Plo \ - ./$(DEPDIR)/elem.Plo ./$(DEPDIR)/ops.Plo \ - ./$(DEPDIR)/parser.Plo ./$(DEPDIR)/pcm.Plo \ - ./$(DEPDIR)/text.Plo + ./$(DEPDIR)/decoder.Plo ./$(DEPDIR)/elem.Plo \ + ./$(DEPDIR)/log.Plo ./$(DEPDIR)/ops.Plo ./$(DEPDIR)/parser.Plo \ + ./$(DEPDIR)/pcm.Plo ./$(DEPDIR)/save.Plo ./$(DEPDIR)/text.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -361,7 +362,10 @@ libatopology_la_SOURCES = \ text.c \ channel.c \ ops.c \ - elem.c + elem.c \ + save.c \ + decoder.c \ + log.c noinst_HEADERS = tplg_local.h AM_CPPFLAGS = -I$(top_srcdir)/include @@ -448,10 +452,13 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ctl.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dapm.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/data.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/decoder.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elem.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ops.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parser.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pcm.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/save.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/text.Plo@am__quote@ # am--include-marker $(am__depfiles_remade): @@ -620,10 +627,13 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/ctl.Plo -rm -f ./$(DEPDIR)/dapm.Plo -rm -f ./$(DEPDIR)/data.Plo + -rm -f ./$(DEPDIR)/decoder.Plo -rm -f ./$(DEPDIR)/elem.Plo + -rm -f ./$(DEPDIR)/log.Plo -rm -f ./$(DEPDIR)/ops.Plo -rm -f ./$(DEPDIR)/parser.Plo -rm -f ./$(DEPDIR)/pcm.Plo + -rm -f ./$(DEPDIR)/save.Plo -rm -f ./$(DEPDIR)/text.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ @@ -675,10 +685,13 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/ctl.Plo -rm -f ./$(DEPDIR)/dapm.Plo -rm -f ./$(DEPDIR)/data.Plo + -rm -f ./$(DEPDIR)/decoder.Plo -rm -f ./$(DEPDIR)/elem.Plo + -rm -f ./$(DEPDIR)/log.Plo -rm -f ./$(DEPDIR)/ops.Plo -rm -f ./$(DEPDIR)/parser.Plo -rm -f ./$(DEPDIR)/pcm.Plo + -rm -f ./$(DEPDIR)/save.Plo -rm -f ./$(DEPDIR)/text.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/src/topology/builder.c b/src/topology/builder.c index 5ae3ae8..1575766 100644 --- a/src/topology/builder.c +++ b/src/topology/builder.c @@ -20,31 +20,23 @@ #include "list.h" #include "tplg_local.h" -/* verbose output detailing each object size and file position */ -static void verbose(snd_tplg_t *tplg, const char *fmt, ...) +/* write a block, track the position */ +static ssize_t twrite(snd_tplg_t *tplg, void *data, size_t data_size) { - int offset; - va_list va; - - if (!tplg->verbose) - return; - - offset = lseek(tplg->out_fd, 0, SEEK_CUR); - - va_start(va, fmt); - fprintf(stdout, "0x%6.6x/%6.6d -", offset, offset); - vfprintf(stdout, fmt, va); - va_end(va); + if (tplg->bin_pos + data_size > tplg->bin_size) + return -EIO; + memcpy(tplg->bin + tplg->bin_pos, data, data_size); + tplg->bin_pos += data_size; + return data_size; } /* write out block header to output file */ -static int write_block_header(snd_tplg_t *tplg, unsigned int type, - unsigned int vendor_type, unsigned int version, unsigned int index, - size_t payload_size, int count) +static ssize_t write_block_header(snd_tplg_t *tplg, unsigned int type, + unsigned int vendor_type, + unsigned int version, unsigned int index, + size_t payload_size, int count) { struct snd_soc_tplg_hdr hdr; - size_t bytes; - int offset = lseek(tplg->out_fd, 0, SEEK_CUR); memset(&hdr, 0, sizeof(hdr)); hdr.magic = SND_SOC_TPLG_MAGIC; @@ -58,38 +50,34 @@ static int write_block_header(snd_tplg_t *tplg, unsigned int type, hdr.count = count; /* make sure file offset is aligned with the calculated HDR offset */ - if ((unsigned int)offset != tplg->next_hdr_pos) { - SNDERR("error: New header is at offset 0x%x but file" - " offset 0x%x is %s by %d bytes\n", - tplg->next_hdr_pos, offset, - (unsigned int)offset > tplg->next_hdr_pos ? "ahead" : "behind", - abs(offset - tplg->next_hdr_pos)); - exit(-EINVAL); + if (tplg->bin_pos != tplg->next_hdr_pos) { + SNDERR("New header is at offset 0x%zx but file" + " offset 0x%zx is %s by %ld bytes", + tplg->next_hdr_pos, tplg->bin_pos, + tplg->bin_pos > tplg->next_hdr_pos ? "ahead" : "behind", + labs(tplg->bin_pos - tplg->next_hdr_pos)); + return -EINVAL; } - verbose(tplg, " header index %d type %d count %d size 0x%lx/%ld vendor %d " - "version %d\n", index, type, count, - (long unsigned int)payload_size, (long int)payload_size, - vendor_type, version); + tplg_log(tplg, 'B', tplg->bin_pos, + "header index %d type %d count %d size 0x%lx/%ld vendor %d " + "version %d", index, type, count, + (long unsigned int)payload_size, (long int)payload_size, + vendor_type, version); tplg->next_hdr_pos += hdr.payload_size + sizeof(hdr); - bytes = write(tplg->out_fd, &hdr, sizeof(hdr)); - if (bytes != sizeof(hdr)) { - SNDERR("error: can't write section header %lu\n", - (long unsigned int)bytes); - return bytes; - } - - return bytes; + return twrite(tplg, &hdr, sizeof(hdr)); } static int write_elem_block(snd_tplg_t *tplg, - struct list_head *base, int size, int tplg_type, const char *obj_name) + struct list_head *base, size_t size, + int tplg_type, const char *obj_name) { struct list_head *pos, *sub_pos, *sub_base; struct tplg_elem *elem, *elem_next; - int ret, wsize = 0, total_size = 0, count = 0, block_size = 0; + size_t total_size = 0, count = 0, block_size = 0; + ssize_t ret, wsize; sub_base = base; list_for_each(pos, base) { @@ -108,7 +96,7 @@ static int write_elem_block(snd_tplg_t *tplg, ret = write_block_header(tplg, tplg_type, elem->vendor_type, tplg->version, elem->index, block_size, count); if (ret < 0) { - SNDERR("error: failed to write %s block %d\n", + SNDERR("failed to write %s block %d", obj_name, ret); return ret; } @@ -121,20 +109,19 @@ static int write_elem_block(snd_tplg_t *tplg, continue; if (elem->type != SND_TPLG_TYPE_DAPM_GRAPH) - verbose(tplg, " %s '%s': write %d bytes\n", - obj_name, elem->id, elem->size); + tplg_log(tplg, 'B', tplg->bin_pos, + "%s '%s': write %d bytes", + obj_name, elem->id, elem->size); else - verbose(tplg, " %s '%s -> %s -> %s': write %d bytes\n", - obj_name, elem->route->source, - elem->route->control, - elem->route->sink, elem->size); - - wsize = write(tplg->out_fd, elem->obj, elem->size); - if (wsize < 0) { - SNDERR("error: failed to write %s %d\n", - obj_name, ret); - return ret; - } + tplg_log(tplg, 'B', tplg->bin_pos, + "%s '%s -> %s -> %s': write %d bytes", + obj_name, elem->route->source, + elem->route->control, + elem->route->sink, elem->size); + + wsize = twrite(tplg, elem->obj, elem->size); + if (wsize < 0) + return size; total_size += wsize; /* get to the end of sub list */ @@ -151,7 +138,7 @@ static int write_elem_block(snd_tplg_t *tplg, /* make sure we have written the correct size */ if (total_size != size) { - SNDERR("error: size mismatch. Expected %d wrote %d\n", + SNDERR("size mismatch. Expected %zu wrote %zu", size, total_size); return -EIO; } @@ -159,11 +146,18 @@ static int write_elem_block(snd_tplg_t *tplg, return 0; } -static int calc_block_size(struct list_head *base) +static size_t calc_manifest_size(snd_tplg_t *tplg) +{ + return sizeof(struct snd_soc_tplg_hdr) + + sizeof(tplg->manifest) + + tplg->manifest.priv.size; +} + +static size_t calc_real_size(struct list_head *base) { struct list_head *pos; - struct tplg_elem *elem; - int size = 0; + struct tplg_elem *elem, *elem_next; + size_t size = 0; list_for_each(pos, base) { @@ -173,183 +167,132 @@ static int calc_block_size(struct list_head *base) if (elem->compound_elem) continue; + if (elem->size <= 0) + continue; + size += elem->size; + + elem_next = list_entry(pos->next, struct tplg_elem, list); + + if ((pos->next == base) || (elem_next->index != elem->index)) + size += sizeof(struct snd_soc_tplg_hdr); } return size; } -static int write_block(snd_tplg_t *tplg, struct list_head *base, - int type) +static size_t calc_block_size(struct list_head *base) { - int size; - - /* calculate the block size in bytes for all elems in this list */ - size = calc_block_size(base); - if (size <= 0) - return size; - - verbose(tplg, " block size for type %d is %d\n", type, size); - - /* write each elem for this block */ - switch (type) { - case SND_TPLG_TYPE_MIXER: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_MIXER, "mixer"); - case SND_TPLG_TYPE_BYTES: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_BYTES, "bytes"); - case SND_TPLG_TYPE_ENUM: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_ENUM, "enum"); - case SND_TPLG_TYPE_DAPM_GRAPH: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_DAPM_GRAPH, "route"); - case SND_TPLG_TYPE_DAPM_WIDGET: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_DAPM_WIDGET, "widget"); - case SND_TPLG_TYPE_PCM: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_PCM, "pcm"); - case SND_TPLG_TYPE_BE: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_BACKEND_LINK, "be"); - case SND_TPLG_TYPE_CC: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_CODEC_LINK, "cc"); - case SND_TPLG_TYPE_DATA: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_PDATA, "data"); - case SND_TPLG_TYPE_DAI: - return write_elem_block(tplg, base, size, - SND_SOC_TPLG_TYPE_DAI, "dai"); - default: - return -EINVAL; + struct list_head *pos; + struct tplg_elem *elem; + size_t size = 0; + + list_for_each(pos, base) { + + elem = list_entry(pos, struct tplg_elem, list); + + /* compound elems have already been copied to other elems */ + if (elem->compound_elem) + continue; + + size += elem->size; } - return 0; + return size; } /* write the manifest including its private data */ -static int write_manifest_data(snd_tplg_t *tplg) +static ssize_t write_manifest_data(snd_tplg_t *tplg) { - int ret; + ssize_t ret; /* write the header for this block */ ret = write_block_header(tplg, SND_SOC_TPLG_TYPE_MANIFEST, 0, tplg->version, 0, sizeof(tplg->manifest) + tplg->manifest.priv.size, 1); if (ret < 0) { - SNDERR("error: failed to write manifest block %d\n", ret); - return ret; - } - - verbose(tplg, "manifest : write %d bytes\n", sizeof(tplg->manifest)); - ret = write(tplg->out_fd, &tplg->manifest, sizeof(tplg->manifest)); - if (ret < 0) { - SNDERR("error: failed to write manifest %d\n", ret); + SNDERR("failed to write manifest block"); return ret; } - verbose(tplg, "manifest : write %d priv bytes\n", tplg->manifest.priv.size); - ret = write(tplg->out_fd, tplg->manifest_pdata, tplg->manifest.priv.size); - if (ret < 0) { - SNDERR("error: failed to write manifest priv data %d\n", ret); - return ret; + tplg_log(tplg, 'B', tplg->bin_pos, "manifest: write %d bytes", + sizeof(tplg->manifest)); + ret = twrite(tplg, &tplg->manifest, sizeof(tplg->manifest)); + if (ret >= 0) { + tplg_log(tplg, 'B', tplg->bin_pos, + "manifest: write %d priv bytes", + tplg->manifest.priv.size); + ret = twrite(tplg, tplg->manifest_pdata, tplg->manifest.priv.size); } - - return 0; + return ret; } int tplg_write_data(snd_tplg_t *tplg) { - int ret; - - /* write manifest */ - ret = write_manifest_data(tplg); - if (ret < 0) { - SNDERR("failed to write manifest %d\n", ret); - return ret; - } - - /* write mixer elems. */ - ret = write_block(tplg, &tplg->mixer_list, - SND_TPLG_TYPE_MIXER); - if (ret < 0) { - SNDERR("failed to write control elems %d\n", ret); - return ret; - } - - /* write enum control elems. */ - ret = write_block(tplg, &tplg->enum_list, - SND_TPLG_TYPE_ENUM); - if (ret < 0) { - SNDERR("failed to write control elems %d\n", ret); - return ret; - } - - /* write bytes extended control elems. */ - ret = write_block(tplg, &tplg->bytes_ext_list, - SND_TPLG_TYPE_BYTES); - if (ret < 0) { - SNDERR("failed to write control elems %d\n", ret); - return ret; - } - - /* write widget elems */ - ret = write_block(tplg, &tplg->widget_list, - SND_TPLG_TYPE_DAPM_WIDGET); - if (ret < 0) { - SNDERR("failed to write widget elems %d\n", ret); - return ret; - } - - /* write pcm elems */ - ret = write_block(tplg, &tplg->pcm_list, - SND_TPLG_TYPE_PCM); - if (ret < 0) { - SNDERR("failed to write pcm elems %d\n", ret); - return ret; + struct tplg_table *tptr; + struct list_head *list; + ssize_t ret; + size_t total_size, size; + unsigned int index; + + /* calculate total size */ + total_size = calc_manifest_size(tplg); + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + if (!tptr->build) + continue; + list = (struct list_head *)((void *)tplg + tptr->loff); + size = calc_real_size(list); + total_size += size; } - /* write physical dai elems */ - ret = write_block(tplg, &tplg->dai_list, - SND_TPLG_TYPE_DAI); - if (ret < 0) { - SNDERR("failed to write physical dai elems %d\n", ret); - return ret; + /* allocate new binary output */ + free(tplg->bin); + tplg->bin = malloc(total_size); + tplg->bin_pos = 0; + tplg->bin_size = total_size; + if (tplg->bin == NULL) { + tplg->bin_size = 0; + return -ENOMEM; } - /* write be elems */ - ret = write_block(tplg, &tplg->be_list, - SND_TPLG_TYPE_BE); + /* write manifest */ + ret = write_manifest_data(tplg); if (ret < 0) { - SNDERR("failed to write be elems %d\n", ret); + SNDERR("failed to write manifest %d", ret); return ret; } - /* write cc elems */ - ret = write_block(tplg, &tplg->cc_list, - SND_TPLG_TYPE_CC); - if (ret < 0) { - SNDERR("failed to write cc elems %d\n", ret); - return ret; + /* write all blocks */ + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + if (!tptr->build) + continue; + list = (struct list_head *)((void *)tplg + tptr->loff); + /* calculate the block size in bytes for all elems in this list */ + size = calc_block_size(list); + if (size == 0) + continue; + tplg_log(tplg, 'B', tplg->bin_pos, + "block size for type %s (%d:%d) is 0x%zx/%zd", + tptr->name, tptr->type, + tptr->tsoc, size, size); + ret = write_elem_block(tplg, list, size, + tptr->tsoc, tptr->name); + if (ret < 0) { + SNDERR("failed to write %s elements: %s", + tptr->name, snd_strerror(-ret)); + return ret; + } } - /* write route elems */ - ret = write_block(tplg, &tplg->route_list, - SND_TPLG_TYPE_DAPM_GRAPH); - if (ret < 0) { - SNDERR("failed to write graph elems %d\n", ret); - return ret; - } + tplg_log(tplg, 'B', tplg->bin_pos, "total size is 0x%zx/%zd", + tplg->bin_pos, tplg->bin_pos); - /* write private data */ - ret = write_block(tplg, &tplg->pdata_list, - SND_TPLG_TYPE_DATA); - if (ret < 0) { - SNDERR("failed to write private data %d\n", ret); - return ret; + if (total_size != tplg->bin_pos) { + SNDERR("total size mismatch (%zd != %zd)", + total_size, tplg->bin_pos); + return -EINVAL; } return 0; diff --git a/src/topology/channel.c b/src/topology/channel.c index 8516b23..47d5ea4 100644 --- a/src/topology/channel.c +++ b/src/topology/channel.c @@ -73,32 +73,44 @@ static int lookup_channel(const char *c) return -EINVAL; } +const char *tplg_channel_name(int type) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(channel_map); i++) { + if (channel_map[i].id == type) + return channel_map[i].name; + } + + return NULL; +} + /* Parse a channel mapping. */ -int tplg_parse_channel(snd_tplg_t *tplg, - snd_config_t *cfg, void *private) +int tplg_parse_channel(snd_tplg_t *tplg, snd_config_t *cfg, + void *private) { snd_config_iterator_t i, next; snd_config_t *n; struct snd_soc_tplg_channel *channel = private; - const char *id, *value; - int channel_id; + const char *id; + int channel_id, value; if (tplg->channel_idx >= SND_SOC_TPLG_MAX_CHAN) return -EINVAL; channel += tplg->channel_idx; snd_config_get_id(cfg, &id); - tplg_dbg("\tChannel %s at index %d\n", id, tplg->channel_idx); + tplg_dbg("\tChannel %s at index %d", id, tplg->channel_idx); channel_id = lookup_channel(id); if (channel_id < 0) { - SNDERR("error: invalid channel %s\n", id); + SNDERR("invalid channel %s", id); return -EINVAL; } channel->id = channel_id; channel->size = sizeof(*channel); - tplg_dbg("\tChan %s = %d\n", id, channel->id); + tplg_dbg("\tChan %s = %d", id, channel->id); snd_config_for_each(i, next, cfg) { @@ -109,17 +121,50 @@ int tplg_parse_channel(snd_tplg_t *tplg, continue; /* get value */ - if (snd_config_get_string(n, &value) < 0) + if (tplg_get_integer(n, &value, 0) < 0) continue; if (strcmp(id, "reg") == 0) - channel->reg = atoi(value); + channel->reg = value; else if (strcmp(id, "shift") == 0) - channel->shift = atoi(value); + channel->shift = value; - tplg_dbg("\t\t%s = %s\n", id, value); + tplg_dbg("\t\t%s = %d", id, value); } tplg->channel_idx++; return 0; } + +int tplg_save_channels(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct snd_soc_tplg_channel *channel, + unsigned int count, char **dst, const char *pfx) +{ + struct snd_soc_tplg_channel *c; + const char *s; + unsigned int index; + int err; + + if (count == 0) + return 0; + err = tplg_save_printf(dst, pfx, "channel {\n"); + for (index = 0; err >= 0 && index < count; index++) { + c = channel + index; + s = tplg_channel_name(c->id); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\t%u", c->id); + else + err = tplg_save_printf(dst, pfx, "\t%s", s); + if (err >= 0) + err = tplg_save_printf(dst, NULL, " {\n"); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t\treg %d\n", c->reg); + if (err >= 0 && c->shift > 0) + err = tplg_save_printf(dst, pfx, "\t\tshift %u\n", c->shift); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t}\n"); + } + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} diff --git a/src/topology/ctl.c b/src/topology/ctl.c index a096252..90241b6 100644 --- a/src/topology/ctl.c +++ b/src/topology/ctl.c @@ -28,15 +28,15 @@ struct ctl_access_elem { }; /* CTL access strings and codes */ +/* place the multi-bit values on top - like read_write - for save */ static const struct ctl_access_elem ctl_access[] = { + {"read_write", SNDRV_CTL_ELEM_ACCESS_READWRITE}, + {"tlv_read_write", SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE}, {"read", SNDRV_CTL_ELEM_ACCESS_READ}, {"write", SNDRV_CTL_ELEM_ACCESS_WRITE}, - {"read_write", SNDRV_CTL_ELEM_ACCESS_READWRITE}, {"volatile", SNDRV_CTL_ELEM_ACCESS_VOLATILE}, - {"timestamp", SNDRV_CTL_ELEM_ACCESS_TIMESTAMP}, {"tlv_read", SNDRV_CTL_ELEM_ACCESS_TLV_READ}, {"tlv_write", SNDRV_CTL_ELEM_ACCESS_TLV_WRITE}, - {"tlv_read_write", SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE}, {"tlv_command", SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND}, {"inactive", SNDRV_CTL_ELEM_ACCESS_INACTIVE}, {"lock", SNDRV_CTL_ELEM_ACCESS_LOCK}, @@ -46,14 +46,14 @@ static const struct ctl_access_elem ctl_access[] = { /* find CTL access strings and conver to values */ static int parse_access_values(snd_config_t *cfg, - struct snd_soc_tplg_ctl_hdr *hdr) + struct snd_soc_tplg_ctl_hdr *hdr) { snd_config_iterator_t i, next; snd_config_t *n; const char *value = NULL; unsigned int j; - tplg_dbg(" Access:\n"); + tplg_dbg(" Access:"); snd_config_for_each(i, next, cfg) { n = snd_config_iterator_entry(i); @@ -66,7 +66,7 @@ static int parse_access_values(snd_config_t *cfg, for (j = 0; j < ARRAY_SIZE(ctl_access); j++) { if (strcmp(value, ctl_access[j].name) == 0) { hdr->access |= ctl_access[j].value; - tplg_dbg("\t%s\n", value); + tplg_dbg("\t%s", value); break; } } @@ -77,7 +77,7 @@ static int parse_access_values(snd_config_t *cfg, /* Parse Access */ int parse_access(snd_config_t *cfg, - struct snd_soc_tplg_ctl_hdr *hdr) + struct snd_soc_tplg_ctl_hdr *hdr) { snd_config_iterator_t i, next; snd_config_t *n; @@ -93,7 +93,7 @@ int parse_access(snd_config_t *cfg, if (strcmp(id, "access") == 0) { err = parse_access_values(n, hdr); if (err < 0) { - SNDERR("error: failed to parse access"); + SNDERR("failed to parse access"); return err; } continue; @@ -103,13 +103,53 @@ int parse_access(snd_config_t *cfg, return err; } +/* Save Access */ +static int tplg_save_access(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct snd_soc_tplg_ctl_hdr *hdr, char **dst, + const char *pfx) +{ + const char *last; + unsigned int j, count, access, cval; + int err; + + if (hdr->access == 0) + return 0; + + access = hdr->access; + for (j = 0, count = 0, last = NULL; j < ARRAY_SIZE(ctl_access); j++) { + cval = ctl_access[j].value; + if ((access & cval) == cval) { + access &= ~cval; + last = ctl_access[j].name; + count++; + } + } + if (count == 1) + return tplg_save_printf(dst, pfx, "access.0 %s\n", last); + err = tplg_save_printf(dst, pfx, "access [\n"); + if (err < 0) + return err; + access = hdr->access; + for (j = 0; j < ARRAY_SIZE(ctl_access); j++) { + cval = ctl_access[j].value; + if ((access & cval) == cval) { + err = tplg_save_printf(dst, pfx, "\t%s\n", + ctl_access[j].name); + if (err < 0) + return err; + access &= ~cval; + } + } + return tplg_save_printf(dst, pfx, "]\n"); +} + /* copy referenced TLV to the mixer control */ static int copy_tlv(struct tplg_elem *elem, struct tplg_elem *ref) { struct snd_soc_tplg_mixer_control *mixer_ctrl = elem->mixer_ctrl; struct snd_soc_tplg_ctl_tlv *tlv = ref->tlv; - tplg_dbg("TLV '%s' used by '%s\n", ref->id, elem->id); + tplg_dbg("TLV '%s' used by '%s", ref->id, elem->id); /* TLV has a fixed size */ mixer_ctrl->hdr.tlv = *tlv; @@ -118,7 +158,7 @@ static int copy_tlv(struct tplg_elem *elem, struct tplg_elem *ref) /* check referenced TLV for a mixer control */ static int tplg_build_mixer_control(snd_tplg_t *tplg, - struct tplg_elem *elem) + struct tplg_elem *elem) { struct tplg_ref *ref; struct list_head *base, *pos; @@ -146,8 +186,8 @@ static int tplg_build_mixer_control(snd_tplg_t *tplg, } if (!ref->elem) { - SNDERR("error: cannot find '%s' referenced by" - " control '%s'\n", ref->id, elem->id); + SNDERR("cannot find '%s' referenced by" + " control '%s'", ref->id, elem->id); return -EINVAL; } else if (err < 0) return err; @@ -157,7 +197,7 @@ static int tplg_build_mixer_control(snd_tplg_t *tplg, } static void copy_enum_texts(struct tplg_elem *enum_elem, - struct tplg_elem *ref_elem) + struct tplg_elem *ref_elem) { struct snd_soc_tplg_enum_control *ec = enum_elem->enum_ctrl; struct tplg_texts *texts = ref_elem->texts; @@ -169,7 +209,7 @@ static void copy_enum_texts(struct tplg_elem *enum_elem, /* check referenced text for a enum control */ static int tplg_build_enum_control(snd_tplg_t *tplg, - struct tplg_elem *elem) + struct tplg_elem *elem) { struct tplg_ref *ref; struct list_head *base, *pos; @@ -195,8 +235,8 @@ static int tplg_build_enum_control(snd_tplg_t *tplg, return err; } if (!ref->elem) { - SNDERR("error: cannot find '%s' referenced by" - " control '%s'\n", ref->id, elem->id); + SNDERR("cannot find '%s' referenced by" + " control '%s'", ref->id, elem->id); return -EINVAL; } } @@ -284,17 +324,13 @@ static int tplg_parse_tlv_dbscale(snd_config_t *cfg, struct tplg_elem *elem) { snd_config_iterator_t i, next; snd_config_t *n; - struct snd_soc_tplg_ctl_tlv *tplg_tlv; + struct snd_soc_tplg_ctl_tlv *tplg_tlv = elem->tlv; struct snd_soc_tplg_tlv_dbscale *scale; - const char *id = NULL, *value = NULL; + const char *id = NULL; + int val; - tplg_dbg(" scale: %s\n", elem->id); + tplg_dbg(" scale: %s", elem->id); - tplg_tlv = calloc(1, sizeof(*tplg_tlv)); - if (!tplg_tlv) - return -ENOMEM; - - elem->tlv = tplg_tlv; tplg_tlv->size = sizeof(struct snd_soc_tplg_ctl_tlv); tplg_tlv->type = SNDRV_CTL_TLVT_DB_SCALE; scale = &tplg_tlv->scale; @@ -304,26 +340,24 @@ static int tplg_parse_tlv_dbscale(snd_config_t *cfg, struct tplg_elem *elem) n = snd_config_iterator_entry(i); /* get ID */ - if (snd_config_get_id(n, &id) < 0) { - SNDERR("error: cant get ID\n"); + if (snd_config_get_id(n, &id) < 0) return -EINVAL; - } /* get value */ - if (snd_config_get_string(n, &value) < 0) + if (tplg_get_integer(n, &val, 0)) continue; - tplg_dbg("\t%s = %s\n", id, value); + tplg_dbg("\t%s = %i", id, val); /* get TLV data */ if (strcmp(id, "min") == 0) - scale->min = atoi(value); + scale->min = val; else if (strcmp(id, "step") == 0) - scale->step = atoi(value); + scale->step = val; else if (strcmp(id, "mute") == 0) - scale->mute = atoi(value); + scale->mute = val; else - SNDERR("error: unknown key %s\n", id); + SNDERR("unknown id '%s'", id); } return 0; @@ -331,7 +365,7 @@ static int tplg_parse_tlv_dbscale(snd_config_t *cfg, struct tplg_elem *elem) /* Parse TLV */ int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { snd_config_iterator_t i, next; snd_config_t *n; @@ -352,7 +386,7 @@ int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "scale") == 0) { err = tplg_parse_tlv_dbscale(n, elem); if (err < 0) { - SNDERR("error: failed to DBScale"); + SNDERR("failed to DBScale"); return err; } continue; @@ -362,16 +396,48 @@ int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, return err; } +/* save TLV data */ +int tplg_save_tlv(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_ctl_tlv *tlv = elem->tlv; + struct snd_soc_tplg_tlv_dbscale *scale; + int err; + + if (tlv->type != SNDRV_CTL_TLVT_DB_SCALE) { + SNDERR("unknown TLV type"); + return -EINVAL; + } + + scale = &tlv->scale; + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\tscale {\n"); + if (err >= 0 && scale->min) + err = tplg_save_printf(dst, pfx, "\t\tmin %i\n", scale->min); + if (err >= 0 && scale->step > 0) + err = tplg_save_printf(dst, pfx, "\t\tstep %i\n", scale->step); + if (err >= 0 && scale->mute > 0) + err = tplg_save_printf(dst, pfx, "\t\tmute %i\n", scale->mute); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t}\n"); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse Control Bytes */ int tplg_parse_control_bytes(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) + snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_bytes_control *be; struct tplg_elem *elem; snd_config_iterator_t i, next; snd_config_t *n; const char *id, *val = NULL; - int err; + int err, ival; bool access_set = false, tlv_set = false; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_BYTES); @@ -383,7 +449,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_strlcpy(be->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); be->hdr.type = SND_SOC_TPLG_TYPE_BYTES; - tplg_dbg(" Control Bytes: %s\n", elem->id); + tplg_dbg(" Control Bytes: %s", elem->id); snd_config_for_each(i, next, cfg) { n = snd_config_iterator_entry(i); @@ -397,43 +463,43 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, continue; if (strcmp(id, "base") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - be->base = atoi(val); - tplg_dbg("\t%s: %d\n", id, be->base); + be->base = ival; + tplg_dbg("\t%s: %d", id, be->base); continue; } if (strcmp(id, "num_regs") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - be->num_regs = atoi(val); - tplg_dbg("\t%s: %d\n", id, be->num_regs); + be->num_regs = ival; + tplg_dbg("\t%s: %d", id, be->num_regs); continue; } if (strcmp(id, "max") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - be->max = atoi(val); - tplg_dbg("\t%s: %d\n", id, be->max); + be->max = ival; + tplg_dbg("\t%s: %d", id, be->max); continue; } if (strcmp(id, "mask") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 16)) return -EINVAL; - be->mask = strtol(val, NULL, 16); - tplg_dbg("\t%s: %d\n", id, be->mask); + be->mask = ival; + tplg_dbg("\t%s: %d", id, be->mask); continue; } if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -448,7 +514,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, return err; tlv_set = true; - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } @@ -488,9 +554,52 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, return 0; } +/* save control bytes */ +int tplg_save_control_bytes(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_bytes_control *be = elem->bytes_ext; + char pfx2[16]; + int err; + + if (!be) + return 0; + + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err < 0) + return err; + if (err >= 0 && elem->index > 0) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", elem->index); + if (err >= 0 && be->base > 0) + err = tplg_save_printf(dst, pfx, "\tbase %u\n", be->base); + if (err >= 0 && be->num_regs > 0) + err = tplg_save_printf(dst, pfx, "\tnum_regs %u\n", be->num_regs); + if (err >= 0 && be->max > 0) + err = tplg_save_printf(dst, pfx, "\tmax %u\n", be->max); + if (err >= 0 && be->mask > 0) + err = tplg_save_printf(dst, pfx, "\tmask %u\n", be->mask); + if (err >= 0) + err = tplg_save_ops(tplg, &be->hdr, dst, pfx2); + if (err >= 0) + err = tplg_save_ext_ops(tplg, be, dst, pfx2); + if (err >= 0) + err = tplg_save_access(tplg, &be->hdr, dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_TLV, + "tlv", dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse Control Enums. */ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_enum_control *ec; struct tplg_elem *elem; @@ -511,10 +620,11 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, tplg->channel_idx = 0; /* set channel reg to default state */ - for (j = 0; j < SND_SOC_TPLG_MAX_CHAN; j++) + for (j = 0; j < SND_SOC_TPLG_MAX_CHAN; j++) { ec->channel[j].reg = -1; + } - tplg_dbg(" Control Enum: %s\n", elem->id); + tplg_dbg(" Control Enum: %s", elem->id); snd_config_for_each(i, next, cfg) { @@ -533,14 +643,13 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, return -EINVAL; tplg_ref_add(elem, SND_TPLG_TYPE_TEXT, val); - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } if (strcmp(id, "channel") == 0) { if (ec->num_channels >= SND_SOC_TPLG_MAX_CHAN) { - SNDERR("error: too many channels %s\n", - elem->id); + SNDERR("too many channels %s", elem->id); return -EINVAL; } @@ -562,7 +671,7 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, } if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -585,19 +694,56 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, return 0; } +/* save control eunm */ +int tplg_save_control_enum(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_enum_control *ec = elem->enum_ctrl; + char pfx2[16]; + int err; + + if (!ec) + return 0; + + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err < 0) + return err; + if (err >= 0 && elem->index > 0) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", elem->index); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_TEXT, + "texts", dst, pfx2); + if (err >= 0) + err = tplg_save_channels(tplg, ec->channel, ec->num_channels, + dst, pfx2); + if (err >= 0) + err = tplg_save_ops(tplg, &ec->hdr, dst, pfx2); + if (err >= 0) + err = tplg_save_access(tplg, &ec->hdr, dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse Controls. * * Mixer control. Supports multiple channels. */ int tplg_parse_control_mixer(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) + snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_mixer_control *mc; struct tplg_elem *elem; snd_config_iterator_t i, next; snd_config_t *n; const char *id, *val = NULL; - int err, j; + int err, j, ival; bool access_set = false, tlv_set = false; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_MIXER); @@ -615,7 +761,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, for (j = 0; j < SND_SOC_TPLG_MAX_CHAN; j++) mc->channel[j].reg = -1; - tplg_dbg(" Control Mixer: %s\n", elem->id); + tplg_dbg(" Control Mixer: %s", elem->id); /* giterate trough each mixer elment */ snd_config_for_each(i, next, cfg) { @@ -631,8 +777,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, if (strcmp(id, "channel") == 0) { if (mc->num_channels >= SND_SOC_TPLG_MAX_CHAN) { - SNDERR("error: too many channels %s\n", - elem->id); + SNDERR("too many channels %s", elem->id); return -EINVAL; } @@ -646,24 +791,21 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, } if (strcmp(id, "max") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - mc->max = atoi(val); - tplg_dbg("\t%s: %d\n", id, mc->max); + mc->max = ival; + tplg_dbg("\t%s: %d", id, mc->max); continue; } if (strcmp(id, "invert") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; + mc->invert = ival; - if (strcmp(val, "true") == 0) - mc->invert = 1; - else if (strcmp(val, "false") == 0) - mc->invert = 0; - - tplg_dbg("\t%s: %d\n", id, mc->invert); + tplg_dbg("\t%s: %d", id, mc->invert); continue; } @@ -684,12 +826,12 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, return err; tlv_set = true; - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -715,9 +857,54 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, return 0; } -static int init_ctl_hdr(struct snd_soc_tplg_ctl_hdr *hdr, - struct snd_tplg_ctl_template *t) +int tplg_save_control_mixer(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, char **dst, + const char *pfx) { + struct snd_soc_tplg_mixer_control *mc = elem->mixer_ctrl; + char pfx2[16]; + int err; + + if (!mc) + return 0; + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err < 0) + return err; + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + if (err >= 0 && elem->index > 0) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", elem->index); + if (err >= 0) + err = tplg_save_channels(tplg, mc->channel, mc->num_channels, + dst, pfx2); + if (err >= 0 && mc->max > 0) + err = tplg_save_printf(dst, pfx, "\tmax %u\n", mc->max); + if (err >= 0 && mc->invert > 0) + err = tplg_save_printf(dst, pfx, "\tinvert 1\n", mc->max); + if (err >= 0 && mc->invert > 0) + err = tplg_save_printf(dst, pfx, "\tinvert 1\n", mc->max); + if (err >= 0) + err = tplg_save_ops(tplg, &mc->hdr, dst, pfx2); + if (err >= 0) + err = tplg_save_access(tplg, &mc->hdr, dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_TLV, + "tlv", dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + +static int init_ctl_hdr(snd_tplg_t *tplg, + struct tplg_elem *parent, + struct snd_soc_tplg_ctl_hdr *hdr, + struct snd_tplg_ctl_template *t) +{ + struct tplg_elem *elem; + int err; + hdr->size = sizeof(struct snd_soc_tplg_ctl_hdr); hdr->type = t->type; @@ -743,15 +930,26 @@ static int init_ctl_hdr(struct snd_soc_tplg_ctl_hdr *hdr, && !(hdr->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)) { struct snd_tplg_tlv_template *tlvt = t->tlv; - struct snd_soc_tplg_ctl_tlv *tlv = &hdr->tlv; + struct snd_soc_tplg_ctl_tlv *tlv; struct snd_tplg_tlv_dbscale_template *scalet; struct snd_soc_tplg_tlv_dbscale *scale; if (!tlvt) { - SNDERR("error: missing TLV data\n"); + SNDERR("missing TLV data"); return -EINVAL; } + elem = tplg_elem_new_common(tplg, NULL, parent->id, + SND_TPLG_TYPE_TLV); + if (!elem) + return -ENOMEM; + + tlv = elem->tlv; + + err = tplg_ref_add(parent, SND_TPLG_TYPE_TLV, parent->id); + if (err < 0) + return err; + tlv->size = sizeof(struct snd_soc_tplg_ctl_tlv); tlv->type = tlvt->type; @@ -767,7 +965,7 @@ static int init_ctl_hdr(struct snd_soc_tplg_ctl_hdr *hdr, /* TODO: add support for other TLV types */ default: - SNDERR("error: unsupported TLV type %d\n", tlv->type); + SNDERR("unsupported TLV type %d", tlv->type); break; } } @@ -776,17 +974,17 @@ static int init_ctl_hdr(struct snd_soc_tplg_ctl_hdr *hdr, } int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer, - struct tplg_elem **e) + struct tplg_elem **e) { - struct snd_soc_tplg_private *priv = mixer->priv; struct snd_soc_tplg_mixer_control *mc; + struct snd_soc_tplg_private *priv; struct tplg_elem *elem; int ret, i, num_channels; - tplg_dbg(" Control Mixer: %s\n", mixer->hdr.name); + tplg_dbg(" Control Mixer: %s", mixer->hdr.name); if (mixer->hdr.type != SND_SOC_TPLG_TYPE_MIXER) { - SNDERR("error: invalid mixer type %d\n", mixer->hdr.type); + SNDERR("invalid mixer type %d", mixer->hdr.type); return -EINVAL; } @@ -798,7 +996,7 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer, /* init new mixer */ mc = elem->mixer_ctrl; mc->size = elem->size; - ret = init_ctl_hdr(&mc->hdr, &mixer->hdr); + ret = init_ctl_hdr(tplg, elem, &mc->hdr, &mixer->hdr); if (ret < 0) { tplg_elem_free(elem); return ret; @@ -819,25 +1017,20 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer, for (i = 0; i < num_channels; i++) { struct snd_tplg_channel_elem *channel = &mixer->map->channel[i]; - mc->channel[i].size = channel->size; + mc->channel[i].size = sizeof(mc->channel[0]); mc->channel[i].reg = channel->reg; mc->channel[i].shift = channel->shift; mc->channel[i].id = channel->id; } /* priv data */ - if (priv) { - mc = realloc(mc, elem->size + priv->size); - if (!mc) { - tplg_elem_free(elem); - return -ENOMEM; - } - - elem->mixer_ctrl = mc; - elem->size += priv->size; - mc->priv.size = priv->size; - memcpy(mc->priv.data, priv->data, priv->size); - } + priv = mixer->priv; + if (priv && priv->size > 0) { + ret = tplg_add_data(tplg, elem, priv, + sizeof(*priv) + priv->size); + if (ret < 0) + return ret; + } if (e) *e = elem; @@ -845,16 +1038,17 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer, } int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, - struct tplg_elem **e) + struct tplg_elem **e) { struct snd_soc_tplg_enum_control *ec; + struct snd_soc_tplg_private *priv; struct tplg_elem *elem; - int ret, i, num_items; + int ret, i, num_items, num_channels; - tplg_dbg(" Control Enum: %s\n", enum_ctl->hdr.name); + tplg_dbg(" Control Enum: %s", enum_ctl->hdr.name); if (enum_ctl->hdr.type != SND_SOC_TPLG_TYPE_ENUM) { - SNDERR("error: invalid enum type %d\n", enum_ctl->hdr.type); + SNDERR("invalid enum type %d", enum_ctl->hdr.type); return -EINVAL; } @@ -865,7 +1059,7 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, ec = elem->enum_ctrl; ec->size = elem->size; - ret = init_ctl_hdr(&ec->hdr, &enum_ctl->hdr); + ret = init_ctl_hdr(tplg, elem, &ec->hdr, &enum_ctl->hdr); if (ret < 0) { tplg_elem_free(elem); return ret; @@ -877,6 +1071,22 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, ec->mask = enum_ctl->mask; ec->count = enum_ctl->items; + /* set channel reg to default state */ + for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) + ec->channel[i].reg = -1; + + num_channels = enum_ctl->map ? enum_ctl->map->num_channels : 0; + ec->num_channels = num_channels; + + for (i = 0; i < num_channels; i++) { + struct snd_tplg_channel_elem *channel = &enum_ctl->map->channel[i]; + + ec->channel[i].size = sizeof(ec->channel[0]); + ec->channel[i].reg = channel->reg; + ec->channel[i].shift = channel->shift; + ec->channel[i].id = channel->id; + } + if (enum_ctl->texts != NULL) { for (i = 0; i < num_items; i++) { if (enum_ctl->texts[i] != NULL) @@ -896,21 +1106,13 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, } } - if (enum_ctl->priv != NULL) { - ec = realloc(ec, - elem->size + enum_ctl->priv->size); - if (!ec) { - tplg_elem_free(elem); - return -ENOMEM; - } - - elem->enum_ctrl = ec; - elem->size += enum_ctl->priv->size; - - memcpy(ec->priv.data, enum_ctl->priv->data, - enum_ctl->priv->size); - - ec->priv.size = enum_ctl->priv->size; + /* priv data */ + priv = enum_ctl->priv; + if (priv && priv->size > 0) { + ret = tplg_add_data(tplg, elem, priv, + sizeof(*priv) + priv->size); + if (ret < 0) + return ret; } if (e) @@ -919,16 +1121,17 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, } int tplg_add_bytes(snd_tplg_t *tplg, struct snd_tplg_bytes_template *bytes_ctl, - struct tplg_elem **e) + struct tplg_elem **e) { struct snd_soc_tplg_bytes_control *be; + struct snd_soc_tplg_private *priv; struct tplg_elem *elem; int ret; - tplg_dbg(" Control Bytes: %s\n", bytes_ctl->hdr.name); + tplg_dbg(" Control Bytes: %s", bytes_ctl->hdr.name); if (bytes_ctl->hdr.type != SND_SOC_TPLG_TYPE_BYTES) { - SNDERR("error: invalid bytes type %d\n", bytes_ctl->hdr.type); + SNDERR("invalid bytes type %d", bytes_ctl->hdr.type); return -EINVAL; } @@ -939,7 +1142,7 @@ int tplg_add_bytes(snd_tplg_t *tplg, struct snd_tplg_bytes_template *bytes_ctl, be = elem->bytes_ext; be->size = elem->size; - ret = init_ctl_hdr(&be->hdr, &bytes_ctl->hdr); + ret = init_ctl_hdr(tplg, elem, &be->hdr, &bytes_ctl->hdr); if (ret < 0) { tplg_elem_free(elem); return ret; @@ -952,27 +1155,20 @@ int tplg_add_bytes(snd_tplg_t *tplg, struct snd_tplg_bytes_template *bytes_ctl, be->ext_ops.put = bytes_ctl->ext_ops.put; be->ext_ops.get = bytes_ctl->ext_ops.get; - if (bytes_ctl->priv != NULL) { - be = realloc(be, - elem->size + bytes_ctl->priv->size); - if (!be) { - tplg_elem_free(elem); - return -ENOMEM; - } - elem->bytes_ext = be; - elem->size += bytes_ctl->priv->size; - - memcpy(be->priv.data, bytes_ctl->priv->data, - bytes_ctl->priv->size); - - be->priv.size = bytes_ctl->priv->size; + /* priv data */ + priv = bytes_ctl->priv; + if (priv && priv->size > 0) { + ret = tplg_add_data(tplg, elem, priv, + sizeof(*priv) + priv->size); + if (ret < 0) + return ret; } /* check on TLV bytes control */ if (be->hdr.access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { if ((be->hdr.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) != SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { - SNDERR("error: Invalid TLV bytes control access 0x%x\n", + SNDERR("Invalid TLV bytes control access 0x%x", be->hdr.access); tplg_elem_free(elem); return -EINVAL; @@ -1003,3 +1199,330 @@ int tplg_add_bytes_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) { return tplg_add_bytes(tplg, t->bytes_ctl, NULL); } + +int tplg_decode_control_mixer1(snd_tplg_t *tplg, + struct list_head *heap, + struct snd_tplg_mixer_template *mt, + size_t pos, + void *bin, size_t size) +{ + struct snd_soc_tplg_mixer_control *mc = bin; + struct snd_tplg_channel_map_template *map; + struct snd_tplg_tlv_dbscale_template *db; + int i; + + if (size < sizeof(*mc)) { + SNDERR("mixer: small size %d", size); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "mixer: size %d TLV size %d private size %d", + mc->size, mc->hdr.tlv.size, mc->priv.size); + if (size != mc->size + mc->priv.size) { + SNDERR("mixer: unexpected element size %d", size); + return -EINVAL; + } + + memset(mt, 0, sizeof(*mt)); + mt->hdr.type = mc->hdr.type; + mt->hdr.name = mc->hdr.name; + mt->hdr.access = mc->hdr.access; + mt->hdr.ops.get = mc->hdr.ops.get; + mt->hdr.ops.put = mc->hdr.ops.put; + mt->hdr.ops.info = mc->hdr.ops.info; + mt->min = mc->min; + mt->max = mc->max; + mt->platform_max = mc->platform_max; + tplg_log(tplg, 'D', pos, "mixer: name '%s' access 0x%x", + mt->hdr.name, mt->hdr.access); + if (mc->num_channels > 0) { + map = tplg_calloc(heap, sizeof(*map)); + map->num_channels = mc->num_channels; + for (i = 0; i < map->num_channels; i++) { + map->channel[i].reg = mc->channel[i].reg; + map->channel[i].shift = mc->channel[i].shift; + map->channel[i].id = mc->channel[i].id; + } + mt->map = map; + } + if (mc->hdr.tlv.size == 0) { + /* nothing */ + } else if (mc->hdr.tlv.size == sizeof(struct snd_soc_tplg_ctl_tlv)) { + if (mc->hdr.tlv.type != SNDRV_CTL_TLVT_DB_SCALE) { + SNDERR("mixer: unknown TLV type %d", + mc->hdr.tlv.type); + return -EINVAL; + } + db = tplg_calloc(heap, sizeof(*db)); + if (db == NULL) + return -ENOMEM; + mt->hdr.tlv_scale = db; + db->hdr.type = mc->hdr.tlv.type; + db->min = mc->hdr.tlv.scale.min; + db->step = mc->hdr.tlv.scale.step; + db->mute = mc->hdr.tlv.scale.mute; + tplg_log(tplg, 'D', pos, "mixer: dB scale TLV: min %d step %d mute %d", + db->min, db->step, db->mute); + } else { + SNDERR("mixer: wrong TLV size %d", mc->hdr.tlv.size); + return -EINVAL; + } + + mt->priv = &mc->priv; + tplg_log(tplg, 'D', pos + offsetof(struct snd_soc_tplg_mixer_control, priv), + "mixer: private start"); + return 0; +} + +int tplg_decode_control_mixer(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct list_head heap; + snd_tplg_obj_template_t t; + struct snd_tplg_mixer_template mt; + struct snd_soc_tplg_mixer_control *mc; + size_t size2; + int err; + + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; + +next: + if (size < sizeof(*mc)) { + SNDERR("mixer: small size %d", size); + return -EINVAL; + } + INIT_LIST_HEAD(&heap); + mc = bin; + size2 = mc->size + mc->priv.size; + if (size2 > size) { + SNDERR("mixer: wrong element size (%d, priv %d)", + mc->size, mc->priv.size); + return -EINVAL; + } + + err = tplg_decode_control_mixer1(tplg, &heap, &mt, pos, bin, size2); + if (err >= 0) { + t.mixer = &mt; + err = snd_tplg_add_object(tplg, &t); + } + tplg_free(&heap); + if (err < 0) + return err; + + bin += size2; + size -= size2; + pos += size2; + + if (size > 0) + goto next; + + return 0; +} + +int tplg_decode_control_enum1(snd_tplg_t *tplg, + struct list_head *heap, + struct snd_tplg_enum_template *et, + size_t pos, + void *bin, size_t size) +{ + struct snd_soc_tplg_enum_control *ec = bin; + struct snd_tplg_channel_map_template cmt; + int i; + + if (size < sizeof(*ec)) { + SNDERR("enum: small size %d", size); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "enum: size %d private size %d", + ec->size, ec->priv.size); + if (size != ec->size + ec->priv.size) { + SNDERR("enum: unexpected element size %d", size); + return -EINVAL; + } + if (ec->num_channels > SND_TPLG_MAX_CHAN || + ec->num_channels > SND_SOC_TPLG_MAX_CHAN) { + SNDERR("enum: unexpected channel count %d", ec->num_channels); + return -EINVAL; + } + if (ec->items > SND_SOC_TPLG_NUM_TEXTS) { + SNDERR("enum: unexpected texts count %d", ec->items); + return -EINVAL; + } + + memset(et, 0, sizeof(*et)); + et->hdr.type = ec->hdr.type; + et->hdr.name = ec->hdr.name; + et->hdr.access = ec->hdr.access; + et->hdr.ops.get = ec->hdr.ops.get; + et->hdr.ops.put = ec->hdr.ops.put; + et->hdr.ops.info = ec->hdr.ops.info; + et->mask = ec->mask; + + if (ec->items > 0) { + et->items = ec->items; + et->texts = tplg_calloc(heap, sizeof(char *) * ec->items); + if (!et->texts) + return -ENOMEM; + for (i = 0; ec->items; i++) { + unsigned int j = i * sizeof(int) * ENUM_VAL_SIZE; + et->texts[i] = ec->texts[i]; + et->values[i] = (int *)&ec->values[j]; + } + } + + et->map = &cmt; + memset(&cmt, 0, sizeof(cmt)); + cmt.num_channels = ec->num_channels; + for (i = 0; i < cmt.num_channels; i++) { + struct snd_tplg_channel_elem *channel = &cmt.channel[i]; + tplg_log(tplg, 'D', pos + ((void *)&ec->channel[i] - (void *)ec), + "enum: channel size %d", ec->channel[i].size); + channel->reg = ec->channel[i].reg; + channel->shift = ec->channel[i].shift; + channel->id = ec->channel[i].id; + } + + et->priv = &ec->priv; + return 0; +} + +int tplg_decode_control_enum(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct list_head heap; + snd_tplg_obj_template_t t; + struct snd_tplg_enum_template et; + struct snd_soc_tplg_enum_control *ec; + size_t size2; + int err; + + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; + +next: + if (size < sizeof(*ec)) { + SNDERR("enum: small size %d", size); + return -EINVAL; + } + INIT_LIST_HEAD(&heap); + ec = bin; + size2 = ec->size + ec->priv.size; + if (size2 > size) { + SNDERR("enum: wrong element size (%d, priv %d)", + ec->size, ec->priv.size); + return -EINVAL; + } + + err = tplg_decode_control_enum1(tplg, &heap, &et, pos, bin, size); + if (err >= 0) { + t.enum_ctl = &et; + err = snd_tplg_add_object(tplg, &t); + } + tplg_free(&heap); + if (err < 0) + return err; + + bin += size2; + size -= size2; + pos += size2; + + if (size > 0) + goto next; + + return 0; +} + +int tplg_decode_control_bytes1(snd_tplg_t *tplg, + struct snd_tplg_bytes_template *bt, + size_t pos, + void *bin, size_t size) +{ + struct snd_soc_tplg_bytes_control *bc = bin; + + if (size < sizeof(*bc)) { + SNDERR("bytes: small size %d", size); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "control bytes: size %d private size %d", + bc->size, bc->priv.size); + if (size != bc->size + bc->priv.size) { + SNDERR("bytes: unexpected element size %d", size); + return -EINVAL; + } + + memset(bt, 0, sizeof(*bt)); + bt->hdr.type = bc->hdr.type; + bt->hdr.name = bc->hdr.name; + bt->hdr.access = bc->hdr.access; + bt->hdr.ops.get = bc->hdr.ops.get; + bt->hdr.ops.put = bc->hdr.ops.put; + bt->hdr.ops.info = bc->hdr.ops.info; + bt->max = bc->max; + bt->mask = bc->mask; + bt->base = bc->base; + bt->num_regs = bc->num_regs; + bt->ext_ops.get = bc->ext_ops.get; + bt->ext_ops.put = bc->ext_ops.put; + bt->ext_ops.info = bc->ext_ops.info; + tplg_log(tplg, 'D', pos, "control bytes: name '%s' access 0x%x", + bt->hdr.name, bt->hdr.access); + + bt->priv = &bc->priv; + return 0; +} + +int tplg_decode_control_bytes(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + snd_tplg_obj_template_t t; + struct snd_tplg_bytes_template bt; + struct snd_soc_tplg_bytes_control *bc; + size_t size2; + int err; + + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; + +next: + if (size < sizeof(*bc)) { + SNDERR("bytes: small size %d", size); + return -EINVAL; + } + bc = bin; + size2 = bc->size + bc->priv.size; + if (size2 > size) { + SNDERR("bytes: wrong element size (%d, priv %d)", + bc->size, bc->priv.size); + return -EINVAL; + } + + err = tplg_decode_control_bytes1(tplg, &bt, pos, bin, size); + if (err < 0) + return err; + + t.bytes_ctl = &bt; + err = snd_tplg_add_object(tplg, &t); + if (err < 0) + return err; + + bin += size2; + size -= size2; + pos += size2; + + if (size > 0) + goto next; + + return 0; +} diff --git a/src/topology/dapm.c b/src/topology/dapm.c index 97c9695..cd1a877 100644 --- a/src/topology/dapm.c +++ b/src/topology/dapm.c @@ -60,70 +60,16 @@ static int lookup_widget(const char *w) return -EINVAL; } -static int tplg_parse_dapm_mixers(snd_config_t *cfg, struct tplg_elem *elem) +static const char *get_widget_name(unsigned int type) { - snd_config_iterator_t i, next; - snd_config_t *n; - const char *value = NULL; - - tplg_dbg(" DAPM Mixer Controls: %s\n", elem->id); - - snd_config_for_each(i, next, cfg) { - n = snd_config_iterator_entry(i); - - /* get value */ - if (snd_config_get_string(n, &value) < 0) - continue; - - tplg_ref_add(elem, SND_TPLG_TYPE_MIXER, value); - tplg_dbg("\t\t %s\n", value); - } - - return 0; -} - -static int tplg_parse_dapm_enums(snd_config_t *cfg, struct tplg_elem *elem) -{ - snd_config_iterator_t i, next; - snd_config_t *n; - const char *value = NULL; - - tplg_dbg(" DAPM Enum Controls: %s\n", elem->id); - - snd_config_for_each(i, next, cfg) { - n = snd_config_iterator_entry(i); - - /* get value */ - if (snd_config_get_string(n, &value) < 0) - continue; - - tplg_ref_add(elem, SND_TPLG_TYPE_ENUM, value); - tplg_dbg("\t\t %s\n", value); - } - - return 0; -} - -static int tplg_parse_dapm_bytes(snd_config_t *cfg, struct tplg_elem *elem) -{ - snd_config_iterator_t i, next; - snd_config_t *n; - const char *value = NULL; - - tplg_dbg(" DAPM Bytes Controls: %s\n", elem->id); - - snd_config_for_each(i, next, cfg) { - n = snd_config_iterator_entry(i); - - /* get value */ - if (snd_config_get_string(n, &value) < 0) - continue; + unsigned int i; - tplg_ref_add(elem, SND_TPLG_TYPE_BYTES, value); - tplg_dbg("\t\t %s\n", value); + for (i = 0; i < ARRAY_SIZE(widget_map); i++) { + if ((unsigned int)widget_map[i].id == type) + return widget_map[i].name; } - return 0; + return NULL; } /* move referenced controls to the widget */ @@ -131,8 +77,8 @@ static int copy_dapm_control(struct tplg_elem *elem, struct tplg_elem *ref) { struct snd_soc_tplg_dapm_widget *widget = elem->widget; - tplg_dbg("Control '%s' used by '%s'\n", ref->id, elem->id); - tplg_dbg("\tparent size: %d + %d -> %d, priv size -> %d\n", + tplg_dbg("Control '%s' used by '%s'", ref->id, elem->id); + tplg_dbg("\tparent size: %d + %d -> %d, priv size -> %d", elem->size, ref->size, elem->size + ref->size, widget->priv.size); @@ -152,8 +98,7 @@ static int copy_dapm_control(struct tplg_elem *elem, struct tplg_elem *ref) } /* check referenced controls for a widget */ -static int tplg_build_widget(snd_tplg_t *tplg, - struct tplg_elem *elem) +static int tplg_build_widget(snd_tplg_t *tplg, struct tplg_elem *elem) { struct tplg_ref *ref; struct list_head *base, *pos; @@ -164,7 +109,7 @@ static int tplg_build_widget(snd_tplg_t *tplg, /* A widget's private data sits before the embedded controls. * So merge the private data blocks at first */ - list_for_each(pos, base) { + list_for_each(pos, base) { ref = list_entry(pos, struct tplg_ref, list); if (ref->type != SND_TPLG_TYPE_DATA) @@ -210,8 +155,7 @@ static int tplg_build_widget(snd_tplg_t *tplg, } if (!ref->elem) { - SNDERR("error: cannot find '%s'" - " referenced by widget '%s'\n", + SNDERR("cannot find '%s' referenced by widget '%s'", ref->id, elem->id); return -EINVAL; } @@ -235,8 +179,7 @@ int tplg_build_widgets(snd_tplg_t *tplg) elem = list_entry(pos, struct tplg_elem, list); if (!elem->widget || elem->type != SND_TPLG_TYPE_DAPM_WIDGET) { - SNDERR("error: invalid widget '%s'\n", - elem->id); + SNDERR("invalid widget '%s'", elem->id); return -EINVAL; } @@ -263,25 +206,23 @@ int tplg_build_routes(snd_tplg_t *tplg) elem = list_entry(pos, struct tplg_elem, list); if (!elem->route || elem->type != SND_TPLG_TYPE_DAPM_GRAPH) { - SNDERR("error: invalid route '%s'\n", - elem->id); + SNDERR("invalid route '%s'", elem->id); return -EINVAL; } route = elem->route; - tplg_dbg("\nCheck route: sink '%s', control '%s', source '%s'\n", - route->sink, route->control, route->source); + tplg_dbg("Check route: sink '%s', control '%s', source '%s'", + route->sink, route->control, route->source); /* validate sink */ if (strlen(route->sink) <= 0) { - SNDERR("error: no sink\n"); + SNDERR("no sink"); return -EINVAL; } if (!tplg_elem_lookup(&tplg->widget_list, route->sink, SND_TPLG_TYPE_DAPM_WIDGET, SND_TPLG_INDEX_ALL)) { - SNDERR("warning: undefined sink widget/stream '%s'\n", - route->sink); + SNDERR("undefined sink widget/stream '%s'", route->sink); } /* validate control name */ @@ -290,21 +231,21 @@ int tplg_build_routes(snd_tplg_t *tplg) SND_TPLG_TYPE_MIXER, elem->index) && !tplg_elem_lookup(&tplg->enum_list, route->control, SND_TPLG_TYPE_ENUM, elem->index)) { - SNDERR("warning: Undefined mixer/enum control '%s'\n", - route->control); + SNDERR("undefined mixer/enum control '%s'", + route->control); } } /* validate source */ if (strlen(route->source) <= 0) { - SNDERR("error: no source\n"); + SNDERR("no source"); return -EINVAL; } if (!tplg_elem_lookup(&tplg->widget_list, route->source, SND_TPLG_TYPE_DAPM_WIDGET, SND_TPLG_INDEX_ALL)) { - SNDERR("warning: Undefined source widget/stream '%s'\n", - route->source); + SNDERR("undefined source widget/stream '%s'", + route->source); } /* add graph to manifest */ @@ -314,7 +255,7 @@ int tplg_build_routes(snd_tplg_t *tplg) return 0; } -struct tplg_elem* tplg_elem_new_route(snd_tplg_t *tplg) +struct tplg_elem *tplg_elem_new_route(snd_tplg_t *tplg, int index) { struct tplg_elem *elem; struct snd_soc_tplg_dapm_graph_elem *line; @@ -323,7 +264,11 @@ struct tplg_elem* tplg_elem_new_route(snd_tplg_t *tplg) if (!elem) return NULL; - list_add_tail(&elem->list, &tplg->route_list); + elem->index = index; + if (tplg->dapm_sort) + tplg_elem_insert(elem, &tplg->route_list); + else + list_add_tail(&elem->list, &tplg->route_list); strcpy(elem->id, "line"); elem->type = SND_TPLG_TYPE_DAPM_GRAPH; elem->size = sizeof(*line); @@ -340,9 +285,9 @@ struct tplg_elem* tplg_elem_new_route(snd_tplg_t *tplg) #define LINE_SIZE 1024 -/* line is defined as '"source, control, sink"' */ +/* line is defined as '"sink, control, source"' */ static int tplg_parse_line(const char *text, - struct snd_soc_tplg_dapm_graph_elem *line) + struct snd_soc_tplg_dapm_graph_elem *line) { char buf[LINE_SIZE]; unsigned int len, i; @@ -352,7 +297,7 @@ static int tplg_parse_line(const char *text, len = strlen(buf); if (len <= 2) { - SNDERR("error: invalid route \"%s\"\n", buf); + SNDERR("invalid route \"%s\"", buf); return -EINVAL; } @@ -361,7 +306,7 @@ static int tplg_parse_line(const char *text, if (buf[i] == ',') goto second; } - SNDERR("error: invalid route \"%s\"\n", buf); + SNDERR("invalid route \"%s\"", buf); return -EINVAL; second: @@ -375,7 +320,7 @@ second: goto done; } - SNDERR("error: invalid route \"%s\"\n", buf); + SNDERR("invalid route \"%s\"", buf); return -EINVAL; done: @@ -404,17 +349,16 @@ static int tplg_parse_routes(snd_tplg_t *tplg, snd_config_t *cfg, int index) if (snd_config_get_string(n, &val) < 0) continue; - elem = tplg_elem_new_route(tplg); + elem = tplg_elem_new_route(tplg, index); if (!elem) return -ENOMEM; - elem->index = index; line = elem->route; err = tplg_parse_line(val, line); if (err < 0) return err; - tplg_dbg("route: sink '%s', control '%s', source '%s'\n", + tplg_dbg("route: sink '%s', control '%s', source '%s'", line->sink, line->control, line->source); } @@ -422,16 +366,16 @@ static int tplg_parse_routes(snd_tplg_t *tplg, snd_config_t *cfg, int index) } int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { snd_config_iterator_t i, next; snd_config_t *n; int err; - const char *graph_id, *val = NULL; + const char *graph_id; int index = -1; if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound is expected for dapm graph definition\n"); + SNDERR("compound is expected for dapm graph definition"); return -EINVAL; } @@ -446,20 +390,21 @@ int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, } if (strcmp(id, "index") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &index, 0)) + return -EINVAL; + if (index < 0) return -EINVAL; - index = atoi(val); } if (strcmp(id, "lines") == 0) { if (index < 0) { - SNDERR("error: failed to parse dapm graph %s, missing index\n", + SNDERR("failed to parse dapm graph %s, missing index", graph_id); return -EINVAL; } err = tplg_parse_routes(tplg, n, index); if (err < 0) { - SNDERR("error: failed to parse dapm graph %s\n", + SNDERR("failed to parse dapm graph %s", graph_id); return err; } @@ -470,22 +415,113 @@ int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, return 0; } +/* save DAPM graph */ +int tplg_save_dapm_graph(snd_tplg_t *tplg, int index, char **dst, const char *pfx) +{ + struct snd_soc_tplg_dapm_graph_elem *route; + struct list_head *pos; + struct tplg_elem *elem; + int err, first, old_index; + unsigned block, count; + const char *fmt; + + old_index = -1; + block = 0; + count = 0; + list_for_each(pos, &tplg->route_list) { + elem = list_entry(pos, struct tplg_elem, list); + if (!elem->route || elem->type != SND_TPLG_TYPE_DAPM_GRAPH) + continue; + if (index >= 0 && elem->index != index) + continue; + if (old_index != elem->index) { + block++; + old_index = elem->index; + } + count++; + } + if (count == 0) + return 0; + if (block < 10) { + fmt = "\tset%u {\n"; + } else if (block < 100) { + fmt = "\tset%02u {\n"; + } else if (block < 1000) { + fmt = "\tset%03u {\n"; + } else { + return -EINVAL; + } + old_index = -1; + block = -1; + first = 1; + err = tplg_save_printf(dst, pfx, "SectionGraph {\n"); + list_for_each(pos, &tplg->route_list) { + elem = list_entry(pos, struct tplg_elem, list); + if (!elem->route || elem->type != SND_TPLG_TYPE_DAPM_GRAPH) + continue; + if (index >= 0 && elem->index != index) + continue; + if (old_index != elem->index) { + if (old_index >= 0) { + err = tplg_save_printf(dst, pfx, "\t\t]\n"); + if (err < 0) + return err; + err = tplg_save_printf(dst, pfx, "\t}\n"); + if (err < 0) + return err; + } + old_index = elem->index; + block++; + first = 1; + err = tplg_save_printf(dst, pfx, fmt, block); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t\tindex %u\n", + elem->index); + if (err < 0) + return err; + } + if (first) { + first = 0; + err = tplg_save_printf(dst, pfx, "\t\tlines [\n", elem->index); + if (err < 0) + return err; + } + route = elem->route; + err = tplg_save_printf(dst, pfx, "\t\t\t'%s, %s, %s'\n", + route->sink, route->control, + route->source); + if (err < 0) + return err; + } + + if (!first) { + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t\t]\n"); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t}\n"); + } + + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* DAPM Widget */ int tplg_parse_dapm_widget(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) + snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_dapm_widget *widget; struct tplg_elem *elem; snd_config_iterator_t i, next; snd_config_t *n; const char *id, *val = NULL; - int widget_type, err; + int widget_type, err, ival; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_DAPM_WIDGET); if (!elem) return -ENOMEM; - tplg_dbg(" Widget: %s\n", elem->id); + tplg_dbg(" Widget: %s", elem->id); widget = elem->widget; snd_strlcpy(widget->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); @@ -509,13 +545,13 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, widget_type = lookup_widget(val); if (widget_type < 0){ - SNDERR("Widget '%s': Unsupported widget type %s\n", + SNDERR("widget '%s': Unsupported widget type %s", elem->id, val); return -EINVAL; } widget->id = widget_type; - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } @@ -525,77 +561,78 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, snd_strlcpy(widget->sname, val, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } if (strcmp(id, "no_pm") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; - if (strcmp(val, "true") == 0) - widget->reg = -1; + widget->reg = ival ? -1 : 0; - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } if (strcmp(id, "shift") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - widget->shift = atoi(val); - tplg_dbg("\t%s: %d\n", id, widget->shift); + widget->shift = ival; + tplg_dbg("\t%s: %d", id, widget->shift); continue; } if (strcmp(id, "reg") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - widget->reg = atoi(val); - tplg_dbg("\t%s: %d\n", id, widget->reg); + widget->reg = ival; + tplg_dbg("\t%s: %d", id, widget->reg); continue; } if (strcmp(id, "invert") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; - widget->invert = atoi(val); - tplg_dbg("\t%s: %d\n", id, widget->invert); + widget->invert = ival; + tplg_dbg("\t%s: %d", id, widget->invert); continue; } if (strcmp(id, "subseq") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - widget->subseq= atoi(val); - tplg_dbg("\t%s: %d\n", id, widget->subseq); + widget->subseq = ival; + tplg_dbg("\t%s: %d", id, widget->subseq); continue; } if (strcmp(id, "event_type") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - widget->event_type = atoi(val); - tplg_dbg("\t%s: %d\n", id, widget->event_type); + widget->event_type = ival; + tplg_dbg("\t%s: %d", id, widget->event_type); continue; } if (strcmp(id, "event_flags") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - widget->event_flags = atoi(val); - tplg_dbg("\t%s: %d\n", id, widget->event_flags); + widget->event_flags = ival; + tplg_dbg("\t%s: %d", id, widget->event_flags); continue; } if (strcmp(id, "enum") == 0) { - err = tplg_parse_dapm_enums(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_ENUM); if (err < 0) return err; @@ -603,7 +640,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, } if (strcmp(id, "mixer") == 0) { - err = tplg_parse_dapm_mixers(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_MIXER); if (err < 0) return err; @@ -611,7 +648,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, } if (strcmp(id, "bytes") == 0) { - err = tplg_parse_dapm_bytes(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_BYTES); if (err < 0) return err; @@ -619,7 +656,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, } if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -629,7 +666,67 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, return 0; } -int tplg_add_route(snd_tplg_t *tplg, struct snd_tplg_graph_elem *t) +/* save DAPM widget */ +int tplg_save_dapm_widget(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_dapm_widget *widget = elem->widget; + const char *s; + char pfx2[16]; + int err; + + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && elem->index) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", + elem->index); + if (err >= 0) { + s = get_widget_name(widget->id); + if (s) + err = tplg_save_printf(dst, pfx, "\ttype %s\n", s); + else + err = tplg_save_printf(dst, pfx, "\ttype %u\n", + widget->id); + } + if (err >= 0 && widget->sname[0]) + err = tplg_save_printf(dst, pfx, "\tstream_name '%s'\n", + widget->sname); + if (err >= 0 && widget->reg) + err = tplg_save_printf(dst, pfx, "\tno_pm 1\n"); + if (err >= 0 && widget->shift) + err = tplg_save_printf(dst, pfx, "\tshift %u\n", + widget->shift); + if (err >= 0 && widget->invert) + err = tplg_save_printf(dst, pfx, "\tinvert %u\n", + widget->invert); + if (err >= 0 && widget->subseq) + err = tplg_save_printf(dst, pfx, "\tsubseq %u\n", + widget->subseq); + if (err >= 0 && widget->event_type) + err = tplg_save_printf(dst, pfx, "\tevent_type %u\n", + widget->event_type); + if (err >= 0 && widget->event_flags) + err = tplg_save_printf(dst, pfx, "\tevent_flags %u\n", + widget->event_flags); + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_ENUM, + "enum", dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_MIXER, + "mixer", dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_BYTES, + "bytes", dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + +int tplg_add_route(snd_tplg_t *tplg, struct snd_tplg_graph_elem *t, int index) { struct tplg_elem *elem; struct snd_soc_tplg_dapm_graph_elem *line; @@ -637,7 +734,7 @@ int tplg_add_route(snd_tplg_t *tplg, struct snd_tplg_graph_elem *t) if (!t->src || !t->sink) return -EINVAL; - elem = tplg_elem_new_route(tplg); + elem = tplg_elem_new_route(tplg, index); if (!elem) return -ENOMEM; @@ -645,7 +742,7 @@ int tplg_add_route(snd_tplg_t *tplg, struct snd_tplg_graph_elem *t) snd_strlcpy(line->source, t->src, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); if (t->ctl) snd_strlcpy(line->control, t->ctl, - SNDRV_CTL_ELEM_ID_NAME_MAXLEN); + SNDRV_CTL_ELEM_ID_NAME_MAXLEN); snd_strlcpy(line->sink, t->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); return 0; @@ -657,7 +754,7 @@ int tplg_add_graph_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) int i, ret; for (i = 0; i < gt->count; i++) { - ret = tplg_add_route(tplg, gt->elem + i); + ret = tplg_add_route(tplg, gt->elem + i, t->index); if (ret < 0) return ret; } @@ -672,7 +769,7 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) struct tplg_elem *elem; int i, ret = 0; - tplg_dbg("Widget: %s\n", wt->name); + tplg_dbg("Widget: %s", wt->name); elem = tplg_elem_new_common(tplg, NULL, wt->name, SND_TPLG_TYPE_DAPM_WIDGET); @@ -696,20 +793,14 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) w->event_flags = wt->event_flags; w->event_type = wt->event_type; - if (wt->priv != NULL) { - w = realloc(w, - elem->size + wt->priv->size); - if (!w) { + /* add private data */ + if (wt->priv != NULL && wt->priv->size > 0) { + ret = tplg_add_data(tplg, elem, wt->priv, + sizeof(*wt->priv) + wt->priv->size); + if (ret < 0) { tplg_elem_free(elem); - return -ENOMEM; + return ret; } - - elem->widget = w; - elem->size += wt->priv->size; - - memcpy(w->priv.data, wt->priv->data, - wt->priv->size); - w->priv.size = wt->priv->size; } /* add controls to the widget's reference list */ @@ -742,9 +833,8 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) break; default: - SNDERR("error: widget %s: invalid type %d for ctl %d\n", + SNDERR("widget %s: invalid type %d for ctl %d", wt->name, ct->type, i); - ret = -EINVAL; break; } @@ -762,3 +852,213 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) return 0; } + +/* decode dapm widget from the binary input */ +int tplg_decode_dapm_widget(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct list_head heap; + struct snd_soc_tplg_dapm_widget *w; + snd_tplg_obj_template_t t; + struct snd_tplg_widget_template *wt; + struct snd_tplg_mixer_template *mt; + struct snd_tplg_enum_template *et; + struct snd_tplg_bytes_template *bt; + struct snd_soc_tplg_ctl_hdr *chdr; + struct snd_soc_tplg_mixer_control *mc; + struct snd_soc_tplg_enum_control *ec; + struct snd_soc_tplg_bytes_control *bc; + size_t size2; + unsigned int index; + int err; + + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; + +next: + INIT_LIST_HEAD(&heap); + w = bin; + + if (size < sizeof(*w)) { + SNDERR("dapm widget: small size %d", size); + return -EINVAL; + } + if (sizeof(*w) != w->size) { + SNDERR("dapm widget: unknown element size %d (expected %zd)", + w->size, sizeof(*w)); + return -EINVAL; + } + if (w->num_kcontrols > 16) { + SNDERR("dapm widget: too many kcontrols %d", + w->num_kcontrols); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "dapm widget: size %d private size %d kcontrols %d", + w->size, w->priv.size, w->num_kcontrols); + + wt = tplg_calloc(&heap, sizeof(*wt) + sizeof(void *) * w->num_kcontrols); + if (wt == NULL) + return -ENOMEM; + wt->id = w->id; + wt->name = w->name; + wt->sname = w->sname; + wt->reg = w->reg; + wt->shift = w->shift; + wt->mask = w->mask; + wt->subseq = w->subseq; + wt->invert = w->invert; + wt->ignore_suspend = w->ignore_suspend; + wt->event_flags = w->event_flags; + wt->event_type = w->event_type; + + tplg_log(tplg, 'D', pos, "dapm widget: name '%s' sname '%s'", + wt->name, wt->sname); + + if (sizeof(*w) + w->priv.size > size) { + SNDERR("dapm widget: wrong private data size %d", + w->priv.size); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos + offsetof(struct snd_soc_tplg_dapm_widget, priv), + "dapm widget: private start"); + + wt->priv = &w->priv; + bin += sizeof(*w) + w->priv.size; + size -= sizeof(*w) + w->priv.size; + pos += sizeof(*w) + w->priv.size; + + for (index = 0; index < w->num_kcontrols; index++) { + chdr = bin; + switch (chdr->type) { + case SND_SOC_TPLG_TYPE_MIXER: + mt = tplg_calloc(&heap, sizeof(*mt)); + if (mt == NULL) { + err = -ENOMEM; + goto retval; + } + wt->ctl[index] = (void *)mt; + wt->num_ctls++; + mc = bin; + size2 = mc->size + mc->priv.size; + tplg_log(tplg, 'D', pos, "kcontrol mixer size %zd", size2); + if (size2 > size) { + SNDERR("dapm widget: small mixer size %d", + size2); + err = -EINVAL; + goto retval; + } + err = tplg_decode_control_mixer1(tplg, &heap, mt, pos, + bin, size2); + break; + case SND_SOC_TPLG_TYPE_ENUM: + et = tplg_calloc(&heap, sizeof(*mt)); + if (et == NULL) { + err = -ENOMEM; + goto retval; + } + wt->ctl[index] = (void *)et; + wt->num_ctls++; + ec = bin; + size2 = ec->size + ec->priv.size; + tplg_log(tplg, 'D', pos, "kcontrol enum size %zd", size2); + if (size2 > size) { + SNDERR("dapm widget: small enum size %d", + size2); + err = -EINVAL; + goto retval; + } + err = tplg_decode_control_enum1(tplg, &heap, et, pos, + bin, size2); + break; + case SND_SOC_TPLG_TYPE_BYTES: + bt = tplg_calloc(&heap, sizeof(*bt)); + if (bt == NULL) { + err = -ENOMEM; + goto retval; + } + wt->ctl[index] = (void *)bt; + wt->num_ctls++; + bc = bin; + size2 = bc->size + bc->priv.size; + tplg_log(tplg, 'D', pos, "kcontrol bytes size %zd", size2); + if (size2 > size) { + SNDERR("dapm widget: small bytes size %d", + size2); + err = -EINVAL; + goto retval; + } + err = tplg_decode_control_bytes1(tplg, bt, pos, + bin, size2); + break; + default: + SNDERR("dapm widget: wrong control type %d", + chdr->type); + err = -EINVAL; + goto retval; + } + if (err < 0) + goto retval; + bin += size2; + size -= size2; + pos += size2; + } + + t.widget = wt; + err = snd_tplg_add_object(tplg, &t); + tplg_free(&heap); + if (err < 0) + return err; + if (size > 0) + goto next; + return 0; + +retval: + tplg_free(&heap); + return err; +} + +/* decode dapm link from the binary input */ +int tplg_decode_dapm_graph(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct snd_soc_tplg_dapm_graph_elem *g; + snd_tplg_obj_template_t t; + struct snd_tplg_graph_template *gt; + struct snd_tplg_graph_elem *ge; + size_t asize; + int err; + + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; + + asize = sizeof(*gt) + (size / sizeof(*g)) * sizeof(*ge); + gt = alloca(asize); + memset(gt, 0, asize); + for (ge = gt->elem; size > 0; ge++) { + g = bin; + if (size < sizeof(*g)) { + SNDERR("dapm graph: small size %d", size); + return -EINVAL; + } + ge->src = g->source; + ge->ctl = g->control; + ge->sink = g->sink; + gt->count++; + tplg_log(tplg, 'D', pos, "dapm graph: src='%s' ctl='%s' sink='%s'", + ge->src, ge->ctl, ge->sink); + bin += sizeof(*g); + size -= sizeof(*g); + pos += sizeof(*g); + } + + t.graph = gt; + return snd_tplg_add_object(tplg, &t); +} diff --git a/src/topology/data.c b/src/topology/data.c index 729ce1f..5742b35 100644 --- a/src/topology/data.c +++ b/src/topology/data.c @@ -21,6 +21,10 @@ #include "tplg_local.h" #include +#define UUID_FORMAT "\ +%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:\ +%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" + /* Get private data buffer of an element */ struct snd_soc_tplg_private *get_priv_data(struct tplg_elem *elem) { @@ -57,25 +61,115 @@ struct snd_soc_tplg_private *get_priv_data(struct tplg_elem *elem) priv = &elem->pcm->priv; break; default: - SNDERR("error: '%s': no support for private data for type %d\n", + SNDERR("'%s': no support for private data for type %d", elem->id, elem->type); } return priv; } +/* Parse references for the element, either a single data section + * or a list of data sections. + */ +int tplg_parse_refs(snd_config_t *cfg, struct tplg_elem *elem, + unsigned int type) +{ + snd_config_type_t cfg_type; + snd_config_iterator_t i, next; + snd_config_t *n; + const char *val = NULL; + int err, count; + + cfg_type = snd_config_get_type(cfg); + + /* refer to a single data section */ + if (cfg_type == SND_CONFIG_TYPE_STRING) { + if (snd_config_get_string(cfg, &val) < 0) + return -EINVAL; + + tplg_dbg("\tref data: %s", val); + err = tplg_ref_add(elem, type, val); + if (err < 0) + return err; + return 1; + } + + if (cfg_type != SND_CONFIG_TYPE_COMPOUND) { + SNDERR("compound type expected for %s", elem->id); + return -EINVAL; + } + + /* refer to a list of data sections */ + count = 0; + snd_config_for_each(i, next, cfg) { + const char *val; + + n = snd_config_iterator_entry(i); + if (snd_config_get_string(n, &val) < 0) + continue; + + tplg_dbg("\tref data: %s", val); + err = tplg_ref_add(elem, type, val); + if (err < 0) + return err; + count++; + } + + return count; +} + +/* save references */ +int tplg_save_refs(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, unsigned int type, + const char *id, char **dst, const char *pfx) +{ + struct tplg_ref *ref, *last; + struct list_head *pos; + int err, count; + + count = 0; + last = NULL; + list_for_each(pos, &elem->ref_list) { + ref = list_entry(pos, struct tplg_ref, list); + if (ref->type == type) { + last = ref; + count++; + } + } + + if (count == 0) + return 0; + + if (count == 1) + return tplg_save_printf(dst, pfx, "%s '%s'\n", id, last->id); + + err = tplg_save_printf(dst, pfx, "%s [\n", id); + if (err < 0) + return err; + list_for_each(pos, &elem->ref_list) { + ref = list_entry(pos, struct tplg_ref, list); + if (ref->type == type) { + err = tplg_save_printf(dst, pfx, "\t'%s'\n", ref->id); + if (err < 0) + return err; + } + } + + return tplg_save_printf(dst, pfx, "]\n"); +} + /* Get Private data from a file. */ static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem) { struct snd_soc_tplg_private *priv = NULL; const char *value = NULL; - char filename[MAX_FILE]; + char filename[PATH_MAX]; char *env = getenv(ALSA_CONFIG_TPLG_VAR); FILE *fp; size_t size, bytes_read; int ret = 0; - tplg_dbg("data DataFile: %s\n", elem->id); + tplg_dbg("data DataFile: %s", elem->id); if (snd_config_get_string(cfg, &value) < 0) return -EINVAL; @@ -89,8 +183,7 @@ static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem) fp = fopen(filename, "r"); if (fp == NULL) { - SNDERR("error: invalid data file path '%s'\n", - filename); + SNDERR("invalid data file path '%s'", filename); return -errno; } @@ -98,12 +191,12 @@ static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem) size = ftell(fp); fseek(fp, 0L, SEEK_SET); if (size <= 0) { - SNDERR("error: invalid data file size %zu\n", size); + SNDERR("invalid data file size %zu", size); ret = -EINVAL; goto err; } if (size > TPLG_MAX_PRIV_SIZE) { - SNDERR("error: data file too big %zu\n", size); + SNDERR("data file too big %zu", size); ret = -EINVAL; goto err; } @@ -137,61 +230,109 @@ err: return ret; } -static void dump_priv_data(struct tplg_elem *elem) +static void dump_priv_data(struct tplg_elem *elem ATTRIBUTE_UNUSED) { +#ifdef TPLG_DEBUG struct snd_soc_tplg_private *priv = elem->data; - unsigned int i, j = 0; + unsigned char *p = (unsigned char *)priv->data; + char buf[128], buf2[8]; + unsigned int i; - tplg_dbg(" elem size = %d, priv data size = %d\n", + tplg_dbg(" elem size = %d, priv data size = %d", elem->size, priv->size); + buf[0] = '\0'; for (i = 0; i < priv->size; i++) { - if (j++ % 8 == 0) - tplg_dbg("\n"); + if (i > 0 && (i % 16) == 0) { + tplg_dbg("%s", buf); + buf[0] = '\0'; + } - tplg_dbg(" 0x%x", *p++); + snprintf(buf2, sizeof(buf2), " %02x", *p++); + strcat(buf, buf2); } - tplg_dbg("\n\n"); + if (buf[0]) + tplg_dbg("%s", buf); +#endif +} + +static inline int check_nibble(unsigned char c) +{ + return (c >= '0' && c <= '9') || + (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F'); } /* get number of hex value elements in CSV list */ static int get_hex_num(const char *str) { - int commas = 0, values = 0, len = strlen(str); - const char *end = str + len; + int delims, values, len = strlen(str); + const char *s, *end = str + len; + /* check "aa:bb:00" syntax */ + s = str; + delims = values = 0; + while (s < end) { + /* skip white space */ + if (isspace(*s)) { + s++; + continue; + } + /* find delimeters */ + if (*s == ':') { + delims++; + s++; + continue; + } + /* check 00 hexadecimal value */ + if (s + 1 <= end) { + if (check_nibble(s[0]) && check_nibble(s[1])) { + values++; + } else { + goto format2; + } + s++; + } + s++; + } + goto end; + +format2: /* we expect "0x0, 0x0, 0x0" */ - while (str < end) { + s = str; + delims = values = 0; + while (s < end) { /* skip white space */ - if (isspace(*str)) { - str++; + if (isspace(*s)) { + s++; continue; } /* find delimeters */ - if (*str == ',') { - commas++; - str++; + if (*s == ',') { + delims++; + s++; continue; } /* find 0x[0-9] values */ - if (*str == '0' && str + 2 <= end) { - if (str[1] == 'x' && str[2] >= '0' && str[2] <= 'f') { + if (*s == '0' && s + 2 <= end) { + if (s[1] == 'x' && check_nibble(s[2])) { + if (check_nibble(s[3])) + s++; values++; - str += 3; - } else { - str++; + s += 2; } } - str++; + s++; } +end: /* there should always be one less comma than value */ - if (values -1 != commas) + if (values - 1 != delims) return -EINVAL; return values; @@ -208,6 +349,32 @@ static int get_uuid(const char *str, unsigned char *uuid_le) if (tmp == NULL) return -ENOMEM; + if (strchr(tmp, ':') == NULL) + goto data2; + + s = strtok(tmp, ":"); + while (s != NULL) { + errno = 0; + val = strtoul(s, NULL, 16); + if ((errno == ERANGE && val == ULONG_MAX) + || (errno != 0 && val == 0) + || (val > UCHAR_MAX)) { + SNDERR("invalid value for uuid"); + ret = -EINVAL; + goto out; + } + + *(uuid_le + values) = (unsigned char)val; + + values++; + if (values >= 16) + break; + + s = strtok(NULL, ":"); + } + goto out; + +data2: s = strtok(tmp, ","); while (s != NULL) { @@ -216,12 +383,12 @@ static int get_uuid(const char *str, unsigned char *uuid_le) if ((errno == ERANGE && val == ULONG_MAX) || (errno != 0 && val == 0) || (val > UCHAR_MAX)) { - SNDERR("error: invalid value for uuid\n"); + SNDERR("invalid value for uuid"); ret = -EINVAL; goto out; } - *(uuid_le + values) = (unsigned char)val; + *(uuid_le + values) = (unsigned char)val; values++; if (values >= 16) @@ -231,7 +398,7 @@ static int get_uuid(const char *str, unsigned char *uuid_le) } if (values < 16) { - SNDERR("error: less than 16 integers for uuid\n"); + SNDERR("less than 16 integers for uuid"); ret = -EINVAL; } @@ -280,7 +447,7 @@ static int copy_data_hex(char *data, int off, const char *str, int width) return -ENOMEM; p += off; - s = strtok(tmp, ","); + s = strtok(tmp, ",:"); while (s != NULL) { ret = write_hex(p, s, width); @@ -289,7 +456,7 @@ static int copy_data_hex(char *data, int off, const char *str, int width) return ret; } - s = strtok(NULL, ","); + s = strtok(NULL, ",:"); p += width; } @@ -305,14 +472,14 @@ static int tplg_parse_data_hex(snd_config_t *cfg, struct tplg_elem *elem, int size, esize, off, num; int ret; - tplg_dbg(" data: %s\n", elem->id); + tplg_dbg(" data: %s", elem->id); if (snd_config_get_string(cfg, &value) < 0) return -EINVAL; num = get_hex_num(value); if (num <= 0) { - SNDERR("error: malformed hex variable list %s\n", value); + SNDERR("malformed hex variable list %s", value); return -EINVAL; } @@ -320,7 +487,7 @@ static int tplg_parse_data_hex(snd_config_t *cfg, struct tplg_elem *elem, priv = elem->data; if (size > TPLG_MAX_PRIV_SIZE) { - SNDERR("error: data too big %d\n", size); + SNDERR("data too big %d", size); return -EINVAL; } @@ -349,7 +516,7 @@ static int tplg_parse_data_hex(snd_config_t *cfg, struct tplg_elem *elem, /* get the token integer value from its id */ static int get_token_value(const char *token_id, - struct tplg_vendor_tokens *tokens) + struct tplg_vendor_tokens *tokens) { unsigned int i; @@ -358,7 +525,7 @@ static int get_token_value(const char *token_id, return tokens->token[i].value; } - SNDERR("error: cannot find token id '%s'\n", token_id); + SNDERR("cannot find token id '%s'", token_id); return -1; } @@ -405,7 +572,7 @@ static bool has_tuples(struct tplg_elem *elem) } /* get size of a tuple element from its type */ -static unsigned int get_tuple_size(int type) +unsigned int tplg_get_tuple_size(int type) { switch (type) { @@ -422,7 +589,8 @@ static unsigned int get_tuple_size(int type) /* Add a tuples object to the private buffer of its parent data element */ static int copy_tuples(struct tplg_elem *elem, - struct tplg_vendor_tuples *tuples, struct tplg_vendor_tokens *tokens) + struct tplg_vendor_tuples *tuples, + struct tplg_vendor_tokens *tokens) { struct snd_soc_tplg_private *priv = elem->data, *priv2; struct tplg_tuple_set *tuple_set; @@ -441,11 +609,11 @@ static int copy_tuples(struct tplg_elem *elem, for (i = 0; i < tuples->num_sets ; i++) { tuple_set = tuples->set[i]; set_size = sizeof(struct snd_soc_tplg_vendor_array) - + get_tuple_size(tuple_set->type) + + tplg_get_tuple_size(tuple_set->type) * tuple_set->num_tuples; size += set_size; if (size > TPLG_MAX_PRIV_SIZE) { - SNDERR("error: data too big %d\n", size); + SNDERR("data too big %d", size); return -EINVAL; } @@ -468,6 +636,7 @@ static int copy_tuples(struct tplg_elem *elem, elem->data = priv; array = (struct snd_soc_tplg_vendor_array *)(priv->data + off); + memset(array, 0, set_size); array->size = set_size; array->type = tuple_set->type; array->num_elems = tuple_set->num_tuples; @@ -521,20 +690,20 @@ static int build_tuples(snd_tplg_t *tplg, struct tplg_elem *elem) if (ref->type != SND_TPLG_TYPE_TUPLE) continue; - tplg_dbg("tuples '%s' used by data '%s'\n", ref->id, elem->id); + tplg_dbg("tuples '%s' used by data '%s'", ref->id, elem->id); if (!ref->elem) ref->elem = tplg_elem_lookup(&tplg->tuple_list, ref->id, SND_TPLG_TYPE_TUPLE, elem->index); tuples = ref->elem; if (!tuples) { - SNDERR("error: cannot find tuples %s\n", ref->id); + SNDERR("cannot find tuples %s", ref->id); return -EINVAL; } tokens = get_tokens(tplg, tuples); if (!tokens) { - SNDERR("error: cannot find token for %s\n", ref->id); + SNDERR("cannot find token for %s", ref->id); return -EINVAL; } @@ -547,34 +716,89 @@ static int build_tuples(snd_tplg_t *tplg, struct tplg_elem *elem) return 0; } +struct tuple_type { + unsigned int type; + const char *name; + unsigned int size; +}; + +static struct tuple_type tuple_types[] = { + { + .type = SND_SOC_TPLG_TUPLE_TYPE_UUID, + .name = "uuid", + .size = 4, + }, + { + .type = SND_SOC_TPLG_TUPLE_TYPE_STRING, + .name = "string", + .size = 6, + }, + { + .type = SND_SOC_TPLG_TUPLE_TYPE_BOOL, + .name = "bool", + .size = 4, + }, + { + .type = SND_SOC_TPLG_TUPLE_TYPE_BYTE, + .name = "byte", + .size = 4, + }, + { + .type = SND_SOC_TPLG_TUPLE_TYPE_SHORT, + .name = "short", + .size = 5, + }, + { + .type = SND_SOC_TPLG_TUPLE_TYPE_WORD, + .name = "word", + .size = 4 + }, +}; + +static int get_tuple_type(const char *name) +{ + struct tuple_type *t; + unsigned int i; + + /* skip initial index for sorting */ + while ((*name >= '0' && *name <= '9') || *name == '_') + name++; + for (i = 0; i < ARRAY_SIZE(tuple_types); i++) { + t = &tuple_types[i]; + if (strncasecmp(t->name, name, t->size) == 0) + return t->type; + } + return -EINVAL; +} + +static const char *get_tuple_type_name(unsigned int type) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(tuple_types); i++) + if (tuple_types[i].type == type) + return tuple_types[i].name; + return NULL; +} + static int parse_tuple_set(snd_config_t *cfg, - struct tplg_tuple_set **s) + struct tplg_tuple_set **s) { snd_config_iterator_t i, next; snd_config_t *n; const char *id, *value; struct tplg_tuple_set *set; - unsigned int type, num_tuples = 0; + unsigned int num_tuples = 0; struct tplg_tuple *tuple; - unsigned long int tuple_val; + unsigned int tuple_val; + int type, ival; snd_config_get_id(cfg, &id); - if (strncmp(id, "uuid", 4) == 0) - type = SND_SOC_TPLG_TUPLE_TYPE_UUID; - else if (strncmp(id, "string", 5) == 0) - type = SND_SOC_TPLG_TUPLE_TYPE_STRING; - else if (strncmp(id, "bool", 4) == 0) - type = SND_SOC_TPLG_TUPLE_TYPE_BOOL; - else if (strncmp(id, "byte", 4) == 0) - type = SND_SOC_TPLG_TUPLE_TYPE_BYTE; - else if (strncmp(id, "short", 5) == 0) - type = SND_SOC_TPLG_TUPLE_TYPE_SHORT; - else if (strncmp(id, "word", 4) == 0) - type = SND_SOC_TPLG_TUPLE_TYPE_WORD; - else { - SNDERR("error: invalid tuple type '%s'\n", id); - return -EINVAL; + type = get_tuple_type(id); + if (type < 0) { + SNDERR("invalid tuple type '%s'", id); + return type; } snd_config_for_each(i, next, cfg) @@ -582,7 +806,7 @@ static int parse_tuple_set(snd_config_t *cfg, if (!num_tuples) return 0; - tplg_dbg("\t %d %s tuples:\n", num_tuples, id); + tplg_dbg("\t %d %s tuples:", num_tuples, id); set = calloc(1, sizeof(*set) + num_tuples * sizeof(struct tplg_tuple)); if (!set) return -ENOMEM; @@ -597,41 +821,40 @@ static int parse_tuple_set(snd_config_t *cfg, if (snd_config_get_id(n, &id) < 0) continue; - /* get value */ - if (snd_config_get_string(n, &value) < 0) - continue; - tuple = &set->tuple[set->num_tuples]; snd_strlcpy(tuple->token, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); switch (type) { case SND_SOC_TPLG_TUPLE_TYPE_UUID: + if (snd_config_get_string(n, &value) < 0) + continue; if (get_uuid(value, tuple->uuid) < 0) goto err; break; case SND_SOC_TPLG_TUPLE_TYPE_STRING: + if (snd_config_get_string(n, &value) < 0) + continue; snd_strlcpy(tuple->string, value, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->string); + tplg_dbg("\t\t%s = %s", tuple->token, tuple->string); break; case SND_SOC_TPLG_TUPLE_TYPE_BOOL: - if (strcmp(value, "true") == 0) - tuple->value = 1; - tplg_dbg("\t\t%s = %d\n", tuple->token, tuple->value); + ival = snd_config_get_bool(n); + if (ival < 0) + continue; + tuple->value = ival; + tplg_dbg("\t\t%s = %d", tuple->token, tuple->value); break; case SND_SOC_TPLG_TUPLE_TYPE_BYTE: case SND_SOC_TPLG_TUPLE_TYPE_SHORT: case SND_SOC_TPLG_TUPLE_TYPE_WORD: - errno = 0; - /* no support for negative value */ - tuple_val = strtoul(value, NULL, 0); - if ((errno == ERANGE && tuple_val == ULONG_MAX) - || (errno != 0 && tuple_val == 0)) { - SNDERR("error: tuple %s:strtoul fail\n", id); + ival = tplg_get_unsigned(n, &tuple_val, 0); + if (ival < 0) { + SNDERR("tuple %s: %s", id, snd_strerror(ival)); goto err; } @@ -641,12 +864,12 @@ static int parse_tuple_set(snd_config_t *cfg, && tuple_val > USHRT_MAX) || (type == SND_SOC_TPLG_TUPLE_TYPE_BYTE && tuple_val > UCHAR_MAX)) { - SNDERR("error: tuple %s: invalid value\n", id); + SNDERR("tuple %s: invalid value", id); goto err; } - tuple->value = (unsigned int) tuple_val; - tplg_dbg("\t\t%s = 0x%x\n", tuple->token, tuple->value); + tuple->value = tuple_val; + tplg_dbg("\t\t%s = 0x%x", tuple->token, tuple->value); break; default: @@ -664,8 +887,86 @@ err: return -EINVAL; } +/* save tuple set */ +static int tplg_save_tuple_set(struct tplg_vendor_tuples *tuples, + unsigned int set_index, + char **dst, const char *pfx) +{ + struct tplg_tuple_set *set; + struct tplg_tuple *tuple; + const char *s, *fmt; + char buf[32]; + unsigned int i; + int err; + + set = tuples->set[set_index]; + if (set->num_tuples == 0) + return 0; + s = get_tuple_type_name(set->type); + if (s == NULL) + return -EINVAL; + if (tuples->num_sets < 10) + fmt = "%u_"; + else if (tuples->num_sets < 100) + fmt = "%02u_"; + else if (tuples->num_sets < 1000) + fmt = "%03u_"; + else + return -EINVAL; + if (set->num_tuples > 1) { + snprintf(buf, sizeof(buf), "tuples.%s%%s {\n", fmt); + err = tplg_save_printf(dst, NULL, buf, set_index, s); + if (err < 0) + return err; + } + for (i = 0; i < set->num_tuples; i++) { + tuple = &set->tuple[i]; + if (set->num_tuples == 1) { + snprintf(buf, sizeof(buf), "tuples.%s%%s.'%%s' ", fmt); + err = tplg_save_printf(dst, NULL, buf, + set_index, s, tuple->token); + } else { + err = tplg_save_printf(dst, pfx, "\t'%s' ", + tuple->token); + } + switch (set->type) { + case SND_SOC_TPLG_TUPLE_TYPE_UUID: + err = tplg_save_printf(dst, NULL, "'" UUID_FORMAT "'\n", + tuple->uuid[0], tuple->uuid[1], + tuple->uuid[2], tuple->uuid[3], + tuple->uuid[4], tuple->uuid[5], + tuple->uuid[6], tuple->uuid[7], + tuple->uuid[8], tuple->uuid[9], + tuple->uuid[10], tuple->uuid[11], + tuple->uuid[12], tuple->uuid[13], + tuple->uuid[14], tuple->uuid[15]); + break; + case SND_SOC_TPLG_TUPLE_TYPE_STRING: + err = tplg_save_printf(dst, NULL, "'%s'\n", + tuple->string); + break; + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + case SND_SOC_TPLG_TUPLE_TYPE_BYTE: + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + err = tplg_save_printf(dst, NULL, "%u\n", tuple->value); + break; + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + tplg_nice_value_format(buf, sizeof(buf), tuple->value); + err = tplg_save_printf(dst, NULL, "%s\n", buf); + break; + default: + return -EINVAL; + } + if (err < 0) + return err; + } + if (set->num_tuples > 1) + return tplg_save_printf(dst, pfx, "}\n"); + return 0; +} + static int parse_tuple_sets(snd_config_t *cfg, - struct tplg_vendor_tuples *tuples) + struct tplg_vendor_tuples *tuples) { snd_config_iterator_t i, next; snd_config_t *n; @@ -675,7 +976,7 @@ static int parse_tuple_sets(snd_config_t *cfg, if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_id(cfg, &id) >= 0) - SNDERR("error: compound type expected for %s", id); + SNDERR("compound type expected for %s", id); return -EINVAL; } @@ -693,8 +994,8 @@ static int parse_tuple_sets(snd_config_t *cfg, snd_config_for_each(i, next, cfg) { n = snd_config_iterator_entry(i); if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected for %s, is %d", - id, snd_config_get_type(n)); + SNDERR("compound type expected for %s, is %d", + id, snd_config_get_type(n)); return -EINVAL; } @@ -710,100 +1011,37 @@ static int parse_tuple_sets(snd_config_t *cfg, return 0; } -/* Parse tuples references for a data element, either a single tuples section - * or a list of tuples sections. - */ -static int parse_tuples_refs(snd_config_t *cfg, - struct tplg_elem *elem) -{ - snd_config_type_t type; - snd_config_iterator_t i, next; - snd_config_t *n; - const char *val = NULL; - - type = snd_config_get_type(cfg); - - /* refer to a single tuples section */ - if (type == SND_CONFIG_TYPE_STRING) { - if (snd_config_get_string(cfg, &val) < 0) - return -EINVAL; - tplg_dbg("\ttuples: %s\n", val); - return tplg_ref_add(elem, SND_TPLG_TYPE_TUPLE, val); - } - - if (type != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected for %s", elem->id); - return -EINVAL; - } - - /* refer to a list of data sections */ - snd_config_for_each(i, next, cfg) { - const char *val; - - n = snd_config_iterator_entry(i); - if (snd_config_get_string(n, &val) < 0) - continue; - - tplg_dbg("\ttuples: %s\n", val); - tplg_ref_add(elem, SND_TPLG_TYPE_TUPLE, val); - } - - return 0; -} - -/* Parse private data references for the element, either a single data section - * or a list of data sections. - */ -int tplg_parse_data_refs(snd_config_t *cfg, - struct tplg_elem *elem) +/* save tuple sets */ +int tplg_save_tuple_sets(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) { - snd_config_type_t type; - snd_config_iterator_t i, next; - snd_config_t *n; - const char *val = NULL; - - type = snd_config_get_type(cfg); - - /* refer to a single data section */ - if (type == SND_CONFIG_TYPE_STRING) { - if (snd_config_get_string(cfg, &val) < 0) - return -EINVAL; - - tplg_dbg("\tdata: %s\n", val); - return tplg_ref_add(elem, SND_TPLG_TYPE_DATA, val); - } - - if (type != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected for %s", elem->id); - return -EINVAL; - } - - /* refer to a list of data sections */ - snd_config_for_each(i, next, cfg) { - const char *val; - - n = snd_config_iterator_entry(i); - if (snd_config_get_string(n, &val) < 0) - continue; + struct tplg_vendor_tuples *tuples = elem->tuples; + unsigned int i; + int err = 0; - tplg_dbg("\tdata: %s\n", val); - tplg_ref_add(elem, SND_TPLG_TYPE_DATA, val); + for (i = 0; i < tuples->num_sets; i++) { + err = tplg_save_printf(dst, pfx, ""); + if (err < 0) + break; + err = tplg_save_tuple_set(tuples, i, dst, pfx); + if (err < 0) + break; } - - return 0; + return err; } /* Parse vendor tokens */ int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { snd_config_iterator_t i, next; snd_config_t *n; - const char *id, *value; + const char *id; struct tplg_elem *elem; struct tplg_vendor_tokens *tokens; - int num_tokens = 0; + int num_tokens = 0, value; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_TOKEN); if (!elem) @@ -816,7 +1054,7 @@ int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, if (!num_tokens) return 0; - tplg_dbg(" Vendor tokens: %s, %d tokens\n", elem->id, num_tokens); + tplg_dbg(" Vendor tokens: %s, %d tokens", elem->id, num_tokens); tokens = calloc(1, sizeof(*tokens) + num_tokens * sizeof(struct tplg_token)); @@ -830,13 +1068,13 @@ int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, if (snd_config_get_id(n, &id) < 0) continue; - if (snd_config_get_string(n, &value) < 0) + if (tplg_get_integer(n, &value, 0)) continue; snd_strlcpy(tokens->token[tokens->num_tokens].id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tokens->token[tokens->num_tokens].value = atoi(value); - tplg_dbg("\t\t %s : %d\n", tokens->token[tokens->num_tokens].id, + tokens->token[tokens->num_tokens].value = value; + tplg_dbg("\t\t %s : %d", tokens->token[tokens->num_tokens].id, tokens->token[tokens->num_tokens].value); tokens->num_tokens++; } @@ -844,10 +1082,35 @@ int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, return 0; } +/* save vendor tokens */ +int tplg_save_tokens(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct tplg_vendor_tokens *tokens = elem->tokens; + unsigned int i; + int err; + + if (!tokens || tokens->num_tokens == 0) + return 0; + + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err < 0) + return err; + for (i = 0; err >= 0 && i < tokens->num_tokens; i++) + err = tplg_save_printf(dst, pfx, "\t'%s' %u\n", + tokens->token[i].id, + tokens->token[i].value); + err = tplg_save_printf(dst, pfx, "}\n"); + if (err < 0) + return err; + return 0; +} + /* Parse vendor tuples. */ int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { snd_config_iterator_t i, next; snd_config_t *n; @@ -860,7 +1123,7 @@ int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, if (!elem) return -ENOMEM; - tplg_dbg(" Vendor Tuples: %s\n", elem->id); + tplg_dbg(" Vendor Tuples: %s", elem->id); tuples = calloc(1, sizeof(*tuples)); if (!tuples) @@ -877,7 +1140,7 @@ int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, if (snd_config_get_string(n, &value) < 0) return -EINVAL; tplg_ref_add(elem, SND_TPLG_TYPE_TOKEN, value); - tplg_dbg("\t refer to vendor tokens: %s\n", value); + tplg_dbg("\t refer to vendor tokens: %s", value); } if (strcmp(id, "tuples") == 0) { @@ -890,6 +1153,29 @@ int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, return 0; } +/* save vendor tuples */ +int tplg_save_tuples(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + char pfx2[16]; + int err; + + if (!elem->tuples) + return 0; + + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_TOKEN, + "tokens", dst, pfx2); + if (err >= 0) + err = tplg_save_tuple_sets(tplg, elem, dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return 0; +} + /* Free handler of tuples */ void tplg_free_tuples(void *obj) { @@ -908,7 +1194,7 @@ void tplg_free_tuples(void *obj) /* Parse manifest's data references */ int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_manifest *manifest; struct tplg_elem *elem; @@ -918,7 +1204,7 @@ int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, int err; if (!list_empty(&tplg->manifest_list)) { - SNDERR("error: already has manifest data\n"); + SNDERR("already has manifest data"); return -EINVAL; } @@ -929,7 +1215,7 @@ int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, manifest = elem->manifest; manifest->size = elem->size; - tplg_dbg(" Manifest: %s\n", elem->id); + tplg_dbg(" Manifest: %s", elem->id); snd_config_for_each(i, next, cfg) { n = snd_config_iterator_entry(i); @@ -944,7 +1230,7 @@ int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -954,6 +1240,54 @@ int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, return 0; } +/* save manifest data */ +int tplg_save_manifest_data(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, char **dst, + const char *pfx) +{ + struct list_head *pos; + struct tplg_ref *ref; + int err, index, count; + + /* for each ref in this manifest elem */ + count = 0; + list_for_each(pos, &elem->ref_list) { + ref = list_entry(pos, struct tplg_ref, list); + if (ref->type != SND_TPLG_TYPE_DATA) + continue; + count++; + } + if (count == 0) + return tplg_save_printf(dst, NULL, + "'%s'.comment 'empty'\n", elem->id); + if (count > 1) { + err = tplg_save_printf(dst, NULL, "'%s'.data [\n", elem->id); + if (err < 0) + return err; + } + index = 0; + list_for_each(pos, &elem->ref_list) { + ref = list_entry(pos, struct tplg_ref, list); + if (ref->type != SND_TPLG_TYPE_DATA) + continue; + if (count == 1) { + err = tplg_save_printf(dst, NULL, "'%s'.data.%u '%s'\n", + elem->id, index, ref->id); + } else { + err = tplg_save_printf(dst, pfx, "\t'%s'\n", ref->id); + if (err < 0) + return err; + } + index++; + } + if (count > 1) { + err = tplg_save_printf(dst, pfx, "]\n"); + if (err < 0) + return err; + } + return 0; +} + /* merge private data of manifest */ int tplg_build_manifest_data(snd_tplg_t *tplg) { @@ -1008,12 +1342,12 @@ int tplg_build_manifest_data(snd_tplg_t *tplg) * words, tuples. */ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { snd_config_iterator_t i, next; snd_config_t *n; - const char *id, *val = NULL; - int err = 0; + const char *id; + int err = 0, ival; struct tplg_elem *elem; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_DATA); @@ -1030,7 +1364,7 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "file") == 0) { err = tplg_parse_data_file(n, elem); if (err < 0) { - SNDERR("error: failed to parse data file\n"); + SNDERR("failed to parse data file"); return err; } continue; @@ -1039,7 +1373,7 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "bytes") == 0) { err = tplg_parse_data_hex(n, elem, 1); if (err < 0) { - SNDERR("error: failed to parse data bytes\n"); + SNDERR("failed to parse data bytes"); return err; } continue; @@ -1048,7 +1382,7 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "shorts") == 0) { err = tplg_parse_data_hex(n, elem, 2); if (err < 0) { - SNDERR("error: failed to parse data shorts\n"); + SNDERR("failed to parse data shorts"); return err; } continue; @@ -1057,25 +1391,25 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "words") == 0) { err = tplg_parse_data_hex(n, elem, 4); if (err < 0) { - SNDERR("error: failed to parse data words\n"); + SNDERR("failed to parse data words"); return err; } continue; } if (strcmp(id, "tuples") == 0) { - err = parse_tuples_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_TUPLE); if (err < 0) return err; continue; } if (strcmp(id, "type") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (tplg_get_integer(n, &ival, 0)) return -EINVAL; - elem->vendor_type = atoi(val); - tplg_dbg("\t%s: %d\n", id, elem->index); + elem->vendor_type = ival; + tplg_dbg("\t%s: %d", id, elem->index); continue; } } @@ -1083,6 +1417,81 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, return err; } +/* save data element */ +int tplg_save_data(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_private *priv = elem->data; + struct list_head *pos; + struct tplg_ref *ref; + char pfx2[16]; + unsigned int i, count; + int err; + + count = 0; + if (priv && priv->size > 0) + count++; + list_for_each(pos, &elem->ref_list) { + ref = list_entry(pos, struct tplg_ref, list); + if (ref->type == SND_TPLG_TYPE_TUPLE) + count++; + } + if (elem->vendor_type > 0) + count++; + + if (count > 1) { + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0) + err = tplg_save_printf(dst, NULL, ""); + } else { + err = tplg_save_printf(dst, NULL, "'%s'.", elem->id); + } + if (err >= 0 && priv && priv->size > 0) { + if (count > 1) { + err = tplg_save_printf(dst, pfx, ""); + if (err < 0) + return err; + } + if (priv->size > 8) { + err = tplg_save_printf(dst, NULL, "bytes\n"); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "\t'"); + } else { + err = tplg_save_printf(dst, NULL, "bytes '"); + } + if (err < 0) + return err; + for (i = 0; i < priv->size; i++) { + if (i > 0 && (i % 8) == 0) { + err = tplg_save_printf(dst, NULL, ":\n"); + if (err < 0) + return err; + err = tplg_save_printf(dst, pfx, "\t "); + if (err < 0) + return err; + } + err = tplg_save_printf(dst, NULL, "%s%02x", + (i % 8) == 0 ? "" : ":", + (unsigned char)priv->data[i]); + if (err < 0) + return err; + } + err = tplg_save_printf(dst, NULL, "'\n"); + } + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_TUPLE, + "tuples", dst, + count > 1 ? pfx2 : NULL); + if (err >= 0 && elem->vendor_type > 0) + err = tplg_save_printf(dst, pfx, "type %u", + elem->vendor_type); + if (err >= 0 && count > 1) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Find a referenced data element and copy its data to the parent * element's private data buffer. * An element can refer to multiple data sections. Data of these sections @@ -1099,12 +1508,12 @@ int tplg_copy_data(snd_tplg_t *tplg, struct tplg_elem *elem, ref_elem = tplg_elem_lookup(&tplg->pdata_list, ref->id, SND_TPLG_TYPE_DATA, elem->index); if (!ref_elem) { - SNDERR("error: cannot find data '%s' referenced by" - " element '%s'\n", ref->id, elem->id); + SNDERR("cannot find data '%s' referenced by" + " element '%s'", ref->id, elem->id); return -EINVAL; } - tplg_dbg("Data '%s' used by '%s'\n", ref->id, elem->id); + tplg_dbg("Data '%s' used by '%s'", ref->id, elem->id); /* overlook empty private data */ if (!ref_elem->data || !ref_elem->data->size) { ref->elem = ref_elem; @@ -1158,3 +1567,436 @@ int tplg_build_data(snd_tplg_t *tplg) return 0; } + +/* decode manifest data */ +int tplg_decode_manifest_data(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct snd_soc_tplg_manifest *m = bin; + struct tplg_elem *elem; + size_t off; + + if (hdr->index != 0) { + SNDERR("manifest - wrong index %d", hdr->index); + return -EINVAL; + } + + if (sizeof(*m) > size) { + SNDERR("manifest - wrong size %zd (minimal %zd)", + size, sizeof(*m)); + return -EINVAL; + } + + if (m->size != sizeof(*m)) { + SNDERR("manifest - wrong sructure size %d", m->size); + return -EINVAL; + } + + off = offsetof(struct snd_soc_tplg_manifest, priv); + if (off + m->priv.size > size) { + SNDERR("manifest - wrong private size %d", m->priv.size); + return -EINVAL; + } + + tplg->manifest = *m; + + bin += off; + size -= off; + pos += off; + + elem = tplg_elem_new_common(tplg, NULL, "manifest", + SND_TPLG_TYPE_MANIFEST); + if (!elem) + return -ENOMEM; + + tplg_log(tplg, 'D', pos, "manifest: private size %d", size); + return tplg_add_data(tplg, elem, bin, size); +} + +int tplg_add_token(snd_tplg_t *tplg, struct tplg_elem *parent, + unsigned int token, + char str_ref[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]) +{ + struct tplg_elem *elem; + struct tplg_token *t; + struct tplg_vendor_tokens *tokens; + unsigned int i; + size_t size; + + elem = tplg_elem_lookup(&tplg->token_list, parent->id, + SND_TPLG_TYPE_TOKEN, parent->index); + if (elem == NULL) { + elem = tplg_elem_new_common(tplg, NULL, parent->id, + SND_TPLG_TYPE_TOKEN); + if (!elem) + return -ENOMEM; + } + + tokens = elem->tokens; + if (tokens) { + for (i = 0; i < tokens->num_tokens; i++) { + t = &tokens->token[i]; + if (t->value == token) + goto found; + } + size = sizeof(*tokens) + + (tokens->num_tokens + 1) * sizeof(struct tplg_token); + tokens = realloc(tokens, size); + } else { + size = sizeof(*tokens) + 1 * sizeof(struct tplg_token); + tokens = calloc(1, size); + } + + if (!tokens) + return -ENOMEM; + + memset(&tokens->token[tokens->num_tokens], 0, sizeof(struct tplg_token)); + elem->tokens = tokens; + t = &tokens->token[tokens->num_tokens]; + tokens->num_tokens++; + snprintf(t->id, sizeof(t->id), "token%u", token); + t->value = token; +found: + snd_strlcpy(str_ref, t->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); + return 0; +} + +static int tplg_verify_tuple_set(snd_tplg_t *tplg, size_t pos, + const void *bin, size_t size) +{ + const struct snd_soc_tplg_vendor_array *va; + unsigned int j; + + va = bin; + if (size < sizeof(*va) || size < va->size) { + tplg_log(tplg, 'A', pos, "tuple set verify: wrong size %d", size); + return -EINVAL; + } + + switch (va->type) { + case SND_SOC_TPLG_TUPLE_TYPE_UUID: + case SND_SOC_TPLG_TUPLE_TYPE_STRING: + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + case SND_SOC_TPLG_TUPLE_TYPE_BYTE: + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + break; + default: + tplg_log(tplg, 'A', pos, "tuple set verify: unknown array type %d", va->type); + return -EINVAL; + } + + j = tplg_get_tuple_size(va->type) * va->num_elems; + if (j + sizeof(*va) != va->size) { + tplg_log(tplg, 'A', pos, "tuple set verify: wrong vendor array size %d " + "(expected %d for %d count %d)", + va->size, j + sizeof(*va), va->type, va->num_elems); + return -EINVAL; + } + + if (va->num_elems > 4096) { + tplg_log(tplg, 'A', pos, "tuple set verify: tuples overflow %d", va->num_elems); + return -EINVAL; + } + + return 0; +} + +static int tplg_decode_tuple_set(snd_tplg_t *tplg, + size_t pos, + struct tplg_elem *parent, + struct tplg_tuple_set **_set, + const void *bin, size_t size) +{ + const struct snd_soc_tplg_vendor_array *va; + struct tplg_tuple_set *set; + struct tplg_tuple *tuple; + unsigned int j; + int err; + + va = bin; + if (size < sizeof(*va) || size < va->size) { + SNDERR("tuples: wrong size %d", size); + return -EINVAL; + } + + switch (va->type) { + case SND_SOC_TPLG_TUPLE_TYPE_UUID: + case SND_SOC_TPLG_TUPLE_TYPE_STRING: + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + case SND_SOC_TPLG_TUPLE_TYPE_BYTE: + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + break; + default: + SNDERR("tuples: unknown array type %d", va->type); + return -EINVAL; + } + + j = tplg_get_tuple_size(va->type) * va->num_elems; + if (j + sizeof(*va) != va->size) { + SNDERR("tuples: wrong vendor array size %d " + "(expected %d for %d count %d)", + va->size, j + sizeof(*va), va->type, va->num_elems); + return -EINVAL; + } + + if (va->num_elems > 4096) { + SNDERR("tuples: tuples overflow %d", va->num_elems); + return -EINVAL; + } + + set = calloc(1, sizeof(*set) + va->num_elems * sizeof(struct tplg_tuple)); + if (!set) + return -ENOMEM; + + set->type = va->type; + set->num_tuples = va->num_elems; + + tplg_log(tplg, 'A', pos, "tuple set: type %d (%s) tuples %d size %d", set->type, + get_tuple_type_name(set->type), set->num_tuples, va->size); + for (j = 0; j < set->num_tuples; j++) { + tuple = &set->tuple[j]; + switch (va->type) { + case SND_SOC_TPLG_TUPLE_TYPE_UUID: + err = tplg_add_token(tplg, parent, va->uuid[j].token, + tuple->token); + if (err < 0) + goto retval; + memcpy(tuple->uuid, va->uuid[j].uuid, + sizeof(va->uuid[j].uuid)); + break; + case SND_SOC_TPLG_TUPLE_TYPE_STRING: + err = tplg_add_token(tplg, parent, va->string[j].token, + tuple->token); + if (err < 0) + goto retval; + snd_strlcpy(tuple->string, va->string[j].string, + sizeof(tuple->string)); + break; + case SND_SOC_TPLG_TUPLE_TYPE_BOOL: + case SND_SOC_TPLG_TUPLE_TYPE_BYTE: + case SND_SOC_TPLG_TUPLE_TYPE_WORD: + case SND_SOC_TPLG_TUPLE_TYPE_SHORT: + err = tplg_add_token(tplg, parent, va->value[j].token, + tuple->token); + if (err < 0) + goto retval; + tuple->value = va->value[j].value; + break; + } + } + + *_set = set; + return 0; + +retval: + free(set); + return err; +} + +/* verify tuples from the binary input */ +static int tplg_verify_tuples(snd_tplg_t *tplg, size_t pos, + const void *bin, size_t size) +{ + const struct snd_soc_tplg_vendor_array *va; + int err; + + if (size < sizeof(*va)) { + tplg_log(tplg, 'A', pos, "tuples: small size %d", size); + return -EINVAL; + } + +next: + va = bin; + if (size < sizeof(*va)) { + tplg_log(tplg, 'A', pos, "tuples: unexpected vendor arry size %d", size); + return -EINVAL; + } + + err = tplg_verify_tuple_set(tplg, pos, va, va->size); + if (err < 0) + return err; + + bin += va->size; + size -= va->size; + pos += va->size; + if (size > 0) + goto next; + + return 0; +} + +/* add tuples from the binary input */ +static int tplg_decode_tuples(snd_tplg_t *tplg, + size_t pos, + struct tplg_elem *parent, + struct tplg_vendor_tuples *tuples, + const void *bin, size_t size) +{ + const struct snd_soc_tplg_vendor_array *va; + struct tplg_tuple_set *set; + int err; + + if (size < sizeof(*va)) { + SNDERR("tuples: small size %d", size); + return -EINVAL; + } + +next: + va = bin; + if (size < sizeof(*va)) { + SNDERR("tuples: unexpected vendor arry size %d", size); + return -EINVAL; + } + + if (tuples->num_sets >= tuples->alloc_sets) { + SNDERR("tuples: index overflow (%d)", tuples->num_sets); + return -EINVAL; + } + + err = tplg_decode_tuple_set(tplg, pos, parent, &set, va, va->size); + if (err < 0) + return err; + tuples->set[tuples->num_sets++] = set; + + bin += va->size; + size -= va->size; + pos += va->size; + if (size > 0) + goto next; + + return 0; +} + +/* decode private data */ +int tplg_add_data(snd_tplg_t *tplg, + struct tplg_elem *parent, + const void *bin, size_t size) +{ + const struct snd_soc_tplg_private *tp; + const struct snd_soc_tplg_vendor_array *va; + struct tplg_elem *elem = NULL, *elem2 = NULL; + struct tplg_vendor_tuples *tuples = NULL; + char id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char suffix[16]; + size_t pos = 0, off; + int err, num_tuples = 0, block = 0; + + if (size == 0) + return 0; + + off = offsetof(struct snd_soc_tplg_private, array); + +next: + tp = bin; + if (off + size < tp->size) { + SNDERR("data: unexpected element size %d", size); + return -EINVAL; + } + + if (tplg_verify_tuples(tplg, pos, tp->array, tp->size) < 0) { + if (tuples) { + err = tplg_ref_add(elem, SND_TPLG_TYPE_TOKEN, parent->id); + if (err < 0) + return err; + err = tplg_ref_add(elem2, SND_TPLG_TYPE_TUPLE, id); + if (err < 0) + return err; + err = tplg_ref_add(parent, SND_TPLG_TYPE_DATA, id); + if (err < 0) + return err; + tuples = NULL; + } + tplg_log(tplg, 'A', pos, "add bytes: size %d", tp->size); + snprintf(suffix, sizeof(suffix), "data%u", block++); + err = tplg_add_data_bytes(tplg, parent, suffix, tp->array, tp->size); + } else { + if (!tuples) { + snprintf(id, sizeof(id), "%.30s:tuple%d", parent->id, (block++) & 0xffff); + elem = tplg_elem_new_common(tplg, NULL, id, SND_TPLG_TYPE_TUPLE); + if (!elem) + return -ENOMEM; + + elem2 = tplg_elem_new_common(tplg, NULL, id, SND_TPLG_TYPE_DATA); + if (!elem2) + return -ENOMEM; + + tuples = calloc(1, sizeof(*tuples)); + if (!tuples) + return -ENOMEM; + elem->tuples = tuples; + + tuples->alloc_sets = (size / sizeof(*va)) + 1; + tuples->set = calloc(1, tuples->alloc_sets * sizeof(void *)); + if (!tuples->set) { + tuples->alloc_sets = 0; + return -ENOMEM; + } + } + tplg_log(tplg, 'A', pos, "decode tuples: size %d", tp->size); + err = tplg_decode_tuples(tplg, pos, parent, tuples, tp->array, tp->size); + num_tuples++; + } + if (err < 0) + return err; + + bin += off + tp->size; + size -= off + tp->size; + pos += off + tp->size; + if (size > 0) + goto next; + + if (tuples && elem && elem2) { + err = tplg_ref_add(elem, SND_TPLG_TYPE_TOKEN, parent->id); + if (err < 0) + return err; + err = tplg_ref_add(elem2, SND_TPLG_TYPE_TUPLE, id); + if (err < 0) + return err; + err = tplg_ref_add(parent, SND_TPLG_TYPE_DATA, id); + if (err < 0) + return err; + } + + return 0; +} + +/* add private data - bytes */ +int tplg_add_data_bytes(snd_tplg_t *tplg, struct tplg_elem *parent, + const char *suffix, const void *bin, size_t size) +{ + struct snd_soc_tplg_private *priv; + struct tplg_elem *elem; + char id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + + if (suffix) + snprintf(id, sizeof(id), "%.30s:%.12s", parent->id, suffix); + else + snd_strlcpy(id, parent->id, sizeof(id)); + elem = tplg_elem_new_common(tplg, NULL, id, SND_TPLG_TYPE_DATA); + if (!elem) + return -ENOMEM; + + priv = malloc(sizeof(*priv) + size); + if (!priv) + return -ENOMEM; + memcpy(priv->data, bin, size); + priv->size = size; + elem->data = priv; + + return tplg_ref_add(parent, SND_TPLG_TYPE_DATA, id); +} + +/* decode data from the binary input */ +int tplg_decode_data(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + size_t pos ATTRIBUTE_UNUSED, + struct snd_soc_tplg_hdr *hdr ATTRIBUTE_UNUSED, + void *bin ATTRIBUTE_UNUSED, + size_t size ATTRIBUTE_UNUSED) +{ + SNDERR("data type not expected"); + return -EINVAL; +} diff --git a/src/topology/decoder.c b/src/topology/decoder.c new file mode 100644 index 0000000..66ebe5d --- /dev/null +++ b/src/topology/decoder.c @@ -0,0 +1,122 @@ +/* + Copyright (c) 2019 Red Hat Inc. + All rights reserved. + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + Authors: Jaroslav Kysela +*/ + +#include "list.h" +#include "tplg_local.h" + +int tplg_decode_template(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + snd_tplg_obj_template_t *t) +{ + int type; + + type = tplg_get_type(hdr->type); + tplg_log(tplg, 'D', pos, "template: asoc type %d library type %d", + hdr->type, type); + if (type < 0) + return type; + + memset(t, 0, sizeof(*t)); + t->type = type; + t->index = hdr->index; + t->version = hdr->version; + t->vendor_type = hdr->vendor_type; + tplg_log(tplg, 'D', pos, "template: index %d version %d vendor_type %d", + hdr->index, hdr->version, hdr->vendor_type); + return 0; +} + +int snd_tplg_decode(snd_tplg_t *tplg, void *bin, size_t size, int dflags) +{ + struct snd_soc_tplg_hdr *hdr; + struct tplg_table *tptr; + size_t pos; + void *b = bin; + unsigned int index; + int err; + + if (dflags != 0) + return -EINVAL; + if (tplg == NULL || bin == NULL) + return -EINVAL; + while (1) { + pos = b - bin; + if (size == pos) { + tplg_log(tplg, 'D', pos, "block: success (total %zd)", size); + return 0; + } + if (size - pos < sizeof(*hdr)) { + tplg_log(tplg, 'D', pos, "block: small size"); + SNDERR("incomplete header data to decode"); + return -EINVAL; + } + hdr = b; + if (hdr->magic != SND_SOC_TPLG_MAGIC) { + SNDERR("bad block magic %08x", hdr->magic); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "block: abi %d size %d payload size %d", + hdr->abi, hdr->size, hdr->payload_size); + if (hdr->abi != SND_SOC_TPLG_ABI_VERSION) { + SNDERR("unsupported ABI version %d", hdr->abi); + return -EINVAL; + } + if (hdr->size != sizeof(*hdr)) { + SNDERR("header size mismatch"); + return -EINVAL; + } + + if (size - pos < hdr->size + hdr->payload_size) { + SNDERR("incomplete payload data to decode"); + return -EINVAL; + } + + if (hdr->payload_size < 8) { + SNDERR("wrong payload size %d", hdr->payload_size); + return -EINVAL; + } + + /* first block must be manifest */ + if (b == bin) { + if (hdr->type != SND_SOC_TPLG_TYPE_MANIFEST) { + SNDERR("first block must be manifest (value %d)", hdr->type); + return -EINVAL; + } + err = snd_tplg_set_version(tplg, hdr->version); + if (err < 0) + return err; + } + + pos += hdr->size; + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + if (tptr->tsoc == (int)hdr->type) + break; + } + if (index >= tplg_table_items || tptr->decod == NULL) { + SNDERR("unknown block type %d", hdr->type); + return -EINVAL; + } + tplg_log(tplg, 'D', pos, "block: type %d - %s", hdr->type, tptr->name); + err = tptr->decod(tplg, pos, hdr, b + hdr->size, hdr->payload_size); + if (err < 0) + return err; + b += hdr->size + hdr->payload_size; + } +} diff --git a/src/topology/elem.c b/src/topology/elem.c index a9d1d85..cbd7f4b 100644 --- a/src/topology/elem.c +++ b/src/topology/elem.c @@ -20,6 +20,228 @@ #include "list.h" #include "tplg_local.h" +struct tplg_table tplg_table[] = { + { + .name = "manifest", + .id = "SectionManifest", + .loff = offsetof(snd_tplg_t, manifest_list), + .type = SND_TPLG_TYPE_MANIFEST, + .tsoc = SND_SOC_TPLG_TYPE_MANIFEST, + .size = sizeof(struct snd_soc_tplg_manifest), + .enew = 1, + .parse = tplg_parse_manifest_data, + .save = tplg_save_manifest_data, + .decod = tplg_decode_manifest_data, + }, + { + .name = "control mixer", + .id = "SectionControlMixer", + .loff = offsetof(snd_tplg_t, mixer_list), + .type = SND_TPLG_TYPE_MIXER, + .tsoc = SND_SOC_TPLG_TYPE_MIXER, + .size = sizeof(struct snd_soc_tplg_mixer_control), + .build = 1, + .enew = 1, + .parse = tplg_parse_control_mixer, + .save = tplg_save_control_mixer, + .decod = tplg_decode_control_mixer, + }, + { + .name = "control enum", + .id = "SectionControlEnum", + .loff = offsetof(snd_tplg_t, enum_list), + .type = SND_TPLG_TYPE_ENUM, + .tsoc = SND_SOC_TPLG_TYPE_ENUM, + .size = sizeof(struct snd_soc_tplg_enum_control), + .build = 1, + .enew = 1, + .parse = tplg_parse_control_enum, + .save = tplg_save_control_enum, + .decod = tplg_decode_control_enum, + }, + { + .name = "control extended (bytes)", + .id = "SectionControlBytes", + .loff = offsetof(snd_tplg_t, bytes_ext_list), + .type = SND_TPLG_TYPE_BYTES, + .tsoc = SND_SOC_TPLG_TYPE_BYTES, + .size = sizeof(struct snd_soc_tplg_bytes_control), + .build = 1, + .enew = 1, + .parse = tplg_parse_control_bytes, + .save = tplg_save_control_bytes, + .decod = tplg_decode_control_bytes, + }, + { + .name = "dapm widget", + .id = "SectionWidget", + .loff = offsetof(snd_tplg_t, widget_list), + .type = SND_TPLG_TYPE_DAPM_WIDGET, + .tsoc = SND_SOC_TPLG_TYPE_DAPM_WIDGET, + .size = sizeof(struct snd_soc_tplg_dapm_widget), + .build = 1, + .enew = 1, + .parse = tplg_parse_dapm_widget, + .save = tplg_save_dapm_widget, + .decod = tplg_decode_dapm_widget, + }, + { + .name = "pcm", + .id = "SectionPCM", + .loff = offsetof(snd_tplg_t, pcm_list), + .type = SND_TPLG_TYPE_PCM, + .tsoc = SND_SOC_TPLG_TYPE_PCM, + .size = sizeof(struct snd_soc_tplg_pcm), + .build = 1, + .enew = 1, + .parse = tplg_parse_pcm, + .save = tplg_save_pcm, + .decod = tplg_decode_pcm, + }, + { + .name = "physical dai", + .id = "SectionDAI", + .loff = offsetof(snd_tplg_t, dai_list), + .type = SND_TPLG_TYPE_DAI, + .tsoc = SND_SOC_TPLG_TYPE_DAI, + .size = sizeof(struct snd_soc_tplg_dai), + .build = 1, + .enew = 1, + .parse = tplg_parse_dai, + .save = tplg_save_dai, + .decod = tplg_decode_dai, + }, + { + .name = "be", + .id = "SectionBE", + .id2 = "SectionLink", + .loff = offsetof(snd_tplg_t, be_list), + .type = SND_TPLG_TYPE_BE, + .tsoc = SND_SOC_TPLG_TYPE_BACKEND_LINK, + .size = sizeof(struct snd_soc_tplg_link_config), + .build = 1, + .enew = 1, + .parse = tplg_parse_link, + .save = tplg_save_link, + .decod = tplg_decode_link, + }, + { + .name = "cc", + .id = "SectionCC", + .loff = offsetof(snd_tplg_t, cc_list), + .type = SND_TPLG_TYPE_CC, + .tsoc = SND_SOC_TPLG_TYPE_CODEC_LINK, + .size = sizeof(struct snd_soc_tplg_link_config), + .build = 1, + .enew = 1, + .parse = tplg_parse_cc, + .save = tplg_save_cc, + .decod = tplg_decode_cc, + }, + { + .name = "route (dapm graph)", + .id = "SectionGraph", + .loff = offsetof(snd_tplg_t, route_list), + .type = SND_TPLG_TYPE_DAPM_GRAPH, + .tsoc = SND_SOC_TPLG_TYPE_DAPM_GRAPH, + .build = 1, + .parse = tplg_parse_dapm_graph, + .gsave = tplg_save_dapm_graph, + .decod = tplg_decode_dapm_graph, + }, + { + .name = "private data", + .id = "SectionData", + .loff = offsetof(snd_tplg_t, pdata_list), + .type = SND_TPLG_TYPE_DATA, + .tsoc = SND_SOC_TPLG_TYPE_PDATA, + .build = 1, + .enew = 1, + .parse = tplg_parse_data, + .save = tplg_save_data, + .decod = tplg_decode_data, + }, + { + .name = "text", + .id = "SectionText", + .loff = offsetof(snd_tplg_t, text_list), + .type = SND_TPLG_TYPE_TEXT, + .size = sizeof(struct tplg_texts), + .enew = 1, + .parse = tplg_parse_text, + .save = tplg_save_text, + }, + { + .name = "tlv", + .id = "SectionTLV", + .loff = offsetof(snd_tplg_t, tlv_list), + .type = SND_TPLG_TYPE_TLV, + .size = sizeof(struct snd_soc_tplg_ctl_tlv), + .enew = 1, + .parse = tplg_parse_tlv, + .save = tplg_save_tlv, + }, + { + .name = "stream config", + .loff = offsetof(snd_tplg_t, pcm_config_list), + .type = SND_TPLG_TYPE_STREAM_CONFIG, + .size = sizeof(struct snd_soc_tplg_stream), + .enew = 1, + }, + { + .name = "stream capabilities", + .id = "SectionPCMCapabilities", + .loff = offsetof(snd_tplg_t, pcm_caps_list), + .type = SND_TPLG_TYPE_STREAM_CAPS, + .size = sizeof(struct snd_soc_tplg_stream_caps), + .enew = 1, + .parse = tplg_parse_stream_caps, + .save = tplg_save_stream_caps, + }, + { + .name = "token", + .id = "SectionVendorTokens", + .loff = offsetof(snd_tplg_t, token_list), + .type = SND_TPLG_TYPE_TOKEN, + .enew = 1, + .parse = tplg_parse_tokens, + .save = tplg_save_tokens, + }, + { + .name = "tuple", + .id = "SectionVendorTuples", + .loff = offsetof(snd_tplg_t, tuple_list), + .type = SND_TPLG_TYPE_TUPLE, + .free = tplg_free_tuples, + .enew = 1, + .parse = tplg_parse_tuples, + .save = tplg_save_tuples, + }, + { + .name = "hw config", + .id = "SectionHWConfig", + .loff = offsetof(snd_tplg_t, hw_cfg_list), + .type = SND_TPLG_TYPE_HW_CONFIG, + .size = sizeof(struct snd_soc_tplg_hw_config), + .enew = 1, + .parse = tplg_parse_hw_config, + .save = tplg_save_hw_config, + } +}; + +unsigned int tplg_table_items = ARRAY_SIZE(tplg_table); + +int tplg_get_type(int asoc_type) +{ + unsigned int index; + + for (index = 0; index < tplg_table_items; index++) + if (tplg_table[index].tsoc == asoc_type) + return tplg_table[index].type; + SNDERR("uknown asoc type %d", asoc_type); + return -EINVAL; +} + int tplg_ref_add(struct tplg_elem *elem, int type, const char* id) { struct tplg_ref *ref; @@ -79,6 +301,8 @@ struct tplg_elem *tplg_elem_new(void) void tplg_elem_free(struct tplg_elem *elem) { + list_del(&elem->list); + tplg_ref_free_list(&elem->ref_list); /* free struct snd_tplg_ object, @@ -101,13 +325,12 @@ void tplg_elem_free_list(struct list_head *base) list_for_each_safe(pos, npos, base) { elem = list_entry(pos, struct tplg_elem, list); - list_del(&elem->list); tplg_elem_free(elem); } } struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id, - unsigned int type, int index) + unsigned int type, int index) { struct list_head *pos; struct tplg_elem *elem; @@ -131,8 +354,38 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id, return NULL; } -/* insert a new element into list in the ascending order of index value*/ -static void tplg_elem_insert(struct tplg_elem *elem_p, struct list_head *list) +/* find an element by type */ +struct tplg_elem *tplg_elem_type_lookup(snd_tplg_t *tplg, + enum snd_tplg_type type) +{ + struct tplg_table *tptr; + struct list_head *pos, *list; + struct tplg_elem *elem; + unsigned int index; + + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + if (!tptr->enew) + continue; + if ((int)type != tptr->type) + continue; + break; + } + if (index >= tplg_table_items) + return NULL; + + list = (struct list_head *)((void *)tplg + tptr->loff); + + /* return only first element */ + list_for_each(pos, list) { + elem = list_entry(pos, struct tplg_elem, list); + return elem; + } + return NULL; +} + +/* insert a new element into list in the ascending order of index value */ +void tplg_elem_insert(struct tplg_elem *elem_p, struct list_head *list) { struct list_head *pos, *p = &(elem_p->list); struct tplg_elem *elem; @@ -142,19 +395,22 @@ static void tplg_elem_insert(struct tplg_elem *elem_p, struct list_head *list) if (elem_p->index < elem->index) break; } - p->prev = pos->prev; - pos->prev->next = p; - pos->prev = p; - p->next = pos; + /* insert item before pos */ + list_insert(p, pos->prev, pos); } /* create a new common element and object */ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, - snd_config_t *cfg, const char *name, enum snd_tplg_type type) + snd_config_t *cfg, + const char *name, + enum snd_tplg_type type) { + struct tplg_table *tptr; struct tplg_elem *elem; - const char *id, *val = NULL; + struct list_head *list; + const char *id; int obj_size = 0; + unsigned index; void *obj; snd_config_iterator_t i, next; snd_config_t *n; @@ -178,89 +434,38 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, if (snd_config_get_id(n, &id)) continue; if (strcmp(id, "index") == 0) { - if (snd_config_get_string(n, &val) < 0) { + if (tplg_get_integer(n, &elem->index, 0)) { + free(elem); + return NULL; + } + if (elem->index < 0) { free(elem); return NULL; } - elem->index = atoi(val); } } } else if (name != NULL) snd_strlcpy(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - switch (type) { - case SND_TPLG_TYPE_DATA: - tplg_elem_insert(elem, &tplg->pdata_list); - break; - case SND_TPLG_TYPE_MANIFEST: - tplg_elem_insert(elem, &tplg->manifest_list); - obj_size = sizeof(struct snd_soc_tplg_manifest); - break; - case SND_TPLG_TYPE_TEXT: - tplg_elem_insert(elem, &tplg->text_list); - obj_size = sizeof(struct tplg_texts); - break; - case SND_TPLG_TYPE_TLV: - tplg_elem_insert(elem, &tplg->tlv_list); - elem->size = sizeof(struct snd_soc_tplg_ctl_tlv); + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + if (!tptr->enew) + continue; + if ((int)type != tptr->type) + continue; break; - case SND_TPLG_TYPE_BYTES: - tplg_elem_insert(elem, &tplg->bytes_ext_list); - obj_size = sizeof(struct snd_soc_tplg_bytes_control); - break; - case SND_TPLG_TYPE_ENUM: - tplg_elem_insert(elem, &tplg->enum_list); - obj_size = sizeof(struct snd_soc_tplg_enum_control); - break; - case SND_TPLG_TYPE_MIXER: - tplg_elem_insert(elem, &tplg->mixer_list); - obj_size = sizeof(struct snd_soc_tplg_mixer_control); - break; - case SND_TPLG_TYPE_DAPM_WIDGET: - tplg_elem_insert(elem, &tplg->widget_list); - obj_size = sizeof(struct snd_soc_tplg_dapm_widget); - break; - case SND_TPLG_TYPE_STREAM_CONFIG: - tplg_elem_insert(elem, &tplg->pcm_config_list); - obj_size = sizeof(struct snd_soc_tplg_stream); - break; - case SND_TPLG_TYPE_STREAM_CAPS: - tplg_elem_insert(elem, &tplg->pcm_caps_list); - obj_size = sizeof(struct snd_soc_tplg_stream_caps); - break; - case SND_TPLG_TYPE_PCM: - tplg_elem_insert(elem, &tplg->pcm_list); - obj_size = sizeof(struct snd_soc_tplg_pcm); - break; - case SND_TPLG_TYPE_DAI: - tplg_elem_insert(elem, &tplg->dai_list); - obj_size = sizeof(struct snd_soc_tplg_dai); - break; - case SND_TPLG_TYPE_BE: - case SND_TPLG_TYPE_LINK: - tplg_elem_insert(elem, &tplg->be_list); - obj_size = sizeof(struct snd_soc_tplg_link_config); - break; - case SND_TPLG_TYPE_CC: - tplg_elem_insert(elem, &tplg->cc_list); - obj_size = sizeof(struct snd_soc_tplg_link_config); - break; - case SND_TPLG_TYPE_TOKEN: - tplg_elem_insert(elem, &tplg->token_list); - break; - case SND_TPLG_TYPE_TUPLE: - tplg_elem_insert(elem, &tplg->tuple_list); - elem->free = tplg_free_tuples; - break; - case SND_TPLG_TYPE_HW_CONFIG: - tplg_elem_insert(elem, &tplg->hw_cfg_list); - obj_size = sizeof(struct snd_soc_tplg_hw_config); - break; - default: + } + if (index >= tplg_table_items) { free(elem); return NULL; } + list = (struct list_head *)((void *)tplg + tptr->loff); + tplg_elem_insert(elem, list); + obj_size = tptr->size; + elem->free = tptr->free; + elem->table = tptr; + /* create new object too if required */ if (obj_size > 0) { obj = calloc(1, obj_size); @@ -276,3 +481,31 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, elem->type = type; return elem; } + +struct tplg_alloc { + struct list_head list; + void *data[0]; +}; + +void *tplg_calloc(struct list_head *heap, size_t size) +{ + struct tplg_alloc *a; + + a = calloc(1, sizeof(*a) + size); + if (a == NULL) + return NULL; + list_add_tail(&a->list, heap); + return a->data; +} + +void tplg_free(struct list_head *heap) +{ + struct list_head *pos, *npos; + struct tplg_alloc *a; + + list_for_each_safe(pos, npos, heap) { + a = list_entry(pos, struct tplg_alloc, list); + list_del(&a->list); + free(a); + } +} diff --git a/src/topology/log.c b/src/topology/log.c new file mode 100644 index 0000000..1ca3652 --- /dev/null +++ b/src/topology/log.c @@ -0,0 +1,34 @@ +/* + Copyright (c) 2019 Red Hat Inc. + All rights reserved. + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + Authors: Jaroslav Kysela +*/ + +#include "list.h" +#include "tplg_local.h" + +/* verbose output detailing each object size and file position */ +void tplg_log_(snd_tplg_t *tplg, char type, size_t pos, const char *fmt, ...) +{ + va_list va; + + if (!tplg->verbose) + return; + + va_start(va, fmt); + fprintf(stdout, "%c0x%6.6zx/%6.6zd - ", type, pos, pos); + vfprintf(stdout, fmt, va); + va_end(va); + putc('\n', stdout); +} diff --git a/src/topology/ops.c b/src/topology/ops.c index 6f8dc1f..110eef5 100644 --- a/src/topology/ops.c +++ b/src/topology/ops.c @@ -42,21 +42,34 @@ static int lookup_ops(const char *c) } /* cant find string name in our table so we use its ID number */ - return atoi(c); + return strtol(c, NULL, 0); +} + +const char *tplg_ops_name(int type) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(control_map); i++) { + if (control_map[i].id == type) + return control_map[i].name; + } + + return NULL; } /* Parse Control operations. Ops can come from standard names above or * bespoke driver controls with numbers >= 256 */ -int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, - snd_config_t *cfg, void *private) +int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_t *cfg, + void *private) { snd_config_iterator_t i, next; snd_config_t *n; struct snd_soc_tplg_ctl_hdr *hdr = private; const char *id, *value; + int ival; - tplg_dbg("\tOps\n"); + tplg_dbg("\tOps"); hdr->size = sizeof(*hdr); snd_config_for_each(i, next, cfg) { @@ -68,34 +81,81 @@ int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, continue; /* get value - try strings then ints */ - if (snd_config_get_string(n, &value) < 0) - continue; + if (snd_config_get_type(n) == SND_CONFIG_TYPE_STRING) { + if (snd_config_get_string(n, &value) < 0) + continue; + ival = lookup_ops(value); + } else { + if (tplg_get_integer(n, &ival, 0)) + continue; + } if (strcmp(id, "info") == 0) - hdr->ops.info = lookup_ops(value); + hdr->ops.info = ival; else if (strcmp(id, "put") == 0) - hdr->ops.put = lookup_ops(value); + hdr->ops.put = ival; else if (strcmp(id, "get") == 0) - hdr->ops.get = lookup_ops(value); + hdr->ops.get = ival; - tplg_dbg("\t\t%s = %s\n", id, value); + tplg_dbg("\t\t%s = %d", id, ival); } return 0; } +/* save control operations */ +int tplg_save_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct snd_soc_tplg_ctl_hdr *hdr, char **dst, + const char *pfx) +{ + const char *s; + int err; + + if (hdr->ops.info + hdr->ops.get + hdr->ops.put == 0) + return 0; + err = tplg_save_printf(dst, pfx, "ops.0 {\n"); + if (err >= 0 && hdr->ops.info > 0) { + s = tplg_ops_name(hdr->ops.info); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\tinfo %u\n", + hdr->ops.info); + else + err = tplg_save_printf(dst, pfx, "\tinfo %s\n", s); + } + if (err >= 0 && hdr->ops.get > 0) { + s = tplg_ops_name(hdr->ops.get); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\tget %u\n", + hdr->ops.get); + else + err = tplg_save_printf(dst, pfx, "\tget %s\n", s); + } + if (err >= 0 && hdr->ops.put > 0) { + s = tplg_ops_name(hdr->ops.put); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\tput %u\n", + hdr->ops.put); + else + err = tplg_save_printf(dst, pfx, "\tput %s\n", s); + } + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse External Control operations. Ops can come from standard names above or * bespoke driver controls with numbers >= 256 */ int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, - snd_config_t *cfg, void *private) + snd_config_t *cfg, void *private) { snd_config_iterator_t i, next; snd_config_t *n; struct snd_soc_tplg_bytes_control *be = private; const char *id, *value; + int ival; - tplg_dbg("\tExt Ops\n"); + tplg_dbg("\tExt Ops"); snd_config_for_each(i, next, cfg) { @@ -106,18 +166,64 @@ int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, continue; /* get value - try strings then ints */ - if (snd_config_get_string(n, &value) < 0) - continue; + if (snd_config_get_type(n) == SND_CONFIG_TYPE_STRING) { + if (snd_config_get_string(n, &value) < 0) + continue; + ival = lookup_ops(value); + } else { + if (tplg_get_integer(n, &ival, 0)) + continue; + } if (strcmp(id, "info") == 0) - be->ext_ops.info = lookup_ops(value); + be->ext_ops.info = ival; else if (strcmp(id, "put") == 0) - be->ext_ops.put = lookup_ops(value); + be->ext_ops.put = ival; else if (strcmp(id, "get") == 0) - be->ext_ops.get = lookup_ops(value); + be->ext_ops.get = ival; - tplg_dbg("\t\t%s = %s\n", id, value); + tplg_dbg("\t\t%s = %s", id, value); } return 0; } + +/* save external control operations */ +int tplg_save_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct snd_soc_tplg_bytes_control *be, + char **dst, const char *pfx) +{ + const char *s; + int err; + + if (be->ext_ops.info + be->ext_ops.get + be->ext_ops.put == 0) + return 0; + err = tplg_save_printf(dst, pfx, "extops.0 {\n"); + if (err >= 0 && be->ext_ops.info > 0) { + s = tplg_ops_name(be->ext_ops.info); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\tinfo %u\n", + be->ext_ops.info); + else + err = tplg_save_printf(dst, pfx, "\tinfo %s\n", s); + } + if (err >= 0 && be->ext_ops.get > 0) { + s = tplg_ops_name(be->ext_ops.get); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\tget %u\n", + be->ext_ops.get); + else + err = tplg_save_printf(dst, pfx, "\tget %s\n", s); + } + if (err >= 0 && be->ext_ops.put > 0) { + s = tplg_ops_name(be->ext_ops.put); + if (s == NULL) + err = tplg_save_printf(dst, pfx, "\tput %u\n", + be->ext_ops.put); + else + err = tplg_save_printf(dst, pfx, "\tput %s\n", s); + } + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} diff --git a/src/topology/parser.c b/src/topology/parser.c index 5940692..436e484 100644 --- a/src/topology/parser.c +++ b/src/topology/parser.c @@ -22,11 +22,96 @@ #include "tplg_local.h" /* + * Get integer value + */ +int tplg_get_integer(snd_config_t *n, int *val, int base) +{ + const char *str; + long lval; + int err; + + switch (snd_config_get_type(n)) { + case SND_CONFIG_TYPE_INTEGER: + err = snd_config_get_integer(n, &lval); + if (err < 0) + return err; + if (lval < INT_MIN || lval > INT_MAX) + return -ERANGE; + *val = lval; + return err; + case SND_CONFIG_TYPE_STRING: + err = snd_config_get_string(n, &str); + if (err < 0) + return err; + errno = 0; + *val = strtol(str, NULL, base); + if (errno == ERANGE) + return -ERANGE; + if (errno && *val == 0) + return -EINVAL; + return 0; + default: + return -EINVAL; + } +} + +/* + * Get unsigned integer value + */ +int tplg_get_unsigned(snd_config_t *n, unsigned *val, int base) +{ + const char *str; + long lval; + long long llval; + unsigned long uval; + int err; + + switch (snd_config_get_type(n)) { + case SND_CONFIG_TYPE_INTEGER: + err = snd_config_get_integer(n, &lval); + if (err < 0) + return err; + if (lval < 0 && lval >= INT_MIN) + lval = UINT_MAX + lval + 1; + if (lval < 0 || lval > UINT_MAX) + return -ERANGE; + *val = lval; + return err; + case SND_CONFIG_TYPE_INTEGER64: + err = snd_config_get_integer64(n, &llval); + if (err < 0) + return err; + if (llval < 0 && llval >= INT_MIN) + llval = UINT_MAX + llval + 1; + if (llval < 0 || llval > UINT_MAX) + return -ERANGE; + *val = llval; + return err; + case SND_CONFIG_TYPE_STRING: + err = snd_config_get_string(n, &str); + if (err < 0) + return err; + errno = 0; + uval = strtoul(str, NULL, base); + if (errno == ERANGE && uval == ULONG_MAX) + return -ERANGE; + if (errno && uval == 0) + return -EINVAL; + if (uval > UINT_MAX) + return -ERANGE; + *val = uval; + return 0; + default: + return -EINVAL; + } +} + +/* * Parse compound */ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg, - int (*fcn)(snd_tplg_t *, snd_config_t *, void *), - void *private) + int (*fcn)(snd_tplg_t *, snd_config_t *, void *), + void *private) { const char *id; snd_config_iterator_t i, next; @@ -37,7 +122,7 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg, return -EINVAL; if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected for %s", id); + SNDERR("compound type expected for %s", id); return -EINVAL; } @@ -46,7 +131,7 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg, n = snd_config_iterator_entry(i); if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected for %s, is %d", + SNDERR("compound type expected for %s, is %d", id, snd_config_get_type(cfg)); return -EINVAL; } @@ -61,13 +146,16 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg, static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg) { + int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); snd_config_iterator_t i, next; snd_config_t *n; const char *id; + struct tplg_table *p; + unsigned int idx; int err; if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected at top level"); + SNDERR("compound type expected at top level"); return -EINVAL; } @@ -78,195 +166,55 @@ static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg) if (snd_config_get_id(n, &id) < 0) continue; - if (strcmp(id, "SectionTLV") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_tlv, - NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionControlMixer") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_control_mixer, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionControlEnum") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_control_enum, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionControlBytes") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_control_bytes, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionWidget") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_dapm_widget, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionPCMCapabilities") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_stream_caps, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionPCM") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_pcm, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionDAI") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_dai, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionHWConfig") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_hw_config, - NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionLink") == 0 - || strcmp(id, "SectionBE") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_link, - NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionCC") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_cc, - NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionGraph") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_dapm_graph, NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionText") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_text, - NULL); - if (err < 0) - return err; - continue; + parser = NULL; + for (idx = 0; idx < tplg_table_items; idx++) { + p = &tplg_table[idx]; + if (p->id && strcmp(id, p->id) == 0) { + parser = p->parse; + break; + } + if (p->id2 && strcmp(id, p->id2) == 0) { + parser = p->parse; + break; + } } - if (strcmp(id, "SectionData") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_data, - NULL); - if (err < 0) - return err; + if (parser == NULL) { + SNDERR("unknown section %s", id); continue; } - if (strcmp(id, "SectionVendorTokens") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_tokens, - NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionVendorTuples") == 0) { - err = tplg_parse_compound(tplg, n, tplg_parse_tuples, - NULL); - if (err < 0) - return err; - continue; - } - - if (strcmp(id, "SectionManifest") == 0) { - err = tplg_parse_compound(tplg, n, - tplg_parse_manifest_data, - NULL); - if (err < 0) - return err; - continue; - } - - SNDERR("error: unknown section %s\n", id); + err = tplg_parse_compound(tplg, n, parser, NULL); + if (err < 0) + return err; } return 0; } -static int tplg_load_config(const char *file, snd_config_t **cfg) +static int tplg_load_config(snd_tplg_t *tplg, snd_input_t *in) { - FILE *fp; - snd_input_t *in; snd_config_t *top; int ret; - fp = fopen(file, "r"); - if (fp == NULL) { - SNDERR("error: could not open configuration file %s", - file); - return -errno; - } - - ret = snd_input_stdio_attach(&in, fp, 1); - if (ret < 0) { - fclose(fp); - SNDERR("error: could not attach stdio %s", file); - return ret; - } ret = snd_config_top(&top); if (ret < 0) - goto err; + return ret; ret = snd_config_load(top, in); if (ret < 0) { - SNDERR("error: could not load configuration file %s", - file); - goto err_load; + SNDERR("could not load configuration"); + snd_config_delete(top); + return ret; } - ret = snd_input_close(in); + ret = tplg_parse_config(tplg, top); + snd_config_delete(top); if (ret < 0) { - in = NULL; - goto err_load; + SNDERR("failed to parse topology"); + return ret; } - *cfg = top; return 0; - -err_load: - snd_config_delete(top); -err: - if (in) - snd_input_close(in); - return ret; } static int tplg_build_integ(snd_tplg_t *tplg) @@ -312,50 +260,67 @@ static int tplg_build_integ(snd_tplg_t *tplg) return err; } -int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile, - const char *outfile) +int snd_tplg_load(snd_tplg_t *tplg, const char *buf, size_t size) { - snd_config_t *cfg = NULL; - int err = 0; - - tplg->out_fd = - open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - if (tplg->out_fd < 0) { - SNDERR("error: failed to open %s err %d\n", - outfile, -errno); - return -errno; - } + snd_input_t *in; + int err; - err = tplg_load_config(infile, &cfg); + err = snd_input_buffer_open(&in, buf, size); if (err < 0) { - SNDERR("error: failed to load topology file %s\n", - infile); - goto out_close; + SNDERR("could not create input buffer"); + return err; } - err = tplg_parse_config(tplg, cfg); - if (err < 0) { - SNDERR("error: failed to parse topology\n"); - goto out; - } + err = tplg_load_config(tplg, in); + snd_input_close(in); + return err; +} + +static int tplg_build(snd_tplg_t *tplg) +{ + int err; err = tplg_build_integ(tplg); if (err < 0) { - SNDERR("error: failed to check topology integrity\n"); - goto out; + SNDERR("failed to check topology integrity"); + return err; } err = tplg_write_data(tplg); if (err < 0) { - SNDERR("error: failed to write data %d\n", err); - goto out; + SNDERR("failed to write data %d", err); + return err; } + return 0; +} -out: - snd_config_delete(cfg); -out_close: - close(tplg->out_fd); - return err; +int snd_tplg_build_file(snd_tplg_t *tplg, + const char *infile, + const char *outfile) +{ + FILE *fp; + snd_input_t *in; + int err; + + fp = fopen(infile, "r"); + if (fp == NULL) { + SNDERR("could not open configuration file %s", infile); + return -errno; + } + + err = snd_input_stdio_attach(&in, fp, 1); + if (err < 0) { + fclose(fp); + SNDERR("could not attach stdio %s", infile); + return err; + } + + err = tplg_load_config(tplg, in); + snd_input_close(in); + if (err < 0) + return err; + + return snd_tplg_build(tplg, outfile); } int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) @@ -380,53 +345,72 @@ int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) case SND_TPLG_TYPE_CC: return tplg_add_link_object(tplg, t); default: - SNDERR("error: invalid object type %d\n", t->type); + SNDERR("invalid object type %d", t->type); return -EINVAL; }; } int snd_tplg_build(snd_tplg_t *tplg, const char *outfile) { - int err; + int fd, err; + ssize_t r; + + err = tplg_build(tplg); + if (err < 0) + return err; - tplg->out_fd = - open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - if (tplg->out_fd < 0) { - SNDERR("error: failed to open %s err %d\n", - outfile, -errno); + fd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) { + SNDERR("failed to open %s err %d", outfile, -errno); return -errno; } - - err = tplg_build_integ(tplg); - if (err < 0) { - SNDERR("error: failed to check topology integrity\n"); - goto out; + r = write(fd, tplg->bin, tplg->bin_size); + close(fd); + if (r < 0) { + err = -errno; + SNDERR("write error: %s", strerror(errno)); + return err; } - - err = tplg_write_data(tplg); - if (err < 0) { - SNDERR("error: failed to write data %d\n", err); - goto out; + if ((size_t)r != tplg->bin_size) { + SNDERR("partial write (%zd != %zd)", r, tplg->bin_size); + return -EIO; } + return 0; +} -out: - close(tplg->out_fd); - return err; +int snd_tplg_build_bin(snd_tplg_t *tplg, + void **bin, size_t *size) +{ + int err; + + err = tplg_build(tplg); + if (err < 0) + return err; + + *bin = tplg->bin; + *size = tplg->bin_size; + tplg->bin = NULL; + tplg->bin_size = tplg->bin_pos = 0; + return 0; } int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len) { + struct tplg_elem *elem; + + elem = tplg_elem_type_lookup(tplg, SND_TPLG_TYPE_MANIFEST); + if (elem == NULL) { + elem = tplg_elem_new_common(tplg, NULL, "manifest", + SND_TPLG_TYPE_MANIFEST); + if (!elem) + return -ENOMEM; + tplg->manifest.size = elem->size; + } + if (len <= 0) return 0; - tplg->manifest.priv.size = len; - - tplg->manifest_pdata = malloc(len); - if (!tplg->manifest_pdata) - return -ENOMEM; - - memcpy(tplg->manifest_pdata, data, len); - return 0; + return tplg_add_data_bytes(tplg, elem, NULL, data, len); } int snd_tplg_set_version(snd_tplg_t *tplg, unsigned int version) @@ -451,12 +435,12 @@ static bool is_little_endian(void) return false; } -snd_tplg_t *snd_tplg_new(void) +snd_tplg_t *snd_tplg_create(int flags) { snd_tplg_t *tplg; if (!is_little_endian()) { - SNDERR("error: cannot support big-endian machines\n"); + SNDERR("cannot support big-endian machines"); return NULL; } @@ -464,6 +448,9 @@ snd_tplg_t *snd_tplg_new(void) if (!tplg) return NULL; + tplg->verbose = !!(flags & SND_TPLG_CREATE_VERBOSE); + tplg->dapm_sort = (flags & SND_TPLG_CREATE_DAPM_NOSORT) == 0; + tplg->manifest.size = sizeof(struct snd_soc_tplg_manifest); INIT_LIST_HEAD(&tplg->tlv_list); @@ -488,10 +475,15 @@ snd_tplg_t *snd_tplg_new(void) return tplg; } +snd_tplg_t *snd_tplg_new(void) +{ + return snd_tplg_create(0); +} + void snd_tplg_free(snd_tplg_t *tplg) { - if (tplg->manifest_pdata) - free(tplg->manifest_pdata); + free(tplg->bin); + free(tplg->manifest_pdata); tplg_elem_free_list(&tplg->tlv_list); tplg_elem_free_list(&tplg->widget_list); @@ -514,3 +506,8 @@ void snd_tplg_free(snd_tplg_t *tplg) free(tplg); } + +const char *snd_tplg_version(void) +{ + return SND_LIB_VERSION_STR; +} diff --git a/src/topology/pcm.c b/src/topology/pcm.c index 553fd82..b15b950 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -63,11 +63,12 @@ struct tplg_elem *lookup_pcm_dai_stream(struct list_head *base, const char* id) /* copy referenced caps to the parent (pcm or be dai) */ static void copy_stream_caps(const char *id ATTRIBUTE_UNUSED, - struct snd_soc_tplg_stream_caps *caps, struct tplg_elem *ref_elem) + struct snd_soc_tplg_stream_caps *caps, + struct tplg_elem *ref_elem) { struct snd_soc_tplg_stream_caps *ref_caps = ref_elem->stream_caps; - tplg_dbg("Copy pcm caps (%ld bytes) from '%s' to '%s' \n", + tplg_dbg("Copy pcm caps (%ld bytes) from '%s' to '%s'", sizeof(*caps), ref_elem->id, id); *caps = *ref_caps; @@ -75,7 +76,8 @@ static void copy_stream_caps(const char *id ATTRIBUTE_UNUSED, /* find and copy the referenced stream caps */ static int tplg_build_stream_caps(snd_tplg_t *tplg, - const char *id, int index, struct snd_soc_tplg_stream_caps *caps) + const char *id, int index, + struct snd_soc_tplg_stream_caps *caps) { struct tplg_elem *ref_elem = NULL; unsigned int i; @@ -114,8 +116,8 @@ static int build_pcm(snd_tplg_t *tplg, struct tplg_elem *elem) return err; } if (!ref->elem) { - SNDERR("error: cannot find '%s' referenced by" - " PCM '%s'\n", ref->id, elem->id); + SNDERR("cannot find '%s' referenced by" + " PCM '%s'", ref->id, elem->id); return -EINVAL; } } @@ -135,7 +137,7 @@ int tplg_build_pcms(snd_tplg_t *tplg, unsigned int type) elem = list_entry(pos, struct tplg_elem, list); if (elem->type != type) { - SNDERR("error: invalid elem '%s'\n", elem->id); + SNDERR("invalid elem '%s'", elem->id); return -EINVAL; } @@ -194,7 +196,7 @@ int tplg_build_dais(snd_tplg_t *tplg, unsigned int type) elem = list_entry(pos, struct tplg_elem, list); if (elem->type != type) { - SNDERR("error: invalid elem '%s'\n", elem->id); + SNDERR("invalid elem '%s'", elem->id); return -EINVAL; } @@ -207,7 +209,8 @@ int tplg_build_dais(snd_tplg_t *tplg, unsigned int type) } static int tplg_build_stream_cfg(snd_tplg_t *tplg, - struct snd_soc_tplg_stream *stream, int num_streams, int index) + struct snd_soc_tplg_stream *stream, + int num_streams, int index) { struct snd_soc_tplg_stream *strm; struct tplg_elem *ref_elem; @@ -248,9 +251,9 @@ static int build_link(snd_tplg_t *tplg, struct tplg_elem *elem) ref->elem = tplg_elem_lookup(&tplg->hw_cfg_list, ref->id, SND_TPLG_TYPE_HW_CONFIG, elem->index); if (!ref->elem) { - SNDERR("error: cannot find HW config '%s'" - " referenced by link '%s'\n", - ref->id, elem->id); + SNDERR("cannot find HW config '%s'" + " referenced by link '%s'", + ref->id, elem->id); return -EINVAL; } @@ -264,6 +267,7 @@ static int build_link(snd_tplg_t *tplg, struct tplg_elem *elem) err = tplg_copy_data(tplg, elem, ref); if (err < 0) return err; + link = elem->link; /* realloc */ break; default: @@ -317,7 +321,7 @@ static int split_format(struct snd_soc_tplg_stream_caps *caps, char *str) while ((s != NULL) && (i < SND_SOC_TPLG_MAX_FORMATS)) { format = snd_pcm_format_value(s); if (format == SND_PCM_FORMAT_UNKNOWN) { - SNDERR("error: unsupported stream format %s\n", s); + SNDERR("unsupported stream format %s", s); return -EINVAL; } @@ -342,6 +346,13 @@ static int get_rate_value(const char* name) return SND_PCM_RATE_UNKNOWN; } +static const char *get_rate_name(int rate) +{ + if (rate >= 0 && rate <= SND_PCM_RATE_LAST) + return snd_pcm_rate_names[rate]; + return NULL; +} + static int split_rate(struct snd_soc_tplg_stream_caps *caps, char *str) { char *s = NULL; @@ -353,7 +364,7 @@ static int split_rate(struct snd_soc_tplg_stream_caps *caps, char *str) rate = get_rate_value(s); if (rate == SND_PCM_RATE_UNKNOWN) { - SNDERR("error: unsupported stream rate %s\n", s); + SNDERR("unsupported stream rate %s", s); return -EINVAL; } @@ -365,9 +376,28 @@ static int split_rate(struct snd_soc_tplg_stream_caps *caps, char *str) return 0; } +static int parse_unsigned(snd_config_t *n, unsigned int *dst) +{ + int ival; + + if (tplg_get_integer(n, &ival, 0) < 0) + return -EINVAL; + + *dst = ival; +#if TPLG_DEBUG + { + const char *id; + if (snd_config_get_id(n, &id) >= 0) + tplg_dbg("\t\t%s: %d", id, *dst); + } +#endif + return 0; +} + /* Parse pcm stream capabilities */ int tplg_parse_stream_caps(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) + snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_stream_caps *sc; struct tplg_elem *elem; @@ -385,7 +415,7 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, sc->size = elem->size; snd_strlcpy(sc->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg(" PCM Capabilities: %s\n", elem->id); + tplg_dbg(" PCM Capabilities: %s", elem->id); snd_config_for_each(i, next, cfg) { n = snd_config_iterator_entry(i); @@ -398,10 +428,10 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, if (id[0] == '#') continue; - if (snd_config_get_string(n, &val) < 0) - return -EINVAL; - if (strcmp(id, "formats") == 0) { + if (snd_config_get_string(n, &val) < 0) + return -EINVAL; + s = strdup(val); if (s == NULL) return -ENOMEM; @@ -412,11 +442,14 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, if (err < 0) return err; - tplg_dbg("\t\t%s: %s\n", id, val); + tplg_dbg("\t\t%s: %s", id, val); continue; } if (strcmp(id, "rates") == 0) { + if (snd_config_get_string(n, &val) < 0) + return -EINVAL; + s = strdup(val); if (!s) return -ENOMEM; @@ -427,73 +460,73 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, if (err < 0) return err; - tplg_dbg("\t\t%s: %s\n", id, val); + tplg_dbg("\t\t%s: %s", id, val); continue; } if (strcmp(id, "rate_min") == 0) { - sc->rate_min = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->rate_min); + if (parse_unsigned(n, &sc->rate_min)) + return -EINVAL; continue; } if (strcmp(id, "rate_max") == 0) { - sc->rate_max = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->rate_max); + if (parse_unsigned(n, &sc->rate_max)) + return -EINVAL; continue; } if (strcmp(id, "channels_min") == 0) { - sc->channels_min = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->channels_min); + if (parse_unsigned(n, &sc->channels_min)) + return -EINVAL; continue; } if (strcmp(id, "channels_max") == 0) { - sc->channels_max = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->channels_max); + if (parse_unsigned(n, &sc->channels_max)) + return -EINVAL; continue; } if (strcmp(id, "periods_min") == 0) { - sc->periods_min = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->periods_min); + if (parse_unsigned(n, &sc->periods_min)) + return -EINVAL; continue; } if (strcmp(id, "periods_max") == 0) { - sc->periods_max = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->periods_max); + if (parse_unsigned(n, &sc->periods_max)) + return -EINVAL; continue; } if (strcmp(id, "period_size_min") == 0) { - sc->period_size_min = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->period_size_min); + if (parse_unsigned(n, &sc->period_size_min)) + return -EINVAL; continue; } if (strcmp(id, "period_size_max") == 0) { - sc->period_size_max = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->period_size_max); + if (parse_unsigned(n, &sc->period_size_max)) + return -EINVAL; continue; } if (strcmp(id, "buffer_size_min") == 0) { - sc->buffer_size_min = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->buffer_size_min); + if (parse_unsigned(n, &sc->buffer_size_min)) + return -EINVAL; continue; } if (strcmp(id, "buffer_size_max") == 0) { - sc->buffer_size_max = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->buffer_size_max); + if (parse_unsigned(n, &sc->buffer_size_max)) + return -EINVAL; continue; } if (strcmp(id, "sig_bits") == 0) { - sc->sig_bits = atoi(val); - tplg_dbg("\t\t%s: %d\n", id, sc->sig_bits); + if (parse_unsigned(n, &sc->sig_bits)) + return -EINVAL; continue; } @@ -502,6 +535,80 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, return 0; } +/* save stream caps */ +int tplg_save_stream_caps(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_stream_caps *sc = elem->stream_caps; + const char *s; + unsigned int i; + int err, first; + + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && sc->formats) { + err = tplg_save_printf(dst, pfx, "\tformats '"); + first = 1; + for (i = 0; err >= 0 && i < SND_PCM_FORMAT_LAST; i++) { + if (sc->formats & (1ULL << i)) { + s = snd_pcm_format_name(i); + err = tplg_save_printf(dst, NULL, "%s%s", + !first ? ", " : "", s); + first = 0; + } + } + if (err >= 0) + err = tplg_save_printf(dst, NULL, "'\n"); + } + if (err >= 0 && sc->rates) { + err = tplg_save_printf(dst, pfx, "\trates '"); + first = 1; + for (i = 0; err >= 0 && i < SND_PCM_RATE_LAST; i++) { + if (sc->rates & (1ULL << i)) { + s = get_rate_name(i); + err = tplg_save_printf(dst, NULL, "%s%s", + !first ? ", " : "", s); + first = 0; + } + } + if (err >= 0) + err = tplg_save_printf(dst, NULL, "'\n"); + } + if (err >= 0 && sc->rate_min) + err = tplg_save_printf(dst, pfx, "\trate_min %u\n", + sc->rate_min); + if (err >= 0 && sc->rate_max) + err = tplg_save_printf(dst, pfx, "\trate_max %u\n", + sc->rate_max); + if (err >= 0 && sc->channels_min) + err = tplg_save_printf(dst, pfx, "\tchannels_min %u\n", + sc->channels_min); + if (err >= 0 && sc->channels_max) + err = tplg_save_printf(dst, pfx, "\tchannels_max %u\n", + sc->channels_max); + if (err >= 0 && sc->periods_min) + err = tplg_save_printf(dst, pfx, "\tperiods_min %u\n", + sc->periods_min); + if (err >= 0 && sc->periods_max) + err = tplg_save_printf(dst, pfx, "\tperiods_max %u\n", + sc->periods_max); + if (err >= 0 && sc->period_size_min) + err = tplg_save_printf(dst, pfx, "\tperiod_size_min %u\n", + sc->period_size_min); + if (err >= 0 && sc->period_size_max) + err = tplg_save_printf(dst, pfx, "\tperiod_size_max %u\n", + sc->period_size_max); + if (err >= 0 && sc->buffer_size_min) + err = tplg_save_printf(dst, pfx, "\tbuffer_size_min %u\n", + sc->buffer_size_min); + if (err >= 0 && sc->buffer_size_max) + err = tplg_save_printf(dst, pfx, "\tbuffer_size_max %u\n", + sc->buffer_size_max); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse the caps and config of a pcm stream */ static int tplg_parse_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_t *cfg, void *private) @@ -518,7 +625,7 @@ static int tplg_parse_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_get_id(cfg, &id); - tplg_dbg("\t%s:\n", id); + tplg_dbg("\t%s:", id); switch (elem->type) { case SND_TPLG_TYPE_PCM: @@ -565,7 +672,7 @@ static int tplg_parse_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_strlcpy(caps[stream].name, value, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg("\t\t%s\n\t\t\t%s\n", id, value); + tplg_dbg("\t\t%s\n\t\t\t%s", id, value); continue; } } @@ -573,6 +680,61 @@ static int tplg_parse_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED, return 0; } +/* Save the caps and config of a pcm stream */ +int tplg_save_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + static const char *stream_ids[2] = { + "playback", + "capture" + }; + static unsigned int stream_types[2] = { + SND_SOC_TPLG_STREAM_PLAYBACK, + SND_SOC_TPLG_STREAM_CAPTURE + }; + struct snd_soc_tplg_stream_caps *caps; + unsigned int streams[2], stream; + const char *s; + int err; + + switch (elem->type) { + case SND_TPLG_TYPE_PCM: + streams[0] = elem->pcm->playback; + streams[1] = elem->pcm->capture; + caps = elem->pcm->caps; + break; + case SND_TPLG_TYPE_DAI: + streams[0] = elem->dai->playback; + streams[1] = elem->dai->capture; + caps = elem->dai->caps; + break; + default: + return -EINVAL; + } + + for (stream = 0; stream < 2; stream++) { + if (streams[stream] == 0) + continue; + if (!caps) + continue; + s = caps[stream_types[stream]].name; + if (s[0] == '\0') + continue; + err = tplg_save_printf(dst, pfx, "pcm.%s {\n", stream_ids[stream]); + if (err < 0) + return err; + err = tplg_save_printf(dst, pfx, "\tcapabilities '%s'\n", s); + if (err < 0) + return err; + err = tplg_save_printf(dst, pfx, "}\n"); + if (err < 0) + return err; + } + + return 0; +} + /* Parse name and id of a front-end DAI (ie. cpu dai of a FE DAI link) */ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_t *cfg, void *private) @@ -581,11 +743,10 @@ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED, struct snd_soc_tplg_pcm *pcm = elem->pcm; snd_config_iterator_t i, next; snd_config_t *n; - const char *id, *value = NULL; - unsigned long int id_val; + const char *id; snd_config_get_id(cfg, &id); - tplg_dbg("\t\tFE DAI %s:\n", id); + tplg_dbg("\t\tFE DAI %s:", id); snd_strlcpy(pcm->dai_name, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); snd_config_for_each(i, next, cfg) { @@ -597,26 +758,31 @@ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED, continue; if (strcmp(id, "id") == 0) { - if (snd_config_get_string(n, &value) < 0) - continue; - errno = 0; - /* no support for negative value */ - id_val = strtoul(value, NULL, 0); - if ((errno == ERANGE && id_val == ULONG_MAX) - || (errno != 0 && id_val == 0) - || id_val > UINT_MAX) { - SNDERR("error: invalid fe dai ID\n"); + if (tplg_get_unsigned(n, &pcm->dai_id, 0)) { + SNDERR("invalid fe dai ID"); return -EINVAL; } - pcm->dai_id = (int) id_val; - tplg_dbg("\t\t\tindex: %d\n", pcm->dai_id); + tplg_dbg("\t\t\tindex: %d", pcm->dai_id); } } return 0; } +/* Save the caps and config of a pcm stream */ +int tplg_save_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_pcm *pcm = elem->pcm; + int err = 0; + + if (pcm->dai_id > 0) + err = tplg_save_printf(dst, pfx, "dai.0.id %u\n", pcm->dai_id); + return err; +} + /* parse a flag bit of the given mask */ static int parse_flag(snd_config_t *n, unsigned int mask_in, unsigned int *mask, unsigned int *flags) @@ -636,16 +802,42 @@ static int parse_flag(snd_config_t *n, unsigned int mask_in, return 0; } +static int save_flags(unsigned int flags, unsigned int mask, + char **dst, const char *pfx) +{ + static unsigned int flag_masks[3] = { + SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES, + SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS, + SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS, + }; + static const char *flag_ids[3] = { + "symmetric_rates", + "symmetric_channels", + "symmetric_sample_bits", + }; + unsigned int i; + int err = 0; + + for (i = 0; err >= 0 && i < ARRAY_SIZE(flag_masks); i++) { + if (mask & flag_masks[i]) { + unsigned int v = (flags & flag_masks[i]) ? 1 : 0; + err = tplg_save_printf(dst, pfx, "%s %u\n", + flag_ids[i], v); + } + } + return err; +} + /* Parse PCM (for front end DAI & DAI link) in text conf file */ -int tplg_parse_pcm(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) +int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_pcm *pcm; struct tplg_elem *elem; snd_config_iterator_t i, next; snd_config_t *n; - const char *id, *val = NULL; - int err; + const char *id; + int err, ival; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_PCM); if (!elem) @@ -655,7 +847,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg, pcm->size = elem->size; snd_strlcpy(pcm->pcm_name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg(" PCM: %s\n", elem->id); + tplg_dbg(" PCM: %s", elem->id); snd_config_for_each(i, next, cfg) { @@ -670,11 +862,8 @@ int tplg_parse_pcm(snd_tplg_t *tplg, continue; if (strcmp(id, "id") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &pcm->pcm_id)) return -EINVAL; - - pcm->pcm_id = atoi(val); - tplg_dbg("\t%s: %d\n", id, pcm->pcm_id); continue; } @@ -687,13 +876,13 @@ int tplg_parse_pcm(snd_tplg_t *tplg, } if (strcmp(id, "compress") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; - if (strcmp(val, "true") == 0) - pcm->compress = 1; + pcm->compress = ival; - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %d", id, ival); continue; } @@ -735,7 +924,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg, /* private data */ if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -745,15 +934,49 @@ int tplg_parse_pcm(snd_tplg_t *tplg, return 0; } +/* save PCM */ +int tplg_save_pcm(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_pcm *pcm = elem->pcm; + char pfx2[16]; + int err; + + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && elem->index) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", + elem->index); + if (err >= 0 && pcm->pcm_id) + err = tplg_save_printf(dst, pfx, "\tid %u\n", + pcm->pcm_id); + if (err >= 0 && pcm->compress) + err = tplg_save_printf(dst, pfx, "\tcompress 1\n"); + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + if (err >= 0) + err = tplg_save_fe_dai(tplg, elem, dst, pfx2); + if (err >= 0) + err = tplg_save_streams(tplg, elem, dst, pfx2); + if (err >= 0) + err = save_flags(pcm->flags, pcm->flag_mask, dst, pfx); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse physical DAI */ -int tplg_parse_dai(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) +int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_dai *dai; struct tplg_elem *elem; snd_config_iterator_t i, next; snd_config_t *n; - const char *id, *val = NULL; + const char *id; int err; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_DAI); @@ -765,7 +988,7 @@ int tplg_parse_dai(snd_tplg_t *tplg, snd_strlcpy(dai->dai_name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg(" DAI: %s\n", elem->id); + tplg_dbg(" DAI: %s", elem->id); snd_config_for_each(i, next, cfg) { @@ -780,30 +1003,21 @@ int tplg_parse_dai(snd_tplg_t *tplg, continue; if (strcmp(id, "id") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &dai->dai_id)) return -EINVAL; - - dai->dai_id = atoi(val); - tplg_dbg("\t%s: %d\n", id, dai->dai_id); continue; } if (strcmp(id, "playback") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &dai->playback)) return -EINVAL; - - dai->playback = atoi(val); - tplg_dbg("\t%s: %d\n", id, dai->playback); continue; } if (strcmp(id, "capture") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &dai->capture)) return -EINVAL; - - dai->capture = atoi(val); - tplg_dbg("\t%s: %d\n", id, dai->capture); continue; } @@ -847,11 +1061,9 @@ int tplg_parse_dai(snd_tplg_t *tplg, /* private data */ if (strcmp(id, "data") == 0) { - if (snd_config_get_string(n, &val) < 0) - return -EINVAL; - - tplg_ref_add(elem, SND_TPLG_TYPE_DATA, val); - tplg_dbg("\t%s: %s\n", id, val); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); + if (err < 0) + return err; continue; } } @@ -859,61 +1071,61 @@ int tplg_parse_dai(snd_tplg_t *tplg, return 0; } +/* save DAI */ +int tplg_save_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_dai *dai = elem->dai; + char pfx2[16]; + int err; + + if (!dai) + return 0; + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && elem->index) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", + elem->index); + if (err >= 0 && dai->dai_id) + err = tplg_save_printf(dst, pfx, "\tid %u\n", + dai->dai_id); + if (err >= 0 && dai->playback) + err = tplg_save_printf(dst, pfx, "\tplayback %u\n", + dai->playback); + if (err >= 0 && dai->capture) + err = tplg_save_printf(dst, pfx, "\tcapture %u\n", + dai->capture); + if (err >= 0) + err = tplg_save_streams(tplg, elem, dst, pfx2); + if (err >= 0) + err = save_flags(dai->flags, dai->flag_mask, dst, pfx); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* parse physical link runtime supported HW configs in text conf file */ static int parse_hw_config_refs(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_t *cfg, struct tplg_elem *elem) { struct snd_soc_tplg_link_config *link = elem->link; - snd_config_type_t type; - snd_config_iterator_t i, next; - snd_config_t *n; - const char *id, *val = NULL; - - if (snd_config_get_id(cfg, &id) < 0) - return -EINVAL; - type = snd_config_get_type(cfg); - - /* refer to a single HW config */ - if (type == SND_CONFIG_TYPE_STRING) { - if (snd_config_get_string(cfg, &val) < 0) - return -EINVAL; - - link->num_hw_configs = 1; - return tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val); - } - - if (type != SND_CONFIG_TYPE_COMPOUND) { - SNDERR("error: compound type expected for %s", id); - return -EINVAL; - } - - /* refer to a list of HW configs */ - snd_config_for_each(i, next, cfg) { - const char *val; - int err; - - n = snd_config_iterator_entry(i); - if (snd_config_get_string(n, &val) < 0) - continue; - - if (link->num_hw_configs >= SND_SOC_TPLG_HW_CONFIG_MAX) { - SNDERR("error: exceed max hw configs for link %s", id); - return -EINVAL; - } - - link->num_hw_configs++; - err = tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val); - if (err < 0) - return err; - } + int err; + err = tplg_parse_refs(cfg, elem, SND_TPLG_TYPE_HW_CONFIG); + if (err < 0) + return err; + link->num_hw_configs = err; return 0; } /* Parse a physical link element in text conf file */ -int tplg_parse_link(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) +int tplg_parse_link(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_link_config *link; struct tplg_elem *elem; @@ -930,7 +1142,7 @@ int tplg_parse_link(snd_tplg_t *tplg, link->size = elem->size; snd_strlcpy(link->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg(" Link: %s\n", elem->id); + tplg_dbg(" Link: %s", elem->id); snd_config_for_each(i, next, cfg) { @@ -945,11 +1157,8 @@ int tplg_parse_link(snd_tplg_t *tplg, continue; if (strcmp(id, "id") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &link->id)) return -EINVAL; - - link->id = atoi(val); - tplg_dbg("\t%s: %d\n", id, link->id); continue; } @@ -959,7 +1168,7 @@ int tplg_parse_link(snd_tplg_t *tplg, snd_strlcpy(link->stream_name, val, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg("\t%s: %s\n", id, val); + tplg_dbg("\t%s: %s", id, val); continue; } @@ -971,10 +1180,8 @@ int tplg_parse_link(snd_tplg_t *tplg, } if (strcmp(id, "default_hw_conf_id") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &link->default_hw_config_id)) return -EINVAL; - - link->default_hw_config_id = atoi(val); continue; } @@ -1008,7 +1215,7 @@ int tplg_parse_link(snd_tplg_t *tplg, /* private data */ if (strcmp(id, "data") == 0) { - err = tplg_parse_data_refs(n, elem); + err = tplg_parse_refs(n, elem, SND_TPLG_TYPE_DATA); if (err < 0) return err; continue; @@ -1018,15 +1225,53 @@ int tplg_parse_link(snd_tplg_t *tplg, return 0; } +/* save physical link */ +int tplg_save_link(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_link_config *link = elem->link; + char pfx2[16]; + int err; + + if (!link) + return 0; + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && elem->index) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", + elem->index); + if (err >= 0 && link->id) + err = tplg_save_printf(dst, pfx, "\tid %u\n", + link->id); + if (err >= 0 && link->stream_name[0]) + err = tplg_save_printf(dst, pfx, "\tstream_name '%s'\n", + link->stream_name); + if (err >= 0 && link->default_hw_config_id) + err = tplg_save_printf(dst, pfx, "\tdefault_hw_conf_id %u\n", + link->default_hw_config_id); + if (err >= 0) + err = save_flags(link->flags, link->flag_mask, dst, pfx); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_HW_CONFIG, + "hw_configs", dst, pfx2); + if (err >= 0) + err = tplg_save_refs(tplg, elem, SND_TPLG_TYPE_DATA, + "data", dst, pfx2); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* Parse cc */ -int tplg_parse_cc(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) +int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) { struct snd_soc_tplg_link_config *link; struct tplg_elem *elem; snd_config_iterator_t i, next; snd_config_t *n; - const char *id, *val = NULL; + const char *id; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_CC); if (!elem) @@ -1035,7 +1280,7 @@ int tplg_parse_cc(snd_tplg_t *tplg, link = elem->link; link->size = elem->size; - tplg_dbg(" CC: %s\n", elem->id); + tplg_dbg(" CC: %s", elem->id); snd_config_for_each(i, next, cfg) { @@ -1050,11 +1295,8 @@ int tplg_parse_cc(snd_tplg_t *tplg, continue; if (strcmp(id, "id") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &link->id)) return -EINVAL; - - link->id = atoi(val); - tplg_dbg("\t%s: %d\n", id, link->id); continue; } @@ -1063,36 +1305,95 @@ int tplg_parse_cc(snd_tplg_t *tplg, return 0; } -static int get_audio_hw_format(const char *val) +/* save CC */ +int tplg_save_cc(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) { - if (!strlen(val)) - return -EINVAL; - - if (!strcmp(val, "I2S")) - return SND_SOC_DAI_FORMAT_I2S; + struct snd_soc_tplg_link_config *link = elem->link; + char pfx2[16]; + int err; - if (!strcmp(val, "RIGHT_J")) - return SND_SOC_DAI_FORMAT_RIGHT_J; + if (!link) + return 0; + snprintf(pfx2, sizeof(pfx2), "%s\t", pfx ?: ""); + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && elem->index) + err = tplg_save_printf(dst, pfx, "\tindex %u\n", + elem->index); + if (err >= 0 && link->id) + err = tplg_save_printf(dst, pfx, "\tid %u\n", + link->id); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} - if (!strcmp(val, "LEFT_J")) - return SND_SOC_DAI_FORMAT_LEFT_J; +struct audio_hw_format { + unsigned int type; + const char *name; +}; - if (!strcmp(val, "DSP_A")) - return SND_SOC_DAI_FORMAT_DSP_A; +static struct audio_hw_format audio_hw_formats[] = { + { + .type = SND_SOC_DAI_FORMAT_I2S, + .name = "I2S", + }, + { + .type = SND_SOC_DAI_FORMAT_RIGHT_J, + .name = "RIGHT_J", + }, + { + .type = SND_SOC_DAI_FORMAT_LEFT_J, + .name = "LEFT_J", + }, + { + .type = SND_SOC_DAI_FORMAT_DSP_A, + .name = "DSP_A", + }, + { + .type = SND_SOC_DAI_FORMAT_DSP_B, + .name = "DSP_B", + }, + { + .type = SND_SOC_DAI_FORMAT_AC97, + .name = "AC97", + }, + { + .type = SND_SOC_DAI_FORMAT_AC97, + .name = "AC97", + }, + { + .type = SND_SOC_DAI_FORMAT_PDM, + .name = "PDM", + }, +}; - if (!strcmp(val, "DSP_B")) - return SND_SOC_DAI_FORMAT_DSP_B; +static int get_audio_hw_format(const char *val) +{ + unsigned int i; - if (!strcmp(val, "AC97")) - return SND_SOC_DAI_FORMAT_AC97; + if (val[0] == '\0') + return -EINVAL; - if (!strcmp(val, "PDM")) - return SND_SOC_DAI_FORMAT_PDM; + for (i = 0; i < ARRAY_SIZE(audio_hw_formats); i++) + if (strcasecmp(audio_hw_formats[i].name, val) == 0) + return audio_hw_formats[i].type; - SNDERR("error: invalid audio HW format %s\n", val); + SNDERR("invalid audio HW format %s", val); return -EINVAL; } +static const char *get_audio_hw_format_name(unsigned int type) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(audio_hw_formats); i++) + if (audio_hw_formats[i].type == type) + return audio_hw_formats[i].name; + return NULL; +} + int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) { @@ -1102,7 +1403,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, snd_config_iterator_t i, next; snd_config_t *n; const char *id, *val = NULL; - int ret; + int ret, ival; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_HW_CONFIG); if (!elem) @@ -1111,7 +1412,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, hw_cfg = elem->hw_cfg; hw_cfg->size = elem->size; - tplg_dbg(" Link HW config: %s\n", elem->id); + tplg_dbg(" Link HW config: %s", elem->id); snd_config_for_each(i, next, cfg) { @@ -1126,11 +1427,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, continue; if (strcmp(id, "id") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->id)) return -EINVAL; - - hw_cfg->id = atoi(val); - tplg_dbg("\t%s: %d\n", id, hw_cfg->id); continue; } @@ -1155,8 +1453,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, /* For backwards capability, * "master" == "codec is slave" */ - SNDERR("warning: deprecated bclk value '%s'\n", - val); + SNDERR("deprecated bclk value '%s'", val); hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CS; } else if (!strcmp(val, "codec_slave")) { @@ -1169,20 +1466,18 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "bclk_freq") == 0 || strcmp(id, "bclk_rate") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->bclk_rate)) return -EINVAL; - - hw_cfg->bclk_rate = atoi(val); continue; } if (strcmp(id, "bclk_invert") == 0 || strcmp(id, "invert_bclk") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; - if (!strcmp(val, "true")) - hw_cfg->invert_bclk = true; + hw_cfg->invert_bclk = ival; continue; } @@ -1195,8 +1490,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, /* For backwards capability, * "master" == "codec is slave" */ - SNDERR("warning: deprecated fsync value '%s'\n", - val); + SNDERR("deprecated fsync value '%s'", val); hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS; } else if (!strcmp(val, "codec_slave")) { @@ -1209,29 +1503,25 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "fsync_invert") == 0 || strcmp(id, "invert_fsync") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; - if (!strcmp(val, "true")) - hw_cfg->invert_fsync = true; + hw_cfg->invert_fsync = ival; continue; } if (strcmp(id, "fsync_freq") == 0 || strcmp(id, "fsync_rate") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->fsync_rate)) return -EINVAL; - - hw_cfg->fsync_rate = atoi(val); continue; } if (strcmp(id, "mclk_freq") == 0 || strcmp(id, "mclk_rate") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->mclk_rate)) return -EINVAL; - - hw_cfg->mclk_rate = atoi(val); continue; } @@ -1244,8 +1534,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, /* For backwards capability, * "master" == "for codec, mclk is input" */ - SNDERR("warning: deprecated mclk value '%s'\n", - val); + SNDERR("deprecated mclk value '%s'", val); hw_cfg->mclk_direction = SND_SOC_TPLG_MCLK_CI; } else if (!strcmp(val, "codec_mclk_in")) { @@ -1258,10 +1547,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (strcmp(id, "pm_gate_clocks") == 0 || strcmp(id, "clock_gated") == 0) { - if (snd_config_get_string(n, &val) < 0) + ival = snd_config_get_bool(n); + if (ival < 0) return -EINVAL; - if (!strcmp(val, "true")) + if (ival) hw_cfg->clock_gated = SND_SOC_TPLG_DAI_CLK_GATE_GATED; else @@ -1271,50 +1561,38 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, } if (strcmp(id, "tdm_slots") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->tdm_slots)) return -EINVAL; - - hw_cfg->tdm_slots = atoi(val); continue; } if (strcmp(id, "tdm_slot_width") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->tdm_slot_width)) return -EINVAL; - - hw_cfg->tdm_slot_width = atoi(val); continue; } if (strcmp(id, "tx_slots") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->tx_slots)) return -EINVAL; - - hw_cfg->tx_slots = atoi(val); continue; } if (strcmp(id, "rx_slots") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->rx_slots)) return -EINVAL; - - hw_cfg->rx_slots = atoi(val); continue; } if (strcmp(id, "tx_channels") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->tx_channels)) return -EINVAL; - - hw_cfg->tx_channels = atoi(val); continue; } if (strcmp(id, "rx_channels") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (parse_unsigned(n, &hw_cfg->rx_channels)) return -EINVAL; - - hw_cfg->rx_channels = atoi(val); continue; } @@ -1323,9 +1601,74 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, return 0; } +/* save hw config */ +int tplg_save_hw_config(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct snd_soc_tplg_hw_config *hc = elem->hw_cfg; + int err; + + err = tplg_save_printf(dst, NULL, "'%s' {\n", elem->id); + if (err >= 0 && hc->id) + err = tplg_save_printf(dst, pfx, "\tid %u\n", + hc->id); + if (err >= 0 && hc->fmt) + err = tplg_save_printf(dst, pfx, "\tformat '%s'\n", + get_audio_hw_format_name(hc->fmt)); + if (err >= 0 && hc->bclk_master) + err = tplg_save_printf(dst, pfx, "\tbclk '%s'\n", + hc->bclk_master == SND_SOC_TPLG_BCLK_CS ? + "codec_slave" : "codec_master"); + if (err >= 0 && hc->bclk_rate) + err = tplg_save_printf(dst, pfx, "\tbclk_freq %u\n", + hc->bclk_rate); + if (err >= 0 && hc->invert_bclk) + err = tplg_save_printf(dst, pfx, "\tbclk_invert 1\n"); + if (err >= 0 && hc->fsync_master) + err = tplg_save_printf(dst, pfx, "\tfsync_master '%s'\n", + hc->fsync_master == SND_SOC_TPLG_FSYNC_CS ? + "codec_slave" : "codec_master"); + if (err >= 0 && hc->fsync_rate) + err = tplg_save_printf(dst, pfx, "\tfsync_freq %u\n", + hc->fsync_rate); + if (err >= 0 && hc->invert_fsync) + err = tplg_save_printf(dst, pfx, "\tfsync_invert 1\n"); + if (err >= 0 && hc->mclk_rate) + err = tplg_save_printf(dst, pfx, "\tmclk_freq %u\n", + hc->mclk_rate); + if (err >= 0 && hc->mclk_direction) + err = tplg_save_printf(dst, pfx, "\tmclk '%s'\n", + hc->mclk_direction == SND_SOC_TPLG_MCLK_CI ? + "codec_mclk_in" : "codec_mclk_out"); + if (err >= 0 && hc->clock_gated) + err = tplg_save_printf(dst, pfx, "\tpm_gate_clocks 1\n"); + if (err >= 0 && hc->tdm_slots) + err = tplg_save_printf(dst, pfx, "\ttdm_slots %u\n", + hc->tdm_slots); + if (err >= 0 && hc->tdm_slot_width) + err = tplg_save_printf(dst, pfx, "\ttdm_slot_width %u\n", + hc->tdm_slot_width); + if (err >= 0 && hc->tx_slots) + err = tplg_save_printf(dst, pfx, "\ttx_slots %u\n", + hc->tx_slots); + if (err >= 0 && hc->rx_slots) + err = tplg_save_printf(dst, pfx, "\trx_slots %u\n", + hc->rx_slots); + if (err >= 0 && hc->tx_channels) + err = tplg_save_printf(dst, pfx, "\ttx_channels %u\n", + hc->tx_channels); + if (err >= 0 && hc->rx_channels) + err = tplg_save_printf(dst, pfx, "\trx_channels %u\n", + hc->rx_channels); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "}\n"); + return err; +} + /* copy stream object */ static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm, - struct snd_tplg_stream_template *strm_tpl) + struct snd_tplg_stream_template *strm_tpl) { snd_strlcpy(strm->name, strm_tpl->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); @@ -1336,11 +1679,20 @@ static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm, strm->channels = strm_tpl->channels; } -static void tplg_add_stream_caps(struct snd_soc_tplg_stream_caps *caps, - struct snd_tplg_stream_caps_template *caps_tpl) +static int tplg_add_stream_caps(snd_tplg_t *tplg, + struct snd_tplg_stream_caps_template *caps_tpl) { - snd_strlcpy(caps->name, caps_tpl->name, - SNDRV_CTL_ELEM_ID_NAME_MAXLEN); + struct snd_soc_tplg_stream_caps *caps; + struct tplg_elem *elem; + + elem = tplg_elem_new_common(tplg, NULL, caps_tpl->name, + SND_TPLG_TYPE_STREAM_CAPS); + if (!elem) + return -ENOMEM; + + caps = elem->stream_caps; + + snd_strlcpy(caps->name, caps_tpl->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); caps->formats = caps_tpl->formats; caps->rates = caps_tpl->rates; @@ -1355,17 +1707,19 @@ static void tplg_add_stream_caps(struct snd_soc_tplg_stream_caps *caps, caps->buffer_size_min = caps_tpl->buffer_size_min; caps->buffer_size_max = caps_tpl->buffer_size_max; caps->sig_bits = caps_tpl->sig_bits; + return 0; } /* Add a PCM element (FE DAI & DAI link) from C API */ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) { struct snd_tplg_pcm_template *pcm_tpl = t->pcm; - struct snd_soc_tplg_pcm *pcm, *_pcm; + struct snd_soc_tplg_private *priv; + struct snd_soc_tplg_pcm *pcm; struct tplg_elem *elem; - int i; + int ret, i; - tplg_dbg("PCM: %s, DAI %s\n", pcm_tpl->pcm_name, pcm_tpl->dai_name); + tplg_dbg("PCM: %s, DAI %s", pcm_tpl->pcm_name, pcm_tpl->dai_name); if (pcm_tpl->num_streams > SND_SOC_TPLG_STREAM_CONFIG_MAX) return -EINVAL; @@ -1389,8 +1743,13 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) pcm->compress = pcm_tpl->compress; for (i = 0; i < 2; i++) { - if (pcm_tpl->caps[i]) - tplg_add_stream_caps(&pcm->caps[i], pcm_tpl->caps[i]); + if (!pcm_tpl->caps[i] || !pcm_tpl->caps[i]->name) + continue; + ret = tplg_add_stream_caps(tplg, pcm_tpl->caps[i]); + if (ret < 0) + return ret; + snd_strlcpy(pcm->caps[i].name, pcm_tpl->caps[i]->name, + sizeof(pcm->caps[i].name)); } pcm->flag_mask = pcm_tpl->flag_mask; @@ -1401,22 +1760,12 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) tplg_add_stream_object(&pcm->stream[i], &pcm_tpl->stream[i]); /* private data */ - if (pcm_tpl->priv != NULL && pcm_tpl->priv->size) { - tplg_dbg("\t priv data size %d\n", pcm_tpl->priv->size); - _pcm = realloc(pcm, - elem->size + pcm_tpl->priv->size); - if (!_pcm) { - tplg_elem_free(elem); - return -ENOMEM; - } - - pcm = _pcm; - elem->pcm = pcm; - elem->size += pcm_tpl->priv->size; - - memcpy(pcm->priv.data, pcm_tpl->priv->data, - pcm_tpl->priv->size); - pcm->priv.size = pcm_tpl->priv->size; + priv = pcm_tpl->priv; + if (priv && priv->size > 0) { + ret = tplg_add_data(tplg, elem, priv, + sizeof(*priv) + priv->size); + if (ret < 0) + return ret; } return 0; @@ -1424,7 +1773,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) /* Set link HW config from C API template */ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg, - struct snd_tplg_hw_config_template *tpl) + struct snd_tplg_hw_config_template *tpl) { unsigned int i; @@ -1467,9 +1816,11 @@ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg, int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) { struct snd_tplg_link_template *link_tpl = t->link; - struct snd_soc_tplg_link_config *link, *_link; + struct snd_soc_tplg_link_config *link; + struct snd_soc_tplg_private *priv; struct tplg_elem *elem; unsigned int i; + int ret; if (t->type != SND_TPLG_TYPE_LINK && t->type != SND_TPLG_TYPE_BE && t->type != SND_TPLG_TYPE_CC) @@ -1511,21 +1862,12 @@ int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) link->flags = link_tpl->flags; /* private data */ - if (link_tpl->priv != NULL && link_tpl->priv->size) { - _link = realloc(link, - elem->size + link_tpl->priv->size); - if (!_link) { - tplg_elem_free(elem); - return -ENOMEM; - } - - link = _link; - elem->link = link; - elem->size += link_tpl->priv->size; - - memcpy(link->priv.data, link_tpl->priv->data, - link_tpl->priv->size); - link->priv.size = link_tpl->priv->size; + priv = link_tpl->priv; + if (priv && priv->size > 0) { + ret = tplg_add_data(tplg, elem, priv, + sizeof(*priv) + priv->size); + if (ret < 0) + return ret; } return 0; @@ -1534,14 +1876,15 @@ int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) int tplg_add_dai_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) { struct snd_tplg_dai_template *dai_tpl = t->dai; - struct snd_soc_tplg_dai *dai, *_dai; + struct snd_soc_tplg_dai *dai; + struct snd_soc_tplg_private *priv; struct tplg_elem *elem; - int i; + int ret, i; - tplg_dbg("DAI %s\n", dai_tpl->dai_name); + tplg_dbg("DAI %s", dai_tpl->dai_name); elem = tplg_elem_new_common(tplg, NULL, dai_tpl->dai_name, - SND_TPLG_TYPE_DAI); + SND_TPLG_TYPE_DAI); if (!elem) return -ENOMEM; @@ -1557,8 +1900,13 @@ int tplg_add_dai_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) dai->capture = dai_tpl->capture; for (i = 0; i < 2; i++) { - if (dai_tpl->caps[i]) - tplg_add_stream_caps(&dai->caps[i], dai_tpl->caps[i]); + if (!dai_tpl->caps[i] || !dai_tpl->caps[i]->name) + continue; + ret = tplg_add_stream_caps(tplg, dai_tpl->caps[i]); + if (ret < 0) + return ret; + snd_strlcpy(dai->caps[i].name, dai_tpl->caps[i]->name, + sizeof(dai->caps[i].name)); } /* flags */ @@ -1566,22 +1914,301 @@ int tplg_add_dai_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t) dai->flags = dai_tpl->flags; /* private data */ - if (dai_tpl->priv != NULL) { - _dai = realloc(dai, - elem->size + dai_tpl->priv->size); - if (!_dai) { - tplg_elem_free(elem); - return -ENOMEM; + priv = dai_tpl->priv; + if (priv && priv->size > 0) { + ret = tplg_add_data(tplg, elem, priv, + sizeof(*priv) + priv->size); + if (ret < 0) + return ret; + } + + return 0; +} + +/* decode pcm from the binary input */ +int tplg_decode_pcm(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct snd_soc_tplg_pcm *pcm; + snd_tplg_obj_template_t t; + struct snd_tplg_pcm_template *pt; + struct snd_tplg_stream_caps_template caps[2], *cap; + struct snd_tplg_stream_template *stream; + unsigned int i; + size_t asize; + int err; + + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; + + asize = sizeof(*pt) + SND_SOC_TPLG_STREAM_CONFIG_MAX * sizeof(*stream); + pt = alloca(asize); + +next: + memset(pt, 0, asize); + pcm = bin; + + if (size < sizeof(*pcm)) { + SNDERR("pcm: small size %d", size); + return -EINVAL; + } + if (sizeof(*pcm) != pcm->size) { + SNDERR("pcm: unknown element size %d (expected %zd)", + pcm->size, sizeof(*pcm)); + return -EINVAL; + } + if (pcm->num_streams > SND_SOC_TPLG_STREAM_CONFIG_MAX) { + SNDERR("pcm: wrong number of streams %d", pcm->num_streams); + return -EINVAL; + } + if (sizeof(*pcm) + pcm->priv.size > size) { + SNDERR("pcm: wrong private data size %d", pcm->priv.size); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "pcm: size %d private size %d streams %d", + pcm->size, pcm->priv.size, pcm->num_streams); + + pt->pcm_name = pcm->pcm_name; + tplg_log(tplg, 'D', pos, "pcm: pcm_name '%s'", pt->pcm_name); + pt->dai_name = pcm->dai_name; + tplg_log(tplg, 'D', pos, "pcm: dai_name '%s'", pt->dai_name); + pt->pcm_id = pcm->pcm_id; + pt->dai_id = pcm->dai_id; + tplg_log(tplg, 'D', pos, "pcm: pcm_id %d dai_id %d", pt->pcm_id, pt->dai_id); + pt->playback = pcm->playback; + pt->capture = pcm->capture; + pt->compress = pcm->compress; + tplg_log(tplg, 'D', pos, "pcm: playback %d capture %d compress", + pt->playback, pt->capture, pt->compress); + pt->num_streams = pcm->num_streams; + pt->flag_mask = pcm->flag_mask; + pt->flags = pcm->flags; + for (i = 0; i < pcm->num_streams; i++) { + stream = &pt->stream[i]; + if (pcm->stream[i].size != sizeof(pcm->stream[0])) { + SNDERR("pcm: unknown stream structure size %d", + pcm->stream[i].size); + return -EINVAL; } + stream->name = pcm->stream[i].name; + tplg_log(tplg, 'D', pos + offsetof(struct snd_soc_tplg_pcm, stream[i]), + "stream %d: '%s'", i, stream->name); + stream->format = pcm->stream[i].format; + stream->rate = pcm->stream[i].rate; + stream->period_bytes = pcm->stream[i].period_bytes; + stream->buffer_bytes = pcm->stream[i].buffer_bytes; + stream->channels = pcm->stream[i].channels; + } + for (i = 0; i < 2; i++) { + if (i == 0 && !pcm->playback) + continue; + if (i == 1 && !pcm->capture) + continue; + cap = &caps[i]; + pt->caps[i] = cap; + if (pcm->caps[i].size != sizeof(pcm->caps[0])) { + SNDERR("pcm: unknown caps structure size %d", + pcm->caps[i].size); + return -EINVAL; + } + cap->name = pcm->caps[i].name; + tplg_log(tplg, 'D', pos + offsetof(struct snd_soc_tplg_pcm, caps[i]), + "caps %d: '%s'", i, cap->name); + cap->formats = pcm->caps[i].formats; + cap->rates = pcm->caps[i].rates; + cap->rate_min = pcm->caps[i].rate_min; + cap->rate_max = pcm->caps[i].rate_max; + cap->channels_min = pcm->caps[i].channels_min; + cap->channels_max = pcm->caps[i].channels_max; + cap->periods_min = pcm->caps[i].periods_min; + cap->periods_max = pcm->caps[i].periods_max; + cap->period_size_min = pcm->caps[i].period_size_min; + cap->period_size_max = pcm->caps[i].period_size_max; + cap->buffer_size_min = pcm->caps[i].buffer_size_min; + cap->buffer_size_max = pcm->caps[i].buffer_size_max; + cap->sig_bits = pcm->caps[i].sig_bits; + } + + tplg_log(tplg, 'D', pos + offsetof(struct snd_soc_tplg_pcm, priv), + "pcm: private start"); + pt->priv = &pcm->priv; + + bin += sizeof(*pcm) + pcm->priv.size; + size -= sizeof(*pcm) + pcm->priv.size; + pos += sizeof(*pcm) + pcm->priv.size; + + t.pcm = pt; + err = snd_tplg_add_object(tplg, &t); + if (err < 0) + return err; + + if (size > 0) + goto next; + + return 0; +} + +/* decode dai from the binary input */ +int tplg_decode_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + size_t pos ATTRIBUTE_UNUSED, + struct snd_soc_tplg_hdr *hdr ATTRIBUTE_UNUSED, + void *bin ATTRIBUTE_UNUSED, + size_t size ATTRIBUTE_UNUSED) +{ + SNDERR("not implemented"); + return -ENXIO; +} + +/* decode cc from the binary input */ +int tplg_decode_cc(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + size_t pos ATTRIBUTE_UNUSED, + struct snd_soc_tplg_hdr *hdr ATTRIBUTE_UNUSED, + void *bin ATTRIBUTE_UNUSED, + size_t size ATTRIBUTE_UNUSED) +{ + SNDERR("not implemented"); + return -ENXIO; +} + +/* decode link from the binary input */ +int tplg_decode_link(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size) +{ + struct snd_soc_tplg_link_config *link; + snd_tplg_obj_template_t t; + struct snd_tplg_link_template lt; + struct snd_tplg_stream_template streams[SND_SOC_TPLG_STREAM_CONFIG_MAX]; + struct snd_tplg_stream_template *stream; + struct snd_tplg_hw_config_template hws[SND_SOC_TPLG_HW_CONFIG_MAX]; + struct snd_tplg_hw_config_template *hw; + unsigned int i, j; + int err; - dai = _dai; - dai->priv.size = dai_tpl->priv->size; + err = tplg_decode_template(tplg, pos, hdr, &t); + if (err < 0) + return err; - elem->dai = dai; - elem->size += dai->priv.size; - memcpy(dai->priv.data, dai_tpl->priv->data, - dai->priv.size); +next: + memset(<, 0, sizeof(lt)); + memset(streams, 0, sizeof(streams)); + memset(hws, 0, sizeof(hws)); + link = bin; + + if (size < sizeof(*link)) { + SNDERR("link: small size %d", size); + return -EINVAL; } + if (sizeof(*link) != link->size) { + SNDERR("link: unknown element size %d (expected %zd)", + link->size, sizeof(*link)); + return -EINVAL; + } + if (link->num_streams > SND_SOC_TPLG_STREAM_CONFIG_MAX) { + SNDERR("link: wrong number of streams %d", link->num_streams); + return -EINVAL; + } + if (link->num_hw_configs > SND_SOC_TPLG_HW_CONFIG_MAX) { + SNDERR("link: wrong number of streams %d", link->num_streams); + return -EINVAL; + } + if (sizeof(*link) + link->priv.size > size) { + SNDERR("link: wrong private data size %d", link->priv.size); + return -EINVAL; + } + + tplg_log(tplg, 'D', pos, "link: size %d private size %d streams %d " + "hw_configs %d", + link->size, link->priv.size, link->num_streams, + link->num_hw_configs); + + lt.id = link->id; + lt.name = link->name; + tplg_log(tplg, 'D', pos, "link: name '%s'", lt.name); + lt.stream_name = link->stream_name; + tplg_log(tplg, 'D', pos, "link: stream_name '%s'", lt.stream_name); + lt.num_streams = link->num_streams; + lt.num_hw_configs = link->num_hw_configs; + lt.default_hw_config_id = link->default_hw_config_id; + lt.flag_mask = link->flag_mask; + lt.flags = link->flags; + for (i = 0; i < link->num_streams; i++) { + stream = &streams[i]; + if (link->stream[i].size != sizeof(link->stream[0])) { + SNDERR("link: unknown stream structure size %d", + link->stream[i].size); + return -EINVAL; + } + stream->name = link->stream[i].name; + tplg_log(tplg, 'D', + pos + offsetof(struct snd_soc_tplg_link_config, stream[i]), + "stream %d: '%s'", i, stream->name); + stream->format = link->stream[i].format; + stream->rate = link->stream[i].rate; + stream->period_bytes = link->stream[i].period_bytes; + stream->buffer_bytes = link->stream[i].buffer_bytes; + stream->channels = link->stream[i].channels; + } + lt.stream = streams; + for (i = 0; i < link->num_hw_configs; i++) { + hw = &hws[i]; + if (link->hw_config[i].size != sizeof(link->hw_config[0])) { + SNDERR("link: unknown hw_config structure size %d", + link->hw_config[i].size); + return -EINVAL; + } + hw->id = link->hw_config[i].id; + hw->fmt = link->hw_config[i].fmt; + hw->clock_gated = link->hw_config[i].clock_gated; + hw->invert_bclk = link->hw_config[i].invert_bclk; + hw->invert_fsync = link->hw_config[i].invert_fsync; + hw->bclk_master = link->hw_config[i].bclk_master; + hw->fsync_master = link->hw_config[i].fsync_master; + hw->mclk_direction = link->hw_config[i].mclk_direction; + hw->mclk_rate = link->hw_config[i].mclk_rate; + hw->bclk_rate = link->hw_config[i].bclk_rate; + hw->fsync_rate = link->hw_config[i].fsync_rate; + hw->tdm_slots = link->hw_config[i].tdm_slots; + hw->tdm_slot_width = link->hw_config[i].tdm_slot_width; + hw->tx_slots = link->hw_config[i].tx_slots; + hw->rx_slots = link->hw_config[i].rx_slots; + hw->tx_channels = link->hw_config[i].tx_channels; + if (hw->tx_channels > SND_SOC_TPLG_MAX_CHAN) { + SNDERR("link: wrong tx channels %d", hw->tx_channels); + return -EINVAL; + } + for (j = 0; j < hw->tx_channels; j++) + hw->tx_chanmap[j] = link->hw_config[i].tx_chanmap[j]; + hw->rx_channels = link->hw_config[i].rx_channels; + if (hw->rx_channels > SND_SOC_TPLG_MAX_CHAN) { + SNDERR("link: wrong rx channels %d", hw->tx_channels); + return -EINVAL; + } + for (j = 0; j < hw->rx_channels; j++) + hw->rx_chanmap[j] = link->hw_config[i].rx_chanmap[j]; + } + lt.hw_config = hws; + + tplg_log(tplg, 'D', pos + offsetof(struct snd_soc_tplg_pcm, priv), + "link: private start"); + lt.priv = &link->priv; + + bin += sizeof(*link) + link->priv.size; + size -= sizeof(*link) + link->priv.size; + pos += sizeof(*link) + link->priv.size; + + t.link = < + err = snd_tplg_add_object(tplg, &t); + if (err < 0) + return err; + + if (size > 0) + goto next; return 0; } diff --git a/src/topology/save.c b/src/topology/save.c new file mode 100644 index 0000000..4ecf86c --- /dev/null +++ b/src/topology/save.c @@ -0,0 +1,607 @@ +/* + Copyright(c) 2019 Red Hat Inc. + All rights reserved. + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + Authors: Jaroslav Kysela +*/ + +#include "list.h" +#include "tplg_local.h" + +#define SAVE_ALLOC_SHIFT (13) /* 8192 bytes */ + +int tplg_save_printf(char **dst, const char *pfx, const char *fmt, ...) +{ + va_list va; + char buf[1024], *s; + size_t n, l, t, pl; + + if (pfx == NULL) + pfx = ""; + + va_start(va, fmt); + n = vsnprintf(buf, sizeof(buf), fmt, va); + va_end(va); + + if (n >= sizeof(buf)) + return -EOVERFLOW; + + pl = strlen(pfx); + l = *dst ? strlen(*dst) : 0; + t = l + pl + n + 1; + /* allocate chunks */ + if (*dst == NULL || + (l >> SAVE_ALLOC_SHIFT) != (t >> SAVE_ALLOC_SHIFT)) { + s = realloc(*dst, ((t >> SAVE_ALLOC_SHIFT) + 1) << + SAVE_ALLOC_SHIFT); + if (s == NULL) { + free(*dst); + *dst = NULL; + return -ENOMEM; + } + } else { + s = *dst; + } + + if (pl > 0) + strcpy(s + l, pfx); + strcpy(s + l + pl, buf); + *dst = s; + return 0; +} + +int tplg_nice_value_format(char *dst, size_t dst_size, unsigned int value) +{ + if ((value % 1000) != 0) { + if (value > 0xfffffff0) + return snprintf(dst, dst_size, "%d", (int)value); + if (value >= 0xffff0000) + return snprintf(dst, dst_size, "0x%x", value); + } + return snprintf(dst, dst_size, "%u", value); +} + +static int tplg_pprint_integer(snd_config_t *n, char **ret) +{ + long lval; + int err, type; + char buf[16]; + + type = snd_config_get_type(n); + if (type == SND_CONFIG_TYPE_INTEGER) { + err = snd_config_get_integer(n, &lval); + if (err < 0) + return err; + if (lval < INT_MIN || lval > UINT_MAX) + return snd_config_get_ascii(n, ret); + } else if (type == SND_CONFIG_TYPE_INTEGER64) { + long long llval; + err = snd_config_get_integer64(n, &llval); + if (err < 0) + return err; + if (llval < INT_MIN || llval > UINT_MAX) + return snd_config_get_ascii(n, ret); + lval = llval; + } + err = tplg_nice_value_format(buf, sizeof(buf), (unsigned int)lval); + if (err < 0) + return err; + *ret = strdup(buf); + if (*ret == NULL) + return -ENOMEM; + return 0; +} + +static int _compar(const void *a, const void *b) +{ + const snd_config_t *c1 = *(snd_config_t **)a; + const snd_config_t *c2 = *(snd_config_t **)b; + const char *id1, *id2; + if (snd_config_get_id(c1, &id1)) return 0; + if (snd_config_get_id(c2, &id2)) return 0; + return strcmp(id1, id2); +} + +static snd_config_t *sort_config(const char *id, snd_config_t *src) +{ + snd_config_t *dst, **a; + snd_config_iterator_t i, next; + int index, array, count; + + if (snd_config_get_type(src) != SND_CONFIG_TYPE_COMPOUND) { + + if (snd_config_copy(&dst, src) >= 0) + return dst; + return NULL; + } + count = 0; + snd_config_for_each(i, next, src) + count++; + a = malloc(sizeof(dst) * count); + if (a == NULL) + return NULL; + array = snd_config_is_array(src); + if (array <= 0) { + index = 0; + snd_config_for_each(i, next, src) { + snd_config_t *s = snd_config_iterator_entry(i); + a[index++] = s; + } + qsort(a, count, sizeof(a[0]), _compar); + } + if (snd_config_make_compound(&dst, id, count == 1)) { + free(a); + return NULL; + } + for (index = 0; index < count; index++) { + snd_config_t *s = a[index]; + const char *id2; + if (snd_config_get_id(s, &id2)) { + snd_config_delete(dst); + free(a); + return NULL; + } + s = sort_config(id2, s); + if (s == NULL || snd_config_add(dst, s)) { + if (s) + snd_config_delete(s); + snd_config_delete(dst); + free(a); + return NULL; + } + } + free(a); + return dst; +} + +static int tplg_check_quoted(const unsigned char *p) +{ + for ( ; *p != '\0'; p++) { + switch (*p) { + case ' ': + case '=': + case ';': + case ',': + case '.': + case '{': + case '}': + case '\'': + case '"': + return 1; + default: + if (*p <= 31 || *p >= 127) + return 1; + + } + } + return 0; +} + +static int tplg_save_quoted(char **dst, const char *str) +{ + static const char nibble[16] = "0123456789abcdef"; + unsigned char *p, *d, *t; + int c; + + d = t = alloca(strlen(str) * 5 + 1 + 1); + for (p = (unsigned char *)str; *p != '\0'; p++) { + c = *p; + switch (c) { + case '\n': + *t++ = '\\'; + *t++ = 'n'; + break; + case '\t': + *t++ = '\\'; + *t++ = 't'; + break; + case '\v': + *t++ = '\\'; + *t++ = 'v'; + break; + case '\b': + *t++ = '\\'; + *t++ = 'b'; + break; + case '\r': + *t++ = '\\'; + *t++ = 'r'; + break; + case '\f': + *t++ = '\\'; + *t++ = 'f'; + break; + case '\'': + *t++ = '\\'; + *t++ = c; + break; + default: + if (c >= 32 && c <= 126) { + *t++ = c; + } else { + *t++ = '\\'; + *t++ = 'x'; + *t++ = nibble[(c >> 4) & 0x0f]; + *t++ = nibble[(c >> 0) & 0x0f]; + } + break; + } + } + *t = '\0'; + return tplg_save_printf(dst, NULL, "'%s'", d); +} + +static int tplg_save_string(char **dst, const char *str, int id) +{ + const unsigned char *p = (const unsigned char *)str; + + if (!p || !*p) + return tplg_save_printf(dst, NULL, "''"); + + if (!id && ((*p >= '0' && *p <= '9') || *p == '-')) + return tplg_save_quoted(dst, str); + + if (tplg_check_quoted(p)) + return tplg_save_quoted(dst, str); + + return tplg_save_printf(dst, NULL, "%s", str); +} + +static int save_config(char **dst, int level, const char *delim, snd_config_t *src) +{ + snd_config_iterator_t i, next; + snd_config_t *s; + const char *id; + char *pfx; + unsigned int count; + int type, err, quoted, array; + + if (delim == NULL) + delim = ""; + + type = snd_config_get_type(src); + if (type != SND_CONFIG_TYPE_COMPOUND) { + char *val; + if (type == SND_CONFIG_TYPE_INTEGER || + type == SND_CONFIG_TYPE_INTEGER64) { + err = tplg_pprint_integer(src, &val); + } else { + err = snd_config_get_ascii(src, &val); + } + if (err < 0) + return err; + if (type == SND_CONFIG_TYPE_STRING) { + /* hexa array pretty print */ + id = strchr(val, '\n'); + if (id) { + err = tplg_save_printf(dst, NULL, "\n"); + if (err < 0) + goto retval; + for (id++; *id == '\t'; id++) { + err = tplg_save_printf(dst, NULL, "\t"); + if (err < 0) + goto retval; + } + delim = ""; + } + err = tplg_save_printf(dst, NULL, "%s'%s'\n", delim, val); + } else { + err = tplg_save_printf(dst, NULL, "%s%s\n", delim, val); + } +retval: + free(val); + return err; + } + + count = 0; + quoted = 0; + array = snd_config_is_array(src); + s = NULL; + snd_config_for_each(i, next, src) { + s = snd_config_iterator_entry(i); + err = snd_config_get_id(s, &id); + if (err < 0) + return err; + if (!quoted && tplg_check_quoted((unsigned char *)id)) + quoted = 1; + count++; + } + if (count == 0) + return 0; + + if (count == 1) { + err = snd_config_get_id(s, &id); + if (err >= 0 && level > 0) + err = tplg_save_printf(dst, NULL, "."); + if (err >= 0) + err = tplg_save_string(dst, id, 1); + if (err >= 0) + err = save_config(dst, level, " ", s); + return err; + } + + pfx = alloca(level + 1); + memset(pfx, '\t', level); + pfx[level] = '\0'; + + if (level > 0) { + err = tplg_save_printf(dst, NULL, "%s%s\n", delim, + array > 0 ? "[" : "{"); + if (err < 0) + return err; + } + + snd_config_for_each(i, next, src) { + s = snd_config_iterator_entry(i); + const char *id; + err = snd_config_get_id(s, &id); + if (err < 0) + return err; + err = tplg_save_printf(dst, pfx, ""); + if (err < 0) + return err; + if (array <= 0) { + delim = " "; + if (quoted) { + err = tplg_save_quoted(dst, id); + } else { + err = tplg_save_string(dst, id, 1); + if (err < 0) + return err; + } + } else { + delim = ""; + } + err = save_config(dst, level + 1, delim, s); + if (err < 0) + return err; + } + + if (level > 0) { + pfx[level - 1] = '\0'; + err = tplg_save_printf(dst, pfx, "%s\n", + array > 0 ? "]" : "}"); + if (err < 0) + return err; + } + + return 0; +} + +static int tplg_save(snd_tplg_t *tplg, char **dst, int gindex, const char *prefix) +{ + struct tplg_table *tptr; + struct tplg_elem *elem; + struct list_head *list, *pos; + char pfx2[16]; + unsigned int index; + int err, count; + + snprintf(pfx2, sizeof(pfx2), "%s\t", prefix ?: ""); + + /* write all blocks */ + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + list = (struct list_head *)((void *)tplg + tptr->loff); + + /* count elements */ + count = 0; + list_for_each(pos, list) { + elem = list_entry(pos, struct tplg_elem, list); + if (gindex >= 0 && elem->index != gindex) + continue; + if (tptr->save == NULL && tptr->gsave == NULL) { + SNDERR("unable to create %s block (no callback)", + tptr->id); + err = -ENXIO; + goto _err; + } + if (tptr->save) + count++; + } + + if (count == 0) + continue; + + if (count > 1) { + err = tplg_save_printf(dst, prefix, "%s {\n", + elem->table ? + elem->table->id : "_NOID_"); + } else { + err = tplg_save_printf(dst, prefix, "%s.", + elem->table ? + elem->table->id : "_NOID_"); + } + + if (err < 0) + goto _err; + + list_for_each(pos, list) { + elem = list_entry(pos, struct tplg_elem, list); + if (gindex >= 0 && elem->index != gindex) + continue; + if (count > 1) { + err = tplg_save_printf(dst, pfx2, ""); + if (err < 0) + goto _err; + } + err = tptr->save(tplg, elem, dst, count > 1 ? pfx2 : prefix); + if (err < 0) { + SNDERR("failed to save %s elements: %s", + tptr->id, snd_strerror(-err)); + goto _err; + } + } + if (count > 1) { + err = tplg_save_printf(dst, prefix, "}\n"); + if (err < 0) + goto _err; + } + } + + /* save globals */ + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + if (tptr->gsave) { + err = tptr->gsave(tplg, gindex, dst, prefix); + if (err < 0) + goto _err; + } + } + + return 0; + +_err: + free(*dst); + *dst = NULL; + return err; +} + +static int tplg_index_compar(const void *a, const void *b) +{ + const int *a1 = a, *b1 = b; + return *a1 - *b1; +} + +static int tplg_index_groups(snd_tplg_t *tplg, int **indexes) +{ + struct tplg_table *tptr; + struct tplg_elem *elem; + struct list_head *list, *pos; + unsigned int index, j, count, size; + int *a, *b; + + count = 0; + size = 16; + a = malloc(size * sizeof(a[0])); + + for (index = 0; index < tplg_table_items; index++) { + tptr = &tplg_table[index]; + list = (struct list_head *)((void *)tplg + tptr->loff); + list_for_each(pos, list) { + elem = list_entry(pos, struct tplg_elem, list); + for (j = 0; j < count; j++) { + if (a[j] == elem->index) + break; + } + if (j < count) + continue; + if (count + 1 >= size) { + size += 8; + b = realloc(a, size * sizeof(a[0])); + if (b == NULL) { + free(a); + return -ENOMEM; + } + a = b; + } + a[count++] = elem->index; + } + } + a[count] = -1; + + qsort(a, count, sizeof(a[0]), tplg_index_compar); + + *indexes = a; + return 0; +} + +int snd_tplg_save(snd_tplg_t *tplg, char **dst, int flags) +{ + snd_input_t *in; + snd_config_t *top, *top2; + char *dst2; + int *indexes, *a; + int err; + + assert(tplg); + assert(dst); + *dst = NULL; + + if (flags & SND_TPLG_SAVE_GROUPS) { + err = tplg_index_groups(tplg, &indexes); + if (err < 0) + return err; + for (a = indexes; err >= 0 && *a >= 0; a++) { + err = tplg_save_printf(dst, NULL, + "IndexGroup.%d {\n", + *a); + if (err >= 0) + err = tplg_save(tplg, dst, *a, "\t"); + if (err >= 0) + err = tplg_save_printf(dst, NULL, "}\n"); + } + free(indexes); + } else { + err = tplg_save(tplg, dst, -1, NULL); + } + + if (err < 0) + goto _err; + + if (*dst == NULL) + return -EINVAL; + + if (flags & SND_TPLG_SAVE_NOCHECK) + return 0; + + /* always load configuration - check */ + err = snd_input_buffer_open(&in, *dst, strlen(*dst)); + if (err < 0) { + SNDERR("could not create input buffer"); + goto _err; + } + + err = snd_config_top(&top); + if (err < 0) { + snd_input_close(in); + goto _err; + } + + err = snd_config_load(top, in); + snd_input_close(in); + if (err < 0) { + SNDERR("could not load configuration"); + snd_config_delete(top); + goto _err; + } + + if (flags & SND_TPLG_SAVE_SORT) { + top2 = sort_config(NULL, top); + if (top2 == NULL) { + SNDERR("could not sort configuration"); + snd_config_delete(top); + err = -EINVAL; + goto _err; + } + snd_config_delete(top); + top = top2; + } + + dst2 = NULL; + err = save_config(&dst2, 0, NULL, top); + snd_config_delete(top); + if (err < 0) { + SNDERR("could not save configuration"); + goto _err; + } + + free(*dst); + *dst = dst2; + return 0; + +_err: + free(*dst); + *dst = NULL; + return err; +} diff --git a/src/topology/text.c b/src/topology/text.c index 72647fe..507c545 100644 --- a/src/topology/text.c +++ b/src/topology/text.c @@ -32,13 +32,13 @@ static int parse_text_values(snd_config_t *cfg, struct tplg_elem *elem) const char *value = NULL; int j = 0; - tplg_dbg(" Text Values: %s\n", elem->id); + tplg_dbg(" Text Values: %s", elem->id); snd_config_for_each(i, next, cfg) { n = snd_config_iterator_entry(i); if (j == SND_SOC_TPLG_NUM_TEXTS) { - tplg_dbg("error: text string number exceeds %d\n", j); + tplg_dbg("text string number exceeds %d", j); return -ENOMEM; } @@ -48,7 +48,7 @@ static int parse_text_values(snd_config_t *cfg, struct tplg_elem *elem) snd_strlcpy(&texts->items[j][0], value, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - tplg_dbg("\t%s\n", &texts->items[j][0]); + tplg_dbg("\t%s", &texts->items[j][0]); j++; } @@ -59,7 +59,7 @@ static int parse_text_values(snd_config_t *cfg, struct tplg_elem *elem) /* Parse Text data */ int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED) + void *private ATTRIBUTE_UNUSED) { snd_config_iterator_t i, next; snd_config_t *n; @@ -89,3 +89,22 @@ int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, return err; } + +/* save text data */ +int tplg_save_text(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + struct tplg_elem *elem, + char **dst, const char *pfx) +{ + struct tplg_texts *texts = elem->texts; + unsigned int i; + int err; + + if (!texts || texts->num_items == 0) + return 0; + err = tplg_save_printf(dst, pfx, "'%s'.values [\n", elem->id); + for (i = 0; err >= 0 && i < texts->num_items; i++) + err = tplg_save_printf(dst, pfx, "\t'%s'\n", texts->items[i][0]); + if (err >= 0) + err = tplg_save_printf(dst, pfx, "]\n"); + return err; +} diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h index c32267d..5ace0d1 100644 --- a/src/topology/tplg_local.h +++ b/src/topology/tplg_local.h @@ -18,8 +18,7 @@ #include "list.h" #include "topology.h" -#define __packed __attribute__((__packed__)) - +#include #include #include #include @@ -30,7 +29,6 @@ #define tplg_dbg(fmt, arg...) do { } while (0) #endif -#define MAX_FILE 256 #define TPLG_MAX_PRIV_SIZE (1024 * 128) /** The name of the environment variable containing the tplg directory */ @@ -38,6 +36,7 @@ struct tplg_ref; struct tplg_elem; +struct tplg_table; typedef enum _snd_pcm_rates { SND_PCM_RATE_UNKNOWN = -1, @@ -60,19 +59,17 @@ typedef enum _snd_pcm_rates { } snd_pcm_rates_t; struct snd_tplg { - - /* opaque vendor data */ - int vendor_fd; - char *vendor_name; - /* out file */ - int out_fd; + unsigned char *bin; + size_t bin_pos; + size_t bin_size; int verbose; + unsigned int dapm_sort: 1; unsigned int version; /* runtime state */ - unsigned int next_hdr_pos; + size_t next_hdr_pos; int index; int channel_idx; @@ -144,13 +141,16 @@ struct tplg_tuple_set { }; struct tplg_vendor_tuples { - unsigned int num_sets; + unsigned int num_sets; + unsigned int alloc_sets; struct tplg_tuple_set **set; }; /* topology element */ struct tplg_elem { + struct tplg_table *table; + char id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; int index; @@ -200,64 +200,69 @@ struct map_elem { int id; }; -int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg, - int (*fcn)(snd_tplg_t *, snd_config_t *, void *), - void *private); - -int tplg_write_data(snd_tplg_t *tplg); - -int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -void tplg_free_tuples(void *obj); - -int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -int tplg_parse_control_bytes(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); - -int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); - -int tplg_parse_control_mixer(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +/* mapping table */ +struct tplg_table { + const char *name; + const char *id; + const char *id2; + off_t loff; + size_t size; + int type; + int tsoc; + unsigned build: 1; + unsigned enew: 1; + void (*free)(void *); + int (*parse)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); + int (*save)(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *prefix); + int (*gsave)(snd_tplg_t *tplg, int index, + char **dst, const char *prefix); + int (*decod)(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +}; -int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); +extern struct tplg_table tplg_table[]; +extern unsigned int tplg_table_items; -int tplg_parse_dapm_widget(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +#define tplg_log(tplg, type, pos, fmt, args...) do { \ + if ((tplg)->verbose) \ + tplg_log_((tplg), (type), (pos), (fmt), ##args); \ +} while (0) -int tplg_parse_stream_caps(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +void tplg_log_(snd_tplg_t *tplg, char type, size_t pos, const char *fmt, ...); -int tplg_parse_pcm(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +void *tplg_calloc(struct list_head *heap, size_t size); +void tplg_free(struct list_head *heap); -int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); +int tplg_get_type(int asoc_type); -int tplg_parse_link(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg, + int (*fcn)(snd_tplg_t *, snd_config_t *, void *), + void *private); -int tplg_parse_cc(snd_tplg_t *tplg, - snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +int tplg_write_data(snd_tplg_t *tplg); -int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, - void *private ATTRIBUTE_UNUSED); +int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_control_mixer(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_dapm_widget(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_link(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); +int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, void *priv); + +unsigned int tplg_get_tuple_size(int type); +void tplg_free_tuples(void *obj); int tplg_build_data(snd_tplg_t *tplg); int tplg_build_manifest_data(snd_tplg_t *tplg); @@ -269,7 +274,8 @@ int tplg_build_pcm_dai(snd_tplg_t *tplg, unsigned int type); int tplg_copy_data(snd_tplg_t *tplg, struct tplg_elem *elem, struct tplg_ref *ref); -int tplg_parse_data_refs(snd_config_t *cfg, struct tplg_elem *elem); +int tplg_parse_refs(snd_config_t *cfg, struct tplg_elem *elem, + unsigned int type); int tplg_ref_add(struct tplg_elem *elem, int type, const char* id); int tplg_ref_add_elem(struct tplg_elem *elem, struct tplg_elem *elem_ref); @@ -277,16 +283,24 @@ int tplg_ref_add_elem(struct tplg_elem *elem, struct tplg_elem *elem_ref); struct tplg_elem *tplg_elem_new(void); void tplg_elem_free(struct tplg_elem *elem); void tplg_elem_free_list(struct list_head *base); +void tplg_elem_insert(struct tplg_elem *elem_p, struct list_head *list); struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id, unsigned int type, int index); +struct tplg_elem *tplg_elem_type_lookup(snd_tplg_t *tplg, + enum snd_tplg_type type); struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, snd_config_t *cfg, const char *name, enum snd_tplg_type type); +int tplg_get_integer(snd_config_t *n, int *val, int base); +int tplg_get_unsigned(snd_config_t *n, unsigned *val, int base); + +const char *tplg_channel_name(int type); int tplg_parse_channel(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_t *cfg, void *private); +const char *tplg_ops_name(int type); int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, snd_config_t *cfg, void *private); int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, @@ -295,6 +309,10 @@ int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, struct tplg_elem *lookup_pcm_dai_stream(struct list_head *base, const char* id); +int tplg_add_data(snd_tplg_t *tplg, struct tplg_elem *parent, + const void *bin, size_t size); +int tplg_add_data_bytes(snd_tplg_t *tplg, struct tplg_elem *parent, + const char *suffix, const void *bin, size_t size); int tplg_add_mixer_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); int tplg_add_enum_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); int tplg_add_bytes_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); @@ -314,3 +332,101 @@ int tplg_build_links(snd_tplg_t *tplg, unsigned int type); int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); int tplg_add_dai_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t); + +int tplg_nice_value_format(char *dst, size_t dst_size, unsigned int value); + +int tplg_save_printf(char **dst, const char *prefix, const char *fmt, ...); +int tplg_save_refs(snd_tplg_t *tplg, struct tplg_elem *elem, unsigned int type, + const char *id, char **dst, const char *pfx); +int tplg_save_channels(snd_tplg_t *tplg, struct snd_soc_tplg_channel *channel, + unsigned int channel_count, char **dst, const char *pfx); +int tplg_save_ops(snd_tplg_t *tplg, struct snd_soc_tplg_ctl_hdr *hdr, + char **dst, const char *pfx); +int tplg_save_ext_ops(snd_tplg_t *tplg, struct snd_soc_tplg_bytes_control *be, + char **dst, const char *pfx); +int tplg_save_manifest_data(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_control_mixer(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_control_enum(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_control_bytes(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_tlv(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_data(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_text(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_tokens(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_tuples(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_dapm_graph(snd_tplg_t *tplg, int index, + char **dst, const char *pfx); +int tplg_save_dapm_widget(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_link(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_cc(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_pcm(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_hw_config(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_stream_caps(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); +int tplg_save_dai(snd_tplg_t *tplg, struct tplg_elem *elem, + char **dst, const char *pfx); + +int tplg_decode_template(snd_tplg_t *tplg, + size_t pos, + struct snd_soc_tplg_hdr *hdr, + snd_tplg_obj_template_t *t); +int tplg_decode_manifest_data(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_control_mixer1(snd_tplg_t *tplg, + struct list_head *heap, + struct snd_tplg_mixer_template *mt, + size_t pos, + void *bin, size_t size); +int tplg_decode_control_mixer(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_control_enum1(snd_tplg_t *tplg, + struct list_head *heap, + struct snd_tplg_enum_template *et, + size_t pos, + void *bin, size_t size); +int tplg_decode_control_enum(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_control_bytes1(snd_tplg_t *tplg, + struct snd_tplg_bytes_template *bt, + size_t pos, + void *bin, size_t size); +int tplg_decode_control_bytes(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_data(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_dapm_graph(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_dapm_widget(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_link(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_cc(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_pcm(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); +int tplg_decode_dai(snd_tplg_t *tplg, size_t pos, + struct snd_soc_tplg_hdr *hdr, + void *bin, size_t size); diff --git a/src/ucm/Makefile.am b/src/ucm/Makefile.am index 41a679c..feb3c0c 100644 --- a/src/ucm/Makefile.am +++ b/src/ucm/Makefile.am @@ -1,6 +1,7 @@ EXTRA_LTLIBRARIES = libucm.la -libucm_la_SOURCES = utils.c parser.c ucm_cond.c ucm_subs.c main.c +libucm_la_SOURCES = utils.c parser.c ucm_cond.c ucm_subs.c ucm_include.c \ + ucm_regex.c main.c noinst_HEADERS = ucm_local.h diff --git a/src/ucm/Makefile.in b/src/ucm/Makefile.in index 9de5377..8156f99 100644 --- a/src/ucm/Makefile.in +++ b/src/ucm/Makefile.in @@ -105,7 +105,7 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = libucm_la_LIBADD = am_libucm_la_OBJECTS = utils.lo parser.lo ucm_cond.lo ucm_subs.lo \ - main.lo + ucm_include.lo ucm_regex.lo main.lo libucm_la_OBJECTS = $(am_libucm_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -127,7 +127,8 @@ DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/main.Plo ./$(DEPDIR)/parser.Plo \ - ./$(DEPDIR)/ucm_cond.Plo ./$(DEPDIR)/ucm_subs.Plo \ + ./$(DEPDIR)/ucm_cond.Plo ./$(DEPDIR)/ucm_include.Plo \ + ./$(DEPDIR)/ucm_regex.Plo ./$(DEPDIR)/ucm_subs.Plo \ ./$(DEPDIR)/utils.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ @@ -308,7 +309,9 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ EXTRA_LTLIBRARIES = libucm.la -libucm_la_SOURCES = utils.c parser.c ucm_cond.c ucm_subs.c main.c +libucm_la_SOURCES = utils.c parser.c ucm_cond.c ucm_subs.c ucm_include.c \ + ucm_regex.c main.c + noinst_HEADERS = ucm_local.h AM_CPPFLAGS = -I$(top_srcdir)/include all: all-am @@ -357,6 +360,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parser.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucm_cond.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucm_include.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucm_regex.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ucm_subs.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Plo@am__quote@ # am--include-marker @@ -520,6 +525,8 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/main.Plo -rm -f ./$(DEPDIR)/parser.Plo -rm -f ./$(DEPDIR)/ucm_cond.Plo + -rm -f ./$(DEPDIR)/ucm_include.Plo + -rm -f ./$(DEPDIR)/ucm_regex.Plo -rm -f ./$(DEPDIR)/ucm_subs.Plo -rm -f ./$(DEPDIR)/utils.Plo -rm -f Makefile @@ -570,6 +577,8 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/main.Plo -rm -f ./$(DEPDIR)/parser.Plo -rm -f ./$(DEPDIR)/ucm_cond.Plo + -rm -f ./$(DEPDIR)/ucm_include.Plo + -rm -f ./$(DEPDIR)/ucm_regex.Plo -rm -f ./$(DEPDIR)/ucm_subs.Plo -rm -f ./$(DEPDIR)/utils.Plo -rm -f Makefile diff --git a/src/ucm/main.c b/src/ucm/main.c index b0b6ffb..9e43ac6 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -61,11 +61,13 @@ static int check_identifier(const char *identifier, const char *prefix) { int len; - if (strcmp(identifier, prefix) == 0) - return 1; len = strlen(prefix); - if (memcmp(identifier, prefix, len) == 0 && identifier[len] == '/') + if (strncmp(identifier, prefix, len) != 0) + return 0; + + if (identifier[len] == 0 || identifier[len] == '/') return 1; + return 0; } @@ -331,6 +333,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, struct sequence_element *s; char *cdev = NULL; snd_ctl_t *ctl = NULL; + struct ctl_list *ctl_list; int err = 0; list_for_each(pos, seq) { @@ -398,11 +401,12 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, } } if (ctl == NULL) { - err = uc_mgr_open_ctl(uc_mgr, &ctl, cdev); + err = uc_mgr_open_ctl(uc_mgr, &ctl_list, cdev, 1); if (err < 0) { uc_error("unable to open ctl device '%s'", cdev); goto __fail; } + ctl = ctl_list->ctl; } err = execute_cset(ctl, s->data.cset, s->type); if (err < 0) { @@ -514,7 +518,7 @@ static int add_auto_values(snd_use_case_mgr_t *uc_mgr) char buf[40]; int err; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list) { id = snd_ctl_card_info_get_id(ctl_list->ctl_info); snprintf(buf, sizeof(buf), "hw:%s", id); @@ -529,6 +533,27 @@ static int add_auto_values(snd_use_case_mgr_t *uc_mgr) } /** + * \brief execute default commands + * \param uc_mgr Use case manager + * \return zero on success, otherwise a negative error code + */ +static int set_defaults(snd_use_case_mgr_t *uc_mgr) +{ + int err; + + if (uc_mgr->default_list_executed) + return 0; + err = execute_sequence(uc_mgr, &uc_mgr->default_list, + &uc_mgr->value_list, NULL, NULL); + if (err < 0) { + uc_error("Unable to execute default sequence"); + return err; + } + uc_mgr->default_list_executed = 1; + return 0; +} + +/** * \brief Import master config and execute the default sequence * \param uc_mgr Use case manager * \return zero on success, otherwise a negative error code @@ -540,14 +565,7 @@ static int import_master_config(snd_use_case_mgr_t *uc_mgr) err = uc_mgr_import_master_config(uc_mgr); if (err < 0) return err; - err = add_auto_values(uc_mgr); - if (err < 0) - return err; - err = execute_sequence(uc_mgr, &uc_mgr->default_list, - &uc_mgr->value_list, NULL, NULL); - if (err < 0) - uc_error("Unable to execute default sequence"); - return err; + return add_auto_values(uc_mgr); } /** @@ -843,6 +861,9 @@ static int set_verb(snd_use_case_mgr_t *uc_mgr, int err; if (enable) { + err = set_defaults(uc_mgr); + if (err < 0) + return err; seq = &verb->enable_list; } else { seq = &verb->disable_list; @@ -941,11 +962,13 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr, if (mgr == NULL) return -ENOMEM; INIT_LIST_HEAD(&mgr->verb_list); + INIT_LIST_HEAD(&mgr->once_list); INIT_LIST_HEAD(&mgr->default_list); INIT_LIST_HEAD(&mgr->value_list); INIT_LIST_HEAD(&mgr->active_modifiers); INIT_LIST_HEAD(&mgr->active_devices); INIT_LIST_HEAD(&mgr->ctl_list); + INIT_LIST_HEAD(&mgr->variable_list); pthread_mutex_init(&mgr->mutex, NULL); mgr->card_name = strdup(card_name); @@ -983,6 +1006,8 @@ int snd_use_case_mgr_reload(snd_use_case_mgr_t *uc_mgr) uc_mgr_free_verb(uc_mgr); + uc_mgr->default_list_executed = 0; + /* reload all use cases */ err = import_master_config(uc_mgr); if (err < 0) { @@ -1070,7 +1095,6 @@ int snd_use_case_mgr_reset(snd_use_case_mgr_t *uc_mgr) /** * \brief Get list of verbs in pair verbname+comment * \param list Returned list - * \param verbname For verb (NULL = current) * \return Number of list entries if success, otherwise a negative error code */ static int get_verb_list(snd_use_case_mgr_t *uc_mgr, const char **list[]) @@ -1158,8 +1182,10 @@ static int get_supcon_device_list(snd_use_case_mgr_t *uc_mgr, modifier = find_modifier(uc_mgr, verb, name, 0); if (modifier) { - if (modifier->dev_list.type != type) + if (modifier->dev_list.type != type) { + *list = NULL; return 0; + } return get_list(&modifier->dev_list.list, list, struct dev_list_node, list, name); @@ -1167,15 +1193,16 @@ static int get_supcon_device_list(snd_use_case_mgr_t *uc_mgr, device = find_device(uc_mgr, verb, name, 0); if (device) { - if (device->dev_list.type != type) + if (device->dev_list.type != type) { + *list = NULL; return 0; + } return get_list(&device->dev_list.list, list, struct dev_list_node, list, name); } return -ENOENT; - } /** @@ -1204,41 +1231,201 @@ static int get_conflicting_device_list(snd_use_case_mgr_t *uc_mgr, #ifndef DOC_HIDDEN struct myvalue { - struct list_head list; - char *value; + struct list_head list; + const char *text; }; #endif +/** + * \brief Convert myvalue list string list + * \param list myvalue list + * \param res string list + * \retval Number of list entries if success, otherwise a negativer error code + */ +static int myvalue_to_str_list(struct list_head *list, char ***res) +{ + struct list_head *pos; + struct myvalue *value; + char **p; + int cnt; + + cnt = alloc_str_list(list, 1, res); + if (cnt < 0) + return cnt; + p = *res; + list_for_each(pos, list) { + value = list_entry(pos, struct myvalue, list); + *p = strdup(value->text); + if (*p == NULL) { + snd_use_case_free_list((const char **)p, cnt); + return -ENOMEM; + } + p++; + } + return cnt; +} + +/** + * \brief Free myvalue list + * \param list myvalue list + */ +static void myvalue_list_free(struct list_head *list) +{ + struct list_head *pos, *npos; + struct myvalue *value; + + list_for_each_safe(pos, npos, list) { + value = list_entry(pos, struct myvalue, list); + list_del(&value->list); + free(value); + } +} + +/** + * \brief Merge one value to the myvalue list + * \param list The list with values + * \param value The value to be merged (without duplicates) + * \return 1 if dup, 0 if success, otherwise a negative error code + */ +static int merge_value(struct list_head *list, const char *text) +{ + struct list_head *pos; + struct myvalue *value; + + list_for_each(pos, list) { + value = list_entry(pos, struct myvalue, list); + if (strcmp(value->text, text) == 0) + return 1; + } + value = malloc(sizeof(*value)); + if (value == NULL) + return -ENOMEM; + value->text = text; + list_add_tail(&value->list, list); + return 0; +} + +/** + * \brief Find all values for given identifier + * \param list Returned list + * \param source Source list with ucm_value structures + * \return Zero if success, otherwise a negative error code + */ +static int add_identifiers(struct list_head *list, + struct list_head *source) +{ + struct ucm_value *v; + struct list_head *pos; + int err; + + list_for_each(pos, source) { + v = list_entry(pos, struct ucm_value, list); + err = merge_value(list, v->name); + if (err < 0) + return err; + } + return 0; +} + +/** + * \brief Find all values for given identifier + * \param list Returned list + * \param identifier Identifier + * \param source Source list with ucm_value structures + */ static int add_values(struct list_head *list, const char *identifier, struct list_head *source) { - struct ucm_value *v; - struct myvalue *val; - struct list_head *pos, *pos1; - int match; + struct ucm_value *v; + struct list_head *pos; + int err; - list_for_each(pos, source) { - v = list_entry(pos, struct ucm_value, list); - if (check_identifier(identifier, v->name)) { - match = 0; - list_for_each(pos1, list) { - val = list_entry(pos1, struct myvalue, list); - if (strcmp(val->value, v->data) == 0) { - match = 1; - break; - } - } - if (!match) { - val = malloc(sizeof(struct myvalue)); - if (val == NULL) - return -ENOMEM; - val->value = v->data; - list_add_tail(&val->list, list); - } - } - } - return 0; + list_for_each(pos, source) { + v = list_entry(pos, struct ucm_value, list); + if (check_identifier(identifier, v->name)) { + err = merge_value(list, v->data); + if (err < 0) + return err; + } + } + return 0; +} + +/** + * \brief compare two identifiers + */ +static int identifier_cmp(const void *_a, const void *_b) +{ + const char * const *a = _a; + const char * const *b = _b; + return strcmp(*a, *b); +} + +/** + * \brief Get list of available identifiers + * \param list Returned list + * \param name Name of verb or modifier to query + * \return Number of list entries if success, otherwise a negative error code + */ +static int get_identifiers_list(snd_use_case_mgr_t *uc_mgr, + const char **list[], char *name) +{ + struct use_case_verb *verb; + struct use_case_modifier *modifier; + struct use_case_device *device; + struct list_head mylist; + struct list_head *value_list; + char *str, **res; + int err; + + if (!name) + return -ENOENT; + + str = strchr(name, '/'); + if (str) { + *str = '\0'; + verb = find_verb(uc_mgr, str + 1); + } + else { + verb = uc_mgr->active_verb; + } + if (!verb) + return -ENOENT; + + value_list = NULL; + modifier = find_modifier(uc_mgr, verb, name, 0); + if (modifier) { + value_list = &modifier->value_list; + } else { + device = find_device(uc_mgr, verb, name, 0); + if (device) + value_list = &device->value_list; + } + if (value_list == NULL) + return -ENOENT; + + INIT_LIST_HEAD(&mylist); + err = add_identifiers(&mylist, &uc_mgr->value_list); + if (err < 0) + goto __fail; + err = add_identifiers(&mylist, &verb->value_list); + if (err < 0) + goto __fail; + err = add_identifiers(&mylist, value_list); + if (err < 0) + goto __fail; + err = myvalue_to_str_list(&mylist, &res); + if (err > 0) + *list = (const char **)res; + else if (err == 0) + *list = NULL; +__fail: + myvalue_list_free(&mylist); + if (err <= 0) + return err; + qsort(*list, err, sizeof(char *), identifier_cmp); + return err; } /** @@ -1252,8 +1439,7 @@ static int get_value_list(snd_use_case_mgr_t *uc_mgr, const char **list[], char *verbname) { - struct list_head mylist, *pos, *npos; - struct myvalue *val; + struct list_head mylist, *pos; struct use_case_verb *verb; struct use_case_device *dev; struct use_case_modifier *mod; @@ -1286,26 +1472,13 @@ static int get_value_list(snd_use_case_mgr_t *uc_mgr, if (err < 0) goto __fail; } - err = alloc_str_list(&mylist, 1, &res); - if (err >= 0) { + err = myvalue_to_str_list(&mylist, &res); + if (err > 0) *list = (const char **)res; - list_for_each(pos, &mylist) { - val = list_entry(pos, struct myvalue, list); - *res = strdup(val->value); - if (*res == NULL) { - snd_use_case_free_list((const char **)res, err); - err = -ENOMEM; - goto __fail; - } - res++; - } - } + else if (err == 0) + *list = NULL; __fail: - list_for_each_safe(pos, npos, &mylist) { - val = list_entry(pos, struct myvalue, list); - list_del(&val->list); - free(val); - } + myvalue_list_free(&mylist); return err; } @@ -1375,21 +1548,23 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, } else { str = NULL; } - if (check_identifier(identifier, "_devices")) - err = get_device_list(uc_mgr, list, str); + if (check_identifier(identifier, "_devices")) + err = get_device_list(uc_mgr, list, str); else if (check_identifier(identifier, "_modifiers")) - err = get_modifier_list(uc_mgr, list, str); - else if (check_identifier(identifier, "_supporteddevs")) - err = get_supported_device_list(uc_mgr, list, str); - else if (check_identifier(identifier, "_conflictingdevs")) - err = get_conflicting_device_list(uc_mgr, list, str); + err = get_modifier_list(uc_mgr, list, str); + else if (check_identifier(identifier, "_identifiers")) + err = get_identifiers_list(uc_mgr, list, str); + else if (check_identifier(identifier, "_supporteddevs")) + err = get_supported_device_list(uc_mgr, list, str); + else if (check_identifier(identifier, "_conflictingdevs")) + err = get_conflicting_device_list(uc_mgr, list, str); else if (identifier[0] == '_') err = -ENOENT; - else - err = get_value_list(uc_mgr, identifier, list, str); - if (str) - free(str); - } + else + err = get_value_list(uc_mgr, identifier, list, str); + if (str) + free(str); + } __end: pthread_mutex_unlock(&uc_mgr->mutex); return err; @@ -1548,12 +1723,13 @@ int snd_use_case_get(snd_use_case_mgr_t *uc_mgr, err = 0; } else if (strcmp(identifier, "_file") == 0) { /* get the conf file name of the opened card */ - if ((uc_mgr->card_name == NULL) - || (uc_mgr->conf_file_name[0] == '\0')) { + if ((uc_mgr->card_name == NULL) || + (uc_mgr->conf_file_name == NULL) || + (uc_mgr->conf_file_name[0] == '\0')) { err = -ENOENT; goto __end; } - *value = strndup(uc_mgr->conf_file_name, MAX_FILE); + *value = strdup(uc_mgr->conf_file_name); if (*value == NULL) { err = -ENOMEM; goto __end; @@ -1673,6 +1849,34 @@ int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr, return err; } +static int set_boot_user(snd_use_case_mgr_t *uc_mgr, + const char *value) +{ + int err; + + if (value != NULL && *value) { + uc_error("error: wrong value for _boot (%s)", value); + return -EINVAL; + } + err = execute_sequence(uc_mgr, &uc_mgr->once_list, + &uc_mgr->value_list, NULL, NULL); + if (err < 0) { + uc_error("Unable to execute once sequence"); + return err; + } + return err; +} + +static int set_defaults_user(snd_use_case_mgr_t *uc_mgr, + const char *value) +{ + if (value != NULL && *value) { + uc_error("error: wrong value for _defaults (%s)", value); + return -EINVAL; + } + return set_defaults(uc_mgr); +} + static int handle_transition_verb(snd_use_case_mgr_t *uc_mgr, struct use_case_verb *new_verb) { @@ -1884,7 +2088,11 @@ int snd_use_case_set(snd_use_case_mgr_t *uc_mgr, int err = 0; pthread_mutex_lock(&uc_mgr->mutex); - if (strcmp(identifier, "_verb") == 0) + if (strcmp(identifier, "_boot") == 0) + err = set_boot_user(uc_mgr, value); + else if (strcmp(identifier, "_defaults") == 0) + err = set_defaults_user(uc_mgr, value); + else if (strcmp(identifier, "_verb") == 0) err = set_verb_user(uc_mgr, value); else if (strcmp(identifier, "_enadev") == 0) err = set_device_user(uc_mgr, value, 1); @@ -1963,8 +2171,10 @@ int snd_use_case_parse_selem_id(snd_mixer_selem_id_t *dst, const char *ucm_id, const char *value) { +#ifdef BUILD_MIXER if (strcmp(ucm_id, "PlaybackMixerId") == 0 || strcmp(ucm_id, "CaptureMixerId") == 0) return snd_mixer_selem_id_parse(dst, value); +#endif return -EINVAL; } diff --git a/src/ucm/parser.c b/src/ucm/parser.c index ba50027..3b7fc93 100644 --- a/src/ucm/parser.c +++ b/src/ucm/parser.c @@ -62,64 +62,50 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg); /* - * compose configuration file + * compose the absolute ucm filename */ -static void configuration_filename2(char *fn, size_t fn_len, int format, - const char *dir, const char *file, - const char *suffix) +static void ucm_filename(char *fn, size_t fn_len, long version, + const char *dir, const char *file) { - snprintf(fn, fn_len, "%s/ucm%s/%s/%s%s", - snd_config_topdir(), format >= 2 ? "2" : "", - dir, file, suffix); + const char *env = getenv(version > 1 ? ALSA_CONFIG_UCM2_VAR : ALSA_CONFIG_UCM_VAR); + + if (env == NULL) + snprintf(fn, fn_len, "%s/%s/%s%s%s", + snd_config_topdir(), version > 1 ? "ucm2" : "ucm", + dir ?: "", dir ? "/" : "", file); + else + snprintf(fn, fn_len, "%s/%s%s%s", + env, dir ?: "", dir ? "/" : "", file); } -static void configuration_filename(snd_use_case_mgr_t *uc_mgr, - char *fn, size_t fn_len, - const char *dir, const char *file, - const char *suffix) +/* + * + */ +int uc_mgr_config_load_file(snd_use_case_mgr_t *uc_mgr, + const char *file, snd_config_t **cfg) { - const char *env; - - if (uc_mgr->conf_format > 0) { - /* known format */ - env = getenv(uc_mgr->conf_format >= 2 ? ALSA_CONFIG_UCM2_VAR : - ALSA_CONFIG_UCM_VAR); - } else { - /* auto-detect */ - env = getenv(ALSA_CONFIG_UCM2_VAR); - if (env == NULL) { - env = getenv(ALSA_CONFIG_UCM_VAR); - } else { - uc_mgr->conf_format = 2; - } - } - if (env) { - snprintf(fn, fn_len, "%s/%s/%s%s", env, dir, file, suffix); - return; - } - - if (uc_mgr->conf_format > 0) { - configuration_filename2(fn, fn_len, uc_mgr->conf_format, - dir, file, suffix); - return; - } - - configuration_filename2(fn, fn_len, 2, dir, file, suffix); - if (access(fn, R_OK) == 0) { - /* Found an ucm2 file, only look in the ucm2 dir from now on */ - uc_mgr->conf_format = 2; - return; - } + char filename[PATH_MAX]; + int err; - configuration_filename2(fn, fn_len, 0, dir, file, suffix); - if (access(fn, R_OK) == 0) { - /* Found an ucm1 file, only look in the ucm dir from now on */ - uc_mgr->conf_format = 1; - return; + ucm_filename(filename, sizeof(filename), uc_mgr->conf_format, + file[0] == '/' ? NULL : uc_mgr->conf_dir_name, + file); + err = uc_mgr_config_load(uc_mgr->conf_format, filename, cfg); + if (err < 0) { + uc_error("error: failed to open file %s : %d", filename, -errno); + return err; } + return 0; +} - /* make sure that the error message refers to the new path */ - configuration_filename2(fn, fn_len, 2, dir, file, suffix); +/* + * Replace mallocated string + */ +static char *replace_string(char **dst, const char *value) +{ + free(*dst); + *dst = value ? strdup(value) : NULL; + return *dst; } /* @@ -139,6 +125,80 @@ int parse_string(snd_config_t *n, char **res) } /* + * Parse string and substitute + */ +int parse_string_substitute(snd_use_case_mgr_t *uc_mgr, + snd_config_t *n, char **res) +{ + const char *str; + char *s; + int err; + + err = snd_config_get_string(n, &str); + if (err < 0) + return err; + err = uc_mgr_get_substituted_value(uc_mgr, &s, str); + if (err >= 0) + *res = s; + return err; +} + +/* + * Parse string and substitute + */ +int parse_string_substitute3(snd_use_case_mgr_t *uc_mgr, + snd_config_t *n, char **res) +{ + if (uc_mgr->conf_format < 3) + return parse_string(n, res); + return parse_string_substitute(uc_mgr, n, res); +} + +/* + * Parse integer with substitution + */ +int parse_integer_substitute(snd_use_case_mgr_t *uc_mgr, + snd_config_t *n, long *res) +{ + char *s1, *s2; + int err; + + err = snd_config_get_ascii(n, &s1); + if (err < 0) + return err; + err = uc_mgr_get_substituted_value(uc_mgr, &s2, s1); + if (err >= 0) + err = safe_strtol(s2, res); + free(s2); + free(s1); + return err; +} + +/* + * Parse integer with substitution + */ +int parse_integer_substitute3(snd_use_case_mgr_t *uc_mgr, + snd_config_t *n, long *res) +{ + char *s1, *s2; + int err; + + err = snd_config_get_ascii(n, &s1); + if (err < 0) + return err; + if (uc_mgr->conf_format < 3) + s2 = s1; + else + err = uc_mgr_get_substituted_value(uc_mgr, &s2, s1); + if (err >= 0) + err = safe_strtol(s2, res); + if (s1 != s2) + free(s2); + free(s1); + return err; +} + +/* * Parse safe ID */ int parse_is_name_safe(const char *name) @@ -150,19 +210,146 @@ int parse_is_name_safe(const char *name) return 1; } -int parse_get_safe_id(snd_config_t *n, const char **id) +int get_string3(snd_use_case_mgr_t *uc_mgr, const char *s1, char **s) +{ + if (uc_mgr->conf_format < 3) { + *s = strdup(s1); + if (*s == NULL) + return -ENOMEM; + return 0; + } + return uc_mgr_get_substituted_value(uc_mgr, s, s1); +} + +int parse_get_safe_name(snd_use_case_mgr_t *uc_mgr, snd_config_t *n, + const char *alt, char **name) +{ + const char *id; + int err; + + if (alt) { + id = alt; + } else { + err = snd_config_get_id(n, &id); + if (err < 0) + return err; + } + if (!parse_is_name_safe(id)) + return -EINVAL; + return get_string3(uc_mgr, id, name); +} + +/* + * Evaluate variable regex definitions (in-place delete) + */ +static int evaluate_regex(snd_use_case_mgr_t *uc_mgr, + snd_config_t *cfg) { + snd_config_iterator_t i, next; + snd_config_t *d, *n; + const char *id; int err; - err = snd_config_get_id(n, id); + err = snd_config_search(cfg, "DefineRegex", &d); + if (err == -ENOENT) + return 1; if (err < 0) return err; - if (!parse_is_name_safe((char *)(*id))) + + if (snd_config_get_type(d) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for DefineRegex"); return -EINVAL; + } + + if (uc_mgr->conf_format < 3) { + uc_error("DefineRegex is supported in v3+ syntax"); + return -EINVAL; + } + + snd_config_for_each(i, next, d) { + n = snd_config_iterator_entry(i); + err = snd_config_get_id(n, &id); + if (err < 0) + return err; + err = uc_mgr_define_regex(uc_mgr, id, n); + if (err < 0) + return err; + } + + snd_config_delete(d); return 0; } /* + * Evaluate variable definitions (in-place delete) + */ +static int evaluate_define(snd_use_case_mgr_t *uc_mgr, + snd_config_t *cfg) +{ + snd_config_iterator_t i, next; + snd_config_t *d, *n; + const char *id; + char *var, *s; + int err; + + err = snd_config_search(cfg, "Define", &d); + if (err == -ENOENT) + return evaluate_regex(uc_mgr, cfg); + if (err < 0) + return err; + + if (snd_config_get_type(d) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for Define"); + return -EINVAL; + } + + if (uc_mgr->conf_format < 3) { + uc_error("Define is supported in v3+ syntax"); + return -EINVAL; + } + + snd_config_for_each(i, next, d) { + n = snd_config_iterator_entry(i); + err = snd_config_get_id(n, &id); + if (err < 0) + return err; + err = snd_config_get_ascii(n, &var); + if (err < 0) + return err; + err = uc_mgr_get_substituted_value(uc_mgr, &s, var); + free(var); + if (err < 0) + return err; + uc_mgr_set_variable(uc_mgr, id, s); + free(s); + } + + snd_config_delete(d); + + return evaluate_regex(uc_mgr, cfg); +} + +/* + * Evaluate include (in-place) + */ +static int evaluate_include(snd_use_case_mgr_t *uc_mgr, + snd_config_t *cfg) +{ + snd_config_t *n; + int err; + + err = snd_config_search(cfg, "Include", &n); + if (err == -ENOENT) + return 1; + if (err < 0) + return err; + + err = uc_mgr_evaluate_include(uc_mgr, cfg, n); + snd_config_delete(n); + return err; +} + +/* * Evaluate condition (in-place) */ static int evaluate_condition(snd_use_case_mgr_t *uc_mgr, @@ -173,7 +360,7 @@ static int evaluate_condition(snd_use_case_mgr_t *uc_mgr, err = snd_config_search(cfg, "If", &n); if (err == -ENOENT) - return 0; + return 1; if (err < 0) return err; @@ -183,6 +370,34 @@ static int evaluate_condition(snd_use_case_mgr_t *uc_mgr, } /* + * In-place evaluate + */ +int uc_mgr_evaluate_inplace(snd_use_case_mgr_t *uc_mgr, + snd_config_t *cfg) +{ + int err1 = 0, err2 = 0, err3 = 0; + + while (err1 == 0 || err2 == 0 || err3 == 0) { + /* variables at first */ + err1 = evaluate_define(uc_mgr, cfg); + if (err1 < 0) + return err1; + /* include at second */ + err2 = evaluate_include(uc_mgr, cfg); + if (err2 < 0) + return err2; + /* include may define another variables */ + /* conditions may depend on them */ + if (err2 == 0) + continue; + err3 = evaluate_condition(uc_mgr, cfg); + if (err3 < 0) + return err3; + } + return 0; +} + +/* * Parse transition */ static int parse_transition(snd_use_case_mgr_t *uc_mgr, @@ -214,10 +429,10 @@ static int parse_transition(snd_use_case_mgr_t *uc_mgr, return -ENOMEM; INIT_LIST_HEAD(&tseq->transition_list); - tseq->name = strdup(id); - if (tseq->name == NULL) { + err = get_string3(uc_mgr, id, &tseq->name); + if (err < 0) { free(tseq); - return -ENOMEM; + return err; } err = parse_sequence(uc_mgr, &tseq->transition_list, n); @@ -318,7 +533,7 @@ static int parse_device_list(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, sdev = calloc(1, sizeof(struct dev_list_node)); if (sdev == NULL) return -ENOMEM; - err = parse_string(n, &sdev->name); + err = parse_string_substitute3(uc_mgr, n, &sdev->name); if (err < 0) { free(sdev); return err; @@ -391,21 +606,23 @@ struct use_case_device *find_component_dev(snd_use_case_mgr_t *uc_mgr, * disable sequence is needed by its parenet device. */ static int parse_component_seq(snd_use_case_mgr_t *uc_mgr, - snd_config_t *n, int enable, - struct component_sequence *cmpt_seq) + snd_config_t *n, int enable, + struct component_sequence *cmpt_seq) { - const char *val; + char *val; int err; - err = snd_config_get_string(n, &val); + err = parse_string_substitute3(uc_mgr, n, &val); if (err < 0) return err; cmpt_seq->device = find_component_dev(uc_mgr, val); if (!cmpt_seq->device) { uc_error("error: Cannot find component device %s", val); + free(val); return -EINVAL; } + free(val); /* Parent needs its enable or disable sequence */ cmpt_seq->enable = enable; @@ -470,7 +687,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "cdev") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_CDEV; - err = parse_string(n, &curr->data.cdev); + err = parse_string_substitute3(uc_mgr, n, &curr->data.cdev); if (err < 0) { uc_error("error: cdev requires a string!"); return err; @@ -480,7 +697,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "cset") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_CSET; - err = parse_string(n, &curr->data.cset); + err = parse_string_substitute3(uc_mgr, n, &curr->data.cset); if (err < 0) { uc_error("error: cset requires a string!"); return err; @@ -514,7 +731,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "cset-bin-file") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE; - err = parse_string(n, &curr->data.cset); + err = parse_string_substitute3(uc_mgr, n, &curr->data.cset); if (err < 0) { uc_error("error: cset-bin-file requires a string!"); return err; @@ -524,7 +741,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "cset-tlv") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_CSET_TLV; - err = parse_string(n, &curr->data.cset); + err = parse_string_substitute3(uc_mgr, n, &curr->data.cset); if (err < 0) { uc_error("error: cset-tlv requires a string!"); return err; @@ -534,7 +751,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "usleep") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP; - err = snd_config_get_integer(n, &curr->data.sleep); + err = parse_integer_substitute3(uc_mgr, n, &curr->data.sleep); if (err < 0) { uc_error("error: usleep requires integer!"); return err; @@ -544,7 +761,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "msleep") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP; - err = snd_config_get_integer(n, &curr->data.sleep); + err = parse_integer_substitute3(uc_mgr, n, &curr->data.sleep); if (err < 0) { uc_error("error: msleep requires integer!"); return err; @@ -555,7 +772,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr, if (strcmp(cmd, "exec") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_EXEC; - err = parse_string(n, &curr->data.exec); + err = parse_string_substitute3(uc_mgr, n, &curr->data.exec); if (err < 0) { uc_error("error: exec requires a string!"); return err; @@ -617,8 +834,8 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, return -EINVAL; } - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); if (err < 0) return err; @@ -641,7 +858,7 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, } break; case SND_CONFIG_TYPE_STRING: - err = parse_string(n, &s); + err = parse_string_substitute(uc_mgr, n, &s); if (err < 0) { uc_error("error: unable to parse a string for id '%s'!", id); return err; @@ -664,82 +881,75 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, /* * Parse Modifier Use cases * - * # Each modifier is described in new section. N modifiers are allowed - * SectionModifier."Capture Voice" { - * - * Comment "Record voice call" + * # Each modifier is described in new section. N modifiers are allowed + * SectionModifier."Capture Voice" { * - * SupportedDevice [ - * "x" - * "y" - * ] + * Comment "Record voice call" * - * ConflictingDevice [ - * "x" - * "y" - * ] + * SupportedDevice [ + * "x" + * "y" + * ] * - * EnableSequence [ - * .... - * ] + * ConflictingDevice [ + * "x" + * "y" + * ] * - * DisableSequence [ - * ... - * ] + * EnableSequence [ + * .... + * ] * - * TransitionSequence."ToModifierName" [ - * ... - * ] + * DisableSequence [ + * ... + * ] * - * # Optional TQ and ALSA PCMs - * Value { - * TQ Voice - * CapturePCM "hw:1" - * PlaybackVolume "name='Master Playback Volume',index=2" - * PlaybackSwitch "name='Master Playback Switch',index=2" - * } + * TransitionSequence."ToModifierName" [ + * ... + * ] * - * } + * # Optional TQ and ALSA PCMs + * Value { + * TQ Voice + * CapturePCM "hw:1" + * PlaybackVolume "name='Master Playback Volume',index=2" + * PlaybackSwitch "name='Master Playback Switch',index=2" + * } + * } * * SupportedDevice and ConflictingDevice cannot be specified together. * Both are optional. */ static int parse_modifier(snd_use_case_mgr_t *uc_mgr, - snd_config_t *cfg, - void *data1, - void *data2) + snd_config_t *cfg, + void *data1, void *data2) { struct use_case_verb *verb = data1; struct use_case_modifier *modifier; - const char *name; + char *name; snd_config_iterator_t i, next; snd_config_t *n; int err; - if (data2) { - name = data2; - if (!parse_is_name_safe(name)) - return -EINVAL; - } - else { - if (parse_get_safe_id(cfg, &name) < 0) - return -EINVAL; - } + if (parse_get_safe_name(uc_mgr, cfg, data2, &name) < 0) + return -EINVAL; /* allocate modifier */ modifier = calloc(1, sizeof(*modifier)); - if (modifier == NULL) + if (modifier == NULL) { + free(name); return -ENOMEM; + } INIT_LIST_HEAD(&modifier->enable_list); INIT_LIST_HEAD(&modifier->disable_list); INIT_LIST_HEAD(&modifier->transition_list); INIT_LIST_HEAD(&modifier->dev_list.list); INIT_LIST_HEAD(&modifier->value_list); list_add_tail(&modifier->list, &verb->modifier_list); - modifier->name = strdup(name); + modifier->name = name; - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); if (err < 0) return err; @@ -750,7 +960,7 @@ static int parse_modifier(snd_use_case_mgr_t *uc_mgr, continue; if (strcmp(id, "Comment") == 0) { - err = parse_string(n, &modifier->comment); + err = parse_string_substitute3(uc_mgr, n, &modifier->comment); if (err < 0) { uc_error("error: failed to get modifier comment"); return err; @@ -824,11 +1034,11 @@ static int parse_modifier(snd_use_case_mgr_t *uc_mgr, /* * Parse Device Use Cases * - *# Each device is described in new section. N devices are allowed - *SectionDevice."Headphones" { + * # Each device is described in new section. N devices are allowed + * SectionDevice."Headphones" { * Comment "Headphones connected to 3.5mm jack" * - * upportedDevice [ + * SupportedDevice [ * "x" * "y" * ] @@ -858,39 +1068,33 @@ static int parse_modifier(snd_use_case_mgr_t *uc_mgr, */ static int parse_device(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg, - void *data1, - void *data2) + void *data1, void *data2) { struct use_case_verb *verb = data1; - const char *name; + char *name; struct use_case_device *device; snd_config_iterator_t i, next; snd_config_t *n; int err; - if (data2) { - name = data2; - if (!parse_is_name_safe(name)) - return -EINVAL; - } - else { - if (parse_get_safe_id(cfg, &name) < 0) - return -EINVAL; - } + if (parse_get_safe_name(uc_mgr, cfg, data2, &name) < 0) + return -EINVAL; device = calloc(1, sizeof(*device)); - if (device == NULL) + if (device == NULL) { + free(name); return -ENOMEM; + } INIT_LIST_HEAD(&device->enable_list); INIT_LIST_HEAD(&device->disable_list); INIT_LIST_HEAD(&device->transition_list); INIT_LIST_HEAD(&device->dev_list.list); INIT_LIST_HEAD(&device->value_list); list_add_tail(&device->list, &verb->device_list); - device->name = strdup(name); + device->name = name; - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); if (err < 0) return err; @@ -901,7 +1105,7 @@ static int parse_device(snd_use_case_mgr_t *uc_mgr, continue; if (strcmp(id, "Comment") == 0) { - err = parse_string(n, &device->comment); + err = parse_string_substitute3(uc_mgr, n, &device->comment); if (err < 0) { uc_error("error: failed to get device comment"); return err; @@ -974,6 +1178,82 @@ static int parse_device(snd_use_case_mgr_t *uc_mgr, return 0; } +/* + * Parse Device Rename/Delete Command + * + * # The devices might be renamed to allow the better conditional runtime + * # evaluation. Bellow example renames Speaker1 device to Speaker and + * # removes Speaker2 device. + * RenameDevice."Speaker1" "Speaker" + * RemoveDevice."Speaker2" "Speaker2" + */ +static int parse_dev_name_list(snd_use_case_mgr_t *uc_mgr, + snd_config_t *cfg, + struct list_head *list) +{ + snd_config_t *n; + snd_config_iterator_t i, next; + const char *id, *name1; + char *name1s, *name2; + struct ucm_dev_name *dev; + snd_config_iterator_t pos; + int err; + + if (snd_config_get_id(cfg, &id) < 0) + return -EINVAL; + + if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for %s", id); + return -EINVAL; + } + + snd_config_for_each(i, next, cfg) { + n = snd_config_iterator_entry(i); + + if (snd_config_get_id(n, &name1) < 0) + return -EINVAL; + + err = get_string3(uc_mgr, name1, &name1s); + if (err < 0) + return err; + + err = parse_string_substitute3(uc_mgr, n, &name2); + if (err < 0) { + free(name1s); + uc_error("error: failed to get target device name for '%s'", name1); + return err; + } + + /* skip duplicates */ + list_for_each(pos, list) { + dev = list_entry(pos, struct ucm_dev_name, list); + if (strcmp(dev->name1, name1s) == 0) { + free(name2); + free(name1s); + return 0; + } + } + + free(name1s); + + dev = calloc(1, sizeof(*dev)); + if (dev == NULL) { + free(name2); + return -ENOMEM; + } + dev->name1 = strdup(name1); + if (dev->name1 == NULL) { + free(dev); + free(name2); + return -ENOMEM; + } + dev->name2 = name2; + list_add_tail(&dev->list, list); + } + + return 0; +} + static int parse_compound_check_legacy(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg, int (*fcn)(snd_use_case_mgr_t *, snd_config_t *, void *, void *), @@ -1033,7 +1313,88 @@ static int parse_modifier_name(snd_use_case_mgr_t *uc_mgr, void *data1, void *data2 ATTRIBUTE_UNUSED) { - return parse_compound_check_legacy(uc_mgr, cfg, parse_modifier, data1); + return parse_compound(uc_mgr, cfg, parse_modifier, data1, data2); +} + +static int verb_dev_list_add(struct use_case_verb *verb, + enum dev_list_type dst_type, + const char *dst, + const char *src) +{ + struct use_case_device *device; + struct list_head *pos; + + list_for_each(pos, &verb->device_list) { + device = list_entry(pos, struct use_case_device, list); + if (strcmp(device->name, dst) != 0) + continue; + if (device->dev_list.type != dst_type) { + if (list_empty(&device->dev_list.list)) { + device->dev_list.type = dst_type; + } else { + uc_error("error: incompatible device list type ('%s', '%s')", + device->name, src); + return -EINVAL; + } + } + return uc_mgr_put_to_dev_list(&device->dev_list, src); + } + uc_error("error: unable to find device '%s'", dst); + return -ENOENT; +} + +static int verb_dev_list_check(struct use_case_verb *verb) +{ + struct list_head *pos, *pos2; + struct use_case_device *device; + struct dev_list_node *dlist; + int err; + + list_for_each(pos, &verb->device_list) { + device = list_entry(pos, struct use_case_device, list); + list_for_each(pos2, &device->dev_list.list) { + dlist = list_entry(pos2, struct dev_list_node, list); + err = verb_dev_list_add(verb, device->dev_list.type, + dlist->name, device->name); + if (err < 0) + return err; + } + } + return 0; +} + +static int verb_device_management(struct use_case_verb *verb) +{ + struct list_head *pos; + struct ucm_dev_name *dev; + int err; + + /* rename devices */ + list_for_each(pos, &verb->rename_list) { + dev = list_entry(pos, struct ucm_dev_name, list); + err = uc_mgr_rename_device(verb, dev->name1, dev->name2); + if (err < 0) { + uc_error("error: cannot rename device '%s' to '%s'", dev->name1, dev->name2); + return err; + } + } + + /* remove devices */ + list_for_each(pos, &verb->remove_list) { + dev = list_entry(pos, struct ucm_dev_name, list); + err = uc_mgr_remove_device(verb, dev->name2); + if (err < 0) { + uc_error("error: cannot remove device '%s'", dev->name2); + return err; + } + } + + /* those lists are no longer used */ + uc_mgr_free_dev_name_list(&verb->rename_list); + uc_mgr_free_dev_name_list(&verb->remove_list); + + /* handle conflicting/supported lists */ + return verb_dev_list_check(verb); } /* @@ -1081,8 +1442,8 @@ static int parse_verb(snd_use_case_mgr_t *uc_mgr, snd_config_t *n; int err; - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); if (err < 0) return err; @@ -1155,7 +1516,6 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *n; struct use_case_verb *verb; snd_config_t *cfg; - char filename[MAX_FILE]; int err; /* allocate verb */ @@ -1169,6 +1529,8 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, INIT_LIST_HEAD(&verb->cmpt_device_list); INIT_LIST_HEAD(&verb->modifier_list); INIT_LIST_HEAD(&verb->value_list); + INIT_LIST_HEAD(&verb->rename_list); + INIT_LIST_HEAD(&verb->remove_list); list_add_tail(&verb->list, &uc_mgr->verb_list); if (use_case_name == NULL) return -EINVAL; @@ -1183,17 +1545,12 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, } /* open Verb file for reading */ - configuration_filename(uc_mgr, filename, sizeof(filename), - uc_mgr->conf_file_name, file, ""); - err = uc_mgr_config_load(uc_mgr->conf_format, filename, &cfg); - if (err < 0) { - uc_error("error: failed to open verb file %s : %d", - filename, -errno); + err = uc_mgr_config_load_file(uc_mgr, file, &cfg); + if (err < 0) return err; - } - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); if (err < 0) return err; @@ -1238,6 +1595,26 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, } continue; } + + /* device renames */ + if (strcmp(id, "RenameDevice") == 0) { + err = parse_dev_name_list(uc_mgr, n, &verb->rename_list); + if (err < 0) { + uc_error("error: %s failed to parse device rename", + file); + goto _err; + } + } + + /* device remove */ + if (strcmp(id, "RemoveDevice") == 0) { + err = parse_dev_name_list(uc_mgr, n, &verb->remove_list); + if (err < 0) { + uc_error("error: %s failed to parse device remove", + file); + goto _err; + } + } } snd_config_delete(cfg); @@ -1247,6 +1624,14 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr, uc_error("error: no use case device defined", file); return -EINVAL; } + + /* do device rename and delete */ + err = verb_device_management(verb); + if (err < 0) { + uc_error("error: device management error in verb '%s'", verb->name); + return err; + } + return 0; _err: @@ -1263,23 +1648,24 @@ static int parse_master_section(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg, { snd_config_iterator_t i, next; snd_config_t *n; - const char *use_case_name, *file = NULL, *comment = NULL; + char *use_case_name, *file = NULL, *comment = NULL; int err; - if (snd_config_get_id(cfg, &use_case_name) < 0) { - uc_error("unable to get name for use case section"); - return -EINVAL; - } - if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { uc_error("compound type expected for use case section"); return -EINVAL; } - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); - if (err < 0) + err = parse_get_safe_name(uc_mgr, cfg, NULL, &use_case_name); + if (err < 0) { + uc_error("unable to get name for use case section"); return err; + } + + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); + if (err < 0) + goto __error; /* parse master config sections */ snd_config_for_each(i, next, cfg) { @@ -1290,20 +1676,20 @@ static int parse_master_section(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg, /* get use case verb file name */ if (strcmp(id, "File") == 0) { - err = snd_config_get_string(n, &file); + err = parse_string_substitute3(uc_mgr, n, &file); if (err < 0) { uc_error("failed to get File"); - return err; + goto __error; } continue; } /* get optional use case comment */ if (strncmp(id, "Comment", 7) == 0) { - err = snd_config_get_string(n, &comment); + err = parse_string_substitute3(uc_mgr, n, &comment); if (err < 0) { uc_error("error: failed to get Comment"); - return err; + goto __error; } continue; } @@ -1316,11 +1702,38 @@ static int parse_master_section(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg, /* do we have both use case name and file ? */ if (!file) { uc_error("error: use case missing file"); - return -EINVAL; + err = -EINVAL; + goto __error; } /* parse verb file */ - return parse_verb_file(uc_mgr, use_case_name, comment, file); + err = parse_verb_file(uc_mgr, use_case_name, comment, file); + +__error: + free(use_case_name); + free(file); + free(comment); + return err; +} + +/* + * parse controls which should be run only at initial boot + */ +static int parse_controls_boot(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) +{ + int err; + + if (!list_empty(&uc_mgr->once_list)) { + uc_error("Once list is not empty"); + return -EINVAL; + } + err = parse_sequence(uc_mgr, &uc_mgr->once_list, cfg); + if (err < 0) { + uc_error("Unable to parse BootSequence"); + return err; + } + + return 0; } /* @@ -1329,7 +1742,7 @@ static int parse_master_section(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg, static int parse_controls(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) { int err; - + if (!list_empty(&uc_mgr->default_list)) { uc_error("Default list is not empty"); return -EINVAL; @@ -1339,7 +1752,7 @@ static int parse_controls(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) uc_error("Unable to parse SectionDefaults"); return err; } - + return 0; } @@ -1371,11 +1784,16 @@ static int parse_controls(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) * CaptureCTL "hw:CARD=0" * } * + * # The initial boot (run once) configuration. + * + * BootSequence [ + * cset "name='Master Playback Switch',index=2 1,1" + * cset "name='Master Playback Volume',index=2 25,25" + * ] + * * # This file also stores the default sound card state. * * SectionDefaults [ - * cset "name='Master Playback Switch',index=2 1,1" - * cset "name='Master Playback Volume',index=2 25,25" * cset "name='Master Mono Playback',index=1 0" * cset "name='Master Mono Playback Volume',index=1 0" * cset "name='PCM Switch',index=2 1,1" @@ -1416,10 +1834,11 @@ static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) } /* delete this field to avoid strcmp() call in the loop */ snd_config_delete(n); + uc_mgr->conf_format = l; } - /* in-place condition evaluation */ - err = evaluate_condition(uc_mgr, cfg); + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); if (err < 0) return err; @@ -1449,6 +1868,14 @@ static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) continue; } + /* find default control values section (first boot only) */ + if (strcmp(id, "BootSequence") == 0) { + err = parse_controls_boot(uc_mgr, n); + if (err < 0) + return err; + continue; + } + /* find default control values section and parse it */ if (strcmp(id, "SectionDefaults") == 0) { err = parse_controls(uc_mgr, n); @@ -1475,36 +1902,26 @@ static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) /* get the card info */ static int get_card_info(snd_use_case_mgr_t *mgr, const char *ctl_name, - snd_ctl_t **_handle, - snd_ctl_card_info_t *info) + snd_ctl_card_info_t **info) { - snd_ctl_t *handle; + struct ctl_list *ctl_list; int err; - *_handle = NULL; - - err = uc_mgr_open_ctl(mgr, &handle, ctl_name); + err = uc_mgr_open_ctl(mgr, &ctl_list, ctl_name, 0); if (err < 0) return err; - err = snd_ctl_card_info(handle, info); - if (err < 0) { - uc_error("control hardware info (%s): %s", ctl_name, snd_strerror(err)); - } else { - *_handle = handle; - } - + if (info) + *info = ctl_list->ctl_info; return err; } -/* find the card in the local machine and store the card long name */ -static int get_card_long_name(snd_use_case_mgr_t *mgr, char *longname) +/* find the card in the local machine */ +static int get_by_card_name(snd_use_case_mgr_t *mgr, const char *card_name) { - const char *card_name = mgr->card_name; int card, err; - snd_ctl_t *ctl; snd_ctl_card_info_t *info; - const char *_name, *_long_name; + const char *_driver, *_name, *_long_name; snd_ctl_card_info_alloca(&info); @@ -1517,20 +1934,20 @@ static int get_card_long_name(snd_use_case_mgr_t *mgr, char *longname) while (card >= 0) { char name[32]; - /* most probably, we do not need to cache all CTL devices here */ + /* clear the list, keep the only one CTL device */ uc_mgr_free_ctl_list(mgr); sprintf(name, "hw:%d", card); - err = get_card_info(mgr, name, &ctl, info); + err = get_card_info(mgr, name, &info); if (err == 0) { + _driver = snd_ctl_card_info_get_driver(info); _name = snd_ctl_card_info_get_name(info); _long_name = snd_ctl_card_info_get_longname(info); - if (!strcmp(card_name, _name) || - !strcmp(card_name, _long_name)) { - snd_strlcpy(longname, _long_name, MAX_CARD_LONG_NAME); + if (!strcmp(card_name, _driver) || + !strcmp(card_name, _name) || + !strcmp(card_name, _long_name)) return 0; - } } if (snd_card_next(&card) < 0) { @@ -1545,119 +1962,245 @@ static int get_card_long_name(snd_use_case_mgr_t *mgr, char *longname) } /* set the driver name and long name by the card ctl name */ -static int get_by_card(snd_use_case_mgr_t *mgr, const char *ctl_name, char *longname) +static inline int get_by_card(snd_use_case_mgr_t *mgr, const char *ctl_name) { - snd_ctl_t *ctl; - snd_ctl_card_info_t *info; - const char *_name, *_long_name; + return get_card_info(mgr, ctl_name, NULL); +} + +static int parse_toplevel_path(snd_use_case_mgr_t *uc_mgr, + char *filename, + snd_config_t *cfg) +{ + snd_config_iterator_t i, next, i2, next2; + snd_config_t *n, *n2; + const char *id; + char *dir = NULL, *file = NULL, fn[PATH_MAX]; + long version; int err; - snd_ctl_card_info_alloca(&info); + if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for UseCasePath node"); + return -EINVAL; + } - err = get_card_info(mgr, ctl_name, &ctl, info); - if (err) - return err; + /* parse use case path config sections */ + snd_config_for_each(i, next, cfg) { + n = snd_config_iterator_entry(i); - _name = snd_ctl_card_info_get_name(info); - _long_name = snd_ctl_card_info_get_longname(info); - snd_strlcpy(mgr->conf_file_name, _name, sizeof(mgr->conf_file_name)); - snd_strlcpy(longname, _long_name, MAX_CARD_LONG_NAME); + if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for UseCasePath.something node"); + return -EINVAL; + } - return 0; + if (snd_config_get_id(n, &id) < 0) + continue; + + version = 2; + + /* parse use case path config sections */ + snd_config_for_each(i2, next2, n) { + + n2 = snd_config_iterator_entry(i2); + if (snd_config_get_id(n2, &id) < 0) + continue; + + if (strcmp(id, "Version") == 0) { + err = parse_integer_substitute(uc_mgr, n2, &version); + if (err < 0) { + uc_error("unable to parse UcmDirectory"); + goto __error; + } + if (version < 1 || version > 2) { + uc_error("Version must be 1 or 2"); + err = -EINVAL; + goto __error; + } + continue; + } + + if (strcmp(id, "Directory") == 0) { + err = parse_string_substitute(uc_mgr, n2, &dir); + if (err < 0) { + uc_error("unable to parse Directory"); + goto __error; + } + continue; + } + + if (strcmp(id, "File") == 0) { + err = parse_string_substitute(uc_mgr, n2, &file); + if (err < 0) { + uc_error("unable to parse File"); + goto __error; + } + continue; + } + + uc_error("unknown UseCasePath field %s", id); + } + + if (dir == NULL) { + uc_error("Directory is not defined in %s!", filename); + goto __next; + } + if (file == NULL) { + uc_error("File is not defined in %s!", filename); + goto __next; + } + + ucm_filename(fn, sizeof(fn), version, dir, file); + if (access(fn, R_OK) == 0) { + if (replace_string(&uc_mgr->conf_dir_name, dir) == NULL) { + err = -ENOMEM; + goto __error; + } + if (replace_string(&uc_mgr->conf_file_name, file) == NULL) { + err = -ENOMEM; + goto __error; + } + strncpy(filename, fn, PATH_MAX); + uc_mgr->conf_format = version; + goto __ok; + } + +__next: + free(file); + free(dir); + dir = NULL; + file = NULL; + } + + err = -ENOENT; + goto __error; + +__ok: + err = 0; +__error: + free(file); + free(dir); + return err; } -static int load_master_config(snd_use_case_mgr_t *uc_mgr, - const char *card_name, snd_config_t **cfg, int longname) +static int parse_toplevel_config(snd_use_case_mgr_t *uc_mgr, + char *filename, + snd_config_t *cfg) { - char filename[MAX_FILE]; + snd_config_iterator_t i, next; + snd_config_t *n; + const char *id; + long l; int err; - if (strnlen(card_name, MAX_CARD_LONG_NAME) == MAX_CARD_LONG_NAME) { - uc_error("error: invalid card name %s (at most %d chars)", - card_name, MAX_CARD_LONG_NAME - 1); + if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for toplevel file"); return -EINVAL; } - uc_mgr->conf_format = 0; - if (longname) { - if (getenv(ALSA_CONFIG_UCM2_VAR) || !getenv(ALSA_CONFIG_UCM_VAR)) { - uc_mgr->conf_format = 2; - configuration_filename(uc_mgr, filename, sizeof(filename), - uc_mgr->conf_file_name, card_name, ".conf"); - if (access(filename, R_OK) == 0) - goto __load; - } - /* try the old ucm directory */ - uc_mgr->conf_format = 1; - configuration_filename(uc_mgr, filename, sizeof(filename), - card_name, card_name, ".conf"); - if (access(filename, R_OK) != 0) - return -ENOENT; - } else { - configuration_filename(uc_mgr, filename, sizeof(filename), - card_name, card_name, ".conf"); + err = snd_config_search(cfg, "Syntax", &n); + if (err < 0) { + uc_error("Syntax field not found in %s", filename); + return -EINVAL; + } + err = snd_config_get_integer(n, &l); + if (err < 0) { + uc_error("Syntax field is invalid in %s", filename); + return err; + } + if (l < 2 || l > SYNTAX_VERSION_MAX) { + uc_error("Incompatible syntax %d in %s", l, filename); + return -EINVAL; + } + /* delete this field to avoid strcmp() call in the loop */ + snd_config_delete(n); + uc_mgr->conf_format = l; + + /* in-place evaluation */ + err = uc_mgr_evaluate_inplace(uc_mgr, cfg); + if (err < 0) + return err; + + /* parse toplevel config sections */ + snd_config_for_each(i, next, cfg) { + + n = snd_config_iterator_entry(i); + if (snd_config_get_id(n, &id) < 0) + continue; + + if (strcmp(id, "UseCasePath") == 0) { + err = parse_toplevel_path(uc_mgr, filename, n); + if (err == 0) + return err; + continue; + } + + uc_error("uknown toplevel field %s", id); } -__load: + return -ENOENT; +} + +static int load_toplevel_config(snd_use_case_mgr_t *uc_mgr, + snd_config_t **cfg) +{ + char filename[PATH_MAX]; + snd_config_t *tcfg; + int err; + + ucm_filename(filename, sizeof(filename), 2, NULL, "ucm.conf"); + + if (access(filename, R_OK) != 0) { + uc_error("Unable to find the top-level configuration file '%s'.", filename); + return -ENOENT; + } + + err = uc_mgr_config_load(2, filename, &tcfg); + if (err < 0) + goto __error; + + /* filename is shared for function input and output! */ + err = parse_toplevel_config(uc_mgr, filename, tcfg); + snd_config_delete(tcfg); + if (err < 0) + goto __error; + err = uc_mgr_config_load(uc_mgr->conf_format, filename, cfg); if (err < 0) { uc_error("error: could not parse configuration for card %s", - card_name); - return err; + uc_mgr->card_name); + goto __error; } return 0; + +__error: + return err; } -/* load master use case file for sound card - * - * The same ASoC machine driver can be shared by many different devices. - * For user space to differentiate them and get the best device-specific - * configuration, ASoC machine drivers may use the DMI info - * (vendor-product-version-board) as the card long name. And user space can - * define configuration files like longnamei/longname.conf for a specific device. - * - * This function will try to find the card in the local machine and get its - * long name, then load the file longname/longname.conf to get the best - * device-specific configuration. If the card is not found in the local - * machine or the device-specific file is not available, fall back to load - * the default configuration file name/name.conf. +/* load master use case file for sound card based on rules in ucm2/ucm.conf */ int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr) { snd_config_t *cfg; - const char *name = uc_mgr->card_name; - char longname[MAX_CARD_LONG_NAME]; + const char *name; int err; - snd_strlcpy(uc_mgr->conf_file_name, uc_mgr->card_name, sizeof(uc_mgr->conf_file_name)); - + name = uc_mgr->card_name; if (strncmp(name, "hw:", 3) == 0) { - err = get_by_card(uc_mgr, name, longname); - if (err == 0) - goto __longname; - uc_error("card '%s' is not valid", name); - goto __error; - } else if (strncmp(name, "strict:", 7)) { - err = get_card_long_name(uc_mgr, longname); - if (err == 0) { /* load file that matches the card long name */ -__longname: - err = load_master_config(uc_mgr, longname, &cfg, 1); - } - - if (err == 0) { - /* got device-specific file that matches the card long name */ - snd_strlcpy(uc_mgr->conf_file_name, longname, sizeof(uc_mgr->conf_file_name)); - goto __parse; + err = get_by_card(uc_mgr, name); + if (err < 0) { + uc_error("card '%s' is not valid", name); + goto __error; } + } else if (strncmp(name, "strict:", 7)) { + /* do not handle the error here */ + /* we can refer the virtual UCM config */ + get_by_card_name(uc_mgr, name); } - /* standard path */ - err = load_master_config(uc_mgr, uc_mgr->conf_file_name, &cfg, 0); + err = load_toplevel_config(uc_mgr, &cfg); if (err < 0) goto __error; -__parse: err = parse_master_file(uc_mgr, cfg); snd_config_delete(cfg); if (err < 0) { @@ -1669,7 +2212,7 @@ __parse: __error: uc_mgr_free_ctl_list(uc_mgr); - uc_mgr->conf_file_name[0] = '\0'; + replace_string(&uc_mgr->conf_dir_name, NULL); return err; } @@ -1714,7 +2257,7 @@ static int is_component_directory(const char *dir) */ int uc_mgr_scan_master_configs(const char **_list[]) { - char filename[MAX_FILE], dfl[MAX_FILE]; + char filename[PATH_MAX], dfl[PATH_MAX], fn[FILENAME_MAX]; char *env = getenv(ALSA_CONFIG_UCM2_VAR); const char **list, *d_name; snd_config_t *cfg, *c; @@ -1771,8 +2314,11 @@ int uc_mgr_scan_master_configs(const char **_list[]) if (is_component_directory(d_name)) continue; - configuration_filename2(filename, sizeof(filename), 2, - d_name, d_name, ".conf"); + snprintf(fn, sizeof(fn), "%s.conf", d_name); + ucm_filename(filename, sizeof(filename), 2, d_name, fn); + if (eaccess(filename, R_OK)) + continue; + err = uc_mgr_config_load(2, filename, &cfg); if (err < 0) goto __err; diff --git a/src/ucm/ucm_cond.c b/src/ucm/ucm_cond.c index 22b418d..cc49153 100644 --- a/src/ucm/ucm_cond.c +++ b/src/ucm/ucm_cond.c @@ -44,6 +44,23 @@ static int if_eval_string(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval) char *s1, *s2; int err; + if (uc_mgr->conf_format >= 3) { + err = get_string(eval, "Empty", &string1); + if (err < 0 && err != -ENOENT) { + uc_error("String error (If.Condition.Empty)"); + return -EINVAL; + } + + if (string1) { + err = uc_mgr_get_substituted_value(uc_mgr, &s1, string1); + if (err < 0) + return err; + err = s1 == NULL || s1[0] == '\0'; + free(s1); + return err; + } + } + err = get_string(eval, "String1", &string1); if (err < 0 && err != -ENOENT) { uc_error("String error (If.Condition.String1)"); @@ -163,6 +180,7 @@ static int if_eval_regex_match(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval) static int if_eval_control_exists(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval) { snd_ctl_t *ctl; + struct ctl_list *ctl_list; const char *device = NULL, *ctldef, *enumval = NULL, *name; snd_ctl_elem_id_t *elem_id; snd_ctl_elem_info_t *elem_info; @@ -211,10 +229,11 @@ static int if_eval_control_exists(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval err = uc_mgr_get_substituted_value(uc_mgr, &s, device); if (err < 0) return err; - err = uc_mgr_open_ctl(uc_mgr, &ctl, s); + err = uc_mgr_open_ctl(uc_mgr, &ctl_list, s, 1); free(s); if (err < 0) return err; + ctl = ctl_list->ctl; } snd_ctl_elem_info_set_id(elem_info, elem_id); @@ -266,12 +285,15 @@ static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval) return -EINVAL; } - if (strcmp(type, "ControlExists") == 0) - return if_eval_control_exists(uc_mgr, eval); + if (strcmp(type, "AlwaysTrue") == 0) + return 1; if (strcmp(type, "String") == 0) return if_eval_string(uc_mgr, eval); + if (strcmp(type, "ControlExists") == 0) + return if_eval_control_exists(uc_mgr, eval); + if (strcmp(type, "RegexMatch") == 0) return if_eval_regex_match(uc_mgr, eval); @@ -347,72 +369,6 @@ static void config_dump(snd_config_t *cfg) } #endif -static int compound_merge(const char *id, - snd_config_t *dst, snd_config_t *src, - snd_config_t *before, snd_config_t *after) -{ - snd_config_iterator_t i, next; - snd_config_t *n, *_before = NULL, *_after = NULL; - const char *s; - int err; - - if (snd_config_get_type(src) != SND_CONFIG_TYPE_COMPOUND) { - uc_error("compound type expected for If True/False block"); - return -EINVAL; - } - - if (before) { - err = get_string(before, id, &s); - if (err < 0 && err != -ENOENT) - return err; - if (err == 0) { - err = snd_config_search(dst, s, &_before); - if (err < 0 && err != -ENOENT) - return err; - } - } - if (after) { - err = get_string(after, id, &s); - if (err < 0 && err != -ENOENT) - return err; - if (err == 0) { - err = snd_config_search(dst, s, &_after); - if (err < 0 && err != -ENOENT) - return err; - } - } - - if (_before && _after) { - uc_error("defined both before and after identifiers in the If block"); - return -EINVAL; - } - - snd_config_for_each(i, next, src) { - n = snd_config_iterator_entry(i); - err = snd_config_remove(n); - if (err < 0) - return err; - if (_before) { - err = snd_config_add_before(_before, n); - if (err < 0) - return err; - _before = NULL; - _after = n; - } else if (_after) { - err = snd_config_add_after(_after, n); - if (err < 0) - return err; - _after = n; - } else { - err = snd_config_add(dst, n); - if (err < 0) - return err; - } - } - - return 0; -} - /* * put back the result from all conditions to the parent */ @@ -420,9 +376,8 @@ int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr, snd_config_t *parent, snd_config_t *cond) { - snd_config_iterator_t i, i2, next, next2; - snd_config_t *a, *n, *n2, *parent2, *before, *after; - const char *id; + snd_config_iterator_t i, next; + snd_config_t *a, *n, *before, *after; int err; if (uc_mgr->conf_format < 2) { @@ -443,38 +398,13 @@ int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr, return err; if (a == NULL) continue; - err = snd_config_search(a, "If", &n2); - if (err < 0 && err != -ENOENT) { - uc_error("If block error (If)"); - return -EINVAL; - } else if (err == 0) { - err = uc_mgr_evaluate_condition(uc_mgr, a, n2); - if (err < 0) - return err; - snd_config_delete(n2); - } - snd_config_for_each(i2, next2, a) { - n2 = snd_config_iterator_entry(i2); - err = snd_config_remove(n2); - if (err < 0) - return err; - err = snd_config_get_id(n2, &id); - if (err < 0) { -__add: - err = snd_config_add(parent, n2); - if (err < 0) - return err; - continue; - } else { - err = snd_config_search(parent, id, &parent2); - if (err == -ENOENT) - goto __add; - err = compound_merge(id, parent2, n2, before, after); - if (err < 0) - return err; - } - snd_config_delete(n2); - } + err = uc_mgr_evaluate_inplace(uc_mgr, a); + if (err < 0) + return err; + err = uc_mgr_config_tree_merge(parent, a, before, after); + if (err < 0) + return err; + snd_config_delete(a); } return 0; } diff --git a/src/ucm/ucm_include.c b/src/ucm/ucm_include.c new file mode 100644 index 0000000..c69490f --- /dev/null +++ b/src/ucm/ucm_include.c @@ -0,0 +1,281 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Support for the verb/device/modifier core logic and API, + * command line tool and file parser was kindly sponsored by + * Texas Instruments Inc. + * Support for multiple active modifiers and devices, + * transition sequences, multiple client access and user defined use + * cases was kindly sponsored by Wolfson Microelectronics PLC. + * + * Copyright (C) 2020 Red Hat Inc. + * Authors: Jaroslav Kysela + */ + +#include "ucm_local.h" + +static int get_string(snd_config_t *compound, const char *key, const char **str) +{ + snd_config_t *node; + int err; + + err = snd_config_search(compound, key, &node); + if (err < 0) + return err; + return snd_config_get_string(node, str); +} + +static int include_eval_one(snd_use_case_mgr_t *uc_mgr, + snd_config_t *inc, + snd_config_t **result, + snd_config_t **before, + snd_config_t **after) +{ + const char *file; + char *s; + int err; + + *result = NULL; + + if (snd_config_get_type(inc) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for Include.1"); + return -EINVAL; + } + + err = get_string(inc, "File", &file); + if (err < 0) { + uc_error("file expected (Include)"); + return -EINVAL; + } + + err = snd_config_search(inc, "Before", before); + if (err < 0 && err != -ENOENT) { + uc_error("before block identifier error"); + return -EINVAL; + } + + err = snd_config_search(inc, "After", after); + if (err < 0 && err != -ENOENT) { + uc_error("before block identifier error"); + return -EINVAL; + } + + err = uc_mgr_get_substituted_value(uc_mgr, &s, file); + if (err < 0) + return err; + err = uc_mgr_config_load_file(uc_mgr, s, result); + free(s); + return err; +} + +#if 0 +static void config_dump(snd_config_t *cfg) +{ + snd_output_t *out; + snd_output_stdio_attach(&out, stderr, 0); + snd_output_printf(out, "-----\n"); + snd_config_save(cfg, out); + snd_output_close(out); +} +#endif + +static int find_position_node(snd_config_t **res, snd_config_t *dst, + const char *id, snd_config_t *pos) +{ + const char *s; + int err; + + err = get_string(pos, id, &s); + if (err < 0 && err != -ENOENT) + return err; + if (err == 0) { + err = snd_config_search(dst, s, res); + if (err < 0 && err != -ENOENT) + return err; + } + return 0; +} + +static int compound_merge(const char *id, + snd_config_t *dst, snd_config_t *src, + snd_config_t *before, snd_config_t *after) +{ + snd_config_iterator_t i, next; + snd_config_t *n, *_before = NULL, *_after = NULL; + char tmpid[32]; + int err, array, idx; + + if (snd_config_get_type(src) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for the merged block"); + return -EINVAL; + } + + if (before) { + err = find_position_node(&_before, dst, id, before); + if (err < 0) + return err; + } + if (after) { + err = find_position_node(&_after, dst, id, after); + if (err < 0) + return err; + } + + if (_before && _after) { + uc_error("defined both before and after identifiers in the If or Include block"); + return -EINVAL; + } + + array = snd_config_is_array(dst); + if (array < 0) { + uc_error("destination configuration node is not a compound"); + return array; + } + if (array && snd_config_is_array(src) <= 0) { + uc_error("source configuration node is not an array"); + return -EINVAL; + } + + idx = 0; + + /* for array, use a temporary non-clashing identifier */ + if (array > 0) { + snd_config_for_each(i, next, dst) { + n = snd_config_iterator_entry(i); + snprintf(tmpid, sizeof(tmpid), "_tmp_%d", idx++); + err = snd_config_set_id(n, tmpid); + if (err < 0) + return err; + } + } + + snd_config_for_each(i, next, src) { + n = snd_config_iterator_entry(i); + err = snd_config_remove(n); + if (err < 0) + return err; + /* for array, use a temporary non-clashing identifier */ + if (array > 0) { + snprintf(tmpid, sizeof(tmpid), "_tmp_%d", idx++); + err = snd_config_set_id(n, tmpid); + if (err < 0) + return err; + } + if (_before) { + err = snd_config_add_before(_before, n); + if (err < 0) + return err; + _before = NULL; + _after = n; + } else if (_after) { + err = snd_config_add_after(_after, n); + if (err < 0) + return err; + _after = n; + } else { + err = snd_config_add(dst, n); + if (err < 0) + return err; + } + } + + /* set new indexes for the final array */ + if (array > 0) { + idx = 0; + snd_config_for_each(i, next, dst) { + n = snd_config_iterator_entry(i); + snprintf(tmpid, sizeof(tmpid), "%d", idx++); + err = snd_config_set_id(n, tmpid); + if (err < 0) + return err; + } + } + + return 0; +} + +int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx, + snd_config_t *before, snd_config_t *after) +{ + snd_config_iterator_t i, next; + snd_config_t *n, *parent2; + const char *id; + int err; + + snd_config_for_each(i, next, new_ctx) { + n = snd_config_iterator_entry(i); + err = snd_config_remove(n); + if (err < 0) + return err; + err = snd_config_get_id(n, &id); + if (err < 0) { +__add: + err = snd_config_add(parent, n); + if (err < 0) + return err; + continue; + } else { + err = snd_config_search(parent, id, &parent2); + if (err == -ENOENT) + goto __add; + err = compound_merge(id, parent2, n, before, after); + if (err < 0) + return err; + } + snd_config_delete(n); + } + return 0; +} + +/* + * put back the included configuration to the parent + */ +int uc_mgr_evaluate_include(snd_use_case_mgr_t *uc_mgr, + snd_config_t *parent, + snd_config_t *inc) +{ + snd_config_iterator_t i, next; + snd_config_t *a, *n, *before, *after; + int err; + + if (uc_mgr->conf_format < 3) { + uc_error("in-place include is supported in v3+ syntax"); + return -EINVAL; + } + + if (snd_config_get_type(inc) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for Include"); + return -EINVAL; + } + + snd_config_for_each(i, next, inc) { + n = snd_config_iterator_entry(i); + before = after = NULL; + err = include_eval_one(uc_mgr, n, &a, &before, &after); + if (err < 0) + return err; + if (a == NULL) + continue; + err = uc_mgr_evaluate_inplace(uc_mgr, a); + if (err < 0) + return err; + err = uc_mgr_config_tree_merge(parent, a, before, after); + if (err < 0) + return err; + snd_config_delete(a); + + } + return 0; +} diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index ba96150..709f4cb 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -40,9 +40,8 @@ #include #include "use-case.h" -#define SYNTAX_VERSION_MAX 2 +#define SYNTAX_VERSION_MAX 3 -#define MAX_FILE 256 #define MAX_CARD_SHORT_NAME 32 #define MAX_CARD_LONG_NAME 80 @@ -116,6 +115,13 @@ struct ctl_list { struct list_head dev_list; snd_ctl_t *ctl; snd_ctl_card_info_t *ctl_info; + int slave; +}; + +struct ucm_dev_name { + struct list_head list; + char *name1; + char *name2; }; /* @@ -187,7 +193,6 @@ struct use_case_verb { /* verb transition list */ struct list_head transition_list; - /* hardware devices that can be used with this use case */ struct list_head device_list; /* component device list */ @@ -198,6 +203,10 @@ struct use_case_verb { /* value list */ struct list_head value_list; + + /* temporary modifications lists */ + struct list_head rename_list; + struct list_head remove_list; }; /* @@ -205,15 +214,20 @@ struct use_case_verb { */ struct snd_use_case_mgr { char *card_name; - char conf_file_name[MAX_CARD_LONG_NAME]; + char *conf_file_name; + char *conf_dir_name; char *comment; int conf_format; /* use case verb, devices and modifier configs parsed from files */ struct list_head verb_list; + /* boot settings - sequence */ + struct list_head once_list; + /* default settings - sequence */ struct list_head default_list; + int default_list_executed; /* default settings - value list */ struct list_head value_list; @@ -226,6 +240,9 @@ struct snd_use_case_mgr { /* locking */ pthread_mutex_t mutex; + /* UCM internal variables defined in configuration files */ + struct list_head variable_list; + /* list of opened control devices */ struct list_head ctl_list; @@ -249,33 +266,65 @@ struct snd_use_case_mgr { void uc_mgr_error(const char *fmt, ...); void uc_mgr_stdout(const char *fmt, ...); +const char *uc_mgr_config_dir(int format); int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg); +int uc_mgr_config_load_file(snd_use_case_mgr_t *uc_mgr, const char *file, snd_config_t **cfg); int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr); int uc_mgr_scan_master_configs(const char **_list[]); +int uc_mgr_put_to_dev_list(struct dev_list *dev_list, const char *name); +int uc_mgr_remove_device(struct use_case_verb *verb, const char *name); +int uc_mgr_rename_device(struct use_case_verb *verb, const char *src, + const char *dst); + +void uc_mgr_free_dev_name_list(struct list_head *base); void uc_mgr_free_sequence_element(struct sequence_element *seq); void uc_mgr_free_transition_element(struct transition_sequence *seq); void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr); void uc_mgr_free(snd_use_case_mgr_t *uc_mgr); int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr, - snd_ctl_t **ctl, - const char *device); + struct ctl_list **ctl_list, + const char *device, + int slave); -struct ctl_list *uc_mgr_get_one_ctl(snd_use_case_mgr_t *uc_mgr); +struct ctl_list *uc_mgr_get_master_ctl(snd_use_case_mgr_t *uc_mgr); +struct ctl_list *uc_mgr_get_ctl_by_name(snd_use_case_mgr_t *uc_mgr, + const char *name, int idx); snd_ctl_t *uc_mgr_get_ctl(snd_use_case_mgr_t *uc_mgr); void uc_mgr_free_ctl_list(snd_use_case_mgr_t *uc_mgr); int uc_mgr_add_value(struct list_head *base, const char *key, char *val); +const char *uc_mgr_get_variable(snd_use_case_mgr_t *uc_mgr, + const char *name); + +int uc_mgr_set_variable(snd_use_case_mgr_t *uc_mgr, + const char *name, + const char *val); + int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr, char **_rvalue, const char *value); +int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx, + snd_config_t *before, snd_config_t *after); + +int uc_mgr_evaluate_inplace(snd_use_case_mgr_t *uc_mgr, + snd_config_t *cfg); + +int uc_mgr_evaluate_include(snd_use_case_mgr_t *uc_mgr, + snd_config_t *parent, + snd_config_t *inc); + int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr, snd_config_t *parent, snd_config_t *cond); +int uc_mgr_define_regex(snd_use_case_mgr_t *uc_mgr, + const char *name, + snd_config_t *eval); + /** The name of the environment variable containing the UCM directory */ #define ALSA_CONFIG_UCM_VAR "ALSA_CONFIG_UCM" diff --git a/src/ucm/ucm_regex.c b/src/ucm/ucm_regex.c new file mode 100644 index 0000000..be8f277 --- /dev/null +++ b/src/ucm/ucm_regex.c @@ -0,0 +1,174 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Support for the verb/device/modifier core logic and API, + * command line tool and file parser was kindly sponsored by + * Texas Instruments Inc. + * Support for multiple active modifiers and devices, + * transition sequences, multiple client access and user defined use + * cases was kindly sponsored by Wolfson Microelectronics PLC. + * + * Copyright (C) 2019 Red Hat Inc. + * Authors: Jaroslav Kysela + */ + +#include "ucm_local.h" +#include +#include + +static int get_string(snd_config_t *compound, const char *key, const char **str) +{ + snd_config_t *node; + int err; + + err = snd_config_search(compound, key, &node); + if (err < 0) + return err; + return snd_config_get_string(node, str); +} + +static char *extract_substring(const char *data, regmatch_t *match) +{ + char *s; + size_t len; + + len = match->rm_eo - match->rm_so; + s = malloc(len + 1); + if (s == NULL) + return NULL; + memcpy(s, data + match->rm_so, len); + s[len] = '\0'; + return s; +} + +static int set_variables(snd_use_case_mgr_t *uc_mgr, const char *data, + unsigned int match_size, regmatch_t *match, + const char *name) +{ + size_t name2_len = strlen(name) + 16; + char *name2 = alloca(name2_len); + char *s; + unsigned int i; + int err; + + if (match[0].rm_so < 0 || match[0].rm_eo < 0) + return 0; + s = extract_substring(data, &match[0]); + if (s == NULL) + return -ENOMEM; + err = uc_mgr_set_variable(uc_mgr, name, s); + free(s); + if (err < 0) + return err; + for (i = 1; i < match_size; i++) { + if (match[0].rm_so < 0 || match[0].rm_eo < 0) + return 0; + s = extract_substring(data, &match[i]); + if (s == NULL) + return -ENOMEM; + snprintf(name2, name2_len, "%s%u", name, i); + err = uc_mgr_set_variable(uc_mgr, name2, s); + free(s); + if (err < 0) + return err; + } + return 0; +} + +int uc_mgr_define_regex(snd_use_case_mgr_t *uc_mgr, const char *name, + snd_config_t *eval) +{ + const char *string, *regex_string, *flags_string; + char *s; + regex_t re; + int options = 0; + regmatch_t match[20]; + int err; + + if (uc_mgr->conf_format < 3) { + uc_error("define regex is supported in v3+ syntax"); + return -EINVAL; + } + + if (snd_config_get_type(eval) != SND_CONFIG_TYPE_COMPOUND) { + uc_error("compound type expected for DefineRegex"); + return -EINVAL; + } + + err = get_string(eval, "String", &string); + if (err < 0) { + uc_error("DefineRegex error (String)"); + return -EINVAL; + } + + err = get_string(eval, "Regex", ®ex_string); + if (err < 0) { + uc_error("DefineRegex error (Regex string)"); + return -EINVAL; + } + + err = get_string(eval, "Flags", &flags_string); + if (err == -ENOENT) { + options = REG_EXTENDED; + } else if (err < 0) { + uc_error("DefineRegex error (Flags string)"); + return -EINVAL; + } else { + while (*flags_string) { + switch (tolower(*flags_string)) { + case 'e': + options |= REG_EXTENDED; + break; + case 'i': + options |= REG_ICASE; + break; + case 's': + options |= REG_NOSUB; + break; + case 'n': + options |= REG_NEWLINE; + break; + default: + uc_error("DefineRegex error (unknown flag '%c')", *flags_string); + return -EINVAL; + } + flags_string++; + } + } + + err = uc_mgr_get_substituted_value(uc_mgr, &s, regex_string); + if (err < 0) + return err; + err = regcomp(&re, s, options); + free(s); + if (err) { + uc_error("Regex '%s' compilation failed (code %d)", err); + return -EINVAL; + } + + err = uc_mgr_get_substituted_value(uc_mgr, &s, string); + if (err < 0) { + regfree(&re); + return err; + } + err = regexec(&re, s, ARRAY_SIZE(match), match, 0); + if (err < 0) + err = -errno; + else + err = set_variables(uc_mgr, s, ARRAY_SIZE(match), match, name); + free(s); + regfree(&re); + return err; +} diff --git a/src/ucm/ucm_subs.c b/src/ucm/ucm_subs.c index 00afa9e..a154aa5 100644 --- a/src/ucm/ucm_subs.c +++ b/src/ucm/ucm_subs.c @@ -25,21 +25,74 @@ */ #include "ucm_local.h" +#include #include #include +static char *rval_open_name(snd_use_case_mgr_t *uc_mgr) +{ + const char *name; + if (uc_mgr->conf_format < 3) + return NULL; + name = uc_mgr->card_name; + if (name) { + if (strncmp(name, "strict:", 7) == 0) + name += 7; + return strdup(name); + } + return NULL; +} + +static char *rval_conf_topdir(snd_use_case_mgr_t *uc_mgr) +{ + const char *dir; + + if (uc_mgr->conf_format < 3) + return NULL; + dir = uc_mgr_config_dir(uc_mgr->conf_format); + if (dir && dir[0]) + return strdup(dir); + return NULL; +} + +static char *rval_conf_dir(snd_use_case_mgr_t *uc_mgr) +{ + if (uc_mgr->conf_format < 3) + return NULL; + if (uc_mgr->conf_dir_name && uc_mgr->conf_dir_name[0]) + return strdup(uc_mgr->conf_dir_name); + return NULL; +} + static char *rval_conf_name(snd_use_case_mgr_t *uc_mgr) { - if (uc_mgr->conf_file_name[0]) + if (uc_mgr->conf_file_name && uc_mgr->conf_file_name[0]) return strdup(uc_mgr->conf_file_name); return NULL; } +static char *get_card_number(struct ctl_list *ctl_list) +{ + char num[16]; + + if (ctl_list == NULL) + return strdup(""); + snprintf(num, sizeof(num), "%i", snd_ctl_card_info_get_card(ctl_list->ctl_info)); + return strdup(num); +} + +static char *rval_card_number(snd_use_case_mgr_t *uc_mgr) +{ + if (uc_mgr->conf_format < 3) + return NULL; + return get_card_number(uc_mgr_get_master_ctl(uc_mgr)); +} + static char *rval_card_id(snd_use_case_mgr_t *uc_mgr) { struct ctl_list *ctl_list; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list == NULL) return NULL; return strdup(snd_ctl_card_info_get_id(ctl_list->ctl_info)); @@ -49,7 +102,7 @@ static char *rval_card_driver(snd_use_case_mgr_t *uc_mgr) { struct ctl_list *ctl_list; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list == NULL) return NULL; return strdup(snd_ctl_card_info_get_driver(ctl_list->ctl_info)); @@ -59,7 +112,7 @@ static char *rval_card_name(snd_use_case_mgr_t *uc_mgr) { struct ctl_list *ctl_list; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list == NULL) return NULL; return strdup(snd_ctl_card_info_get_name(ctl_list->ctl_info)); @@ -69,7 +122,7 @@ static char *rval_card_longname(snd_use_case_mgr_t *uc_mgr) { struct ctl_list *ctl_list; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list == NULL) return NULL; return strdup(snd_ctl_card_info_get_longname(ctl_list->ctl_info)); @@ -79,12 +132,53 @@ static char *rval_card_components(snd_use_case_mgr_t *uc_mgr) { struct ctl_list *ctl_list; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list == NULL) return NULL; return strdup(snd_ctl_card_info_get_components(ctl_list->ctl_info)); } +static struct ctl_list *get_ctl_list_by_name(snd_use_case_mgr_t *uc_mgr, const char *id) +{ + char *name, *index; + long idx = 0; + + name = alloca(strlen(id) + 1); + strcpy(name, id); + index = strchr(name, '#'); + if (index) { + *index = '\0'; + if (safe_strtol(index + 1, &idx)) + return NULL; + } + return uc_mgr_get_ctl_by_name(uc_mgr, name, idx); +} + +static char *rval_card_number_by_name(snd_use_case_mgr_t *uc_mgr, const char *id) +{ + if (uc_mgr->conf_format < 3) { + uc_error("CardNumberByName substitution is supported in v3+ syntax"); + return NULL; + } + + return get_card_number(get_ctl_list_by_name(uc_mgr, id)); +} + +static char *rval_card_id_by_name(snd_use_case_mgr_t *uc_mgr, const char *id) +{ + struct ctl_list *ctl_list; + + if (uc_mgr->conf_format < 3) { + uc_error("CardIdByName substitution is supported in v3+ syntax"); + return NULL; + } + + ctl_list = get_ctl_list_by_name(uc_mgr, id); + if (ctl_list == NULL) + return NULL; + return strdup(snd_ctl_card_info_get_id(ctl_list->ctl_info)); +} + static char *rval_env(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char *id) { char *e; @@ -145,29 +239,35 @@ static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char return strdup(path); } -#define MATCH_VARIABLE(name, id, fcn) \ +static char *rval_var(snd_use_case_mgr_t *uc_mgr, const char *id) +{ + const char *v; + + if (uc_mgr->conf_format < 3) { + uc_error("variable substitution is supported in v3+ syntax"); + return NULL; + } + + v = uc_mgr_get_variable(uc_mgr, id); + if (v) + return strdup(v); + return NULL; +} + +#define MATCH_VARIABLE(name, id, fcn, empty_ok) \ if (strncmp((name), (id), sizeof(id) - 1) == 0) { \ rval = fcn(uc_mgr); \ idsize = sizeof(id) - 1; \ + allow_empty = (empty_ok); \ goto __rval; \ } -#define MATCH_VARIABLE2(name, id, fcn) \ +#define MATCH_VARIABLE2(name, id, fcn, empty_ok) \ if (strncmp((name), (id), sizeof(id) - 1) == 0) { \ idsize = sizeof(id) - 1; \ - tmp = strchr(value + idsize, '}'); \ - if (tmp) { \ - rvalsize = tmp - (value + idsize); \ - if (rvalsize > sizeof(v2)) { \ - err = -ENOMEM; \ - goto __error; \ - } \ - strncpy(v2, value + idsize, rvalsize); \ - v2[rvalsize] = '\0'; \ - idsize += rvalsize + 1; \ - rval = fcn(uc_mgr, v2); \ - goto __rval; \ - } \ + allow_empty = (empty_ok); \ + fcn2 = (fcn); \ + goto __match2; \ } int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr, @@ -176,7 +276,9 @@ int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr, { size_t size, nsize, idsize, rvalsize, dpos = 0; const char *tmp; - char *r, *nr, *rval, v2[32]; + char *r, *nr, *rval, v2[48]; + bool ignore_error, allow_empty; + char *(*fcn2)(snd_use_case_mgr_t *, const char *id); int err; if (value == NULL) @@ -188,54 +290,101 @@ int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr, return -ENOMEM; while (*value) { - if (*value == '$' && *(value+1) == '{') { - MATCH_VARIABLE(value, "${ConfName}", rval_conf_name); - MATCH_VARIABLE(value, "${CardId}", rval_card_id); - MATCH_VARIABLE(value, "${CardDriver}", rval_card_driver); - MATCH_VARIABLE(value, "${CardName}", rval_card_name); - MATCH_VARIABLE(value, "${CardLongName}", rval_card_longname); - MATCH_VARIABLE(value, "${CardComponents}", rval_card_components); - MATCH_VARIABLE2(value, "${env:", rval_env); - MATCH_VARIABLE2(value, "${sys:", rval_sysfs); - err = -EINVAL; - tmp = strchr(value, '}'); - if (tmp) { - strncpy(r, value, tmp + 1 - value); - r[tmp + 1 - value] = '\0'; - uc_error("variable '%s' is not known!", r); + if (*value != '$') { +__std: + r[dpos++] = *value; + value++; + continue; + } + ignore_error = false; + if (value[1] == '$' && value[2] == '{' && uc_mgr->conf_format >= 3) { + value++; + ignore_error = true; + } else if (value[1] != '{') { + goto __std; + } + allow_empty = false; + fcn2 = NULL; + MATCH_VARIABLE(value, "${OpenName}", rval_open_name, false); + MATCH_VARIABLE(value, "${ConfTopDir}", rval_conf_topdir, false); + MATCH_VARIABLE(value, "${ConfDir}", rval_conf_dir, false); + MATCH_VARIABLE(value, "${ConfName}", rval_conf_name, false); + MATCH_VARIABLE(value, "${CardNumber}", rval_card_number, true); + MATCH_VARIABLE(value, "${CardId}", rval_card_id, false); + MATCH_VARIABLE(value, "${CardDriver}", rval_card_driver, false); + MATCH_VARIABLE(value, "${CardName}", rval_card_name, false); + MATCH_VARIABLE(value, "${CardLongName}", rval_card_longname, false); + MATCH_VARIABLE(value, "${CardComponents}", rval_card_components, true); + MATCH_VARIABLE2(value, "${env:", rval_env, false); + MATCH_VARIABLE2(value, "${sys:", rval_sysfs, false); + MATCH_VARIABLE2(value, "${var:", rval_var, true); + MATCH_VARIABLE2(value, "${CardNumberByName:", rval_card_number_by_name, false); + MATCH_VARIABLE2(value, "${CardIdByName:", rval_card_id_by_name, false); +__merr: + err = -EINVAL; + tmp = strchr(value, '}'); + if (tmp) { + strncpy(r, value, tmp + 1 - value); + r[tmp + 1 - value] = '\0'; + uc_error("variable '%s' is not known!", r); + } else { + uc_error("variable reference '%s' is not complete", value); + } + goto __error; +__match2: + tmp = strchr(value + idsize, '}'); + if (tmp) { + rvalsize = tmp - (value + idsize); + if (rvalsize >= sizeof(v2)) { + err = -ENOMEM; + goto __error; + } + strncpy(v2, value + idsize, rvalsize); + v2[rvalsize] = '\0'; + idsize += rvalsize + 1; + if (*v2 == '$' && uc_mgr->conf_format >= 3) { + tmp = uc_mgr_get_variable(uc_mgr, v2 + 1); + if (tmp == NULL) { + uc_error("define '%s' is not reachable in this context!", v2 + 1); + rval = NULL; + } else { + rval = fcn2(uc_mgr, tmp); + } } else { - uc_error("variable reference '%s' is not complete", value); + rval = fcn2(uc_mgr, v2); } - goto __error; + goto __rval; + } + goto __merr; __rval: - if (rval == NULL || rval[0] == '\0') { + if (rval == NULL || (!allow_empty && rval[0] == '\0')) { + free(rval); + if (ignore_error) { + value += idsize; + continue; + } + strncpy(r, value, idsize); + r[idsize] = '\0'; + uc_error("variable '%s' is not defined in this context!", r); + err = -EINVAL; + goto __error; + } + value += idsize; + rvalsize = strlen(rval); + nsize = size + rvalsize - idsize; + if (nsize > size) { + nr = realloc(r, nsize); + if (nr == NULL) { free(rval); - strncpy(r, value, idsize); - r[idsize] = '\0'; - uc_error("variable '%s' is not defined in this context!", r); - err = -EINVAL; + err = -ENOMEM; goto __error; } - value += idsize; - rvalsize = strlen(rval); - nsize = size + rvalsize - idsize; - if (nsize > size) { - nr = realloc(r, nsize); - if (nr == NULL) { - free(rval); - err = -ENOMEM; - goto __error; - } - size = nsize; - r = nr; - } - strcpy(r + dpos, rval); - dpos += rvalsize; - free(rval); - } else { - r[dpos++] = *value; - value++; + size = nsize; + r = nr; } + strcpy(r + dpos, rval); + dpos += rvalsize; + free(rval); } r[dpos] = '\0'; diff --git a/src/ucm/utils.c b/src/ucm/utils.c index cde1d67..fbced51 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -49,26 +49,73 @@ void uc_mgr_stdout(const char *fmt,...) va_end(va); } -struct ctl_list *uc_mgr_get_one_ctl(snd_use_case_mgr_t *uc_mgr) +struct ctl_list *uc_mgr_get_master_ctl(snd_use_case_mgr_t *uc_mgr) { struct list_head *pos; - struct ctl_list *ctl_list = NULL; + struct ctl_list *ctl_list = NULL, *ctl_list2; list_for_each(pos, &uc_mgr->ctl_list) { + ctl_list2 = list_entry(pos, struct ctl_list, list); + if (ctl_list2->slave) + continue; if (ctl_list) { uc_error("multiple control device names were found!"); return NULL; } - ctl_list = list_entry(pos, struct ctl_list, list); + ctl_list = ctl_list2; } return ctl_list; } +struct ctl_list *uc_mgr_get_ctl_by_name(snd_use_case_mgr_t *uc_mgr, const char *name, int idx) +{ + struct list_head *pos; + struct ctl_list *ctl_list = NULL; + const char *s; + char cname[32]; + int idx2, card, err; + + idx2 = idx; + list_for_each(pos, &uc_mgr->ctl_list) { + ctl_list = list_entry(pos, struct ctl_list, list); + s = snd_ctl_card_info_get_name(ctl_list->ctl_info); + if (s == NULL) + continue; + if (strcmp(s, name) == 0) { + if (idx2 == 0) + return ctl_list; + idx2--; + } + } + + idx2 = idx; + card = -1; + if (snd_card_next(&card) < 0 || card < 0) + return NULL; + + while (card >= 0) { + sprintf(cname, "hw:%d", card); + err = uc_mgr_open_ctl(uc_mgr, &ctl_list, cname, 1); + if (err < 0) + continue; /* really? */ + s = snd_ctl_card_info_get_name(ctl_list->ctl_info); + if (s && strcmp(s, name) == 0) { + if (idx2 == 0) + return ctl_list; + idx2--; + } + if (snd_card_next(&card) < 0) + break; + } + + return NULL; +} + snd_ctl_t *uc_mgr_get_ctl(snd_use_case_mgr_t *uc_mgr) { struct ctl_list *ctl_list; - ctl_list = uc_mgr_get_one_ctl(uc_mgr); + ctl_list = uc_mgr_get_master_ctl(uc_mgr); if (ctl_list) return ctl_list->ctl; return NULL; @@ -127,10 +174,11 @@ static int uc_mgr_ctl_add_dev(struct ctl_list *ctl_list, const char *device) } static int uc_mgr_ctl_add(snd_use_case_mgr_t *uc_mgr, - struct ctl_list *ctl_list, + struct ctl_list **ctl_list, snd_ctl_t *ctl, int card, snd_ctl_card_info_t *info, - const char *device) + const char *device, + int slave) { struct ctl_list *cl = NULL; const char *id = snd_ctl_card_info_get_id(info); @@ -139,7 +187,7 @@ static int uc_mgr_ctl_add(snd_use_case_mgr_t *uc_mgr, if (id == NULL || id[0] == '\0') return -ENOENT; - if (!ctl_list) { + if (!(*ctl_list)) { cl = malloc(sizeof(*cl)); if (cl == NULL) return -ENOMEM; @@ -150,41 +198,49 @@ static int uc_mgr_ctl_add(snd_use_case_mgr_t *uc_mgr, return -ENOMEM; } snd_ctl_card_info_copy(cl->ctl_info, info); - ctl_list = cl; + cl->slave = slave; + *ctl_list = cl; + } else { + if (!slave) + (*ctl_list)->slave = slave; } if (card >= 0) { snprintf(dev, sizeof(dev), "hw:%d", card); hit |= !!(device && (strcmp(dev, device) == 0)); - err = uc_mgr_ctl_add_dev(ctl_list, dev); + err = uc_mgr_ctl_add_dev(*ctl_list, dev); if (err < 0) goto __nomem; } snprintf(dev, sizeof(dev), "hw:%s", id); hit |= !!(device && (strcmp(dev, device) == 0)); - err = uc_mgr_ctl_add_dev(ctl_list, dev); + err = uc_mgr_ctl_add_dev(*ctl_list, dev); if (err < 0) goto __nomem; /* the UCM name not based on the card name / id */ if (!hit && device) { - err = uc_mgr_ctl_add_dev(ctl_list, device); + err = uc_mgr_ctl_add_dev(*ctl_list, device); if (err < 0) goto __nomem; } - list_add_tail(&ctl_list->list, &uc_mgr->ctl_list); + list_add_tail(&(*ctl_list)->list, &uc_mgr->ctl_list); return 0; __nomem: - if (ctl_list == cl) + if (*ctl_list == cl) { uc_mgr_free_ctl(cl); + *ctl_list = NULL; + } return -ENOMEM; } int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr, - snd_ctl_t **ctl, - const char *device) + struct ctl_list **ctll, + const char *device, + int slave) { struct list_head *pos1, *pos2; + snd_ctl_t *ctl; struct ctl_list *ctl_list; struct ctl_dev *ctl_dev; snd_ctl_card_info_t *info; @@ -199,25 +255,26 @@ int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr, list_for_each(pos2, &ctl_list->dev_list) { ctl_dev = list_entry(pos2, struct ctl_dev, list); if (strcmp(ctl_dev->device, device) == 0) { - *ctl = ctl_list->ctl; + *ctll = ctl_list; + if (!slave) + ctl_list->slave = 0; return 0; } } } - err = snd_ctl_open(ctl, device, 0); + err = snd_ctl_open(&ctl, device, 0); if (err < 0) return err; id = NULL; - err = snd_ctl_card_info(*ctl, info); + err = snd_ctl_card_info(ctl, info); if (err == 0) id = snd_ctl_card_info_get_id(info); if (err < 0 || id == NULL || id[0] == '\0') { uc_error("control hardware info (%s): %s", device, snd_strerror(err)); - snd_ctl_close(*ctl); - *ctl = NULL; - return err; + snd_ctl_close(ctl); + return err >= 0 ? -EINVAL : err; } /* insert to cache, if just name differs */ @@ -225,33 +282,50 @@ int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr, ctl_list = list_entry(pos1, struct ctl_list, list); if (strcmp(id, snd_ctl_card_info_get_id(ctl_list->ctl_info)) == 0) { card = snd_card_get_index(id); - err = uc_mgr_ctl_add(uc_mgr, ctl_list, *ctl, card, info, device); + err = uc_mgr_ctl_add(uc_mgr, &ctl_list, ctl, card, info, device, slave); if (err < 0) goto __nomem; - snd_ctl_close(*ctl); - *ctl = ctl_list->ctl; + snd_ctl_close(ctl); + *ctll = ctl_list; return 0; } } - err = uc_mgr_ctl_add(uc_mgr, NULL, *ctl, -1, info, device); + ctl_list = NULL; + err = uc_mgr_ctl_add(uc_mgr, &ctl_list, ctl, -1, info, device, slave); if (err < 0) goto __nomem; + *ctll = ctl_list; return 0; __nomem: - snd_ctl_close(*ctl); - *ctl = NULL; + snd_ctl_close(ctl); return -ENOMEM; } +const char *uc_mgr_config_dir(int format) +{ + const char *path; + + if (format >= 2) { + path = getenv(ALSA_CONFIG_UCM2_VAR); + if (!path || path[0] == '\0') + path = ALSA_CONFIG_DIR "/ucm2"; + } else { + path = getenv(ALSA_CONFIG_UCM_VAR); + if (!path || path[0] == '\0') + path = ALSA_CONFIG_DIR "/ucm"; + } + return path; +} + int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg) { FILE *fp; snd_input_t *in; snd_config_t *top; - const char *path, *default_paths[2]; + const char *default_paths[2]; int err; fp = fopen(file, "r"); @@ -268,17 +342,7 @@ int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg) if (err < 0) goto __err1; - if (format >= 2) { - path = getenv(ALSA_CONFIG_UCM2_VAR); - if (!path || path[0] == '\0') - path = ALSA_CONFIG_DIR "/ucm2"; - } else { - path = getenv(ALSA_CONFIG_UCM_VAR); - if (!path || path[0] == '\0') - path = ALSA_CONFIG_DIR "/ucm"; - } - - default_paths[0] = path; + default_paths[0] = uc_mgr_config_dir(format); default_paths[1] = NULL; err = _snd_config_load_with_include(top, in, 0, default_paths); if (err < 0) { @@ -328,6 +392,69 @@ void uc_mgr_free_dev_list(struct dev_list *dev_list) } } +int uc_mgr_put_to_dev_list(struct dev_list *dev_list, const char *name) +{ + struct list_head *pos; + struct dev_list_node *dlist; + char *n; + + list_for_each(pos, &dev_list->list) { + dlist = list_entry(pos, struct dev_list_node, list); + if (strcmp(dlist->name, name) == 0) + return 0; + } + + dlist = calloc(1, sizeof(*dlist)); + if (dlist == NULL) + return -ENOMEM; + n = strdup(name); + if (n == NULL) { + free(dlist); + return -ENOMEM; + } + dlist->name = n; + list_add(&dlist->list, &dev_list->list); + return 0; +} + +int uc_mgr_rename_in_dev_list(struct dev_list *dev_list, const char *src, + const char *dst) +{ + struct list_head *pos; + struct dev_list_node *dlist; + char *dst1; + + list_for_each(pos, &dev_list->list) { + dlist = list_entry(pos, struct dev_list_node, list); + if (strcmp(dlist->name, src) == 0) { + dst1 = strdup(dst); + if (dst1 == NULL) + return -ENOMEM; + free(dlist->name); + dlist->name = dst1; + return 0; + } + } + return -ENODEV; +} + +int uc_mgr_remove_from_dev_list(struct dev_list *dev_list, const char *name) +{ + struct list_head *pos; + struct dev_list_node *dlist; + + list_for_each(pos, &dev_list->list) { + dlist = list_entry(pos, struct dev_list_node, list); + if (strcmp(dlist->name, name) == 0) { + free(dlist->name); + list_del(&dlist->list); + free(dlist); + return 0; + } + } + return -ENODEV; +} + void uc_mgr_free_sequence_element(struct sequence_element *seq) { if (seq == NULL) @@ -381,6 +508,20 @@ void uc_mgr_free_transition(struct list_head *base) } } +void uc_mgr_free_dev_name_list(struct list_head *base) +{ + struct list_head *pos, *npos; + struct ucm_dev_name *dev; + + list_for_each_safe(pos, npos, base) { + dev = list_entry(pos, struct ucm_dev_name, list); + list_del(&dev->list); + free(dev->name1); + free(dev->name2); + free(dev); + } +} + void uc_mgr_free_modifier(struct list_head *base) { struct list_head *pos, *npos; @@ -400,23 +541,123 @@ void uc_mgr_free_modifier(struct list_head *base) } } -void uc_mgr_free_device(struct list_head *base) +void uc_mgr_free_device(struct use_case_device *dev) +{ + free(dev->name); + free(dev->comment); + uc_mgr_free_sequence(&dev->enable_list); + uc_mgr_free_sequence(&dev->disable_list); + uc_mgr_free_transition(&dev->transition_list); + uc_mgr_free_dev_list(&dev->dev_list); + uc_mgr_free_value(&dev->value_list); + list_del(&dev->list); + free(dev); +} + +void uc_mgr_free_device_list(struct list_head *base) { struct list_head *pos, *npos; struct use_case_device *dev; list_for_each_safe(pos, npos, base) { dev = list_entry(pos, struct use_case_device, list); - free(dev->name); - free(dev->comment); - uc_mgr_free_sequence(&dev->enable_list); - uc_mgr_free_sequence(&dev->disable_list); - uc_mgr_free_transition(&dev->transition_list); - uc_mgr_free_dev_list(&dev->dev_list); - uc_mgr_free_value(&dev->value_list); - list_del(&dev->list); - free(dev); + uc_mgr_free_device(dev); + } +} + +int uc_mgr_rename_device(struct use_case_verb *verb, const char *src, + const char *dst) +{ + struct use_case_device *device; + struct list_head *pos, *npos; + char *dst1; + + /* no errors when device is not found */ + list_for_each_safe(pos, npos, &verb->device_list) { + device = list_entry(pos, struct use_case_device, list); + if (strcmp(device->name, src) == 0) { + dst1 = strdup(dst); + if (dst1 == NULL) + return -ENOMEM; + free(device->name); + device->name = dst1; + continue; + } + uc_mgr_rename_in_dev_list(&device->dev_list, src, dst); + } + return 0; +} + +int uc_mgr_remove_device(struct use_case_verb *verb, const char *name) +{ + struct use_case_device *device; + struct list_head *pos, *npos; + int err, found = 0; + + list_for_each_safe(pos, npos, &verb->device_list) { + device = list_entry(pos, struct use_case_device, list); + if (strcmp(device->name, name) == 0) { + uc_mgr_free_device(device); + found++; + continue; + } + err = uc_mgr_remove_from_dev_list(&device->dev_list, name); + if (err < 0 && err != -ENODEV) + return err; + if (err == 0) + found++; + } + return found == 0 ? -ENODEV : 0; +} + +const char *uc_mgr_get_variable(snd_use_case_mgr_t *uc_mgr, const char *name) +{ + struct list_head *pos; + struct ucm_value *value; + + list_for_each(pos, &uc_mgr->variable_list) { + value = list_entry(pos, struct ucm_value, list); + if (strcmp(value->name, name) == 0) + return value->data; + } + return NULL; +} + +int uc_mgr_set_variable(snd_use_case_mgr_t *uc_mgr, const char *name, + const char *val) +{ + struct list_head *pos; + struct ucm_value *curr; + char *val2; + + list_for_each(pos, &uc_mgr->variable_list) { + curr = list_entry(pos, struct ucm_value, list); + if (strcmp(curr->name, name) == 0) { + val2 = strdup(val); + if (val2 == NULL) + return -ENOMEM; + free(curr->data); + curr->data = val2; + return 0; + } + } + + curr = calloc(1, sizeof(struct ucm_value)); + if (curr == NULL) + return -ENOMEM; + curr->name = strdup(name); + if (curr->name == NULL) { + free(curr); + return -ENOMEM; + } + curr->data = strdup(val); + if (curr->data == NULL) { + free(curr->name); + free(curr); + return -ENOMEM; } + list_add_tail(&curr->list, &uc_mgr->variable_list); + return 0; } void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) @@ -432,16 +673,24 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr) uc_mgr_free_sequence(&verb->disable_list); uc_mgr_free_transition(&verb->transition_list); uc_mgr_free_value(&verb->value_list); - uc_mgr_free_device(&verb->device_list); - uc_mgr_free_device(&verb->cmpt_device_list); + uc_mgr_free_device_list(&verb->device_list); + uc_mgr_free_device_list(&verb->cmpt_device_list); uc_mgr_free_modifier(&verb->modifier_list); + uc_mgr_free_dev_name_list(&verb->rename_list); + uc_mgr_free_dev_name_list(&verb->remove_list); list_del(&verb->list); free(verb); } + uc_mgr_free_sequence(&uc_mgr->once_list); uc_mgr_free_sequence(&uc_mgr->default_list); uc_mgr_free_value(&uc_mgr->value_list); + uc_mgr_free_value(&uc_mgr->variable_list); free(uc_mgr->comment); + free(uc_mgr->conf_dir_name); + free(uc_mgr->conf_file_name); uc_mgr->comment = NULL; + uc_mgr->conf_dir_name = NULL; + uc_mgr->conf_file_name = NULL; uc_mgr->active_verb = NULL; INIT_LIST_HEAD(&uc_mgr->active_devices); INIT_LIST_HEAD(&uc_mgr->active_modifiers); diff --git a/test/pcm_min.c b/test/pcm_min.c index 7462a45..4c120b4 100644 --- a/test/pcm_min.c +++ b/test/pcm_min.c @@ -5,47 +5,49 @@ #include "../include/asoundlib.h" static char *device = "default"; /* playback device */ - -snd_output_t *output = NULL; unsigned char buffer[16*1024]; /* some random data */ int main(void) { - int err; - unsigned int i; - snd_pcm_t *handle; - snd_pcm_sframes_t frames; + int err; + unsigned int i; + snd_pcm_t *handle; + snd_pcm_sframes_t frames; - for (i = 0; i < sizeof(buffer); i++) - buffer[i] = random() & 0xff; + for (i = 0; i < sizeof(buffer); i++) + buffer[i] = random() & 0xff; if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Playback open error: %s\n", snd_strerror(err)); exit(EXIT_FAILURE); } if ((err = snd_pcm_set_params(handle, - SND_PCM_FORMAT_U8, - SND_PCM_ACCESS_RW_INTERLEAVED, - 1, - 48000, - 1, - 500000)) < 0) { /* 0.5sec */ + SND_PCM_FORMAT_U8, + SND_PCM_ACCESS_RW_INTERLEAVED, + 1, + 48000, + 1, + 500000)) < 0) { /* 0.5sec */ printf("Playback open error: %s\n", snd_strerror(err)); exit(EXIT_FAILURE); } for (i = 0; i < 16; i++) { - frames = snd_pcm_writei(handle, buffer, sizeof(buffer)); - if (frames < 0) - frames = snd_pcm_recover(handle, frames, 0); - if (frames < 0) { - printf("snd_pcm_writei failed: %s\n", snd_strerror(frames)); - break; - } - if (frames > 0 && frames < (long)sizeof(buffer)) - printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames); - } + frames = snd_pcm_writei(handle, buffer, sizeof(buffer)); + if (frames < 0) + frames = snd_pcm_recover(handle, frames, 0); + if (frames < 0) { + printf("snd_pcm_writei failed: %s\n", snd_strerror(frames)); + break; + } + if (frames > 0 && frames < (long)sizeof(buffer)) + printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames); + } + /* pass the remaining samples, otherwise they're dropped in close */ + err = snd_pcm_drain(handle); + if (err < 0) + printf("snd_pcm_drain failed: %s\n", snd_strerror(err)); snd_pcm_close(handle); return 0; } diff --git a/utils/alsa.m4 b/utils/alsa.m4 index 4c457f0..04cc880 100644 --- a/utils/alsa.m4 +++ b/utils/alsa.m4 @@ -22,6 +22,7 @@ alsa_save_CFLAGS="$CFLAGS" alsa_save_LDFLAGS="$LDFLAGS" alsa_save_LIBS="$LIBS" alsa_found=yes +alsa_topology_found=no dnl dnl Get the cflags and libraries for alsa @@ -158,10 +159,18 @@ AC_CHECK_LIB([asound], [snd_ctl_open],, alsa_found=no] ) if test "x$enable_atopology" = "xyes"; then +alsa_topology_found=yes +alsa_save_LIBS2="$LIBS" AC_CHECK_LIB([atopology], [snd_tplg_new],, [ifelse([$3], , [AC_MSG_ERROR(No linkable libatopology was found.)]) - alsa_found=no] + alsa_topology_found=no, +] ) +LIBS="$alsa_save_LIBS2" +fi +else +if test "x$enable_atopology" = "xyes"; then + alsa_topology_found=yes fi fi @@ -183,7 +192,7 @@ fi dnl add the alsa topology library; must be at the end AC_MSG_CHECKING(for ALSA topology LDFLAGS) -if test "x$enable_atopology" = "xyes"; then +if test "x$alsa_topology_found" = "xyes"; then ALSA_TOPOLOGY_LIBS="$ALSA_TOPOLOGY_LIBS -latopology" fi AC_MSG_RESULT($ALSA_TOPOLOGY_LIBS) diff --git a/version b/version index ff81ff4..fc041a3 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.2.1.2 +1.2.3.2