- Fixes to OS wrappers to allow extra mask parameter for PCCard status
[AROS.git] / workbench / devs / networks / etherlink3 / aros_device.c
blobf71b479a185adcaf3dc8fdcb3cf6b4b268992650
1 /*
3 Copyright (C) 2011 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA.
23 #include <exec/types.h>
24 #include <exec/resident.h>
25 #include <aros/asmcall.h>
26 #include <aros/libcall.h>
27 #include "initializers.h"
29 #include "device.h"
31 #include "device_protos.h"
34 /* Private prototypes */
36 AROS_LD2(struct DevBase *, AROSDevInit,
37 AROS_LDA(struct DevBase *, dev_base, D0),
38 AROS_LDA(struct DevBase *, seg_list, A0),
39 struct DevBase *, base, 0, S2);
40 AROS_LD3(BYTE, AROSDevOpen,
41 AROS_LDA(struct IOSana2Req *, request, A1),
42 AROS_LDA(LONG, unit_num, D0),
43 AROS_LDA(ULONG, flags, D1),
44 struct DevBase *, base, 1, S2);
45 AROS_LD1(APTR, AROSDevClose,
46 AROS_LDA(struct IOSana2Req *, request, A1),
47 struct DevBase *, base, 2, S2);
48 AROS_LD0(APTR, AROSDevExpunge,
49 struct DevBase *, base, 3, S2);
50 AROS_LD0(APTR, AROSDevReserved,
51 struct DevBase *, base, 4, S2);
52 AROS_LD1(VOID, AROSDevBeginIO,
53 AROS_LDA(struct IOSana2Req *, request, A1),
54 struct DevBase *, base, 5, S2);
55 AROS_LD1(VOID, AROSDevAbortIO,
56 AROS_LDA(struct IOSana2Req *, request, A1),
57 struct DevBase *, base, 6, S2);
58 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size);
59 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size);
60 static UBYTE *DMATXFunction(struct IOSana2Req *request);
61 AROS_UFP3(BOOL, AROSInt,
62 AROS_UFPA(APTR *, int_data, A1),
63 AROS_UFPA(APTR, this_code, A5),
64 AROS_UFPA(UBYTE, mask, D0));
66 extern const APTR init_data;
67 extern const struct Resident rom_tag;
68 extern const TEXT device_name[];
69 extern const TEXT version_string[];
72 static const APTR vectors[] =
74 (APTR)AROS_SLIB_ENTRY(AROSDevOpen, S2, 1),
75 (APTR)AROS_SLIB_ENTRY(AROSDevClose, S2, 2),
76 (APTR)AROS_SLIB_ENTRY(AROSDevExpunge, S2, 3),
77 (APTR)AROS_SLIB_ENTRY(AROSDevReserved, S2, 4),
78 (APTR)AROS_SLIB_ENTRY(AROSDevBeginIO, S2, 5),
79 (APTR)AROS_SLIB_ENTRY(AROSDevAbortIO, S2, 6),
80 (APTR)-1
84 static const APTR init_table[] =
86 (APTR)sizeof(struct DevBase),
87 (APTR)vectors,
88 (APTR)&init_data,
89 (APTR)AROS_SLIB_ENTRY(AROSDevInit, S2, 0),
93 const struct Resident aros_rom_tag =
95 RTC_MATCHWORD,
96 (struct Resident *)&aros_rom_tag,
97 (APTR)(&rom_tag + 1),
98 RTF_AUTOINIT,
99 VERSION,
100 NT_DEVICE,
102 (TEXT *)device_name,
103 (TEXT *)version_string,
104 (APTR)init_table
109 /****i* etherlink3.device/AROSDevInit **************************************
111 * NAME
112 * AROSDevInit
114 ****************************************************************************
118 AROS_LH2(struct DevBase *, AROSDevInit,
119 AROS_LHA(struct DevBase *, dev_base, D0),
120 AROS_LHA(struct DevBase *, seg_list, A0),
121 struct DevBase *, base, 0, S2)
123 AROS_LIBFUNC_INIT
125 base = DevInit(dev_base, seg_list, base);
127 if(base != NULL)
128 base->wrapper_int_code = (APTR)AROSInt;
129 return base;
131 AROS_LIBFUNC_EXIT
136 /****i* etherlink3.device/AROSDevOpen **************************************
138 * NAME
139 * AROSDevOpen
141 ****************************************************************************
145 AROS_LH3(BYTE, AROSDevOpen,
146 AROS_LHA(struct IOSana2Req *, request, A1),
147 AROS_LHA(LONG, unit_num, D0),
148 AROS_LHA(ULONG, flags, D1),
149 struct DevBase *, base, 1, S2)
151 AROS_LIBFUNC_INIT
153 struct Opener *opener;
154 BYTE error;
156 error = DevOpen(request, unit_num, flags, base);
158 /* Set up wrapper hooks to hide register-call functions */
160 if(error == 0)
162 opener = request->ios2_BufferManagement;
163 opener->real_rx_function = opener->rx_function;
164 opener->real_tx_function = opener->tx_function;
165 opener->rx_function = (APTR)RXFunction;
166 opener->tx_function = (APTR)TXFunction;
167 if(opener->dma_tx_function != NULL)
169 opener->real_dma_tx_function = opener->dma_tx_function;
170 opener->dma_tx_function = (APTR)DMATXFunction;
174 return error;
176 AROS_LIBFUNC_EXIT
181 /****i* etherlink3.device/AROSDevClose *************************************
183 * NAME
184 * AROSDevClose
186 ****************************************************************************
190 AROS_LH1(APTR, AROSDevClose,
191 AROS_LHA(struct IOSana2Req *, request, A1),
192 struct DevBase *, base, 2, S2)
194 AROS_LIBFUNC_INIT
196 return DevClose(request, base);
198 AROS_LIBFUNC_EXIT
203 /****i* etherlink3.device/AROSDevExpunge ***********************************
205 * NAME
206 * AROSDevExpunge
208 ****************************************************************************
212 AROS_LH0(APTR, AROSDevExpunge,
213 struct DevBase *, base, 3, S2)
215 AROS_LIBFUNC_INIT
217 return DevExpunge(base);
219 AROS_LIBFUNC_EXIT
224 /****i* etherlink3.device/AROSDevReserved **********************************
226 * NAME
227 * AROSDevReserved
229 ****************************************************************************
233 AROS_LH0(APTR, AROSDevReserved,
234 struct DevBase *, base, 4, S2)
236 AROS_LIBFUNC_INIT
238 return DevReserved(base);
240 AROS_LIBFUNC_EXIT
245 /****i* etherlink3.device/AROSDevBeginIO ***********************************
247 * NAME
248 * AROSDevBeginIO
250 ****************************************************************************
254 AROS_LH1(VOID, AROSDevBeginIO,
255 AROS_LHA(struct IOSana2Req *, request, A1),
256 struct DevBase *, base, 5, S2)
258 AROS_LIBFUNC_INIT
260 /* Replace caller's cookie with our own */
262 switch(request->ios2_Req.io_Command)
264 case CMD_READ:
265 case CMD_WRITE:
266 case S2_MULTICAST:
267 case S2_BROADCAST:
268 case S2_READORPHAN:
269 request->ios2_StatData = request->ios2_Data;
270 request->ios2_Data = request;
273 DevBeginIO(request, base);
275 AROS_LIBFUNC_EXIT
280 /****i* etherlink3.device/AROSDevAbortIO ***********************************
282 * NAME
283 * AROSDevAbortIO -- Try to stop a request.
285 ****************************************************************************
289 AROS_LH1(VOID, AROSDevAbortIO,
290 AROS_LHA(struct IOSana2Req *, request, A1),
291 struct DevBase *, base, 6, S2)
293 AROS_LIBFUNC_INIT
295 DevAbortIO(request, base);
297 AROS_LIBFUNC_EXIT
302 /****i* etherlink3.device/RXFunction ***************************************
304 * NAME
305 * RXFunction
307 ****************************************************************************
311 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
313 struct DevBase *base;
314 struct Opener *opener;
315 APTR cookie;
317 base = (struct DevBase *)request->ios2_Req.io_Device;
318 opener = request->ios2_BufferManagement;
319 cookie = request->ios2_StatData;
320 request->ios2_Data = cookie;
322 return AROS_UFC3(BOOL, (APTR)opener->real_rx_function,
323 AROS_UFCA(APTR, cookie, A0),
324 AROS_UFCA(APTR, buffer, A1),
325 AROS_UFCA(ULONG, size, D0));
330 /****i* etherlink3.device/TXFunction ***************************************
332 * NAME
333 * TXFunction
335 ****************************************************************************
339 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
341 struct DevBase *base;
342 struct Opener *opener;
343 APTR cookie;
345 base = (struct DevBase *)request->ios2_Req.io_Device;
346 opener = request->ios2_BufferManagement;
347 cookie = request->ios2_StatData;
348 request->ios2_Data = cookie;
350 return AROS_UFC3(BOOL, (APTR)opener->real_tx_function,
351 AROS_UFCA(APTR, buffer, A0),
352 AROS_UFCA(APTR, cookie, A1),
353 AROS_UFCA(ULONG, size, D0));
358 /****i* etherlink3.device/DMATXFunction ************************************
360 * NAME
361 * DMATXFunction
363 ****************************************************************************
367 static UBYTE *DMATXFunction(struct IOSana2Req *request)
369 struct DevBase *base;
370 struct Opener *opener;
371 APTR cookie;
373 base = (struct DevBase *)request->ios2_Req.io_Device;
374 opener = request->ios2_BufferManagement;
375 cookie = request->ios2_StatData;
376 request->ios2_Data = cookie;
378 return AROS_UFC1(UBYTE *, (APTR)opener->real_dma_tx_function,
379 AROS_UFCA(APTR, cookie, A0));
384 /****i* etherlink3.device/AROSInt ******************************************
386 * NAME
387 * AROSInt
389 ****************************************************************************
393 AROS_UFH3(BOOL, AROSInt,
394 AROS_UFHA(APTR *, int_data, A1),
395 AROS_UFHA(APTR, this_code, A5),
396 AROS_UFHA(UBYTE, mask, D0))
398 AROS_USERFUNC_INIT
400 BOOL (*int_code)(APTR, APTR, UBYTE);
402 int_code = int_data[0];
403 return int_code(int_data[1], int_code, mask);
405 AROS_USERFUNC_EXIT