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,
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>
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
);
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
,
73 static const APTR mos_init_table
[] =
75 (APTR
)sizeof(struct DevBase
),
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},
100 const struct Resident mos_rom_tag
=
103 (struct Resident
*)&mos_rom_tag
,
104 (APTR
)(&rom_tag
+ 1),
105 RTF_AUTOINIT
| RTF_PPC
| RTF_EXTENDED
,
110 (STRPTR
)version_string
,
111 (APTR
)mos_init_table
,
113 (struct TagItem
*)&query_tags
117 static const struct EmulLibEntry int_trap
=
126 /****i* prism2.device/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
);
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
;
151 /****i* prism2.device/MOSDevOpen *******************************************
156 ****************************************************************************
160 static BYTE
MOSDevOpen()
162 struct IOSana2Req
*request
;
163 struct Opener
*opener
;
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 */
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
;
190 /****i* prism2.device/MOSDevClose ******************************************
195 ****************************************************************************
199 static APTR
MOSDevClose()
201 return DevClose((APTR
)REG_A1
, (APTR
)REG_A6
);
206 /****i* prism2.device/MOSDevExpunge ****************************************
211 ****************************************************************************
215 static APTR
MOSDevExpunge()
217 return DevExpunge((APTR
)REG_A6
);
222 /****i* prism2.device/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
)
244 request
->ios2_StatData
= request
->ios2_Data
;
245 request
->ios2_Data
= request
;
248 DevBeginIO(request
, (APTR
)REG_A6
);
255 /****i* prism2.device/MOSDevAbortIO ****************************************
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 *******************************************
276 ****************************************************************************
280 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
282 struct DevBase
*base
;
283 struct EmulCaos context
;
284 struct Opener
*opener
;
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 *******************************************
306 ****************************************************************************
310 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
312 struct DevBase
*base
;
313 struct EmulCaos context
;
314 struct Opener
*opener
;
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 ****************************************
336 ****************************************************************************
340 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
342 struct DevBase
*base
;
343 struct EmulCaos context
;
344 struct Opener
*opener
;
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 ***********************************************
364 ****************************************************************************
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
);