Changeset 82201 in vbox for trunk/src/VBox/Devices/Input
- Timestamp:
- Nov 25, 2019 9:32:30 PM (5 years ago)
- Location:
- trunk/src/VBox/Devices/Input
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/DevPS2.cpp
r82195 r82201 48 48 #define LOG_GROUP LOG_GROUP_DEV_KBD 49 49 #include <VBox/vmm/pdmdev.h> 50 #include <VBox/AssertGuest.h> 50 51 #include <iprt/assert.h> 51 52 #include <iprt/uuid.h> … … 149 150 150 151 151 /*********************************************************************************************************************************152 * Internal Functions *153 *********************************************************************************************************************************/154 RT_C_DECLS_BEGIN155 PDMBOTHCBDECL(int) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);156 PDMBOTHCBDECL(int) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);157 PDMBOTHCBDECL(int) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);158 PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);159 RT_C_DECLS_END160 161 162 152 /** 163 153 * Convert an AT (Scan Set 2) scancode to PC (Scan Set 1). … … 310 300 } 311 301 312 static uint32_t kbd_read_status(PKBDSTATE s, uint32_t addr) 313 { 314 int val = s->status; 315 NOREF(addr); 316 317 #if defined(DEBUG_KBD) 318 Log(("kbd: read status=0x%02x\n", val)); 319 #endif 320 return val; 321 } 322 323 static int kbd_write_command(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t addr, uint32_t val) 324 { 325 int rc = VINF_SUCCESS; 326 NOREF(addr); 327 302 static VBOXSTRICTRC kbd_write_command(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t val) 303 { 328 304 #ifdef DEBUG_KBD 329 305 Log(("kbd: write cmd=0x%02x\n", val)); … … 355 331 # ifndef IN_RING3 356 332 if (!PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns))) 357 { 358 rc = VINF_IOM_R3_IOPORT_WRITE; 359 break; 360 } 361 # else /* IN_RING3 */ 333 return VINF_IOM_R3_IOPORT_WRITE; 334 # else /* IN_RING3 */ 362 335 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), true); 363 336 # endif /* IN_RING3 */ … … 397 370 # ifndef IN_RING3 398 371 if (!PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns))) 399 r c =VINF_IOM_R3_IOPORT_WRITE;400 # else /* IN_RING3 */372 return VINF_IOM_R3_IOPORT_WRITE; 373 # else /* IN_RING3 */ 401 374 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), true); 402 375 # endif /* IN_RING3 */ … … 405 378 # ifndef IN_RING3 406 379 if (PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns))) 407 r c =VINF_IOM_R3_IOPORT_WRITE;408 # else /* IN_RING3 */380 return VINF_IOM_R3_IOPORT_WRITE; 381 # else /* IN_RING3 */ 409 382 PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), false); 410 # endif /* !IN_RING3 */383 # endif /* IN_RING3 */ 411 384 break; 412 385 #endif … … 419 392 case KBD_CCMD_RESET_ALT: 420 393 #ifndef IN_RING3 421 r c =VINF_IOM_R3_IOPORT_WRITE;422 #else /* IN_RING3 */394 return VINF_IOM_R3_IOPORT_WRITE; 395 #else /* IN_RING3 */ 423 396 LogRel(("Reset initiated by keyboard controller\n")); 424 rc = PDMDevHlpVMReset(s->CTX_SUFF(pDevIns), PDMVMRESET_F_KBD); 425 #endif /* !IN_RING3 */ 426 break; 397 return PDMDevHlpVMReset(s->CTX_SUFF(pDevIns), PDMVMRESET_F_KBD); 398 #endif /* IN_RING3 */ 427 399 case 0xff: 428 400 /* ignore that - I don't know what is its use */ … … 444 416 break; 445 417 } 446 return rc;447 } 448 449 static uint32_t kbd_read_data(PPDMDEVINS pDevIns, PKBDSTATE s , uint32_t addr)418 return VINF_SUCCESS; 419 } 420 421 static uint32_t kbd_read_data(PPDMDEVINS pDevIns, PKBDSTATE s) 450 422 { 451 423 uint32_t val; 452 NOREF(addr);453 424 454 425 /* Return the current DBB contents. */ … … 483 454 } 484 455 485 static int kbd_write_data(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t addr, uint32_tval)456 static int kbd_write_data(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t val) 486 457 { 487 458 int rc = VINF_SUCCESS; 488 NOREF(addr);489 459 490 460 #ifdef DEBUG_KBD … … 674 644 675 645 /** 676 * Port I/O Handler for keyboard data IN operations. 677 * 678 * @returns VBox status code. 679 * 680 * @param pDevIns The device instance. 681 * @param pvUser User argument - ignored. 682 * @param Port Port number used for the IN operation. 683 * @param pu32 Where to store the result. 684 * @param cb Number of bytes read. 685 */ 686 PDMBOTHCBDECL(int) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb) 687 { 688 uint32_t fluff = 0; 689 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 690 691 NOREF(pvUser); 692 switch (cb) { 693 case 4: 694 fluff |= 0xffff0000; /* Crazy Apple (Darwin 6.0.2 and earlier). */ 695 RT_FALL_THRU(); 696 case 2: 697 fluff |= 0x0000ff00; 698 RT_FALL_THRU(); 699 case 1: 700 *pu32 = fluff | kbd_read_data(pDevIns, pThis, Port); 701 Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32)); 702 return VINF_SUCCESS; 703 default: 704 AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb)); 705 return VERR_IOM_IOPORT_UNUSED; 706 } 707 } 708 709 /** 710 * Port I/O Handler for keyboard data OUT operations. 711 * 712 * @returns VBox status code. 713 * 714 * @param pDevIns The device instance. 715 * @param pvUser User argument - ignored. 716 * @param Port Port number used for the IN operation. 717 * @param u32 The value to output. 718 * @param cb The value size in bytes. 719 */ 720 PDMBOTHCBDECL(int) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb) 721 { 722 int rc = VINF_SUCCESS; 723 NOREF(pvUser); 646 * @callback_method_impl{FNIOMIOPORTNEWIN, 647 * Port I/O Handler for keyboard data IN operations.} 648 */ 649 static DECLCALLBACK(VBOXSTRICTRC) kbdIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb) 650 { 651 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 652 RT_NOREF(pvUser, offPort); 653 Assert(offPort == 0); 654 655 switch (cb) 656 { 657 case 1: 658 *pu32 = kbd_read_data(pDevIns, pThis); 659 Log2(("kbdIOPortDataRead: *pu32=%#x\n", *pu32)); 660 return VINF_SUCCESS; 661 662 case 4: 663 case 2: 664 { 665 uint32_t const uFluff = cb == 2 ? UINT32_C(0x0000ff00) 666 : UINT32_C(0xffffff00) /* Crazy Apple (Darwin 6.0.2 and earlier). */; 667 *pu32 = uFluff | kbd_read_data(pDevIns, pThis); 668 Log2(("kbdIOPortDataRead: cb=%u *pu32=%#x\n", cb, *pu32)); 669 return VINF_SUCCESS; 670 } 671 672 default: 673 ASSERT_GUEST_MSG_FAILED(("Port=0x60+%x cb=%d\n", offPort, cb)); 674 return VERR_IOM_IOPORT_UNUSED; 675 } 676 } 677 678 /** 679 * @callback_method_impl{FNIOMIOPORTNEWOUT, 680 * Port I/O Handler for keyboard data OUT operations.} 681 */ 682 static DECLCALLBACK(VBOXSTRICTRC) kbdIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb) 683 { 684 VBOXSTRICTRC rc = VINF_SUCCESS; 685 RT_NOREF(offPort, pvUser); 686 Assert(offPort == 0); 687 724 688 if (cb == 1 || cb == 2) 725 689 { 726 690 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 727 rc = kbd_write_data(pDevIns, pThis, Port,(uint8_t)u32);728 Log2(("kbdIOPortDataWrite: Port= %#x cb=%d u32=%#x\n",Port, cb, u32));691 rc = kbd_write_data(pDevIns, pThis, (uint8_t)u32); 692 Log2(("kbdIOPortDataWrite: Port=0x60+%x cb=%d u32=%#x\n", offPort, cb, u32)); 729 693 } 730 694 else 731 A ssertMsgFailed(("Port=%#x cb=%d\n",Port, cb));695 ASSERT_GUEST_MSG_FAILED(("Port=0x60+%x cb=%d\n", offPort, cb)); 732 696 return rc; 733 697 } 734 698 735 699 /** 736 * Port I/O Handler for keyboard status IN operations. 737 * 738 * @returns VBox status code. 739 * 740 * @param pDevIns The device instance. 741 * @param pvUser User argument - ignored. 742 * @param Port Port number used for the IN operation. 743 * @param pu32 Where to store the result. 744 * @param cb Number of bytes read. 745 */ 746 PDMBOTHCBDECL(int) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb) 747 { 748 uint32_t fluff = 0; 749 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 750 751 NOREF(pvUser); 752 switch (cb) { 753 case 4: 754 fluff |= 0xffff0000; /* Crazy Apple (Darwin 6.0.2 and earlier). */ 755 RT_FALL_THRU(); 756 case 2: 757 fluff |= 0x0000ff00; 758 RT_FALL_THRU(); 759 case 1: 760 *pu32 = fluff | kbd_read_status(pThis, Port); 761 Log2(("kbdIOPortStatusRead: Port=%#x cb=%d -> *pu32=%#x\n", Port, cb, *pu32)); 762 return VINF_SUCCESS; 763 default: 764 AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb)); 765 return VERR_IOM_IOPORT_UNUSED; 766 } 767 } 768 769 /** 770 * Port I/O Handler for keyboard command OUT operations. 771 * 772 * @returns VBox status code. 773 * 774 * @param pDevIns The device instance. 775 * @param pvUser User argument - ignored. 776 * @param Port Port number used for the IN operation. 777 * @param u32 The value to output. 778 * @param cb The value size in bytes. 779 */ 780 PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb) 781 { 782 int rc = VINF_SUCCESS; 783 NOREF(pvUser); 700 * @callback_method_impl{FNIOMIOPORTNEWIN, 701 * Port I/O Handler for keyboard status IN operations.} 702 */ 703 static DECLCALLBACK(VBOXSTRICTRC) kbdIOPortStatusRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb) 704 { 705 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 706 RT_NOREF(offPort, pvUser); 707 Assert(offPort == 0); 708 709 switch (cb) 710 { 711 case 1: 712 *pu32 = pThis->status; 713 Log2(("kbdIOPortStatusRead: -> *pu32=%#x\n", *pu32)); 714 return VINF_SUCCESS; 715 716 case 2: 717 case 4: 718 { 719 uint32_t const uFluff = cb == 2 ? UINT32_C(0x0000ff00) 720 : UINT32_C(0xffffff00) /* Crazy Apple (Darwin 6.0.2 and earlier). */; 721 *pu32 = uFluff | pThis->status; 722 Log2(("kbdIOPortStatusRead: cb=%u -> *pu32=%#x\n", cb, *pu32)); 723 return VINF_SUCCESS; 724 } 725 726 default: 727 ASSERT_GUEST_MSG_FAILED(("Port=0x64+%x cb=%d\n", offPort, cb)); 728 return VERR_IOM_IOPORT_UNUSED; 729 } 730 } 731 732 /** 733 * @callback_method_impl{FNIOMIOPORTNEWIN, 734 * Port I/O Handler for keyboard command OUT operations.} 735 */ 736 static DECLCALLBACK(VBOXSTRICTRC) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb) 737 { 738 RT_NOREF(offPort, pvUser); 739 Assert(offPort == 0); 740 784 741 if (cb == 1 || cb == 2) 785 742 { 786 KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);787 rc = kbd_write_command(pDevIns, pThis, Port, (uint8_t)u32);788 Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));789 }790 else791 AssertMsgFailed(("Port=%#x cb=%d\n",Port, cb));792 return rc;743 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 744 VBOXSTRICTRC rc = kbd_write_command(pDevIns, pThis, (uint8_t)u32); 745 Log2(("kbdIOPortCommandWrite: cb=%d u32=%#x rc=%Rrc\n", cb, u32, VBOXSTRICTRC_VAL(rc))); 746 return rc; 747 } 748 ASSERT_GUEST_MSG_FAILED(("offPort=0x64+%x cb=%d\n", offPort, cb)); 749 return VINF_SUCCESS; 793 750 } 794 751 … … 1099 1056 * Register I/O ports. 1100 1057 */ 1101 rc = PDMDevHlpIOPortRegister(pDevIns, 0x60, 1, NULL, kbdIOPortDataWrite, kbdIOPortDataRead, NULL, NULL, "PC Keyboard - Data"); 1102 AssertRCReturn(rc, rc); 1103 rc = PDMDevHlpIOPortRegister(pDevIns, 0x64, 1, NULL, kbdIOPortCommandWrite, kbdIOPortStatusRead, NULL, NULL, "PC Keyboard - Command / Status"); 1104 AssertRCReturn(rc, rc); 1105 if (pDevIns->fRCEnabled) 1106 { 1107 rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x60, 1, 0, "kbdIOPortDataWrite", "kbdIOPortDataRead", NULL, NULL, "PC Keyboard - Data"); 1108 if (RT_FAILURE(rc)) 1109 return rc; 1110 rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x64, 1, 0, "kbdIOPortCommandWrite", "kbdIOPortStatusRead", NULL, NULL, "PC Keyboard - Command / Status"); 1111 if (RT_FAILURE(rc)) 1112 return rc; 1113 } 1114 if (pDevIns->fR0Enabled) 1115 { 1116 rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x60, 1, 0, "kbdIOPortDataWrite", "kbdIOPortDataRead", NULL, NULL, "PC Keyboard - Data"); 1117 if (RT_FAILURE(rc)) 1118 return rc; 1119 rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x64, 1, 0, "kbdIOPortCommandWrite", "kbdIOPortStatusRead", NULL, NULL, "PC Keyboard - Command / Status"); 1120 if (RT_FAILURE(rc)) 1121 return rc; 1122 } 1058 rc = PDMDevHlpIoPortCreateAndMap(pDevIns, 0x60 /*uPort*/, 1 /*cPorts*/, kbdIOPortDataWrite, kbdIOPortDataRead, 1059 "PC Keyboard - Data", NULL /*pExtDescs*/, &pThis->hIoPortData); 1060 AssertRCReturn(rc, rc); 1061 rc = PDMDevHlpIoPortCreateAndMap(pDevIns, 0x64 /*uPort*/, 1 /*cPorts*/, kbdIOPortCommandWrite, kbdIOPortStatusRead, 1062 "PC Keyboard - Command / Status", NULL /*pExtDescs*/, &pThis->hIoPortCmdStatus); 1063 AssertRCReturn(rc, rc); 1123 1064 1124 1065 /* … … 1147 1088 } 1148 1089 1149 #endif /* IN_RING3 */ 1090 #else /* !IN_RING3 */ 1091 1092 /** 1093 * @callback_method_impl{PDMDEVREGR0,pfnConstruct} 1094 */ 1095 static DECLCALLBACK(int) kbdRZConstruct(PPDMDEVINS pDevIns) 1096 { 1097 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 1098 PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE); 1099 1100 int rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortData, kbdIOPortDataWrite, kbdIOPortDataRead, NULL /*pvUser*/); 1101 AssertRCReturn(rc, rc); 1102 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortCmdStatus, kbdIOPortCommandWrite, kbdIOPortStatusRead, NULL /*pvUser*/); 1103 AssertRCReturn(rc, rc); 1104 1105 return VINF_SUCCESS; 1106 } 1107 1108 #endif /* !IN_RING3 */ 1150 1109 1151 1110 /** … … 1196 1155 #elif defined(IN_RING0) 1197 1156 /* .pfnEarlyConstruct = */ NULL, 1198 /* .pfnConstruct = */ NULL,1157 /* .pfnConstruct = */ kbdRZConstruct, 1199 1158 /* .pfnDestruct = */ NULL, 1200 1159 /* .pfnFinalDestruct = */ NULL, … … 1209 1168 /* .pfnReserved7 = */ NULL, 1210 1169 #elif defined(IN_RC) 1211 /* .pfnConstruct = */ NULL,1170 /* .pfnConstruct = */ kbdRZConstruct, 1212 1171 /* .pfnReserved0 = */ NULL, 1213 1172 /* .pfnReserved1 = */ NULL, -
trunk/src/VBox/Devices/Input/DevPS2.h
r82200 r82201 341 341 PPDMDEVINSR0 pDevInsR0; 342 342 343 /** I/O port 60h. */ 344 IOMIOPORTHANDLE hIoPortData; 345 /** I/O port 64h. */ 346 IOMIOPORTHANDLE hIoPortCmdStatus; 347 343 348 /** Keyboard state (implemented in separate PS2K module). */ 344 349 PS2K Kbd;
Note:
See TracChangeset
for help on using the changeset viewer.