VirtualBox

Changeset 70774 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 28, 2018 9:46:57 PM (7 years ago)
Author:
vboxsync
Message:

Devices/Serial: Allow attaching/detaching the driver below during runtime (forgotten file)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DevSerial.cpp

    r70097 r70774  
    11441144
    11451145/**
     1146 * @interface_method_impl{PDMDEVREG,pfnAttach}
     1147 */
     1148static DECLCALLBACK(int) serialR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     1149{
     1150    RT_NOREF(iLUN, fFlags);
     1151    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
     1152
     1153    int rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Serial Char");
     1154    if (RT_SUCCESS(rc))
     1155    {
     1156        pThis->pDrvChar = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMICHARCONNECTOR);
     1157        if (!pThis->pDrvChar)
     1158        {
     1159            AssertLogRelMsgFailed(("Configuration error: instance %d has no char interface!\n", pDevIns->iInstance));
     1160            return VERR_PDM_MISSING_INTERFACE;
     1161        }
     1162    }
     1163    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     1164    {
     1165        pThis->pDrvBase = NULL;
     1166        pThis->pDrvChar = NULL;
     1167        rc = VINF_SUCCESS;
     1168        LogRel(("Serial%d: no unit\n", pDevIns->iInstance));
     1169    }
     1170    else /* Don't call VMSetError here as we assume that the driver already set an appropriate error */
     1171        LogRel(("Serial%d: Failed to attach to char driver. rc=%Rrc\n", pDevIns->iInstance, rc));
     1172
     1173   return rc;
     1174}
     1175
     1176
     1177/**
     1178 * @interface_method_impl{PDMDEVREG,pfnDetach}
     1179 */
     1180static DECLCALLBACK(void) serialR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     1181{
     1182    RT_NOREF(iLUN, fFlags);
     1183    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
     1184
     1185    /* Zero out important members. */
     1186    pThis->pDrvBase = NULL;
     1187    pThis->pDrvChar = NULL;
     1188}
     1189
     1190
     1191/**
    11461192 * @interface_method_impl{PDMDEVREG,pfnDestruct}
    11471193 */
     
    13621408    /*
    13631409     * Attach the char driver and get the interfaces.
    1364      * For now no run-time changes are supported.
    13651410     */
    13661411    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Serial Char");
     
    14331478    NULL,
    14341479    /* pfnAttach */
    1435     NULL,
     1480    serialR3Attach,
    14361481    /* pfnDetach */
    1437     NULL,
     1482    serialR3Detach,
    14381483    /* pfnQueryInterface. */
    14391484    NULL,
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