Corrections to SVN properties.
[AROS.git] / workbench / devs / networks / etherlink3 / mos_device.c
blob2ac724254dc524d7da2cb93fab72f1c42fae20c7
1 /*
3 Copyright (C) 2000-2008 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 <utility/utility.h>
27 #include <proto/exec.h>
29 #include "device.h"
31 #include "device_protos.h"
34 /* Private prototypes */
36 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
37 struct DevBase *base);
38 static BYTE MOSDevOpen();
39 static APTR MOSDevClose();
40 static APTR MOSDevExpunge();
41 static VOID MOSDevBeginIO();
42 static VOID MOSDevAbortIO();
43 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size);
44 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size);
45 static UBYTE *DMATXFunction(struct IOSana2Req *request);
46 static BOOL MOSInt();
48 extern const APTR init_data;
49 extern const struct Resident rom_tag;
50 extern const TEXT device_name[];
51 extern const TEXT version_string[];
54 static const TEXT openpci_name[] = "openpci.library";
57 static const APTR mos_vectors[] =
59 (APTR)FUNCARRAY_32BIT_NATIVE,
60 (APTR)MOSDevOpen,
61 (APTR)MOSDevClose,
62 (APTR)MOSDevExpunge,
63 (APTR)DevReserved,
64 (APTR)MOSDevBeginIO,
65 (APTR)MOSDevAbortIO,
66 (APTR)-1
70 static const APTR mos_init_table[] =
72 (APTR)sizeof(struct DevBase),
73 (APTR)mos_vectors,
74 (APTR)&init_data,
75 (APTR)MOSDevInit
79 const struct Resident mos_rom_tag =
81 RTC_MATCHWORD,
82 (struct Resident *)&mos_rom_tag,
83 (APTR)(&rom_tag + 1),
84 RTF_AUTOINIT | RTF_PPC,
85 VERSION,
86 NT_DEVICE,
88 (STRPTR)device_name,
89 (STRPTR)version_string,
90 (APTR)mos_init_table
94 static const struct EmulLibEntry int_trap =
96 TRAP_LIB,
98 (APTR)MOSInt
103 /****i* etherlink3.device/MOSDevInit ***************************************
105 * NAME
106 * MOSDevInit
108 ****************************************************************************
112 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
113 struct DevBase *base)
115 base = DevInit(dev_base, seg_list, base);
117 if(base != NULL)
119 base->openpci_base = OpenLibrary(openpci_name, OPENPCI_VERSION);
120 base->wrapper_int_code = (APTR)&int_trap;
122 return base;
127 /****i* etherlink3.device/MOSDevOpen ***************************************
129 * NAME
130 * MOSDevOpen
132 ****************************************************************************
136 static BYTE MOSDevOpen()
138 struct IOSana2Req *request;
139 struct Opener *opener;
140 BYTE error;
142 request = (APTR)REG_A1;
143 error = DevOpen(request, REG_D0, REG_D1, (APTR)REG_A6);
145 /* Set up wrapper hooks to hide 68k emulation */
147 if(error == 0)
149 opener = request->ios2_BufferManagement;
150 opener->real_rx_function = opener->rx_function;
151 opener->real_tx_function = opener->tx_function;
152 opener->rx_function = (APTR)RXFunction;
153 opener->tx_function = (APTR)TXFunction;
154 if(opener->dma_tx_function != NULL)
156 opener->real_dma_tx_function = opener->dma_tx_function;
157 opener->dma_tx_function = (APTR)DMATXFunction;
161 return error;
166 /****i* etherlink3.device/MOSDevClose **************************************
168 * NAME
169 * MOSDevClose
171 ****************************************************************************
175 static APTR MOSDevClose()
177 return DevClose((APTR)REG_A1, (APTR)REG_A6);
182 /****i* etherlink3.device/MOSDevExpunge ************************************
184 * NAME
185 * MOSDevExpunge
187 ****************************************************************************
191 static APTR MOSDevExpunge()
193 return DevExpunge((APTR)REG_A6);
198 /****i* etherlink3.device/MOSDevBeginIO ************************************
200 * NAME
201 * MOSDevBeginIO
203 ****************************************************************************
207 static VOID MOSDevBeginIO()
209 struct IOSana2Req *request = (APTR)REG_A1;
211 /* Replace caller's cookie with our own */
213 switch(request->ios2_Req.io_Command)
215 case CMD_READ:
216 case CMD_WRITE:
217 case S2_MULTICAST:
218 case S2_BROADCAST:
219 case S2_READORPHAN:
220 request->ios2_StatData = request->ios2_Data;
221 request->ios2_Data = request;
224 DevBeginIO(request, (APTR)REG_A6);
226 return;
231 /****i* etherlink3.device/MOSDevAbortIO ************************************
233 * NAME
234 * MOSDevAbortIO -- Try to stop a request.
236 ****************************************************************************
240 static VOID MOSDevAbortIO()
242 DevAbortIO((APTR)REG_A1, (APTR)REG_A6);
247 /****i* etherlink3.device/RXFunction ***************************************
249 * NAME
250 * RXFunction
252 ****************************************************************************
256 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
258 struct DevBase *base;
259 struct EmulCaos context;
260 struct Opener *opener;
261 APTR cookie;
263 base = (struct DevBase *)request->ios2_Req.io_Device;
264 opener = request->ios2_BufferManagement;
265 cookie = request->ios2_StatData;
266 request->ios2_Data = cookie;
268 context.caos_Un.Function = (APTR)opener->real_rx_function;
269 context.reg_a0 = (ULONG)cookie;
270 context.reg_a1 = (ULONG)buffer;
271 context.reg_d0 = size;
272 return MyEmulHandle->EmulCall68k(&context);
277 /****i* etherlink3.device/TXFunction ***************************************
279 * NAME
280 * TXFunction
282 ****************************************************************************
286 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
288 struct DevBase *base;
289 struct EmulCaos context;
290 struct Opener *opener;
291 APTR cookie;
293 base = (struct DevBase *)request->ios2_Req.io_Device;
294 opener = request->ios2_BufferManagement;
295 cookie = request->ios2_StatData;
296 request->ios2_Data = cookie;
298 context.caos_Un.Function = (APTR)opener->real_tx_function;
299 context.reg_a0 = (ULONG)buffer;
300 context.reg_a1 = (ULONG)cookie;
301 context.reg_d0 = size;
302 return MyEmulHandle->EmulCall68k(&context);
307 /****i* etherlink3.device/DMATXFunction ************************************
309 * NAME
310 * DMATXFunction
312 ****************************************************************************
316 static UBYTE *DMATXFunction(struct IOSana2Req *request)
318 struct DevBase *base;
319 struct EmulCaos context;
320 struct Opener *opener;
321 APTR cookie;
323 base = (struct DevBase *)request->ios2_Req.io_Device;
324 opener = request->ios2_BufferManagement;
325 cookie = request->ios2_StatData;
326 request->ios2_Data = cookie;
328 context.caos_Un.Function = (APTR)opener->real_dma_tx_function;
329 context.reg_a0 = (ULONG)cookie;
330 return (UBYTE *)MyEmulHandle->EmulCall68k(&context);
335 /****i* etherlink3.device/MOSInt *******************************************
337 * NAME
338 * MOSInt
340 ****************************************************************************
344 static BOOL MOSInt()
346 APTR *int_data;
347 BOOL (*int_code)(APTR, APTR);
349 int_data = (APTR)REG_A1;
350 int_code = int_data[0];
351 return int_code(int_data[1], int_code);