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 <resources/card.h>
29 #include "initializers.h"
33 #include "device_protos.h"
36 /* Private prototypes */
38 AROS_UFP3(struct DevBase
*, AROSDevInit
,
39 AROS_UFPA(struct DevBase
*, dev_base
, D0
),
40 AROS_UFPA(APTR
, seg_list
, A0
),
41 AROS_UFPA(struct DevBase
*, base
, A6
));
42 AROS_LD3(BYTE
, AROSDevOpen
,
43 AROS_LDA(struct IOSana2Req
*, request
, A1
),
44 AROS_LDA(LONG
, unit_num
, D0
),
45 AROS_LDA(ULONG
, flags
, D1
),
46 struct DevBase
*, base
, 1, S2
);
47 AROS_LD1(APTR
, AROSDevClose
,
48 AROS_LDA(struct IOSana2Req
*, request
, A1
),
49 struct DevBase
*, base
, 2, S2
);
50 AROS_LD0(APTR
, AROSDevExpunge
,
51 struct DevBase
*, base
, 3, S2
);
52 AROS_LD0(APTR
, AROSDevReserved
,
53 struct DevBase
*, base
, 4, S2
);
54 AROS_LD1(VOID
, AROSDevBeginIO
,
55 AROS_LDA(struct IOSana2Req
*, request
, A1
),
56 struct DevBase
*, base
, 5, S2
);
57 AROS_LD1(VOID
, AROSDevAbortIO
,
58 AROS_LDA(struct IOSana2Req
*, request
, A1
),
59 struct DevBase
*, base
, 6, S2
);
60 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
);
61 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
);
62 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
);
64 AROS_CARDP(AROSCardInt
);
66 extern const APTR init_data
;
67 extern const struct Resident rom_tag
;
68 extern const TEXT device_name
[];
69 extern const TEXT version_string
[];
72 static const APTR vectors
[] =
74 (APTR
)AROS_SLIB_ENTRY(AROSDevOpen
, S2
, 1),
75 (APTR
)AROS_SLIB_ENTRY(AROSDevClose
, S2
, 2),
76 (APTR
)AROS_SLIB_ENTRY(AROSDevExpunge
, S2
, 3),
77 (APTR
)AROS_SLIB_ENTRY(AROSDevReserved
, S2
, 4),
78 (APTR
)AROS_SLIB_ENTRY(AROSDevBeginIO
, S2
, 5),
79 (APTR
)AROS_SLIB_ENTRY(AROSDevAbortIO
, S2
, 6),
84 static const APTR init_table
[] =
86 (APTR
)sizeof(struct DevBase
),
93 const struct Resident aros_rom_tag
=
96 (struct Resident
*)&aros_rom_tag
,
103 (TEXT
*)version_string
,
109 /****i* prism2.device/AROSDevInit ******************************************
114 ****************************************************************************
118 AROS_UFH3(struct DevBase
*, AROSDevInit
,
119 AROS_UFHA(struct DevBase
*, dev_base
, D0
),
120 AROS_UFHA(APTR
, seg_list
, A0
),
121 AROS_UFHA(struct DevBase
*, base
, A6
))
125 base
= DevInit(dev_base
, seg_list
, base
);
128 base
->wrapper_int_code
= (APTR
)AROSInt
;
129 base
->wrapper_card_code
= (APTR
)AROSCardInt
;
138 /****i* prism2.device/AROSDevOpen ******************************************
143 ****************************************************************************
147 AROS_LH3(BYTE
, AROSDevOpen
,
148 AROS_LHA(struct IOSana2Req
*, request
, A1
),
149 AROS_LHA(LONG
, unit_num
, D0
),
150 AROS_LHA(ULONG
, flags
, D1
),
151 struct DevBase
*, base
, 1, S2
)
155 struct Opener
*opener
;
158 error
= DevOpen(request
, unit_num
, flags
, base
);
160 /* Set up wrapper hooks to hide register-call functions */
164 opener
= request
->ios2_BufferManagement
;
165 opener
->real_rx_function
= opener
->rx_function
;
166 opener
->real_tx_function
= opener
->tx_function
;
167 opener
->rx_function
= (APTR
)RXFunction
;
168 opener
->tx_function
= (APTR
)TXFunction
;
169 if(opener
->dma_tx_function
!= NULL
)
171 opener
->real_dma_tx_function
= opener
->dma_tx_function
;
172 opener
->dma_tx_function
= (APTR
)DMATXFunction
;
183 /****i* prism2.device/AROSDevClose *****************************************
188 ****************************************************************************
192 AROS_LH1(APTR
, AROSDevClose
,
193 AROS_LHA(struct IOSana2Req
*, request
, A1
),
194 struct DevBase
*, base
, 2, S2
)
198 return DevClose(request
, base
);
205 /****i* prism2.device/AROSDevExpunge ***************************************
210 ****************************************************************************
214 AROS_LH0(APTR
, AROSDevExpunge
,
215 struct DevBase
*, base
, 3, S2
)
219 return DevExpunge(base
);
226 /****i* prism2.device/AROSDevReserved **************************************
231 ****************************************************************************
235 AROS_LH0(APTR
, AROSDevReserved
,
236 struct DevBase
*, base
, 4, S2
)
240 return DevReserved(base
);
247 /****i* prism2.device/AROSDevBeginIO ***************************************
252 ****************************************************************************
256 AROS_LH1(VOID
, AROSDevBeginIO
,
257 AROS_LHA(struct IOSana2Req
*, request
, A1
),
258 struct DevBase
*, base
, 5, S2
)
262 /* Replace caller's cookie with our own */
264 switch(request
->ios2_Req
.io_Command
)
271 request
->ios2_StatData
= request
->ios2_Data
;
272 request
->ios2_Data
= request
;
275 DevBeginIO(request
, base
);
282 /****i* prism2.device/AROSDevAbortIO ***************************************
285 * AROSDevAbortIO -- Try to stop a request.
287 ****************************************************************************
291 AROS_LH1(VOID
, AROSDevAbortIO
,
292 AROS_LHA(struct IOSana2Req
*, request
, A1
),
293 struct DevBase
*, base
, 6, S2
)
297 DevAbortIO(request
, base
);
304 /****i* prism2.device/RXFunction *******************************************
309 ****************************************************************************
313 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
315 struct Opener
*opener
;
318 opener
= request
->ios2_BufferManagement
;
319 cookie
= request
->ios2_StatData
;
320 request
->ios2_Data
= cookie
;
322 return AROS_UFC3(BOOL
, (APTR
)opener
->real_rx_function
,
323 AROS_UFCA(APTR
, cookie
, A0
),
324 AROS_UFCA(APTR
, buffer
, A1
),
325 AROS_UFCA(ULONG
, size
, D0
));
330 /****i* prism2.device/TXFunction *******************************************
335 ****************************************************************************
339 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
341 struct Opener
*opener
;
344 opener
= request
->ios2_BufferManagement
;
345 cookie
= request
->ios2_StatData
;
346 request
->ios2_Data
= cookie
;
348 return AROS_UFC3(BOOL
, (APTR
)opener
->real_tx_function
,
349 AROS_UFCA(APTR
, buffer
, A0
),
350 AROS_UFCA(APTR
, cookie
, A1
),
351 AROS_UFCA(ULONG
, size
, D0
));
356 /****i* prism2.device/DMATXFunction ****************************************
361 ****************************************************************************
365 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
367 struct Opener
*opener
;
370 opener
= request
->ios2_BufferManagement
;
371 cookie
= request
->ios2_StatData
;
372 request
->ios2_Data
= cookie
;
374 return AROS_UFC1(UBYTE
*, (APTR
)opener
->real_dma_tx_function
,
375 AROS_UFCA(APTR
, cookie
, A0
));
380 /****i* prism2.device/AROSInt **********************************************
385 ****************************************************************************
390 AROS_INTH2(AROSInt
, APTR
*, int_data
, mask
)
394 BOOL (*int_code
)(APTR
, APTR
, UBYTE
);
396 int_code
= int_data
[0];
397 return int_code(int_data
[1], int_code
, mask
);
402 /****i* prism2.device/AROSCardInt ******************************************
407 ****************************************************************************
411 AROS_CARDH(AROSCardInt
, APTR
*, int_data
, mask
)
415 BOOL (*int_code
)(APTR
, APTR
, UBYTE
);
417 int_code
= int_data
[0];
418 return int_code(int_data
[1], int_code
, mask
);