Reduce interrupt latency in sound/pci/via82xx.c
PATCH 1/1 Reduce interrupt latency in sound/pci/via82xx.c
Hi Takashi
Please apply, if you agree.
Thanks,
Karsten
From: Karsten Wiese <[email protected]>
Reduce interrupt latency in sound/pci/via82xx.c
The change only affects the via823x kind of chips. Here the via8233_pcm_pointer_hw() function
(named snd_via8233_pcm_pointer() before)
needs to loop until a non zero position is red from the chip.
Measurements have shown that more than 200 loops are typically needed on an Athlon64.
As io-reads cost many cycles, those loops sum up huge. via8233_pcm_pointer_hw() runs either in interrupt or with interrupts disabled. So it introduces significant interrupt latency.
The patch introduces a calculated position value hwptr_done, that is updated by the interrupt routine when a period is completed. This works much faster at the cost of less precise positions. Position precision is period_size, which is ok for nearly all applications.
The actual method chosen depends on the period_size used and its relation to the module parameter hw_position[]:
if (period_size >= hw_position[device_index]))
Use chip based precise position calculation
else
Use fast coarse position calculation
alsa-kernel/pci/via82xx.c +43 -5
@@ -83,6 +83,7 @@static int ac97_clock[SNDRV_CARDS ] = {[0 ... (SNDRV_CARDS -1 )] =48000 };static char *ac97_quirk[SNDRV_CARDS ];static int dxs_support[SNDRV_CARDS ]; +static int hw_position[SNDRV_CARDS ] = {[0 ... (SNDRV_CARDS -1 )] =8192 };module_param_array (index, int,NULL ,0444 );MODULE_PARM_DESC (index,"Index value for VIA 82xx bridge." );
@@ -102,6 +103,8 @@MODULE_PARM_DESC (ac97_quirk,"AC'97 workaround for strange hardware." );module_param_array (dxs_support, int,NULL ,0444 );MODULE_PARM_DESC (dxs_support,"Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)" ); +module_param_array (hw_position, int,NULL ,0444 ); +MODULE_PARM_DESC (hw_position,"If actual frames per period is bigger or equal, position is red from hardware. Else position resolution is period size." );/* revision numbers for via686 */
@@ -328,6 +331,7 @@unsigned int fragsize;unsigned int bufsize;unsigned int bufsize2; +int hwptr_done;/* processed frame position in the buffer */ };
@@ -596,6 +600,7 @@outb (0x00 ,VIADEV_REG (viadev,OFFSET_TYPE ));/* for via686 */ // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); viadev->lastpos =0 ; + viadev->hwptr_done =0 ; }
@@ -621,13 +626,26 @@spin_lock (&chip->reg_lock);for (i =0 ; i < chip->num_devs; i++) {viadev_t *viadev = &chip->devs[i]; +snd_pcm_substream_t *substream;unsigned char c_status =inb (VIADEV_REG (viadev,OFFSET_STATUS )); c_status &= (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG |VIA_REG_STAT_STOPPED );if (! c_status)continue ; -if (viadev->substream && viadev->running) { + substream = viadev->substream; +if (substream && viadev->running) {spin_unlock (&chip->reg_lock); -snd_pcm_period_elapsed (viadev->substream); + +/* +* Update period bound position. +* Its used by via8233 when hw_pointer[dev] > period_size. +* To check for this condition would take as much cycles as to just do it. +*/ +if (c_status &VIA_REG_STAT_EOL ) + viadev->hwptr_done =0 ; +else + viadev->hwptr_done += substream->runtime->period_size; + +snd_pcm_period_elapsed (substream);spin_lock (&chip->reg_lock); }outb (c_status,VIADEV_REG (viadev,OFFSET_STATUS ));/* ack */
@@ -764,12 +782,12 @@ }/* -* get the current pointer on via823x +* get the current pointer on via823x from chip +* exact, but slow due to excessive looping */ -static snd_pcm_uframes_t snd_via8233_pcm_pointer (snd_pcm_substream_t *substream) +static snd_pcm_uframes_t via8233_pcm_pointer_hw (snd_pcm_substream_t *substream,viadev_t *viadev) {via82xx_t *chip =snd_pcm_substream_chip (substream); -viadev_t *viadev = (viadev_t *)substream->runtime->private_data;unsigned int idx, count, res;int timeout =5000 ;
@@ -800,6 +818,26 @@return bytes_to_frames (substream->runtime, res); } +/* +* get the current pointer on via82xx from elapsed periods. +* resolution limited to period_size. fast. +*/ +static snd_pcm_uframes_t via82xx_pcm_pointer (snd_pcm_substream_t *substream,viadev_t *viadev) +{ +return viadev->hwptr_done; +} + +/* +* get the current pointer on via823x +*/ +static snd_pcm_uframes_t snd_via8233_pcm_pointer (snd_pcm_substream_t *substream) +{ +viadev_t *viadev = (viadev_t *)substream->runtime->private_data; +if (likely (hw_position[substream->pcm->device] > substream->runtime->period_size)) +return via82xx_pcm_pointer (substream, viadev); +else +return via8233_pcm_pointer_hw (substream, viadev); +}/* * hw_params callback:
At Mon, 12 Sep 2005 14:18:04 +0200,
Quoted 31 lines · Karsten Wiese
From: Karsten Wiese <[email protected]>
Reduce interrupt latency in
sound/pci/via82xx.cThe change only affects the via823x kind of chips. Here the
via8233_pcm_pointer_hw()function
(namedsnd_via8233_pcm_pointer()before)
needs to loop until a non zero position is red from the chip.Measurements have shown that more than 200 loops are typically needed on an Athlon64.
As io-reads cost many cycles, those loops sum up huge.via8233_pcm_pointer_hw()runs either in interrupt or with interrupts disabled. So it introduces significant interrupt latency.The patch introduces a calculated position value
hwptr_done, that is updated by the interrupt routine when a period is completed. This works much faster at the cost of less precise positions. Position precision isperiod_size, which is ok for nearly all applications.The actual method chosen depends on the
period_sizeused and its relation to the module parameter hw_position[]:
if (period_size>= hw_position[device_index]))
Use chip based precise position calculation
else
Use fast coarse position calculation
Quoted 1 line
Signed-off-by Karsten Wiese <[email protected]>
I don't like that the behavior depends on the period size. If it's bad to loop too much, we should fix this behavior.
The question is how to handle the value 0 of CUR_COUNT register. Usually this occurs in a boundary, i.e. very likely only in snd_pcm_period_elapsed().
So, for example, add a flag indicating that the position callback is being called in the irq handler. And the position callback assumes the exact next period if CUR_COUNT is 0 and this flag is set. If the flag isn't set, the driver loops probing to get an accurate position.
Takashi
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Am Montag, 12. September 2005 14:35 schrieb Takashi Iwai:
Quoted 4 lines
I don't like that the behavior depends on the period size. If it's bad to loop too much, we should fix this behavior.
Quoted 8 lines
The question is how to handle the value 0 of
CUR_COUNTregister. Usually this occurs in a boundary, i.e. very likely only insnd_pcm_period_elapsed().So, for example, add a flag indicating that the position callback is being called in the irq handler. And the position callback assumes the exact next period if
CUR_COUNTis 0 and this flag is set. If the flag isn't set, the driver loops probing to get an accurate position.
This doesn't help in the worst case:
An application requests position when CUR_COUNT is already 0 immediately before the interrupt callback runs. Thus it disables interrupt (or blocks the callback by spinlock) until it reads != 0 resulting in the same interrupt latency.
How about a bool module_parameter to choose the pointer calculation method then?
Do you know any application benefitting from the sub period position precision?
If not so, we could even use #ifdef to choose the method at compile time and default to the new fast method.
Thus we'd still have the know how in the code and default to optimal interrupt performance.
Karsten
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
At Mon, 12 Sep 2005 15:09:27 +0200,
Quoted 15 lines · Karsten Wiese
Am Montag, 12. September 2005 14:35 schrieb Takashi Iwai:
Quoted 4 lines
I don't like that the behavior depends on the period size. If it's bad to loop too much, we should fix this behavior.
Quoted 8 lines
The question is how to handle the value 0 of
CUR_COUNTregister. Usually this occurs in a boundary, i.e. very likely only insnd_pcm_period_elapsed().So, for example, add a flag indicating that the position callback is being called in the irq handler. And the position callback assumes the exact next period if
CUR_COUNTis 0 and this flag is set. If the flag isn't set, the driver loops probing to get an accurate position.
Quoted 5 lines
This doesn't help in the worst case:
An application requests position whenCUR_COUNTis already 0 immediately before the interrupt callback runs. Thus it disables interrupt (or blocks the callback by spinlock) until it reads != 0 resulting in the same interrupt latency.
Hmm, then let's fix the handling of 0 read in all cases. We can simply assume the next period in this case as an exception.
Quoted 4 lines
How about a bool
module_parameterto choose the pointer calculation method then?
Do you know any application benefitting from the sub period position precision?
dmix/dsnoop/dshare.
Takashi
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Am Montag, 12. September 2005 15:09 schrieb Takashi Iwai:
Quoted 2 lines
Hmm, then let's fix the handling of 0 read in all cases. We can simply assume the next period in this case as an exception.
No. I've looked at the change sequence of CUR_COUNT through an iopl(3)ed app running as root polling CUR_COUNT.
The problem case looks like this:
step value
====== ==========
0 0x01000020 // page index 1, 32 bytes left to transfer
1 0x01000000 // page index 1 complete
2 0x02000000 // switched to page index 2, looks like complete
// _but hasn't yet started!_
3 0x02001000 // page index 2, 4096 bytes left to transfer
Step 1 values could be red up to ~270 times in a row. Step 2 values occurred maximum 2 times in a row so far.
If above Step 2 repetition count would reflect real worst case, we could handle (CUR_COUNT & 0xFFFFFF)==0 like this:
read CUR_COUNT 3 times in a row.
index page of lowest (CUR_COUNT >> 24) has completed
Problem is that 3 times in a row might not be enough for all machines. So we'd assume 6 times to be safe and that would give significant latency again, though still better than what we have now.
How about:
- when in interrupt, read CUR_COUNT 1 time.
if (CUR_COUNT & 0xFFFFFF)==0 use fast position with period resolution
- when not in interrupt get position from chip by reading CUR_COUNT maximum 6 times
- provide default off module_parameter "fast_position" to always only use fast position
Karsten
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
At Mon, 12 Sep 2005 16:31:31 +0200,
Quoted 13 lines · Karsten Wiese
Am Montag, 12. September 2005 15:09 schrieb Takashi Iwai:
Quoted 2 lines
Hmm, then let's fix the handling of 0 read in all cases. We can simply assume the next period in this case as an exception.
No. I've looked at the change sequence of
CUR_COUNTthrough an iopl(3)ed app running as root pollingCUR_COUNT.
The problem case looks like this:
step value
====== ==========
00x01000020// page index 1, 32 bytes left to transfer
10x01000000// page index 1 complete
20x02000000// switched to page index 2, looks like complete
Quoted 6 lines
// _but hasn't yet started!_3
0x02001000// page index 2, 4096 bytes left to transferStep 1 values could be red up to ~270 times in a row. Step 2 values occurred maximum 2 times in a row so far.
Well, we can check the validity of the assumed position by comparing with the last position. An untested patch is below.
Quoted 10 lines
If above Step 2 repetition count would reflect real worst case, we could handle (
CUR_COUNT& 0xFFFFFF)==0 like this:read
CUR_COUNT3 times in a row.
index page of lowest (CUR_COUNT>> 24) has completedProblem is that 3 times in a row might not be enough for all machines. So we'd assume 6 times to be safe and that would give significant latency again, though still better than what we have now.
Quoted 6 lines
How about:
- when in interrupt, readCUR_COUNT1 time.
if (CUR_COUNT& 0xFFFFFF)==0 use fast position with period resolution
- when not in interrupt get position from chip by readingCUR_COUNTmaximum 6 times
This sounds not bad.
Quoted 2 lines
- provide default off
module_parameter"fast_position" to always only use fast position
... if the solution witout loop doesn't work.
Takashi
Index: alsa-kernel/pci/via82xx.c
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/via82xx.c,v retrieving revision 1.178
pci/via82xx.c +25 -16
@@ -325,6 +325,7 @@struct snd_via_sg_table *idx_table;/* for recovery from the unexpected pointer */ unsigned int lastpos; +unsigned int hwpos;unsigned int fragsize;unsigned int bufsize;unsigned int bufsize2;
@@ -596,6 +597,7 @@outb (0x00 ,VIADEV_REG (viadev,OFFSET_TYPE ));/* for via686 */ // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); viadev->lastpos =0 ; + viadev->hwpos =0 ; }
@@ -626,6 +628,8 @@if (! c_status)continue ;if (viadev->substream && viadev->running) { + viadev->hwpos += viadev->fragsize; + viadev->hwpos %= viadev->bufsize;spin_unlock (&chip->reg_lock);snd_pcm_period_elapsed (viadev->substream);spin_lock (&chip->reg_lock);
@@ -771,29 +775,34 @@via82xx_t *chip =snd_pcm_substream_chip (substream);viadev_t *viadev = (viadev_t *)substream->runtime->private_data;unsigned int idx, count, res; -int timeout =5000 ; snd_assert(viadev->tbl_entries, return 0);if (!(inb (VIADEV_REG (viadev,OFFSET_STATUS )) &VIA_REG_STAT_ACTIVE ))return 0 ;spin_lock (&chip->reg_lock); -do { - count =inl (VIADEV_REG (viadev,OFFSET_CURR_COUNT )); -/* some mobos read 0 count */ -if ((count &0xffffff ) || ! viadev->running) -break ; - }while (--timeout); -if (! timeout) -snd_printd (KERN_ERR "zero position is read\n" ); - idx = count >>24 ; -if (idx >= viadev->tbl_entries) { + count =inl (VIADEV_REG (viadev,OFFSET_CURR_COUNT )); +/* some mobos read 0 count +* +* This happens when the register is being updated. We assume the +* new period here +*/ +if (! (count &0xffffff )) { + res = viadev->hwpos; +if (check_invalid_pos (viadev, res)) + res = viadev->lastpos; +else + viadev->lastpos = res; + }else { + idx = count >>24 ; +if (idx >= viadev->tbl_entries) {#ifdef POINTER_DEBUG -printk ("fail: invalid idx = %i/%i\n" , idx, viadev->tbl_entries); +printk ("fail: invalid idx = %i/%i\n" , idx, viadev->tbl_entries);#endif - res = viadev->lastpos; - }else { - count &=0xffffff ; - res =calc_linear_pos (viadev, idx, count); + res = viadev->lastpos; + }else { + count &=0xffffff ; + res =calc_linear_pos (viadev, idx, count); + } }spin_unlock (&chip->reg_lock);
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Quoted 14 lines · Karsten Wiese
Am Montag, 12. September 2005 15:09 schrieb Takashi Iwai:
Quoted 2 lines
Hmm, then let's fix the handling of 0 read in all cases. We can simply assume the next period in this case as an exception.
No. I've looked at the change sequence of
CUR_COUNTthrough an iopl(3)ed app running as root pollingCUR_COUNT.
The problem case looks like this:
step value
====== ==========
00x01000020// page index 1, 32 bytes left to transfer
10x01000000// page index 1 complete
20x02000000// switched to page index 2, looks like complete
Quoted 7 lines
// _but hasn't yet started!_3
0x02001000// page index 2, 4096 bytes left to transferStep 1 values could be red up to ~270 times in a row. Step 2 values occurred maximum 2 times in a row so far.
That looks truely horrible.
So upper byte in counting up, and lower 3 bytes are counting down!!!
Can you please give me some indication of how long the register stays at each value, and at what point the interrupt happens.
Are you also saying that the count can proceed like this:0x010000000x020000000x020010000x02000fff
...0x020000010x020000000x03000000
So, here we actually have 0x0200000 twice in the same sequence. That sort of situation will never work well and there is really not a lot that can be done except to say that whenever ((value & 0xffffff) == 0) we don't have a clue where we are in the buffer!
You say the Step 1 values could be red up to ~270 times in a row but Step 2 values occured max 2 times in a row. Can we assume therefore that the counter is getting stuck st Step 1 for some reason?
James
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
At Mon, 12 Sep 2005 23:00:16 +0100,
Quoted 20 lines · James Courtier-Dutton
Quoted 18 lines · Karsten Wiese
Am Montag, 12. September 2005 15:09 schrieb Takashi Iwai:
Quoted 2 lines
Hmm, then let's fix the handling of 0 read in all cases. We can simply assume the next period in this case as an exception.
No. I've looked at the change sequence of
CUR_COUNTthrough an iopl(3)ed app running as root pollingCUR_COUNT.
The problem case looks like this:
step value
====== ==========
00x01000020// page index 1, 32 bytes left to transfer
10x01000000// page index 1 complete
20x02000000// switched to page index 2, looks like complete// _but hasn't yet started!_3
0x02001000// page index 2, 4096 bytes left to transfer
Quoted 6 lines
Quoted 3 lines
Step 1 values could be red up to ~270 times in a row. Step 2 values occurred maximum 2 times in a row so far.
That looks truely horrible.
So upper byte in counting up, and lower 3 bytes are counting down!!!
It's the correct behavior.
The lower 3 bytes are the _residual_ counter, and the upper byte is the index of the SG buffer descriptor.
Takashi
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Am Dienstag, 13. September 2005 00:00 schrieb James Courtier-Dutton:
Quoted 19 lines
Quoted 18 lines · Karsten Wiese
Am Montag, 12. September 2005 15:09 schrieb Takashi Iwai:
Quoted 2 lines
Hmm, then let's fix the handling of 0 read in all cases. We can simply assume the next period in this case as an exception.
No. I've looked at the change sequence of
CUR_COUNTthrough an iopl(3)ed app running as root pollingCUR_COUNT.
The problem case looks like this:
step value
====== ==========
00x01000020// page index 1, 32 bytes left to transfer
10x01000000// page index 1 complete
20x02000000// switched to page index 2, looks like complete// _but hasn't yet started!_3
0x02001000// page index 2, 4096 bytes left to transfer
Quoted 6 lines
Quoted 3 lines
Step 1 values could be red up to ~270 times in a row. Step 2 values occurred maximum 2 times in a row so far.
That looks truely horrible.
So upper byte in counting up, and lower 3 bytes are counting down!!!
bits 31-24 hold s(catter)g(ather)d(ma) page index, bits 23-0 show the count of bytes still to transfer.
Quoted 3 lines
Can you please give me some indication of how long the register stays at each value, and at what point the interrupt happens.
I think the interrupt line is activated, where the first Step 1 value is red. Haven't checked the exact times in useconds.
Quoted 10 lines
Are you also saying that the count can proceed like this:
0x010000000x020000000x020010000x02000fff
...0x020000010x020000000x03000000
yes
Quoted 9 lines
So, here we actually have
0x0200000twice in the same sequence. That sort of situation will never work well and there is really not a lot that can be done except to say that whenever ((value &0xffffff) == 0) we don't have a clue where we are in the buffer!You say the Step 1 values could be red up to ~270 times in a row but Step 2 values occured max 2 times in a row. Can we assume therefore that the counter is getting stuck st Step 1 for some reason?
Yes, it waits shortly when it has finished a period.
So if above assumption about when the interrupt triggers is correct, another strategy to solve the ((value & 0xffffff) == 0) situation, when not in interrupt would look like:
int c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)) if (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG))
we have finished the period
else
we are still at the start of the period, interrupt routine has just run,
use last interrupt position
Will take some time before I try that. Urgent stuff piling up here...
Karsten
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Am Dienstag, 13. September 2005 13:18 schrieb Karsten Wiese:
Quoted 9 lines
another strategy to solve the ((value &
0xffffff) == 0) situation, when not in interrupt would look like:
intc_status=inb(VIADEV_REG(viadev, OFFSET_STATUS))if (c_status& (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG))
we have finished the period
else
we are still at the start of the period, interrupt routine has just run,
use last interrupt position
Attached patch implements above idea and works fine here.
Karsten
Reduce interrupt latency in sound/pci/via82xx.c
The change only affects the via823x kind of chips. Here the via8233_pcm_pointer_hw() function
(named snd_via8233_pcm_pointer() before)
needed to loop until a non zero position is red from the chip.
Measurements have shown that more than 200 loops are typically needed on an Athlon64.
As io-reads cost many cycles, those loops sum up huge. via8233_pcm_pointer_hw() runs either in interrupt or with interrupts disabled. So it introduces significant interrupt latency.
The patch introduces a calculated position value hwptr_done, that is updated by the interrupt routine when a period is completed. It is only used, if the 823x chip returns a zero position, which can't be interpreted reliably.
Further optimisation is applied on the 8233 chip's interrupt routine:
Only the SGD_SHADOW is read, as it contains all infos needed. We ommit ~5 more register reads that way.
sound/pci/via82xx.c +117 -30
@@ -41,6 +41,9 @@* device for applications. * - clean up the code, separate low-level initialization * routines for each chipset. +* +* Sep. 26, 2005 Karsten Wiese <[email protected]> +* - Optimize position calculation for the 823x chips. */ #include <sound/driver.h>
@@ -336,6 +339,8 @@unsigned int fragsize;unsigned int bufsize;unsigned int bufsize2; +int hwptr_done;/* processed frame position in the buffer */ +int in_interrupt; };
@@ -401,8 +406,8 @@ };static struct pci_device_id snd_via82xx_ids[] = { - {0x1106 ,0x3058 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA686 , },/* 686A */ - {0x1106 ,0x3059 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA8233 , },/* VT8233 */ + {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_82C686_5 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA686 , },/* 686A */ + {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_8233_5 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA8233 , },/* VT8233 */ {0 , } };
@@ -556,7 +561,7 @@ {via82xx_t *chip = ac97->private_data;unsigned int xval; - + xval = !ac97->num ?VIA_REG_AC97_CODEC_ID_PRIMARY :VIA_REG_AC97_CODEC_ID_SECONDARY ; xval <<=VIA_REG_AC97_CODEC_ID_SHIFT ; xval |= reg <<VIA_REG_AC97_CMD_SHIFT ;
@@ -604,14 +609,15 @@outb (0x00 ,VIADEV_REG (viadev,OFFSET_TYPE ));/* for via686 */ // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); viadev->lastpos =0 ; + viadev->hwptr_done =0 ; }/* * Interrupt handler +* Used for 686 and 8233A */ - -static irqreturn_t snd_via82xx_interrupt (int irq,void *dev_id,struct pt_regs *regs) +static irqreturn_t snd_via686_interrupt (int irq,void *dev_id,struct pt_regs *regs) {via82xx_t *chip = dev_id;unsigned int status;
@@ -630,13 +636,23 @@for (i =0 ; i < chip->num_devs; i++) {viadev_t *viadev = &chip->devs[i];unsigned char c_status =inb (VIADEV_REG (viadev,OFFSET_STATUS )); - c_status &= (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG |VIA_REG_STAT_STOPPED ); -if (! c_status) +if (! (c_status & (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG |VIA_REG_STAT_STOPPED )))continue ;if (viadev->substream && viadev->running) { +/* +* Update hwptr_done based on 'period elapsed' +* interrupts. We'll use it, when the chip returns 0 +* for OFFSET_CURR_COUNT. +*/ +if (c_status &VIA_REG_STAT_EOL ) + viadev->hwptr_done =0 ; +else + viadev->hwptr_done += viadev->fragsize; + viadev->in_interrupt = c_status;spin_unlock (&chip->reg_lock);snd_pcm_period_elapsed (viadev->substream);spin_lock (&chip->reg_lock); + viadev->in_interrupt =0 ; }outb (c_status,VIADEV_REG (viadev,OFFSET_STATUS ));/* ack */ }
@@ -645,6 +661,61 @@ }/* +* Interrupt handler +*/ +static irqreturn_t snd_via8233_interrupt (int irq,void *dev_id,struct pt_regs *regs) +{ +via82xx_t *chip = dev_id; +unsigned int status; +unsigned int i; +unsigned int intr_mask; +irqreturn_t irqreturn =IRQ_NONE ; + + +/* check status for each stream */ + intr_mask = chip->intr_mask; +spin_lock (&chip->reg_lock); + status =inl (VIAREG (chip,SGD_SHADOW )); +for (i =0 ; i < chip->num_devs; + i++, intr_mask >>=4 , status >>=4 ) { +viadev_t *viadev = &chip->devs[i]; +snd_pcm_substream_t *substream; +unsigned char c_status; +while (!(intr_mask &3 )) { + intr_mask >>=4 ; + status >>=4 ; + } + c_status = status & (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG ); +if (!c_status) +continue ; + c_status |= ((status &8 ) <<4 );// ACTIVE Flag + substream = viadev->substream; +if (substream && viadev->running) { +/* +* Update hwptr_done based on 'period elapsed' +* interrupts. We'll use it, when the chip returns 0 +* for OFFSET_CURR_COUNT. +*/ +if (c_status &VIA_REG_STAT_EOL ) + viadev->hwptr_done =0 ; +else + viadev->hwptr_done += viadev->fragsize; + viadev->in_interrupt = c_status; +spin_unlock (&chip->reg_lock); + +snd_pcm_period_elapsed (substream); + +spin_lock (&chip->reg_lock); + viadev->in_interrupt =0 ; + } +outb (c_status,VIADEV_REG (viadev,OFFSET_STATUS ));/* ack */ + irqreturn =IRQ_HANDLED ; + } +spin_unlock (&chip->reg_lock); +return irqreturn; +} + +/* * PCM callbacks */
@@ -705,6 +776,8 @@ size = viadev->idx_table[idx].size; base = viadev->idx_table[idx].offset; res = base + size - count; +if (res >= viadev->bufsize) + res -= viadev->bufsize;/* check the validity of the calculated position */ if (size < count) {
@@ -734,9 +807,6 @@ } } } - viadev->lastpos = res;/* remember the last position */ -if (res >= viadev->bufsize) - res -= viadev->bufsize;return res; }
@@ -764,6 +834,7 @@else /* CURR_PTR holds the address + 8 */ idx = ((ptr - (unsigned int )viadev->table.addr) /8 -1 ) % viadev->tbl_entries; res =calc_linear_pos (viadev, idx, count); + viadev->lastpos = res;/* remember the last position */ spin_unlock (&chip->reg_lock);return bytes_to_frames (substream->runtime, res);
@@ -777,36 +848,49 @@via82xx_t *chip =snd_pcm_substream_chip (substream);viadev_t *viadev = (viadev_t *)substream->runtime->private_data;unsigned int idx, count, res; -int timeout =5000 ; +int status; snd_assert(viadev->tbl_entries, return 0); -if (!(inb (VIADEV_REG (viadev,OFFSET_STATUS )) &VIA_REG_STAT_ACTIVE )) -return 0 ; +spin_lock (&chip->reg_lock); -do { - count =inl (VIADEV_REG (viadev,OFFSET_CURR_COUNT )); -/* some mobos read 0 count */ -if ((count &0xffffff ) || ! viadev->running) -break ; - }while (--timeout); -if (! timeout) -snd_printd (KERN_ERR "zero position is read\n" ); - idx = count >>24 ; -if (idx >= viadev->tbl_entries) { + count =inl (VIADEV_REG (viadev,OFFSET_CURR_COUNT )); + status = viadev->in_interrupt; +if (!status) + status =inb (VIADEV_REG (viadev,OFFSET_STATUS )); + +if (!(status &VIA_REG_STAT_ACTIVE )) { + res =0 ; + goto unlock; + } +if (count &0xffffff ) { + idx = count >>24 ; +if (idx >= viadev->tbl_entries) {#ifdef POINTER_DEBUG -printk ("fail: invalid idx = %i/%i\n" , idx, viadev->tbl_entries); +printk ("fail: invalid idx = %i/%i\n" , idx, viadev->tbl_entries);#endif - res = viadev->lastpos; + res = viadev->lastpos; + }else { + count &=0xffffff ; + res =calc_linear_pos (viadev, idx, count); + } }else { - count &=0xffffff ; - res =calc_linear_pos (viadev, idx, count); - } + res = viadev->hwptr_done; +if (!viadev->in_interrupt) { +if (status &VIA_REG_STAT_EOL ) { + res =0 ; + }else +if (status &VIA_REG_STAT_FLAG ) { + res += viadev->fragsize; + } + } + } +unlock: + viadev->lastpos = res;spin_unlock (&chip->reg_lock);return bytes_to_frames (substream->runtime, res); } -/* * hw_params callback: * allocate the buffer and build up the buffer description table
@@ -2089,7 +2173,10 @@return err; } chip->port =pci_resource_start (pci,0 ); -if (request_irq (pci->irq, snd_via82xx_interrupt,SA_INTERRUPT |SA_SHIRQ , +if (request_irq (pci->irq, + chip_type ==TYPE_VIA8233 ? + snd_via8233_interrupt : snd_via686_interrupt, +SA_INTERRUPT |SA_SHIRQ , card->driver, (void *)chip)) {snd_printk ("unable to grab IRQ %d\n" , pci->irq);snd_via82xx_free (chip);
At some time ago,
sound/pci/via82xx.c line 412
Quoted 12 lines · Karsten Wiese
sound/pci/via82xx.c +2
-2@@ -401,8 +406,8 @@ };static struct pci_device_id snd_via82xx_ids[] = { - {0x1106 ,0x3058 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA686 , },/* 686A */ - {0x1106 ,0x3059 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA8233 , },/* VT8233 */ + {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_82C686_5 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA686 , },/* 686A */ + {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_8233_5 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA8233 , },/* VT8233 */ {0 , } };
I like to keep the numbers here to check the support PCI IDs easier from the driver code. I don't think changing this to PCI_* would improve the readability.
The only drawback to use the numbers is possible typos, though.
Quoted 15 lines
sound/pci/via82xx.c +14
-0/* +* Interrupt handler +*/ +static irqreturn_t snd_via8233_interrupt (int irq,void *dev_id,struct pt_regs *regs) +{ +via82xx_t *chip = dev_id; +unsigned int status; +unsigned int i; +unsigned int intr_mask; +irqreturn_t irqreturn =IRQ_NONE ; + + +/* check status for each stream */ + intr_mask = chip->intr_mask; +spin_lock (&chip->reg_lock);
sound/pci/via82xx.c line 687
Quoted 10 lines
sound/pci/via82xx.c +10
-0+ status =inl (VIAREG (chip,SGD_SHADOW )); +for (i =0 ; i < chip->num_devs; + i++, intr_mask >>=4 , status >>=4 ) { +viadev_t *viadev = &chip->devs[i]; +snd_pcm_substream_t *substream; +unsigned char c_status; +while (!(intr_mask &3 )) { + intr_mask >>=4 ; + status >>=4 ; + }
It'd be better to have a new field in viadev struct to indicate the shift bits rather than this loop. The loop looks ad-hoc.
Also, could you use tabs instead of spaces, as mentioned in CodingStyle?
Otherwise, it looks fine to me.
Thanks!
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
At Thu, 29 Sep 2005 12:44:59 +0200,
Quoted 2 lines · I wrote:
Otherwise, it looks fine to me.
Oh, also it'd be helpful to write irq handler like below:
irqreturn_t foo()
{
int handled = 0;
...
if (something)
handled = 1;
...
return IRQ_RETVAL(handled);
}This makes possible to compile even on 2.2/2.4 kernels without patches.
thanks,
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
Am Donnerstag, 29. September 2005 12:44 schrieb Takashi Iwai:
Quoted 13 lines
Review
Quoted 8 lines
static struct
pci_device_idsnd_via82xx_ids[] = {(quoted diff) +2
-2- { 0x1106, 0x3058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ - { 0x1106, 0x3059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ + { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ + { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ { 0, } };I like to keep the numbers here to check the support PCI IDs easier from the driver code. I don't think changing this to PCI_* would improve the readability.
The only drawback to use the numbers is possible typos, though.
hmm, symbolic names make it easier to grep/cscope the tree for occurrences of the IDs.
So in this patch the structures are initialized symbolically plus the hex-IDs are there as comment.
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8
-0+ /* check status for each stream */ + intr_mask = chip->intr_mask; + spin_lock(&chip->reg_lock); + status = inl(VIAREG(chip, SGD_SHADOW)); + for (i = 0; i < chip->num_devs; + i++, intr_mask >>= 4, status >>= 4) { + viadev_t *viadev = &chip->devs[i]; + snd_pcm_substream_t *substream;
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ unsigned char c_status; + while (!(intr_mask & 3)) { + intr_mask >>= 4; + status >>= 4; + }It'd be better to have a new field in viadev struct to indicate the shift bits rather than this loop. The loop looks ad-hoc.
Done.
Quoted 3 lines
Also, could you use tabs instead of spaces, as mentioned in CodingStyle?
KMail fooled me once again. Better now?
Interrupt return macro for 2.4 compatibility is also there.
Karsten
From: Karsten Wiese <[email protected]>
Reduce interrupt latency in sound/pci/via82xx.c
The change only affects the via823x kind of chips. Here the via8233_pcm_pointer_hw() function
(named snd_via8233_pcm_pointer() before)
needed to loop until a non zero position is red from the chip.
Measurements have shown that more than 200 loops are typically needed on an Athlon64.
As io-reads cost many cycles, those loops sum up huge. via8233_pcm_pointer_hw() runs either in interrupt or with interrupts disabled. So it introduces significant interrupt latency.
The patch introduces a calculated position value hwptr_done, that is updated by the interrupt routine when a period is completed. It is only used, if the 823x chip returns a zero position, which can't be interpreted reliably.
Further optimisation is applied on the 8233 chip's interrupt routine:
Only the SGD_SHADOW is read, as it contains all infos needed. We ommit ~5 more register reads that way.
sound/pci/via82xx.c +131 -40
@@ -41,6 +41,9 @@* device for applications. * - clean up the code, separate low-level initialization * routines for each chipset. +* +* Sep. 26, 2005 Karsten Wiese <[email protected]> +* - Optimize position calculation for the 823x chips. */ #include <sound/driver.h>
@@ -130,6 +133,7 @@/* common offsets */ #define VIA_REG_OFFSET_STATUS 0x00/* byte - channel status */ #define VIA_REG_STAT_ACTIVE 0x80/* RO */ +#define VIA8233_SHADOW_STAT_ACTIVE 0x08/* RO */ #define VIA_REG_STAT_PAUSED 0x40/* RO */ #define VIA_REG_STAT_TRIGGER_QUEUED 0x08/* RO */ #define VIA_REG_STAT_STOPPED 0x04/* RWC */
@@ -328,6 +332,9 @@unsigned int fragsize;unsigned int bufsize;unsigned int bufsize2; +int hwptr_done;/* processed frame position in the buffer */ +int in_interrupt; +int shadow_shift; };
@@ -393,8 +400,10 @@ };static struct pci_device_id snd_via82xx_ids[] = { - {0x1106 ,0x3058 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA686 , },/* 686A */ - {0x1106 ,0x3059 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA8233 , },/* VT8233 */ + {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_82C686_5 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA686 , },/* 686A */ +/* 0x1106 0x3058 */ + {PCI_VENDOR_ID_VIA ,PCI_DEVICE_ID_VIA_8233_5 ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 ,TYPE_CARD_VIA8233 , },/* VT8233 */ +/* 0x1106 0x3059 */ {0 , } };
@@ -548,7 +557,7 @@ {via82xx_t *chip = ac97->private_data;unsigned int xval; - + xval = !ac97->num ?VIA_REG_AC97_CODEC_ID_PRIMARY :VIA_REG_AC97_CODEC_ID_SECONDARY ; xval <<=VIA_REG_AC97_CODEC_ID_SHIFT ; xval |= reg <<VIA_REG_AC97_CMD_SHIFT ;
@@ -596,14 +605,15 @@outb (0x00 ,VIADEV_REG (viadev,OFFSET_TYPE ));/* for via686 */ // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); viadev->lastpos =0 ; + viadev->hwptr_done =0 ; }/* * Interrupt handler +* Used for 686 and 8233A */ - -static irqreturn_t snd_via82xx_interrupt (int irq,void *dev_id,struct pt_regs *regs) +static irqreturn_t snd_via686_interrupt (int irq,void *dev_id,struct pt_regs *regs) {via82xx_t *chip = dev_id;unsigned int status;
@@ -622,18 +632,81 @@for (i =0 ; i < chip->num_devs; i++) {viadev_t *viadev = &chip->devs[i];unsigned char c_status =inb (VIADEV_REG (viadev,OFFSET_STATUS )); - c_status &= (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG |VIA_REG_STAT_STOPPED ); -if (! c_status) +if (! (c_status & (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG |VIA_REG_STAT_STOPPED )))continue ;if (viadev->substream && viadev->running) { +/* +* Update hwptr_done based on 'period elapsed' +* interrupts. We'll use it, when the chip returns 0 +* for OFFSET_CURR_COUNT. +*/ +if (c_status &VIA_REG_STAT_EOL ) + viadev->hwptr_done =0 ; +else + viadev->hwptr_done += viadev->fragsize; + viadev->in_interrupt = c_status;spin_unlock (&chip->reg_lock);snd_pcm_period_elapsed (viadev->substream);spin_lock (&chip->reg_lock); + viadev->in_interrupt =0 ; }outb (c_status,VIADEV_REG (viadev,OFFSET_STATUS ));/* ack */ }spin_unlock (&chip->reg_lock); -return IRQ_HANDLED ; +return IRQ_RETVAL (IRQ_HANDLED ); +} + +/* +* Interrupt handler +*/ +static irqreturn_t snd_via8233_interrupt (int irq,void *dev_id,struct pt_regs *regs) +{ +via82xx_t *chip = dev_id; +unsigned int status; +unsigned int i; +irqreturn_t irqreturn =IRQ_NONE ; + + +/* check status for each stream */ +spin_lock (&chip->reg_lock); + status =inl (VIAREG (chip,SGD_SHADOW )); + +for (i =0 ; i < chip->num_devs; i++) { +viadev_t *viadev = &chip->devs[i]; +snd_pcm_substream_t *substream; +unsigned char c_status, shadow_status; + + shadow_status = (status >> viadev->shadow_shift) & (VIA8233_SHADOW_STAT_ACTIVE |VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG ); + c_status = shadow_status & (VIA_REG_STAT_EOL |VIA_REG_STAT_FLAG ); +if (!c_status) +continue ; + + substream = viadev->substream; +if (substream && viadev->running) { +/* +* Update hwptr_done based on 'period elapsed' +* interrupts. We'll use it, when the chip returns 0 +* for OFFSET_CURR_COUNT. +*/ +if (c_status &VIA_REG_STAT_EOL ) + viadev->hwptr_done =0 ; +else + viadev->hwptr_done += viadev->fragsize; + viadev->in_interrupt = c_status; +if (shadow_status &VIA8233_SHADOW_STAT_ACTIVE ) + viadev->in_interrupt |=VIA_REG_STAT_ACTIVE ; +spin_unlock (&chip->reg_lock); + +snd_pcm_period_elapsed (substream); + +spin_lock (&chip->reg_lock); + viadev->in_interrupt =0 ; + } +outb (c_status,VIADEV_REG (viadev,OFFSET_STATUS ));/* ack */ + irqreturn =IRQ_HANDLED ; + } +spin_unlock (&chip->reg_lock); +return IRQ_RETVAL (irqreturn); }/*
@@ -699,6 +772,8 @@ size = viadev->idx_table[idx].size; base = viadev->idx_table[idx].offset; res = base + size - count; +if (res >= viadev->bufsize) + res -= viadev->bufsize;/* check the validity of the calculated position */ if (size < count) {
@@ -728,9 +803,6 @@ } } } - viadev->lastpos = res;/* remember the last position */ -if (res >= viadev->bufsize) - res -= viadev->bufsize;return res; }
@@ -758,6 +830,7 @@else /* CURR_PTR holds the address + 8 */ idx = ((ptr - (unsigned int )viadev->table.addr) /8 -1 ) % viadev->tbl_entries; res =calc_linear_pos (viadev, idx, count); + viadev->lastpos = res;/* remember the last position */ spin_unlock (&chip->reg_lock);return bytes_to_frames (substream->runtime, res);
@@ -771,30 +844,44 @@via82xx_t *chip =snd_pcm_substream_chip (substream);viadev_t *viadev = (viadev_t *)substream->runtime->private_data;unsigned int idx, count, res; -int timeout =5000 ; +int status; snd_assert(viadev->tbl_entries, return 0); -if (!(inb (VIADEV_REG (viadev,OFFSET_STATUS )) &VIA_REG_STAT_ACTIVE )) -return 0 ; +spin_lock (&chip->reg_lock); -do { - count =inl (VIADEV_REG (viadev,OFFSET_CURR_COUNT )); -/* some mobos read 0 count */ -if ((count &0xffffff ) || ! viadev->running) -break ; - }while (--timeout); -if (! timeout) -snd_printd (KERN_ERR "zero position is read\n" ); - idx = count >>24 ; -if (idx >= viadev->tbl_entries) { + count =inl (VIADEV_REG (viadev,OFFSET_CURR_COUNT )); + status = viadev->in_interrupt; +if (!status) + status =inb (VIADEV_REG (viadev,OFFSET_STATUS )); + +if (!(status &VIA_REG_STAT_ACTIVE )) { + res =0 ; + goto unlock; + } +if (count &0xffffff ) { + idx = count >>24 ; +if (idx >= viadev->tbl_entries) {#ifdef POINTER_DEBUG -printk ("fail: invalid idx = %i/%i\n" , idx, viadev->tbl_entries); +printk ("fail: invalid idx = %i/%i\n" , idx, viadev->tbl_entries);#endif - res = viadev->lastpos; + res = viadev->lastpos; + }else { + count &=0xffffff ; + res =calc_linear_pos (viadev, idx, count); + } }else { - count &=0xffffff ; - res =calc_linear_pos (viadev, idx, count); - } + res = viadev->hwptr_done; +if (!viadev->in_interrupt) { +if (status &VIA_REG_STAT_EOL ) { + res =0 ; + }else +if (status &VIA_REG_STAT_FLAG ) { + res += viadev->fragsize; + } + } + } +unlock: + viadev->lastpos = res;spin_unlock (&chip->reg_lock);return bytes_to_frames (substream->runtime, res);
@@ -1239,9 +1326,10 @@ }; -static void init_viadev (via82xx_t *chip,int idx,unsigned int reg_offset,int direction) +static void init_viadev (via82xx_t *chip,int idx,unsigned int reg_offset,int shadow_pos,int direction) { chip->devs[idx].reg_offset = reg_offset; + chip->devs[idx].shadow_shift = shadow_pos *4 ; chip->devs[idx].direction = direction; chip->devs[idx].port = chip->port + reg_offset; }
@@ -1271,9 +1359,9 @@ chip->pcms[0 ] = pcm;/* set up playbacks */ for (i =0 ; i <4 ; i++) -init_viadev (chip, i,0x10 * i,0 ); +init_viadev (chip, i,0x10 * i, i,0 );/* capture */ -init_viadev (chip, chip->capture_devno,VIA_REG_CAPTURE_8233_STATUS ,1 ); +init_viadev (chip, chip->capture_devno,VIA_REG_CAPTURE_8233_STATUS ,6 ,1 );if ((err =snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV_SG ,snd_dma_pci_data (chip->pci),64 *1024 ,128 *1024 )) <0 )
@@ -1289,9 +1377,9 @@strcpy (pcm->name, chip->card->shortname); chip->pcms[1 ] = pcm;/* set up playback */ -init_viadev (chip, chip->multi_devno,VIA_REG_MULTPLAY_STATUS ,0 ); +init_viadev (chip, chip->multi_devno,VIA_REG_MULTPLAY_STATUS ,4 ,0 );/* set up capture */ -init_viadev (chip, chip->capture_devno +1 ,VIA_REG_CAPTURE_8233_STATUS +0x10 ,1 ); +init_viadev (chip, chip->capture_devno +1 ,VIA_REG_CAPTURE_8233_STATUS +0x10 ,7 ,1 );if ((err =snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV_SG ,snd_dma_pci_data (chip->pci),64 *1024 ,128 *1024 )) <0 )
@@ -1324,9 +1412,9 @@strcpy (pcm->name, chip->card->shortname); chip->pcms[0 ] = pcm;/* set up playback */ -init_viadev (chip, chip->multi_devno,VIA_REG_MULTPLAY_STATUS ,0 ); +init_viadev (chip, chip->multi_devno,VIA_REG_MULTPLAY_STATUS ,4 ,0 );/* capture */ -init_viadev (chip, chip->capture_devno,VIA_REG_CAPTURE_8233_STATUS ,1 ); +init_viadev (chip, chip->capture_devno,VIA_REG_CAPTURE_8233_STATUS ,6 ,1 );if ((err =snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV_SG ,snd_dma_pci_data (chip->pci),64 *1024 ,128 *1024 )) <0 )
@@ -1345,7 +1433,7 @@strcpy (pcm->name, chip->card->shortname); chip->pcms[1 ] = pcm;/* set up playback */ -init_viadev (chip, chip->playback_devno,0x30 ,0 ); +init_viadev (chip, chip->playback_devno,0x30 ,3 ,0 );if ((err =snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV_SG ,snd_dma_pci_data (chip->pci),64 *1024 ,128 *1024 )) <0 )
@@ -1375,8 +1463,8 @@ pcm->private_data = chip;strcpy (pcm->name, chip->card->shortname); chip->pcms[0 ] = pcm; -init_viadev (chip,0 ,VIA_REG_PLAYBACK_STATUS ,0 ); -init_viadev (chip,1 ,VIA_REG_CAPTURE_STATUS ,1 ); +init_viadev (chip,0 ,VIA_REG_PLAYBACK_STATUS ,0 ,0 ); +init_viadev (chip,1 ,VIA_REG_CAPTURE_STATUS ,0 ,1 );if ((err =snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV_SG ,snd_dma_pci_data (chip->pci),64 *1024 ,128 *1024 )) <0 )
@@ -2084,7 +2172,10 @@return err; } chip->port =pci_resource_start (pci,0 ); -if (request_irq (pci->irq, snd_via82xx_interrupt,SA_INTERRUPT |SA_SHIRQ , +if (request_irq (pci->irq, + chip_type ==TYPE_VIA8233 ? + snd_via8233_interrupt : snd_via686_interrupt, +SA_INTERRUPT |SA_SHIRQ , card->driver, (void *)chip)) {snd_printk ("unable to grab IRQ %d\n" , pci->irq);snd_via82xx_free (chip);
At Tue, 18 Oct 2005 14:42:10 +0200,
Quoted 6 lines · Karsten Wiese
Quoted 4 lines
Also, could you use tabs instead of spaces, as mentioned in CodingStyle?
KMail fooled me once again. Better now?
Yep.
Quoted 1 line
Interrupt return macro for 2.4 compatibility is also there.
Well....
Quoted 3 lines
sound/pci/via82xx.c +1
-1-static irqreturn_t snd_via82xx_interrupt (int irq,void *dev_id,struct pt_regs *regs) +static irqreturn_t snd_via686_interrupt (int irq,void *dev_id,struct pt_regs *regs) {
(snip)
sound/pci/via82xx.c line 656
Quoted 2 lines
sound/pci/via82xx.c +1
-1-return IRQ_HANDLED ; +return IRQ_RETVAL (IRQ_HANDLED );
This change is useless.
sound/pci/via82xx.c line 667
Quoted 11 lines
sound/pci/via82xx.c +11
-0+} + +/* +* Interrupt handler +*/ +static irqreturn_t snd_via8233_interrupt (int irq,void *dev_id,struct pt_regs *regs) +{ +via82xx_t *chip = dev_id; +unsigned int status; +unsigned int i; +irqreturn_t irqreturn =IRQ_NONE ;
It should be just an int:
int irqreturn = 0;
(snip)
sound/pci/via82xx.c line 706
Quoted 2 lines
sound/pci/via82xx.c +2
-0+outb (c_status,VIADEV_REG (viadev,OFFSET_STATUS ));/* ack */ + irqreturn =IRQ_HANDLED ;
And
irqreturn = 1;
Others look fine.
I'll commit your patch with these fixes.
Thanks!
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl