Changeset 46730 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jun 21, 2013 10:53:46 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/UsbMouse.cpp
r46516 r46730 120 120 typedef struct USBHID 121 121 { 122 /** Pointer back to the PDM USB Device instance structure. */123 PPDMUSBINS pUsbIns;122 /** USB device instance number. */ 123 uint32_t iInstance; 124 124 /** Critical section protecting the device state. */ 125 125 RTCRITSECT CritSect; … … 634 634 static int usbHidCompleteStall(PUSBHID pThis, PUSBHIDEP pEp, PVUSBURB pUrb, const char *pszWhy) 635 635 { 636 Log(("usbHidCompleteStall/#%u: pUrb=%p:%s: %s\n", pThis-> pUsbIns->iInstance, pUrb, pUrb->pszDesc, pszWhy));636 Log(("usbHidCompleteStall/#%u: pUrb=%p:%s: %s\n", pThis->iInstance, pUrb, pUrb->pszDesc, pszWhy)); 637 637 638 638 pUrb->enmStatus = VUSBSTATUS_STALL; … … 657 657 static int usbHidCompleteOk(PUSBHID pThis, PVUSBURB pUrb, size_t cbData) 658 658 { 659 Log(("usbHidCompleteOk/#%u: pUrb=%p:%s cbData=%#zx\n", pThis-> pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData));659 Log(("usbHidCompleteOk/#%u: pUrb=%p:%s cbData=%#zx\n", pThis->iInstance, pUrb, pUrb->pszDesc, cbData)); 660 660 661 661 pUrb->enmStatus = VUSBSTATUS_OK; … … 859 859 } 860 860 861 /** 862 * @copydoc PDMUSBREG::pfnUrbReap 863 */ 864 static DECLCALLBACK(PVUSBURB) usbHidUrbReap(PPDMUSBINS pUsbIns, RTMSINTERVAL cMillies) 865 { 866 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 867 LogFlow(("usbHidUrbReap/#%u: cMillies=%u\n", pUsbIns->iInstance, cMillies)); 868 861 862 static PVUSBURB usbHidUrbReapCore(PUSBHID pThis, RTMSINTERVAL cMillies) 863 { 869 864 RTCritSectEnter(&pThis->CritSect); 870 865 … … 887 882 888 883 if (pUrb) 889 Log(("usbHidUrbReap/#%u: pUrb=%p:%s\n", p UsbIns->iInstance, pUrb, pUrb->pszDesc));884 Log(("usbHidUrbReap/#%u: pUrb=%p:%s\n", pThis->iInstance, pUrb, pUrb->pszDesc)); 890 885 return pUrb; 891 886 } … … 893 888 894 889 /** 895 * @copydoc PDMUSBREG::pfnUrbCancel 896 */ 897 static DECLCALLBACK(int) usbHidUrbCancel(PPDMUSBINS pUsbIns, PVUSBURB pUrb) 890 * @copydoc PDMUSBREG::pfnUrbReap 891 */ 892 static DECLCALLBACK(PVUSBURB) usbHidUrbReap(PPDMUSBINS pUsbIns, 893 RTMSINTERVAL cMillies) 898 894 { 899 895 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 900 LogFlow(("usbHidUrbCancel/#%u: pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc)); 896 LogFlow(("usbHidUrbReap/#%u: cMillies=%u\n", pThis->iInstance, cMillies)); 897 return usbHidUrbReapCore(pThis, cMillies); 898 } 899 900 901 static int usbHidUrbCancelCore(PUSBHID pThis, PVUSBURB pUrb) 902 { 901 903 RTCritSectEnter(&pThis->CritSect); 902 904 … … 911 913 } 912 914 915 916 /** 917 * @copydoc PDMUSBREG::pfnUrbCancel 918 */ 919 static DECLCALLBACK(int) usbHidUrbCancel(PPDMUSBINS pUsbIns, PVUSBURB pUrb) 920 { 921 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 922 LogFlow(("usbHidUrbCancel/#%u: pUrb=%p:%s\n", pThis->iInstance, pUrb, 923 pUrb->pszDesc)); 924 return usbHidUrbCancelCore(pThis, pUrb); 925 } 913 926 914 927 /** … … 1149 1162 1150 1163 1151 /** 1152 * @copydoc PDMUSBREG::pfnUrbQueue 1153 */ 1154 static DECLCALLBACK(int) usbHidQueue(PPDMUSBINS pUsbIns, PVUSBURB pUrb) 1155 { 1156 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1157 LogFlow(("usbHidQueue/#%u: pUrb=%p:%s EndPt=%#x\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->EndPt)); 1164 static int usbHidQueueCore(PUSBHID pThis, PVUSBURB pUrb) 1165 { 1158 1166 RTCritSectEnter(&pThis->CritSect); 1159 1167 … … 1186 1194 1187 1195 /** 1188 * @copydoc PDMUSBREG::pfnU sbClearHaltedEndpoint1189 */ 1190 static DECLCALLBACK(int) usbHid UsbClearHaltedEndpoint(PPDMUSBINS pUsbIns, unsigned uEndpoint)1196 * @copydoc PDMUSBREG::pfnUrbQueue 1197 */ 1198 static DECLCALLBACK(int) usbHidQueue(PPDMUSBINS pUsbIns, PVUSBURB pUrb) 1191 1199 { 1192 1200 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1193 LogFlow(("usbHidUsbClearHaltedEndpoint/#%u: uEndpoint=%#x\n", pUsbIns->iInstance, uEndpoint)); 1194 1201 LogFlow(("usbHidQueue/#%u: pUrb=%p:%s EndPt=%#x\n", pUsbIns->iInstance, 1202 pUrb, pUrb->pszDesc, pUrb->EndPt)); 1203 return usbHidQueueCore(pThis, pUrb); 1204 } 1205 1206 1207 static int usbHidUsbClearHaltedEndpointCore(PUSBHID pThis, unsigned uEndpoint) 1208 { 1195 1209 if ((uEndpoint & ~0x80) < RT_ELEMENTS(pThis->aEps)) 1196 1210 { … … 1205 1219 1206 1220 /** 1221 * @copydoc PDMUSBREG::pfnUsbClearHaltedEndpoint 1222 */ 1223 static DECLCALLBACK(int) usbHidUsbClearHaltedEndpoint(PPDMUSBINS pUsbIns, 1224 unsigned uEndpoint) 1225 { 1226 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1227 LogFlow(("usbHidUsbClearHaltedEndpoint/#%u: uEndpoint=%#x\n", 1228 pUsbIns->iInstance, uEndpoint)); 1229 return usbHidUsbClearHaltedEndpointCore(pThis, uEndpoint); 1230 } 1231 1232 1233 /** 1207 1234 * @copydoc PDMUSBREG::pfnUsbSetInterface 1208 1235 */ 1209 static DECLCALLBACK(int) usbHidUsbSetInterface(PPDMUSBINS pUsbIns, uint8_t bInterfaceNumber, uint8_t bAlternateSetting) 1210 { 1211 LogFlow(("usbHidUsbSetInterface/#%u: bInterfaceNumber=%u bAlternateSetting=%u\n", pUsbIns->iInstance, bInterfaceNumber, bAlternateSetting)); 1236 static DECLCALLBACK(int) usbHidUsbSetInterface(PPDMUSBINS pUsbIns, 1237 uint8_t bInterfaceNumber, 1238 uint8_t bAlternateSetting) 1239 { 1240 LogFlow(("usbHidUsbSetInterface/#%u: bInterfaceNumber=%u bAlternateSetting=%u\n", 1241 pUsbIns->iInstance, bInterfaceNumber, bAlternateSetting)); 1212 1242 Assert(bAlternateSetting == 0); 1213 1243 return VINF_SUCCESS; … … 1215 1245 1216 1246 1217 /** 1218 * @copydoc PDMUSBREG::pfnUsbSetConfiguration 1219 */ 1220 static DECLCALLBACK(int) usbHidUsbSetConfiguration(PPDMUSBINS pUsbIns, uint8_t bConfigurationValue, 1221 const void *pvOldCfgDesc, const void *pvOldIfState, const void *pvNewCfgDesc) 1222 { 1223 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1224 LogFlow(("usbHidUsbSetConfiguration/#%u: bConfigurationValue=%u\n", pUsbIns->iInstance, bConfigurationValue)); 1247 static int usbHidUsbSetConfigurationCore(PUSBHID pThis, 1248 uint8_t bConfigurationValue, 1249 const void *pvOldCfgDesc, 1250 const void *pvOldIfState, 1251 const void *pvNewCfgDesc) 1252 { 1225 1253 Assert(bConfigurationValue == 1); 1226 1254 RTCritSectEnter(&pThis->CritSect); … … 1230 1258 */ 1231 1259 if (pThis->bConfigurationValue == bConfigurationValue) 1232 usbHidResetWorker(pThis, NULL, true /*fSetConfig*/); /** @todo figure out the exact difference */ 1260 usbHidResetWorker(pThis, NULL, true /*fSetConfig*/); 1261 /** @todo figure out the exact difference */ 1233 1262 pThis->bConfigurationValue = bConfigurationValue; 1234 1263 … … 1245 1274 1246 1275 /** 1276 * @copydoc PDMUSBREG::pfnUsbSetConfiguration 1277 */ 1278 static DECLCALLBACK(int) usbHidUsbSetConfiguration(PPDMUSBINS pUsbIns, 1279 uint8_t bConfigurationValue, 1280 const void *pvOldCfgDesc, 1281 const void *pvOldIfState, 1282 const void *pvNewCfgDesc) 1283 { 1284 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1285 LogFlow(("usbHidUsbSetConfiguration/#%u: bConfigurationValue=%u\n", 1286 pUsbIns->iInstance, bConfigurationValue)); 1287 return usbHidUsbSetConfigurationCore(pThis, bConfigurationValue, 1288 pvOldCfgDesc, pvOldIfState, 1289 pvNewCfgDesc); 1290 } 1291 1292 1293 /** 1247 1294 * @copydoc PDMUSBREG::pfnUsbGetDescriptorCache 1248 1295 */ 1249 static DECLCALLBACK(PCPDMUSBDESCCACHE) usbHidUsbGetDescriptorCache(PPDMUSBINS pUsbIns) 1250 { 1251 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1252 LogFlow(("usbHidUsbGetDescriptorCache/#%u:\n", pUsbIns->iInstance)); 1296 static PCPDMUSBDESCCACHE usbHidUsbGetDescriptorCacheCore(PUSBHID pThis) 1297 { 1253 1298 if (pThis->isAbsolute) { 1254 1299 return &g_UsbHidTDescCache; … … 1260 1305 1261 1306 /** 1307 * @copydoc PDMUSBREG::pfnUsbGetDescriptorCache 1308 */ 1309 static DECLCALLBACK(PCPDMUSBDESCCACHE) usbHidUsbGetDescriptorCache(PPDMUSBINS 1310 pUsbIns) 1311 { 1312 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1313 LogFlow(("usbHidUsbGetDescriptorCache/#%u:\n", pUsbIns->iInstance)); 1314 return usbHidUsbGetDescriptorCacheCore(pThis); 1315 } 1316 1317 1318 static DECLCALLBACK(int) usbHidUsbResetCore(PUSBHID pThis) 1319 { 1320 RTCritSectEnter(&pThis->CritSect); 1321 1322 int rc = usbHidResetWorker(pThis, NULL, false /*fSetConfig*/); 1323 1324 RTCritSectLeave(&pThis->CritSect); 1325 return rc; 1326 } 1327 1328 1329 /** 1262 1330 * @copydoc PDMUSBREG::pfnUsbReset 1263 1331 */ … … 1266 1334 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1267 1335 LogFlow(("usbHidUsbReset/#%u:\n", pUsbIns->iInstance)); 1268 RTCritSectEnter(&pThis->CritSect); 1269 1270 int rc = usbHidResetWorker(pThis, NULL, false /*fSetConfig*/); 1271 1272 RTCritSectLeave(&pThis->CritSect); 1273 return rc; 1274 } 1275 1276 1277 /** 1278 * @copydoc PDMUSBREG::pfnDestruct 1279 */ 1280 static void usbHidDestruct(PPDMUSBINS pUsbIns) 1281 { 1282 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1283 LogFlow(("usbHidDestruct/#%u:\n", pUsbIns->iInstance)); 1284 1336 return usbHidUsbResetCore(pThis); 1337 } 1338 1339 1340 static void usbHidDestructCore(PUSBHID pThis) 1341 { 1285 1342 if (RTCritSectIsInitialized(&pThis->CritSect)) 1286 1343 { … … 1299 1356 1300 1357 /** 1301 * @copydoc PDMUSBREG::pfn Construct1302 */ 1303 static DECLCALLBACK( int) usbHidConstruct(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal)1358 * @copydoc PDMUSBREG::pfnDestruct 1359 */ 1360 static DECLCALLBACK(void) usbHidDestruct(PPDMUSBINS pUsbIns) 1304 1361 { 1305 1362 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1306 Log(("usbHidConstruct/#%u:\n", iInstance)); 1307 1363 LogFlow(("usbHidDestruct/#%u:\n", pUsbIns->iInstance)); 1364 usbHidDestructCore(pThis); 1365 } 1366 1367 1368 static int usbHidConstructCore(PUSBHID pThis, int iInstance, bool isAbsolute, 1369 uint8_t u8CoordShift) 1370 { 1308 1371 /* 1309 1372 * Perform the basic structure initialization first so the destructor 1310 1373 * will not misbehave. 1311 1374 */ 1312 pThis-> pUsbIns = pUsbIns;1375 pThis->iInstance = iInstance; 1313 1376 pThis->hEvtDoneQueue = NIL_RTSEMEVENT; 1314 1377 usbHidQueueInit(&pThis->ToHostQueue); … … 1321 1384 AssertRCReturn(rc, rc); 1322 1385 1386 pThis->isAbsolute = isAbsolute; 1387 pThis->u8CoordShift = u8CoordShift; 1388 1389 pThis->Lun0.IBase.pfnQueryInterface = usbHidMouseQueryInterface; 1390 pThis->Lun0.IPort.pfnPutEvent = usbHidMousePutEvent; 1391 pThis->Lun0.IPort.pfnPutEventAbs = usbHidMousePutEventAbs; 1392 1393 return VINF_SUCCESS; 1394 } 1395 1396 1397 static void usbHidConstructFinish(PUSBHID pThis, PPDMIMOUSECONNECTOR pDrv) 1398 { 1399 pThis->Lun0.pDrv = pDrv; 1400 } 1401 1402 1403 /** 1404 * @copydoc PDMUSBREG::pfnConstruct 1405 */ 1406 static DECLCALLBACK(int) usbHidConstruct(PPDMUSBINS pUsbIns, int iInstance, 1407 PCFGMNODE pCfg, PCFGMNODE pCfgGlobal) 1408 { 1409 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1410 bool isAbsolute; 1411 uint8_t u8CoordShift; 1412 PPDMIMOUSECONNECTOR pDrv; 1413 Log(("usbHidConstruct/#%u:\n", iInstance)); 1414 1323 1415 /* 1324 1416 * Validate and read the configuration. 1325 1417 */ 1326 rc = CFGMR3ValidateConfig(pCfg, "/", "Absolute|CoordShift", "Config", "UsbHid", iInstance); 1418 int rc = CFGMR3ValidateConfig(pCfg, "/", "Absolute|CoordShift", "Config", 1419 "UsbHid", iInstance); 1327 1420 if (RT_FAILURE(rc)) 1328 1421 return rc; 1329 rc = CFGMR3QueryBoolDef(pCfg, "Absolute", & pThis->isAbsolute, false);1422 rc = CFGMR3QueryBoolDef(pCfg, "Absolute", &isAbsolute, false); 1330 1423 if (RT_FAILURE(rc)) 1331 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, N_("HID failed to query settings")); 1332 1333 pThis->Lun0.IBase.pfnQueryInterface = usbHidMouseQueryInterface; 1334 pThis->Lun0.IPort.pfnPutEvent = usbHidMousePutEvent; 1335 pThis->Lun0.IPort.pfnPutEventAbs = usbHidMousePutEventAbs; 1424 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, 1425 N_("HID failed to query settings")); 1426 1427 rc = CFGMR3QueryU8Def(pCfg, "CoordShift", &u8CoordShift, 1); 1428 if (RT_FAILURE(rc)) 1429 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, 1430 N_("HID failed to query shift factor")); 1431 1432 rc = usbHidConstructCore(pThis, iInstance, isAbsolute, u8CoordShift); 1336 1433 1337 1434 /* 1338 1435 * Attach the mouse driver. 1339 1436 */ 1340 rc = PDMUsbHlpDriverAttach(pUsbIns, 0 /*iLun*/, &pThis->Lun0.IBase, &pThis->Lun0.pDrvBase, "Mouse Port"); 1437 rc = PDMUsbHlpDriverAttach(pUsbIns, 0 /*iLun*/, &pThis->Lun0.IBase, 1438 &pThis->Lun0.pDrvBase, "Mouse Port"); 1341 1439 if (RT_FAILURE(rc)) 1342 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, N_("HID failed to attach mouse driver"));1343 1344 pThis->Lun0.pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Lun0.pDrvBase, PDMIMOUSECONNECTOR); 1345 if (!pThis->Lun0.pDrv)1346 return PDMUsbHlpVMSetError(pUsbIns, VERR_PDM_MISSING_INTERFACE, RT_SRC_POS, N_("HID failed to query mouse interface"));1347 1348 rc = CFGMR3QueryU8Def(pCfg, "CoordShift", &pThis->u8CoordShift, 1);1349 if (RT_FAILURE(rc))1350 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, N_("HID failed to query shift factor"));1440 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, 1441 N_("HID failed to attach mouse driver")); 1442 1443 pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Lun0.pDrvBase, PDMIMOUSECONNECTOR); 1444 if (!pDrv) 1445 return PDMUsbHlpVMSetError(pUsbIns, VERR_PDM_MISSING_INTERFACE, 1446 RT_SRC_POS, 1447 N_("HID failed to query mouse interface")); 1448 usbHidConstructFinish(pThis, pDrv); 1351 1449 1352 1450 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.