Changeset 88905 in vbox for trunk/src/VBox
- Timestamp:
- May 6, 2021 2:14:24 PM (4 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevHda.cpp
r88880 r88905 2401 2401 RTListForEach(&pThisCC->lstDrv, pDrv, HDADRIVER, Node) 2402 2402 { 2403 /* We ignore failures here because one non-working driver shouldn't 2404 be allowed to spoil it for everyone else. */ 2403 2405 int rc2 = hdaR3MixerAddDrvStream(pDevIns, pMixSink, pCfg, pDrv); 2404 2406 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)); 2409 2408 } 2410 2409 } … … 4389 4388 4390 4389 /** 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(). 4396 4391 * 4397 4392 * @returns VBox status code. … … 4400 4395 * @param pThisCC The ring-3 HDA device state. 4401 4396 * @param uLUN The logical unit which is being detached. 4402 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.4403 4397 * @param ppDrv Attached driver instance on success. Optional. 4404 4398 */ 4405 static int hdaR3AttachInternal(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTATER3 pThisCC, unsigned uLUN, uint32_t fFlags, PHDADRIVER *ppDrv) 4406 { 4407 RT_NOREF(fFlags); 4408 4399 static int hdaR3AttachInternal(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTATER3 pThisCC, unsigned uLUN, PHDADRIVER *ppDrv) 4400 { 4409 4401 /* 4410 4402 * Attach driver. 4411 4403 */ 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); 4415 4406 4416 4407 PPDMIBASE pDrvBase; … … 4421 4412 if (pDrv) 4422 4413 { 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)) 4441 4417 { 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; 4444 4466 } 4445 4467 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; 4469 4469 } 4470 4470 else … … 4473 4473 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 4474 4474 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)); 4484 4480 return rc; 4485 4481 } 4486 4482 4487 /** 4488 * Detach command, internal version. 4483 4484 /** 4485 * @interface_method_impl{PDMDEVREG,pfnAttach} 4486 */ 4487 static 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. 4489 4512 * 4490 4513 * This is called to let the device detach from a driver for a specified LUN 4491 * duringruntime.4514 * at runtime. 4492 4515 * 4493 * @returns VBox status code.4494 4516 * @param pDevIns The device instance. 4495 4517 * @param pThisCC The ring-3 HDA device state. 4496 4518 * @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 */ 4520 static void hdaR3DetachInternal(PPDMDEVINS pDevIns, PHDASTATER3 pThisCC, PHDADRIVER pDrv) 4521 { 4503 4522 /* First, remove the driver from our list and destory it's associated streams. 4504 4523 * This also will un-set the driver as a recording source (if associated). */ … … 4539 4558 } 4540 4559 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 */ 4567 static DECLCALLBACK(void) hdaR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags) 4550 4568 { 4551 4569 PHDASTATE pThis = PDMDEVINS_2_DATA(pDevIns, PHDASTATE); 4552 4570 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); 4557 4575 4558 4576 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 } 4565 4587 4566 4588 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)); 4600 4590 } 4601 4591 … … 4955 4945 AssertBreak(iLun < UINT8_MAX); 4956 4946 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 */); 4958 4948 if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 4959 4949 { -
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r88899 r88905 3941 3941 * Attach driver. 3942 3942 */ 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); 3946 3945 3947 3946 PPDMIBASE pDrvBase; … … 3952 3951 if (pDrv) 3953 3952 { 3954 pDrv->pDrvBase = pDrvBase;3955 3953 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) 3971 3956 { 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; 3974 3981 } 3975 3976 if (ppDrv) 3977 *ppDrv = pDrv; 3982 RTMemFree(pDrv); 3983 rc = VERR_PDM_MISSING_INTERFACE_BELOW; 3978 3984 } 3979 3985 else … … 3982 3988 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 3983 3989 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)); 3993 3995 return rc; 3994 3996 } 3995 3997 3996 3998 /** 3997 * Detach command, internal version. 3999 * @interface_method_impl{PDMDEVREGR3,pfnAttach} 4000 */ 4001 static 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. 3998 4026 * 3999 4027 * 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 * 4003 4030 * @param pDevIns The device instance. 4004 4031 * @param pThisCC The ring-3 AC'97 device state. 4005 4032 * @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 */ 4034 static void ichac97R3DetachInternal(PPDMDEVINS pDevIns, PAC97STATER3 pThisCC, PAC97DRIVER pDrv) 4035 { 4012 4036 /* First, remove the driver from our list and destory it's associated streams. 4013 4037 * This also will un-set the driver as a recording source (if associated). */ … … 4049 4073 } 4050 4074 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 */ 4081 static DECLCALLBACK(void) ichac97R3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags) 4059 4082 { 4060 4083 PAC97STATE pThis = PDMDEVINS_2_DATA(pDevIns, PAC97STATE); 4061 4084 PAC97STATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PAC97STATER3); 4085 RT_NOREF(fFlags); 4062 4086 4063 4087 LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags)); … … 4066 4090 4067 4091 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 } 4074 4103 4075 4104 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)); 4110 4106 } 4111 4107 -
trunk/src/VBox/Devices/Audio/DevSB16.cpp
r88899 r88905 1934 1934 1935 1935 /********************************************************************************************************************************* 1936 * Driver handling*1936 * LUN (driver) management * 1937 1937 *********************************************************************************************************************************/ 1938 1938 … … 1950 1950 1951 1951 if (enmDir == PDMAUDIODIR_IN) 1952 {1953 1952 return NULL; /** @todo Recording not implemented yet. */ 1954 } 1955 elseif (enmDir == PDMAUDIODIR_OUT)1953 1954 if (enmDir == PDMAUDIODIR_OUT) 1956 1955 { 1957 1956 LogFunc(("enmDst=%RU32\n", dstSrc.enmDst)); … … 2124 2123 if (AudioHlpStreamCfgIsValid(&pThis->aStreams[i].Cfg)) 2125 2124 { 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); 2128 2127 if (RT_SUCCESS(rc)) 2129 2128 rc = rc2; … … 2137 2136 * Removes a specific SB16 driver from the driver chain and destroys its 2138 2137 * associated streams. 2138 * 2139 * This is only used by sb16Detach. 2139 2140 * 2140 2141 * @param pDevIns The device instance. … … 2866 2867 2867 2868 /* 2868 * A ttachdriver.2869 * Allocate a new driver structure and try attach the driver. 2869 2870 */ 2870 2871 PSB16DRIVER pDrv = (PSB16DRIVER)RTMemAllocZ(sizeof(SB16DRIVER)); … … 2876 2877 if (RT_SUCCESS(rc)) 2877 2878 { 2878 pDrv->pDrvBase = pDrvBase;2879 2879 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)) 2895 2882 { 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; 2898 2907 } 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)); 2903 2912 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)); 2911 2917 return rc; 2912 2918 } 2913 2919 2914 2920 /** 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 */ 2923 static 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)); 2929 2928 2930 2929 /** @todo r=andy Any locking required here? */ 2931 2930 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 2949 2931 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; 2958 2941 } 2959 2942 … … 2968 2951 LogFunc(("iLUN=%u, fFlags=0x%x\n", iLUN, fFlags)); 2969 2952 2970 PSB16DRIVER pDrv , pDrvNext;2971 RTListForEach Safe(&pThis->lstDrv, pDrv, pDrvNext, SB16DRIVER, Node)2953 PSB16DRIVER pDrv; 2954 RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node) 2972 2955 { 2973 2956 if (pDrv->uLUN == iLUN) 2974 2957 { 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; 2982 2961 } 2983 2962 } 2963 LogFunc(("LUN#%u was not found\n", iLUN)); 2984 2964 } 2985 2965
Note:
See TracChangeset
for help on using the changeset viewer.