Fixed my network drivers to work with ABIv1 (apart from prism2.device, which
[AROS.git] / workbench / devs / networks / realtek8180 / aros_device.c
blob12d821c92fd9bc89bcbe40e5d08bf176eaf11fb7
1 /*
3 Copyright (C) 2011,2012 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_UFP3(struct DevBase *, AROSDevInit,
37 AROS_UFPA(struct DevBase *, dev_base, D0),
38 AROS_UFPA(APTR, seg_list, A0),
39 AROS_UFPA(struct DevBase *, base, A6));
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)AROSDevInit,
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* realtek8180.device/AROSDevInit *************************************
111 * NAME
112 * AROSDevInit
114 ****************************************************************************
118 AROS_UFH3(struct DevBase *, AROSDevInit,
119 AROS_UFHA(struct DevBase *, dev_base, D0),
120 AROS_UFHA(APTR, seg_list, A0),
121 AROS_UFHA(struct DevBase *, base, A6))
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* realtek8180.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* realtek8180.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* realtek8180.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* realtek8180.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* realtek8180.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* realtek8180.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* realtek8180.device/RXFunction **************************************
304 * NAME
305 * RXFunction
307 ****************************************************************************
311 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
313 struct Opener *opener;
314 APTR cookie;
316 opener = request->ios2_BufferManagement;
317 cookie = request->ios2_StatData;
318 request->ios2_Data = cookie;
320 return AROS_UFC3(BOOL, (APTR)opener->real_rx_function,
321 AROS_UFCA(APTR, cookie, A0),
322 AROS_UFCA(APTR, buffer, A1),
323 AROS_UFCA(ULONG, size, D0));
328 /****i* realtek8180.device/TXFunction **************************************
330 * NAME
331 * TXFunction
333 ****************************************************************************
337 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
339 struct Opener *opener;
340 APTR cookie;
342 opener = request->ios2_BufferManagement;
343 cookie = request->ios2_StatData;
344 request->ios2_Data = cookie;
346 return AROS_UFC3(BOOL, (APTR)opener->real_tx_function,
347 AROS_UFCA(APTR, buffer, A0),
348 AROS_UFCA(APTR, cookie, A1),
349 AROS_UFCA(ULONG, size, D0));
354 /****i* realtek8180.device/DMATXFunction ***********************************
356 * NAME
357 * DMATXFunction
359 ****************************************************************************
363 static UBYTE *DMATXFunction(struct IOSana2Req *request)
365 struct Opener *opener;
366 APTR cookie;
368 opener = request->ios2_BufferManagement;
369 cookie = request->ios2_StatData;
370 request->ios2_Data = cookie;
372 return AROS_UFC1(UBYTE *, (APTR)opener->real_dma_tx_function,
373 AROS_UFCA(APTR, cookie, A0));
378 /****i* realtek8180.device/AROSInt *****************************************
380 * NAME
381 * AROSInt
383 ****************************************************************************
387 AROS_UFH3(BOOL, AROSInt,
388 AROS_UFHA(APTR *, int_data, A1),
389 AROS_UFHA(APTR, this_code, A5),
390 AROS_UFHA(UBYTE, mask, D0))
392 AROS_USERFUNC_INIT
394 BOOL (*int_code)(APTR, APTR, UBYTE);
396 int_code = int_data[0];
397 return int_code(int_data[1], int_code, mask);
399 AROS_USERFUNC_EXIT