grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / networks / realtek8180 / mos_device.c
blob0146facb3ac58296c6e13e20a002428218e2bc0a
1 /*
3 File: mos_device.c
4 Author: Neil Cafferkey
5 Copyright (C) 2000-2008 Neil Cafferkey
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA.
25 #include <exec/types.h>
26 #include <exec/resident.h>
27 #include <utility/utility.h>
29 #include <proto/exec.h>
31 #include "device.h"
33 #include "device_protos.h"
36 /* Private prototypes */
38 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
39 struct DevBase *base);
40 static BYTE MOSDevOpen();
41 static APTR MOSDevClose();
42 static APTR MOSDevExpunge();
43 static VOID MOSDevBeginIO();
44 static VOID MOSDevAbortIO();
45 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size);
46 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size);
47 static UBYTE *DMATXFunction(struct IOSana2Req *request);
48 static BOOL MOSInt();
50 extern const APTR init_data;
51 extern const struct Resident rom_tag;
52 extern const TEXT device_name[];
53 extern const TEXT version_string[];
56 static const APTR mos_vectors[] =
58 (APTR)FUNCARRAY_32BIT_NATIVE,
59 (APTR)MOSDevOpen,
60 (APTR)MOSDevClose,
61 (APTR)MOSDevExpunge,
62 (APTR)DevReserved,
63 (APTR)MOSDevBeginIO,
64 (APTR)MOSDevAbortIO,
65 (APTR)-1
69 static const APTR mos_init_table[] =
71 (APTR)sizeof(struct DevBase),
72 (APTR)mos_vectors,
73 (APTR)&init_data,
74 (APTR)MOSDevInit
78 const struct Resident mos_rom_tag =
80 RTC_MATCHWORD,
81 (struct Resident *)&mos_rom_tag,
82 (APTR)(&rom_tag + 1),
83 RTF_AUTOINIT | RTF_PPC,
84 VERSION,
85 NT_DEVICE,
87 (STRPTR)device_name,
88 (STRPTR)version_string,
89 (APTR)mos_init_table
93 static const struct EmulLibEntry int_trap =
95 TRAP_LIB,
97 (APTR)MOSInt
102 /****i* atheros.device/MOSDevInit ******************************************
104 * NAME
105 * MOSDevInit
107 ****************************************************************************
111 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
112 struct DevBase *base)
114 base = DevInit(dev_base, seg_list, base);
116 if(base != NULL)
118 base->wrapper_int_code = (APTR)&int_trap;
120 return base;
125 /****i* atheros.device/MOSDevOpen ******************************************
127 * NAME
128 * MOSDevOpen
130 ****************************************************************************
134 static BYTE MOSDevOpen()
136 struct IOSana2Req *request;
137 struct Opener *opener;
138 BYTE error;
140 request = (APTR)REG_A1;
141 error = DevOpen(request, REG_D0, REG_D1, (APTR)REG_A6);
143 /* Set up wrapper hooks to hide 68k emulation */
145 if(error == 0)
147 opener = request->ios2_BufferManagement;
148 opener->real_rx_function = opener->rx_function;
149 opener->real_tx_function = opener->tx_function;
150 opener->rx_function = (APTR)RXFunction;
151 opener->tx_function = (APTR)TXFunction;
152 if(opener->dma_tx_function != NULL)
154 opener->real_dma_tx_function = opener->dma_tx_function;
155 opener->dma_tx_function = (APTR)DMATXFunction;
159 return error;
164 /****i* atheros.device/MOSDevClose *****************************************
166 * NAME
167 * MOSDevClose
169 ****************************************************************************
173 static APTR MOSDevClose()
175 return DevClose((APTR)REG_A1, (APTR)REG_A6);
180 /****i* atheros.device/MOSDevExpunge ***************************************
182 * NAME
183 * MOSDevExpunge
185 ****************************************************************************
189 static APTR MOSDevExpunge()
191 return DevExpunge((APTR)REG_A6);
196 /****i* atheros.device/MOSDevBeginIO ***************************************
198 * NAME
199 * MOSDevBeginIO
201 ****************************************************************************
205 static VOID MOSDevBeginIO()
207 struct IOSana2Req *request = (APTR)REG_A1;
209 /* Replace caller's cookie with our own */
211 switch(request->ios2_Req.io_Command)
213 case CMD_READ:
214 case CMD_WRITE:
215 case S2_MULTICAST:
216 case S2_BROADCAST:
217 case S2_READORPHAN:
218 request->ios2_StatData = request->ios2_Data;
219 request->ios2_Data = request;
222 DevBeginIO(request, (APTR)REG_A6);
224 return;
229 /****i* atheros.device/MOSDevAbortIO ***************************************
231 * NAME
232 * MOSDevAbortIO -- Try to stop a request.
234 ****************************************************************************
238 static VOID MOSDevAbortIO()
240 DevAbortIO((APTR)REG_A1, (APTR)REG_A6);
245 /****i* atheros.device/RXFunction ******************************************
247 * NAME
248 * RXFunction
250 ****************************************************************************
254 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
256 struct DevBase *base;
257 struct EmulCaos context;
258 struct Opener *opener;
259 APTR cookie;
261 base = (struct DevBase *)request->ios2_Req.io_Device;
262 opener = request->ios2_BufferManagement;
263 cookie = request->ios2_StatData;
264 request->ios2_Data = cookie;
266 context.caos_Un.Function = (APTR)opener->real_rx_function;
267 context.reg_a0 = (ULONG)cookie;
268 context.reg_a1 = (ULONG)buffer;
269 context.reg_d0 = size;
270 return MyEmulHandle->EmulCall68k(&context);
275 /****i* atheros.device/TXFunction ******************************************
277 * NAME
278 * TXFunction
280 ****************************************************************************
284 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
286 struct DevBase *base;
287 struct EmulCaos context;
288 struct Opener *opener;
289 APTR cookie;
291 base = (struct DevBase *)request->ios2_Req.io_Device;
292 opener = request->ios2_BufferManagement;
293 cookie = request->ios2_StatData;
294 request->ios2_Data = cookie;
296 context.caos_Un.Function = (APTR)opener->real_tx_function;
297 context.reg_a0 = (ULONG)buffer;
298 context.reg_a1 = (ULONG)cookie;
299 context.reg_d0 = size;
300 return MyEmulHandle->EmulCall68k(&context);
305 /****i* atheros.device/DMATXFunction ***************************************
307 * NAME
308 * DMATXFunction
310 ****************************************************************************
314 static UBYTE *DMATXFunction(struct IOSana2Req *request)
316 struct DevBase *base;
317 struct EmulCaos context;
318 struct Opener *opener;
319 APTR cookie;
321 base = (struct DevBase *)request->ios2_Req.io_Device;
322 opener = request->ios2_BufferManagement;
323 cookie = request->ios2_StatData;
324 request->ios2_Data = cookie;
326 context.caos_Un.Function = (APTR)opener->real_dma_tx_function;
327 context.reg_a0 = (ULONG)cookie;
328 return (UBYTE *)MyEmulHandle->EmulCall68k(&context);
333 /****i* atheros.device/MOSInt **********************************************
335 * NAME
336 * MOSInt
338 ****************************************************************************
342 static BOOL MOSInt()
344 APTR *int_data;
345 BOOL (*int_code)(APTR, APTR);
347 int_data = (APTR)REG_A1;
348 int_code = int_data[0];
349 return int_code(int_data[1], int_code);