2008-07-27 07:56:38 +08:00
|
|
|
/*
|
|
|
|
* dsp_pipeline.c: pipelined audio processing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, Nadi Sarrar
|
|
|
|
*
|
|
|
|
* Nadi Sarrar <nadi@beronet.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The full GNU General Public License is included in this distribution in the
|
|
|
|
* file called LICENSE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-07-27 07:56:38 +08:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mISDNif.h>
|
|
|
|
#include <linux/mISDNdsp.h>
|
2011-07-11 00:23:16 +08:00
|
|
|
#include <linux/export.h>
|
2008-07-27 07:56:38 +08:00
|
|
|
#include "dsp.h"
|
|
|
|
#include "dsp_hwec.h"
|
|
|
|
|
|
|
|
/* uncomment for debugging */
|
|
|
|
/*#define PIPELINE_DEBUG*/
|
|
|
|
|
|
|
|
struct dsp_pipeline_entry {
|
|
|
|
struct mISDN_dsp_element *elem;
|
|
|
|
void *p;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
struct dsp_element_entry {
|
|
|
|
struct mISDN_dsp_element *elem;
|
|
|
|
struct device dev;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(dsp_elements);
|
|
|
|
|
|
|
|
/* sysfs */
|
|
|
|
static struct class *elements_class;
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
attr_show_args(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct mISDN_dsp_element *elem = dev_get_drvdata(dev);
|
2009-06-02 21:37:37 +08:00
|
|
|
int i;
|
|
|
|
char *p = buf;
|
2008-07-27 07:56:38 +08:00
|
|
|
|
|
|
|
*buf = 0;
|
2009-06-02 21:37:37 +08:00
|
|
|
for (i = 0; i < elem->num_args; i++)
|
|
|
|
p += sprintf(p, "Name: %s\n%s%s%sDescription: %s\n\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
elem->args[i].name,
|
|
|
|
elem->args[i].def ? "Default: " : "",
|
|
|
|
elem->args[i].def ? elem->args[i].def : "",
|
|
|
|
elem->args[i].def ? "\n" : "",
|
|
|
|
elem->args[i].desc);
|
2008-07-27 07:56:38 +08:00
|
|
|
|
2009-06-02 21:37:37 +08:00
|
|
|
return p - buf;
|
2008-07-27 07:56:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_attribute element_attributes[] = {
|
|
|
|
__ATTR(args, 0444, attr_show_args, NULL),
|
|
|
|
};
|
|
|
|
|
2008-09-28 21:40:15 +08:00
|
|
|
static void
|
|
|
|
mISDN_dsp_dev_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct dsp_element_entry *entry =
|
|
|
|
container_of(dev, struct dsp_element_entry, dev);
|
|
|
|
list_del(&entry->list);
|
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
|
2008-07-27 07:56:38 +08:00
|
|
|
int mISDN_dsp_element_register(struct mISDN_dsp_element *elem)
|
|
|
|
{
|
|
|
|
struct dsp_element_entry *entry;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
if (!elem)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-10-11 14:13:29 +08:00
|
|
|
entry = kzalloc(sizeof(struct dsp_element_entry), GFP_ATOMIC);
|
2008-07-27 07:56:38 +08:00
|
|
|
if (!entry)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
entry->elem = elem;
|
|
|
|
|
|
|
|
entry->dev.class = elements_class;
|
2008-09-28 21:40:15 +08:00
|
|
|
entry->dev.release = mISDN_dsp_dev_release;
|
2008-07-27 07:56:38 +08:00
|
|
|
dev_set_drvdata(&entry->dev, elem);
|
2013-07-04 06:04:56 +08:00
|
|
|
dev_set_name(&entry->dev, "%s", elem->name);
|
2008-07-27 07:56:38 +08:00
|
|
|
ret = device_register(&entry->dev);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "%s: failed to register %s\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, elem->name);
|
2008-07-27 07:56:38 +08:00
|
|
|
goto err1;
|
|
|
|
}
|
2008-09-28 21:40:15 +08:00
|
|
|
list_add_tail(&entry->list, &dsp_elements);
|
2008-07-27 07:56:38 +08:00
|
|
|
|
2009-01-10 04:22:52 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(element_attributes); ++i) {
|
2008-07-27 07:56:38 +08:00
|
|
|
ret = device_create_file(&entry->dev,
|
2012-02-20 11:52:38 +08:00
|
|
|
&element_attributes[i]);
|
2008-07-27 07:56:38 +08:00
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "%s: failed to create device file\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__);
|
2008-07-27 07:56:38 +08:00
|
|
|
goto err2;
|
|
|
|
}
|
2009-01-10 04:22:52 +08:00
|
|
|
}
|
2008-07-27 07:56:38 +08:00
|
|
|
|
2008-09-28 21:40:15 +08:00
|
|
|
#ifdef PIPELINE_DEBUG
|
2008-07-27 07:56:38 +08:00
|
|
|
printk(KERN_DEBUG "%s: %s registered\n", __func__, elem->name);
|
2008-09-28 21:40:15 +08:00
|
|
|
#endif
|
2008-07-27 07:56:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err2:
|
|
|
|
device_unregister(&entry->dev);
|
2008-09-28 21:40:15 +08:00
|
|
|
return ret;
|
2008-07-27 07:56:38 +08:00
|
|
|
err1:
|
|
|
|
kfree(entry);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mISDN_dsp_element_register);
|
|
|
|
|
|
|
|
void mISDN_dsp_element_unregister(struct mISDN_dsp_element *elem)
|
|
|
|
{
|
|
|
|
struct dsp_element_entry *entry, *n;
|
|
|
|
|
|
|
|
if (!elem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, n, &dsp_elements, list)
|
|
|
|
if (entry->elem == elem) {
|
|
|
|
device_unregister(&entry->dev);
|
2008-09-28 21:40:15 +08:00
|
|
|
#ifdef PIPELINE_DEBUG
|
2008-07-27 07:56:38 +08:00
|
|
|
printk(KERN_DEBUG "%s: %s unregistered\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, elem->name);
|
2008-09-28 21:40:15 +08:00
|
|
|
#endif
|
2008-07-27 07:56:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
printk(KERN_ERR "%s: element %s not in list.\n", __func__, elem->name);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mISDN_dsp_element_unregister);
|
|
|
|
|
|
|
|
int dsp_pipeline_module_init(void)
|
|
|
|
{
|
|
|
|
elements_class = class_create(THIS_MODULE, "dsp_pipeline");
|
|
|
|
if (IS_ERR(elements_class))
|
|
|
|
return PTR_ERR(elements_class);
|
|
|
|
|
|
|
|
#ifdef PIPELINE_DEBUG
|
|
|
|
printk(KERN_DEBUG "%s: dsp pipeline module initialized\n", __func__);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dsp_hwec_init();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dsp_pipeline_module_exit(void)
|
|
|
|
{
|
|
|
|
struct dsp_element_entry *entry, *n;
|
|
|
|
|
|
|
|
dsp_hwec_exit();
|
|
|
|
|
|
|
|
class_destroy(elements_class);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, n, &dsp_elements, list) {
|
|
|
|
list_del(&entry->list);
|
|
|
|
printk(KERN_WARNING "%s: element was still registered: %s\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, entry->elem->name);
|
2008-07-27 07:56:38 +08:00
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
|
2008-09-28 21:40:15 +08:00
|
|
|
#ifdef PIPELINE_DEBUG
|
2008-07-27 07:56:38 +08:00
|
|
|
printk(KERN_DEBUG "%s: dsp pipeline module exited\n", __func__);
|
2008-09-28 21:40:15 +08:00
|
|
|
#endif
|
2008-07-27 07:56:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int dsp_pipeline_init(struct dsp_pipeline *pipeline)
|
|
|
|
{
|
|
|
|
if (!pipeline)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&pipeline->list);
|
|
|
|
|
|
|
|
#ifdef PIPELINE_DEBUG
|
|
|
|
printk(KERN_DEBUG "%s: dsp pipeline ready\n", __func__);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _dsp_pipeline_destroy(struct dsp_pipeline *pipeline)
|
|
|
|
{
|
|
|
|
struct dsp_pipeline_entry *entry, *n;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, n, &pipeline->list, list) {
|
|
|
|
list_del(&entry->list);
|
|
|
|
if (entry->elem == dsp_hwec)
|
|
|
|
dsp_hwec_disable(container_of(pipeline, struct dsp,
|
2012-02-20 11:52:38 +08:00
|
|
|
pipeline));
|
2008-07-27 07:56:38 +08:00
|
|
|
else
|
|
|
|
entry->elem->free(entry->p);
|
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dsp_pipeline_destroy(struct dsp_pipeline *pipeline)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!pipeline)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_dsp_pipeline_destroy(pipeline);
|
|
|
|
|
|
|
|
#ifdef PIPELINE_DEBUG
|
|
|
|
printk(KERN_DEBUG "%s: dsp pipeline destroyed\n", __func__);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg)
|
|
|
|
{
|
|
|
|
int len, incomplete = 0, found = 0;
|
|
|
|
char *dup, *tok, *name, *args;
|
|
|
|
struct dsp_element_entry *entry, *n;
|
|
|
|
struct dsp_pipeline_entry *pipeline_entry;
|
|
|
|
struct mISDN_dsp_element *elem;
|
|
|
|
|
|
|
|
if (!pipeline)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!list_empty(&pipeline->list))
|
|
|
|
_dsp_pipeline_destroy(pipeline);
|
|
|
|
|
|
|
|
if (!cfg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = strlen(cfg);
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
|
|
|
|
2008-10-11 14:13:29 +08:00
|
|
|
dup = kmalloc(len + 1, GFP_ATOMIC);
|
2008-07-27 07:56:38 +08:00
|
|
|
if (!dup)
|
|
|
|
return 0;
|
|
|
|
strcpy(dup, cfg);
|
|
|
|
while ((tok = strsep(&dup, "|"))) {
|
|
|
|
if (!strlen(tok))
|
|
|
|
continue;
|
|
|
|
name = strsep(&tok, "(");
|
|
|
|
args = strsep(&tok, ")");
|
|
|
|
if (args && !*args)
|
2008-12-13 13:11:28 +08:00
|
|
|
args = NULL;
|
2008-07-27 07:56:38 +08:00
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, n, &dsp_elements, list)
|
|
|
|
if (!strcmp(entry->elem->name, name)) {
|
|
|
|
elem = entry->elem;
|
|
|
|
|
|
|
|
pipeline_entry = kmalloc(sizeof(struct
|
2012-02-20 11:52:38 +08:00
|
|
|
dsp_pipeline_entry), GFP_ATOMIC);
|
2008-07-27 07:56:38 +08:00
|
|
|
if (!pipeline_entry) {
|
2008-09-28 21:40:15 +08:00
|
|
|
printk(KERN_ERR "%s: failed to add "
|
2012-02-20 11:52:38 +08:00
|
|
|
"entry to pipeline: %s (out of "
|
|
|
|
"memory)\n", __func__, elem->name);
|
2008-07-27 07:56:38 +08:00
|
|
|
incomplete = 1;
|
|
|
|
goto _out;
|
|
|
|
}
|
|
|
|
pipeline_entry->elem = elem;
|
|
|
|
|
|
|
|
if (elem == dsp_hwec) {
|
|
|
|
/* This is a hack to make the hwec
|
|
|
|
available as a pipeline module */
|
|
|
|
dsp_hwec_enable(container_of(pipeline,
|
2012-02-20 11:52:38 +08:00
|
|
|
struct dsp, pipeline), args);
|
2008-07-27 07:56:38 +08:00
|
|
|
list_add_tail(&pipeline_entry->list,
|
2012-02-20 11:52:38 +08:00
|
|
|
&pipeline->list);
|
2008-07-27 07:56:38 +08:00
|
|
|
} else {
|
|
|
|
pipeline_entry->p = elem->new(args);
|
|
|
|
if (pipeline_entry->p) {
|
|
|
|
list_add_tail(&pipeline_entry->
|
2012-02-20 11:52:38 +08:00
|
|
|
list, &pipeline->list);
|
2008-07-27 07:56:38 +08:00
|
|
|
#ifdef PIPELINE_DEBUG
|
|
|
|
printk(KERN_DEBUG "%s: created "
|
2012-02-20 11:52:38 +08:00
|
|
|
"instance of %s%s%s\n",
|
|
|
|
__func__, name, args ?
|
|
|
|
" with args " : "", args ?
|
|
|
|
args : "");
|
2008-07-27 07:56:38 +08:00
|
|
|
#endif
|
|
|
|
} else {
|
2008-09-28 21:40:15 +08:00
|
|
|
printk(KERN_ERR "%s: failed "
|
2012-02-20 11:52:38 +08:00
|
|
|
"to add entry to pipeline: "
|
|
|
|
"%s (new() returned NULL)\n",
|
|
|
|
__func__, elem->name);
|
2008-07-27 07:56:38 +08:00
|
|
|
kfree(pipeline_entry);
|
|
|
|
incomplete = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
found = 0;
|
|
|
|
else {
|
2008-09-28 21:40:15 +08:00
|
|
|
printk(KERN_ERR "%s: element not found, skipping: "
|
2012-02-20 11:52:38 +08:00
|
|
|
"%s\n", __func__, name);
|
2008-07-27 07:56:38 +08:00
|
|
|
incomplete = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_out:
|
|
|
|
if (!list_empty(&pipeline->list))
|
|
|
|
pipeline->inuse = 1;
|
|
|
|
else
|
|
|
|
pipeline->inuse = 0;
|
|
|
|
|
|
|
|
#ifdef PIPELINE_DEBUG
|
|
|
|
printk(KERN_DEBUG "%s: dsp pipeline built%s: %s\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
__func__, incomplete ? " incomplete" : "", cfg);
|
2008-07-27 07:56:38 +08:00
|
|
|
#endif
|
|
|
|
kfree(dup);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data, int len)
|
|
|
|
{
|
|
|
|
struct dsp_pipeline_entry *entry;
|
|
|
|
|
|
|
|
if (!pipeline)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &pipeline->list, list)
|
|
|
|
if (entry->elem->process_tx)
|
|
|
|
entry->elem->process_tx(entry->p, data, len);
|
|
|
|
}
|
|
|
|
|
2009-05-22 19:04:46 +08:00
|
|
|
void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data, int len,
|
2012-02-20 11:52:38 +08:00
|
|
|
unsigned int txlen)
|
2008-07-27 07:56:38 +08:00
|
|
|
{
|
|
|
|
struct dsp_pipeline_entry *entry;
|
|
|
|
|
|
|
|
if (!pipeline)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_for_each_entry_reverse(entry, &pipeline->list, list)
|
|
|
|
if (entry->elem->process_rx)
|
2009-05-22 19:04:46 +08:00
|
|
|
entry->elem->process_rx(entry->p, data, len, txlen);
|
2008-07-27 07:56:38 +08:00
|
|
|
}
|