kernel-fxtec-pro1x/sound/oss/msnd.c
Tejun Heo 5a0e3ad6af 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-30 22:02:32 +09:00

413 lines
8.2 KiB
C

/*********************************************************************
*
* msnd.c - Driver Base
*
* Turtle Beach MultiSound Sound Card Driver for Linux
*
* Copyright (C) 1998 Andrew Veliath
*
* 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 <linux/module.h>
#include <linux/kernel.h>
#include <linux/vmalloc.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/spinlock.h>
#include <asm/irq.h>
#include "msnd.h"
#define LOGNAME "msnd"
#define MSND_MAX_DEVS 4
static multisound_dev_t *devs[MSND_MAX_DEVS];
static int num_devs;
int msnd_register(multisound_dev_t *dev)
{
int i;
for (i = 0; i < MSND_MAX_DEVS; ++i)
if (devs[i] == NULL)
break;
if (i == MSND_MAX_DEVS)
return -ENOMEM;
devs[i] = dev;
++num_devs;
return 0;
}
void msnd_unregister(multisound_dev_t *dev)
{
int i;
for (i = 0; i < MSND_MAX_DEVS; ++i)
if (devs[i] == dev)
break;
if (i == MSND_MAX_DEVS) {
printk(KERN_WARNING LOGNAME ": Unregistering unknown device\n");
return;
}
devs[i] = NULL;
--num_devs;
}
void msnd_init_queue(void __iomem *base, int start, int size)
{
writew(PCTODSP_BASED(start), base + JQS_wStart);
writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
writew(0, base + JQS_wHead);
writew(0, base + JQS_wTail);
}
void msnd_fifo_init(msnd_fifo *f)
{
f->data = NULL;
}
void msnd_fifo_free(msnd_fifo *f)
{
vfree(f->data);
f->data = NULL;
}
int msnd_fifo_alloc(msnd_fifo *f, size_t n)
{
msnd_fifo_free(f);
f->data = vmalloc(n);
f->n = n;
f->tail = 0;
f->head = 0;
f->len = 0;
if (!f->data)
return -ENOMEM;
return 0;
}
void msnd_fifo_make_empty(msnd_fifo *f)
{
f->len = f->tail = f->head = 0;
}
int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len)
{
int count = 0;
while ((count < len) && (f->len != f->n)) {
int nwritten;
if (f->head <= f->tail) {
nwritten = len - count;
if (nwritten > f->n - f->tail)
nwritten = f->n - f->tail;
}
else {
nwritten = f->head - f->tail;
if (nwritten > len - count)
nwritten = len - count;
}
memcpy_fromio(f->data + f->tail, buf, nwritten);
count += nwritten;
buf += nwritten;
f->len += nwritten;
f->tail += nwritten;
f->tail %= f->n;
}
return count;
}
int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len)
{
int count = 0;
while ((count < len) && (f->len != f->n)) {
int nwritten;
if (f->head <= f->tail) {
nwritten = len - count;
if (nwritten > f->n - f->tail)
nwritten = f->n - f->tail;
}
else {
nwritten = f->head - f->tail;
if (nwritten > len - count)
nwritten = len - count;
}
memcpy(f->data + f->tail, buf, nwritten);
count += nwritten;
buf += nwritten;
f->len += nwritten;
f->tail += nwritten;
f->tail %= f->n;
}
return count;
}
int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len)
{
int count = 0;
while ((count < len) && (f->len > 0)) {
int nread;
if (f->tail <= f->head) {
nread = len - count;
if (nread > f->n - f->head)
nread = f->n - f->head;
}
else {
nread = f->tail - f->head;
if (nread > len - count)
nread = len - count;
}
memcpy_toio(buf, f->data + f->head, nread);
count += nread;
buf += nread;
f->len -= nread;
f->head += nread;
f->head %= f->n;
}
return count;
}
int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len)
{
int count = 0;
while ((count < len) && (f->len > 0)) {
int nread;
if (f->tail <= f->head) {
nread = len - count;
if (nread > f->n - f->head)
nread = f->n - f->head;
}
else {
nread = f->tail - f->head;
if (nread > len - count)
nread = len - count;
}
memcpy(buf, f->data + f->head, nread);
count += nread;
buf += nread;
f->len -= nread;
f->head += nread;
f->head %= f->n;
}
return count;
}
static int msnd_wait_TXDE(multisound_dev_t *dev)
{
register unsigned int io = dev->io;
register int timeout = 1000;
while(timeout-- > 0)
if (msnd_inb(io + HP_ISR) & HPISR_TXDE)
return 0;
return -EIO;
}
static int msnd_wait_HC0(multisound_dev_t *dev)
{
register unsigned int io = dev->io;
register int timeout = 1000;
while(timeout-- > 0)
if (!(msnd_inb(io + HP_CVR) & HPCVR_HC))
return 0;
return -EIO;
}
int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd)
{
unsigned long flags;
spin_lock_irqsave(&dev->lock, flags);
if (msnd_wait_HC0(dev) == 0) {
msnd_outb(cmd, dev->io + HP_CVR);
spin_unlock_irqrestore(&dev->lock, flags);
return 0;
}
spin_unlock_irqrestore(&dev->lock, flags);
printk(KERN_DEBUG LOGNAME ": Send DSP command timeout\n");
return -EIO;
}
int msnd_send_word(multisound_dev_t *dev, unsigned char high,
unsigned char mid, unsigned char low)
{
register unsigned int io = dev->io;
if (msnd_wait_TXDE(dev) == 0) {
msnd_outb(high, io + HP_TXH);
msnd_outb(mid, io + HP_TXM);
msnd_outb(low, io + HP_TXL);
return 0;
}
printk(KERN_DEBUG LOGNAME ": Send host word timeout\n");
return -EIO;
}
int msnd_upload_host(multisound_dev_t *dev, char *bin, int len)
{
int i;
if (len % 3 != 0) {
printk(KERN_WARNING LOGNAME ": Upload host data not multiple of 3!\n");
return -EINVAL;
}
for (i = 0; i < len; i += 3)
if (msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]) != 0)
return -EIO;
msnd_inb(dev->io + HP_RXL);
msnd_inb(dev->io + HP_CVR);
return 0;
}
int msnd_enable_irq(multisound_dev_t *dev)
{
unsigned long flags;
if (dev->irq_ref++)
return 0;
printk(KERN_DEBUG LOGNAME ": Enabling IRQ\n");
spin_lock_irqsave(&dev->lock, flags);
if (msnd_wait_TXDE(dev) == 0) {
msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
if (dev->type == msndClassic)
msnd_outb(dev->irqid, dev->io + HP_IRQM);
msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
enable_irq(dev->irq);
msnd_init_queue(dev->DSPQ, dev->dspq_data_buff, dev->dspq_buff_size);
spin_unlock_irqrestore(&dev->lock, flags);
return 0;
}
spin_unlock_irqrestore(&dev->lock, flags);
printk(KERN_DEBUG LOGNAME ": Enable IRQ failed\n");
return -EIO;
}
int msnd_disable_irq(multisound_dev_t *dev)
{
unsigned long flags;
if (--dev->irq_ref > 0)
return 0;
if (dev->irq_ref < 0)
printk(KERN_DEBUG LOGNAME ": IRQ ref count is %d\n", dev->irq_ref);
printk(KERN_DEBUG LOGNAME ": Disabling IRQ\n");
spin_lock_irqsave(&dev->lock, flags);
if (msnd_wait_TXDE(dev) == 0) {
msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
if (dev->type == msndClassic)
msnd_outb(HPIRQ_NONE, dev->io + HP_IRQM);
disable_irq(dev->irq);
spin_unlock_irqrestore(&dev->lock, flags);
return 0;
}
spin_unlock_irqrestore(&dev->lock, flags);
printk(KERN_DEBUG LOGNAME ": Disable IRQ failed\n");
return -EIO;
}
#ifndef LINUX20
EXPORT_SYMBOL(msnd_register);
EXPORT_SYMBOL(msnd_unregister);
EXPORT_SYMBOL(msnd_init_queue);
EXPORT_SYMBOL(msnd_fifo_init);
EXPORT_SYMBOL(msnd_fifo_free);
EXPORT_SYMBOL(msnd_fifo_alloc);
EXPORT_SYMBOL(msnd_fifo_make_empty);
EXPORT_SYMBOL(msnd_fifo_write_io);
EXPORT_SYMBOL(msnd_fifo_read_io);
EXPORT_SYMBOL(msnd_fifo_write);
EXPORT_SYMBOL(msnd_fifo_read);
EXPORT_SYMBOL(msnd_send_dsp_cmd);
EXPORT_SYMBOL(msnd_send_word);
EXPORT_SYMBOL(msnd_upload_host);
EXPORT_SYMBOL(msnd_enable_irq);
EXPORT_SYMBOL(msnd_disable_irq);
#endif
#ifdef MODULE
MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
MODULE_DESCRIPTION ("Turtle Beach MultiSound Driver Base");
MODULE_LICENSE("GPL");
int init_module(void)
{
return 0;
}
void cleanup_module(void)
{
}
#endif