Added two wireless drivers: atheros5000.device and realtek8180.device.
[AROS.git] / workbench / devs / networks / atheros5000 / mos_device.c
blobf7ecf043b8cd43f96f1a35a0fd355b847ffca35a
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 TEXT openpci_name[] = "openpci.library";
59 static const APTR mos_vectors[] =
61 (APTR)FUNCARRAY_32BIT_NATIVE,
62 (APTR)MOSDevOpen,
63 (APTR)MOSDevClose,
64 (APTR)MOSDevExpunge,
65 (APTR)DevReserved,
66 (APTR)MOSDevBeginIO,
67 (APTR)MOSDevAbortIO,
68 (APTR)-1
72 static const APTR mos_init_table[] =
74 (APTR)sizeof(struct DevBase),
75 (APTR)mos_vectors,
76 (APTR)&init_data,
77 (APTR)MOSDevInit
81 const struct Resident mos_rom_tag =
83 RTC_MATCHWORD,
84 (struct Resident *)&mos_rom_tag,
85 (APTR)(&rom_tag + 1),
86 RTF_AUTOINIT | RTF_PPC,
87 VERSION,
88 NT_DEVICE,
90 (STRPTR)device_name,
91 (STRPTR)version_string,
92 (APTR)mos_init_table
96 static const struct EmulLibEntry int_trap =
98 TRAP_LIB,
100 (APTR)MOSInt
105 /****i* atheros5000.device/MOSDevInit **************************************
107 * NAME
108 * MOSDevInit
110 ****************************************************************************
114 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
115 struct DevBase *base)
117 base = DevInit(dev_base, seg_list, base);
119 if(base != NULL)
121 base->openpci_base = OpenLibrary(openpci_name, OPENPCI_VERSION);
122 base->wrapper_int_code = (APTR)&int_trap;
124 return base;
129 /****i* atheros5000.device/MOSDevOpen **************************************
131 * NAME
132 * MOSDevOpen
134 ****************************************************************************
138 static BYTE MOSDevOpen()
140 struct IOSana2Req *request;
141 struct Opener *opener;
142 BYTE error;
144 request = (APTR)REG_A1;
145 error = DevOpen(request, REG_D0, REG_D1, (APTR)REG_A6);
147 /* Set up wrapper hooks to hide 68k emulation */
149 if(error == 0)
151 opener = request->ios2_BufferManagement;
152 opener->real_rx_function = opener->rx_function;
153 opener->real_tx_function = opener->tx_function;
154 opener->rx_function = (APTR)RXFunction;
155 opener->tx_function = (APTR)TXFunction;
156 if(opener->dma_tx_function != NULL)
158 opener->real_dma_tx_function = opener->dma_tx_function;
159 opener->dma_tx_function = (APTR)DMATXFunction;
163 return error;
168 /****i* atheros5000.device/MOSDevClose *************************************
170 * NAME
171 * MOSDevClose
173 ****************************************************************************
177 static APTR MOSDevClose()
179 return DevClose((APTR)REG_A1, (APTR)REG_A6);
184 /****i* atheros5000.device/MOSDevExpunge ***********************************
186 * NAME
187 * MOSDevExpunge
189 ****************************************************************************
193 static APTR MOSDevExpunge()
195 return DevExpunge((APTR)REG_A6);
200 /****i* atheros5000.device/MOSDevBeginIO ***********************************
202 * NAME
203 * MOSDevBeginIO
205 ****************************************************************************
209 static VOID MOSDevBeginIO()
211 struct IOSana2Req *request = (APTR)REG_A1;
213 /* Replace caller's cookie with our own */
215 switch(request->ios2_Req.io_Command)
217 case CMD_READ:
218 case CMD_WRITE:
219 case S2_MULTICAST:
220 case S2_BROADCAST:
221 case S2_READORPHAN:
222 request->ios2_StatData = request->ios2_Data;
223 request->ios2_Data = request;
226 DevBeginIO(request, (APTR)REG_A6);
228 return;
233 /****i* atheros5000.device/MOSDevAbortIO ***********************************
235 * NAME
236 * MOSDevAbortIO -- Try to stop a request.
238 ****************************************************************************
242 static VOID MOSDevAbortIO()
244 DevAbortIO((APTR)REG_A1, (APTR)REG_A6);
249 /****i* atheros5000.device/RXFunction **************************************
251 * NAME
252 * RXFunction
254 ****************************************************************************
258 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
260 struct DevBase *base;
261 struct EmulCaos context;
262 struct Opener *opener;
263 APTR cookie;
265 base = (struct DevBase *)request->ios2_Req.io_Device;
266 opener = request->ios2_BufferManagement;
267 cookie = request->ios2_StatData;
268 request->ios2_Data = cookie;
270 context.caos_Un.Function = (APTR)opener->real_rx_function;
271 context.reg_a0 = (ULONG)cookie;
272 context.reg_a1 = (ULONG)buffer;
273 context.reg_d0 = size;
274 return MyEmulHandle->EmulCall68k(&context);
279 /****i* atheros5000.device/TXFunction **************************************
281 * NAME
282 * TXFunction
284 ****************************************************************************
288 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
290 struct DevBase *base;
291 struct EmulCaos context;
292 struct Opener *opener;
293 APTR cookie;
295 base = (struct DevBase *)request->ios2_Req.io_Device;
296 opener = request->ios2_BufferManagement;
297 cookie = request->ios2_StatData;
298 request->ios2_Data = cookie;
300 context.caos_Un.Function = (APTR)opener->real_tx_function;
301 context.reg_a0 = (ULONG)buffer;
302 context.reg_a1 = (ULONG)cookie;
303 context.reg_d0 = size;
304 return MyEmulHandle->EmulCall68k(&context);
309 /****i* atheros5000.device/DMATXFunction ***********************************
311 * NAME
312 * DMATXFunction
314 ****************************************************************************
318 static UBYTE *DMATXFunction(struct IOSana2Req *request)
320 struct DevBase *base;
321 struct EmulCaos context;
322 struct Opener *opener;
323 APTR cookie;
325 base = (struct DevBase *)request->ios2_Req.io_Device;
326 opener = request->ios2_BufferManagement;
327 cookie = request->ios2_StatData;
328 request->ios2_Data = cookie;
330 context.caos_Un.Function = (APTR)opener->real_dma_tx_function;
331 context.reg_a0 = (ULONG)cookie;
332 return (UBYTE *)MyEmulHandle->EmulCall68k(&context);
337 /****i* atheros5000.device/MOSInt ******************************************
339 * NAME
340 * MOSInt
342 ****************************************************************************
346 static BOOL MOSInt()
348 APTR *int_data;
349 BOOL (*int_code)(APTR, APTR);
351 int_data = (APTR)REG_A1;
352 int_code = int_data[0];
353 return int_code(int_data[1], int_code);