Commit e9e7d7fa authored by Linus Torvalds's avatar Linus Torvalds

v2.4.7.8 -> v2.4.8

  - Rik van Riel: free up swap cache on swapin when swap is full..
  - Robert Love: merge emu10k sound driver.  This one is better ("Yeah,
  you actually get sound out of it")
  - Jeremy Linton: swapin/swapoff race condition fix
parent 6c4b34bf
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 8
EXTRAVERSION =-pre8
EXTRAVERSION =
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
......
......@@ -73,7 +73,7 @@ subdir-$(CONFIG_SOUND_EMU10K1) += emu10k1
subdir-$(CONFIG_SOUND_CS4281) += cs4281
ifeq ($(CONFIG_SOUND_EMU10K1),y)
obj-y += emu10k1/emu10k1.o
obj-y += ac97_codec.o emu10k1/emu10k1.o
endif
ifeq ($(CONFIG_SOUND_CS4281),y)
......
......@@ -39,22 +39,6 @@
#include <linux/types.h>
/* ------------------- DEFINES -------------------- */
#define CMD_WRITEFN0 0x0
#define CMD_READFN0 0x1
#define CMD_WRITEPTR 0x2
#define CMD_READPTR 0x3
#define CMD_SETRECSRC 0x4
#define CMD_GETRECSRC 0x5
#define CMD_GETVOICEPARAM 0x6
#define CMD_SETVOICEPARAM 0x7
struct mixer_private_ioctl {
u32 cmd;
u32 val[10];
};
/************************************************************************************************/
/* PCI function 0 registers, address = <val> + PCIBASE0 */
/************************************************************************************************/
......@@ -171,7 +155,10 @@ struct mixer_private_ioctl {
#define HCFG_CODECFORMAT_I2S 0x00010000 /* I2S CODEC format -- Secondary (Rear) Output */
#define HCFG_GPINPUT0 0x00004000 /* External pin112 */
#define HCFG_GPINPUT1 0x00002000 /* External pin110 */
#define HCFG_GPOUTPUT_MASK 0x00001c00 /* External pins which may be controlled */
#define HCFG_GPOUT0 0x00001000 /* set to enable digital out on 5.1 cards */
#define HCFG_JOYENABLE 0x00000200 /* Internal joystick enable */
#define HCFG_PHASETRACKENABLE 0x00000100 /* Phase tracking enable */
/* 1 = Force all 3 async digital inputs to use */
......@@ -224,54 +211,6 @@ struct mixer_private_ioctl {
#define AC97ADDRESS_READY 0x80 /* Read-only bit, reflects CODEC READY signal */
#define AC97ADDRESS_ADDRESS 0x7f /* Address of indexed AC97 register */
/************************************************************************************************/
/* PCI function 1 registers, address = <val> + PCIBASE1 */
/************************************************************************************************/
#define JOYSTICK1 0x00 /* Analog joystick port register */
#define JOYSTICK2 0x01 /* Analog joystick port register */
#define JOYSTICK3 0x02 /* Analog joystick port register */
#define JOYSTICK4 0x03 /* Analog joystick port register */
#define JOYSTICK5 0x04 /* Analog joystick port register */
#define JOYSTICK6 0x05 /* Analog joystick port register */
#define JOYSTICK7 0x06 /* Analog joystick port register */
#define JOYSTICK8 0x07 /* Analog joystick port register */
/* When writing, any write causes JOYSTICK_COMPARATOR output enable to be pulsed on write. */
/* When reading, use these bitfields: */
#define JOYSTICK_BUTTONS 0x0f /* Joystick button data */
#define JOYSTICK_COMPARATOR 0xf0 /* Joystick comparator data */
/********************************************************************************************************/
/* AC97 pointer-offset register set, accessed through the AC97ADDRESS and AC97DATA registers */
/********************************************************************************************************/
#define AC97_RESET 0x00
#define AC97_MASTERVOLUME 0x02 /* Master volume */
#define AC97_HEADPHONEVOLUME 0x04 /* Headphone volume */
#define AC97_MASTERVOLUMEMONO 0x06 /* Mast volume mono */
#define AC97_MASTERTONE 0x08
#define AC97_PCBEEPVOLUME 0x0a /* PC speaker system beep volume */
#define AC97_PHONEVOLUME 0x0c
#define AC97_MICVOLUME 0x0e
#define AC97_LINEINVOLUME 0x10
#define AC97_CDVOLUME 0x12
#define AC97_VIDEOVOLUME 0x14
#define AC97_AUXVOLUME 0x16
#define AC97_PCMOUTVOLUME 0x18
#define AC97_RECORDSELECT 0x1a
#define AC97_RECORDGAIN 0x1c
#define AC97_RECORDGAINMIC 0x1e
#define AC97_GENERALPURPOSE 0x20
#define AC97_3DCONTROL 0x22
#define AC97_MODEMRATE 0x24
#define AC97_POWERDOWN 0x26
#define AC97_VENDORID1 0x7c
#define AC97_VENDORID2 0x7e
#define AC97_ZVIDEOVOLUME 0xec
#define AC97_AC3VOLUME 0xed
/********************************************************************************************************/
/* Emu10k1 pointer-offset register set, accessed through the PTR and DATA registers */
/********************************************************************************************************/
......@@ -568,6 +507,16 @@ struct mixer_private_ioctl {
#define DBG 0x52 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */
/* definitions for debug register - taken from the alsa drivers */
#define DBG_ZC 0x80000000 /* zero tram counter */
#define DBG_SATURATION_OCCURED 0x02000000 /* saturation control */
#define DBG_SATURATION_ADDR 0x01ff0000 /* saturation address */
#define DBG_SINGLE_STEP 0x00008000 /* single step mode */
#define DBG_STEP 0x00004000 /* start single step */
#define DBG_CONDITION_CODE 0x00003e00 /* condition code */
#define DBG_SINGLE_STEP_ADDR 0x000001ff /* single step address */
#define REG53 0x53 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */
#define SPCS0 0x54 /* SPDIF output Channel Status 0 register */
......@@ -616,6 +565,10 @@ struct mixer_private_ioctl {
#define SPBYPASS 0x5e /* SPDIF BYPASS mode register */
#define SPBYPASS_ENABLE 0x00000001 /* Enable SPDIF bypass mode */
#define AC97SLOT 0x5f /* additional AC97 slots enable bits */
#define AC97SLOT_CNTR 0x10 /* Center enable */
#define AC97SLOT_LFE 0x20 /* LFE enable */
#define CDSRCS 0x60 /* CD-ROM Sample Rate Converter status register */
#define GPSRCS 0x61 /* General Purpose SPDIF sample rate cvt status */
......
......@@ -5,8 +5,9 @@
O_TARGET := emu10k1.o
obj-y := audio.o cardmi.o cardmo.o cardwi.o cardwo.o ecard.o \
emuadxmg.o hwaccess.o irqmgr.o main.o midi.o mixer.o \
recmgr.o timer.o voicemgr.o
efxmgr.o emuadxmg.o hwaccess.o irqmgr.o joystick.o \
main.o midi.o mixer.o passthrough.o recmgr.o timer.o \
voicemgr.o
obj-m := $(O_TARGET)
ifdef DEBUG
......
This diff is collapsed.
/*
**********************************************************************
* sblive_mi.c - MIDI UART input HAL for emu10k1 driver
......@@ -291,7 +290,7 @@ int emu10k1_mpuin_callback(struct emu10k1_mpuin *card_mpuin, u32 msg, unsigned l
if (msg == ICARDMIDI_INDATA || msg == ICARDMIDI_INDATAERROR) {
callback_msg[1] = data;
callback_msg[2] = bytesvalid;
DPD(2, "emu10k1_mpuin_callback: midimsg = %lx\n", data);
DPD(2, "emu10k1_mpuin_callback: midimsg = %#lx\n", data);
} else {
midiq = (struct midi_queue *) data;
midihdr = (struct midi_hdr *) midiq->refdata;
......
......@@ -34,7 +34,6 @@
#define _CARDMI_H
#include "icardmid.h"
#include <linux/sched.h>
#include <linux/interrupt.h>
typedef enum
......
/*
**********************************************************************
* cardmo.c - MIDI UART output HAL for emu10k1 driver
......
......@@ -36,6 +36,12 @@
#include "audio.h"
#include "cardwi.h"
/**
* query_format - returns a valid sound format
*
* This function will return a valid sound format as close
* to the requested one as possible.
*/
void query_format(int recsrc, struct wave_format *wave_fmt)
{
......@@ -62,8 +68,18 @@ void query_format(int recsrc, struct wave_format *wave_fmt)
else
wave_fmt->samplingrate = 0x1F40;
if ((wave_fmt->bitsperchannel != 8) && (wave_fmt->bitsperchannel != 16))
switch (wave_fmt->id) {
case AFMT_S16_LE:
wave_fmt->bitsperchannel = 16;
break;
case AFMT_U8:
wave_fmt->bitsperchannel = 8;
break;
default:
wave_fmt->id = AFMT_S16_LE;
wave_fmt->bitsperchannel = 16;
break;
}
break;
......@@ -80,13 +96,13 @@ void query_format(int recsrc, struct wave_format *wave_fmt)
wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3;
wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel;
wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate;
return;
}
static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
{
if ((buffer->addr = pci_alloc_consistent(card->pci_dev, buffer->size * buffer->cov, &buffer->dma_handle)) == NULL)
buffer->addr = pci_alloc_consistent(card->pci_dev, buffer->size * buffer->cov,
&buffer->dma_handle);
if (buffer->addr == NULL)
return -1;
return 0;
......@@ -95,9 +111,8 @@ static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
static void free_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
{
if (buffer->addr != NULL)
pci_free_consistent(card->pci_dev, buffer->size * buffer->cov, buffer->addr, buffer->dma_handle);
return;
pci_free_consistent(card->pci_dev, buffer->size * buffer->cov,
buffer->addr, buffer->dma_handle);
}
int emu10k1_wavein_open(struct emu10k1_wavedevice *wave_dev)
......@@ -195,8 +210,6 @@ void emu10k1_wavein_close(struct emu10k1_wavedevice *wave_dev)
spin_unlock_irqrestore(&card->lock, flags);
wiinst->state = WAVE_STATE_CLOSED;
return;
}
void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev)
......@@ -214,8 +227,6 @@ void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev)
wiinst->buffer.bytestocopy = 0;
wiinst->state |= WAVE_STATE_STARTED;
return;
}
void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev)
......@@ -232,8 +243,6 @@ void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev)
emu10k1_stop_record(card, &wiinst->buffer);
wiinst->state &= ~WAVE_STATE_STARTED;
return;
}
int emu10k1_wavein_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format)
......@@ -282,20 +291,21 @@ void emu10k1_wavein_getxfersize(struct wiinst *wiinst, u32 * size)
*size = buffer->bytestocopy;
if (wiinst->mmapped)
return;
if (*size > buffer->size) {
*size = buffer->size;
buffer->pos = buffer->hw_pos;
buffer->bytestocopy = buffer->size;
DPF(1, "buffer overrun\n");
}
return;
}
static void copy_block(u8 *dst, u8 * src, u32 str, u32 len, u8 cov)
{
if (cov == 1)
copy_to_user(dst, src + str, len);
__copy_to_user(dst, src + str, len);
else {
u8 byte;
u32 i;
......@@ -304,11 +314,9 @@ static void copy_block(u8 *dst, u8 * src, u32 str, u32 len, u8 cov)
for (i = 0; i < len; i++) {
byte = src[2 * i] ^ 0x80;
copy_to_user(dst + i, &byte, 1);
__copy_to_user(dst + i, &byte, 1);
}
}
return;
}
void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 * data, u32 * size)
......@@ -340,8 +348,6 @@ void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 * data, u32 * size)
} else {
copy_block(data, buffer->addr, start, sizetocopy, buffer->cov);
}
return;
}
void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst)
......@@ -362,6 +368,4 @@ void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst)
wiinst->buffer.bytestocopy += diff;
wiinst->buffer.hw_pos = hw_pos;
return;
}
......@@ -43,6 +43,7 @@ struct wavein_buffer {
u32 pos; /* software cursor position */
u32 bytestocopy; /* bytes of recorded data available */
u32 size;
u32 pages;
u32 sizereg;
u32 sizeregval;
u32 addrreg;
......
This diff is collapsed.
......@@ -45,6 +45,14 @@
#define WAVEOUT_DEFAULTBUFLEN 500 /* Time to play the entire buffer in ms */
#define WAVEOUT_MINFRAGSHIFT 6
#define WAVEOUT_MAXVOICES 6
/* waveout_mem is cardwo internal */
struct waveout_mem {
int emupageindex;
void *addr[BUFMAXPAGES];
dma_addr_t dma_handle[BUFMAXPAGES];
};
struct waveout_buffer {
u16 ossfragshift;
......@@ -52,20 +60,19 @@ struct waveout_buffer {
u32 fragment_size; /* in bytes units */
u32 size; /* in bytes units */
u32 pages; /* buffer size in page units*/
int emupageindex;
void *addr[BUFMAXPAGES];
dma_addr_t dma_handle[BUFMAXPAGES];
u32 silence_pos; /* software cursor position (including silence) */
struct waveout_mem mem[WAVEOUT_MAXVOICES];
u32 silence_pos; /* software cursor position (including silence bytes) */
u32 hw_pos; /* hardware cursor position */
u32 bytestocopy; /* free space on buffer (including silence) */
u32 free_bytes; /* free bytes available on the buffer (not including silence bytes) */
u8 fill_silence;
u32 silence_bytes; /* silence bytes in buffer */
u32 silence_bytes; /* silence bytes on the buffer */
};
struct woinst
{
u8 state;
struct emu_voice voice;
u8 num_voices;
struct emu_voice voice[WAVEOUT_MAXVOICES];
struct emu_timer timer;
struct wave_format format;
struct waveout_buffer buffer;
......
......@@ -83,10 +83,13 @@ static void ecard_write(struct emu10k1_card *card, u32 value)
{
u16 count;
u32 data, hcvalue;
unsigned long flags;
hcvalue = emu10k1_readfn0(card, HCFG) & ~(HOOKN_BIT|HANDN_BIT|PULSEN_BIT);
spin_lock_irqsave(&card->lock, flags);
emu10k1_writefn0(card, HCFG, hcvalue);
hcvalue = inl(card->iobase + HCFG) & ~(HOOKN_BIT|HANDN_BIT|PULSEN_BIT);
outl(card->iobase + HCFG, hcvalue);
for (count = 0 ; count < EC_NUM_CONTROL_BITS; count++) {
......@@ -94,19 +97,21 @@ static void ecard_write(struct emu10k1_card *card, u32 value)
data = ((value & 0x1) ? PULSEN_BIT : 0);
value >>= 1;
emu10k1_writefn0(card, HCFG, hcvalue | data);
outl(card->iobase + HCFG, hcvalue | data);
/* Clock the shift register */
emu10k1_writefn0(card, HCFG, hcvalue | data | HANDN_BIT);
emu10k1_writefn0(card, HCFG, hcvalue | data);
outl(card->iobase + HCFG, hcvalue | data | HANDN_BIT);
outl(card->iobase + HCFG, hcvalue | data);
}
/* Latch the bits */
emu10k1_writefn0(card, HCFG, hcvalue | HOOKN_BIT);
emu10k1_writefn0(card, HCFG, hcvalue);
outl(card->iobase + HCFG, hcvalue | HOOKN_BIT);
outl(card->iobase + HCFG, hcvalue);
spin_unlock_irqrestore(&card->lock, flags);
}
int __devinit emu10k1_ecard_init(struct emu10k1_card *card)
void __devinit emu10k1_ecard_init(struct emu10k1_card *card)
{
u32 hcvalue;
struct ecard_state ecard;
......@@ -125,7 +130,6 @@ int __devinit emu10k1_ecard_init(struct emu10k1_card *card)
* and enable audio output */
hcvalue = emu10k1_readfn0(card, HCFG);
emu10k1_writefn0(card, HCFG, hcvalue | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S);
emu10k1_readfn0(card, HCFG);
/* Step 1: Turn off the led and deassert TRIM_CS */
ecard_write(card, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
......@@ -148,8 +152,6 @@ int __devinit emu10k1_ecard_init(struct emu10k1_card *card)
/* Step 5: Set the analog input gain */
ecard_setadcgain(card, &ecard, ecard.adc_gain);
return 0;
}
......@@ -29,7 +29,6 @@
#include "8010.h"
#include "hwaccess.h"
#include <linux/init.h>
#include <linux/sched.h>
/* In A1 Silicon, these bits are in the HC register */
#define HOOKN_BIT (1L << 12)
......@@ -109,6 +108,6 @@ struct ecard_state {
u16 mux2_setting;
};
int emu10k1_ecard_init(struct emu10k1_card *) __devinit;
void emu10k1_ecard_init(struct emu10k1_card *) __devinit;
#endif /* _ECARD_H */
/*
**********************************************************************
* efxmgr.c
* Copyright 1999, 2000 Creative Labs, Inc.
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* October 20, 1999 Bertrand Lee base code release
*
**********************************************************************
*
* 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/bitops.h>
#include "hwaccess.h"
#include "efxmgr.h"
int emu10k1_find_control_gpr(struct patch_manager *mgr, const char *patch_name, const char *gpr_name)
{
struct dsp_patch *patch;
struct dsp_rpatch *rpatch;
char s[PATCH_NAME_SIZE + 4];
u32 *gpr_used;
int i;
DPD(2, "emu10k1_find_control_gpr(): %s %s\n", patch_name, gpr_name);
rpatch = &mgr->rpatch;
if (!strcmp(rpatch->name, patch_name)) {
gpr_used = rpatch->gpr_used;
goto match;
}
for(i = 0; i < mgr->current_pages * PATCHES_PER_PAGE; i++) {
patch = PATCH(mgr, i);
sprintf(s,"%s", patch->name);
if (!strcmp(s, patch_name)) {
gpr_used = patch->gpr_used;
goto match;
}
}
return -1;
match:
for (i = 0; i < NUM_GPRS; i++)
if (mgr->gpr[i].type == GPR_TYPE_CONTROL &&
test_bit(i, gpr_used) &&
!strcmp(mgr->gpr[i].name, gpr_name))
return i;
return -1;
}
void emu10k1_set_control_gpr(struct emu10k1_card *card, int addr, s32 val, int flag)
{
struct patch_manager *mgr = &card->mgr;
DPD(2, "emu10k1_set_control_gpr(): %d %x\n", addr, val);
if (addr < 0 || addr >= NUM_GPRS)
return;
if (flag)
val += sblive_readptr(card, GPR_BASE + addr, 0);
if (val > mgr->gpr[addr].max)
val = mgr->gpr[addr].max;
else if (val < mgr->gpr[addr].min)
val = mgr->gpr[addr].min;
sblive_writeptr(card, GPR_BASE + addr, 0, val);
}
//TODO: make this configurable:
#define VOLCTRL_CHANNEL SOUND_MIXER_VOLUME
#define VOLCTRL_STEP_SIZE 5
//An internal function for setting OSS mixer controls.
void emu10k1_set_oss_vol(struct emu10k1_card *card, int oss_mixer,
unsigned int left, unsigned int right){
extern struct oss_scaling volume_params[SOUND_MIXER_NRDEVICES];
card->ac97.mixer_state[oss_mixer] = (right << 8) | left;
if (!card->isaps)
card->ac97.write_mixer(&card->ac97, oss_mixer, left, right);
emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][0], left,
volume_params[oss_mixer].scale,
volume_params[oss_mixer].muting);
emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][1], right,
volume_params[oss_mixer].scale,
volume_params[oss_mixer].muting);
}
//FIXME: mute should unmute when pressed a second time
void emu10k1_mute_irqhandler(struct emu10k1_card *card)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
spin_lock_irqsave(&mgr->lock, flags);
emu10k1_set_oss_vol(card,VOLCTRL_CHANNEL,0,0);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_volincr_irqhandler(struct emu10k1_card *card)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
unsigned int oss_channel=VOLCTRL_CHANNEL, left=0,right=0;
spin_lock_irqsave(&mgr->lock, flags);
left = card->ac97.mixer_state[oss_channel] & 0xff;
right = (card->ac97.mixer_state[oss_channel] >> 8) & 0xff;
if((left+=VOLCTRL_STEP_SIZE )>100)
left=100;
if((right+=VOLCTRL_STEP_SIZE )>100)
right=100;
emu10k1_set_oss_vol(card,oss_channel,left,right);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_voldecr_irqhandler(struct emu10k1_card *card)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
int oss_channel=VOLCTRL_CHANNEL, left=0,right=0;
spin_lock_irqsave(&mgr->lock, flags);
left = card->ac97.mixer_state[oss_channel] & 0xff;
right = (card->ac97.mixer_state[oss_channel] >> 8) & 0xff;
if((left-=VOLCTRL_STEP_SIZE )<0)
left=0;
if((right-=VOLCTRL_STEP_SIZE )<0)
right=0;
emu10k1_set_oss_vol(card,oss_channel,left,right);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_set_volume_gpr(struct emu10k1_card *card, int addr, s32 vol, int scale, int muting)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
const s32 log2lin[5] ={ // attenuation (dB)
0x7fffffff, // 0.0
0x7fffffff * 0.840896415253715 , // 1.5
0x7fffffff * 0.707106781186548, // 3.0
0x7fffffff * 0.594603557501361 , // 4.5
};
if (addr < 0)
return;
vol = (100 - vol ) * scale / 100;
// Thanks to the comp.dsp newsgroup for this neat trick:
vol = vol >= muting ? 0: log2lin[vol&3]>>(vol>>2);
spin_lock_irqsave(&mgr->lock, flags);
emu10k1_set_control_gpr(card, addr, vol, 0);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_dsp_irqhandler(struct emu10k1_card *card)
{
unsigned long flags;
if (card->pt.state != PT_STATE_INACTIVE) {
u32 bc;
bc = sblive_readptr(card, GPR_BASE + card->pt.intr_gpr, 0);
if (bc != 0) {
spin_lock_irqsave(&card->lock, flags);
card->pt.blocks_played = bc;
if (card->pt.blocks_played >= card->pt.blocks_copied) {
DPF(1, "buffer underrun in passthrough playback\n");
emu10k1_pt_stop(card);
}
wake_up_interruptible(&card->pt.wait);
spin_unlock_irqrestore(&card->lock, flags);
DPD(3, "pt interrupt, bc = %d\n", bc);
}
}
}
......@@ -39,5 +39,204 @@
WRITE_EFX(card, (pc) * 2 + 1, ((op) << 20) | ((z) << 10) | (w)); \
++pc; } while (0)
#define NUM_INPUTS 0x20
#define NUM_OUTPUTS 0x20
#define NUM_GPRS 0x100
#define GPR_NAME_SIZE 32
#define PATCH_NAME_SIZE 32
struct dsp_rpatch {
char name[PATCH_NAME_SIZE];
u16 code_start;
u16 code_size;
u32 gpr_used[NUM_GPRS / 32];
u32 gpr_input[NUM_GPRS / 32];
u32 route[NUM_OUTPUTS];
u32 route_v[NUM_OUTPUTS];
};
struct dsp_patch {
char name[PATCH_NAME_SIZE];
u8 id;
u32 input; /* bitmap of the lines used as inputs */
u32 output; /* bitmap of the lines used as outputs */
u16 code_start;
u16 code_size;
u32 gpr_used[NUM_GPRS / 32]; /* bitmap of used gprs */
u32 gpr_input[NUM_GPRS / 32];
u8 traml_istart; /* starting address of the internal tram lines used */ u8 traml_isize; /* number of internal tram lines used */
u8 traml_estart;
u8 traml_esize;
u16 tramb_istart; /* starting address of the internal tram memory used */
u16 tramb_isize; /* amount of internal memory used */
u32 tramb_estart;
u32 tramb_esize;
};
struct dsp_gpr {
u8 type; /* gpr type, STATIC, DYNAMIC, INPUT, OUTPUT, CONTROL */
char name[GPR_NAME_SIZE]; /* gpr value, only valid for control gprs */
s32 min, max; /* value range for this gpr, only valid for control gprs */
u8 line; /* which input/output line is the gpr attached, only valid for input/output gprs */
u8 usage;
};
enum {
GPR_TYPE_NULL = 0,
GPR_TYPE_IO,
GPR_TYPE_STATIC,
GPR_TYPE_DYNAMIC,
GPR_TYPE_CONTROL,
GPR_TYPE_CONSTANT
};
#define GPR_BASE 0x100
#define OUTPUT_BASE 0x20
//We can get this info by looking at the code start
//#define PATCH_TYPE_INPUT 0x1
//#define PATCH_TYPE_OUTPUT 0x2
#define MAX_PATCHES_PAGES 32
struct patch_manager {
void *patch[MAX_PATCHES_PAGES];
int current_pages;
struct dsp_rpatch rpatch;
struct dsp_gpr gpr[NUM_GPRS]; /* gpr usage table */
spinlock_t lock;
s16 ctrl_gpr[SOUND_MIXER_NRDEVICES][2];
};
#define PATCHES_PER_PAGE (PAGE_SIZE / sizeof(struct dsp_patch))
#define PATCH(mgr, i) ((struct dsp_patch *) (mgr)->patch[(i) / PATCHES_PER_PAGE] + (i) % PATCHES_PER_PAGE)
/* PCM volume control */
#define TMP_PCM_L 0x100 //temp PCM L (after the vol control)
#define TMP_PCM_R 0x101
#define VOL_PCM_L 0x102 //vol PCM
#define VOL_PCM_R 0x103
/* Routing patch */
#define TMP_AC_L 0x104 //tmp ac97 out
#define TMP_AC_R 0x105
#define TMP_REAR_L 0x106 //output - Temp Rear
#define TMP_REAR_R 0x107
#define TMP_DIGI_L 0x108 //output - Temp digital
#define TMP_DIGI_R 0x109
#define DSP_VOL_L 0x10a // main dsp volume
#define DSP_VOL_R 0x10b
/* hw inputs */
#define PCM_IN_L 0x00
#define PCM_IN_R 0x01
#define PCM1_IN_L 0x04
#define PCM1_IN_R 0x05
#define AC97_IN_L 0x10
#define AC97_IN_R 0x11
#define SPDIF_CD_L 0x12
#define SPDIF_CD_R 0x13
/* hw outputs */
#define AC97_FRONT_L 0x20
#define AC97_FRONT_R 0x21
#define DIGITAL_OUT_L 0x22
#define DIGITAL_OUT_R 0x23
#define ANALOG_REAR_L 0x28
#define ANALOG_REAR_R 0x29
#define ADC_REC_L 0x2a
#define ADC_REC_R 0x2b
#define INPUT_PATCH_START(patch, nm, ln, i) \
do { \
patch = PATCH(mgr, patch_n); \
strcpy(patch->name, nm); \
patch->code_start = pc * 2; \
patch->input = (1<<(0x1f&ln)); \
patch->output= (1<<(0x1f&ln)); \
patch->id = i; \
} while(0)
#define INPUT_PATCH_END(patch) \
do { \
patch->code_size = pc * 2 - patch->code_start; \
patch_n++; \
} while(0)
#define ROUTING_PATCH_START(patch, nm) \
do { \
patch = &mgr->rpatch; \
strcpy(patch->name, nm); \
patch->code_start = pc * 2; \
} while(0)
#define ROUTING_PATCH_END(patch) \
do { \
patch->code_size = pc * 2 - patch->code_start; \
} while(0)
#define CONNECT(input, output) set_bit(input, &rpatch->route[(output) - OUTPUT_BASE]);
#define CONNECT_V(input, output) set_bit(input, &rpatch->route_v[(output) - OUTPUT_BASE]);
#define OUTPUT_PATCH_START(patch, nm, ln, i) \
do { \
patch = PATCH(mgr, patch_n); \
strcpy(patch->name, nm); \
patch->code_start = pc * 2; \
patch->input = (1<<(0x1f&ln)); \
patch->output= (1<<(0x1f&ln)); \
patch->id = i; \
} while(0)
#define OUTPUT_PATCH_END(patch) \
do { \
patch->code_size = pc * 2 - patch->code_start; \
patch_n++; \
} while(0)
#define GET_OUTPUT_GPR(patch, g, ln) \
do { \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_IO; \
mgr->gpr[(g) - GPR_BASE].usage++; \
mgr->gpr[(g) - GPR_BASE].line = ln; \
set_bit((g) - GPR_BASE, patch->gpr_used); \
} while(0)
#define GET_INPUT_GPR(patch, g, ln) \
do { \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_IO; \
mgr->gpr[(g) - GPR_BASE].usage++; \
mgr->gpr[(g) - GPR_BASE].line = ln; \
set_bit((g) - GPR_BASE, patch->gpr_used); \
set_bit((g) - GPR_BASE, patch->gpr_input); \
} while(0)
#define GET_DYNAMIC_GPR(patch, g) \
do { \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_DYNAMIC; \
mgr->gpr[(g) - GPR_BASE].usage++; \
set_bit((g) - GPR_BASE, patch->gpr_used); \
} while(0)
#define GET_CONTROL_GPR(patch, g, nm, a, b) \
do { \
strcpy(mgr->gpr[(g) - GPR_BASE].name, nm); \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_CONTROL; \
mgr->gpr[(g) - GPR_BASE].usage++; \
mgr->gpr[(g) - GPR_BASE].min = a; \
mgr->gpr[(g) - GPR_BASE].max = b; \
sblive_writeptr(card, g, 0, b); \
set_bit((g) - GPR_BASE, patch->gpr_used); \
} while(0)
#endif /* _EFXMGR_H */
#ifndef __EMU_WRAPPER_H
#define __EMU_WRAPPER_H
#define vma_get_pgoff(v) ((v)->vm_pgoff)
#define PCI_SET_DMA_MASK(pdev,mask) (((pdev)->dma_mask) = (mask))
#endif
......@@ -355,51 +355,33 @@ static void sblive_wcwait(struct emu10k1_card *card, u32 wait)
}
}
int sblive_readac97(struct emu10k1_card *card, u8 index, u16 * data)
u16 emu10k1_ac97_read(struct ac97_codec *codec, u8 reg)
{
struct emu10k1_card *card = codec->private_data;
u16 data;
unsigned long flags;
spin_lock_irqsave(&card->lock, flags);
outb(index, card->iobase + AC97ADDRESS);
*data = inw(card->iobase + AC97DATA);
outb(reg, card->iobase + AC97ADDRESS);
data = inw(card->iobase + AC97DATA);
spin_unlock_irqrestore(&card->lock, flags);
return 0;
}
int sblive_writeac97(struct emu10k1_card *card, u8 index, u16 data)
{
unsigned long flags;
spin_lock_irqsave(&card->lock, flags);
outb(index, card->iobase + AC97ADDRESS);
outw(data, card->iobase + AC97DATA);
spin_unlock_irqrestore(&card->lock, flags);
return 0;
return data;
}
int sblive_rmwac97(struct emu10k1_card *card, u8 index, u16 data, u16 mask)
void emu10k1_ac97_write(struct ac97_codec *codec, u8 reg, u16 value)
{
u16 temp;
struct emu10k1_card *card = codec->private_data;
unsigned long flags;
spin_lock_irqsave(&card->lock, flags);
outb(index, card->iobase + AC97ADDRESS);
temp = inw(card->iobase + AC97DATA);
temp &= ~mask;
data &= mask;
temp |= data;
outw(temp, card->iobase + AC97DATA);
outb(reg, card->iobase + AC97ADDRESS);
outw(value, card->iobase + AC97DATA);
spin_unlock_irqrestore(&card->lock, flags);
return 0;
}
/*********************************************************
......
......@@ -35,9 +35,12 @@
#include <linux/fs.h>
#include <linux/sound.h>
#include <linux/soundcard.h>
#include <linux/ac97_codec.h>
#include <linux/pci.h>
#include "emu_wrapper.h"
#include "passthrough.h"
#include "efxmgr.h"
#include "midi.h"
#define EMUPAGESIZE 4096 /* don't change */
#define NUM_G 64 /* use all channels */
......@@ -93,6 +96,38 @@ struct emu10k1_wavein
u32 fxwc;
};
#define CMD_READ 1
#define CMD_WRITE 2
struct mixer_private_ioctl {
u32 cmd;
u32 val[90];
};
/* bogus ioctls numbers to escape from OSS mixer limitations */
#define CMD_WRITEFN0 _IOW('D', 0, struct mixer_private_ioctl)
#define CMD_READFN0 _IOR('D', 1, struct mixer_private_ioctl)
#define CMD_WRITEPTR _IOW('D', 2, struct mixer_private_ioctl)
#define CMD_READPTR _IOR('D', 3, struct mixer_private_ioctl)
#define CMD_SETRECSRC _IOW('D', 4, struct mixer_private_ioctl)
#define CMD_GETRECSRC _IOR('D', 5, struct mixer_private_ioctl)
#define CMD_GETVOICEPARAM _IOR('D', 6, struct mixer_private_ioctl)
#define CMD_SETVOICEPARAM _IOW('D', 7, struct mixer_private_ioctl)
#define CMD_GETPATCH _IOR('D', 8, struct mixer_private_ioctl)
#define CMD_GETGPR _IOR('D', 9, struct mixer_private_ioctl)
#define CMD_GETCTLGPR _IOR('D', 10, struct mixer_private_ioctl)
#define CMD_SETPATCH _IOW('D', 11, struct mixer_private_ioctl)
#define CMD_SETGPR _IOW('D', 12, struct mixer_private_ioctl)
#define CMD_SETCTLGPR _IOW('D', 13, struct mixer_private_ioctl)
#define CMD_SETGPOUT _IOW('D', 14, struct mixer_private_ioctl)
#define CMD_GETGPR2OSS _IOR('D', 15, struct mixer_private_ioctl)
#define CMD_SETGPR2OSS _IOW('D', 16, struct mixer_private_ioctl)
#define CMD_SETMCH_FX _IOW('D', 17, struct mixer_private_ioctl)
#define CMD_SETPASSTHROUGH _IOW('D', 18, struct mixer_private_ioctl)
struct oss_scaling {
char scale, muting;
};
struct emu10k1_card
{
......@@ -117,20 +152,25 @@ struct emu10k1_card
unsigned short model;
unsigned int irq;
int audio_num;
int audio1_num;
int mixer_num;
int midi_num;
int audio_dev;
int audio_dev1;
int midi_dev;
#ifdef EMU10K1_SEQUENCER
int seq_dev;
struct emu10k1_mididevice *seq_mididev;
#endif
struct ac97_codec ac97;
int ac97_supported_mixers;
int ac97_stereo_mixers;
/* Number of first fx voice for multichannel output */
u8 mchannel_fx;
struct emu10k1_waveout waveout;
struct emu10k1_wavein wavein;
struct emu10k1_mpuout *mpuout;
struct emu10k1_mpuin *mpuin;
u16 arrwVol[SOUND_MIXER_NRDEVICES + 1];
/* array is used from the member 1 to save (-1) operation */
u32 digmix[9 * 6 * 2];
unsigned int modcnt;
struct semaphore open_sem;
mode_t open_mode;
wait_queue_head_t open_wait;
......@@ -141,26 +181,25 @@ struct emu10k1_card
u8 chiprev; /* Chip revision */
int isaps;
struct patch_manager mgr;
struct pt_data pt;
};
int emu10k1_addxmgr_alloc(u32, struct emu10k1_card *);
void emu10k1_addxmgr_free(struct emu10k1_card *, int);
#ifdef PRIVATE_PCM_VOLUME
#define MAX_PCM_CHANNELS NUM_G
struct sblive_pcm_volume_rec {
struct files_struct *files; // identification of the same thread
u8 attn_l; // attenuation for left channel
u8 attn_r; // attenuation for right channel
u16 mixer; // saved mixer value for return
u8 channel_l; // idx of left channel
u8 channel_r; // idx of right channel
int opened; // counter - locks element
};
extern struct sblive_pcm_volume_rec sblive_pcm_volume[];
extern u16 pcm_last_mixer;
#endif
int emu10k1_find_control_gpr(struct patch_manager *, const char *, const char *);
void emu10k1_set_control_gpr(struct emu10k1_card *, int , s32, int );
void emu10k1_set_volume_gpr(struct emu10k1_card *, int, s32, int, int);
#define VOL_6BIT 0x40,0x40
#define VOL_5BIT 0x20,0x20
#define VOL_4BIT 0x10,0x7f
#define TIMEOUT 16384
......@@ -185,10 +224,9 @@ void emu10k1_irq_disable(struct emu10k1_card *, u32);
void emu10k1_set_stop_on_loop(struct emu10k1_card *, u32);
void emu10k1_clear_stop_on_loop(struct emu10k1_card *, u32);
/* AC97 Mixer access function */
int sblive_readac97(struct emu10k1_card *, u8, u16 *);
int sblive_writeac97(struct emu10k1_card *, u8, u16);
int sblive_rmwac97(struct emu10k1_card *, u8, u16, u16);
/* AC97 Codec register access function */
u16 emu10k1_ac97_read(struct ac97_codec *, u8);
void emu10k1_ac97_write(struct ac97_codec *, u8, u16);
/* MPU access function*/
int emu10k1_mpu_write_data(struct emu10k1_card *, u8);
......
......@@ -34,12 +34,15 @@
struct wave_format
{
int id;
int samplingrate;
u8 bitsperchannel;
u8 channels; /* 1 = Mono, 2 = Stereo */
u8 channels; /* 1 = Mono, 2 = Stereo, 3, ... = Multichannel */
u8 bytesperchannel;
u8 bytespervoicesample;
u8 bytespersample;
int bytespersec;
u8 passthrough;
};
/* emu10k1_wave states */
......
......@@ -41,10 +41,7 @@
void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
struct emu10k1_card *card = (struct emu10k1_card *) dev_id;
u32 irqstatus, tmp;
if (!(irqstatus = emu10k1_readfn0(card, IPR)))
return;
u32 irqstatus;
DPD(4, "emu10k1_interrupt called, irq = %u\n", irq);
......@@ -60,16 +57,22 @@ void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
** - Eric
*/
do {
DPD(4, "irq status %x\n", irqstatus);
while ((irqstatus = inl(card->iobase + IPR))) {
DPD(4, "irq status %#x\n", irqstatus);
tmp = irqstatus;
/* acknowledge interrupt */
outl(irqstatus, card->iobase + IPR);
if (irqstatus & IRQTYPE_TIMER) {
emu10k1_timer_irqhandler(card);
irqstatus &= ~IRQTYPE_TIMER;
}
if (irqstatus & IRQTYPE_DSP) {
emu10k1_dsp_irqhandler(card);
irqstatus &= ~IRQTYPE_DSP;
}
if (irqstatus & IRQTYPE_MPUIN) {
emu10k1_mpuin_irqhandler(card);
irqstatus &= ~IRQTYPE_MPUIN;
......@@ -80,13 +83,22 @@ void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
irqstatus &= ~IRQTYPE_MPUOUT;
}
if (irqstatus)
emu10k1_irq_disable(card, irqstatus);
if (irqstatus & IPR_MUTE) {
emu10k1_mute_irqhandler(card);
irqstatus &=~IPR_MUTE;
}
emu10k1_writefn0(card, IPR, tmp);
if (irqstatus & IPR_VOLINCR) {
emu10k1_volincr_irqhandler(card);
irqstatus &=~IPR_VOLINCR;
}
} while ((irqstatus = emu10k1_readfn0(card, IPR)));
if (irqstatus & IPR_VOLDECR) {
emu10k1_voldecr_irqhandler(card);
irqstatus &=~IPR_VOLDECR;
}
return;
if (irqstatus)
emu10k1_irq_disable(card, irqstatus);
}
}
......@@ -44,5 +44,9 @@
#define IRQTYPE_DSP IPR_FXDSP
void emu10k1_timer_irqhandler(struct emu10k1_card *);
void emu10k1_dsp_irqhandler(struct emu10k1_card *);
void emu10k1_mute_irqhandler(struct emu10k1_card *);
void emu10k1_volincr_irqhandler(struct emu10k1_card *);
void emu10k1_voldecr_irqhandler(struct emu10k1_card *);
#endif /* _IRQ_H */
/*
**********************************************************************
* joystick.c - Creative EMU10K1 Joystick port driver
* Copyright 2000 Rui Sousa.
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* April 1, 2000 Rui Sousa initial version
* April 28, 2000 Rui Sousa fixed a kernel oops,
* make use of kcompat24 for
* 2.2 kernels compatibility.
* May 1, 2000 Rui Sousa improved kernel compatibility
* layer.
*
**********************************************************************
*
* 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/init.h>
#include <linux/version.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/list.h>
#define DRIVER_VERSION "0.3.1"
#ifndef PCI_VENDOR_ID_CREATIVE
#define PCI_VENDOR_ID_CREATIVE 0x1102
#endif
#ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK
#define PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK 0x7002
#endif
/* PCI function 1 registers, address = <val> + PCIBASE1 */
#define JOYSTICK1 0x00 /* Analog joystick port register */
#define JOYSTICK2 0x01 /* Analog joystick port register */
#define JOYSTICK3 0x02 /* Analog joystick port register */
#define JOYSTICK4 0x03 /* Analog joystick port register */
#define JOYSTICK5 0x04 /* Analog joystick port register */
#define JOYSTICK6 0x05 /* Analog joystick port register */
#define JOYSTICK7 0x06 /* Analog joystick port register */
#define JOYSTICK8 0x07 /* Analog joystick port register */
/* When writing, any write causes JOYSTICK_COMPARATOR output enable to be pulsed on write. */
/* When reading, use these bitfields: */
#define JOYSTICK_BUTTONS 0x0f /* Joystick button data */
#define JOYSTICK_COMPARATOR 0xf0 /* Joystick comparator data */
#define NR_DEV 5
static int io[NR_DEV] = { 0, };
enum {
EMU10K1_JOYSTICK = 0
};
static char *card_names[] = {
"EMU10K1 Joystick Port"
};
static struct pci_device_id emu10k1_joy_pci_tbl[] __devinitdata = {
{PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK,
PCI_ANY_ID, PCI_ANY_ID, 0, 0, EMU10K1_JOYSTICK},
{0,}
};
MODULE_DEVICE_TABLE(pci, emu10k1_joy_pci_tbl);
struct emu10k1_joy_card {
struct list_head list;
struct pci_dev *pci_dev;
unsigned long iobase;
unsigned long length;
u8 addr_changed;
};
static LIST_HEAD(emu10k1_joy_devs);
static unsigned int devindex = 0;
/* Driver initialization routine */
static int __devinit emu10k1_joy_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
{
struct emu10k1_joy_card *card;
u16 model;
u8 chiprev;
if ((card = kmalloc(sizeof(struct emu10k1_joy_card), GFP_KERNEL)) == NULL) {
printk(KERN_ERR "emu10k1-joy: out of memory\n");
return -ENOMEM;
}
memset(card, 0, sizeof(struct emu10k1_joy_card));
if (pci_enable_device(pci_dev)) {
printk(KERN_ERR "emu10k1-joy: couldn't enable device\n");
kfree(card);
return -ENODEV;
}
card->iobase = pci_resource_start(pci_dev, 0);
card->length = pci_resource_len(pci_dev, 0);
if (request_region(card->iobase, card->length, card_names[pci_id->driver_data])
== NULL) {
printk(KERN_ERR "emu10k1-joy: IO space in use\n");
kfree(card);
return -ENODEV;
}
pci_set_drvdata(pci_dev, card);
card->pci_dev = pci_dev;
card->addr_changed = 0;
pci_read_config_byte(pci_dev, PCI_REVISION_ID, &chiprev);
pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &model);
printk(KERN_INFO "emu10k1-joy: %s rev %d model 0x%x found, IO at 0x%04lx-0x%04lx\n",
card_names[pci_id->driver_data], chiprev, model, card->iobase,
card->iobase + card->length - 1);
if (io[devindex]) {
if ((io[devindex] & ~0x18) != 0x200) {
printk(KERN_ERR "emu10k1-joy: invalid io value\n");
release_region(card->iobase, card->length);
kfree(card);
return -ENODEV;
}
card->addr_changed = 1;
pci_write_config_dword(pci_dev, PCI_BASE_ADDRESS_0, io[devindex]);
printk(KERN_INFO "emu10k1-joy: IO ports mirrored at 0x%03x\n", io[devindex]);
}
list_add(&card->list, &emu10k1_joy_devs);
devindex++;
return 0;
}
static void __devexit emu10k1_joy_remove(struct pci_dev *pci_dev)
{
struct emu10k1_joy_card *card = pci_get_drvdata(pci_dev);
if(card->addr_changed)
pci_write_config_dword(pci_dev, PCI_BASE_ADDRESS_0, card->iobase);
release_region(card->iobase, card->length);
list_del(&card->list);
kfree(card);
pci_set_drvdata(pci_dev, NULL);
}
MODULE_PARM(io, "1-" __MODULE_STRING(NR_DEV) "i");
MODULE_PARM_DESC(io, "sets joystick port address");
MODULE_AUTHOR("Rui Sousa (Email to: emu10k1-devel@opensource.creative.com)");
MODULE_DESCRIPTION("Creative EMU10K1 PCI Joystick Port v" DRIVER_VERSION
"\nCopyright (C) 2000 Rui Sousa");
static struct pci_driver emu10k1_joy_pci_driver = {
name:"emu10k1 joystick",
id_table:emu10k1_joy_pci_tbl,
probe:emu10k1_joy_probe,
remove:emu10k1_joy_remove,
};
static int __init emu10k1_joy_init_module(void)
{
printk(KERN_INFO "Creative EMU10K1 PCI Joystick Port, version " DRIVER_VERSION ", " __TIME__
" " __DATE__ "\n");
return pci_module_init(&emu10k1_joy_pci_driver);
}
static void __exit emu10k1_joy_cleanup_module(void)
{
pci_unregister_driver(&emu10k1_joy_pci_driver);
return;
}
module_init(emu10k1_joy_init_module);
module_exit(emu10k1_joy_cleanup_module);
This diff is collapsed.
/*
**********************************************************************
* midi.c - /dev/midi interface for emu10k1 driver
......@@ -43,6 +42,10 @@
#include "cardmi.h"
#include "midi.h"
#ifdef EMU10K1_SEQUENCER
#include "sound_config.h"
#endif
static spinlock_t midi_spinlock __attribute((unused)) = SPIN_LOCK_UNLOCKED;
static void init_midi_hdr(struct midi_hdr *midihdr)
......@@ -85,23 +88,30 @@ static int midiin_add_buffer(struct emu10k1_mididevice *midi_dev, struct midi_hd
static int emu10k1_midi_open(struct inode *inode, struct file *file)
{
int minor = MINOR(inode->i_rdev);
struct emu10k1_card *card=NULL;
struct emu10k1_card *card = NULL;
struct emu10k1_mididevice *midi_dev;
struct list_head *entry;
DPF(2, "emu10k1_midi_open()\n");
/* Check for correct device to open */
list_for_each(entry, &emu10k1_devs) {
card = list_entry(entry, struct emu10k1_card, list);
if (card->midi_num == minor)
break;
if (card->midi_dev == minor)
goto match;
}
if (entry == &emu10k1_devs)
return -ENODEV;
match:
#ifdef EMU10K1_SEQUENCER
if(card->seq_mididev) /* card is opened by sequencer */
return -EBUSY;
#endif
/* Wait for device to become free */
down(&card->open_sem);
while (card->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
......@@ -235,6 +245,7 @@ static int emu10k1_midi_release(struct inode *inode, struct file *file)
unlock_kernel();
return 0;
}
......@@ -245,7 +256,7 @@ static ssize_t emu10k1_midi_read(struct file *file, char *buffer, size_t count,
u16 cnt;
unsigned long flags;
DPD(4, "emu10k1_midi_read(), count %x\n", (u32) count);
DPD(4, "emu10k1_midi_read(), count %#x\n", (u32) count);
if (pos != &file->f_pos)
return -ESPIPE;
......@@ -320,7 +331,7 @@ static ssize_t emu10k1_midi_write(struct file *file, const char *buffer, size_t
ssize_t ret = 0;
unsigned long flags;
DPD(4, "emu10k1_midi_write(), count=%x\n", (u32) count);
DPD(4, "emu10k1_midi_write(), count=%#x\n", (u32) count);
if (pos != &file->f_pos)
return -ESPIPE;
......@@ -441,3 +452,154 @@ struct file_operations emu10k1_midi_fops = {
open: emu10k1_midi_open,
release: emu10k1_midi_release,
};
#ifdef EMU10K1_SEQUENCER
/* functions used for sequencer access */
int emu10k1_seq_midi_open(int dev, int mode,
void (*input) (int dev, unsigned char data),
void (*output) (int dev))
{
struct emu10k1_card *card;
struct midi_openinfo dsCardMidiOpenInfo;
struct emu10k1_mididevice *midi_dev;
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return -EINVAL;
card = midi_devs[dev]->devc;
if(card->open_mode) /* card is opened native */
return -EBUSY;
DPF(2, "emu10k1_seq_midi_open()\n");
if ((midi_dev = (struct emu10k1_mididevice *) kmalloc(sizeof(*midi_dev), GFP_KERNEL)) == NULL) {
return -EINVAL;
}
midi_dev->card = card;
midi_dev->mistate = MIDIIN_STATE_STOPPED;
init_waitqueue_head(&midi_dev->oWait);
init_waitqueue_head(&midi_dev->iWait);
midi_dev->ird = 0;
midi_dev->iwr = 0;
midi_dev->icnt = 0;
INIT_LIST_HEAD(&midi_dev->mid_hdrs);
dsCardMidiOpenInfo.refdata = (unsigned long) midi_dev;
if (emu10k1_mpuout_open(card, &dsCardMidiOpenInfo) < 0) {
ERROR();
return -ENODEV;
}
card->seq_mididev = midi_dev;
return 0;
}
void emu10k1_seq_midi_close(int dev)
{
struct emu10k1_card *card;
DPF(2, "emu10k1_seq_midi_close()\n");
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return;
card = midi_devs[dev]->devc;
emu10k1_mpuout_close(card);
if(card->seq_mididev) {
kfree(card->seq_mididev);
card->seq_mididev = 0;
}
}
int emu10k1_seq_midi_out(int dev, unsigned char midi_byte)
{
struct emu10k1_card *card;
struct midi_hdr *midihdr;
unsigned long flags;
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return -EINVAL;
card = midi_devs[dev]->devc;
if ((midihdr = (struct midi_hdr *) kmalloc(sizeof(struct midi_hdr), GFP_KERNEL)) == NULL)
return -EINVAL;
midihdr->bufferlength = 1;
midihdr->bytesrecorded = 0;
midihdr->flags = 0;
if ((midihdr->data = (u8 *) kmalloc(1, GFP_KERNEL)) == NULL) {
ERROR();
kfree(midihdr);
return -EINVAL;
}
*(midihdr->data) = midi_byte;
spin_lock_irqsave(&midi_spinlock, flags);
if (emu10k1_mpuout_add_buffer(card, midihdr) < 0) {
ERROR();
kfree(midihdr->data);
kfree(midihdr);
spin_unlock_irqrestore(&midi_spinlock, flags);
return -EINVAL;
}
spin_unlock_irqrestore(&midi_spinlock, flags);
return 1;
}
int emu10k1_seq_midi_start_read(int dev)
{
return 0;
}
int emu10k1_seq_midi_end_read(int dev)
{
return 0;
}
void emu10k1_seq_midi_kick(int dev)
{
}
int emu10k1_seq_midi_buffer_status(int dev)
{
int count;
struct midi_queue *queue;
struct emu10k1_card *card;
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return -EINVAL;
count = 0;
card = midi_devs[dev]->devc;
queue = card->mpuout->firstmidiq;
while(queue != NULL) {
count++;
if(queue == card->mpuout->lastmidiq)
break;
queue = queue->next;
}
return count;
}
#endif
This diff is collapsed.
/*
**********************************************************************
* passthrough.c -- Emu10k1 digital passthrough
* Copyright (C) 2001 Juha Yrjl <jyrjola@cc.hut.fi>
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* May 15, 2001 Juha Yrjl base code release
*
**********************************************************************
*
* 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.
*
**********************************************************************
*/
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/malloc.h>
#include <linux/version.h>
#include <linux/bitops.h>
#include <asm/io.h>
#include <linux/sched.h>
#include <linux/smp_lock.h>
#include <linux/wrapper.h>
#include "hwaccess.h"
#include "cardwo.h"
#include "cardwi.h"
#include "recmgr.h"
#include "irqmgr.h"
#include "audio.h"
#include "8010.h"
#include "passthrough.h"
static void pt_putsamples(struct pt_data *pt, u16 *ptr, u16 left, u16 right)
{
unsigned int idx;
ptr[pt->copyptr] = left;
idx = pt->copyptr + PT_SAMPLES/2;
idx %= PT_SAMPLES;
ptr[idx] = right;
}
static inline int pt_can_write(struct pt_data *pt)
{
return pt->blocks_copied < pt->blocks_played + 8;
}
static int pt_wait_for_write(struct emu10k1_wavedevice *wavedev, int nonblock)
{
struct emu10k1_card *card = wavedev->card;
struct pt_data *pt = &card->pt;
if (nonblock && !pt_can_write(pt))
return -EAGAIN;
while (!pt_can_write(pt) && pt->state != PT_STATE_INACTIVE) {
interruptible_sleep_on(&pt->wait);
if (signal_pending(current))
return -ERESTARTSYS;
}
if (pt->state == PT_STATE_INACTIVE)
return -EAGAIN;
return 0;
}
static int pt_putblock(struct emu10k1_wavedevice *wave_dev, u16 *block, int nonblock)
{
struct woinst *woinst = wave_dev->woinst;
struct emu10k1_card *card = wave_dev->card;
struct pt_data *pt = &card->pt;
u16 *ptr = (u16 *) card->tankmem.addr;
int i = 0, r;
unsigned long flags;
r = pt_wait_for_write(wave_dev, nonblock);
if (r < 0)
return r;
spin_lock_irqsave(&card->pt.lock, flags);
while (i < PT_BLOCKSAMPLES) {
pt_putsamples(pt, ptr, block[2*i], block[2*i+1]);
if (pt->copyptr == 0)
pt->copyptr = PT_SAMPLES;
pt->copyptr--;
i++;
}
woinst->total_copied += PT_BLOCKSIZE;
pt->blocks_copied++;
if (pt->blocks_copied >= 4 && pt->state != PT_STATE_PLAYING) {
DPF(2, "activating digital pass-through playback\n");
sblive_writeptr(card, GPR_BASE + pt->enable_gpr, 0, 1);
pt->state = PT_STATE_PLAYING;
}
spin_unlock_irqrestore(&card->pt.lock, flags);
return 0;
}
static int pt_setup(struct emu10k1_wavedevice *wave_dev)
{
u32 bits;
struct emu10k1_card *card = wave_dev->card;
struct pt_data *pt = &card->pt;
int i;
for (i = 0; i < 3; i++) {
pt->old_spcs[i] = sblive_readptr(card, SPCS0 + i, 0);
if (pt->spcs_to_use & (1 << i)) {
DPD(2, "using S/PDIF port %d\n", i);
bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
if (pt->ac3data)
bits |= SPCS_NOTAUDIODATA;
sblive_writeptr(card, SPCS0 + i, 0, bits);
}
}
return 0;
}
ssize_t emu10k1_pt_write(struct file *file, const char *buffer, size_t count)
{
struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
struct emu10k1_card *card = wave_dev->card;
struct pt_data *pt = &card->pt;
int nonblock, i, r, blocks, blocks_copied, bytes_copied = 0;
DPD(3, "emu10k1_pt_write(): %d bytes\n", count);
nonblock = file->f_flags & O_NONBLOCK;
if (card->tankmem.size < PT_SAMPLES*2)
return -EFAULT;
if (pt->state == PT_STATE_INACTIVE) {
DPF(2, "bufptr init\n");
pt->playptr = PT_SAMPLES-1;
pt->copyptr = PT_INITPTR;
pt->blocks_played = pt->blocks_copied = 0;
memset(card->tankmem.addr, 0, card->tankmem.size);
pt->state = PT_STATE_ACTIVATED;
pt->buf = kmalloc(PT_BLOCKSIZE, GFP_KERNEL);
pt->prepend_size = 0;
if (pt->buf == NULL)
return -ENOMEM;
pt_setup(wave_dev);
}
if (pt->prepend_size) {
int needed = PT_BLOCKSIZE - pt->prepend_size;
DPD(3, "prepend size %d, prepending %d bytes\n", pt->prepend_size, needed);
if (count < needed) {
copy_from_user(pt->buf + pt->prepend_size, buffer, count);
pt->prepend_size += count;
DPD(3, "prepend size now %d\n", pt->prepend_size);
return count;
}
copy_from_user(pt->buf + pt->prepend_size, buffer, needed);
r = pt_putblock(wave_dev, (u16 *) pt->buf, nonblock);
if (r)
return r;
bytes_copied += needed;
pt->prepend_size = 0;
}
blocks = (count-bytes_copied)/PT_BLOCKSIZE;
blocks_copied = 0;
while (blocks > 0) {
u16 *bufptr = (u16 *) buffer + (bytes_copied/2);
copy_from_user(pt->buf, bufptr, PT_BLOCKSIZE);
bufptr = (u16 *) pt->buf;
r = pt_putblock(wave_dev, bufptr, nonblock);
if (r) {
if (bytes_copied)
return bytes_copied;
else
return r;
}
bytes_copied += PT_BLOCKSIZE;
blocks--;
blocks_copied++;
}
i = count - bytes_copied;
if (i) {
pt->prepend_size = i;
copy_from_user(pt->buf, buffer + bytes_copied, i);
bytes_copied += i;
DPD(3, "filling prepend buffer with %d bytes", i);
}
return bytes_copied;
}
void emu10k1_pt_stop(struct emu10k1_card *card)
{
struct pt_data *pt = &card->pt;
int i;
unsigned long flags;
spin_lock_irqsave(&card->pt.lock, flags);
if (pt->state != PT_STATE_INACTIVE) {
DPF(2, "digital pass-through stopped\n");
sblive_writeptr(card, GPR_BASE + pt->enable_gpr, 0, 0);
for (i = 0; i < 3; i++) {
if (pt->spcs_to_use & (1 << i))
sblive_writeptr(card, SPCS0 + i, 0, pt->old_spcs[i]);
}
pt->state = PT_STATE_INACTIVE;
kfree(pt->buf);
}
spin_unlock_irqrestore(&card->pt.lock, flags);
}
void emu10k1_pt_waveout_update(struct emu10k1_wavedevice *wave_dev)
{
struct woinst *woinst = wave_dev->woinst;
struct pt_data *pt = &wave_dev->card->pt;
u32 pos;
if (pt->state == PT_STATE_PLAYING && pt->pos_gpr >= 0) {
pos = sblive_readptr(wave_dev->card, GPR_BASE + pt->pos_gpr, 0);
if (pos > PT_BLOCKSAMPLES)
pos = PT_BLOCKSAMPLES;
pos = 4 * (PT_BLOCKSAMPLES - pos);
} else
pos = 0;
woinst->total_played = pt->blocks_played * woinst->buffer.fragment_size + pos;
woinst->buffer.hw_pos = pos;
}
/*
**********************************************************************
* passthrough.h -- Emu10k1 digital passthrough header file
* Copyright (C) 2001 Juha Yrjl <jyrjola@cc.hut.fi>
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* May 15, 2001 Juha Yrjl base code release
*
**********************************************************************
*
* 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.
*
**********************************************************************
*/
#ifndef _PASSTHROUGH_H
#define _PASSTHROUGH_H
#include "audio.h"
/* number of 16-bit stereo samples in XTRAM buffer */
#define PT_SAMPLES 0x8000
#define PT_BLOCKSAMPLES 0x400
#define PT_BLOCKSIZE (PT_BLOCKSAMPLES*4)
#define PT_BLOCKSIZE_LOG2 12
#define PT_BLOCKCOUNT (PT_SAMPLES/PT_BLOCKSAMPLES)
#define PT_INITPTR (PT_SAMPLES/2-1)
#define PT_STATE_INACTIVE 0
#define PT_STATE_ACTIVATED 1
#define PT_STATE_PLAYING 2
/* passthrough struct */
struct pt_data
{
u8 selected, state, spcs_to_use;
int intr_gpr, enable_gpr, pos_gpr;
u32 blocks_played, blocks_copied, old_spcs[3];
u32 playptr, copyptr;
u32 prepend_size;
u8 *buf;
u8 ac3data;
char *patch_name, *intr_gpr_name, *enable_gpr_name, *pos_gpr_name;
wait_queue_head_t wait;
spinlock_t lock;
};
ssize_t emu10k1_pt_write(struct file *file, const char *buf, size_t count);
void emu10k1_pt_stop(struct emu10k1_card *card);
void emu10k1_pt_waveout_update(struct emu10k1_wavedevice *wave_dev);
#endif /* _PASSTHROUGH_H */
......@@ -130,7 +130,7 @@ void emu10k1_set_record_src(struct emu10k1_card *card, struct wiinst *wiinst)
break;
}
DPD(2, "bus addx: %x\n", buffer->dma_handle);
DPD(2, "bus addx: %#x\n", buffer->dma_handle);
sblive_writeptr(card, buffer->addrreg, 0, buffer->dma_handle);
......
......@@ -65,21 +65,6 @@ int emu10k1_voice_alloc(struct emu10k1_card *card, struct emu_voice *voice)
voice->card = card;
voice->num = i;
#ifdef PRIVATE_PCM_VOLUME
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
sblive_pcm_volume[i].channel_l = voice->num;
DPD(2, "preset left: %d\n", voice->num);
if (voice->flags & VOICE_FLAGS_STEREO) {
sblive_pcm_volume[i].channel_r = voice->num + 1;
DPD(2, "preset right: %d\n", voice->num + 1);
}
break;
}
}
#endif
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
DPD(2, " voice allocated -> %d\n", voice->num + i);
......@@ -104,20 +89,6 @@ void emu10k1_voice_free(struct emu_voice *voice)
if (voice->usage == VOICE_USAGE_FREE)
return;
#ifdef PRIVATE_PCM_VOLUME
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
if (voice->num == sblive_pcm_volume[i].channel_l)
sblive_pcm_volume[i].channel_l = NUM_G;
if ((voice->flags & VOICE_FLAGS_STEREO)
&& (voice->num + 1) == sblive_pcm_volume[i].channel_r) {
sblive_pcm_volume[i].channel_r = NUM_G;
}
break;
}
}
#endif
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
DPD(2, " voice released -> %d\n", voice->num + i);
......@@ -139,8 +110,6 @@ void emu10k1_voice_free(struct emu_voice *voice)
card->voicetable[voice->num + 1] = VOICE_USAGE_FREE;
spin_unlock_irqrestore(&card->lock, flags);
return;
}
void emu10k1_voice_playback_setup(struct emu_voice *voice)
......@@ -203,38 +172,22 @@ void emu10k1_voice_playback_setup(struct emu_voice *voice)
/* pitch envelope */
PEFE_PITCHAMOUNT, 0, TAGLIST_END);
#ifdef PRIVATE_PCM_VOLUME
{
int j;
for (j = 0; j < MAX_PCM_CHANNELS; j++) {
if (sblive_pcm_volume[j].channel_l == voice->num + i) {
voice->params[i].initial_attn = (sblive_pcm_volume[j].channel_r < NUM_G) ? sblive_pcm_volume[i].attn_l :
// test for mono channel (reverse logic is correct here!)
(sblive_pcm_volume[j].attn_r >
sblive_pcm_volume[j].attn_l) ? sblive_pcm_volume[j].attn_l : sblive_pcm_volume[j].attn_r;
DPD(2, "set left volume %d\n", voice->params[i].initial_attn);
break;
} else if (sblive_pcm_volume[j].channel_r == voice->num + i) {
voice->params[i].initial_attn = sblive_pcm_volume[j].attn_r;
DPD(2, "set right volume %d\n", voice->params[i].initial_attn);
break;
}
}
}
#endif
voice->params[i].fc_target = 0xffff;
}
return;
}
void emu10k1_voice_start(struct emu_voice *voice, int set)
void emu10k1_voices_start(struct emu_voice *first_voice, unsigned int num_voices, int set)
{
struct emu10k1_card *card = voice->card;
int i;
struct emu10k1_card *card = first_voice->card;
struct emu_voice *voice;
unsigned int voicenum;
int j;
DPF(2, "emu10k1_voice_start()\n");
DPF(2, "emu10k1_voices_start()\n");
for (voicenum = 0; voicenum < num_voices; voicenum++)
{
voice = first_voice + voicenum;
if (!set) {
u32 cra, ccis, cs, sample;
......@@ -255,8 +208,8 @@ void emu10k1_voice_start(struct emu_voice *voice, int set)
ccis *= 2;
}
for(i = 0; i < cs; i++)
sblive_writeptr(card, CD0 + i, voice->num, sample);
for(j = 0; j < cs; j++)
sblive_writeptr(card, CD0 + j, voice->num, sample);
/* Reset cache */
sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, 0);
......@@ -272,36 +225,49 @@ void emu10k1_voice_start(struct emu_voice *voice, int set)
sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, ccis);
}
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
sblive_writeptr_tag(card, voice->num + i,
IFATN, (voice->params[i].initial_fc << 8) | voice->params[i].initial_attn,
VTFT, (voice->params[i].volume_target << 16) | voice->params[i].fc_target,
CVCF, (voice->params[i].volume_target << 16) | voice->params[i].fc_target,
DCYSUSV, (voice->params[i].byampl_env_sustain << 8) | voice->params[i].byampl_env_decay,
for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
sblive_writeptr_tag(card, voice->num + j,
IFATN, (voice->params[j].initial_fc << 8) | voice->params[j].initial_attn,
VTFT, (voice->params[j].volume_target << 16) | voice->params[j].fc_target,
CVCF, (voice->params[j].volume_target << 16) | voice->params[j].fc_target,
DCYSUSV, (voice->params[j].byampl_env_sustain << 8) | voice->params[j].byampl_env_decay,
TAGLIST_END);
emu10k1_clear_stop_on_loop(card, voice->num + i);
emu10k1_clear_stop_on_loop(card, voice->num + j);
}
}
sblive_writeptr(card, PTRX_PITCHTARGET, voice->num + i, voice->pitch_target);
for (voicenum = 0; voicenum < num_voices; voicenum++)
{
voice = first_voice + voicenum;
if (i == 0)
for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
sblive_writeptr(card, PTRX_PITCHTARGET, voice->num + j, voice->pitch_target);
if (j == 0)
sblive_writeptr(card, CPF_CURRENTPITCH, voice->num, voice->pitch_target);
sblive_writeptr(card, IP, voice->num + i, voice->initial_pitch);
sblive_writeptr(card, IP, voice->num + j, voice->initial_pitch);
}
}
return;
}
void emu10k1_voice_stop(struct emu_voice *voice)
void emu10k1_voices_stop(struct emu_voice *first_voice, int num_voices)
{
struct emu10k1_card *card = voice->card;
int i;
struct emu10k1_card *card = first_voice->card;
struct emu_voice *voice;
unsigned int voice_num;
int j;
DPF(2, "emu10k1_voice_stop()\n");
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
sblive_writeptr_tag(card, voice->num + i,
for (voice_num = 0; voice_num < num_voices; voice_num++)
{
voice = first_voice + voice_num;
for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
sblive_writeptr_tag(card, voice->num + j,
PTRX_PITCHTARGET, 0,
CPF_CURRENTPITCH, 0,
IFATN, 0xffff,
......@@ -310,7 +276,6 @@ void emu10k1_voice_stop(struct emu_voice *voice)
IP, 0,
TAGLIST_END);
}
return;
}
}
......@@ -85,7 +85,7 @@ struct emu_voice
int emu10k1_voice_alloc(struct emu10k1_card *, struct emu_voice *);
void emu10k1_voice_free(struct emu_voice *);
void emu10k1_voice_playback_setup(struct emu_voice *);
void emu10k1_voice_start(struct emu_voice *, int);
void emu10k1_voice_stop(struct emu_voice *);
void emu10k1_voices_start(struct emu_voice *, unsigned int, int);
void emu10k1_voices_stop(struct emu_voice *, int);
#endif /* _VOICEMGR_H */
......@@ -115,17 +115,15 @@ union bdflush_param {
struct {
int nfract; /* Percentage of buffer cache dirty to
activate bdflush */
int ndirty; /* Maximum number of dirty blocks to write out per
wake-cycle */
int nrefill; /* Number of clean buffers to try to obtain
each time we call refill */
int dummy1; /* unused */
int dummy1; /* old "ndirty" */
int dummy2; /* old "nrefill" */
int dummy3; /* unused */
int interval; /* jiffies delay between kupdate flushes */
int age_buffer; /* Time for normal buffer to age before we flush it */
int nfract_sync; /* Percentage of buffer cache dirty to
int nfract_sync;/* Percentage of buffer cache dirty to
activate bdflush synchronously */
int dummy2; /* unused */
int dummy3; /* unused */
int dummy4; /* unused */
int dummy5; /* unused */
} b_un;
unsigned int data[N_PARAM];
} bdf_prm = {{30, 64, 64, 256, 5*HZ, 30*HZ, 60, 0, 0}};
......@@ -1067,7 +1065,6 @@ struct buffer_head * getblk(kdev_t dev, int block, int size)
out:
write_unlock(&hash_table_lock);
spin_unlock(&lru_list_lock);
touch_buffer(bh);
return bh;
}
......@@ -1234,6 +1231,7 @@ struct buffer_head * bread(kdev_t dev, int block, int size)
struct buffer_head * bh;
bh = getblk(dev, block, size);
touch_buffer(bh);
if (buffer_uptodate(bh))
return bh;
ll_rw_block(READ, 1, &bh);
......@@ -2601,20 +2599,19 @@ static int sync_old_buffers(void)
sync_supers(0);
unlock_kernel();
spin_lock(&lru_list_lock);
for (;;) {
if (write_some_buffers(NODEV)) {
struct buffer_head *bh;
spin_lock(&lru_list_lock);
bh = lru_list[BUF_DIRTY];
if (bh && !time_before(jiffies, bh->b_flushtime))
if (!bh || time_before(jiffies, bh->b_flushtime))
break;
if (write_some_buffers(NODEV))
continue;
spin_unlock(&lru_list_lock);
}
run_task_queue(&tq_disk);
return 0;
}
spin_unlock(&lru_list_lock);
return 0;
}
int block_sync_page(struct page *page)
......
......@@ -148,6 +148,7 @@ extern void delete_from_swap_cache_nolock(struct page *page);
extern void free_page_and_swap_cache(struct page *page);
/* linux/mm/swapfile.c */
extern int vm_swap_full(void);
extern unsigned int nr_swapfiles;
extern struct swap_info_struct swap_info[];
extern int is_swap_partition(kdev_t);
......
......@@ -1098,9 +1098,10 @@ void swapin_readahead(swp_entry_t entry)
*/
static int do_swap_page(struct mm_struct * mm,
struct vm_area_struct * vma, unsigned long address,
pte_t * page_table, swp_entry_t entry, int write_access)
pte_t * page_table, pte_t orig_pte, int write_access)
{
struct page *page;
swp_entry_t entry = pte_to_swp_entry(orig_pte);
pte_t pte;
spin_unlock(&mm->page_table_lock);
......@@ -1112,7 +1113,11 @@ static int do_swap_page(struct mm_struct * mm,
unlock_kernel();
if (!page) {
spin_lock(&mm->page_table_lock);
return -1;
/*
* Back out if somebody else faulted in this pte while
* we released the page table lock.
*/
return pte_same(*page_table, orig_pte) ? -1 : 1;
}
}
......@@ -1128,7 +1133,7 @@ static int do_swap_page(struct mm_struct * mm,
* released the page table lock.
*/
spin_lock(&mm->page_table_lock);
if (pte_present(*page_table)) {
if (!pte_same(*page_table, orig_pte)) {
UnlockPage(page);
page_cache_release(page);
return 1;
......@@ -1139,8 +1144,14 @@ static int do_swap_page(struct mm_struct * mm,
pte = mk_pte(page, vma->vm_page_prot);
swap_free(entry);
if (write_access && exclusive_swap_page(page))
if (exclusive_swap_page(page)) {
if (write_access)
pte = pte_mkwrite(pte_mkdirty(pte));
if (vm_swap_full()) {
delete_from_swap_cache_nolock(page);
pte = pte_mkdirty(pte);
}
}
UnlockPage(page);
flush_page_to_ram(page);
......@@ -1297,7 +1308,7 @@ static inline int handle_pte_fault(struct mm_struct *mm,
*/
if (pte_none(entry))
return do_no_page(mm, vma, address, write_access, pte);
return do_swap_page(mm, vma, address, pte, pte_to_swp_entry(entry), write_access);
return do_swap_page(mm, vma, address, pte, entry, write_access);
}
if (write_access) {
......
......@@ -589,7 +589,7 @@ unsigned int nr_free_buffer_pages (void)
zonelist_t *zonelist;
zone_t **zonep, *zone;
zonelist = contig_page_data.node_zonelists + (GFP_KERNEL & GFP_ZONEMASK);
zonelist = contig_page_data.node_zonelists + (GFP_NOFS & GFP_ZONEMASK);
zonep = zonelist->zones;
for (zone = *zonep++; zone; zone = *zonep++) {
......
......@@ -19,11 +19,31 @@
spinlock_t swaplock = SPIN_LOCK_UNLOCKED;
unsigned int nr_swapfiles;
int total_swap_pages;
struct swap_list_t swap_list = {-1, -1};
struct swap_info_struct swap_info[MAX_SWAPFILES];
/*
* When swap space gets filled up, we will set this flag.
* This will make do_swap_page(), in the page fault path,
* free swap entries on swapin so we'll reclaim swap space
* in order to be able to swap something out.
*
* At the moment we start reclaiming when swap usage goes
* over 80% of swap space.
*
* XXX: Random numbers, fixme.
*/
#define SWAP_FULL_PCT 80
int vm_swap_full (void)
{
int swap_used = total_swap_pages - nr_swap_pages;
return swap_used * 100 > total_swap_pages * SWAP_FULL_PCT;
}
#define SWAPFILE_CLUSTER 256
static inline int scan_swap_map(struct swap_info_struct *si, unsigned short count)
......@@ -329,56 +349,26 @@ static void unuse_process(struct mm_struct * mm,
}
/*
* We completely avoid races by reading each swap page in advance,
* and then search for the process using it. All the necessary
* page table adjustments can then be made atomically.
* this is called when we find a page in the swap list
* all the locks have been dropped at this point which
* isn't a problem because we rescan the swap map
* and we _don't_ clear the refrence count if for
* some reason it isn't 0
*/
static int try_to_unuse(unsigned int type)
static inline int free_found_swap_entry(unsigned int type, int i)
{
struct swap_info_struct * si = &swap_info[type];
struct task_struct *p;
struct page *page;
swp_entry_t entry;
int i;
while (1) {
/*
* The algorithm is inefficient but seldomly used
* and probably not worth fixing.
*
* Make sure that we aren't completely killing
* interactive performance.
*/
if (current->need_resched)
schedule();
entry = SWP_ENTRY(type, i);
/*
* Find a swap page in use and read it in.
*/
swap_device_lock(si);
for (i = 1; i < si->max ; i++) {
if (si->swap_map[i] > 0 && si->swap_map[i] != SWAP_MAP_BAD) {
/*
* Prevent swaphandle from being completely
* unused by swap_free while we are trying
* to read in the page - this prevents warning
* messages from rw_swap_page_base.
* Get a page for the entry, using the existing swap
* cache page if there is one. Otherwise, get a clean
* page and read the swap into it.
*/
if (si->swap_map[i] != SWAP_MAP_MAX)
si->swap_map[i]++;
swap_device_unlock(si);
goto found_entry;
}
}
swap_device_unlock(si);
break;
found_entry:
entry = SWP_ENTRY(type, i);
/* Get a page for the entry, using the existing swap
cache page if there is one. Otherwise, get a clean
page and read the swap into it. */
page = read_swap_cache_async(entry);
if (!page) {
swap_free(entry);
......@@ -393,25 +383,100 @@ static int try_to_unuse(unsigned int type)
unuse_process(p->mm, entry, page);
read_unlock(&tasklist_lock);
shmem_unuse(entry, page);
/* Now get rid of the extra reference to the temporary
page we've been using. */
/*
* Now get rid of the extra reference to the temporary
* page we've been using.
*/
page_cache_release(page);
/*
* Check for and clear any overflowed swap map counts.
*/
swap_free(entry);
return 0;
}
/*
* We completely avoid races by reading each swap page in advance,
* and then search for the process using it. All the necessary
* page table adjustments can then be made atomically.
*/
static int try_to_unuse(unsigned int type)
{
struct swap_info_struct * si = &swap_info[type];
int ret, foundpage;
do {
int i;
/*
* The algorithm is inefficient but seldomly used
*
* Find a swap page in use and read it in.
*/
foundpage = 0;
swap_device_lock(si);
for (i = 1; i < si->max ; i++) {
int count = si->swap_map[i];
if (!count || count == SWAP_MAP_BAD)
continue;
/*
* Prevent swaphandle from being completely
* unused by swap_free while we are trying
* to read in the page - this prevents warning
* messages from rw_swap_page_base.
*/
foundpage = 1;
if (count != SWAP_MAP_MAX)
si->swap_map[i] = count + 1;
swap_device_unlock(si);
ret = free_found_swap_entry(type,i);
if (ret)
return ret;
/*
* we pick up the swap_list_lock() to guard the nr_swap_pages,
* si->swap_map[] should only be changed if it is SWAP_MAP_MAX
* otherwise ugly stuff can happen with other people who are in
* the middle of a swap operation to this device. This kind of
* operation can sometimes be detected with the undead swap
* check. Don't worry about these 'undead' entries for now
* they will be caught the next time though the top loop.
* Do worry, about the weak locking that allows this to happen
* because if it happens to a page that is SWAP_MAP_MAX
* then bad stuff can happen.
*/
swap_list_lock();
swap_device_lock(si);
if (si->swap_map[i] > 0) {
if (si->swap_map[i] != SWAP_MAP_MAX)
/* normally this would just kill the swap page if
* it still existed, it appears though that the locks
* are a little fuzzy
*/
if (si->swap_map[i] != SWAP_MAP_MAX) {
printk("VM: Undead swap entry %08lx\n",
entry.val);
SWP_ENTRY(type, i).val);
} else {
nr_swap_pages++;
si->swap_map[i] = 0;
}
}
swap_device_unlock(si);
swap_list_unlock();
/*
* This lock stuff is ulgy!
* Make sure that we aren't completely killing
* interactive performance.
*/
if (current->need_resched)
schedule();
swap_device_lock(si);
}
swap_device_unlock(si);
} while (foundpage);
return 0;
}
......@@ -462,6 +527,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
swap_list.next = swap_list.head;
}
nr_swap_pages -= p->pages;
total_swap_pages -= p->pages;
swap_list_unlock();
p->flags = SWP_USED;
err = try_to_unuse(type);
......@@ -477,6 +543,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
else
swap_info[prev].next = p - swap_info;
nr_swap_pages += p->pages;
total_swap_pages += p->pages;
swap_list_unlock();
p->flags = SWP_WRITEOK;
goto out_dput;
......@@ -764,6 +831,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
p->pages = nr_good_pages;
swap_list_lock();
nr_swap_pages += nr_good_pages;
total_swap_pages += nr_good_pages;
printk(KERN_INFO "Adding Swap: %dk swap-space (priority %d)\n",
nr_good_pages<<(PAGE_SHIFT-10), p->prio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment