VirtualBox

Changeset 82201 in vbox for trunk/src/VBox/Devices/Input


Ignore:
Timestamp:
Nov 25, 2019 9:32:30 PM (5 years ago)
Author:
vboxsync
Message:

DevPS2: Converted I/O ports. bugref:9218

Location:
trunk/src/VBox/Devices/Input
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/DevPS2.cpp

    r82195 r82201  
    4848#define LOG_GROUP LOG_GROUP_DEV_KBD
    4949#include <VBox/vmm/pdmdev.h>
     50#include <VBox/AssertGuest.h>
    5051#include <iprt/assert.h>
    5152#include <iprt/uuid.h>
     
    149150
    150151
    151 /*********************************************************************************************************************************
    152 *   Internal Functions                                                                                                           *
    153 *********************************************************************************************************************************/
    154 RT_C_DECLS_BEGIN
    155 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_END
    160 
    161 
    162152/**
    163153 * Convert an AT (Scan Set 2) scancode to PC (Scan Set 1).
     
    310300}
    311301
    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 
     302static VBOXSTRICTRC kbd_write_command(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t val)
     303{
    328304#ifdef DEBUG_KBD
    329305    Log(("kbd: write cmd=0x%02x\n", val));
     
    355331# ifndef IN_RING3
    356332        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 */
    362335        PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), true);
    363336# endif /* IN_RING3 */
     
    397370# ifndef IN_RING3
    398371        if (!PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)))
    399             rc = VINF_IOM_R3_IOPORT_WRITE;
    400 # else /* IN_RING3 */
     372            return VINF_IOM_R3_IOPORT_WRITE;
     373# else  /* IN_RING3 */
    401374        PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), true);
    402375# endif /* IN_RING3 */
     
    405378# ifndef IN_RING3
    406379        if (PDMDevHlpA20IsEnabled(s->CTX_SUFF(pDevIns)))
    407             rc = VINF_IOM_R3_IOPORT_WRITE;
    408 # else /* IN_RING3 */
     380            return VINF_IOM_R3_IOPORT_WRITE;
     381# else  /* IN_RING3 */
    409382        PDMDevHlpA20Set(s->CTX_SUFF(pDevIns), false);
    410 # endif /* !IN_RING3 */
     383# endif /* IN_RING3 */
    411384        break;
    412385#endif
     
    419392    case KBD_CCMD_RESET_ALT:
    420393#ifndef IN_RING3
    421         rc = VINF_IOM_R3_IOPORT_WRITE;
    422 #else /* IN_RING3 */
     394        return VINF_IOM_R3_IOPORT_WRITE;
     395#else  /* IN_RING3 */
    423396        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 */
    427399    case 0xff:
    428400        /* ignore that - I don't know what is its use */
     
    444416        break;
    445417    }
    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
     421static uint32_t kbd_read_data(PPDMDEVINS pDevIns, PKBDSTATE s)
    450422{
    451423    uint32_t val;
    452     NOREF(addr);
    453424
    454425    /* Return the current DBB contents. */
     
    483454}
    484455
    485 static int kbd_write_data(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t addr, uint32_t val)
     456static int kbd_write_data(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t val)
    486457{
    487458    int rc = VINF_SUCCESS;
    488     NOREF(addr);
    489459
    490460#ifdef DEBUG_KBD
     
    674644
    675645/**
    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 */
     649static 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 */
     682static 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
    724688    if (cb == 1 || cb == 2)
    725689    {
    726690        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));
    729693    }
    730694    else
    731         AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
     695        ASSERT_GUEST_MSG_FAILED(("Port=0x60+%x cb=%d\n", offPort, cb));
    732696    return rc;
    733697}
    734698
    735699/**
    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 */
     703static 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 */
     736static 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
    784741    if (cb == 1 || cb == 2)
    785742    {
    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     else
    791         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;
    793750}
    794751
     
    10991056     * Register I/O ports.
    11001057     */
    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);
    11231064
    11241065    /*
     
    11471088}
    11481089
    1149 #endif /* IN_RING3 */
     1090#else  /* !IN_RING3 */
     1091
     1092/**
     1093 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     1094 */
     1095static 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 */
    11501109
    11511110/**
     
    11961155#elif defined(IN_RING0)
    11971156    /* .pfnEarlyConstruct = */      NULL,
    1198     /* .pfnConstruct = */           NULL,
     1157    /* .pfnConstruct = */           kbdRZConstruct,
    11991158    /* .pfnDestruct = */            NULL,
    12001159    /* .pfnFinalDestruct = */       NULL,
     
    12091168    /* .pfnReserved7 = */           NULL,
    12101169#elif defined(IN_RC)
    1211     /* .pfnConstruct = */           NULL,
     1170    /* .pfnConstruct = */           kbdRZConstruct,
    12121171    /* .pfnReserved0 = */           NULL,
    12131172    /* .pfnReserved1 = */           NULL,
  • trunk/src/VBox/Devices/Input/DevPS2.h

    r82200 r82201  
    341341    PPDMDEVINSR0                pDevInsR0;
    342342
     343    /** I/O port 60h. */
     344    IOMIOPORTHANDLE             hIoPortData;
     345    /** I/O port 64h. */
     346    IOMIOPORTHANDLE             hIoPortCmdStatus;
     347
    343348    /** Keyboard state (implemented in separate PS2K module). */
    344349    PS2K                        Kbd;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette