VBoxAcpi.cpp revision 70118d62d01079551f31eaf0a3b2227290ddf3ee
/* $Id$ */
/** @file
* VBoxAcpi - VirtualBox ACPI manipulation functionality.
*/
/*
* 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;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#if !defined(IN_RING3)
#endif
#define LOG_GROUP LOG_GROUP_DEV_ACPI
#ifdef VBOX_WITH_DYNAMIC_DSDT
/* vbox.dsl - input to generate proper DSDT on the fly */
#else
/* Statically compiled AML */
#endif
#include "VBoxDD.h"
#ifdef VBOX_WITH_DYNAMIC_DSDT
{
*pcbDsdt = 0;
return 0;
}
{
return 0;
}
#else /* VBOX_WITH_DYNAMIC_DSDT */
{
int rc;
if (RT_FAILURE(rc))
return rc;
/* Clear CPU objects at all, if needed */
bool fShowCpu;
if (RT_FAILURE(rc))
return rc;
if (!fShowCpu)
cNumCpus = 0;
/**
* Now search AML for:
* AML_PROCESSOR_OP (UINT16) 0x5b83
* and replace whole block with
* AML_NOOP_OP (UINT16) 0xa3
* for VCPU not configured
*/
{
/*
* AML_PROCESSOR_OP
*
* DefProcessor := ProcessorOp PkgLength NameString ProcID
PblkAddr PblkLen ObjectList
* ProcessorOp := ExtOpPrefix 0x83
* ProcID := ByteData
* PblkAddr := DwordData
* PblkLen := ByteData
*/
{
/* false alarm, not named starting CP */
continue;
/* Processor ID */
continue;
/* Will fill unwanted CPU block with NOOPs */
/*
* See 18.2.4 Package Length Encoding in ACPI spec
* for full format
*/
("So far, we only understand simple package length"));
/* including AML_PROCESSOR_OP itself */
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 */
pabAml[9] = 0;
return 0;
}
/**
* Patch the CPU hot-plug SSDT version to
* only contain the ACPI containers which may have a CPU
*/
{
int rc;
if (RT_FAILURE(rc))
return rc;
/**
* Now search AML for:
* AML_DEVICE_OP (UINT16) 0x5b82
* and replace whole block with
* AML_NOOP_OP (UINT16) 0xa3
* for VCPU not configured
*/
{
/*
* AML_DEVICE_OP
*
* DefDevice := DeviceOp PkgLength NameString ObjectList
* DeviceOp := ExtOpPrefix 0x82
*/
{
/* Check if the enclosed CPU device is configured. */
if (cLengthBytesFollow == 0)
{
/* Simple package length */
cBytes = pabAmlPkgLength[0];
}
else
{
unsigned idxLengthByte = 1;
while (idxLengthByte <= cLengthBytesFollow)
{
}
}
bool fCpuConfigured = false;
bool fCpuFound = false;
{
/* false alarm, not named starting SCK */
idxAml++;
continue;
}
{
/*
* AML_PROCESSOR_OP
*
* DefProcessor := ProcessorOp PkgLength NameString ProcID
PblkAddr PblkLen ObjectList
* ProcessorOp := ExtOpPrefix 0x83
* ProcID := ByteData
* PblkAddr := DwordData
* PblkLen := ByteData
*/
{
/* false alarm, not named starting CP */
continue;
fCpuFound = true;
/* Processor ID */
{
fCpuConfigured = true;
break;
}
else
{
fCpuConfigured = false;
break;
}
}
}
if (!fCpuConfigured)
{
/* Will fill unwanted CPU block with NOOPs */
/*
* See 18.2.4 Package Length Encoding in ACPI spec
* for full format
*/
/* including AML_DEVICE_OP itself */
}
idxAml++;
}
else
idxAml++;
}
/* now recompute checksum, whole file byte sum must be 0 */
pabAml[9] = 0;
return 0;
}
#endif /* VBOX_WITH_DYNAMIC_DSDT */
/**
* Loads an AML file if present in CFGM
*
* @returns VBox status code
* @param pDevIns The device instance
* @param pcszCfgName The configuration key holding the file path
* @param pcszSignature The signature to check for
* @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 **ppabAmlCode, size_t *pcbAmlCode)
{
char *pszAmlFilePath = NULL;
if (RT_SUCCESS(rc))
{
/* Load from file. */
if (RT_SUCCESS(rc))
{
/*
* An AML file contains the raw DSDT thus the size of the file
* is equal to the size of the DSDT.
*/
/* Don't use AML files over 4GB ;) */
if ( RT_SUCCESS(rc)
{
if (pabAmlCode)
{
/*
* We fail if reading failed or the identifier at the
* beginning is wrong.
*/
if ( RT_FAILURE(rc)
{
pabAmlCode = NULL;
/* Return error if file header check failed */
if (RT_SUCCESS(rc))
}
else
{
*pcbAmlCode = cbAmlCode;
rc = VINF_SUCCESS;
}
}
else
rc = VERR_NO_MEMORY;
}
}
}
return rc;
}
/** No docs, lazy coder. */
{
#ifdef VBOX_WITH_DYNAMIC_DSDT
#else
size_t cbAmlCodeDsdt = 0;
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
{
rc = VINF_SUCCESS;
/* Use the compiled in AML code */
cbAmlCodeDsdt = sizeof(AmlCode);
if (pabAmlCodeDsdt)
else
rc = VERR_NO_MEMORY;
}
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to read \"DsdtFilePath\""));
if (RT_SUCCESS(rc))
{
*ppvPtr = pabAmlCodeDsdt;
*pcbDsdt = cbAmlCodeDsdt;
}
return rc;
#endif
}
/** No docs, lazy coder. */
{
#ifdef VBOX_WITH_DYNAMIC_DSDT
#else
if (pvPtr)
return VINF_SUCCESS;
#endif
}
/** No docs, lazy coder. */
{
size_t cbAmlCodeSsdt = 0;
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
{
bool fCpuHotPlug = false;
if (RT_FAILURE(rc))
return rc;
if (fCpuHotPlug)
{
cbAmlCodeSsdt = sizeof(AmlCodeSsdtCpuHotPlug);
}
else
{
cbAmlCodeSsdt = sizeof(AmlCodeSsdtStandard);
}
if (pabAmlCodeSsdt)
{
if (fCpuHotPlug)
else
}
else
rc = VERR_NO_MEMORY;
}
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to read \"SsdtFilePath\""));
if (RT_SUCCESS(rc))
{
*ppvPtr = pabAmlCodeSsdt;
*pcbSsdt = cbAmlCodeSsdt;
}
return VINF_SUCCESS;
}
/** No docs, lazy coder. */
{
if (pvPtr)
return VINF_SUCCESS;
}