DevFwCommon.cpp revision 104ccde52a280c876fe4e367d6fa0f5b9515d9e8
/* $Id$ */
/** @file
* FwCommon - Shared firmware code (used by DevPcBios & DevEFI).
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV
#include <iprt/buildconfig.h>
#include "../Builtins.h"
#include "../Builtins2.h"
#include "DevFwCommon.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/*
* Default DMI data (legacy).
* Don't change this information otherwise Windows guests will demand re-activation!
*/
static const int32_t s_iDefDmiBIOSReleaseMajor = 0;
static const int32_t s_iDefDmiBIOSReleaseMinor = 0;
static const int32_t s_iDefDmiBIOSFirmwareMajor = 0;
static const int32_t s_iDefDmiBIOSFirmwareMinor = 0;
static const char *s_szDefDmiBIOSVendor = "innotek GmbH";
static const char *s_szDefDmiBIOSVersion = "VirtualBox";
static const char *s_szDefDmiBIOSReleaseDate = "12/01/2006";
static const char *s_szDefDmiSystemVendor = "innotek GmbH";
static const char *s_szDefDmiSystemProduct = "VirtualBox";
static const char *s_szDefDmiSystemVersion = "1.2";
static const char *s_szDefDmiSystemSerial = "0";
static const char *s_szDefDmiSystemFamily = "Virtual Machine";
static const char *s_szDefDmiChassisVendor = "Sun Microsystems, Inc.";
static const char *s_szDefDmiChassisVersion = "";
static const char *s_szDefDmiChassisSerial = "";
static const char *s_szDefDmiChassisAssetTag = "";
static char g_szHostDmiSystemProduct[64];
static char g_szHostDmiSystemVersion[64];
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
#pragma pack(1)
typedef struct SMBIOSHDR
{
} *SMBIOSHDRPTR;
typedef struct DMIMAINHDR
{
} *DMIMAINHDRPTR;
/** DMI header */
typedef struct DMIHDR
{
} *PDMIHDR;
/** DMI BIOS information (Type 0) */
typedef struct DMIBIOSINF
{
} *PDMIBIOSINF;
/** DMI system information (Type 1) */
typedef struct DMISYSTEMINF
{
} *PDMISYSTEMINF;
/** DMI system enclosure or chassis type (Type 3) */
typedef struct DMICHASSIS
{
/* v2.3+, currently not supported */
} *PDMICHASSIS;
/** DMI processor information (Type 4) */
typedef struct DMIPROCESSORINF
{
} *PDMIPROCESSORINF;
/** DMI OEM strings (Type 11) */
typedef struct DMIOEMSTRINGS
{
} *PDMIOEMSTRINGS;
/** MPS floating pointer structure */
typedef struct MPSFLOATPTR
{
} *PMPSFLOATPTR;
/** MPS config table header */
typedef struct MPSCFGTBLHEADER
{
} *PMPSCFGTBLHEADER;
/** MPS processor entry */
typedef struct MPSPROCENTRY
{
} *PMPSPROCENTRY;
/** MPS bus entry */
typedef struct MPSBUSENTRY
{
} *PMPSBUSENTRY;
typedef struct MPSIOAPICENTRY
{
} *PMPSIOAPICENTRY;
/** MPS I/O-Interrupt entry */
typedef struct MPSIOINTERRUPTENTRY
{
} *PMPSIOIRQENTRY;
#pragma pack()
/**
* Calculate a simple checksum for the MPS table.
*
* @param data data
* @param len size of data
*/
{
return -u8Sum;
}
{
return (u8Sum == 0);
}
/*
* Macmini2,1 - matches Mac Mini
*/
static void fwCommonUseHostDMIStrings(void)
{
int rc;
g_szHostDmiSystemProduct, sizeof(g_szHostDmiSystemProduct));
if (RT_SUCCESS(rc))
{
}
g_szHostDmiSystemVersion, sizeof(g_szHostDmiSystemVersion));
if (RT_SUCCESS(rc))
{
}
}
/**
* Construct the DMI table.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pTable Where to create the DMI table.
* @param cbMax The maximum size of the DMI table.
* @param pUuid Pointer to the UUID to use if the DmiUuid
* configuration string isn't present.
* @param pCfg The handle to our config node.
* @param fPutSmbiosHeaders Plant SMBIOS headers if true.
*/
{
{ \
size_t cbNeed = (size_t)(pszStr + cbWant - (char *)pTable) + 5; /* +1 for strtab terminator +4 for end-of-table entry */ \
{ \
if (fHideErrors) \
{ \
LogRel(("One of the DMI strings is too long -- using default DMI data!\n")); \
continue; \
} \
N_("One of the DMI strings is too long. Check all bios/Dmi* configuration entries. At least %zu bytes are needed but there is no space for more than %d bytes"), cbNeed, cbMax); \
} \
}
{ \
if (fForceDefault) \
pszTmp = default_value; \
else \
{ \
if (RT_FAILURE(rc)) \
{ \
if (fHideErrors) \
{ \
LogRel(("Configuration error: Querying \"" name "\" as a string failed -- using default DMI data!\n")); \
continue; \
} \
} \
pszTmp = ""; \
else \
} \
if (!pszTmp[0]) \
variable = 0; /* empty string */ \
else \
{ \
} \
}
{ \
if (fForceDefault) \
else \
{ \
if (RT_FAILURE(rc)) \
{ \
if (fHideErrors) \
{ \
LogRel(("Configuration error: Querying \"" # name "\" as an int failed -- using default DMI data!\n")); \
continue; \
} \
} \
} \
}
#define TERM_STRUCT \
{ \
if (iStrNr == 1) \
}
bool fForceDefault = false;
#ifdef VBOX_BIOS_DMI_FALLBACK
/*
* There will be two passes. If an error occurs during the first pass, a
* message will be written to the release log and we fall back to default
* DMI data and start a second pass.
*/
bool fHideErrors = true;
#else
/*
* There will be one pass, every error is fatal and will prevent the VM
* from starting.
*/
bool fHideErrors = false;
#endif
if (RT_FAILURE (rc))
N_("Configuration error: Failed to read \"DmiUseHostInfo\""));
/* Sync up with host default DMI values */
if (fDmiUseHostInfo)
for (;; fForceDefault = true, fHideErrors = false)
{
int iStrNr;
char szBuf[256];
char szDmiSystemUuid[64];
char *pszDmiSystemUuid;
const char *pszTmp;
if (fForceDefault)
else
{
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
else if (RT_FAILURE(rc))
{
if (fHideErrors)
{
LogRel(("Configuration error: Querying \"DmiSystemUuid\" as a string failed, using default DMI data\n"));
continue;
}
N_("Configuration error: Querying \"DmiSystemUuid\" as a string failed"));
}
else
}
/*********************************
* DMI BIOS information (Type 0) *
*********************************/
/* don't set these fields by default for legacy compatibility */
if (iDmiBIOSReleaseMajor != 0 || iDmiBIOSReleaseMinor != 0)
{
if (iDmiBIOSFirmwareMajor != 0 || iDmiBIOSFirmwareMinor != 0)
{
}
}
iStrNr = 1;
/* any more?? */
;
/* any more?? */
;
/* any more?? */
;
/***********************************
* DMI system information (Type 1) *
***********************************/
CHECKSIZE(sizeof(*pSystemInf));
iStrNr = 1;
if (pszDmiSystemUuid)
{
if (RT_FAILURE(rc))
{
if (fHideErrors)
{
LogRel(("Configuration error: Invalid UUID for DMI tables specified, using default DMI data\n"));
continue;
}
N_("Configuration error: Invalid UUID for DMI tables specified"));
}
}
pSystemInf->u8SKUNumber = 0;
/********************************************
* DMI System Enclosure or Chassis (Type 3) *
********************************************/
iStrNr = 1;
#ifdef VBOX_WITH_DMI_CHASSIS
#else
#endif
# if 0
/* v2.3+, currently not supported */
pChassis->u32OEMdefined = 0;
# endif
/*****************************
* DMI OEM strings (Type 11) *
*****************************/
CHECKSIZE(sizeof(*pOEMStrings));
iStrNr = 1;
#ifdef VBOX_WITH_DMI_OEMSTRINGS
#else
#endif
char szTmp[64];
/* End-of-table marker - includes padding to account for fixed table size. */
/* If more fields are added here, fix the size check in READCFGSTR */
/* Success! */
break;
}
if (fPutSmbiosHeaders)
{
struct {
struct DMIMAINHDR dmi;
=
{
// The SMBIOS header
{
{ 0x5f, 0x53, 0x4d, 0x5f}, // "_SM_" signature
0x00, // checksum
0x1f, // EPS length, defined by standard
VBOX_SMBIOS_MAJOR_VER, // SMBIOS major version
VBOX_SMBIOS_MINOR_VER, // SMBIOS minor version
VBOX_SMBIOS_MAXSS, // Maximum structure size
0x00, // Entry point revision
{ 0x00, 0x00, 0x00, 0x00, 0x00 } // padding
},
// The DMI header
{
{ 0x5f, 0x44, 0x4d, 0x49, 0x5f }, // "_DMI_" signature
0x00, // checksum
VBOX_DMI_TABLE_SIZE, // DMI tables length
VBOX_DMI_TABLE_BASE, // DMI tables base
VBOX_DMI_TABLE_ENTR, // DMI tables entries
VBOX_DMI_TABLE_VER, // DMI version
}
};
aBiosHeaders.smbios.u8Checksum = fwCommonChecksum((uint8_t*)&aBiosHeaders.smbios, sizeof(aBiosHeaders.smbios));
aBiosHeaders.dmi.u8Checksum = fwCommonChecksum((uint8_t*)&aBiosHeaders.dmi, sizeof(aBiosHeaders.dmi));
}
return VINF_SUCCESS;
}
/**
* Construct the MPS table. Only applicable if IOAPIC is active!
*
* See ``MultiProcessor Specificatiton Version 1.4 (May 1997)'':
* ``1.3 Scope
* ...
* The hardware required to implement the MP specification is kept to a
* minimum, as follows:
* * One or more processors that are Intel architecture instruction set
* compatible, such as the CPUs in the Intel486 or Pentium processor
* family.
* * One or more APICs, such as the Intel 82489DX Advanced Programmable
* Interrupt Controller or the integrated APIC, such as that on the
* Intel Pentium 735\\90 and 815\\100 processors, together with a discrete
* I/O APIC unit.''
* and later:
* ``4.3.3 I/O APIC Entries
* The configuration table contains one or more entries for I/O APICs.
* ...
* I/O APIC FLAGS: EN 3:0 1 If zero, this I/O APIC is unusable, and the
* operating system should not attempt to access
* this I/O APIC.
* At least one I/O APIC must be enabled.''
*
* @param pDevIns The device instance data.
* @param pTable Where to write the table.
* @param cbMax The maximum size of the MPS table.
* @param cCpus The number of guest CPUs.
*/
{
/* configuration table */
pCfgTab->u32OemTablePtr = 0;
pCfgTab->u16OemTableSize = 0;
+ 1 /* ISA Bus */
+ 1 /* PCI Bus */
+ 16 /* Interrupts */
+ 1 /* Local interrupts */;
pCfgTab->u16ExtTableLength = 0;
pCfgTab->u8ExtTableChecksum = 0;
pCfgTab->u8Reserved = 0;
if (u32Eax >= 1)
{
/* Local APIC will be enabled later so override it here. Since we provide
* an MP table we have an IOAPIC and therefore a Local APIC. */
}
/* Construct MPS table for each VCPU. */
for (int i = 0; i < cCpus; i++)
{
pProcEntry->u8CPUFlags = (i == 0 ? 2 /* bootstrap processor */ : 0 /* application processor */) | 1 /* enabled */;
pProcEntry->u32Reserved[0] =
pProcEntry++;
}
uint32_t iBusIdPci0 = 0;
/* ISA bus */
pBusEntry++;
/* PCI bus */
* MP spec: "The configuration table contains one or more entries for I/O APICs.
* ... At least one I/O APIC must be enabled." */
/* Interrupt tables */
/* Bus vectors */
{
/*
* 0 - INT, vectored interrupt,
* 3 - ExtINT, vectored interrupt provided by PIC
* As we emulate system with both APIC and PIC, it's needed for their coexistence.
*/
trigger mode = conforms to bus */
/* IRQ0 mapped to pin 2, other are identity mapped */
}
/* Local delivery */
pIrqEntry->u8SrcBusIrq = 0;
pIrqEntry->u8DstIOAPICInt = 0;
pIrqEntry++;
("VBOX_MPS_TABLE_SIZE=%d, maximum allowed size is %d",
floatPtr.u8Checksum = 0;
floatPtr.au8Feature[0] = 0;
}