2 Copyright © 2002-2009, Chris Hodges. All rights reserved.
3 Copyright © 2010-2012, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
8 #include <proto/utility.h>
9 #include <clib/alib_protos.h>
13 #include "cmd_protos.h"
14 #include "pci_protos.h"
16 #define UtilityBase base->hd_UtilityBase
18 const char devname
[] = MOD_NAME_STRING
;
19 CONST_STRPTR xfer_names
[] = {"CONTROL", "BULK", "ISO", "INT"};
21 static int devInit(LIBBASETYPEPTR base
)
23 KPRINTF(10, ("devInit base: 0x%p SysBase: 0x%p\n", base
, SysBase
));
25 base
->hd_UtilityBase
= (APTR
) OpenLibrary("utility.library", 39);
30 CreatePool(MEMF_PUBLIC
| MEMF_CLEAR
| MEMF_SEM_PROTECTED
, 16384,
34 NewList(&base
->hd_Units
);
36 KPRINTF(10, ("devInit: Ok\n"));
40 KPRINTF(10, ("devInit: CreatePool() failed!\n"));
41 CloseLibrary((struct Library
*)UtilityBase
);
48 ("devInit: OpenLibrary(\"utility.library\", 39) failed!\n"));
52 KPRINTF(10, ("devInit: openCnt = %ld\n", base
->hd_Library
.lib_OpenCnt
));
54 return base
? TRUE
: FALSE
;
58 *===========================================================
59 * devOpen(ioreq, unit, flags, base)
60 *===========================================================
62 * This is the the DEV_OPEN function.
65 static int devOpen(LIBBASETYPEPTR base
, struct IOUsbHWReq
*ioreq
,
66 ULONG unit
, ULONG flags
)
69 ("devOpen ioreq: 0x%p unit: %ld flags: 0x%08lx base: 0x%p\n", ioreq
,
72 KPRINTF(10, ("devOpen: openCnt = %ld\n", base
->hd_Library
.lib_OpenCnt
));
74 if (ioreq
->iouh_Req
.io_Message
.mn_Length
< sizeof(struct IOUsbHWReq
))
76 KPRINTF(20, ("devOpen: invalid MN_LENGTH!\n"));
78 ioreq
->iouh_Req
.io_Error
= IOERR_BADLENGTH
;
82 /* Default to open failure. */
83 ioreq
->iouh_Req
.io_Error
= IOERR_OPENFAIL
;
85 ioreq
->iouh_Req
.io_Unit
= Open_Unit(ioreq
, unit
, base
);
86 if (!ioreq
->iouh_Req
.io_Unit
)
88 KPRINTF(20, ("devOpen: could not open unit!\n"));
93 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
94 ioreq
->iouh_Req
.io_Error
= 0;
105 *===========================================================
106 * devClose(ioreq, base)
107 *===========================================================
109 * This is the the DEV_EXPUNGE function.
113 static int devClose(LIBBASETYPEPTR base
, struct IOUsbHWReq
*ioreq
)
115 KPRINTF(10, ("devClose ioreq: 0x%p base: 0x%p\n", ioreq
, base
));
117 Close_Unit(base
, (struct PCIUnit
*)ioreq
->iouh_Req
.io_Unit
, ioreq
);
119 ioreq
->iouh_Req
.io_Unit
= (APTR
) - 1;
120 ioreq
->iouh_Req
.io_Device
= (APTR
) - 1;
125 static int devExpunge(LIBBASETYPEPTR base
)
129 DeletePool(base
->hd_MemPool
);
131 KPRINTF(5, ("devExpunge: closelibrary utilitybase 0x%p\n",
133 CloseLibrary((struct Library
*)UtilityBase
);
137 ADD2INITLIB(devInit
, 0)
138 ADD2OPENDEV(devOpen
, 0)
139 ADD2CLOSEDEV(devClose
, 0) ADD2EXPUNGELIB(devExpunge
, 0)
142 *===========================================================
143 * devBeginIO(ioreq, base)
144 *===========================================================
146 * This is the DEV_BEGINIO vector of the device.
149 AROS_LH1(void, devBeginIO
,
150 AROS_LHA(struct IOUsbHWReq
*, ioreq
, A1
), LIBBASETYPEPTR
, base
, 5, ohci
)
154 struct PCIUnit
*unit
= (struct PCIUnit
*)ioreq
->iouh_Req
.io_Unit
;
157 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
158 ioreq
->iouh_Req
.io_Error
= UHIOERR_NO_ERROR
;
160 if (ioreq
->iouh_Req
.io_Command
< NSCMD_DEVICEQUERY
)
162 switch (ioreq
->iouh_Req
.io_Command
)
165 ret
= cmdReset(ioreq
, unit
, base
);
169 ret
= cmdFlush(ioreq
, unit
, base
);
172 case UHCMD_QUERYDEVICE
:
173 ret
= cmdQueryDevice(ioreq
, unit
, base
);
177 ret
= cmdUsbReset(ioreq
, unit
, base
);
180 case UHCMD_USBRESUME
:
181 ret
= cmdUsbResume(ioreq
, unit
, base
);
184 case UHCMD_USBSUSPEND
:
185 ret
= cmdUsbSuspend(ioreq
, unit
, base
);
189 ret
= cmdUsbOper(ioreq
, unit
, base
);
192 case UHCMD_CONTROLXFER
:
193 ret
= cmdXFer(ioreq
, unit
, base
);
197 ret
= cmdXFer(ioreq
, unit
, base
);
201 ret
= cmdXFer(ioreq
, unit
, base
);
205 ret
= cmdXFer(ioreq
, unit
, base
);
215 switch (ioreq
->iouh_Req
.io_Command
)
217 case NSCMD_DEVICEQUERY
:
218 ret
= cmdNSDeviceQuery((struct IOStdReq
*)ioreq
, unit
, base
);
227 if (ret
!= RC_DONTREPLY
)
229 KPRINTF(1, ("TermIO\n"));
232 /* Set error codes */
233 ioreq
->iouh_Req
.io_Error
= ret
& 0xff;
235 /* Terminate the iorequest */
243 *===========================================================
244 * devAbortIO(ioreq, base)
245 *===========================================================
247 * This is the DEV_ABORTIO vector of the device. It abort
248 * the given iorequest, and set
251 AROS_LH1(LONG
, devAbortIO
,
252 AROS_LHA(struct IOUsbHWReq
*, ioreq
, A1
), LIBBASETYPEPTR
, base
, 6, ohci
)
256 KPRINTF(50, ("devAbortIO ioreq: 0x%p, command %ld, status %ld\n",
257 ioreq
, ioreq
->iouh_Req
.io_Command
,
258 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
));
261 if (ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
== NT_MESSAGE
)
263 if (cmdAbortIO(ioreq
, base
))