Changeset 88504 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Apr 14, 2021 12:24:41 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevHdaCodec.cpp
r88503 r88504 151 151 { 152 152 RT_NOREF(pszArgs); 153 for (uint8_t i = 1; i < pThis->cTotalNodes; i++) 153 uint8_t const cTotalNodes = RT_MIN(pThis->cTotalNodes, RT_ELEMENTS(pThis->aNodes)); 154 for (uint8_t i = 1; i < cTotalNodes; i++) 154 155 { 155 156 PCODECNODE pNode = &pThis->aNodes[i]; … … 754 755 pThis->fInReset = true; 755 756 756 for (uint8_t i = 0; i < pThis->cTotalNodes; i++) 757 uint8_t const cTotalNodes = (uint8_t)RT_MIN(pThis->cTotalNodes, RT_ELEMENTS(pThis->aNodes)); 758 for (uint8_t i = 0; i < cTotalNodes; i++) 757 759 stac9220NodeReset(pThis, i, &pThis->aNodes[i]); 758 760 … … 792 794 #undef STAC9220WIDGET 793 795 796 AssertCompile(STAC9221_NUM_NODES <= RT_ELEMENTS(pThis->aNodes)); 794 797 pThis->cTotalNodes = STAC9221_NUM_NODES; 795 Assert(pThis->cTotalNodes <= CODEC_NODES_MAX);796 798 797 799 pThis->u8AdcVolsLineIn = STAC9220_NID_AMP_ADC0; … … 805 807 * initialize the node default configuration values then! 806 808 */ 807 for (uint8_t i = 0; i < pThis->cTotalNodes; i++)809 for (uint8_t i = 0; i < STAC9221_NUM_NODES; i++) 808 810 stac9220NodeReset(pThis, i, &pThis->aNodes[i]); 809 811 … … 813 815 814 816 /* Common AFG node initializers. */ 815 pThis->aNodes[STAC9220_NID_AFG].afg.node.au32F00_param[0x4] = CODEC_MAKE_F00_04(0x2, pThis->cTotalNodes- 2);817 pThis->aNodes[STAC9220_NID_AFG].afg.node.au32F00_param[0x4] = CODEC_MAKE_F00_04(0x2, STAC9221_NUM_NODES - 2); 816 818 pThis->aNodes[STAC9220_NID_AFG].afg.node.au32F00_param[0x5] = CODEC_MAKE_F00_05(1, CODEC_F00_05_AFG); 817 819 pThis->aNodes[STAC9220_NID_AFG].afg.node.au32F00_param[0xA] = CODEC_F00_0A_44_1KHZ | CODEC_F00_0A_16_BIT; … … 1299 1301 RT_NOREF(pThisCC); 1300 1302 Assert(CODEC_CAD(cmd) == pThis->id); 1301 Assert(CODEC_NID(cmd) < pThis->cTotalNodes); 1302 if (CODEC_NID(cmd) >= pThis->cTotalNodes) 1303 uint8_t const cTotalNodes = (uint8_t)RT_MIN(pThis->cTotalNodes, RT_ELEMENTS(pThis->aNodes)); 1304 Assert(CODEC_NID(cmd) < cTotalNodes); 1305 if (CODEC_NID(cmd) >= cTotalNodes) 1303 1306 { 1304 1307 LogFlowFunc(("invalid node address %d\n", CODEC_NID(cmd))); 1308 *pResp = 0; 1305 1309 return VINF_SUCCESS; 1306 1310 } … … 1315 1319 { 1316 1320 Assert(CODEC_CAD(cmd) == pThis->id); 1317 Assert(CODEC_NID(cmd) < pThis->cTotalNodes); 1318 if (CODEC_NID(cmd) >= pThis->cTotalNodes) 1321 uint8_t const cTotalNodes = (uint8_t)RT_MIN(pThis->cTotalNodes, RT_ELEMENTS(pThis->aNodes)); 1322 Assert(CODEC_NID(cmd) < cTotalNodes); 1323 if (CODEC_NID(cmd) >= cTotalNodes) 1319 1324 { 1320 1325 LogFlowFunc(("invalid node address %d\n", CODEC_NID(cmd))); … … 1520 1525 RT_NOREF(pThisCC); 1521 1526 Assert(CODEC_CAD(cmd) == pThis->id); 1522 Assert(CODEC_NID(cmd) < pThis->cTotalNodes); 1523 if (CODEC_NID(cmd) >= pThis->cTotalNodes) 1524 { 1527 uint8_t const cTotalNodes = (uint8_t)RT_MIN(pThis->cTotalNodes, RT_ELEMENTS(pThis->aNodes)); 1528 Assert(CODEC_NID(cmd) < cTotalNodes); 1529 if (CODEC_NID(cmd) >= cTotalNodes) 1530 { 1531 *pResp = 0; 1525 1532 LogFlowFunc(("invalid node address %d\n", CODEC_NID(cmd))); 1526 1533 return VINF_SUCCESS; … … 2044 2051 * HDA codec verb descriptors. 2045 2052 * 2046 * @todo Any reason not to use binary search here? 2047 * bird: because you'd need to sort the entries first... 2053 * @note This must be ordered by uVerb so we can do a binary lookup. 2048 2054 */ 2049 2055 static const CODECVERB g_aCodecVerbs[] = … … 2051 2057 /* Verb Verb mask Callback Name 2052 2058 ---------- --------------------- ------------------------------------------------------------------- */ 2053 { 0x000 F0000, CODEC_VERB_8BIT_CMD , vrbProcGetParameter , "GetParameter" },2054 { 0x000 F0100, CODEC_VERB_8BIT_CMD , vrbProcGetConSelectCtrl , "GetConSelectCtrl" },2059 { 0x00020000, CODEC_VERB_16BIT_CMD, vrbProcSetConverterFormat , "SetConverterFormat " }, 2060 { 0x00030000, CODEC_VERB_16BIT_CMD, CTX_EXPR(vrbProcR3SetAmplifier,NULL,NULL), "SetAmplifier " }, 2055 2061 { 0x00070100, CODEC_VERB_8BIT_CMD , vrbProcSetConSelectCtrl , "SetConSelectCtrl " }, 2056 { 0x000F0600, CODEC_VERB_8BIT_CMD , vrbProcGetStreamId , "GetStreamId " }, 2062 { 0x00070300, CODEC_VERB_8BIT_CMD , vrbProcSetProcessingState , "SetProcessingState " }, 2063 { 0x00070400, CODEC_VERB_8BIT_CMD , vrbProcSetSDISelect , "SetSDISelect " }, 2064 { 0x00070500, CODEC_VERB_8BIT_CMD , vrbProcSetPowerState , "SetPowerState " }, 2057 2065 { 0x00070600, CODEC_VERB_8BIT_CMD , CTX_EXPR(vrbProcR3SetStreamId,NULL,NULL) , "SetStreamId " }, 2058 { 0x000F0700, CODEC_VERB_8BIT_CMD , vrbProcGetPinCtrl , "GetPinCtrl " },2059 2066 { 0x00070700, CODEC_VERB_8BIT_CMD , vrbProcSetPinCtrl , "SetPinCtrl " }, 2060 { 0x000F0800, CODEC_VERB_8BIT_CMD , vrbProcGetUnsolicitedEnabled , "GetUnsolicitedEnabled " },2061 2067 { 0x00070800, CODEC_VERB_8BIT_CMD , vrbProcSetUnsolicitedEnabled , "SetUnsolicitedEnabled " }, 2062 { 0x000F0900, CODEC_VERB_8BIT_CMD , vrbProcGetPinSense , "GetPinSense " },2063 2068 { 0x00070900, CODEC_VERB_8BIT_CMD , vrbProcSetPinSense , "SetPinSense " }, 2064 { 0x000F0200, CODEC_VERB_8BIT_CMD , vrbProcGetConnectionListEntry , "GetConnectionListEntry" }, 2065 { 0x000F0300, CODEC_VERB_8BIT_CMD , vrbProcGetProcessingState , "GetProcessingState " }, 2066 { 0x00070300, CODEC_VERB_8BIT_CMD , vrbProcSetProcessingState , "SetProcessingState " }, 2067 { 0x000F0D00, CODEC_VERB_8BIT_CMD , vrbProcGetDigitalConverter , "GetDigitalConverter " }, 2069 { 0x00070C00, CODEC_VERB_8BIT_CMD , vrbProcSetEAPD_BTLEnabled , "SetEAPD_BTLEnabled " }, 2068 2070 { 0x00070D00, CODEC_VERB_8BIT_CMD , vrbProcSetDigitalConverter1 , "SetDigitalConverter1 " }, 2069 2071 { 0x00070E00, CODEC_VERB_8BIT_CMD , vrbProcSetDigitalConverter2 , "SetDigitalConverter2 " }, 2070 { 0x000F2000, CODEC_VERB_8BIT_CMD , vrbProcGetSubId , "GetSubId " }, 2072 { 0x00070F00, CODEC_VERB_8BIT_CMD , vrbProcSetVolumeKnobCtrl , "SetVolumeKnobCtrl " }, 2073 { 0x00071500, CODEC_VERB_8BIT_CMD , vrbProcSetGPIOData , "SetGPIOData " }, 2074 { 0x00071600, CODEC_VERB_8BIT_CMD , vrbProcSetGPIOEnableMask , "SetGPIOEnableMask " }, 2075 { 0x00071700, CODEC_VERB_8BIT_CMD , vrbProcSetGPIODirection , "SetGPIODirection " }, 2076 { 0x00071C00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig0 , "SetConfig0 " }, 2077 { 0x00071D00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig1 , "SetConfig1 " }, 2078 { 0x00071E00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig2 , "SetConfig2 " }, 2079 { 0x00071F00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig3 , "SetConfig3 " }, 2071 2080 { 0x00072000, CODEC_VERB_8BIT_CMD , vrbProcSetSubId0 , "SetSubId0 " }, 2072 2081 { 0x00072100, CODEC_VERB_8BIT_CMD , vrbProcSetSubId1 , "SetSubId1 " }, … … 2074 2083 { 0x00072300, CODEC_VERB_8BIT_CMD , vrbProcSetSubId3 , "SetSubId3 " }, 2075 2084 { 0x0007FF00, CODEC_VERB_8BIT_CMD , vrbProcReset , "Reset " }, 2085 { 0x000A0000, CODEC_VERB_16BIT_CMD, vrbProcGetConverterFormat , "GetConverterFormat " }, 2086 { 0x000B0000, CODEC_VERB_16BIT_CMD, vrbProcGetAmplifier , "GetAmplifier " }, 2087 { 0x000F0000, CODEC_VERB_8BIT_CMD , vrbProcGetParameter , "GetParameter " }, 2088 { 0x000F0100, CODEC_VERB_8BIT_CMD , vrbProcGetConSelectCtrl , "GetConSelectCtrl " }, 2089 { 0x000F0200, CODEC_VERB_8BIT_CMD , vrbProcGetConnectionListEntry , "GetConnectionListEntry" }, 2090 { 0x000F0300, CODEC_VERB_8BIT_CMD , vrbProcGetProcessingState , "GetProcessingState " }, 2091 { 0x000F0400, CODEC_VERB_8BIT_CMD , vrbProcGetSDISelect , "GetSDISelect " }, 2076 2092 { 0x000F0500, CODEC_VERB_8BIT_CMD , vrbProcGetPowerState , "GetPowerState " }, 2077 { 0x00070500, CODEC_VERB_8BIT_CMD , vrbProcSetPowerState , "SetPowerState " }, 2093 { 0x000F0600, CODEC_VERB_8BIT_CMD , vrbProcGetStreamId , "GetStreamId " }, 2094 { 0x000F0700, CODEC_VERB_8BIT_CMD , vrbProcGetPinCtrl , "GetPinCtrl " }, 2095 { 0x000F0800, CODEC_VERB_8BIT_CMD , vrbProcGetUnsolicitedEnabled , "GetUnsolicitedEnabled " }, 2096 { 0x000F0900, CODEC_VERB_8BIT_CMD , vrbProcGetPinSense , "GetPinSense " }, 2078 2097 { 0x000F0C00, CODEC_VERB_8BIT_CMD , vrbProcGetEAPD_BTLEnabled , "GetEAPD_BTLEnabled " }, 2079 { 0x000 70C00, CODEC_VERB_8BIT_CMD , vrbProcSetEAPD_BTLEnabled , "SetEAPD_BTLEnabled" },2098 { 0x000F0D00, CODEC_VERB_8BIT_CMD , vrbProcGetDigitalConverter , "GetDigitalConverter " }, 2080 2099 { 0x000F0F00, CODEC_VERB_8BIT_CMD , vrbProcGetVolumeKnobCtrl , "GetVolumeKnobCtrl " }, 2081 { 0x00070F00, CODEC_VERB_8BIT_CMD , vrbProcSetVolumeKnobCtrl , "SetVolumeKnobCtrl " },2082 2100 { 0x000F1500, CODEC_VERB_8BIT_CMD , vrbProcGetGPIOData , "GetGPIOData " }, 2083 { 0x00071500, CODEC_VERB_8BIT_CMD , vrbProcSetGPIOData , "SetGPIOData " },2084 2101 { 0x000F1600, CODEC_VERB_8BIT_CMD , vrbProcGetGPIOEnableMask , "GetGPIOEnableMask " }, 2085 { 0x00071600, CODEC_VERB_8BIT_CMD , vrbProcSetGPIOEnableMask , "SetGPIOEnableMask " },2086 2102 { 0x000F1700, CODEC_VERB_8BIT_CMD , vrbProcGetGPIODirection , "GetGPIODirection " }, 2087 { 0x00071700, CODEC_VERB_8BIT_CMD , vrbProcSetGPIODirection , "SetGPIODirection " },2088 2103 { 0x000F1C00, CODEC_VERB_8BIT_CMD , vrbProcGetConfig , "GetConfig " }, 2089 { 0x00071C00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig0 , "SetConfig0 " }, 2090 { 0x00071D00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig1 , "SetConfig1 " }, 2091 { 0x00071E00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig2 , "SetConfig2 " }, 2092 { 0x00071F00, CODEC_VERB_8BIT_CMD , vrbProcSetConfig3 , "SetConfig3 " }, 2093 { 0x000A0000, CODEC_VERB_16BIT_CMD, vrbProcGetConverterFormat , "GetConverterFormat " }, 2094 { 0x00020000, CODEC_VERB_16BIT_CMD, vrbProcSetConverterFormat , "SetConverterFormat " }, 2095 { 0x000B0000, CODEC_VERB_16BIT_CMD, vrbProcGetAmplifier , "GetAmplifier " }, 2096 { 0x00030000, CODEC_VERB_16BIT_CMD, CTX_EXPR(vrbProcR3SetAmplifier,NULL,NULL), "SetAmplifier " }, 2097 { 0x000F0400, CODEC_VERB_8BIT_CMD , vrbProcGetSDISelect , "GetSDISelect " }, 2098 { 0x00070400, CODEC_VERB_8BIT_CMD , vrbProcSetSDISelect , "SetSDISelect " }, 2104 { 0x000F2000, CODEC_VERB_8BIT_CMD , vrbProcGetSubId , "GetSubId " }, 2099 2105 /** @todo Implement 0x7e7: IDT Set GPIO (STAC922x only). */ 2100 2106 }; … … 2355 2361 ("Unknown codec address 0x%x\n", CODEC_CAD(uCmd)), 2356 2362 VERR_INVALID_PARAMETER); 2357 AssertMsgReturn( CODEC_VERBDATA(uCmd) != 0 2358 && CODEC_NID(uCmd) < pThis->cTotalNodes, 2359 ("[NID0x%02x] Unknown / invalid node or data (0x%x)\n", CODEC_NID(uCmd), CODEC_VERBDATA(uCmd)), 2363 uint32_t const uCmdData = CODEC_VERBDATA(uCmd); 2364 AssertMsgReturn( uCmdData != 0 2365 && CODEC_NID(uCmd) < RT_MIN(pThis->cTotalNodes, RT_ELEMENTS(pThis->aNodes)), 2366 ("[NID0x%02x] Unknown / invalid node or data (0x%x)\n", CODEC_NID(uCmd), uCmdData), 2360 2367 VERR_INVALID_PARAMETER); 2361 2368 STAM_COUNTER_INC(&pThis->CTX_SUFF(StatLookups)); 2362 2369 2363 2370 /* 2364 * Lookupthe verb.2371 * Do a binary lookup of the verb. 2365 2372 * Note! if we want other verb tables, add a table selector before the loop. 2366 2373 */ 2367 for (size_t i = 0; i < RT_ELEMENTS(g_aCodecVerbs); i++) 2368 { 2369 if ((CODEC_VERBDATA(uCmd) & g_aCodecVerbs[i].fMask) == g_aCodecVerbs[i].uVerb) 2370 { 2374 size_t iFirst = 0; 2375 size_t iEnd = RT_ELEMENTS(g_aCodecVerbs); 2376 for (;;) 2377 { 2378 size_t const iCur = iFirst + (iEnd - iFirst) / 2; 2379 uint32_t const uVerb = g_aCodecVerbs[iCur].uVerb; 2380 if (uCmdData < uVerb) 2381 { 2382 if (iCur > iFirst) 2383 iEnd = iCur; 2384 else 2385 break; 2386 } 2387 else if ((uCmdData & g_aCodecVerbs[iCur].fMask) != uVerb) 2388 { 2389 if (iCur + 1 < iEnd) 2390 iFirst = iCur + 1; 2391 else 2392 break; 2393 } 2394 else 2395 { 2396 /* 2397 * Found it! Run the callback and return. 2398 */ 2371 2399 #ifndef IN_RING3 2372 if (!g_aCodecVerbs[i ].pfn)2400 if (!g_aCodecVerbs[iCur].pfn) 2373 2401 { 2374 2402 Log3Func(("[NID0x%02x] (0x%x) %s: 0x%x -> VERR_INVALID_CONTEXT\n", /* -> ring-3 */ 2375 CODEC_NID(uCmd), g_aCodecVerbs[i ].uVerb, g_aCodecVerbs[i].pszName, CODEC_VERB_PAYLOAD8(uCmd)));2403 CODEC_NID(uCmd), g_aCodecVerbs[iCur].uVerb, g_aCodecVerbs[iCur].pszName, CODEC_VERB_PAYLOAD8(uCmd))); 2376 2404 return VERR_INVALID_CONTEXT; 2377 2405 } 2378 2406 #endif 2379 AssertPtrReturn(g_aCodecVerbs[i ].pfn, VERR_INTERNAL_ERROR_5); /* Paranoia^2. */2380 2381 int rc = g_aCodecVerbs[i ].pfn(pThis, pThisCC, uCmd, puResp);2407 AssertPtrReturn(g_aCodecVerbs[iCur].pfn, VERR_INTERNAL_ERROR_5); /* Paranoia^2. */ 2408 2409 int rc = g_aCodecVerbs[iCur].pfn(pThis, pThisCC, uCmd, puResp); 2382 2410 AssertRC(rc); 2383 2411 Log3Func(("[NID0x%02x] (0x%x) %s: 0x%x -> 0x%x\n", 2384 CODEC_NID(uCmd), g_aCodecVerbs[i ].uVerb, g_aCodecVerbs[i].pszName, CODEC_VERB_PAYLOAD8(uCmd), *puResp));2412 CODEC_NID(uCmd), g_aCodecVerbs[iCur].uVerb, g_aCodecVerbs[iCur].pszName, CODEC_VERB_PAYLOAD8(uCmd), *puResp)); 2385 2413 return rc; 2386 2414 } 2387 2415 } 2388 2416 2417 #ifdef VBOX_STRICT 2418 for (size_t i = 0; i < RT_ELEMENTS(g_aCodecVerbs); i++) 2419 { 2420 AssertMsg(i == 0 || g_aCodecVerbs[i - 1].uVerb < g_aCodecVerbs[i].uVerb, 2421 ("i=%#x uVerb[-1]=%#x uVerb=%#x - buggy table!\n", i, g_aCodecVerbs[i - 1].uVerb, g_aCodecVerbs[i].uVerb)); 2422 AssertMsg((uCmdData & g_aCodecVerbs[i].fMask) != g_aCodecVerbs[i].uVerb, 2423 ("i=%#x uVerb=%#x uCmd=%#x - buggy binary search or table!\n", i, g_aCodecVerbs[i].uVerb, uCmd)); 2424 } 2425 #endif 2389 2426 LogFunc(("[NID0x%02x] Callback for %x not found\n", CODEC_NID(uCmd), CODEC_VERBDATA(uCmd))); 2390 2427 return VERR_NOT_FOUND;
Note:
See TracChangeset
for help on using the changeset viewer.