AHI: build Alsa driver when alsa-bridge link lib is detected
[AROS.git] / workbench / devs / networks / prism2 / mos_device.c
blob12cb4058544945835d6a1ff51971172133198cb7
1 /*
3 File: mos_device.c
4 Author: Neil Cafferkey
5 Copyright (C) 2000-2012 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)"Prism-II WLAN network driver"},
87 {QUERYINFOATTR_COPYRIGHT, (UPINT)"2000-2012 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* prism2.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;
144 base->wrapper_card_code = (APTR)&int_trap;
146 return base;
151 /****i* prism2.device/MOSDevOpen *******************************************
153 * NAME
154 * MOSDevOpen
156 ****************************************************************************
160 static BYTE MOSDevOpen()
162 struct IOSana2Req *request;
163 struct Opener *opener;
164 BYTE error;
166 request = (APTR)REG_A1;
167 error = DevOpen(request, REG_D0, REG_D1, (APTR)REG_A6);
169 /* Set up wrapper hooks to hide 68k emulation */
171 if(error == 0)
173 opener = request->ios2_BufferManagement;
174 opener->real_rx_function = opener->rx_function;
175 opener->real_tx_function = opener->tx_function;
176 opener->rx_function = (APTR)RXFunction;
177 opener->tx_function = (APTR)TXFunction;
178 if(opener->dma_tx_function != NULL)
180 opener->real_dma_tx_function = opener->dma_tx_function;
181 opener->dma_tx_function = (APTR)DMATXFunction;
185 return error;
190 /****i* prism2.device/MOSDevClose ******************************************
192 * NAME
193 * MOSDevClose
195 ****************************************************************************
199 static APTR MOSDevClose()
201 return DevClose((APTR)REG_A1, (APTR)REG_A6);
206 /****i* prism2.device/MOSDevExpunge ****************************************
208 * NAME
209 * MOSDevExpunge
211 ****************************************************************************
215 static APTR MOSDevExpunge()
217 return DevExpunge((APTR)REG_A6);
222 /****i* prism2.device/MOSDevBeginIO ****************************************
224 * NAME
225 * MOSDevBeginIO
227 ****************************************************************************
231 static VOID MOSDevBeginIO()
233 struct IOSana2Req *request = (APTR)REG_A1;
235 /* Replace caller's cookie with our own */
237 switch(request->ios2_Req.io_Command)
239 case CMD_READ:
240 case CMD_WRITE:
241 case S2_MULTICAST:
242 case S2_BROADCAST:
243 case S2_READORPHAN:
244 request->ios2_StatData = request->ios2_Data;
245 request->ios2_Data = request;
248 DevBeginIO(request, (APTR)REG_A6);
250 return;
255 /****i* prism2.device/MOSDevAbortIO ****************************************
257 * NAME
258 * MOSDevAbortIO -- Try to stop a request.
260 ****************************************************************************
264 static VOID MOSDevAbortIO()
266 DevAbortIO((APTR)REG_A1, (APTR)REG_A6);
271 /****i* prism2.device/RXFunction *******************************************
273 * NAME
274 * RXFunction
276 ****************************************************************************
280 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
282 struct DevBase *base;
283 struct EmulCaos context;
284 struct Opener *opener;
285 APTR cookie;
287 base = (struct DevBase *)request->ios2_Req.io_Device;
288 opener = request->ios2_BufferManagement;
289 cookie = request->ios2_StatData;
290 request->ios2_Data = cookie;
292 context.caos_Un.Function = (APTR)opener->real_rx_function;
293 context.reg_a0 = (ULONG)cookie;
294 context.reg_a1 = (ULONG)buffer;
295 context.reg_d0 = size;
296 return MyEmulHandle->EmulCall68k(&context);
301 /****i* prism2.device/TXFunction *******************************************
303 * NAME
304 * TXFunction
306 ****************************************************************************
310 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
312 struct DevBase *base;
313 struct EmulCaos context;
314 struct Opener *opener;
315 APTR cookie;
317 base = (struct DevBase *)request->ios2_Req.io_Device;
318 opener = request->ios2_BufferManagement;
319 cookie = request->ios2_StatData;
320 request->ios2_Data = cookie;
322 context.caos_Un.Function = (APTR)opener->real_tx_function;
323 context.reg_a0 = (ULONG)buffer;
324 context.reg_a1 = (ULONG)cookie;
325 context.reg_d0 = size;
326 return MyEmulHandle->EmulCall68k(&context);
331 /****i* prism2.device/DMATXFunction ****************************************
333 * NAME
334 * DMATXFunction
336 ****************************************************************************
340 static UBYTE *DMATXFunction(struct IOSana2Req *request)
342 struct DevBase *base;
343 struct EmulCaos context;
344 struct Opener *opener;
345 APTR cookie;
347 base = (struct DevBase *)request->ios2_Req.io_Device;
348 opener = request->ios2_BufferManagement;
349 cookie = request->ios2_StatData;
350 request->ios2_Data = cookie;
352 context.caos_Un.Function = (APTR)opener->real_dma_tx_function;
353 context.reg_a0 = (ULONG)cookie;
354 return (UBYTE *)MyEmulHandle->EmulCall68k(&context);
359 /****i* prism2.device/MOSInt ***********************************************
361 * NAME
362 * MOSInt
364 ****************************************************************************
368 static BOOL MOSInt()
370 APTR *int_data;
371 BOOL (*int_code)(APTR, APTR);
373 int_data = (APTR)REG_A1;
374 int_code = int_data[0];
375 return int_code(int_data[1], int_code);