VirtualBox

Changeset 88905 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 6, 2021 2:14:24 PM (4 years ago)
Author:
vboxsync
Message:

Audio/Dev*: Overhauled the attach/detach code a little, making attach fail if the configured driver doesn't have a PDMIADUIOCONNECTOR interface among other things. bugref:9890

Location:
trunk/src/VBox/Devices/Audio
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DevHda.cpp

    r88880 r88905  
    24012401        RTListForEach(&pThisCC->lstDrv, pDrv, HDADRIVER, Node)
    24022402        {
     2403            /* We ignore failures here because one non-working driver shouldn't
     2404               be allowed to spoil it for everyone else. */
    24032405            int rc2 = hdaR3MixerAddDrvStream(pDevIns, pMixSink, pCfg, pDrv);
    24042406            if (RT_FAILURE(rc2))
    2405                 LogFunc(("Attaching stream failed with %Rrc\n", rc2));
    2406 
    2407             /* Do not pass failure to rc here, as there might be drivers which aren't
    2408              * configured / ready yet. */
     2407                LogFunc(("Attaching stream failed with %Rrc (ignored)\n", rc2));
    24092408        }
    24102409    }
     
    43894388
    43904389/**
    4391  * Attach command, internal version.
    4392  *
    4393  * This is called to let the device attach to a driver for a specified LUN
    4394  * during runtime. This is not called during VM construction, the device
    4395  * constructor has to attach to all the available drivers.
     4390 * Worker for hdaR3Construct() and hdaR3Attach().
    43964391 *
    43974392 * @returns VBox status code.
     
    44004395 * @param   pThisCC     The ring-3 HDA device state.
    44014396 * @param   uLUN        The logical unit which is being detached.
    4402  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    44034397 * @param   ppDrv       Attached driver instance on success. Optional.
    44044398 */
    4405 static int hdaR3AttachInternal(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTATER3 pThisCC, unsigned uLUN, uint32_t fFlags, PHDADRIVER *ppDrv)
    4406 {
    4407     RT_NOREF(fFlags);
    4408 
     4399static int hdaR3AttachInternal(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTATER3 pThisCC, unsigned uLUN, PHDADRIVER *ppDrv)
     4400{
    44094401    /*
    44104402     * Attach driver.
    44114403     */
    4412     char *pszDesc;
    4413     if (RTStrAPrintf(&pszDesc, "Audio driver port (HDA) for LUN#%u", uLUN) <= 0)
    4414         AssertLogRelFailedReturn(VERR_NO_MEMORY);
     4404    char *pszDesc = RTStrAPrintf2("Audio driver port (HDA) for LUN#%u", uLUN);
     4405    AssertLogRelReturn(pszDesc, VERR_NO_STR_MEMORY);
    44154406
    44164407    PPDMIBASE pDrvBase;
     
    44214412        if (pDrv)
    44224413        {
    4423             pDrv->pDrvBase          = pDrvBase;
    4424             pDrv->pHDAStateShared   = pThis;
    4425             pDrv->pHDAStateR3       = pThisCC;
    4426             pDrv->uLUN              = uLUN;
    4427             pDrv->pConnector        = PDMIBASE_QUERY_INTERFACE(pDrvBase, PDMIAUDIOCONNECTOR);
    4428             AssertMsg(pDrv->pConnector != NULL, ("Configuration error: LUN#%u has no host audio interface, rc=%Rrc\n", uLUN, rc));
    4429 
    4430             /*
    4431              * For now we always set the driver at LUN 0 as our primary
    4432              * host backend. This might change in the future.
    4433              */
    4434             if (pDrv->uLUN == 0)
    4435                 pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
    4436 
    4437             LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", uLUN, pDrv->pConnector, pDrv->fFlags));
    4438 
    4439             /* Attach to driver list if not attached yet. */
    4440             if (!pDrv->fAttached)
     4414            pDrv->pConnector = PDMIBASE_QUERY_INTERFACE(pDrvBase, PDMIAUDIOCONNECTOR);
     4415            AssertPtr(pDrv->pConnector);
     4416            if (RT_VALID_PTR(pDrv->pConnector))
    44414417            {
    4442                 RTListAppend(&pThisCC->lstDrv, &pDrv->Node);
    4443                 pDrv->fAttached = true;
     4418                pDrv->pDrvBase          = pDrvBase;
     4419                pDrv->pHDAStateShared   = pThis;
     4420                pDrv->pHDAStateR3       = pThisCC;
     4421                pDrv->uLUN              = uLUN;
     4422                AssertMsg(pDrv->pConnector != NULL, ("Configuration error: LUN#%u has no host audio interface, rc=%Rrc\n", uLUN, rc));
     4423
     4424                /*
     4425                 * For now we always set the driver at LUN 0 as our primary
     4426                 * host backend. This might change in the future.
     4427                 */
     4428                if (pDrv->uLUN == 0)
     4429                    pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
     4430
     4431                LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", uLUN, pDrv->pConnector, pDrv->fFlags));
     4432
     4433                /* Attach to driver list if not attached yet. */
     4434                if (!pDrv->fAttached)
     4435                {
     4436                    RTListAppend(&pThisCC->lstDrv, &pDrv->Node);
     4437                    pDrv->fAttached = true;
     4438                }
     4439
     4440                if (ppDrv)
     4441                    *ppDrv = pDrv;
     4442
     4443                /*
     4444                 * While we're here, give the windows backends a hint about our typical playback
     4445                 * configuration.
     4446                 * Note! If 48000Hz is advertised to the guest, add it here.
     4447                 */
     4448                if (   pDrv->pConnector
     4449                    && pDrv->pConnector->pfnStreamConfigHint)
     4450                {
     4451                    PDMAUDIOSTREAMCFG Cfg;
     4452                    RT_ZERO(Cfg);
     4453                    Cfg.enmDir                        = PDMAUDIODIR_OUT;
     4454                    Cfg.u.enmDst                      = PDMAUDIOPLAYBACKDST_FRONT;
     4455                    Cfg.enmLayout                     = PDMAUDIOSTREAMLAYOUT_INTERLEAVED;
     4456                    Cfg.Device.cMsSchedulingHint      = 10;
     4457                    Cfg.Backend.cFramesPreBuffering   = UINT32_MAX;
     4458                    PDMAudioPropsInit(&Cfg.Props, 2, true /*fSigned*/, 2, 44100);
     4459                    RTStrPrintf(Cfg.szName, sizeof(Cfg.szName), "output 44.1kHz 2ch S16 (HDA config hint)");
     4460
     4461                    pDrv->pConnector->pfnStreamConfigHint(pDrv->pConnector, &Cfg); /* (may trash CfgReq) */
     4462                }
     4463
     4464                LogFunc(("LUN#%u: VINF_SUCCESS\n", uLUN));
     4465                return VINF_SUCCESS;
    44444466            }
    44454467
    4446             if (ppDrv)
    4447                 *ppDrv = pDrv;
    4448 
    4449             /*
    4450              * While we're here, give the windows backends a hint about our typical playback
    4451              * configuration.
    4452              * Note! If 48000Hz is advertised to the guest, add it here.
    4453              */
    4454             if (   pDrv->pConnector
    4455                 && pDrv->pConnector->pfnStreamConfigHint)
    4456             {
    4457                 PDMAUDIOSTREAMCFG Cfg;
    4458                 RT_ZERO(Cfg);
    4459                 Cfg.enmDir                        = PDMAUDIODIR_OUT;
    4460                 Cfg.u.enmDst                      = PDMAUDIOPLAYBACKDST_FRONT;
    4461                 Cfg.enmLayout                     = PDMAUDIOSTREAMLAYOUT_INTERLEAVED;
    4462                 Cfg.Device.cMsSchedulingHint      = 10;
    4463                 Cfg.Backend.cFramesPreBuffering   = UINT32_MAX;
    4464                 PDMAudioPropsInit(&Cfg.Props, 2, true /*fSigned*/, 2, 44100);
    4465                 RTStrPrintf(Cfg.szName, sizeof(Cfg.szName), "output 44.1kHz 2ch S16 (HDA config hint)");
    4466 
    4467                 pDrv->pConnector->pfnStreamConfigHint(pDrv->pConnector, &Cfg); /* (may trash CfgReq) */
    4468             }
     4468            rc = VERR_PDM_MISSING_INTERFACE_BELOW;
    44694469        }
    44704470        else
     
    44734473    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    44744474        LogFunc(("No attached driver for LUN #%u\n", uLUN));
    4475 
    4476     if (RT_FAILURE(rc))
    4477     {
    4478         /* Only free this string on failure;
    4479          * must remain valid for the live of the driver instance. */
    4480         RTStrFree(pszDesc);
    4481     }
    4482 
    4483     LogFunc(("uLUN=%u, fFlags=0x%x, rc=%Rrc\n", uLUN, fFlags, rc));
     4475    else
     4476        LogFunc(("Failed attaching driver for LUN #%u: %Rrc\n", uLUN, rc));
     4477
     4478    RTStrFree(pszDesc);
     4479    LogFunc(("LUN#%u: rc=%Rrc\n", uLUN, rc));
    44844480    return rc;
    44854481}
    44864482
    4487 /**
    4488  * Detach command, internal version.
     4483
     4484/**
     4485 * @interface_method_impl{PDMDEVREG,pfnAttach}
     4486 */
     4487static DECLCALLBACK(int) hdaR3Attach(PPDMDEVINS pDevIns, unsigned uLUN, uint32_t fFlags)
     4488{
     4489    PHDASTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PHDASTATE);
     4490    PHDASTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PHDASTATER3);
     4491    RT_NOREF(fFlags);
     4492    LogFunc(("uLUN=%u, fFlags=0x%x\n", uLUN, fFlags));
     4493
     4494    DEVHDA_LOCK_RETURN(pDevIns, pThis, VERR_IGNORED);
     4495
     4496    PHDADRIVER pDrv;
     4497    int rc = hdaR3AttachInternal(pDevIns, pThis, pThisCC, uLUN, &pDrv);
     4498    if (RT_SUCCESS(rc))
     4499    {
     4500        int rc2 = hdaR3MixerAddDrv(pDevIns, pThisCC, pDrv);
     4501        if (RT_FAILURE(rc2))
     4502            LogFunc(("hdaR3MixerAddDrv failed with %Rrc (ignored)\n", rc2));
     4503    }
     4504
     4505    DEVHDA_UNLOCK(pDevIns, pThis);
     4506    return rc;
     4507}
     4508
     4509
     4510/**
     4511 * Worker for hdaR3Detach that does all but free pDrv.
    44894512 *
    44904513 * This is called to let the device detach from a driver for a specified LUN
    4491  * during runtime.
     4514 * at runtime.
    44924515 *
    4493  * @returns VBox status code.
    44944516 * @param   pDevIns     The device instance.
    44954517 * @param   pThisCC     The ring-3 HDA device state.
    44964518 * @param   pDrv        Driver to detach from device.
    4497  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    4498  */
    4499 static int hdaR3DetachInternal(PPDMDEVINS pDevIns, PHDASTATER3 pThisCC, PHDADRIVER pDrv, uint32_t fFlags)
    4500 {
    4501     RT_NOREF(fFlags);
    4502 
     4519 */
     4520static void hdaR3DetachInternal(PPDMDEVINS pDevIns, PHDASTATER3 pThisCC, PHDADRIVER pDrv)
     4521{
    45034522    /* First, remove the driver from our list and destory it's associated streams.
    45044523     * This also will un-set the driver as a recording source (if associated). */
     
    45394558    }
    45404559
    4541     LogFunc(("uLUN=%u, fFlags=0x%x\n", pDrv->uLUN, fFlags));
    4542     return VINF_SUCCESS;
    4543 }
    4544 
    4545 
    4546 /**
    4547  * @interface_method_impl{PDMDEVREG,pfnAttach}
    4548  */
    4549 static DECLCALLBACK(int) hdaR3Attach(PPDMDEVINS pDevIns, unsigned uLUN, uint32_t fFlags)
     4560    LogFunc(("LUN#%u detached\n", pDrv->uLUN));
     4561}
     4562
     4563
     4564/**
     4565 * @interface_method_impl{PDMDEVREG,pfnDetach}
     4566 */
     4567static DECLCALLBACK(void) hdaR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    45504568{
    45514569    PHDASTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PHDASTATE);
    45524570    PHDASTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PHDASTATER3);
    4553 
    4554     DEVHDA_LOCK_RETURN(pDevIns, pThis, VERR_IGNORED);
    4555 
    4556     LogFunc(("uLUN=%u, fFlags=0x%x\n", uLUN, fFlags));
     4571    RT_NOREF(fFlags);
     4572    LogFunc(("iLUN=%u, fFlags=%#x\n", iLUN, fFlags));
     4573
     4574    DEVHDA_LOCK(pDevIns, pThis);
    45574575
    45584576    PHDADRIVER pDrv;
    4559     int rc2 = hdaR3AttachInternal(pDevIns, pThis, pThisCC, uLUN, fFlags, &pDrv);
    4560     if (RT_SUCCESS(rc2))
    4561         rc2 = hdaR3MixerAddDrv(pDevIns, pThisCC, pDrv);
    4562 
    4563     if (RT_FAILURE(rc2))
    4564         LogFunc(("Failed with %Rrc\n", rc2));
     4577    RTListForEach(&pThisCC->lstDrv, pDrv, HDADRIVER, Node)
     4578    {
     4579        if (pDrv->uLUN == iLUN)
     4580        {
     4581            hdaR3DetachInternal(pDevIns, pThisCC, pDrv);
     4582            RTMemFree(pDrv);
     4583            DEVHDA_UNLOCK(pDevIns, pThis);
     4584            return;
     4585        }
     4586    }
    45654587
    45664588    DEVHDA_UNLOCK(pDevIns, pThis);
    4567 
    4568     return VINF_SUCCESS;
    4569 }
    4570 
    4571 
    4572 /**
    4573  * @interface_method_impl{PDMDEVREG,pfnDetach}
    4574  */
    4575 static DECLCALLBACK(void) hdaR3Detach(PPDMDEVINS pDevIns, unsigned uLUN, uint32_t fFlags)
    4576 {
    4577     PHDASTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PHDASTATE);
    4578     PHDASTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PHDASTATER3);
    4579 
    4580     DEVHDA_LOCK(pDevIns, pThis);
    4581 
    4582     LogFunc(("uLUN=%u, fFlags=0x%x\n", uLUN, fFlags));
    4583 
    4584     PHDADRIVER pDrv, pDrvNext;
    4585     RTListForEachSafe(&pThisCC->lstDrv, pDrv, pDrvNext, HDADRIVER, Node)
    4586     {
    4587         if (pDrv->uLUN == uLUN)
    4588         {
    4589             int rc2 = hdaR3DetachInternal(pDevIns, pThisCC, pDrv, fFlags);
    4590             if (RT_SUCCESS(rc2))
    4591             {
    4592                 RTMemFree(pDrv);
    4593                 pDrv = NULL;
    4594             }
    4595             break;
    4596         }
    4597     }
    4598 
    4599     DEVHDA_UNLOCK(pDevIns, pThis);
     4589    LogFunc(("LUN#%u was not found\n", iLUN));
    46004590}
    46014591
     
    49554945        AssertBreak(iLun < UINT8_MAX);
    49564946        LogFunc(("Trying to attach driver for LUN#%u ...\n", iLun));
    4957         rc = hdaR3AttachInternal(pDevIns, pThis, pThisCC, iLun, 0 /* fFlags */, NULL /* ppDrv */);
     4947        rc = hdaR3AttachInternal(pDevIns, pThis, pThisCC, iLun, NULL /* ppDrv */);
    49584948        if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    49594949        {
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r88899 r88905  
    39413941     * Attach driver.
    39423942     */
    3943     char *pszDesc;
    3944     if (RTStrAPrintf(&pszDesc, "Audio driver port (AC'97) for LUN #%u", iLun) <= 0)
    3945         AssertLogRelFailedReturn(VERR_NO_MEMORY);
     3943    char *pszDesc = RTStrAPrintf2("Audio driver port (AC'97) for LUN #%u", iLun);
     3944    AssertLogRelReturn(pszDesc, VERR_NO_STR_MEMORY);
    39463945
    39473946    PPDMIBASE pDrvBase;
     
    39523951        if (pDrv)
    39533952        {
    3954             pDrv->pDrvBase   = pDrvBase;
    39553953            pDrv->pConnector = PDMIBASE_QUERY_INTERFACE(pDrvBase, PDMIAUDIOCONNECTOR);
    3956             AssertMsg(pDrv->pConnector != NULL, ("Configuration error: LUN #%u has no host audio interface, rc=%Rrc\n", iLun, rc));
    3957             pDrv->uLUN       = iLun;
    3958             pDrv->pszDesc    = pszDesc;
    3959 
    3960             /*
    3961              * For now we always set the driver at LUN 0 as our primary
    3962              * host backend. This might change in the future.
    3963              */
    3964             if (iLun == 0)
    3965                 pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
    3966 
    3967             LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", iLun, pDrv->pConnector, pDrv->fFlags));
    3968 
    3969             /* Attach to driver list if not attached yet. */
    3970             if (!pDrv->fAttached)
     3954            AssertPtr(pDrv->pConnector);
     3955            if (pDrv->pConnector)
    39713956            {
    3972                 RTListAppend(&pThisCC->lstDrv, &pDrv->Node);
    3973                 pDrv->fAttached = true;
     3957                pDrv->pDrvBase   = pDrvBase;
     3958                pDrv->uLUN       = iLun;
     3959                pDrv->pszDesc    = pszDesc;
     3960
     3961                /*
     3962                 * For now we always set the driver at LUN 0 as our primary
     3963                 * host backend. This might change in the future.
     3964                 */
     3965                if (iLun == 0)
     3966                    pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
     3967
     3968                LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", iLun, pDrv->pConnector, pDrv->fFlags));
     3969
     3970                /* Attach to driver list if not attached yet. */
     3971                if (!pDrv->fAttached)
     3972                {
     3973                    RTListAppend(&pThisCC->lstDrv, &pDrv->Node);
     3974                    pDrv->fAttached = true;
     3975                }
     3976
     3977                if (ppDrv)
     3978                    *ppDrv = pDrv;
     3979                LogFunc(("iLun=%u, fFlags=0x%x: VINF_SUCCESS\n", iLun, fFlags));
     3980                return VINF_SUCCESS;
    39743981            }
    3975 
    3976             if (ppDrv)
    3977                 *ppDrv = pDrv;
     3982            RTMemFree(pDrv);
     3983            rc = VERR_PDM_MISSING_INTERFACE_BELOW;
    39783984        }
    39793985        else
     
    39823988    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    39833989        LogFunc(("No attached driver for LUN #%u\n", iLun));
    3984 
    3985     if (RT_FAILURE(rc))
    3986     {
    3987         /* Only free this string on failure;
    3988          * must remain valid for the live of the driver instance. */
    3989         RTStrFree(pszDesc);
    3990     }
    3991 
    3992     LogFunc(("iLun=%u, fFlags=0x%x, rc=%Rrc\n", iLun, fFlags, rc));
     3990    else
     3991        LogFunc(("Attached driver for LUN #%u failed: %Rrc\n", iLun, rc));
     3992
     3993    RTStrFree(pszDesc);
     3994    LogFunc(("iLun=%u, fFlags=0x%x: rc=%Rrc\n", iLun, fFlags, rc));
    39933995    return rc;
    39943996}
    39953997
    39963998/**
    3997  * Detach command, internal version.
     3999 * @interface_method_impl{PDMDEVREGR3,pfnAttach}
     4000 */
     4001static DECLCALLBACK(int) ichac97R3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     4002{
     4003    PAC97STATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PAC97STATE);
     4004    PAC97STATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PAC97STATER3);
     4005
     4006    LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags));
     4007
     4008    DEVAC97_LOCK(pDevIns, pThis);
     4009
     4010    PAC97DRIVER pDrv;
     4011    int rc = ichac97R3AttachInternal(pDevIns, pThisCC, iLUN, fFlags, &pDrv);
     4012    if (RT_SUCCESS(rc))
     4013    {
     4014        int rc2 = ichac97R3MixerAddDrv(pDevIns, pThisCC, pDrv);
     4015        if (RT_FAILURE(rc2))
     4016            LogFunc(("ichac97R3MixerAddDrv failed with %Rrc (ignored)\n", rc2));
     4017    }
     4018
     4019    DEVAC97_UNLOCK(pDevIns, pThis);
     4020
     4021    return rc;
     4022}
     4023
     4024/**
     4025 * Worker for ichac97R3Detach that does all but freeing the pDrv structure.
    39984026 *
    39994027 * This is called to let the device detach from a driver for a specified LUN
    4000  * during runtime.
    4001  *
    4002  * @returns VBox status code.
     4028 * at runtime.
     4029 *
    40034030 * @param   pDevIns     The device instance.
    40044031 * @param   pThisCC     The ring-3 AC'97 device state.
    40054032 * @param   pDrv        Driver to detach from device.
    4006  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    4007  */
    4008 static int ichac97R3DetachInternal(PPDMDEVINS pDevIns, PAC97STATER3 pThisCC, PAC97DRIVER pDrv, uint32_t fFlags)
    4009 {
    4010     RT_NOREF(fFlags);
    4011 
     4033 */
     4034static void ichac97R3DetachInternal(PPDMDEVINS pDevIns, PAC97STATER3 pThisCC, PAC97DRIVER pDrv)
     4035{
    40124036    /* First, remove the driver from our list and destory it's associated streams.
    40134037     * This also will un-set the driver as a recording source (if associated). */
     
    40494073    }
    40504074
    4051     LogFunc(("uLUN=%u, fFlags=0x%x\n", pDrv->uLUN, fFlags));
    4052     return VINF_SUCCESS;
    4053 }
    4054 
    4055 /**
    4056  * @interface_method_impl{PDMDEVREGR3,pfnAttach}
    4057  */
    4058 static DECLCALLBACK(int) ichac97R3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     4075    LogFunc(("Detached LUN#%u\n", pDrv->uLUN));
     4076}
     4077
     4078/**
     4079 * @interface_method_impl{PDMDEVREG,pfnDetach}
     4080 */
     4081static DECLCALLBACK(void) ichac97R3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    40594082{
    40604083    PAC97STATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PAC97STATE);
    40614084    PAC97STATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PAC97STATER3);
     4085    RT_NOREF(fFlags);
    40624086
    40634087    LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags));
     
    40664090
    40674091    PAC97DRIVER pDrv;
    4068     int rc2 = ichac97R3AttachInternal(pDevIns, pThisCC, iLUN, fFlags, &pDrv);
    4069     if (RT_SUCCESS(rc2))
    4070         rc2 = ichac97R3MixerAddDrv(pDevIns, pThisCC, pDrv);
    4071 
    4072     if (RT_FAILURE(rc2))
    4073         LogFunc(("Failed with %Rrc\n", rc2));
     4092    RTListForEach(&pThisCC->lstDrv, pDrv, AC97DRIVER, Node)
     4093    {
     4094        if (pDrv->uLUN == iLUN)
     4095        {
     4096            ichac97R3DetachInternal(pDevIns, pThisCC, pDrv);
     4097            RTStrFree(pDrv->pszDesc);
     4098            RTMemFree(pDrv);
     4099            DEVAC97_UNLOCK(pDevIns, pThis);
     4100            return;
     4101        }
     4102    }
    40744103
    40754104    DEVAC97_UNLOCK(pDevIns, pThis);
    4076 
    4077     return VINF_SUCCESS;
    4078 }
    4079 
    4080 /**
    4081  * @interface_method_impl{PDMDEVREG,pfnDetach}
    4082  */
    4083 static DECLCALLBACK(void) ichac97R3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    4084 {
    4085     PAC97STATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PAC97STATE);
    4086     PAC97STATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PAC97STATER3);
    4087 
    4088     LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags));
    4089 
    4090     DEVAC97_LOCK(pDevIns, pThis);
    4091 
    4092     PAC97DRIVER pDrv, pDrvNext;
    4093     RTListForEachSafe(&pThisCC->lstDrv, pDrv, pDrvNext, AC97DRIVER, Node)
    4094     {
    4095         if (pDrv->uLUN == iLUN)
    4096         {
    4097             int rc2 = ichac97R3DetachInternal(pDevIns, pThisCC, pDrv, fFlags);
    4098             if (RT_SUCCESS(rc2))
    4099             {
    4100                 RTStrFree(pDrv->pszDesc);
    4101                 RTMemFree(pDrv);
    4102                 pDrv = NULL;
    4103             }
    4104 
    4105             break;
    4106         }
    4107     }
    4108 
    4109     DEVAC97_UNLOCK(pDevIns, pThis);
     4105    LogFunc(("LUN#%u was not found\n", iLUN));
    41104106}
    41114107
  • trunk/src/VBox/Devices/Audio/DevSB16.cpp

    r88899 r88905  
    19341934
    19351935/*********************************************************************************************************************************
    1936 *   Driver handling                                                                                                              *
     1936*   LUN (driver) management                                                                                                      *
    19371937*********************************************************************************************************************************/
    19381938
     
    19501950
    19511951    if (enmDir == PDMAUDIODIR_IN)
    1952     {
    19531952        return NULL; /** @todo Recording not implemented yet. */
    1954     }
    1955     else if (enmDir == PDMAUDIODIR_OUT)
     1953
     1954    if (enmDir == PDMAUDIODIR_OUT)
    19561955    {
    19571956        LogFunc(("enmDst=%RU32\n", dstSrc.enmDst));
     
    21242123        if (AudioHlpStreamCfgIsValid(&pThis->aStreams[i].Cfg))
    21252124        {
    2126             int rc2 = sb16AddDrvStream(pDevIns,
    2127                                        sb16StreamIndexToSink(pThis, pThis->aStreams[i].uIdx), &pThis->aStreams[i].Cfg, pDrv);
     2125            int rc2 = sb16AddDrvStream(pDevIns, sb16StreamIndexToSink(pThis, pThis->aStreams[i].uIdx),
     2126                                       &pThis->aStreams[i].Cfg, pDrv);
    21282127            if (RT_SUCCESS(rc))
    21292128                rc = rc2;
     
    21372136 * Removes a specific SB16 driver from the driver chain and destroys its
    21382137 * associated streams.
     2138 *
     2139 * This is only used by sb16Detach.
    21392140 *
    21402141 * @param   pDevIns     The device instance.
     
    28662867
    28672868    /*
    2868      * Attach driver.
     2869     * Allocate a new driver structure and try attach the driver.
    28692870     */
    28702871    PSB16DRIVER pDrv = (PSB16DRIVER)RTMemAllocZ(sizeof(SB16DRIVER));
     
    28762877    if (RT_SUCCESS(rc))
    28772878    {
    2878         pDrv->pDrvBase   = pDrvBase;
    28792879        pDrv->pConnector = PDMIBASE_QUERY_INTERFACE(pDrvBase, PDMIAUDIOCONNECTOR);
    2880         AssertMsg(pDrv->pConnector != NULL, ("Configuration error: LUN #%u has no host audio interface, rc=%Rrc\n", uLUN, rc));
    2881         pDrv->pSB16State = pThis;
    2882         pDrv->uLUN       = uLUN;
    2883 
    2884         /*
    2885          * For now we always set the driver at LUN 0 as our primary
    2886          * host backend. This might change in the future.
    2887          */
    2888         if (pDrv->uLUN == 0)
    2889             pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
    2890 
    2891         LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", uLUN, pDrv->pConnector, pDrv->fFlags));
    2892 
    2893         /* Attach to driver list if not attached yet. */
    2894         if (!pDrv->fAttached)
     2880        AssertPtr(pDrv->pConnector);
     2881        if (RT_VALID_PTR(pDrv->pConnector))
    28952882        {
    2896             RTListAppend(&pThis->lstDrv, &pDrv->Node);
    2897             pDrv->fAttached = true;
     2883            pDrv->pDrvBase   = pDrvBase;
     2884            pDrv->pSB16State = pThis;
     2885            pDrv->uLUN       = uLUN;
     2886
     2887            /*
     2888             * For now we always set the driver at LUN 0 as our primary
     2889             * host backend. This might change in the future.
     2890             */
     2891            if (pDrv->uLUN == 0)
     2892                pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
     2893
     2894            LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", uLUN, pDrv->pConnector, pDrv->fFlags));
     2895
     2896            /* Attach to driver list if not attached yet. */
     2897            if (!pDrv->fAttached)
     2898            {
     2899                RTListAppend(&pThis->lstDrv, &pDrv->Node);
     2900                pDrv->fAttached = true;
     2901            }
     2902
     2903            if (ppDrv)
     2904                *ppDrv = pDrv;
     2905            LogFunc(("iLUN=%u, fFlags=0x%x: VINF_SUCCESS\n", uLUN, fFlags));
     2906            return VINF_SUCCESS;
    28982907        }
    2899 
    2900         if (ppDrv)
    2901             *ppDrv = pDrv;
    2902     }
     2908        rc = VERR_PDM_MISSING_INTERFACE_BELOW;
     2909    }
     2910    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     2911        LogFunc(("No attached driver for LUN #%u\n", uLUN));
    29032912    else
    2904     {
    2905         if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    2906             LogFunc(("No attached driver for LUN #%u\n", uLUN));
    2907         RTMemFree(pDrv);
    2908     }
    2909 
    2910     LogFunc(("iLUN=%u, fFlags=0x%x, rc=%Rrc\n", uLUN, fFlags, rc));
     2913        LogFunc(("Failed to attached driver for LUN #%u: %Rrc\n", uLUN, rc));
     2914    RTMemFree(pDrv);
     2915
     2916    LogFunc(("iLUN=%u, fFlags=0x%x: rc=%Rrc\n", uLUN, fFlags, rc));
    29112917    return rc;
    29122918}
    29132919
    29142920/**
    2915  * Detach command, internal version.
    2916  *
    2917  * This is called to let the device detach from a driver for a specified LUN
    2918  * during runtime.
    2919  *
    2920  * @returns VBox status code.
    2921  * @param   pDevIns     The device instance.
    2922  * @param   pThis       The SB16 device state.
    2923  * @param   pDrv        Driver to detach from device.
    2924  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    2925  */
    2926 static int sb16DetachInternal(PPDMDEVINS pDevIns, PSB16STATE pThis, PSB16DRIVER pDrv, uint32_t fFlags)
    2927 {
    2928     RT_NOREF(fFlags);
     2921 * @interface_method_impl{PDMDEVREG,pfnAttach}
     2922 */
     2923static DECLCALLBACK(int) sb16Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     2924{
     2925    PSB16STATE pThis = PDMDEVINS_2_DATA(pDevIns, PSB16STATE);
     2926
     2927    LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags));
    29292928
    29302929    /** @todo r=andy Any locking required here? */
    29312930
    2932     sb16RemoveDrv(pDevIns, pThis, pDrv);
    2933 
    2934     LogFunc(("uLUN=%u, fFlags=0x%x\n", pDrv->uLUN, fFlags));
    2935     return VINF_SUCCESS;
    2936 }
    2937 
    2938 /**
    2939  * @interface_method_impl{PDMDEVREG,pfnAttach}
    2940  */
    2941 static DECLCALLBACK(int) sb16Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    2942 {
    2943     PSB16STATE pThis = PDMDEVINS_2_DATA(pDevIns, PSB16STATE);
    2944 
    2945     LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags));
    2946 
    2947     /** @todo r=andy Any locking required here? */
    2948 
    29492931    PSB16DRIVER pDrv;
    2950     int rc2 = sb16AttachInternal(pThis, iLUN, fFlags, &pDrv);
    2951     if (RT_SUCCESS(rc2))
    2952         rc2 = sb16AddDrv(pDevIns, pThis, pDrv);
    2953 
    2954     if (RT_FAILURE(rc2))
    2955         LogFunc(("Failed with %Rrc\n", rc2));
    2956 
    2957     return VINF_SUCCESS;
     2932    int rc = sb16AttachInternal(pThis, iLUN, fFlags, &pDrv);
     2933    if (RT_SUCCESS(rc))
     2934    {
     2935        int rc2 = sb16AddDrv(pDevIns, pThis, pDrv);
     2936        if (RT_FAILURE(rc2))
     2937            LogFunc(("sb16AddDrv failed with %Rrc (ignored)\n", rc2));
     2938    }
     2939
     2940    return rc;
    29582941}
    29592942
     
    29682951    LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags));
    29692952
    2970     PSB16DRIVER pDrv, pDrvNext;
    2971     RTListForEachSafe(&pThis->lstDrv, pDrv, pDrvNext, SB16DRIVER, Node)
     2953    PSB16DRIVER pDrv;
     2954    RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    29722955    {
    29732956        if (pDrv->uLUN == iLUN)
    29742957        {
    2975             int rc2 = sb16DetachInternal(pDevIns, pThis, pDrv, fFlags);
    2976             if (RT_SUCCESS(rc2))
    2977             {
    2978                 RTMemFree(pDrv);
    2979                 pDrv = NULL;
    2980             }
    2981             break;
     2958            sb16RemoveDrv(pDevIns, pThis, pDrv);
     2959            RTMemFree(pDrv);
     2960            return;
    29822961        }
    29832962    }
     2963    LogFunc(("LUN#%u was not found\n", iLUN));
    29842964}
    29852965
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