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)
141 *===========================================================
142 * devBeginIO(ioreq, base)
143 *===========================================================
145 * This is the DEV_BEGINIO vector of the device.
148 AROS_LH1(void, devBeginIO
,
149 AROS_LHA(struct IOUsbHWReq
*, ioreq
, A1
), LIBBASETYPEPTR
, base
, 5, ohci
)
152 struct PCIUnit
*unit
= (struct PCIUnit
*)ioreq
->iouh_Req
.io_Unit
;
155 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
156 ioreq
->iouh_Req
.io_Error
= UHIOERR_NO_ERROR
;
158 if (ioreq
->iouh_Req
.io_Command
< NSCMD_DEVICEQUERY
)
160 switch (ioreq
->iouh_Req
.io_Command
)
163 ret
= cmdReset(ioreq
, unit
, base
);
167 ret
= cmdFlush(ioreq
, unit
, base
);
170 case UHCMD_QUERYDEVICE
:
171 ret
= cmdQueryDevice(ioreq
, unit
, base
);
175 ret
= cmdUsbReset(ioreq
, unit
, base
);
178 case UHCMD_USBRESUME
:
179 ret
= cmdUsbResume(ioreq
, unit
, base
);
182 case UHCMD_USBSUSPEND
:
183 ret
= cmdUsbSuspend(ioreq
, unit
, base
);
187 ret
= cmdUsbOper(ioreq
, unit
, base
);
190 case UHCMD_CONTROLXFER
:
191 ret
= cmdXFer(ioreq
, unit
, base
);
195 ret
= cmdXFer(ioreq
, unit
, base
);
199 ret
= cmdXFer(ioreq
, unit
, base
);
203 ret
= cmdXFer(ioreq
, unit
, base
);
213 switch (ioreq
->iouh_Req
.io_Command
)
215 case NSCMD_DEVICEQUERY
:
216 ret
= cmdNSDeviceQuery((struct IOStdReq
*)ioreq
, unit
, base
);
225 if (ret
!= RC_DONTREPLY
)
227 KPRINTF(1, ("TermIO\n"));
230 /* Set error codes */
231 ioreq
->iouh_Req
.io_Error
= ret
& 0xff;
233 /* Terminate the iorequest */
240 *===========================================================
241 * devAbortIO(ioreq, base)
242 *===========================================================
244 * This is the DEV_ABORTIO vector of the device. It abort
245 * the given iorequest, and set
248 AROS_LH1(LONG
, devAbortIO
,
249 AROS_LHA(struct IOUsbHWReq
*, ioreq
, A1
), LIBBASETYPEPTR
, base
, 6, ohci
)
252 KPRINTF(50, ("devAbortIO ioreq: 0x%p, command %ld, status %ld\n",
253 ioreq
, ioreq
->iouh_Req
.io_Command
,
254 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
));
257 if (ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
== NT_MESSAGE
)
259 if (cmdAbortIO(ioreq
, base
))