Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / networks / atheros5000 / mos_device.c
blobc4e0ddc26dd08e35ea8fb39f8940eefe3cc33637
1 /*
3 File: mos_device.c
4 Author: Neil Cafferkey
5 Copyright (C) 2000-2011 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>
28 #include <libraries/query.h>
30 #include <proto/exec.h>
32 #include "device.h"
34 #include "device_protos.h"
37 /* Private prototypes */
39 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
40 struct DevBase *base);
41 static BYTE MOSDevOpen();
42 static APTR MOSDevClose();
43 static APTR MOSDevExpunge();
44 static VOID MOSDevBeginIO();
45 static VOID MOSDevAbortIO();
46 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size);
47 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size);
48 static UBYTE *DMATXFunction(struct IOSana2Req *request);
49 static BOOL MOSInt();
51 extern const APTR init_data;
52 extern const struct Resident rom_tag;
53 extern const TEXT device_name[];
54 extern const TEXT version_string[];
57 static const TEXT openpci_name[] = "openpci.library";
60 static const APTR mos_vectors[] =
62 (APTR)FUNCARRAY_32BIT_NATIVE,
63 (APTR)MOSDevOpen,
64 (APTR)MOSDevClose,
65 (APTR)MOSDevExpunge,
66 (APTR)DevReserved,
67 (APTR)MOSDevBeginIO,
68 (APTR)MOSDevAbortIO,
69 (APTR)-1
73 static const APTR mos_init_table[] =
75 (APTR)sizeof(struct DevBase),
76 (APTR)mos_vectors,
77 (APTR)&init_data,
78 (APTR)MOSDevInit
82 static const struct TagItem query_tags[] =
84 {QUERYINFOATTR_NAME, (UPINT)device_name},
85 {QUERYINFOATTR_IDSTRING, (UPINT)version_string},
86 {QUERYINFOATTR_DESCRIPTION, (UPINT)"Atheros5000 WLAN network driver"},
87 {QUERYINFOATTR_COPYRIGHT, (UPINT)"2000-2011 Neil Cafferkey"},
88 {QUERYINFOATTR_AUTHOR, (UPINT)"Neil Cafferkey"},
89 {QUERYINFOATTR_DATE, (UPINT)DATE},
90 {QUERYINFOATTR_VERSION, VERSION},
91 {QUERYINFOATTR_REVISION, REVISION},
92 {QUERYINFOATTR_CODETYPE, MACHINE_PPC},
93 {QUERYINFOATTR_SUBTYPE, QUERYSUBTYPE_DEVICE},
94 {QUERYINFOATTR_CLASS, QUERYCLASS_NET},
95 {QUERYINFOATTR_NET_IPTYPE, 2048},
96 {TAG_END, 0}
100 const struct Resident mos_rom_tag =
102 RTC_MATCHWORD,
103 (struct Resident *)&mos_rom_tag,
104 (APTR)(&rom_tag + 1),
105 RTF_AUTOINIT | RTF_PPC | RTF_EXTENDED,
106 VERSION,
107 NT_DEVICE,
109 (STRPTR)device_name,
110 (STRPTR)version_string,
111 (APTR)mos_init_table,
112 REVISION,
113 (struct TagItem *)&query_tags
117 static const struct EmulLibEntry int_trap =
119 TRAP_LIB,
121 (APTR)MOSInt
126 /****i* atheros5000.device/MOSDevInit **************************************
128 * NAME
129 * MOSDevInit
131 ****************************************************************************
135 static struct DevBase *MOSDevInit(struct DevBase *dev_base, APTR seg_list,
136 struct DevBase *base)
138 base = DevInit(dev_base, seg_list, base);
140 if(base != NULL)
142 base->openpci_base = OpenLibrary(openpci_name, OPENPCI_VERSION);
143 base->wrapper_int_code = (APTR)&int_trap;
145 return base;
150 /****i* atheros5000.device/MOSDevOpen **************************************
152 * NAME
153 * MOSDevOpen
155 ****************************************************************************
159 static BYTE MOSDevOpen()
161 struct IOSana2Req *request;
162 struct Opener *opener;
163 BYTE error;
165 request = (APTR)REG_A1;
166 error = DevOpen(request, REG_D0, REG_D1, (APTR)REG_A6);
168 /* Set up wrapper hooks to hide 68k emulation */
170 if(error == 0)
172 opener = request->ios2_BufferManagement;
173 opener->real_rx_function = opener->rx_function;
174 opener->real_tx_function = opener->tx_function;
175 opener->rx_function = (APTR)RXFunction;
176 opener->tx_function = (APTR)TXFunction;
177 if(opener->dma_tx_function != NULL)
179 opener->real_dma_tx_function = opener->dma_tx_function;
180 opener->dma_tx_function = (APTR)DMATXFunction;
184 return error;
189 /****i* atheros5000.device/MOSDevClose *************************************
191 * NAME
192 * MOSDevClose
194 ****************************************************************************
198 static APTR MOSDevClose()
200 return DevClose((APTR)REG_A1, (APTR)REG_A6);
205 /****i* atheros5000.device/MOSDevExpunge ***********************************
207 * NAME
208 * MOSDevExpunge
210 ****************************************************************************
214 static APTR MOSDevExpunge()
216 return DevExpunge((APTR)REG_A6);
221 /****i* atheros5000.device/MOSDevBeginIO ***********************************
223 * NAME
224 * MOSDevBeginIO
226 ****************************************************************************
230 static VOID MOSDevBeginIO()
232 struct IOSana2Req *request = (APTR)REG_A1;
234 /* Replace caller's cookie with our own */
236 switch(request->ios2_Req.io_Command)
238 case CMD_READ:
239 case CMD_WRITE:
240 case S2_MULTICAST:
241 case S2_BROADCAST:
242 case S2_READORPHAN:
243 request->ios2_StatData = request->ios2_Data;
244 request->ios2_Data = request;
247 DevBeginIO(request, (APTR)REG_A6);
249 return;
254 /****i* atheros5000.device/MOSDevAbortIO ***********************************
256 * NAME
257 * MOSDevAbortIO -- Try to stop a request.
259 ****************************************************************************
263 static VOID MOSDevAbortIO()
265 DevAbortIO((APTR)REG_A1, (APTR)REG_A6);
270 /****i* atheros5000.device/RXFunction **************************************
272 * NAME
273 * RXFunction
275 ****************************************************************************
279 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
281 struct DevBase *base;
282 struct EmulCaos context;
283 struct Opener *opener;
284 APTR cookie;
286 base = (struct DevBase *)request->ios2_Req.io_Device;
287 opener = request->ios2_BufferManagement;
288 cookie = request->ios2_StatData;
289 request->ios2_Data = cookie;
291 context.caos_Un.Function = (APTR)opener->real_rx_function;
292 context.reg_a0 = (ULONG)cookie;
293 context.reg_a1 = (ULONG)buffer;
294 context.reg_d0 = size;
295 return MyEmulHandle->EmulCall68k(&context);
300 /****i* atheros5000.device/TXFunction **************************************
302 * NAME
303 * TXFunction
305 ****************************************************************************
309 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
311 struct DevBase *base;
312 struct EmulCaos context;
313 struct Opener *opener;
314 APTR cookie;
316 base = (struct DevBase *)request->ios2_Req.io_Device;
317 opener = request->ios2_BufferManagement;
318 cookie = request->ios2_StatData;
319 request->ios2_Data = cookie;
321 context.caos_Un.Function = (APTR)opener->real_tx_function;
322 context.reg_a0 = (ULONG)buffer;
323 context.reg_a1 = (ULONG)cookie;
324 context.reg_d0 = size;
325 return MyEmulHandle->EmulCall68k(&context);
330 /****i* atheros5000.device/DMATXFunction ***********************************
332 * NAME
333 * DMATXFunction
335 ****************************************************************************
339 static UBYTE *DMATXFunction(struct IOSana2Req *request)
341 struct DevBase *base;
342 struct EmulCaos context;
343 struct Opener *opener;
344 APTR cookie;
346 base = (struct DevBase *)request->ios2_Req.io_Device;
347 opener = request->ios2_BufferManagement;
348 cookie = request->ios2_StatData;
349 request->ios2_Data = cookie;
351 context.caos_Un.Function = (APTR)opener->real_dma_tx_function;
352 context.reg_a0 = (ULONG)cookie;
353 return (UBYTE *)MyEmulHandle->EmulCall68k(&context);
358 /****i* atheros5000.device/MOSInt ******************************************
360 * NAME
361 * MOSInt
363 ****************************************************************************
367 static BOOL MOSInt()
369 APTR *int_data;
370 BOOL (*int_code)(APTR, APTR);
372 int_data = (APTR)REG_A1;
373 int_code = int_data[0];
374 return int_code(int_data[1], int_code);