grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / networks / realtek8180 / aros_device.c
blob0131e0f135b76602df8f834febae40e03117d90b
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_INTP(AROSInt);
63 extern const APTR init_data;
64 extern const struct Resident rom_tag;
65 extern const TEXT device_name[];
66 extern const TEXT version_string[];
69 static const APTR vectors[] =
71 (APTR)AROS_SLIB_ENTRY(AROSDevOpen, S2, 1),
72 (APTR)AROS_SLIB_ENTRY(AROSDevClose, S2, 2),
73 (APTR)AROS_SLIB_ENTRY(AROSDevExpunge, S2, 3),
74 (APTR)AROS_SLIB_ENTRY(AROSDevReserved, S2, 4),
75 (APTR)AROS_SLIB_ENTRY(AROSDevBeginIO, S2, 5),
76 (APTR)AROS_SLIB_ENTRY(AROSDevAbortIO, S2, 6),
77 (APTR)-1
81 static const APTR init_table[] =
83 (APTR)sizeof(struct DevBase),
84 (APTR)vectors,
85 (APTR)&init_data,
86 (APTR)AROSDevInit,
90 const struct Resident aros_rom_tag =
92 RTC_MATCHWORD,
93 (struct Resident *)&aros_rom_tag,
94 (APTR)(&rom_tag + 1),
95 RTF_AUTOINIT,
96 VERSION,
97 NT_DEVICE,
99 (TEXT *)device_name,
100 (TEXT *)version_string,
101 (APTR)init_table
106 /****i* realtek8180.device/AROSDevInit *************************************
108 * NAME
109 * AROSDevInit
111 ****************************************************************************
115 AROS_UFH3(struct DevBase *, AROSDevInit,
116 AROS_UFHA(struct DevBase *, dev_base, D0),
117 AROS_UFHA(APTR, seg_list, A0),
118 AROS_UFHA(struct DevBase *, base, A6))
120 AROS_LIBFUNC_INIT
122 base = DevInit(dev_base, seg_list, base);
124 if(base != NULL)
125 base->wrapper_int_code = (APTR)AROSInt;
126 return base;
128 AROS_LIBFUNC_EXIT
133 /****i* realtek8180.device/AROSDevOpen *************************************
135 * NAME
136 * AROSDevOpen
138 ****************************************************************************
142 AROS_LH3(BYTE, AROSDevOpen,
143 AROS_LHA(struct IOSana2Req *, request, A1),
144 AROS_LHA(LONG, unit_num, D0),
145 AROS_LHA(ULONG, flags, D1),
146 struct DevBase *, base, 1, S2)
148 AROS_LIBFUNC_INIT
150 struct Opener *opener;
151 BYTE error;
153 error = DevOpen(request, unit_num, flags, base);
155 /* Set up wrapper hooks to hide register-call functions */
157 if(error == 0)
159 opener = request->ios2_BufferManagement;
160 opener->real_rx_function = opener->rx_function;
161 opener->real_tx_function = opener->tx_function;
162 opener->rx_function = (APTR)RXFunction;
163 opener->tx_function = (APTR)TXFunction;
164 if(opener->dma_tx_function != NULL)
166 opener->real_dma_tx_function = opener->dma_tx_function;
167 opener->dma_tx_function = (APTR)DMATXFunction;
171 return error;
173 AROS_LIBFUNC_EXIT
178 /****i* realtek8180.device/AROSDevClose ************************************
180 * NAME
181 * AROSDevClose
183 ****************************************************************************
187 AROS_LH1(APTR, AROSDevClose,
188 AROS_LHA(struct IOSana2Req *, request, A1),
189 struct DevBase *, base, 2, S2)
191 AROS_LIBFUNC_INIT
193 return DevClose(request, base);
195 AROS_LIBFUNC_EXIT
200 /****i* realtek8180.device/AROSDevExpunge **********************************
202 * NAME
203 * AROSDevExpunge
205 ****************************************************************************
209 AROS_LH0(APTR, AROSDevExpunge,
210 struct DevBase *, base, 3, S2)
212 AROS_LIBFUNC_INIT
214 return DevExpunge(base);
216 AROS_LIBFUNC_EXIT
221 /****i* realtek8180.device/AROSDevReserved *********************************
223 * NAME
224 * AROSDevReserved
226 ****************************************************************************
230 AROS_LH0(APTR, AROSDevReserved,
231 struct DevBase *, base, 4, S2)
233 AROS_LIBFUNC_INIT
235 return DevReserved(base);
237 AROS_LIBFUNC_EXIT
242 /****i* realtek8180.device/AROSDevBeginIO **********************************
244 * NAME
245 * AROSDevBeginIO
247 ****************************************************************************
251 AROS_LH1(VOID, AROSDevBeginIO,
252 AROS_LHA(struct IOSana2Req *, request, A1),
253 struct DevBase *, base, 5, S2)
255 AROS_LIBFUNC_INIT
257 /* Replace caller's cookie with our own */
259 switch(request->ios2_Req.io_Command)
261 case CMD_READ:
262 case CMD_WRITE:
263 case S2_MULTICAST:
264 case S2_BROADCAST:
265 case S2_READORPHAN:
266 request->ios2_StatData = request->ios2_Data;
267 request->ios2_Data = request;
270 DevBeginIO(request, base);
272 AROS_LIBFUNC_EXIT
277 /****i* realtek8180.device/AROSDevAbortIO **********************************
279 * NAME
280 * AROSDevAbortIO -- Try to stop a request.
282 ****************************************************************************
286 AROS_LH1(VOID, AROSDevAbortIO,
287 AROS_LHA(struct IOSana2Req *, request, A1),
288 struct DevBase *, base, 6, S2)
290 AROS_LIBFUNC_INIT
292 DevAbortIO(request, base);
294 AROS_LIBFUNC_EXIT
299 /****i* realtek8180.device/RXFunction **************************************
301 * NAME
302 * RXFunction
304 ****************************************************************************
308 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
310 struct Opener *opener;
311 APTR cookie;
313 opener = request->ios2_BufferManagement;
314 cookie = request->ios2_StatData;
315 request->ios2_Data = cookie;
317 return AROS_UFC3(BOOL, (APTR)opener->real_rx_function,
318 AROS_UFCA(APTR, cookie, A0),
319 AROS_UFCA(APTR, buffer, A1),
320 AROS_UFCA(ULONG, size, D0));
325 /****i* realtek8180.device/TXFunction **************************************
327 * NAME
328 * TXFunction
330 ****************************************************************************
334 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
336 struct Opener *opener;
337 APTR cookie;
339 opener = request->ios2_BufferManagement;
340 cookie = request->ios2_StatData;
341 request->ios2_Data = cookie;
343 return AROS_UFC3(BOOL, (APTR)opener->real_tx_function,
344 AROS_UFCA(APTR, buffer, A0),
345 AROS_UFCA(APTR, cookie, A1),
346 AROS_UFCA(ULONG, size, D0));
351 /****i* realtek8180.device/DMATXFunction ***********************************
353 * NAME
354 * DMATXFunction
356 ****************************************************************************
360 static UBYTE *DMATXFunction(struct IOSana2Req *request)
362 struct Opener *opener;
363 APTR cookie;
365 opener = request->ios2_BufferManagement;
366 cookie = request->ios2_StatData;
367 request->ios2_Data = cookie;
369 return AROS_UFC1(UBYTE *, (APTR)opener->real_dma_tx_function,
370 AROS_UFCA(APTR, cookie, A0));
375 /****i* realtek8180.device/AROSInt *****************************************
377 * NAME
378 * AROSInt
380 ****************************************************************************
383 #undef SysBase
385 AROS_INTH2(AROSInt, APTR *, int_data, mask)
387 AROS_INTFUNC_INIT
389 BOOL (*int_code)(APTR, APTR, UBYTE);
391 int_code = int_data[0];
392 return int_code(int_data[1], int_code, mask);
394 AROS_INTFUNC_EXIT