- Timestamp:
- Feb 2, 2012 5:11:50 PM (13 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/DevPS2.cpp
r39091 r39959 52 52 53 53 #include "VBoxDD.h" 54 55 #define PCKBD_SAVED_STATE_VERSION 5 54 #include "PS2Dev.h" 55 56 #define PCKBD_SAVED_STATE_VERSION 6 56 57 57 58 … … 205 206 int32_t translate; 206 207 int32_t scancode_set; /* 1=XT, 2=AT, 3=PS/2 */ 208 xlat_state_t xlat_state; 207 209 /* mouse state */ 208 210 int32_t mouse_write_cmd; … … 227 229 /** Pointer to the device instance. */ 228 230 PPDMDEVINSR0 pDevInsR0; 231 232 #if HC_ARCH_BITS == 32 233 uint32_t Alignment0; 234 #endif 235 /** Keyboard state (implemented in separate PS2K module). */ 236 PS2K Kbd; 229 237 /** Critical section protecting the state. */ 230 238 PDMCRITSECT CritSect; 239 240 #ifdef HC_ARCH_BITS //OLD_KBD 231 241 /** 232 242 * Keyboard port - LUN#0. … … 247 257 R3PTRTYPE(PPDMIKEYBOARDCONNECTOR) pDrv; 248 258 } Keyboard; 259 #endif 249 260 250 261 /** … … 301 312 MouseEventQueue *meq = &s->mouse_event_queue; 302 313 int irq12_level, irq1_level; 314 uint8_t val; 303 315 304 316 irq1_level = 0; … … 312 324 s->status &= ~KBD_STAT_MOUSE_OBF; 313 325 /* Keyboard data has priority if both kbd and aux data is available. */ 326 #ifdef OLD_KBD 314 327 if (q->count && !(s->mode & KBD_MODE_DISABLE_KBD)) 315 328 { … … 320 333 q->count--; 321 334 } 322 else if ((mcq->count || meq->count) /*&& !(s->mode & KBD_MODE_DISABLE_MOUSE)*/) 335 #else 336 if (!(s->mode & KBD_MODE_DISABLE_KBD) && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS) 337 { 338 bool fHaveData = true; 339 340 /* If scancode translation is on (it usually is), there's more work to do. */ 341 if (s->translate) 342 { 343 uint8_t xlated_val; 344 345 s->xlat_state = XlateAT2PC(s->xlat_state, val, &xlated_val); 346 val = xlated_val; 347 348 /* If the translation state is XS_BREAK, there's nothing to report 349 * and we keep going until the state changes or there's no more data. 350 */ 351 while (s->xlat_state == XS_BREAK && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS) 352 { 353 s->xlat_state = XlateAT2PC(s->xlat_state, val, &xlated_val); 354 val = xlated_val; 355 } 356 /* This can happen if the last byte in the queue is F0... */ 357 if (s->xlat_state == XS_BREAK) 358 fHaveData = false; 359 } 360 if (fHaveData) 361 { 362 s->dbbout = val; 363 s->status |= KBD_STAT_OBF; 364 } 365 } 366 #endif 367 else if ((mcq->count || meq->count) && !(s->mode & KBD_MODE_DISABLE_MOUSE)) 323 368 { 324 369 s->status |= KBD_STAT_OBF | KBD_STAT_MOUSE_OBF; … … 356 401 } 357 402 403 void KBCUpdateInterrupts(void *pKbc) 404 { 405 KBDState *s = (KBDState *)pKbc; 406 kbd_update_irq(s); 407 } 408 358 409 static void kbd_queue(KBDState *s, int b, int aux) 359 410 { … … 596 647 } 597 648 649 #ifdef OLD_KBD 650 598 651 static void kbd_reset_keyboard(KBDState *s) 599 652 { … … 604 657 s->queue.rptr = 0; 605 658 s->queue.wptr = 0; 659 } 660 661 /* The keyboard BAT is specified to take several hundred milliseconds. We need 662 * to delay sending the result to the host for at least a tiny little while. 663 */ 664 static DECLCALLBACK(void) kbd_timer_cb(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser) 665 { 666 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *); 667 int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY); 668 AssertReleaseRC(rc); 669 670 kbd_queue(pThis, KBD_REPLY_POR, 0); 671 672 PDMCritSectLeave(&pThis->CritSect); 606 673 } 607 674 … … 701 768 return VINF_SUCCESS; 702 769 } 770 771 #else 772 PS2K *GetPS2KFromDevIns(PPDMDEVINS pDevIns) 773 { 774 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *); 775 return &pThis->Kbd; 776 } 777 #endif 703 778 704 779 static void kbd_mouse_set_reported_buttons(KBDState *s, unsigned fButtons, unsigned fButtonMask) … … 1073 1148 /* Automatically enables keyboard interface. */ 1074 1149 s->mode &= ~KBD_MODE_DISABLE_KBD; 1150 #ifdef OLD_KBD 1075 1151 rc = kbd_write_keyboard(s, val); 1152 #else 1153 rc = PS2KByteToKbd(&s->Kbd, val); 1154 if (rc == VINF_SUCCESS) 1155 kbd_update_irq(s); 1156 #endif 1076 1157 break; 1077 1158 case KBD_CCMD_WRITE_MODE: … … 1104 1185 break; 1105 1186 case KBD_CCMD_WRITE_MOUSE: 1187 /* Automatically enables aux interface. */ 1188 s->mode &= ~KBD_MODE_DISABLE_MOUSE; 1106 1189 rc = kbd_write_mouse(s, val); 1107 1190 break; … … 1172 1255 qemu_put_8s(f, &s->status); 1173 1256 qemu_put_8s(f, &s->mode); 1174 qemu_put_be32s(f, &s->kbd_write_cmd); 1175 qemu_put_be32s(f, &s->scan_enabled); 1257 qemu_put_8s(f, &s->dbbout); 1176 1258 qemu_put_be32s(f, &s->mouse_write_cmd); 1177 1259 qemu_put_8s(f, &s->mouse_status); … … 1189 1271 qemu_put_8s(f, &s->mouse_buttons_reported); 1190 1272 1273 #ifdef OLD_KBD 1191 1274 /* XXX: s->scancode_set isn't being saved, but we only really support set 2, 1192 1275 * so no real harm done. … … 1201 1284 SSMR3PutU8(f, s->queue.data[i]); 1202 1285 Log(("kbd_save: %d keyboard queue items stored\n", s->queue.count)); 1286 #endif 1203 1287 1204 1288 cItems = s->mouse_command_queue.count; … … 1237 1321 qemu_get_8s(f, &s->status); 1238 1322 qemu_get_8s(f, &s->mode); 1239 qemu_get_be32s(f, (uint32_t *)&s->kbd_write_cmd); 1240 qemu_get_be32s(f, (uint32_t *)&s->scan_enabled); 1323 if (version_id <= 5) 1324 { 1325 qemu_get_be32s(f, (uint32_t *)&s->kbd_write_cmd); 1326 qemu_get_be32s(f, (uint32_t *)&s->scan_enabled); 1327 } 1328 else 1329 { 1330 qemu_get_8s(f, &s->dbbout); 1331 } 1241 1332 qemu_get_be32s(f, (uint32_t *)&s->mouse_write_cmd); 1242 1333 qemu_get_8s(f, &s->mouse_status); … … 1281 1372 * Load the queues 1282 1373 */ 1283 rc = SSMR3GetU32(f, &u32); 1284 if (RT_FAILURE(rc)) 1285 return rc; 1286 if (u32 > RT_ELEMENTS(s->queue.data)) 1287 { 1288 AssertMsgFailed(("u32=%#x\n", u32)); 1289 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED; 1290 } 1291 for (i = 0; i < u32; i++) 1292 { 1293 rc = SSMR3GetU8(f, &s->queue.data[i]); 1374 if (version_id <= 5) 1375 { 1376 rc = SSMR3GetU32(f, &u32); 1294 1377 if (RT_FAILURE(rc)) 1295 1378 return rc; 1296 } 1297 s->queue.wptr = u32 % RT_ELEMENTS(s->queue.data); 1298 s->queue.count = u32; 1299 Log(("kbd_load: %d keyboard queue items loaded\n", u32)); 1379 if (u32 > RT_ELEMENTS(s->queue.data)) 1380 { 1381 AssertMsgFailed(("u32=%#x\n", u32)); 1382 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED; 1383 } 1384 for (i = 0; i < u32; i++) 1385 { 1386 rc = SSMR3GetU8(f, &s->queue.data[i]); 1387 if (RT_FAILURE(rc)) 1388 return rc; 1389 } 1390 s->queue.wptr = u32 % RT_ELEMENTS(s->queue.data); 1391 s->queue.count = u32; 1392 Log(("kbd_load: %d keyboard queue items loaded\n", u32)); 1393 } 1300 1394 1301 1395 rc = SSMR3GetU32(f, &u32); … … 1488 1582 static DECLCALLBACK(int) kbdSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle) 1489 1583 { 1490 kbd_save(pSSMHandle, PDMINS_2_DATA(pDevIns, KBDState *)); 1584 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *); 1585 kbd_save(pSSMHandle, pThis); 1586 PS2KSaveState(pSSMHandle, &pThis->Kbd); 1491 1587 return VINF_SUCCESS; 1492 1588 } … … 1504 1600 static DECLCALLBACK(int) kbdLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t uVersion, uint32_t uPass) 1505 1601 { 1602 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *); 1603 int rc; 1604 1506 1605 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass); 1507 return kbd_load(pSSMHandle, PDMINS_2_DATA(pDevIns, KBDState *), uVersion); 1606 rc = kbd_load(pSSMHandle, pThis, uVersion); 1607 if (uVersion >= 6) 1608 rc = PS2KLoadState(pSSMHandle, &pThis->Kbd, uVersion); 1609 return rc; 1508 1610 } 1509 1611 … … 1519 1621 1520 1622 kbd_reset(pThis); 1623 #ifdef OLD_KBD 1521 1624 /* Activate the PS/2 keyboard by default. */ 1522 1625 if (pThis->Keyboard.pDrv) 1523 1626 pThis->Keyboard.pDrv->pfnSetActive(pThis->Keyboard.pDrv, true); 1524 } 1525 1627 #else 1628 PS2KReset(&pThis->Kbd); 1629 #endif 1630 } 1631 1632 #ifdef OLD_KBD 1526 1633 1527 1634 /* -=-=-=-=-=- Keyboard: IBase -=-=-=-=-=- */ … … 1559 1666 return VINF_SUCCESS; 1560 1667 } 1668 #endif 1561 1669 1562 1670 … … 1635 1743 /* LUN #0: keyboard */ 1636 1744 case 0: 1745 #ifdef OLD_KBD 1637 1746 rc = PDMDevHlpDriverAttach(pDevIns, iLUN, &pThis->Keyboard.IBase, &pThis->Keyboard.pDrvBase, "Keyboard Port"); 1638 1747 if (RT_SUCCESS(rc)) … … 1652 1761 else 1653 1762 AssertLogRelMsgFailed(("Failed to attach LUN #0! rc=%Rrc\n", rc)); 1763 #else 1764 rc = PS2KAttach(pDevIns, &pThis->Kbd, iLUN, fFlags); 1765 if (RT_FAILURE(rc)) 1766 return rc; 1767 1768 #endif 1654 1769 break; 1655 1770 … … 1737 1852 KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *); 1738 1853 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns); 1739 NOREF(offDelta);1854 PS2KRelocate(&pThis->Kbd, offDelta); 1740 1855 } 1741 1856 … … 1791 1906 pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns); 1792 1907 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns); 1908 1909 #if OLD_KBD 1793 1910 pThis->Keyboard.IBase.pfnQueryInterface = kbdKeyboardQueryInterface; 1794 1911 pThis->Keyboard.IPort.pfnPutEvent = kbdKeyboardPutEvent; 1912 #else 1913 rc = PS2KConstruct(pDevIns, &pThis->Kbd, pThis, iInstance); 1914 if (RT_FAILURE(rc)) 1915 return rc; 1916 #endif 1795 1917 1796 1918 pThis->Mouse.IBase.pfnQueryInterface = kbdMouseQueryInterface; -
trunk/src/VBox/Devices/Makefile.kmk
r39955 r39959 282 282 DevicesR3_SOURCES = \ 283 283 Input/DevPS2.cpp \ 284 Input/PS2K.cpp \ 284 285 Input/UsbKbd.cpp \ 285 286 Input/UsbMouse.cpp \ … … 560 561 Graphics/DevVGA.cpp \ 561 562 Input/DevPS2.cpp \ 563 Input/PS2K.cpp \ 562 564 PC/DevACPI.cpp \ 563 565 PC/DevPit-i8254.cpp \ … … 663 665 Graphics/DevVGA.cpp \ 664 666 Input/DevPS2.cpp \ 667 Input/PS2K.cpp \ 665 668 PC/DevACPI.cpp \ 666 669 PC/DevPit-i8254.cpp \
Note:
See TracChangeset
for help on using the changeset viewer.