revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / networks / intelpro100 / mos_device.c
blob33481d293ced9638d1c4b732eeb12653c8173940
1 /*
3 Copyright (C) 2000-2005 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA.
23 #include <exec/types.h>
24 #include <exec/resident.h>
25 #include <utility/utility.h>
27 #include "device.h"
29 /* Private prototypes */
31 static BYTE MOSDevOpen();
32 static APTR MOSDevClose();
33 static APTR MOSDevExpunge();
34 static VOID MOSDevBeginIO();
35 static VOID MOSDevAbortIO();
36 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size);
37 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size);
38 static UBYTE *DMATXFunction(struct IOSana2Req *request);
39 static BOOL MOSInt();
41 extern const APTR mos_vectors[];
42 extern const APTR mos_init_table[];
43 extern const struct Resident rom_tag;
44 extern const APTR init_table[];
45 extern const TEXT device_name[];
46 extern const TEXT version_string[];
49 static const TEXT openpci_name[] = "openpci.library";
52 const struct Resident mos_rom_tag =
54 RTC_MATCHWORD,
55 (struct Resident *)&mos_rom_tag,
56 (APTR)(&rom_tag + 1),
57 RTF_AUTOINIT | RTF_PPC,
58 VERSION,
59 NT_DEVICE,
61 (STRPTR)device_name,
62 (STRPTR)version_string,
63 (APTR)mos_init_table
67 static const struct EmulLibEntry int_trap =
69 TRAP_LIB,
71 (APTR)MOSInt
75 #include "device.c"
78 static const APTR mos_vectors[] =
80 (APTR)FUNCARRAY_32BIT_NATIVE,
81 (APTR)MOSDevOpen,
82 (APTR)MOSDevClose,
83 (APTR)MOSDevExpunge,
84 (APTR)DevReserved,
85 (APTR)MOSDevBeginIO,
86 (APTR)MOSDevAbortIO,
87 (APTR)-1
91 static const APTR mos_init_table[] =
93 (APTR)sizeof(struct DevBase),
94 (APTR)mos_vectors,
95 (APTR)&init_data,
96 (APTR)DevInit
101 /****i* intelpro100.device/MOSDevOpen **************************************
103 * NAME
104 * MOSDevOpen
106 ****************************************************************************
110 static BYTE MOSDevOpen()
112 struct IOSana2Req *request;
113 struct Opener *opener;
114 BYTE error;
116 request = (APTR)REG_A1;
117 error = DevOpen(request, REG_D0, REG_D1, (APTR)REG_A6);
119 /* Set up wrapper hooks to hide 68k emulation */
121 if(error == 0)
123 opener = request->ios2_BufferManagement;
124 opener->real_rx_function = opener->rx_function;
125 opener->real_tx_function = opener->tx_function;
126 opener->rx_function = (APTR)RXFunction;
127 opener->tx_function = (APTR)TXFunction;
128 if(opener->dma_tx_function != NULL)
130 opener->real_dma_tx_function = opener->dma_tx_function;
131 opener->dma_tx_function = (APTR)DMATXFunction;
135 return error;
140 /****i* intelpro100.device/MOSDevClose *************************************
142 * NAME
143 * MOSDevClose
145 ****************************************************************************
149 static APTR MOSDevClose()
151 return DevClose((APTR)REG_A1, (APTR)REG_A6);
156 /****i* intelpro100.device/MOSDevExpunge ***********************************
158 * NAME
159 * MOSDevExpunge
161 ****************************************************************************
165 static APTR MOSDevExpunge()
167 return DevExpunge((APTR)REG_A6);
172 /****i* intelpro100.device/MOSDevBeginIO ***********************************
174 * NAME
175 * MOSDevBeginIO
177 ****************************************************************************
181 static VOID MOSDevBeginIO()
183 struct IOSana2Req *request = (APTR)REG_A1;
185 /* Replace caller's cookie with our own */
187 switch(request->ios2_Req.io_Command)
189 case CMD_READ:
190 case CMD_WRITE:
191 case S2_MULTICAST:
192 case S2_BROADCAST:
193 case S2_READORPHAN:
194 request->ios2_StatData = request->ios2_Data;
195 request->ios2_Data = request;
198 DevBeginIO(request, (APTR)REG_A6);
200 return;
205 /****i* intelpro100.device/MOSDevAbortIO ***********************************
207 * NAME
208 * MOSDevAbortIO -- Try to stop a request.
210 ****************************************************************************
214 static VOID MOSDevAbortIO()
216 DevAbortIO((APTR)REG_A1, (APTR)REG_A6);
221 /****i* intelpro100.device/RXFunction **************************************
223 * NAME
224 * RXFunction
226 ****************************************************************************
230 static BOOL RXFunction(struct IOSana2Req *request, APTR buffer, ULONG size)
232 struct DevBase *base;
233 struct EmulCaos context;
234 struct Opener *opener;
235 APTR cookie;
237 base = (struct DevBase *)request->ios2_Req.io_Device;
238 opener = request->ios2_BufferManagement;
239 cookie = request->ios2_StatData;
240 request->ios2_Data = cookie;
242 context.caos_Un.Function = (APTR)opener->real_rx_function;
243 context.reg_a0 = (ULONG)cookie;
244 context.reg_a1 = (ULONG)buffer;
245 context.reg_d0 = size;
246 return MyEmulHandle->EmulCall68k(&context);
251 /****i* intelpro100.device/TXFunction **************************************
253 * NAME
254 * TXFunction
256 ****************************************************************************
260 static BOOL TXFunction(APTR buffer, struct IOSana2Req *request, ULONG size)
262 struct DevBase *base;
263 struct EmulCaos context;
264 struct Opener *opener;
265 APTR cookie;
267 base = (struct DevBase *)request->ios2_Req.io_Device;
268 opener = request->ios2_BufferManagement;
269 cookie = request->ios2_StatData;
270 request->ios2_Data = cookie;
272 context.caos_Un.Function = (APTR)opener->real_tx_function;
273 context.reg_a0 = (ULONG)buffer;
274 context.reg_a1 = (ULONG)cookie;
275 context.reg_d0 = size;
276 return MyEmulHandle->EmulCall68k(&context);
281 /****i* intelpro100.device/DMATXFunction ***********************************
283 * NAME
284 * DMATXFunction
286 ****************************************************************************
290 static UBYTE *DMATXFunction(struct IOSana2Req *request)
292 struct DevBase *base;
293 struct EmulCaos context;
294 struct Opener *opener;
295 APTR cookie;
297 base = (struct DevBase *)request->ios2_Req.io_Device;
298 opener = request->ios2_BufferManagement;
299 cookie = request->ios2_StatData;
300 request->ios2_Data = cookie;
302 context.caos_Un.Function = (APTR)opener->real_dma_tx_function;
303 context.reg_a0 = (ULONG)cookie;
304 return (UBYTE *)MyEmulHandle->EmulCall68k(&context);
309 /****i* intelpro100.device/MOSInt ******************************************
311 * NAME
312 * MOSInt
314 ****************************************************************************
318 static BOOL MOSInt()
320 APTR *int_data;
321 BOOL (*int_code)(APTR, APTR);
323 int_data = (APTR)REG_A1;
324 int_code = int_data[0];
325 return int_code(int_data[1], int_code);