source: cmedia/trunk/Lib32/irq.c@ 559

Last change on this file since 559 was 554, checked in by rudi, 14 years ago

Update to version 0.2.3

File size: 4.2 KB
Line 
1/* $Id: irq.c,v 1.1 2000/04/23 14:55:37 ktk Exp $ */
2
3//******************************************************************************
4// OS/2 implementation of Linux irq kernel services
5//
6// Copyright 2000 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#define INCL_NOPMAPI
25#define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
26#include <os2.h>
27#include <ossidc.h>
28#include "irqos2.h"
29
30unsigned long volatile jiffies = 0;
31
32static IRQ_SLOT arSlots[MAX_SLOTS] = { 0 };
33
34
35//******************************************************************************
36//******************************************************************************
37
38static IRQ_SLOT *FindSlot(unsigned irq)
39{
40 IRQ_SLOT *pSlot;
41
42 for( pSlot = arSlots; pSlot != &arSlots[MAX_SLOTS]; pSlot++ )
43 {
44 if( pSlot->irqNo == irq ) return pSlot;
45 }
46
47 return NULL;
48}
49
50
51//******************************************************************************
52//******************************************************************************
53
54int request_irq(unsigned int irq,
55 void (*handler)(int, void *, void *),
56 unsigned long x0, const char *x1, void *x2)
57{
58 unsigned u;
59 IRQ_SLOT *pSlot = FindSlot(irq);
60
61 if( !pSlot ) pSlot = FindSlot(0);
62
63 if( pSlot )
64 {
65 for( u = 0; u < MAX_SHAREDIRQS; u++ )
66 {
67 if( pSlot->irqHandlers[u].handler == NULL )
68 {
69 pSlot->irqNo = irq;
70
71 pSlot->irqHandlers[u].handler = handler;
72 pSlot->irqHandlers[u].x0 = x0;
73 pSlot->irqHandlers[u].x1 = (char *)x1;
74 pSlot->irqHandlers[u].x2 = x2;
75
76 if( pSlot->flHandlers != 0 || OSS32_SetIrq(irq, (ULONG)pSlot) )
77 {
78 pSlot->flHandlers |= 1 << u;
79 return 0;
80 }
81
82 break;
83 }
84 }
85 }
86
87 dprintf(("request_irq: Unable to register irq handler for irq %d\n", irq));
88 return 1;
89}
90
91
92//******************************************************************************
93//******************************************************************************
94void free_irq(unsigned int irq, void *userdata)
95{
96 unsigned u;
97 IRQ_SLOT *pSlot = FindSlot(irq);
98
99 if( pSlot )
100 {
101 for( u = 0; u < MAX_SHAREDIRQS; u++ )
102 {
103 if( pSlot->irqHandlers[u].x2 == userdata )
104 {
105 pSlot->flHandlers &= ~(1 << u);
106 if( pSlot->flHandlers == 0 )
107 {
108 OSS32_FreeIrq(pSlot->irqNo);
109 pSlot->irqNo = 0;
110 pSlot->fEOI = 0;
111 }
112
113 pSlot->irqHandlers[u].handler = NULL;
114 pSlot->irqHandlers[u].x0 = 0;
115 pSlot->irqHandlers[u].x1 = NULL;
116 pSlot->irqHandlers[u].x2 = NULL;
117
118 return;
119 }
120 }
121 }
122}
123
124
125//******************************************************************************
126//******************************************************************************
127void eoi_irq(unsigned int irq)
128{
129 IRQ_SLOT *pSlot = FindSlot(irq);
130
131 if( pSlot ) pSlot->fEOI = 1;
132}
133
134
135//******************************************************************************
136//******************************************************************************
137BOOL _cdecl oss_process_interrupt(int irq, unsigned long param)
138{
139 unsigned u;
140 IRQ_SLOT *pSlot = (IRQ_SLOT *)param;
141
142 (void)irq;
143
144 for( u = 0; u < MAX_SHAREDIRQS; u++ )
145 {
146 if( pSlot->irqHandlers[u].handler )
147 {
148 pSlot->irqHandlers[u].handler(pSlot->irqNo, pSlot->irqHandlers[u].x2, 0);
149 if( pSlot->fEOI ) { pSlot->fEOI = 0; return TRUE; }
150 }
151 }
152
153 return FALSE;
154}
155
156
Note: See TracBrowser for help on using the repository browser.