- Timestamp:
- Feb 13, 2025 6:24:31 PM (3 months ago)
- svn:sync-xref-src-repo-rev:
- 167535
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/acpi/acpi-ast.cpp
r108095 r108215 253 253 break; 254 254 } 255 case kAcpiAstNodeOp_External:256 {257 AssertBreakStmt( pAstNd->cArgs == 3258 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString259 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_ObjType260 && pAstNd->aArgs[2].enmType == kAcpiAstArgType_U8,261 rc = VERR_INTERNAL_ERROR);262 rc = RTAcpiTblExternalAppend(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString, pAstNd->aArgs[1].u.enmObjType, pAstNd->aArgs[2].u.u8);263 break;264 }265 255 case kAcpiAstNodeOp_Method: 266 256 { … … 719 709 break; 720 710 } 711 case kAcpiAstNodeOp_External: 721 712 case kAcpiAstNodeOp_Ones: 722 713 default: -
trunk/src/VBox/Runtime/common/acpi/acpi-compiler.cpp
r108184 r108215 209 209 /** Error information. */ 210 210 PRTERRINFO pErrInfo; 211 /** List of external declarations. */ 212 RTLISTANCHOR LstExternals; 211 213 /** List of AST nodes for the DefinitionBlock() scope. */ 212 214 RTLISTANCHOR LstStmts; … … 996 998 997 999 998 static DECLCALLBACK(int) rtAcpiTblAslParseExternal(PRTACPIASLCU pThis, PCRTACPIASLKEYWORD pKeyword, PRTACPIASTNODE pAstNd) 999 { 1000 RT_NOREF(pKeyword, pAstNd); 1001 1000 static DECLCALLBACK(int) rtAcpiTblAslParseExternal(PRTACPIASLCU pThis) 1001 { 1002 1002 RTACPIASL_PARSE_PUNCTUATOR(RTACPIASLTERMINAL_PUNCTUATOR_OPEN_BRACKET, '('); 1003 1003 1004 1004 /* Namestring is required. */ 1005 1005 RTACPIASL_PARSE_NAME_STRING(pszNameString); 1006 pAstNd->aArgs[0].enmType = kAcpiAstArgType_NameString; 1007 pAstNd->aArgs[0].u.pszNameString = pszNameString; 1008 1009 /* Defaults for optional arguments. */ 1010 pAstNd->aArgs[1].enmType = kAcpiAstArgType_ObjType; 1011 pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Unknown; 1012 pAstNd->aArgs[2].enmType = kAcpiAstArgType_U8; 1013 pAstNd->aArgs[2].u.u8 = 0; 1006 1007 RTACPIOBJTYPE enmObjType = kAcpiObjType_Unknown; 1014 1008 1015 1009 if (rtAcpiAslLexerIsPunctuator(pThis, RTACPIASLTERMINAL_PUNCTUATOR_COMMA)) … … 1026 1020 switch (enmKeyword) 1027 1021 { 1028 case RTACPIASLTERMINAL_KEYWORD_UNKNOWN_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Unknown; break;1029 case RTACPIASLTERMINAL_KEYWORD_INT_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Int; break;1030 case RTACPIASLTERMINAL_KEYWORD_STR_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Str; break;1031 case RTACPIASLTERMINAL_KEYWORD_BUFF_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Buff; break;1032 case RTACPIASLTERMINAL_KEYWORD_PKG_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Pkg; break;1033 case RTACPIASLTERMINAL_KEYWORD_FIELD_UNIT_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_FieldUnit; break;1034 case RTACPIASLTERMINAL_KEYWORD_DEVICE_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Device; break;1035 case RTACPIASLTERMINAL_KEYWORD_EVENT_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Event; break;1036 case RTACPIASLTERMINAL_KEYWORD_METHOD_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Method; break;1037 case RTACPIASLTERMINAL_KEYWORD_MUTEX_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_MutexObj; break;1038 case RTACPIASLTERMINAL_KEYWORD_OP_REGION_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_OpRegion; break;1039 case RTACPIASLTERMINAL_KEYWORD_POWER_RES_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_PowerRes; break;1040 case RTACPIASLTERMINAL_KEYWORD_THERMAL_ZONE_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_ThermalZone; break;1041 case RTACPIASLTERMINAL_KEYWORD_BUFF_FIELD_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_BuffField; break;1042 case RTACPIASLTERMINAL_KEYWORD_PROCESSOR_OBJ: pAstNd->aArgs[1].u.enmObjType = kAcpiObjType_Processor; break;1022 case RTACPIASLTERMINAL_KEYWORD_UNKNOWN_OBJ: enmObjType = kAcpiObjType_Unknown; break; 1023 case RTACPIASLTERMINAL_KEYWORD_INT_OBJ: enmObjType = kAcpiObjType_Int; break; 1024 case RTACPIASLTERMINAL_KEYWORD_STR_OBJ: enmObjType = kAcpiObjType_Str; break; 1025 case RTACPIASLTERMINAL_KEYWORD_BUFF_OBJ: enmObjType = kAcpiObjType_Buff; break; 1026 case RTACPIASLTERMINAL_KEYWORD_PKG_OBJ: enmObjType = kAcpiObjType_Pkg; break; 1027 case RTACPIASLTERMINAL_KEYWORD_FIELD_UNIT_OBJ: enmObjType = kAcpiObjType_FieldUnit; break; 1028 case RTACPIASLTERMINAL_KEYWORD_DEVICE_OBJ: enmObjType = kAcpiObjType_Device; break; 1029 case RTACPIASLTERMINAL_KEYWORD_EVENT_OBJ: enmObjType = kAcpiObjType_Event; break; 1030 case RTACPIASLTERMINAL_KEYWORD_METHOD_OBJ: enmObjType = kAcpiObjType_Method; break; 1031 case RTACPIASLTERMINAL_KEYWORD_MUTEX_OBJ: enmObjType = kAcpiObjType_MutexObj; break; 1032 case RTACPIASLTERMINAL_KEYWORD_OP_REGION_OBJ: enmObjType = kAcpiObjType_OpRegion; break; 1033 case RTACPIASLTERMINAL_KEYWORD_POWER_RES_OBJ: enmObjType = kAcpiObjType_PowerRes; break; 1034 case RTACPIASLTERMINAL_KEYWORD_THERMAL_ZONE_OBJ: enmObjType = kAcpiObjType_ThermalZone; break; 1035 case RTACPIASLTERMINAL_KEYWORD_BUFF_FIELD_OBJ: enmObjType = kAcpiObjType_BuffField; break; 1036 case RTACPIASLTERMINAL_KEYWORD_PROCESSOR_OBJ: enmObjType = kAcpiObjType_Processor; break; 1043 1037 default: 1044 1038 AssertFailedReturn(VERR_INTERNAL_ERROR); … … 1063 1057 RTACPIASL_PARSE_PUNCTUATOR(RTACPIASLTERMINAL_PUNCTUATOR_CLOSE_BRACKET, ')'); 1064 1058 1065 int rc = rtAcpiNsAddEntryAstNode(pThis->pNs, pAstNd->aArgs[0].u.pszNameString, pAstNd, true /*fSwitchTo*/); 1059 /* Query the final name path. */ 1060 char achNamePath[_1K]; 1061 size_t cchNamePath = RT_ELEMENTS(achNamePath) * sizeof(char); 1062 int rc = rtAcpiNsQueryNamePathForNameString(pThis->pNs, pszNameString, &achNamePath[0], &cchNamePath); 1066 1063 if (RT_FAILURE(rc)) 1067 return RTErrInfoSetF(pThis->pErrInfo, rc, "Failed to add External(%s,,,) to namespace", pAstNd->aArgs[0].u.pszNameString); 1064 return RTErrInfoSetF(pThis->pErrInfo, rc, "Failed to query name path for External(%s,,,)", pszNameString); 1065 1066 size_t const cbExternal = RT_UOFFSETOF_DYN(RTACPIASLEXTERNAL, szNamePath[cchNamePath + 1]); 1067 PRTACPIASLEXTERNAL pExternal = (PRTACPIASLEXTERNAL)RTMemAllocZ(cbExternal); 1068 if (!pExternal) 1069 return RTErrInfoSetF(pThis->pErrInfo, VERR_NO_MEMORY, "Out of memory allocating %u bytes for External(%s,,,)", pszNameString, cbExternal); 1070 1071 RTListAppend(&pThis->LstExternals, &pExternal->NdExternal); 1072 1073 pExternal->enmObjType = enmObjType; 1074 pExternal->cArgs = UINT32_MAX; 1075 pExternal->pszName = pszNameString; 1076 pExternal->cchNamePath = cchNamePath; 1077 memcpy(&pExternal->szNamePath[0], &achNamePath[0], cchNamePath + 1); 1078 1079 rc = rtAcpiNsAddEntryExternal(pThis->pNs, pszNameString, pExternal); 1080 if (RT_FAILURE(rc)) 1081 return RTErrInfoSetF(pThis->pErrInfo, rc, "Failed to add External(%s,,,) to namespace", pszNameString); 1068 1082 1069 1083 return VINF_SUCCESS; … … 1199 1213 RTACPIASL_PARSE_NATURAL(offBytes); 1200 1214 aFieldEntries[cFields].pszName = NULL; 1201 aFieldEntries[cFields].cBits = offBytes * sizeof(uint8_t);1215 aFieldEntries[cFields].cBits = offBytes * 8; 1202 1216 RTACPIASL_PARSE_PUNCTUATOR(RTACPIASLTERMINAL_PUNCTUATOR_CLOSE_BRACKET, ')'); 1203 1217 } … … 2399 2413 } 2400 2414 }, 2401 /* kAcpiAstNodeOp_External */ RTACPI_ASL_KEYWORD_DEFINE_ HANDLER( "External", rtAcpiTblAslParseExternal, 1, 2, RTACPI_AST_NODE_F_DEFAULT),2415 /* kAcpiAstNodeOp_External */ RTACPI_ASL_KEYWORD_DEFINE_INVALID, /* Special handling. */ 2402 2416 /* kAcpiAstNodeOp_Method */ RTACPI_ASL_KEYWORD_DEFINE_HANDLER( "Method", rtAcpiTblAslParseMethod, 1, 3, RTACPI_AST_NODE_F_NEW_SCOPE), 2403 2417 /* kAcpiAstNodeOp_Device */ RTACPI_ASL_KEYWORD_DEFINE_1REQ_0OPT("Device", RTACPI_AST_NODE_F_NEW_SCOPE | RTACPI_AST_NODE_F_NS_ENTRY, kAcpiAstArgType_NameString), … … 2758 2772 static int rtAcpiTblAslParseTermArg(PRTACPIASLCU pThis, PRTACPIASTNODE *ppAstNd) 2759 2773 { 2774 int rc; 2760 2775 PCRTSCRIPTLEXTOKEN pTok; 2761 int rc = RTScriptLexQueryToken(pThis->hLexSource, &pTok); 2762 if (RT_FAILURE(rc)) 2763 return RTErrInfoSetF(pThis->pErrInfo, rc, "Parser: Failed to query next token with %Rrc", rc); 2776 2777 /* External declarations are treated differently so consume all here. */ 2778 for (;;) 2779 { 2780 rc = RTScriptLexQueryToken(pThis->hLexSource, &pTok); 2781 if (RT_FAILURE(rc)) 2782 return RTErrInfoSetF(pThis->pErrInfo, rc, "Parser: Failed to query next token with %Rrc", rc); 2783 2784 if ( pTok->enmType == RTSCRIPTLEXTOKTYPE_KEYWORD 2785 && pTok->Type.Keyword.pKeyword->u64Val == kAcpiAstNodeOp_External) 2786 { 2787 RTScriptLexConsumeToken(pThis->hLexSource); 2788 rc = rtAcpiTblAslParseExternal(pThis); 2789 if (RT_FAILURE(rc)) 2790 return rc; 2791 } 2792 else 2793 break; 2794 } 2764 2795 2765 2796 if (pTok->enmType == RTSCRIPTLEXTOKTYPE_ERROR) … … 2918 2949 pThis->hVfsIosIn = hVfsIosIn; 2919 2950 pThis->pErrInfo = pErrInfo; 2951 RTListInit(&pThis->LstExternals); 2920 2952 RTListInit(&pThis->LstStmts); 2921 2953 … … 2935 2967 2936 2968 /* 3. - Traverse AST and output table. */ 2937 PRTACPIASTNODE pIt; 2938 RTListForEach(&pThis->LstStmts, pIt, RTACPIASTNODE, NdAst) 2969 2970 /* First external declarations - those are enclosed in an If (0) { } block. */ 2971 if (!RTListIsEmpty(&pThis->LstExternals)) 2939 2972 { 2940 rc = rtAcpiAstNodeTransform(pIt, pErrInfo); 2941 if (RT_FAILURE(rc)) 2942 break; 2943 2944 rc = rtAcpiAstDumpToTbl(pIt, pThis->hAcpiTbl); 2945 if (RT_FAILURE(rc)) 2946 break; 2973 RTAcpiTblIfStart(pThis->hAcpiTbl); 2974 RTAcpiTblIntegerAppend(pThis->hAcpiTbl, 0); 2975 2976 PRTACPIASLEXTERNAL pExternal; 2977 RTListForEach(&pThis->LstExternals, pExternal, RTACPIASLEXTERNAL, NdExternal) 2978 { 2979 rc = RTAcpiTblExternalAppend(pThis->hAcpiTbl, pExternal->szNamePath, pExternal->enmObjType, 2980 pExternal->cArgs == UINT32_MAX ? 0 : pExternal->cArgs); 2981 if (RT_FAILURE(rc)) 2982 break; 2983 } 2984 2985 RTAcpiTblIfFinalize(pThis->hAcpiTbl); 2986 } 2987 2988 if (RT_SUCCESS(rc)) 2989 { 2990 PRTACPIASTNODE pIt; 2991 RTListForEach(&pThis->LstStmts, pIt, RTACPIASTNODE, NdAst) 2992 { 2993 rc = rtAcpiAstNodeTransform(pIt, pErrInfo); 2994 if (RT_FAILURE(rc)) 2995 break; 2996 2997 rc = rtAcpiAstDumpToTbl(pIt, pThis->hAcpiTbl); 2998 if (RT_FAILURE(rc)) 2999 break; 3000 } 2947 3001 } 2948 3002 -
trunk/src/VBox/Runtime/common/acpi/acpi-ns.cpp
r108184 r108215 231 231 int rc = rtAcpiNsAddEntryWorker(pNsRoot, pszNameString, fSwitchTo, &pNsEntry); 232 232 if (RT_SUCCESS(rc)) 233 { 234 pNsEntry->fAstNd = true; 233 235 pNsEntry->pAstNd = pAstNd; 236 } 234 237 235 238 return rc; … … 243 246 if (RT_SUCCESS(rc)) 244 247 { 248 pNsEntry->fAstNd = false; 245 249 pNsEntry->pAstNd = NULL; 246 250 pNsEntry->offBits = offBits; … … 252 256 253 257 258 DECLHIDDEN(int) rtAcpiNsAddEntryExternal(PRTACPINSROOT pNsRoot, const char *pszNameString, PCRTACPIASLEXTERNAL pExternal) 259 { 260 PRTACPINSENTRY pNsEntry = NULL; 261 int rc = rtAcpiNsAddEntryWorker(pNsRoot, pszNameString, false /*fSwitchTo*/, &pNsEntry); 262 if (RT_SUCCESS(rc)) 263 { 264 pNsEntry->fAstNd = false; 265 pNsEntry->pExternal = pExternal; 266 } 267 268 return rc; 269 } 270 271 272 DECLHIDDEN(int) rtAcpiNsQueryNamePathForNameString(PRTACPINSROOT pNsRoot, const char *pszNameString, char *pachNamePath, size_t *pcchNamePath) 273 { 274 AssertReturn(!pachNamePath || *pcchNamePath >= 6, VERR_INVALID_PARAMETER); /* Needs to support at least \XXXX and the zero terminator. */ 275 276 const char *pszNameSegLast = NULL; 277 PCRTACPINSENTRY pNsEntry = rtAcpiNsLookupWorker(pNsRoot, pszNameString, true /*fExcludeLast*/, &pszNameSegLast); 278 if (pNsEntry) 279 { 280 int rc = VERR_BUFFER_OVERFLOW; 281 size_t cchNamePath = 1; /* For the root prefix. */ 282 283 if (!pachNamePath) 284 { 285 /* Calculate the name path size based on the number of segments. */ 286 uint32_t cEntries = 0; 287 do 288 { 289 cEntries++; 290 pNsEntry = pNsEntry->pParent; 291 } while (pNsEntry); 292 293 cchNamePath += cEntries * (4 + 1) - 1; /* XXXX., except for the last one. */ 294 } 295 else 296 { 297 uint32_t idxEntry = 0; 298 PCRTACPINSENTRY aNsEntries[255]; /* Maximum amount of name segments possible. */ 299 do 300 { 301 aNsEntries[idxEntry++] = pNsEntry; 302 pNsEntry = pNsEntry->pParent; 303 } while (pNsEntry); 304 305 char *pch = pachNamePath; 306 *pch++ = '\\'; 307 *pch = '\0'; 308 309 /* The last entry must be the root entry. */ 310 idxEntry--; 311 Assert(!aNsEntries[idxEntry]->pParent); 312 313 while (idxEntry) 314 { 315 pNsEntry = aNsEntries[--idxEntry]; 316 if (cchNamePath + 5 < *pcchNamePath) 317 { 318 pch[0] = pNsEntry->achNameSeg[0]; 319 pch[1] = pNsEntry->achNameSeg[1]; 320 pch[2] = pNsEntry->achNameSeg[2]; 321 pch[3] = pNsEntry->achNameSeg[3]; 322 pch[4] = '.'; 323 pch += 5; 324 } 325 cchNamePath += 5; 326 } 327 328 /* Append the last name segment. */ 329 if (cchNamePath + 5 < *pcchNamePath) 330 { 331 pch[0] = pszNameSegLast[0]; 332 pch[1] = pszNameSegLast[1]; 333 pch[2] = pszNameSegLast[2]; 334 pch[3] = pszNameSegLast[3]; 335 pch[4] = '\0'; 336 cchNamePath += 4; 337 } 338 339 if (cchNamePath <= *pcchNamePath) 340 rc = VINF_SUCCESS; 341 } 342 343 *pcchNamePath = cchNamePath; 344 return rc; 345 } 346 347 *pcchNamePath = 0; 348 return VERR_NOT_FOUND; 349 } 350 351 254 352 DECLHIDDEN(int) rtAcpiNsPop(PRTACPINSROOT pNsRoot) 255 353 { -
trunk/src/VBox/Runtime/common/acpi/acpi.cpp
r108187 r108215 1642 1642 1643 1643 *pb++ = ACPI_RSRCS_TAG_END; 1644 #if 1 1644 1645 /* 1645 1646 * Generate checksum, we could just write 0 here which will be treated as checksum operation succeeded, … … 1649 1650 */ 1650 1651 *pb = RTAcpiChecksumGenerate(pThis->pbResBuf, pThis->offResBuf - 1); /* Exclude the checksum field. */ 1652 #else 1653 /* iasl just writes zero for the checksum. */ 1654 *pb = 0; 1655 #endif 1651 1656 1652 1657 pThis->fSealed = true; -
trunk/src/VBox/Runtime/include/internal/acpi.h
r108184 r108215 237 237 238 238 239 /** 240 * External declaration. 241 */ 242 typedef struct RTACPIASLEXTERNAL 243 { 244 /** List node for the list of externals. */ 245 RTLISTNODE NdExternal; 246 /** The object type. */ 247 RTACPIOBJTYPE enmObjType; 248 /** For methods this will hold the argument count. */ 249 uint32_t cArgs; 250 /** The name as parsed from the source file. */ 251 const char *pszName; 252 /** Size of the full name path in characters excluding the terminating zero. */ 253 size_t cchNamePath; 254 /** The name path - variable in size. */ 255 char szNamePath[1]; 256 } RTACPIASLEXTERNAL; 257 /** Pointer to an external declaration. */ 258 typedef RTACPIASLEXTERNAL *PRTACPIASLEXTERNAL; 259 /** Pointer to a const external declaration. */ 260 typedef const RTACPIASLEXTERNAL *PCRTACPIASLEXTERNAL; 261 262 263 239 264 /** Pointer to an ACPI namespace entry. */ 240 265 typedef struct RTACPINSENTRY *PRTACPINSENTRY; … … 252 277 /** The name segment identifying the entry. */ 253 278 char achNameSeg[4]; 254 /** The AST node associated with this namespace entry. */ 255 PCRTACPIASTNODE pAstNd; 279 /** Flag whether this points to an AST node or an external. */ 280 bool fAstNd; 281 /** Type dependent data. */ 282 union 283 { 284 /** The AST node associated with this namespace entry. */ 285 PCRTACPIASTNODE pAstNd; 286 /** Pointer to the external declaration. */ 287 PCRTACPIASLEXTERNAL pExternal; 288 }; 256 289 /** Bit offset for resource fields. */ 257 290 uint32_t offBits; … … 358 391 359 392 /** 393 * Adds a new namespace entry to the given name space - resource field. 394 * 395 * @returns IPRT status code. 396 * @param pNsRoot The namespace root to add the entry to. 397 * @param pszNameString An ACPI NameString (either segment or path). 398 * @param offBits Bit offset from the beginning of the resource. 399 * @param cBits NUmber of bits this resource field has. 400 */ 401 DECLHIDDEN(int) rtAcpiNsAddEntryExternal(PRTACPINSROOT pNsRoot, const char *pszNameString, PCRTACPIASLEXTERNAL pExternal); 402 403 404 /** 405 * Queries the name path for the given name string based on the current scope. 406 * 407 * @returns IPRT status code. 408 * @retval VERR_NOT_FOUND if the name string can't be resolved to a name path with the given namespace. 409 * @retval VERR_BUFFER_OVERFLOW if the buffer for holding the name path is too small. pcchNamePath will 410 * hold the required number of characters, excluding the zero temrinator. 411 * @param pNsRoot The namespace root. 412 * @param pszNameString The name string to query the name path for. 413 * @param pachNamePath Where to store the name path (including zero terminator), or NULL if the size is queried. 414 * @param pcchNamePath Holds the size of the name path buffer on input, on successful return 415 * holds the actual length of the name path excluding the zero terminator. 416 */ 417 DECLHIDDEN(int) rtAcpiNsQueryNamePathForNameString(PRTACPINSROOT pNsRoot, const char *pszNameString, char *pachNamePath, size_t *pcchNamePath); 418 419 420 /** 360 421 * Pops the current name space entry from the stack and returns to the previous one. 361 422 *
Note:
See TracChangeset
for help on using the changeset viewer.