- Timestamp:
- Sep 2, 2020 10:44:05 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp
r82968 r85992 68 68 static int patchAml(PPDMDEVINS pDevIns, uint8_t *pabAml, size_t cbAml) 69 69 { 70 uint16_t cNumCpus; 71 int rc; 72 73 rc = CFGMR3QueryU16Def(pDevIns->pCfg, "NumCPUs", &cNumCpus, 1); 74 70 uint16_t cCpus; 71 int rc = CFGMR3QueryU16Def(pDevIns->pCfg, "NumCPUs", &cCpus, 1); 75 72 if (RT_FAILURE(rc)) 76 73 return rc; … … 83 80 84 81 if (!fShowCpu) 85 c NumCpus = 0;86 87 /* *82 cCpus = 0; 83 84 /* 88 85 * Now search AML for: 89 86 * AML_PROCESSOR_OP (UINT16) 0x5b83 … … 97 94 * AML_PROCESSOR_OP 98 95 * 99 * DefProcessor := ProcessorOp PkgLength NameString ProcID 100 PblkAddr PblkLen ObjectList 96 * DefProcessor := ProcessorOp PkgLength NameString ProcID PblkAddr PblkLen ObjectList 101 97 * ProcessorOp := ExtOpPrefix 0x83 102 98 * ProcID := ByteData … … 111 107 112 108 /* Processor ID */ 113 if (pabAml[i+7] < c NumCpus)109 if (pabAml[i+7] < cCpus) 114 110 continue; 115 111 … … 138 134 pabAml[9] = (uint8_t)(0 - bSum); 139 135 140 return 0;136 return VINF_SUCCESS; 141 137 } 142 138 … … 147 143 static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t *pabAml, size_t cbAml) 148 144 { 149 uint16_t cNumCpus; 150 int rc; 151 uint32_t idxAml = 0; 152 153 rc = CFGMR3QueryU16Def(pDevIns->pCfg, "NumCPUs", &cNumCpus, 1); 154 145 uint16_t cCpus; 146 int rc = CFGMR3QueryU16Def(pDevIns->pCfg, "NumCPUs", &cCpus, 1); 155 147 if (RT_FAILURE(rc)) 156 148 return rc; 157 149 158 /* *150 /* 159 151 * Now search AML for: 160 152 * AML_DEVICE_OP (UINT16) 0x5b82 … … 163 155 * for VCPU not configured 164 156 */ 157 uint32_t idxAml = 0; 165 158 while (idxAml < cbAml - 7) 166 159 { … … 230 223 /* Processor ID */ 231 224 uint8_t const idAmlCpu = pabAmlCpu[idxAmlCpu + 8]; 232 if (idAmlCpu < c NumCpus)225 if (idAmlCpu < cCpus) 233 226 { 234 227 LogFlow(("CPU %u is configured\n", idAmlCpu)); … … 272 265 pabAml[9] = (uint8_t)(0 - bSum); 273 266 274 return 0;267 return VINF_SUCCESS; 275 268 } 276 269 … … 287 280 * @param pcbAmlCode Where to store the number of bytes of the AML code on success. 288 281 */ 289 static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, const char *pcszSignature, uint8_t **ppabAmlCode, size_t *pcbAmlCode) 290 { 291 uint8_t *pabAmlCode = NULL; 292 size_t cbAmlCode = 0; 282 static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, const char *pcszSignature, 283 uint8_t **ppabAmlCode, size_t *pcbAmlCode) 284 { 293 285 char *pszAmlFilePath = NULL; 294 286 int rc = CFGMR3QueryStringAlloc(pDevIns->pCfg, pcszCfgName, &pszAmlFilePath); 295 296 287 if (RT_SUCCESS(rc)) 297 288 { 298 289 /* Load from file. */ 299 RTFILE FileAml = NIL_RTFILE; 300 301 rc = RTFileOpen(&FileAml, pszAmlFilePath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 290 RTFILE hFileAml = NIL_RTFILE; 291 rc = RTFileOpen(&hFileAml, pszAmlFilePath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 302 292 if (RT_SUCCESS(rc)) 303 293 { 304 294 /* 305 * An AML file contains the raw DSDT thus the size of the file306 * is equal to the size of the DSDT .295 * An AML file contains the raw DSDT or SSDT thus the size of the file 296 * is equal to the size of the DSDT or SSDT. 307 297 */ 308 298 uint64_t cbAmlFile = 0; 309 rc = RTFileQuerySize(FileAml, &cbAmlFile); 310 311 cbAmlCode = (size_t)cbAmlFile; 312 313 /* Don't use AML files over 4GB ;) */ 299 rc = RTFileQuerySize(hFileAml, &cbAmlFile); 300 301 /* Don't use AML files over 32MiB. */ 314 302 if ( RT_SUCCESS(rc) 315 && ((uint64_t)cbAmlCode == cbAmlFile)) 316 { 317 pabAmlCode = (uint8_t *)RTMemAllocZ(cbAmlCode); 303 && cbAmlFile <= _32M) 304 { 305 size_t const cbAmlCode = (size_t)cbAmlFile; 306 uint8_t *pabAmlCode = (uint8_t *)RTMemAllocZ(cbAmlCode); 318 307 if (pabAmlCode) 319 308 { 320 rc = RTFileReadAt( FileAml, 0, pabAmlCode, cbAmlCode, NULL);309 rc = RTFileReadAt(hFileAml, 0, pabAmlCode, cbAmlCode, NULL); 321 310 322 311 /* … … 344 333 rc = VERR_NO_MEMORY; 345 334 } 346 347 RTFileClose(FileAml); 335 else if (RT_SUCCESS(rc)) 336 rc = VERR_OUT_OF_RANGE; 337 338 RTFileClose(hFileAml); 348 339 } 349 340 MMR3HeapFree(pszAmlFilePath); … … 363 354 size_t cbAmlCodeDsdt = 0; 364 355 int rc = acpiAmlLoadExternal(pDevIns, "DsdtFilePath", "DSDT", &pabAmlCodeDsdt, &cbAmlCodeDsdt); 365 366 356 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 367 357 { 368 rc = VINF_SUCCESS;369 370 358 /* Use the compiled in AML code */ 371 359 cbAmlCodeDsdt = sizeof(AmlCode); 372 pabAmlCodeDsdt = (uint8_t *)RTMem AllocZ(cbAmlCodeDsdt);360 pabAmlCodeDsdt = (uint8_t *)RTMemDup(AmlCode, cbAmlCodeDsdt); 373 361 if (pabAmlCodeDsdt) 374 memcpy(pabAmlCodeDsdt, AmlCode, cbAmlCodeDsdt);362 rc = VINF_SUCCESS; 375 363 else 376 364 rc = VERR_NO_MEMORY; 377 365 } 378 366 else if (RT_FAILURE(rc)) 379 return PDMDEV_SET_ERROR(pDevIns, rc, 380 N_("Configuration error: Failed to read \"DsdtFilePath\"")); 367 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to read \"DsdtFilePath\"")); 381 368 382 369 if (RT_SUCCESS(rc)) … … 409 396 size_t cbAmlCodeSsdt = 0; 410 397 int rc = acpiAmlLoadExternal(pDevIns, "SsdtFilePath", "SSDT", &pabAmlCodeSsdt, &cbAmlCodeSsdt); 411 412 398 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 413 399 { 414 400 bool fCpuHotPlug = false; 415 uint8_t *pabAmlCode = NULL;416 401 rc = CFGMR3QueryBoolDef(pDevIns->pCfg, "CpuHotPlug", &fCpuHotPlug, false); 417 418 if (RT_FAILURE(rc)) 419 return rc; 420 421 if (fCpuHotPlug) 402 if (RT_SUCCESS(rc)) 422 403 { 423 pabAmlCode = AmlCodeSsdtCpuHotPlug; 424 cbAmlCodeSsdt = sizeof(AmlCodeSsdtCpuHotPlug); 404 if (fCpuHotPlug) 405 { 406 cbAmlCodeSsdt = sizeof(AmlCodeSsdtCpuHotPlug); 407 pabAmlCodeSsdt = (uint8_t *)RTMemDup(AmlCodeSsdtCpuHotPlug, sizeof(AmlCodeSsdtCpuHotPlug)); 408 } 409 else 410 { 411 cbAmlCodeSsdt = sizeof(AmlCodeSsdtStandard); 412 pabAmlCodeSsdt = (uint8_t *)RTMemDup(AmlCodeSsdtStandard, sizeof(AmlCodeSsdtStandard)); 413 } 414 if (pabAmlCodeSsdt) 415 { 416 if (fCpuHotPlug) 417 patchAmlCpuHotPlug(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt); 418 else 419 patchAml(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt); 420 } 421 else 422 rc = VERR_NO_MEMORY; 425 423 } 426 else427 {428 pabAmlCode = AmlCodeSsdtStandard;429 cbAmlCodeSsdt = sizeof(AmlCodeSsdtStandard);430 }431 432 pabAmlCodeSsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeSsdt);433 if (pabAmlCodeSsdt)434 {435 memcpy(pabAmlCodeSsdt, pabAmlCode, cbAmlCodeSsdt);436 437 if (fCpuHotPlug)438 patchAmlCpuHotPlug(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt);439 else440 patchAml(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt);441 }442 else443 rc = VERR_NO_MEMORY;444 424 } 445 425 else if (RT_FAILURE(rc)) 446 return PDMDEV_SET_ERROR(pDevIns, rc, 447 N_("Configuration error: Failed to read \"SsdtFilePath\"")); 426 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to read \"SsdtFilePath\"")); 448 427 449 428 if (RT_SUCCESS(rc)) … … 452 431 *pcbSsdt = cbAmlCodeSsdt; 453 432 } 454 455 return VINF_SUCCESS; 433 return rc; 456 434 } 457 435
Note:
See TracChangeset
for help on using the changeset viewer.