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

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 6.6 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
157
158
159
160
161#if 0
162
163static IRQHANDLER_INFO irqHandlers[MAX_IRQS][MAX_SHAREDIRQS] = {0};
164static ULONG nrIrqHandlers[MAX_IRQS] = {0};
165static ULONG eoiIrq[MAX_IRQS] = {0};
166
167//******************************************************************************
168//******************************************************************************
169int request_irq(unsigned int irq,
170 void (*handler)(int, void *, void *),
171 unsigned long x0, const char *x1, void *x2)
172{
173 int i;
174 if(irq > 0xF)
175 return 0;
176
177 for(i=0;i<MAX_SHAREDIRQS;i++) {
178 if(irqHandlers[irq][i].handler == 0) {
179 irqHandlers[irq][i].handler = handler;
180 irqHandlers[irq][i].x0 = x0;
181 irqHandlers[irq][i].x1 = (char *)x1;
182 irqHandlers[irq][i].x2 = x2;
183 nrIrqHandlers[irq]++;
184 if(OSS32_SetIrq(irq, (ULONG)&oss_process_interrupt) == FALSE) {
185 break;
186 }
187 return 0;
188 }
189 }
190 dprintf(("request_irq: Unable to register irq handler for irq %d\n", irq));
191 return 1;
192}
193//******************************************************************************
194//******************************************************************************
195void free_irq(unsigned int irq, void *userdata)
196{
197 int i;
198 for(i=0;i<MAX_SHAREDIRQS;i++) {
199 if(irqHandlers[irq][i].x2 == userdata) {
200 irqHandlers[irq][i].handler = 0;
201 irqHandlers[irq][i].x0 = 0;
202 irqHandlers[irq][i].x1 = 0;
203 irqHandlers[irq][i].x2 = 0;
204 if(--nrIrqHandlers[irq] == 0) {
205 OSS32_FreeIrq(irq);
206 }
207 break;
208 }
209 }
210}
211//******************************************************************************
212//******************************************************************************
213void eoi_irq(unsigned int irq)
214{
215 if(irq > 0xf) {
216 DebugInt3();
217 return;
218 }
219 eoiIrq[irq]++;
220}
221//******************************************************************************
222//******************************************************************************
223BOOL _cdecl oss_process_interrupt(int irq)
224{
225// BOOL rc;
226 int i;
227 for(i=0;i<MAX_SHAREDIRQS;i++) {
228 if(irqHandlers[irq][i].handler != 0) {
229 irqHandlers[irq][i].handler(irq, irqHandlers[irq][i].x2, 0);
230
231 if( eoiIrq[irq] > 0 ) {
232 eoiIrq[irq] = 0; return TRUE;
233 }
234/*
235 rc = (eoiIrq[irq] > 0);
236 if(rc) {
237 eoiIrq[irq] = 0;
238 return rc;
239 }
240*/
241 }
242 }
243 return FALSE;
244}
245//******************************************************************************
246//******************************************************************************
247
248#endif
249
Note: See TracBrowser for help on using the repository browser.