[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)



This adds a new function init_pc_machine_type() which allows to
determine and set the emulated chipset type. Possible values are
MACHINE_TYPE_I440 and MACHINE_TYPE_Q35 and stored in the global variable
machine_type.

The machine_type variable will be used from multiple places in following
commits.

Signed-off-by: Alexey Gerasimenko <x1917x@xxxxxxxxx>
Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxx>
---
 tools/firmware/hvmloader/hvmloader.c |  2 ++
 tools/firmware/hvmloader/pci_regs.h  |  4 +++
 tools/firmware/hvmloader/util.c      | 42 ++++++++++++++++++++++++++++
 tools/firmware/hvmloader/util.h      | 11 ++++++++
 4 files changed, 59 insertions(+)

diff --git a/tools/firmware/hvmloader/hvmloader.c 
b/tools/firmware/hvmloader/hvmloader.c
index 6d23150fc9..626cc53649 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -332,6 +332,8 @@ int main(void)
 
     init_hypercalls();
 
+    init_pc_machine_type();
+
     memory_map_setup();
 
     xenbus_setup();
diff --git a/tools/firmware/hvmloader/pci_regs.h 
b/tools/firmware/hvmloader/pci_regs.h
index 7bf2d873ab..4d4dc0cd01 100644
--- a/tools/firmware/hvmloader/pci_regs.h
+++ b/tools/firmware/hvmloader/pci_regs.h
@@ -107,6 +107,10 @@
 
 #define PCI_INTEL_OPREGION 0xfc /* 4 bits */
 
+#define PCI_VENDOR_ID_INTEL              0x8086
+#define PCI_DEVICE_ID_INTEL_82441        0x1237
+#define PCI_DEVICE_ID_INTEL_Q35_MCH      0x29c0
+
 #endif /* __HVMLOADER_PCI_REGS_H__ */
 
 /*
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index f1ed1eb48d..f9116bea4d 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -22,6 +22,7 @@
 #include "hypercall.h"
 #include "ctype.h"
 #include "vnuma.h"
+#include "pci_regs.h"
 #include <acpi2_0.h>
 #include <libacpi.h>
 #include <stdint.h>
@@ -648,6 +649,47 @@ void __bug(const char *file, int line)
     crash();
 }
 
+machine_type_t machine_type;
+
+void init_pc_machine_type(void)
+{
+    uint16_t vendor_id;
+    uint16_t device_id;
+
+    if ( machine_type != MACHINE_TYPE_UNDEFINED )
+        return;
+
+    vendor_id = pci_readw(0, PCI_VENDOR_ID);
+    device_id = pci_readw(0, PCI_DEVICE_ID);
+
+    /* only Intel platforms are emulated currently */
+    if ( vendor_id != PCI_VENDOR_ID_INTEL )
+        goto error;
+
+    switch ( device_id )
+    {
+    case PCI_DEVICE_ID_INTEL_82441:
+        machine_type = MACHINE_TYPE_I440;
+        printf("Detected i440 chipset\n");
+        break;
+
+    case PCI_DEVICE_ID_INTEL_Q35_MCH:
+        machine_type = MACHINE_TYPE_Q35;
+        printf("Detected Q35 chipset\n");
+        break;
+
+    default:
+        goto error;
+    }
+
+    return;
+
+error:
+    printf("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n",
+           vendor_id, device_id);
+    BUG();
+}
+
 static void validate_hvm_info(struct hvm_info_table *t)
 {
     uint8_t *ptr = (uint8_t *)t;
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 3c5eeff5e7..2f37504aca 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -170,6 +170,17 @@ void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, 
uint32_t val);
 #define pci_writew(devfn, reg, val) pci_write(devfn, reg, 2, (uint16_t)(val))
 #define pci_writel(devfn, reg, val) pci_write(devfn, reg, 4, (uint32_t)(val))
 
+/* Emulated machine types */
+typedef enum {
+    MACHINE_TYPE_UNDEFINED = 0,
+    MACHINE_TYPE_I440,
+    MACHINE_TYPE_Q35,
+} machine_type_t;
+
+extern machine_type_t machine_type;
+
+void init_pc_machine_type(void);
+
 /* Get a pointer to the shared-info page */
 struct shared_info *get_shared_info(void) __attribute__ ((const));
 
-- 
2.51.0



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.