source: GPL/branches/uniaud32-2.1.x/lib32/irq.c@ 573

Last change on this file since 573 was 573, checked in by David Azarewicz, 13 years ago

fixed build problems, changed version number

File size: 6.7 KB
Line 
1/* $Id: irq.c,v 1.1.1.1 2003/07/02 13:57:02 eleph Exp $ */
2/*
3 * OS/2 implementation of Linux irq kernel services
4 *
5 * (C) 2000-2002 InnoTek Systemberatung GmbH
6 * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * USA.
22 *
23 */
24
25#include "linux.h"
26#include <linux/init.h>
27#include <linux/poll.h>
28#include <asm/uaccess.h>
29#include <asm/hardirq.h>
30
31#define LINUX
32#include <ossidc.h>
33#include <ossidc32.h>
34#include <osspci.h>
35#include <dbgos2.h>
36#include "irqos2.h"
37
38
39BOOL fInInterrupt = FALSE;
40
41//******************************************************************************
42//******************************************************************************
43
44static IRQ_SLOT arSlots[MAX_IRQ_SLOTS] = { 0 };
45static ULONG eoiIrq[255] = {0};
46
47
48//******************************************************************************
49//******************************************************************************
50static IRQ_SLOT *FindSlot(unsigned irq)
51{
52 IRQ_SLOT *pSlot;
53
54 for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
55 {
56 if( pSlot->irqNo == irq ) return pSlot;
57 }
58
59 return NULL;
60}
61
62
63//******************************************************************************
64//******************************************************************************
65
66int request_irq(unsigned irq, irq_handler_t handler,
67 unsigned long ulSharedFlag, const char *pchName, void *pUserData)
68{
69 IRQ_SLOT *pSlot = FindSlot(irq & 0xff);
70 unsigned u, uSlotNo = (unsigned)-1;
71 ULONG hRes;
72
73 rprintf(("request_irq: irq %d", irq & 0xff ));
74 if ( !pSlot ) {
75 // find empty slot
76 for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ ) {
77 if( arSlots[uSlotNo].flHandlers == 0 ) {
78 pSlot = &arSlots[uSlotNo];
79 break;
80 }
81 }
82 }
83
84 if ( pSlot ) {
85 hRes = 0;
86 if (RMRequestIRQ(irq, (ulSharedFlag & SA_SHIRQ) != 0, &hRes) == FALSE) {
87 rprintf(("RMRequestIRQ failed for irq %d", irq));
88 return 1;
89 }
90 pSlot->irqNo = irq & 0xff;
91 pSlot->hRes = hRes;
92
93 for ( u = 0; u < MAX_SHAREDIRQS; u++ ) {
94 if ( pSlot->irqHandlers[u].handler == NULL ) {
95 pSlot->irqHandlers[u].handler = handler;
96 pSlot->irqHandlers[u].x0 = ulSharedFlag;
97 pSlot->irqHandlers[u].x1 = (char *)pchName;
98 pSlot->irqHandlers[u].x2 = pUserData;
99
100 if( pSlot->flHandlers != 0 || ALSA_SetIrq( irq & 0xff, uSlotNo, (ulSharedFlag & SA_SHIRQ) != 0) ) {
101 pSlot->flHandlers |= 1 << u;
102 return 0;
103 }
104
105 break;
106 }
107 }
108 }
109
110 rprintf(("request_irq: Unable to register irq handler for irq %d", irq & 0xff ));
111 return 1;
112}
113
114
115//******************************************************************************
116//******************************************************************************
117void free_irq(unsigned int irq, void *userdata)
118{
119 unsigned u;
120 IRQ_SLOT *pSlot;
121
122 if( (pSlot = FindSlot(irq&0xff)) != NULL ) {
123 for( u = 0; u < MAX_SHAREDIRQS; u++ ) {
124 if( pSlot->irqHandlers[u].x2 == userdata ) {
125 pSlot->flHandlers &= ~(1 << u);
126 if( pSlot->flHandlers == 0 ) {
127 rprintf(("free_irq: irq %d", irq & 0xff ));
128 ALSA_FreeIrq(pSlot->irqNo);
129 pSlot->irqNo = 0;
130 RMDeallocateIRQ(pSlot->hRes);
131 pSlot->hRes = 0;
132 // pSlot->fEOI = 0;
133 }
134
135 pSlot->irqHandlers[u].handler = NULL;
136 pSlot->irqHandlers[u].x0 = 0;
137 pSlot->irqHandlers[u].x1 = NULL;
138 pSlot->irqHandlers[u].x2 = NULL;
139
140 return;
141
142 }
143 }
144 }
145}
146
147
148//******************************************************************************
149//******************************************************************************
150void eoi_irq(unsigned int irq)
151{
152 /*(void)irq; */
153 /*
154 IRQ_SLOT *pSlot = FindSlot(irq);
155
156 if( pSlot ) pSlot->fEOI = 1;
157 */
158 eoiIrq[irq & 0xff]++;
159}
160
161
162//******************************************************************************
163//******************************************************************************
164BOOL process_interrupt(ULONG ulSlotNo, ULONG *pulIrq)
165{
166 unsigned u;
167 int rc;
168 IRQ_SLOT *pSlot;
169
170 //dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
171
172 if( ulSlotNo < MAX_IRQ_SLOTS )
173 {
174 pSlot = &arSlots[ulSlotNo];
175
176 for( u = 0; u < MAX_SHAREDIRQS; u++ )
177 {
178 if(pSlot && pSlot->irqHandlers[u].handler )
179 {
180 fInInterrupt = TRUE;
181#if 0
182 rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
183 pSlot->irqHandlers[u].x2, 0);
184#else
185 rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
186 pSlot->irqHandlers[u].x2);
187#endif
188
189 // HDA Hardware generates controller interrupts and stream interrupts
190 // the uniaud16 driver only cares about stream interrupts.
191 // azx_interrupt in alsa-kernel/pci/hda/hda_intel.c will return rc 2 if
192 // the interrupt is from the controller. There is no need to call uniaud16
193 // for these interrupts
194 if ( rc == 2 ) {
195 fInInterrupt = FALSE;
196 *pulIrq = pSlot->irqNo;
197 eoiIrq[pSlot->irqNo] = 0;
198 return TRUE;
199 }
200
201 if (rc == 1) eoi_irq(pSlot->irqNo);
202 rc = (eoiIrq[pSlot->irqNo] > 0);
203 fInInterrupt = FALSE;
204
205 if( rc /*== 1 || pSlot->fEOI*/ ) {
206
207 *pulIrq = pSlot->irqNo;
208 // pSlot->fEOI = 0;
209
210 //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
211 OSS32_ProcessIRQ();
212 //dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
213 eoiIrq[pSlot->irqNo] = 0;
214 return TRUE;
215 }
216 }
217 }
218 }
219 //dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
220
221 return FALSE;
222}
223
224
225//******************************************************************************
226//******************************************************************************
227int in_interrupt()
228{
229 return fInInterrupt;
230}
231
232
233//******************************************************************************
234//******************************************************************************
235void disable_irq(int irq)
236{
237 dprintf(("disable_irq %d NOT implemented", irq));
238}
239
240//******************************************************************************
241//******************************************************************************
242
Note: See TracBrowser for help on using the repository browser.