summaryrefslogtreecommitdiff
path: root/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-03-26 19:21:20 +0000
committer <>2014-05-08 15:03:54 +0000
commitfb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch)
treec2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp
parent58ed4748338f9466599adfc8a9171280ed99e23f (diff)
downloadVirtualBox-master.tar.gz
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp')
-rw-r--r--src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp184
1 files changed, 98 insertions, 86 deletions
diff --git a/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp b/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp
index 3f961b71..926bfc5e 100644
--- a/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp
+++ b/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2009 Oracle Corporation
+ * Copyright (C) 2009-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
@@ -15,8 +15,13 @@
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <iprt/cdefs.h>
#if !defined(IN_RING3)
-#error Pure R3 code
+# error Pure R3 code
#endif
#define LOG_GROUP LOG_GROUP_DEV_ACPI
@@ -41,24 +46,26 @@
# include <vboxssdt-cpuhotplug.hex>
#endif
+#include "VBoxDD.h"
+
+
#ifdef VBOX_WITH_DYNAMIC_DSDT
-static int prepareDynamicDsdt(PPDMDEVINS pDevIns,
- void* *ppPtr,
- size_t *puDsdtLen)
+
+static int prepareDynamicDsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbDsdt)
{
- *ppPtr = NULL;
- *puDsdtLen = 0;
+ *ppvPtr = NULL;
+ *pcbDsdt = 0;
return 0;
}
-static int cleanupDynamicDsdt(PPDMDEVINS pDevIns,
- void* pPtr)
+static int cleanupDynamicDsdt(PPDMDEVINS pDevIns, void *pvPtr)
{
return 0;
}
-#else
-static int patchAml(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
+#else /* VBOX_WITH_DYNAMIC_DSDT */
+
+static int patchAml(PPDMDEVINS pDevIns, uint8_t *pabAml, size_t cbAml)
{
uint16_t cNumCpus;
int rc;
@@ -84,7 +91,7 @@ static int patchAml(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* AML_NOOP_OP (UINT16) 0xa3
* for VCPU not configured
*/
- for (uint32_t i = 0; i < uAmlLen - 7; i++)
+ for (uint32_t i = 0; i < cbAml - 7; i++)
{
/*
* AML_PROCESSOR_OP
@@ -96,14 +103,14 @@ static int patchAml(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* PblkAddr := DwordData
* PblkLen := ByteData
*/
- if ((pAml[i] == 0x5b) && (pAml[i+1] == 0x83))
+ if (pabAml[i] == 0x5b && pabAml[i+1] == 0x83)
{
- if ((pAml[i+3] != 'C') || (pAml[i+4] != 'P'))
+ if (pabAml[i+3] != 'C' || pabAml[i+4] != 'P')
/* false alarm, not named starting CP */
continue;
/* Processor ID */
- if (pAml[i+7] < cNumCpus)
+ if (pabAml[i+7] < cNumCpus)
continue;
/* Will fill unwanted CPU block with NOOPs */
@@ -111,24 +118,24 @@ static int patchAml(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* See 18.2.4 Package Length Encoding in ACPI spec
* for full format
*/
- uint32_t cBytes = pAml[i + 2];
+ uint32_t cBytes = pabAml[i + 2];
AssertReleaseMsg((cBytes >> 6) == 0,
("So far, we only understand simple package length"));
/* including AML_PROCESSOR_OP itself */
for (uint32_t j = 0; j < cBytes + 2; j++)
- pAml[i+j] = 0xa3;
+ pabAml[i+j] = 0xa3;
/* Can increase i by cBytes + 1, but not really worth it */
}
}
/* now recompute checksum, whole file byte sum must be 0 */
- pAml[9] = 0;
- uint8_t aSum = 0;
- for (uint32_t i = 0; i < uAmlLen; i++)
- aSum = aSum + (uint8_t)pAml[i];
- pAml[9] = (uint8_t) (0 - aSum);
+ pabAml[9] = 0;
+ uint8_t bSum = 0;
+ for (uint32_t i = 0; i < cbAml; i++)
+ bSum = bSum + pabAml[i];
+ pabAml[9] = (uint8_t)(0 - bSum);
return 0;
}
@@ -137,7 +144,7 @@ static int patchAml(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* Patch the CPU hot-plug SSDT version to
* only contain the ACPI containers which may have a CPU
*/
-static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
+static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t *pabAml, size_t cbAml)
{
uint16_t cNumCpus;
int rc;
@@ -155,7 +162,7 @@ static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* AML_NOOP_OP (UINT16) 0xa3
* for VCPU not configured
*/
- while (idxAml < uAmlLen - 7)
+ while (idxAml < cbAml - 7)
{
/*
* AML_DEVICE_OP
@@ -163,37 +170,37 @@ static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* DefDevice := DeviceOp PkgLength NameString ObjectList
* DeviceOp := ExtOpPrefix 0x82
*/
- if ((pAml[idxAml] == 0x5b) && (pAml[idxAml+1] == 0x82))
+ if (pabAml[idxAml] == 0x5b && pabAml[idxAml+1] == 0x82)
{
/* Check if the enclosed CPU device is configured. */
- uint8_t *pbAmlPkgLength = &pAml[idxAml+2];
+ uint8_t *pabAmlPkgLength = &pabAml[idxAml+2];
uint32_t cBytes = 0;
- uint32_t cLengthBytesFollow = pbAmlPkgLength[0] >> 6;
+ uint32_t cLengthBytesFollow = pabAmlPkgLength[0] >> 6;
if (cLengthBytesFollow == 0)
{
/* Simple package length */
- cBytes = pbAmlPkgLength[0];
+ cBytes = pabAmlPkgLength[0];
}
else
{
unsigned idxLengthByte = 1;
- cBytes = pbAmlPkgLength[0] & 0xF;
+ cBytes = pabAmlPkgLength[0] & 0xF;
while (idxLengthByte <= cLengthBytesFollow)
{
- cBytes |= pbAmlPkgLength[idxLengthByte] << (4*idxLengthByte);
+ cBytes |= pabAmlPkgLength[idxLengthByte] << (4*idxLengthByte);
idxLengthByte++;
}
}
- uint8_t *pbAmlDevName = &pbAmlPkgLength[cLengthBytesFollow+1];
- uint8_t *pbAmlCpu = &pbAmlDevName[4];
+ uint8_t *pabAmlDevName = &pabAmlPkgLength[cLengthBytesFollow+1];
+ uint8_t *pabAmlCpu = &pabAmlDevName[4];
bool fCpuConfigured = false;
bool fCpuFound = false;
- if ((pbAmlDevName[0] != 'S') || (pbAmlDevName[1] != 'C') || (pbAmlDevName[2] != 'K'))
+ if ((pabAmlDevName[0] != 'S') || (pabAmlDevName[1] != 'C') || (pabAmlDevName[2] != 'K'))
{
/* false alarm, not named starting SCK */
idxAml++;
@@ -212,24 +219,24 @@ static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* PblkAddr := DwordData
* PblkLen := ByteData
*/
- if ((pbAmlCpu[idxAmlCpu] == 0x5b) && (pbAmlCpu[idxAmlCpu+1] == 0x83))
+ if ((pabAmlCpu[idxAmlCpu] == 0x5b) && (pabAmlCpu[idxAmlCpu+1] == 0x83))
{
- if ((pbAmlCpu[idxAmlCpu+4] != 'C') || (pbAmlCpu[idxAmlCpu+5] != 'P'))
+ if ((pabAmlCpu[idxAmlCpu+4] != 'C') || (pabAmlCpu[idxAmlCpu+5] != 'P'))
/* false alarm, not named starting CP */
continue;
fCpuFound = true;
/* Processor ID */
- if (pbAmlCpu[idxAmlCpu+8] < cNumCpus)
+ if (pabAmlCpu[idxAmlCpu+8] < cNumCpus)
{
- LogFlow(("CPU %d is configured\n", pbAmlCpu[idxAmlCpu+8]));
+ LogFlow(("CPU %d is configured\n", pabAmlCpu[idxAmlCpu+8]));
fCpuConfigured = true;
break;
}
else
{
- LogFlow(("CPU %d is not configured\n", pbAmlCpu[idxAmlCpu+8]));
+ LogFlow(("CPU %d is not configured\n", pabAmlCpu[idxAmlCpu+8]));
fCpuConfigured = false;
break;
}
@@ -248,7 +255,7 @@ static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
/* including AML_DEVICE_OP itself */
for (uint32_t j = 0; j < cBytes + 2; j++)
- pAml[idxAml+j] = 0xa3;
+ pabAml[idxAml+j] = 0xa3;
}
idxAml++;
@@ -258,15 +265,16 @@ static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
}
/* now recompute checksum, whole file byte sum must be 0 */
- pAml[9] = 0;
- uint8_t aSum = 0;
- for (uint32_t i = 0; i < uAmlLen; i++)
- aSum = aSum + (uint8_t)pAml[i];
- pAml[9] = (uint8_t) (0 - aSum);
+ pabAml[9] = 0;
+ uint8_t bSum = 0;
+ for (uint32_t i = 0; i < cbAml; i++)
+ bSum = bSum + pabAml[i];
+ pabAml[9] = (uint8_t)(0 - bSum);
return 0;
}
-#endif
+
+#endif /* VBOX_WITH_DYNAMIC_DSDT */
/**
* Loads an AML file if present in CFGM
@@ -275,12 +283,12 @@ static int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t* pAml, size_t uAmlLen)
* @param pDevIns The device instance
* @param pcszCfgName The configuration key holding the file path
* @param pcszSignature The signature to check for
- * @param ppbAmlCode Where to store the pointer to the AML code on success.
+ * @param ppabAmlCode Where to store the pointer to the AML code on success.
* @param pcbAmlCode Where to store the number of bytes of the AML code on success.
*/
-static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, const char *pcszSignature, uint8_t **ppbAmlCode, size_t *pcbAmlCode)
+static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, const char *pcszSignature, uint8_t **ppabAmlCode, size_t *pcbAmlCode)
{
- uint8_t *pbAmlCode = NULL;
+ uint8_t *pabAmlCode = NULL;
size_t cbAmlCode = 0;
char *pszAmlFilePath = NULL;
int rc = CFGMR3QueryStringAlloc(pDevIns->pCfg, pcszCfgName, &pszAmlFilePath);
@@ -306,20 +314,20 @@ static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, cons
if ( RT_SUCCESS(rc)
&& ((uint64_t)cbAmlCode == cbAmlFile))
{
- pbAmlCode = (uint8_t *)RTMemAllocZ(cbAmlCode);
- if (pbAmlCode)
+ pabAmlCode = (uint8_t *)RTMemAllocZ(cbAmlCode);
+ if (pabAmlCode)
{
- rc = RTFileReadAt(FileAml, 0, pbAmlCode, cbAmlCode, NULL);
+ rc = RTFileReadAt(FileAml, 0, pabAmlCode, cbAmlCode, NULL);
/*
* We fail if reading failed or the identifier at the
* beginning is wrong.
*/
if ( RT_FAILURE(rc)
- || strncmp((const char *)pbAmlCode, pcszSignature, 4))
+ || strncmp((const char *)pabAmlCode, pcszSignature, 4))
{
- RTMemFree(pbAmlCode);
- pbAmlCode = NULL;
+ RTMemFree(pabAmlCode);
+ pabAmlCode = NULL;
/* Return error if file header check failed */
if (RT_SUCCESS(rc))
@@ -327,7 +335,7 @@ static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, cons
}
else
{
- *ppbAmlCode = pbAmlCode;
+ *ppabAmlCode = pabAmlCode;
*pcbAmlCode = cbAmlCode;
rc = VINF_SUCCESS;
}
@@ -344,15 +352,16 @@ static int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, cons
return rc;
}
-/* Two only public functions */
-int acpiPrepareDsdt(PPDMDEVINS pDevIns, void * *ppPtr, size_t *puDsdtLen)
+
+/** No docs, lazy coder. */
+int acpiPrepareDsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbDsdt)
{
#ifdef VBOX_WITH_DYNAMIC_DSDT
- return prepareDynamicDsdt(pDevIns, ppPtr, puDsdtLen);
+ return prepareDynamicDsdt(pDevIns, ppvPtr, pcbDsdt);
#else
- uint8_t *pbAmlCodeDsdt = NULL;
+ uint8_t *pabAmlCodeDsdt = NULL;
size_t cbAmlCodeDsdt = 0;
- int rc = acpiAmlLoadExternal(pDevIns, "DsdtFilePath", "DSDT", &pbAmlCodeDsdt, &cbAmlCodeDsdt);
+ int rc = acpiAmlLoadExternal(pDevIns, "DsdtFilePath", "DSDT", &pabAmlCodeDsdt, &cbAmlCodeDsdt);
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
{
@@ -360,9 +369,9 @@ int acpiPrepareDsdt(PPDMDEVINS pDevIns, void * *ppPtr, size_t *puDsdtLen)
/* Use the compiled in AML code */
cbAmlCodeDsdt = sizeof(AmlCode);
- pbAmlCodeDsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeDsdt);
- if (pbAmlCodeDsdt)
- memcpy(pbAmlCodeDsdt, AmlCode, cbAmlCodeDsdt);
+ pabAmlCodeDsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeDsdt);
+ if (pabAmlCodeDsdt)
+ memcpy(pabAmlCodeDsdt, AmlCode, cbAmlCodeDsdt);
else
rc = VERR_NO_MEMORY;
}
@@ -372,35 +381,37 @@ int acpiPrepareDsdt(PPDMDEVINS pDevIns, void * *ppPtr, size_t *puDsdtLen)
if (RT_SUCCESS(rc))
{
- patchAml(pDevIns, pbAmlCodeDsdt, cbAmlCodeDsdt);
- *ppPtr = pbAmlCodeDsdt;
- *puDsdtLen = cbAmlCodeDsdt;
+ patchAml(pDevIns, pabAmlCodeDsdt, cbAmlCodeDsdt);
+ *ppvPtr = pabAmlCodeDsdt;
+ *pcbDsdt = cbAmlCodeDsdt;
}
return rc;
#endif
}
-int acpiCleanupDsdt(PPDMDEVINS pDevIns, void * pPtr)
+/** No docs, lazy coder. */
+int acpiCleanupDsdt(PPDMDEVINS pDevIns, void *pvPtr)
{
#ifdef VBOX_WITH_DYNAMIC_DSDT
- return cleanupDynamicDsdt(pDevIns, pPtr);
+ return cleanupDynamicDsdt(pDevIns, pvPtr);
#else
- if (pPtr)
- RTMemFree(pPtr);
+ if (pvPtr)
+ RTMemFree(pvPtr);
return VINF_SUCCESS;
#endif
}
-int acpiPrepareSsdt(PPDMDEVINS pDevIns, void* *ppPtr, size_t *puSsdtLen)
+/** No docs, lazy coder. */
+int acpiPrepareSsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbSsdt)
{
- uint8_t *pbAmlCodeSsdt = NULL;
+ uint8_t *pabAmlCodeSsdt = NULL;
size_t cbAmlCodeSsdt = 0;
- int rc = acpiAmlLoadExternal(pDevIns, "SsdtFilePath", "SSDT", &pbAmlCodeSsdt, &cbAmlCodeSsdt);
+ int rc = acpiAmlLoadExternal(pDevIns, "SsdtFilePath", "SSDT", &pabAmlCodeSsdt, &cbAmlCodeSsdt);
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
{
bool fCpuHotPlug = false;
- uint8_t *pbAmlCode = NULL;
+ uint8_t *pabAmlCode = NULL;
rc = CFGMR3QueryBoolDef(pDevIns->pCfg, "CpuHotPlug", &fCpuHotPlug, false);
if (RT_FAILURE(rc))
@@ -408,24 +419,24 @@ int acpiPrepareSsdt(PPDMDEVINS pDevIns, void* *ppPtr, size_t *puSsdtLen)
if (fCpuHotPlug)
{
- pbAmlCode = AmlCodeSsdtCpuHotPlug;
+ pabAmlCode = AmlCodeSsdtCpuHotPlug;
cbAmlCodeSsdt = sizeof(AmlCodeSsdtCpuHotPlug);
}
else
{
- pbAmlCode = AmlCodeSsdtStandard;
+ pabAmlCode = AmlCodeSsdtStandard;
cbAmlCodeSsdt = sizeof(AmlCodeSsdtStandard);
}
- pbAmlCodeSsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeSsdt);
- if (pbAmlCodeSsdt)
+ pabAmlCodeSsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeSsdt);
+ if (pabAmlCodeSsdt)
{
- memcpy(pbAmlCodeSsdt, pbAmlCode, cbAmlCodeSsdt);
+ memcpy(pabAmlCodeSsdt, pabAmlCode, cbAmlCodeSsdt);
if (fCpuHotPlug)
- patchAmlCpuHotPlug(pDevIns, pbAmlCodeSsdt, cbAmlCodeSsdt);
+ patchAmlCpuHotPlug(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt);
else
- patchAml(pDevIns, pbAmlCodeSsdt, cbAmlCodeSsdt);
+ patchAml(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt);
}
else
rc = VERR_NO_MEMORY;
@@ -436,17 +447,18 @@ int acpiPrepareSsdt(PPDMDEVINS pDevIns, void* *ppPtr, size_t *puSsdtLen)
if (RT_SUCCESS(rc))
{
- *ppPtr = pbAmlCodeSsdt;
- *puSsdtLen = cbAmlCodeSsdt;
+ *ppvPtr = pabAmlCodeSsdt;
+ *pcbSsdt = cbAmlCodeSsdt;
}
return VINF_SUCCESS;
}
-int acpiCleanupSsdt(PPDMDEVINS pDevIns, void* pPtr)
+/** No docs, lazy coder. */
+int acpiCleanupSsdt(PPDMDEVINS pDevIns, void *pvPtr)
{
- if (pPtr)
- RTMemFree(pPtr);
+ if (pvPtr)
+ RTMemFree(pvPtr);
return VINF_SUCCESS;
}