Changeset 46767 in vbox
- Timestamp:
- Jun 24, 2013 10:06:24 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/UsbMouse.cpp
r46766 r46767 120 120 typedef struct USBHID 121 121 { 122 /** USB device instance number. */123 uint32_t iInstance;122 /** Pointer back to the PDM USB Device instance structure. */ 123 PPDMUSBINS pUsbIns; 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-> iInstance, pUrb, pUrb->pszDesc, pszWhy));636 Log(("usbHidCompleteStall/#%u: pUrb=%p:%s: %s\n", pThis->pUsbIns->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-> iInstance, pUrb, pUrb->pszDesc, cbData));659 Log(("usbHidCompleteOk/#%u: pUrb=%p:%s cbData=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData)); 660 660 661 661 pUrb->enmStatus = VUSBSTATUS_OK; … … 859 859 } 860 860 861 862 static PVUSBURB usbHidUrbReapCore(PUSBHID pThis, RTMSINTERVAL cMillies) 863 { 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 864 869 RTCritSectEnter(&pThis->CritSect); 865 870 … … 882 887 883 888 if (pUrb) 884 Log(("usbHidUrbReap/#%u: pUrb=%p:%s\n", p This->iInstance, pUrb, pUrb->pszDesc));889 Log(("usbHidUrbReap/#%u: pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc)); 885 890 return pUrb; 886 891 } … … 888 893 889 894 /** 890 * @copydoc PDMUSBREG::pfnUrbReap 891 */ 892 static DECLCALLBACK(PVUSBURB) usbHidUrbReap(PPDMUSBINS pUsbIns, 893 RTMSINTERVAL cMillies) 895 * @copydoc PDMUSBREG::pfnUrbCancel 896 */ 897 static DECLCALLBACK(int) usbHidUrbCancel(PPDMUSBINS pUsbIns, PVUSBURB pUrb) 894 898 { 895 899 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 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 { 900 LogFlow(("usbHidUrbCancel/#%u: pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc)); 903 901 RTCritSectEnter(&pThis->CritSect); 904 902 … … 913 911 } 914 912 915 916 /**917 * @copydoc PDMUSBREG::pfnUrbCancel918 */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 }926 913 927 914 /** … … 1162 1149 1163 1150 1164 static int usbHidQueueCore(PUSBHID pThis, PVUSBURB pUrb) 1165 { 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)); 1166 1158 RTCritSectEnter(&pThis->CritSect); 1167 1159 … … 1194 1186 1195 1187 /** 1196 * @copydoc PDMUSBREG::pfnU rbQueue1197 */ 1198 static DECLCALLBACK(int) usbHid Queue(PPDMUSBINS pUsbIns, PVUSBURB pUrb)1188 * @copydoc PDMUSBREG::pfnUsbClearHaltedEndpoint 1189 */ 1190 static DECLCALLBACK(int) usbHidUsbClearHaltedEndpoint(PPDMUSBINS pUsbIns, unsigned uEndpoint) 1199 1191 { 1200 1192 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 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 { 1193 LogFlow(("usbHidUsbClearHaltedEndpoint/#%u: uEndpoint=%#x\n", pUsbIns->iInstance, uEndpoint)); 1194 1209 1195 if ((uEndpoint & ~0x80) < RT_ELEMENTS(pThis->aEps)) 1210 1196 { … … 1219 1205 1220 1206 /** 1221 * @copydoc PDMUSBREG::pfnUsbClearHaltedEndpoint1222 */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 /**1234 1207 * @copydoc PDMUSBREG::pfnUsbSetInterface 1235 1208 */ 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)); 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)); 1242 1212 Assert(bAlternateSetting == 0); 1243 1213 return VINF_SUCCESS; … … 1245 1215 1246 1216 1247 static int usbHidUsbSetConfigurationCore(PUSBHID pThis, 1248 uint8_t bConfigurationValue, 1249 const void *pvOldCfgDesc, 1250 const void *pvOldIfState, 1251 const void *pvNewCfgDesc) 1252 { 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)); 1253 1225 Assert(bConfigurationValue == 1); 1254 1226 RTCritSectEnter(&pThis->CritSect); … … 1258 1230 */ 1259 1231 if (pThis->bConfigurationValue == bConfigurationValue) 1260 usbHidResetWorker(pThis, NULL, true /*fSetConfig*/); 1261 /** @todo figure out the exact difference */ 1232 usbHidResetWorker(pThis, NULL, true /*fSetConfig*/); /** @todo figure out the exact difference */ 1262 1233 pThis->bConfigurationValue = bConfigurationValue; 1263 1234 … … 1274 1245 1275 1246 /** 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) 1247 * @copydoc PDMUSBREG::pfnUsbGetDescriptorCache 1248 */ 1249 static DECLCALLBACK(PCPDMUSBDESCCACHE) usbHidUsbGetDescriptorCache(PPDMUSBINS pUsbIns) 1283 1250 { 1284 1251 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 /** 1294 * @copydoc PDMUSBREG::pfnUsbGetDescriptorCache 1295 */ 1296 static PCPDMUSBDESCCACHE usbHidUsbGetDescriptorCacheCore(PUSBHID pThis) 1297 { 1252 LogFlow(("usbHidUsbGetDescriptorCache/#%u:\n", pUsbIns->iInstance)); 1298 1253 if (pThis->isAbsolute) { 1299 1254 return &g_UsbHidTDescCache; … … 1305 1260 1306 1261 /** 1307 * @copydoc PDMUSBREG::pfnUsbGetDescriptorCache 1308 */ 1309 static DECLCALLBACK(PCPDMUSBDESCCACHE) usbHidUsbGetDescriptorCache(PPDMUSBINS 1310 pUsbIns) 1262 * @copydoc PDMUSBREG::pfnUsbReset 1263 */ 1264 static DECLCALLBACK(int) usbHidUsbReset(PPDMUSBINS pUsbIns, bool fResetOnLinux) 1311 1265 { 1312 1266 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 { 1267 LogFlow(("usbHidUsbReset/#%u:\n", pUsbIns->iInstance)); 1320 1268 RTCritSectEnter(&pThis->CritSect); 1321 1269 … … 1328 1276 1329 1277 /** 1330 * @copydoc PDMUSBREG::pfn UsbReset1331 */ 1332 static DECLCALLBACK(int) usbHidUsbReset(PPDMUSBINS pUsbIns, bool fResetOnLinux)1278 * @copydoc PDMUSBREG::pfnDestruct 1279 */ 1280 static void usbHidDestruct(PPDMUSBINS pUsbIns) 1333 1281 { 1334 1282 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 1335 LogFlow(("usbHidUsbReset/#%u:\n", pUsbIns->iInstance)); 1336 return usbHidUsbResetCore(pThis); 1337 } 1338 1339 1340 static void usbHidDestructCore(PUSBHID pThis) 1341 { 1283 LogFlow(("usbHidDestruct/#%u:\n", pUsbIns->iInstance)); 1284 1342 1285 if (RTCritSectIsInitialized(&pThis->CritSect)) 1343 1286 { … … 1356 1299 1357 1300 /** 1358 * @copydoc PDMUSBREG::pfn Destruct1359 */ 1360 static DECLCALLBACK( void) usbHidDestruct(PPDMUSBINS pUsbIns)1301 * @copydoc PDMUSBREG::pfnConstruct 1302 */ 1303 static DECLCALLBACK(int) usbHidConstruct(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal) 1361 1304 { 1362 1305 PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID); 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 { 1306 Log(("usbHidConstruct/#%u:\n", iInstance)); 1307 1371 1308 /* 1372 1309 * Perform the basic structure initialization first so the destructor 1373 1310 * will not misbehave. 1374 1311 */ 1375 pThis-> iInstance = iInstance;1312 pThis->pUsbIns = pUsbIns; 1376 1313 pThis->hEvtDoneQueue = NIL_RTSEMEVENT; 1377 1314 usbHidQueueInit(&pThis->ToHostQueue); … … 1384 1321 AssertRCReturn(rc, rc); 1385 1322 1386 pThis->isAbsolute = isAbsolute; 1387 pThis->u8CoordShift = u8CoordShift; 1323 /* 1324 * Validate and read the configuration. 1325 */ 1326 rc = CFGMR3ValidateConfig(pCfg, "/", "Absolute|CoordShift", "Config", "UsbHid", iInstance); 1327 if (RT_FAILURE(rc)) 1328 return rc; 1329 rc = CFGMR3QueryBoolDef(pCfg, "Absolute", &pThis->isAbsolute, false); 1330 if (RT_FAILURE(rc)) 1331 return PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, N_("HID failed to query settings")); 1388 1332 1389 1333 pThis->Lun0.IBase.pfnQueryInterface = usbHidMouseQueryInterface; … … 1391 1335 pThis->Lun0.IPort.pfnPutEventAbs = usbHidMousePutEventAbs; 1392 1336 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::pfnConstruct1405 */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 1415 /*1416 * Validate and read the configuration.1417 */1418 int rc = CFGMR3ValidateConfig(pCfg, "/", "Absolute|CoordShift", "Config",1419 "UsbHid", iInstance);1420 if (RT_FAILURE(rc))1421 return rc;1422 rc = CFGMR3QueryBoolDef(pCfg, "Absolute", &isAbsolute, false);1423 if (RT_FAILURE(rc))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);1433 1434 1337 /* 1435 1338 * Attach the mouse driver. 1436 1339 */ 1437 rc = PDMUsbHlpDriverAttach(pUsbIns, 0 /*iLun*/, &pThis->Lun0.IBase, 1438 &pThis->Lun0.pDrvBase, "Mouse Port"); 1340 rc = PDMUsbHlpDriverAttach(pUsbIns, 0 /*iLun*/, &pThis->Lun0.IBase, &pThis->Lun0.pDrvBase, "Mouse Port"); 1439 1341 if (RT_FAILURE(rc)) 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);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")); 1449 1351 1450 1352 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.