aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2022-08-31 08:27:33 +0200
committerGerd Hoffmann <kraxel@redhat.com>2023-08-24 10:56:21 +0200
commit90eeb0c8558a1524836ec94aee11f4cc88b10c78 (patch)
tree6ee2035cd16180a196e6e719a31babcb6cae6bd5
parentbe84867613f791ea344d565d65a9ce85238e8533 (diff)
downloadseabios-90eeb0c8558a1524836ec94aee11f4cc88b10c78.zip
seabios-90eeb0c8558a1524836ec94aee11f4cc88b10c78.tar.gz
seabios-90eeb0c8558a1524836ec94aee11f4cc88b10c78.tar.bz2
detect physical address space size
Check for pae and long mode using cpuid. If present also read the physical address bits. Apply some qemu sanity checks (see below). Record results in PhysBits and LongMode variables. In case we are not sure what the address space size is leave the PhysBits variable unset. On qemu we have the problem that for historical reasons x86_64 processors advertise 40 physical address space bits by default, even in case the host supports less than that so actually using the whole address space will not work. Because of that the code applies some extra sanity checks in case we find 40 (or less) physical address space bits advertised. Only known-good values (which is 40 for amd processors and 36+39 for intel processors) will be accepted as valid. Recommendation is to use 'qemu -cpu ${name},host-phys-bits=on' to advertise valid physical address space bits to the guest. Some distro builds enable this by default, and most likely the qemu default will change in near future too. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r--src/fw/paravirt.c57
-rw-r--r--src/fw/paravirt.h2
2 files changed, 59 insertions, 0 deletions
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c
index 42abac8..3aee4c0 100644
--- a/src/fw/paravirt.c
+++ b/src/fw/paravirt.c
@@ -32,6 +32,10 @@
u32 RamSize;
// Amount of continuous ram >4Gig
u64 RamSizeOver4G;
+// physical address space bits
+u8 CPUPhysBits;
+// 64bit processor
+u8 CPULongMode;
// Type of emulator platform.
int PlatformRunningOn VARFSEG;
// cfg enabled
@@ -130,6 +134,58 @@ static void kvmclock_init(void)
tsctimer_setfreq(MHz * 1000, "kvmclock");
}
+static void physbits(int qemu_quirk)
+{
+ unsigned int max, eax, ebx, ecx, edx;
+ unsigned int physbits;
+ char signature[13];
+ int pae = 0, valid = 0;
+
+ cpuid(0, &eax, &ebx, &ecx, &edx);
+ memcpy(signature + 0, &ebx, 4);
+ memcpy(signature + 4, &edx, 4);
+ memcpy(signature + 8, &ecx, 4);
+ signature[12] = 0;
+ if (eax >= 1) {
+ cpuid(1, &eax, &ebx, &ecx, &edx);
+ pae = (edx & (1 << 6));
+ }
+
+ cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
+ max = eax;
+
+ if (max >= 0x80000001) {
+ cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+ CPULongMode = !!(edx & (1 << 29));
+ }
+
+ if (pae && CPULongMode && max >= 0x80000008) {
+ cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
+ physbits = (u8)eax;
+ if (!qemu_quirk) {
+ valid = 1;
+ } else if (physbits >= 41) {
+ valid = 1;
+ } else if (strcmp(signature, "GenuineIntel") == 0) {
+ if ((physbits == 36) || (physbits == 39))
+ valid = 1;
+ } else if (strcmp(signature, "AuthenticAMD") == 0) {
+ if (physbits == 40)
+ valid = 1;
+ }
+ } else {
+ physbits = pae ? 36 : 32;
+ valid = 1;
+ }
+
+ dprintf(1, "%s: signature=\"%s\", pae=%s, lm=%s, phys-bits=%d, valid=%s\n",
+ __func__, signature, pae ? "yes" : "no", CPULongMode ? "yes" : "no",
+ physbits, valid ? "yes" : "no");
+
+ if (valid)
+ CPUPhysBits = physbits;
+}
+
static void qemu_detect(void)
{
if (!CONFIG_QEMU_HARDWARE)
@@ -162,6 +218,7 @@ static void qemu_detect(void)
dprintf(1, "Running on QEMU (unknown nb: %04x:%04x)\n", v, d);
break;
}
+ physbits(1);
}
static int qemu_early_e820(void);
diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h
index 4e2e993..62a2cd0 100644
--- a/src/fw/paravirt.h
+++ b/src/fw/paravirt.h
@@ -31,6 +31,8 @@ typedef struct QemuCfgDmaAccess {
extern u32 RamSize;
extern u64 RamSizeOver4G;
extern int PlatformRunningOn;
+extern u8 CPUPhysBits;
+extern u8 CPULongMode;
static inline int runningOnQEMU(void) {
return CONFIG_QEMU || (