Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / usb / pciusb / dev.c
blob6e1905685bbf38f3f059448ce7c1e23f99333107
1 /* dev.c - pciusb.device by Chris Hodges
2 */
4 #include "debug.h"
6 #include <proto/exec.h>
7 #include <proto/utility.h>
9 #include "uhwcmd.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",
20 base, SysBase));
22 base->hd_UtilityBase = (struct UtilityBase *) OpenLibrary("utility.library", 39);
24 #define UtilityBase base->hd_UtilityBase
26 if(UtilityBase)
28 base->hd_MemPool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR | MEMF_SEM_PROTECTED,
29 16384, 4096);
30 if(base->hd_MemPool)
32 NewList(&base->hd_Units);
34 KPRINTF(10, ("devInit: Ok\n"));
35 } else {
36 KPRINTF(10, ("devInit: CreatePool() failed!\n"));
37 CloseLibrary((struct Library *) UtilityBase);
38 base = NULL;
40 } else {
41 KPRINTF(10, ("devInit: OpenLibrary(\"utility.library\", 39) failed!\n"));
42 base = NULL;
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;
70 } else {
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"));
78 } else {
79 /* Opended ok! */
80 ioreq->iouh_Req.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
81 ioreq->iouh_Req.io_Error = 0;
83 return TRUE;
87 return FALSE;
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;
108 return TRUE;
112 static int devExpunge(LIBBASETYPEPTR base)
114 pciExpunge(base);
116 DeletePool(base->hd_MemPool);
118 KPRINTF(5, ("devExpunge: closelibrary utilitybase 0x%p\n",
119 UtilityBase));
120 CloseLibrary((struct Library *) UtilityBase);
121 return TRUE;
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)
141 AROS_LIBFUNC_INIT
143 struct PCIUnit *unit = (struct PCIUnit *) ioreq->iouh_Req.io_Unit;
144 WORD ret;
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)
155 case CMD_RESET:
156 ret = cmdReset(ioreq, unit, base);
157 break;
159 case CMD_FLUSH:
160 ret = cmdFlush(ioreq, unit, base);
161 break;
163 case UHCMD_QUERYDEVICE:
164 ret = cmdQueryDevice(ioreq, unit, base);
165 break;
167 case UHCMD_USBRESET:
168 ret = cmdUsbReset(ioreq, unit, base);
169 break;
171 case UHCMD_USBRESUME:
172 ret = cmdUsbResume(ioreq, unit, base);
173 break;
175 case UHCMD_USBSUSPEND:
176 ret = cmdUsbSuspend(ioreq, unit, base);
177 break;
179 case UHCMD_USBOPER:
180 ret = cmdUsbOper(ioreq, unit, base);
181 break;
183 case UHCMD_CONTROLXFER:
184 ret = cmdControlXFer(ioreq, unit, base);
185 break;
187 case UHCMD_BULKXFER:
188 ret = cmdBulkXFer(ioreq, unit, base);
189 break;
191 case UHCMD_INTXFER:
192 ret = cmdIntXFer(ioreq, unit, base);
193 break;
195 case UHCMD_ISOXFER:
196 ret = cmdIsoXFer(ioreq, unit, base);
197 break;
199 default:
200 ret = IOERR_NOCMD;
201 break;
203 } else {
204 switch(ioreq->iouh_Req.io_Command)
206 case NSCMD_DEVICEQUERY:
207 ret = cmdNSDeviceQuery((struct IOStdReq *) ioreq, unit, base);
208 break;
210 default:
211 ret = IOERR_NOCMD;
212 break;
216 if(ret != RC_DONTREPLY)
218 KPRINTF(1, ("TermIO\n"));
219 if (ret != RC_OK)
221 /* Set error codes */
222 ioreq->iouh_Req.io_Error = ret & 0xff;
224 /* Terminate the iorequest */
225 TermIO(ioreq, base);
228 AROS_LIBFUNC_EXIT
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)
244 AROS_LIBFUNC_INIT
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));
248 /* Is it pending? */
249 if(ioreq->iouh_Req.io_Message.mn_Node.ln_Type == NT_MESSAGE)
251 if(cmdAbortIO(ioreq, base))
253 return(0);
256 return(-1);
258 AROS_LIBFUNC_EXIT