ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * VBoxAcpi - VirtualBox ACPI manipulation functionality.
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync * Copyright (C) 2009-2013 Oracle Corporation
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * available from http://www.virtualbox.org. This file is free software;
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * General Public License (GPL) as published by the Free Software
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync/*******************************************************************************
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync* Header Files *
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync*******************************************************************************/
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync#if !defined(IN_RING3)
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync/* vbox.dsl - input to generate proper DSDT on the fly */
7f8a04081173dbe3c72bddd0ffeb237e7f9070b0vboxsync/* Statically compiled AML */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncstatic int prepareDynamicDsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbDsdt)
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncstatic int cleanupDynamicDsdt(PPDMDEVINS pDevIns, void *pvPtr)
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync#else /* VBOX_WITH_DYNAMIC_DSDT */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncstatic int patchAml(PPDMDEVINS pDevIns, uint8_t *pabAml, size_t cbAml)
928e1d6581a40f26932a8b35526773805bc69e47vboxsync rc = CFGMR3QueryU16Def(pDevIns->pCfg, "NumCPUs", &cNumCpus, 1);
a2779f5bd9cc55216a2911d7714ede6a77cac3b2vboxsync /* Clear CPU objects at all, if needed */
928e1d6581a40f26932a8b35526773805bc69e47vboxsync rc = CFGMR3QueryBoolDef(pDevIns->pCfg, "ShowCpu", &fShowCpu, false);
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * Now search AML for:
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * AML_PROCESSOR_OP (UINT16) 0x5b83
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * and replace whole block with
616c4e73368513b3c835881ff9f2386083afad01vboxsync * AML_NOOP_OP (UINT16) 0xa3
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * for VCPU not configured
616c4e73368513b3c835881ff9f2386083afad01vboxsync * AML_PROCESSOR_OP
616c4e73368513b3c835881ff9f2386083afad01vboxsync * DefProcessor := ProcessorOp PkgLength NameString ProcID
ecb074924ed761fe89e91113482db5b7374441b0vboxsync PblkAddr PblkLen ObjectList
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * ProcessorOp := ExtOpPrefix 0x83
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * ProcID := ByteData
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * PblkAddr := DwordData
ecb074924ed761fe89e91113482db5b7374441b0vboxsync * PblkLen := ByteData
ecb074924ed761fe89e91113482db5b7374441b0vboxsync /* false alarm, not named starting CP */
3854599844436d009da0f32760d657fc7690a5a8vboxsync /* Processor ID */
ecb074924ed761fe89e91113482db5b7374441b0vboxsync /* Will fill unwanted CPU block with NOOPs */
616c4e73368513b3c835881ff9f2386083afad01vboxsync * See 18.2.4 Package Length Encoding in ACPI spec
616c4e73368513b3c835881ff9f2386083afad01vboxsync * for full format
ecb074924ed761fe89e91113482db5b7374441b0vboxsync ("So far, we only understand simple package length"));
ecb074924ed761fe89e91113482db5b7374441b0vboxsync /* including AML_PROCESSOR_OP itself */
ecb074924ed761fe89e91113482db5b7374441b0vboxsync /* Can increase i by cBytes + 1, but not really worth it */
ecb074924ed761fe89e91113482db5b7374441b0vboxsync /* now recompute checksum, whole file byte sum must be 0 */
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * Patch the CPU hot-plug SSDT version to
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * only contain the ACPI containers which may have a CPU
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncstatic int patchAmlCpuHotPlug(PPDMDEVINS pDevIns, uint8_t *pabAml, size_t cbAml)
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync rc = CFGMR3QueryU16Def(pDevIns->pCfg, "NumCPUs", &cNumCpus, 1);
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * Now search AML for:
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * AML_DEVICE_OP (UINT16) 0x5b82
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * and replace whole block with
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * AML_NOOP_OP (UINT16) 0xa3
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * for VCPU not configured
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * AML_DEVICE_OP
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * DefDevice := DeviceOp PkgLength NameString ObjectList
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * DeviceOp := ExtOpPrefix 0x82
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync if (pabAml[idxAml] == 0x5b && pabAml[idxAml+1] == 0x82)
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* Check if the enclosed CPU device is configured. */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync uint32_t cLengthBytesFollow = pabAmlPkgLength[0] >> 6;
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* Simple package length */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync cBytes |= pabAmlPkgLength[idxLengthByte] << (4*idxLengthByte);
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync uint8_t *pabAmlDevName = &pabAmlPkgLength[cLengthBytesFollow+1];
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync if ((pabAmlDevName[0] != 'S') || (pabAmlDevName[1] != 'C') || (pabAmlDevName[2] != 'K'))
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* false alarm, not named starting SCK */
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync for (uint32_t idxAmlCpu = 0; idxAmlCpu < cBytes - 7; idxAmlCpu++)
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * AML_PROCESSOR_OP
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * DefProcessor := ProcessorOp PkgLength NameString ProcID
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync PblkAddr PblkLen ObjectList
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * ProcessorOp := ExtOpPrefix 0x83
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * ProcID := ByteData
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * PblkAddr := DwordData
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * PblkLen := ByteData
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync if ((pabAmlCpu[idxAmlCpu] == 0x5b) && (pabAmlCpu[idxAmlCpu+1] == 0x83))
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync if ((pabAmlCpu[idxAmlCpu+4] != 'C') || (pabAmlCpu[idxAmlCpu+5] != 'P'))
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* false alarm, not named starting CP */
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* Processor ID */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync LogFlow(("CPU %d is configured\n", pabAmlCpu[idxAmlCpu+8]));
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync LogFlow(("CPU %d is not configured\n", pabAmlCpu[idxAmlCpu+8]));
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* Will fill unwanted CPU block with NOOPs */
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * See 18.2.4 Package Length Encoding in ACPI spec
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync * for full format
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* including AML_DEVICE_OP itself */
dc5705c90aebb694bb66eea8f3ee7415afcf3828vboxsync /* now recompute checksum, whole file byte sum must be 0 */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync#endif /* VBOX_WITH_DYNAMIC_DSDT */
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync * Loads an AML file if present in CFGM
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync * @returns VBox status code
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync * @param pDevIns The device instance
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync * @param pcszCfgName The configuration key holding the file path
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync * @param pcszSignature The signature to check for
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync * @param ppabAmlCode Where to store the pointer to the AML code on success.
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync * @param pcbAmlCode Where to store the number of bytes of the AML code on success.
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncstatic int acpiAmlLoadExternal(PPDMDEVINS pDevIns, const char *pcszCfgName, const char *pcszSignature, uint8_t **ppabAmlCode, size_t *pcbAmlCode)
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync int rc = CFGMR3QueryStringAlloc(pDevIns->pCfg, pcszCfgName, &pszAmlFilePath);
70e70d246c1b592db31d93071c48bb43ea61100evboxsync /* Load from file. */
70e70d246c1b592db31d93071c48bb43ea61100evboxsync rc = RTFileOpen(&FileAml, pszAmlFilePath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
70e70d246c1b592db31d93071c48bb43ea61100evboxsync * An AML file contains the raw DSDT thus the size of the file
70e70d246c1b592db31d93071c48bb43ea61100evboxsync * is equal to the size of the DSDT.
70e70d246c1b592db31d93071c48bb43ea61100evboxsync /* Don't use AML files over 4GB ;) */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync rc = RTFileReadAt(FileAml, 0, pabAmlCode, cbAmlCode, NULL);
70e70d246c1b592db31d93071c48bb43ea61100evboxsync * We fail if reading failed or the identifier at the
70e70d246c1b592db31d93071c48bb43ea61100evboxsync * beginning is wrong.
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync || strncmp((const char *)pabAmlCode, pcszSignature, 4))
70e70d246c1b592db31d93071c48bb43ea61100evboxsync /* Return error if file header check failed */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync/** No docs, lazy coder. */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncint acpiPrepareDsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbDsdt)
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync return prepareDynamicDsdt(pDevIns, ppvPtr, pcbDsdt);
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync int rc = acpiAmlLoadExternal(pDevIns, "DsdtFilePath", "DSDT", &pabAmlCodeDsdt, &cbAmlCodeDsdt);
70e70d246c1b592db31d93071c48bb43ea61100evboxsync /* Use the compiled in AML code */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync pabAmlCodeDsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeDsdt);
ec7708c74d7fc8feb18fbe1f84b320ec86fb11efvboxsync N_("Configuration error: Failed to read \"DsdtFilePath\""));
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync/** No docs, lazy coder. */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncint acpiCleanupDsdt(PPDMDEVINS pDevIns, void *pvPtr)
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync/** No docs, lazy coder. */
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsyncint acpiPrepareSsdt(PPDMDEVINS pDevIns, void **ppvPtr, size_t *pcbSsdt)
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync int rc = acpiAmlLoadExternal(pDevIns, "SsdtFilePath", "SSDT", &pabAmlCodeSsdt, &cbAmlCodeSsdt);
497a49aa22807122b7dd0bcab3bcdc43d3c479c2vboxsync rc = CFGMR3QueryBoolDef(pDevIns->pCfg, "CpuHotPlug", &fCpuHotPlug, false);
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync pabAmlCodeSsdt = (uint8_t *)RTMemAllocZ(cbAmlCodeSsdt);
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync patchAmlCpuHotPlug(pDevIns, pabAmlCodeSsdt, cbAmlCodeSsdt);
ec7708c74d7fc8feb18fbe1f84b320ec86fb11efvboxsync N_("Configuration error: Failed to read \"SsdtFilePath\""));
70118d62d01079551f31eaf0a3b2227290ddf3eevboxsync/** No docs, lazy coder. */