1 /* dev.c - pciusb.device by Chris Hodges
6 #include <proto/exec.h>
7 #include <proto/utility.h>
11 #define DEVNAME "pciusb.device"
13 #define NewList NEWLIST
15 const char devname
[] = MOD_NAME_STRING
;
17 static int devInit(LIBBASETYPEPTR base
)
19 KPRINTF(10, ("devInit base: 0x%p SysBase: 0x%p\n",
22 base
->hd_UtilityBase
= (struct UtilityBase
*) OpenLibrary("utility.library", 39);
24 #define UtilityBase base->hd_UtilityBase
28 base
->hd_MemPool
= CreatePool(MEMF_PUBLIC
| MEMF_CLEAR
| MEMF_SEM_PROTECTED
,
32 NewList(&base
->hd_Units
);
34 KPRINTF(10, ("devInit: Ok\n"));
36 KPRINTF(10, ("devInit: CreatePool() failed!\n"));
37 CloseLibrary((struct Library
*) UtilityBase
);
41 KPRINTF(10, ("devInit: OpenLibrary(\"utility.library\", 39) failed!\n"));
45 KPRINTF(10, ("devInit: openCnt = %ld\n", base
->hd_Library
.lib_OpenCnt
));
47 return base
? TRUE
: FALSE
;
51 *===========================================================
52 * devOpen(ioreq, unit, flags, base)
53 *===========================================================
55 * This is the the DEV_OPEN function.
58 static int devOpen(LIBBASETYPEPTR base
, struct IOUsbHWReq
*ioreq
, ULONG unit
, ULONG flags
)
60 KPRINTF(10, ("devOpen ioreq: 0x%p unit: %ld flags: 0x%08lx base: 0x%p\n",
61 ioreq
, unit
, flags
, base
));
63 KPRINTF(10, ("devOpen: openCnt = %ld\n", base
->hd_Library
.lib_OpenCnt
));
65 if(ioreq
->iouh_Req
.io_Message
.mn_Length
< sizeof(struct IOUsbHWReq
))
67 KPRINTF(20, ("devOpen: invalid MN_LENGTH!\n"));
69 ioreq
->iouh_Req
.io_Error
= IOERR_BADLENGTH
;
71 /* Default to open failure. */
72 ioreq
->iouh_Req
.io_Error
= IOERR_OPENFAIL
;
74 ioreq
->iouh_Req
.io_Unit
= Open_Unit(ioreq
, unit
, base
);
75 if(!ioreq
->iouh_Req
.io_Unit
)
77 KPRINTF(20, ("devOpen: could not open unit!\n"));
80 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
81 ioreq
->iouh_Req
.io_Error
= 0;
92 *===========================================================
93 * devClose(ioreq, base)
94 *===========================================================
96 * This is the the DEV_EXPUNGE function.
100 static int devClose(LIBBASETYPEPTR base
, struct IOUsbHWReq
*ioreq
)
102 KPRINTF(10, ("devClose ioreq: 0x%p base: 0x%p\n", ioreq
, base
));
104 Close_Unit(base
, (struct PCIUnit
*) ioreq
->iouh_Req
.io_Unit
, ioreq
);
106 ioreq
->iouh_Req
.io_Unit
= (APTR
) -1;
107 ioreq
->iouh_Req
.io_Device
= (APTR
) -1;
112 static int devExpunge(LIBBASETYPEPTR base
)
116 DeletePool(base
->hd_MemPool
);
118 KPRINTF(5, ("devExpunge: closelibrary utilitybase 0x%p\n",
120 CloseLibrary((struct Library
*) UtilityBase
);
124 ADD2INITLIB(devInit
, 0)
125 ADD2OPENDEV(devOpen
, 0)
126 ADD2CLOSEDEV(devClose
, 0)
127 ADD2EXPUNGELIB(devExpunge
, 0)
130 *===========================================================
131 * devBeginIO(ioreq, base)
132 *===========================================================
134 * This is the DEV_BEGINIO vector of the device.
137 AROS_LH1(void, devBeginIO
,
138 AROS_LHA(struct IOUsbHWReq
*, ioreq
, A1
),
139 LIBBASETYPEPTR
, base
, 5, pciusb
)
143 struct PCIUnit
*unit
= (struct PCIUnit
*) ioreq
->iouh_Req
.io_Unit
;
146 //KPRINTF(1, ("devBeginIO ioreq: 0x%08lx base: 0x%08lx cmd: %lu\n", ioreq, base, ioreq->iouh_Req.io_Command));
148 ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
149 ioreq
->iouh_Req
.io_Error
= UHIOERR_NO_ERROR
;
151 if (ioreq
->iouh_Req
.io_Command
< NSCMD_DEVICEQUERY
)
153 switch (ioreq
->iouh_Req
.io_Command
)
156 ret
= cmdReset(ioreq
, unit
, base
);
160 ret
= cmdFlush(ioreq
, unit
, base
);
163 case UHCMD_QUERYDEVICE
:
164 ret
= cmdQueryDevice(ioreq
, unit
, base
);
168 ret
= cmdUsbReset(ioreq
, unit
, base
);
171 case UHCMD_USBRESUME
:
172 ret
= cmdUsbResume(ioreq
, unit
, base
);
175 case UHCMD_USBSUSPEND
:
176 ret
= cmdUsbSuspend(ioreq
, unit
, base
);
180 ret
= cmdUsbOper(ioreq
, unit
, base
);
183 case UHCMD_CONTROLXFER
:
184 ret
= cmdControlXFer(ioreq
, unit
, base
);
188 ret
= cmdBulkXFer(ioreq
, unit
, base
);
192 ret
= cmdIntXFer(ioreq
, unit
, base
);
196 ret
= cmdIsoXFer(ioreq
, unit
, base
);
204 switch(ioreq
->iouh_Req
.io_Command
)
206 case NSCMD_DEVICEQUERY
:
207 ret
= cmdNSDeviceQuery((struct IOStdReq
*) ioreq
, unit
, base
);
216 if(ret
!= RC_DONTREPLY
)
218 KPRINTF(1, ("TermIO\n"));
221 /* Set error codes */
222 ioreq
->iouh_Req
.io_Error
= ret
& 0xff;
224 /* Terminate the iorequest */
232 *===========================================================
233 * devAbortIO(ioreq, base)
234 *===========================================================
236 * This is the DEV_ABORTIO vector of the device. It abort
237 * the given iorequest, and set
240 AROS_LH1(LONG
, devAbortIO
,
241 AROS_LHA(struct IOUsbHWReq
*, ioreq
, A1
),
242 LIBBASETYPEPTR
, base
, 6, pciusb
)
246 KPRINTF(50, ("devAbortIO ioreq: 0x%p, command %ld, status %ld\n", ioreq
, ioreq
->iouh_Req
.io_Command
, ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
));
249 if(ioreq
->iouh_Req
.io_Message
.mn_Node
.ln_Type
== NT_MESSAGE
)
251 if(cmdAbortIO(ioreq
, base
))