source: GPL/trunk/lib32/irq.c

Last change on this file was 772, checked in by David Azarewicz, 5 months ago

Merge in changes from 6.6-LTS branch.
Fixed additional 25+ problems.

File size: 8.8 KB
RevLine 
[32]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//******************************************************************************
[63]43
[604]44static IRQ_SLOT arSlots[MAX_IRQ_SLOTS] = { 0 };
45static ULONG eoiIrq[255] = {0};
[63]46
47
48//******************************************************************************
49//******************************************************************************
50static IRQ_SLOT *FindSlot(unsigned irq)
51{
[604]52 IRQ_SLOT *pSlot;
[63]53
[604]54 for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
55 {
56 if( pSlot->irqNo == irq ) return pSlot;
57 }
[63]58
[604]59 return NULL;
[63]60}
61
62
63//******************************************************************************
64//******************************************************************************
65
[314]66int request_irq(unsigned irq, irq_handler_t handler,
[604]67 unsigned long ulSharedFlag, const char *pchName, void *pUserData)
[32]68{
[604]69 IRQ_SLOT *pSlot = FindSlot(irq & 0xff);
70 unsigned u, uSlotNo = (unsigned)-1;
71 ULONG hRes;
[32]72
[604]73 rprintf(("request_irq: irq %d", irq & 0xff ));
74 if ( !pSlot )
75 {
76 // find empty slot
77 for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ )
78 {
79 if( arSlots[uSlotNo].flHandlers == 0 )
80 {
81 pSlot = &arSlots[uSlotNo];
82 break;
83 }
84 }
85 }
[32]86
[604]87 if ( pSlot )
88 {
89 hRes = 0;
90 if (RMRequestIRQ(irq, (ulSharedFlag & SA_SHIRQ) != 0, &hRes) == FALSE)
91 {
92 rprintf(("RMRequestIRQ failed for irq %d", irq));
93 return 1;
94 }
95 pSlot->irqNo = irq & 0xff;
96 pSlot->hRes = hRes;
[32]97
[604]98 for ( u = 0; u < MAX_SHAREDIRQS; u++ )
99 {
100 if ( pSlot->irqHandlers[u].handler == NULL )
101 {
102 pSlot->irqHandlers[u].handler = handler;
103 pSlot->irqHandlers[u].x0 = ulSharedFlag;
104 pSlot->irqHandlers[u].x1 = (char *)pchName;
105 pSlot->irqHandlers[u].x2 = pUserData;
[76]106
[604]107 if( pSlot->flHandlers != 0 || ALSA_SetIrq( irq & 0xff, uSlotNo, (ulSharedFlag & SA_SHIRQ) != 0) )
108 {
109 pSlot->flHandlers |= 1 << u;
110 return 0;
111 }
[63]112
[604]113 break;
114 }
115 }
116 }
[63]117
[604]118 rprintf(("request_irq: Unable to register irq handler for irq %d", irq & 0xff ));
119 return 1;
[32]120}
[63]121
122
[32]123//******************************************************************************
124//******************************************************************************
125void free_irq(unsigned int irq, void *userdata)
126{
[604]127 unsigned u;
128 IRQ_SLOT *pSlot;
[32]129
[604]130 if( (pSlot = FindSlot(irq&0xff)) != NULL ) {
131 for( u = 0; u < MAX_SHAREDIRQS; u++ ) {
132 if( pSlot->irqHandlers[u].x2 == userdata ) {
133 pSlot->flHandlers &= ~(1 << u);
134 if( pSlot->flHandlers == 0 ) {
135 rprintf(("free_irq: irq %d", irq & 0xff ));
136 ALSA_FreeIrq(pSlot->irqNo);
137 pSlot->irqNo = 0;
138 RMDeallocateIRQ(pSlot->hRes);
139 pSlot->hRes = 0;
140 // pSlot->fEOI = 0;
141 }
[63]142
[604]143 pSlot->irqHandlers[u].handler = NULL;
144 pSlot->irqHandlers[u].x0 = 0;
145 pSlot->irqHandlers[u].x1 = NULL;
146 pSlot->irqHandlers[u].x2 = NULL;
[63]147
[604]148 return;
[63]149
[604]150 }
151 }
152 }
[32]153}
[63]154
155
[32]156//******************************************************************************
157//******************************************************************************
158void eoi_irq(unsigned int irq)
159{
[604]160 /*(void)irq; */
161 /*
162 IRQ_SLOT *pSlot = FindSlot(irq);
[63]163
[604]164 if( pSlot ) pSlot->fEOI = 1;
165 */
166 eoiIrq[irq & 0xff]++;
[32]167}
[63]168
169
[32]170//******************************************************************************
171//******************************************************************************
[63]172BOOL process_interrupt(ULONG ulSlotNo, ULONG *pulIrq)
[32]173{
[604]174 unsigned u;
175 int rc;
176 IRQ_SLOT *pSlot;
[32]177
[604]178 //dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
[32]179
[604]180 if( ulSlotNo < MAX_IRQ_SLOTS )
181 {
182 pSlot = &arSlots[ulSlotNo];
[63]183
[604]184 for( u = 0; u < MAX_SHAREDIRQS; u++ )
185 {
186 if(pSlot && pSlot->irqHandlers[u].handler )
187 {
188 fInInterrupt = TRUE;
[316]189#if 0
[604]190 rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
191 pSlot->irqHandlers[u].x2, 0);
[316]192#else
[604]193 rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
194 pSlot->irqHandlers[u].x2);
[316]195#endif
[437]196
[604]197 // HDA Hardware generates controller interrupts and stream interrupts
198 // the uniaud16 driver only cares about stream interrupts.
199 // azx_interrupt in alsa-kernel/pci/hda/hda_intel.c will return rc 2 if
200 // the interrupt is from the controller. There is no need to call uniaud16
201 // for these interrupts
202 if ( rc == 2 ) {
203 fInInterrupt = FALSE;
204 *pulIrq = pSlot->irqNo;
205 eoiIrq[pSlot->irqNo] = 0;
206 return TRUE;
207 }
[437]208
[604]209 if (rc == 1) eoi_irq(pSlot->irqNo);
210 rc = (eoiIrq[pSlot->irqNo] > 0);
211 fInInterrupt = FALSE;
[63]212
[604]213 if( rc /*== 1 || pSlot->fEOI*/ ) {
[63]214
[604]215 *pulIrq = pSlot->irqNo;
216 // pSlot->fEOI = 0;
[63]217
[604]218 //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
219 OSS32_ProcessIRQ();
220 //dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
221 eoiIrq[pSlot->irqNo] = 0;
222 return TRUE;
223 }
224 }
225 }
226 }
227 //dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
[63]228
[604]229 return FALSE;
[32]230}
[63]231
232
[32]233//******************************************************************************
234//******************************************************************************
235int in_interrupt()
236{
[604]237 return fInInterrupt;
[32]238}
[63]239
240
[32]241//******************************************************************************
242//******************************************************************************
243void disable_irq(int irq)
244{
[604]245 dprintf(("disable_irq %d NOT implemented", irq));
[32]246}
[63]247
[32]248//******************************************************************************
249//******************************************************************************
[63]250
[772]251/*
252 * Device resource management aware IRQ request/free implementation.
253 */
254struct irq_devres {
255 unsigned int irq;
256 void *dev_id;
257};
258
259static void devm_irq_release(struct device *dev, void *res)
260{
261 struct irq_devres *this = res;
262
263 free_irq(this->irq, this->dev_id);
264}
265
266/**
267 * devm_request_threaded_irq - allocate an interrupt line for a managed device
268 * @dev: device to request interrupt for
269 * @irq: Interrupt line to allocate
270 * @handler: Function to be called when the IRQ occurs
271 * @thread_fn: function to be called in a threaded interrupt context. NULL
272 * for devices which handle everything in @handler
273 * @irqflags: Interrupt type flags
274 * @devname: An ascii name for the claiming device, dev_name(dev) if NULL
275 * @dev_id: A cookie passed back to the handler function
276 *
277 * Except for the extra @dev argument, this function takes the
278 * same arguments and performs the same function as
279 * request_threaded_irq(). IRQs requested with this function will be
280 * automatically freed on driver detach.
281 *
282 * If an IRQ allocated with this function needs to be freed
283 * separately, devm_free_irq() must be used.
284 */
285int devm_request_threaded_irq(struct device *dev, unsigned int irq,
286 irq_handler_t handler, irq_handler_t thread_fn,
287 unsigned long irqflags, const char *devname,
288 void *dev_id)
289{
290 struct irq_devres *dr;
291 int rc;
292
293 dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
294 GFP_KERNEL);
295 if (!dr)
296 return -ENOMEM;
297
298 if (!devname)
299 devname = dev_name(dev);
300
301 rc = request_irq(irq, handler, irqflags, devname,
302 dev_id);
303 if (rc) {
304 devres_free(dr);
305 return rc;
306 }
307
308 dr->irq = irq;
309 dr->dev_id = dev_id;
310 devres_add(dev, dr);
311
312 return 0;
313}
Note: See TracBrowser for help on using the repository browser.