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,
25 #include <exec/types.h>
26 #include <exec/resident.h>
27 #include <utility/utility.h>
29 #include <proto/exec.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
);
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
,
72 static const APTR mos_init_table
[] =
74 (APTR
)sizeof(struct DevBase
),
81 const struct Resident mos_rom_tag
=
84 (struct Resident
*)&mos_rom_tag
,
86 RTF_AUTOINIT
| RTF_PPC
,
91 (STRPTR
)version_string
,
96 static const struct EmulLibEntry int_trap
=
105 /****i* atheros5000.device/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
);
121 base
->openpci_base
= OpenLibrary(openpci_name
, OPENPCI_VERSION
);
122 base
->wrapper_int_code
= (APTR
)&int_trap
;
129 /****i* atheros5000.device/MOSDevOpen **************************************
134 ****************************************************************************
138 static BYTE
MOSDevOpen()
140 struct IOSana2Req
*request
;
141 struct Opener
*opener
;
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 */
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
;
168 /****i* atheros5000.device/MOSDevClose *************************************
173 ****************************************************************************
177 static APTR
MOSDevClose()
179 return DevClose((APTR
)REG_A1
, (APTR
)REG_A6
);
184 /****i* atheros5000.device/MOSDevExpunge ***********************************
189 ****************************************************************************
193 static APTR
MOSDevExpunge()
195 return DevExpunge((APTR
)REG_A6
);
200 /****i* atheros5000.device/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
)
222 request
->ios2_StatData
= request
->ios2_Data
;
223 request
->ios2_Data
= request
;
226 DevBeginIO(request
, (APTR
)REG_A6
);
233 /****i* atheros5000.device/MOSDevAbortIO ***********************************
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 **************************************
254 ****************************************************************************
258 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
260 struct DevBase
*base
;
261 struct EmulCaos context
;
262 struct Opener
*opener
;
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 **************************************
284 ****************************************************************************
288 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
290 struct DevBase
*base
;
291 struct EmulCaos context
;
292 struct Opener
*opener
;
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 ***********************************
314 ****************************************************************************
318 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
320 struct DevBase
*base
;
321 struct EmulCaos context
;
322 struct Opener
*opener
;
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 ******************************************
342 ****************************************************************************
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
);