3 Copyright (C) 2011,2012 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,
23 #include <exec/types.h>
24 #include <exec/resident.h>
25 #include <aros/asmcall.h>
26 #include <aros/libcall.h>
27 #include "initializers.h"
31 #include "device_protos.h"
34 /* Private prototypes */
36 AROS_UFP3(struct DevBase
*, AROSDevInit
,
37 AROS_UFPA(struct DevBase
*, dev_base
, D0
),
38 AROS_UFPA(APTR
, seg_list
, A0
),
39 AROS_UFPA(struct DevBase
*, base
, A6
));
40 AROS_LD3(BYTE
, AROSDevOpen
,
41 AROS_LDA(struct IOSana2Req
*, request
, A1
),
42 AROS_LDA(LONG
, unit_num
, D0
),
43 AROS_LDA(ULONG
, flags
, D1
),
44 struct DevBase
*, base
, 1, S2
);
45 AROS_LD1(APTR
, AROSDevClose
,
46 AROS_LDA(struct IOSana2Req
*, request
, A1
),
47 struct DevBase
*, base
, 2, S2
);
48 AROS_LD0(APTR
, AROSDevExpunge
,
49 struct DevBase
*, base
, 3, S2
);
50 AROS_LD0(APTR
, AROSDevReserved
,
51 struct DevBase
*, base
, 4, S2
);
52 AROS_LD1(VOID
, AROSDevBeginIO
,
53 AROS_LDA(struct IOSana2Req
*, request
, A1
),
54 struct DevBase
*, base
, 5, S2
);
55 AROS_LD1(VOID
, AROSDevAbortIO
,
56 AROS_LDA(struct IOSana2Req
*, request
, A1
),
57 struct DevBase
*, base
, 6, S2
);
58 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
);
59 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
);
60 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
);
63 extern const APTR init_data
;
64 extern const struct Resident rom_tag
;
65 extern const TEXT device_name
[];
66 extern const TEXT version_string
[];
69 static const APTR vectors
[] =
71 (APTR
)AROS_SLIB_ENTRY(AROSDevOpen
, S2
, 1),
72 (APTR
)AROS_SLIB_ENTRY(AROSDevClose
, S2
, 2),
73 (APTR
)AROS_SLIB_ENTRY(AROSDevExpunge
, S2
, 3),
74 (APTR
)AROS_SLIB_ENTRY(AROSDevReserved
, S2
, 4),
75 (APTR
)AROS_SLIB_ENTRY(AROSDevBeginIO
, S2
, 5),
76 (APTR
)AROS_SLIB_ENTRY(AROSDevAbortIO
, S2
, 6),
81 static const APTR init_table
[] =
83 (APTR
)sizeof(struct DevBase
),
90 const struct Resident aros_rom_tag
=
93 (struct Resident
*)&aros_rom_tag
,
100 (TEXT
*)version_string
,
106 /****i* rhine.device/AROSDevInit *******************************************
111 ****************************************************************************
115 AROS_UFH3(struct DevBase
*, AROSDevInit
,
116 AROS_UFHA(struct DevBase
*, dev_base
, D0
),
117 AROS_UFHA(APTR
, seg_list
, A0
),
118 AROS_UFHA(struct DevBase
*, base
, A6
))
122 base
= DevInit(dev_base
, seg_list
, base
);
125 base
->wrapper_int_code
= (APTR
)AROSInt
;
133 /****i* rhine.device/AROSDevOpen *******************************************
138 ****************************************************************************
142 AROS_LH3(BYTE
, AROSDevOpen
,
143 AROS_LHA(struct IOSana2Req
*, request
, A1
),
144 AROS_LHA(LONG
, unit_num
, D0
),
145 AROS_LHA(ULONG
, flags
, D1
),
146 struct DevBase
*, base
, 1, S2
)
150 struct Opener
*opener
;
153 error
= DevOpen(request
, unit_num
, flags
, base
);
155 /* Set up wrapper hooks to hide register-call functions */
159 opener
= request
->ios2_BufferManagement
;
160 opener
->real_rx_function
= opener
->rx_function
;
161 opener
->real_tx_function
= opener
->tx_function
;
162 opener
->rx_function
= (APTR
)RXFunction
;
163 opener
->tx_function
= (APTR
)TXFunction
;
164 if(opener
->dma_tx_function
!= NULL
)
166 opener
->real_dma_tx_function
= opener
->dma_tx_function
;
167 opener
->dma_tx_function
= (APTR
)DMATXFunction
;
178 /****i* rhine.device/AROSDevClose ******************************************
183 ****************************************************************************
187 AROS_LH1(APTR
, AROSDevClose
,
188 AROS_LHA(struct IOSana2Req
*, request
, A1
),
189 struct DevBase
*, base
, 2, S2
)
193 return DevClose(request
, base
);
200 /****i* rhine.device/AROSDevExpunge ****************************************
205 ****************************************************************************
209 AROS_LH0(APTR
, AROSDevExpunge
,
210 struct DevBase
*, base
, 3, S2
)
214 return DevExpunge(base
);
221 /****i* rhine.device/AROSDevReserved ***************************************
226 ****************************************************************************
230 AROS_LH0(APTR
, AROSDevReserved
,
231 struct DevBase
*, base
, 4, S2
)
235 return DevReserved(base
);
242 /****i* rhine.device/AROSDevBeginIO ****************************************
247 ****************************************************************************
251 AROS_LH1(VOID
, AROSDevBeginIO
,
252 AROS_LHA(struct IOSana2Req
*, request
, A1
),
253 struct DevBase
*, base
, 5, S2
)
257 /* Replace caller's cookie with our own */
259 switch(request
->ios2_Req
.io_Command
)
266 request
->ios2_StatData
= request
->ios2_Data
;
267 request
->ios2_Data
= request
;
270 DevBeginIO(request
, base
);
277 /****i* rhine.device/AROSDevAbortIO ****************************************
280 * AROSDevAbortIO -- Try to stop a request.
282 ****************************************************************************
286 AROS_LH1(VOID
, AROSDevAbortIO
,
287 AROS_LHA(struct IOSana2Req
*, request
, A1
),
288 struct DevBase
*, base
, 6, S2
)
292 DevAbortIO(request
, base
);
299 /****i* rhine.device/RXFunction ********************************************
304 ****************************************************************************
308 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
310 struct Opener
*opener
;
313 opener
= request
->ios2_BufferManagement
;
314 cookie
= request
->ios2_StatData
;
315 request
->ios2_Data
= cookie
;
317 return AROS_UFC3(BOOL
, (APTR
)opener
->real_rx_function
,
318 AROS_UFCA(APTR
, cookie
, A0
),
319 AROS_UFCA(APTR
, buffer
, A1
),
320 AROS_UFCA(ULONG
, size
, D0
));
325 /****i* rhine.device/TXFunction ********************************************
330 ****************************************************************************
334 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
336 struct Opener
*opener
;
339 opener
= request
->ios2_BufferManagement
;
340 cookie
= request
->ios2_StatData
;
341 request
->ios2_Data
= cookie
;
343 return AROS_UFC3(BOOL
, (APTR
)opener
->real_tx_function
,
344 AROS_UFCA(APTR
, buffer
, A0
),
345 AROS_UFCA(APTR
, cookie
, A1
),
346 AROS_UFCA(ULONG
, size
, D0
));
351 /****i* rhine.device/DMATXFunction *****************************************
356 ****************************************************************************
360 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
362 struct Opener
*opener
;
365 opener
= request
->ios2_BufferManagement
;
366 cookie
= request
->ios2_StatData
;
367 request
->ios2_Data
= cookie
;
369 return AROS_UFC1(UBYTE
*, (APTR
)opener
->real_dma_tx_function
,
370 AROS_UFCA(APTR
, cookie
, A0
));
375 /****i* rhine.device/AROSInt ***********************************************
380 ****************************************************************************
385 AROS_INTH2(AROSInt
, APTR
*, int_data
, mask
)
389 BOOL (*int_code
)(APTR
, APTR
, UBYTE
);
391 int_code
= int_data
[0];
392 return int_code(int_data
[1], int_code
, mask
);