21 if ( devId >= usbConfig.m_maxDevices )
25 dev = &memPool->m_deviceTreeBuf[devId];
39 if (
id >= usbConfig.m_maxEndpoints )
43 ep = &memPool->m_endpointBuf[id];
44 if ( !ep->m_correspDevice )
51 return memPool->m_deviceTreeRoot;
58 newDev = memPool->m_freeDeviceListStart;
61 dbg_printf(
"Ran out of device handles\n");
65 newDev->m_next->m_prev = newDev->m_prev;
67 memPool->m_freeDeviceListEnd = newDev->m_prev;
69 newDev->m_prev->m_next = newDev->m_next;
71 memPool->m_freeDeviceListStart = newDev->m_next;
72 newDev->m_endpointListEnd = NULL;
73 newDev->m_endpointListStart = NULL;
74 newDev->m_devDriver = NULL;
75 newDev->m_deviceStatus = DEVICE_NOTCONNECTED;
76 newDev->m_resetFlag = 0;
77 newDev->m_magicPowerValue = 0;
78 newDev->m_childListEnd = NULL;
79 newDev->m_childListStart = NULL;
80 newDev->m_parent = parent;
81 newDev->m_attachedToPortNo = portNum;
82 newDev->m_privDataField = NULL;
85 newDev->m_prev = parent->m_childListEnd;
86 if ( parent->m_childListEnd )
87 parent->m_childListEnd->m_next = newDev;
89 parent->m_childListStart = newDev;
90 newDev->m_next = NULL;
91 parent->m_childListEnd = newDev;
98 if ( !dev || dev < memPool->m_deviceTreeBuf || dev >= memPool->m_deviceTreeBuf + usbConfig.m_maxDevices )
100 dbg_printf(
"freeDevice %p: Arg is not part of dev buffer\n", dev);
103 dev->m_prev = memPool->m_freeDeviceListEnd;
104 if ( memPool->m_freeDeviceListEnd )
105 memPool->m_freeDeviceListEnd->m_next = dev;
107 memPool->m_freeDeviceListStart = dev;
109 memPool->m_freeDeviceListEnd = dev;
110 dev->m_parent = NULL;
117 res = memPool->m_freeIoReqList;
120 dbg_printf(
"ran out of IoReqs\n");
124 res->m_next->m_prev = res->m_prev;
126 memPool->m_freeIoReqListEnd = res->m_prev;
128 res->m_prev->m_next = res->m_next;
130 memPool->m_freeIoReqList = res->m_next;
142 if ( req < memPool->m_ioReqBufPtr || req >= memPool->m_ioReqBufPtr + usbConfig.m_maxIoReqs )
147 for ( pos = memPool->m_freeIoReqList; pos && pos != req; pos = pos->m_next )
152 dbg_printf(
"freeIoRequest %p: already free.\n", req);
156 req->m_prev = memPool->m_freeIoReqListEnd;
157 if ( memPool->m_freeIoReqListEnd )
158 memPool->m_freeIoReqListEnd->m_next = req;
160 memPool->m_freeIoReqList = req;
162 memPool->m_freeIoReqListEnd = req;
169 newEp = memPool->m_freeEpListStart;
175 newEp->m_next->m_prev = newEp->m_prev;
177 memPool->m_freeEpListEnd = newEp->m_prev;
179 newEp->m_prev->m_next = newEp->m_next;
181 memPool->m_freeEpListStart = newEp->m_next;
182 newEp->m_correspDevice = dev;
183 newEp->m_ioReqListEnd = NULL;
184 newEp->m_ioReqListStart = NULL;
185 newEp->m_busyPrev = NULL;
186 newEp->m_busyNext = NULL;
187 newEp->m_inTdQueue = 0;
188 newEp->m_alignFlag = align;
189 newEp->m_prev = dev->m_endpointListEnd;
190 if ( dev->m_endpointListEnd )
191 dev->m_endpointListEnd->m_next = newEp;
193 dev->m_endpointListStart = newEp;
194 newEp->m_next = NULL;
195 dev->m_endpointListEnd = newEp;
201 if ( !ep || ep < memPool->m_endpointBuf || ep >= memPool->m_endpointBuf + usbConfig.m_maxEndpoints )
205 if ( ep->m_inTdQueue != NOTIN_QUEUE )
207 if ( ep->m_busyNext )
208 ep->m_busyNext->m_busyPrev = ep->m_busyPrev;
210 memPool->m_tdQueueEnd = ep->m_busyPrev;
211 if ( ep->m_busyPrev )
212 ep->m_busyPrev->m_busyNext = ep->m_busyNext;
214 memPool->m_tdQueueStart = ep->m_busyNext;
215 ep->m_inTdQueue = NOTIN_QUEUE;
218 ep->m_next->m_prev = ep->m_prev;
220 dev->m_endpointListEnd = ep->m_prev;
222 ep->m_prev->m_next = ep->m_next;
224 dev->m_endpointListStart = ep->m_next;
225 ep->m_prev = memPool->m_freeEpListEnd;
226 if ( memPool->m_freeEpListEnd )
227 memPool->m_freeEpListEnd->m_next = ep;
229 memPool->m_freeEpListStart = ep;
231 memPool->m_freeEpListEnd = ep;
232 ep->m_correspDevice = NULL;
240 res = memPool->m_freeHcTdList;
245 memPool->m_freeHcTdList = res->m_next;
258 for ( pos = memPool->m_freeHcTdList; pos && argTd != pos; pos = pos->m_next )
263 dbg_printf(
"FreeTD %p: already free\n", argTd);
266 argTd->m_next = memPool->m_freeHcTdList;
267 memPool->m_freeHcTdList = argTd;
274 newTd = memPool->m_freeHcIsoTdList;
279 memPool->m_freeHcIsoTdList = newTd->m_next;
280 newTd->m_next = NULL;
292 for ( pos = memPool->m_freeHcIsoTdList; pos && argTd != pos; pos = pos->m_next )
297 dbg_printf(
"freeIsoTd %p: already free\n", argTd);
300 argTd->m_next = memPool->m_freeHcIsoTdList;
301 memPool->m_freeHcIsoTdList = argTd;