-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy path1201-patch-gvt-hvmloader.patch.patch
140 lines (131 loc) · 5.17 KB
/
1201-patch-gvt-hvmloader.patch.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
From 8cb3e7fdb79dd869edbe7f294e91e781808241d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Wed, 16 Nov 2022 02:38:06 +0100
Subject: [PATCH] patch-gvt-hvmloader.patch
This patches based on Intel XenGT preview, XCP-NG Project.
---
tools/firmware/hvmloader/config.h | 2 +-
tools/firmware/hvmloader/pci.c | 35 ++++++++++++++++++++++++++++++
tools/firmware/hvmloader/rombios.c | 1 +
tools/firmware/hvmloader/vgt.h | 24 ++++++++++++++++++++
4 files changed, 61 insertions(+), 1 deletion(-)
create mode 100644 tools/firmware/hvmloader/vgt.h
diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index cd716bf39245..c9184366641b 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -4,7 +4,7 @@
#include <stdint.h>
#include <stdbool.h>
-enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
+enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt, VGA_vgt };
extern enum virtual_vga virtual_vga;
extern unsigned long igd_opregion_pgbase;
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index c3c61ca060a6..fe5ad75e9eb4 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -23,6 +23,7 @@
#include "hypercall.h"
#include "config.h"
#include "pci_regs.h"
+#include "vgt.h"
#include <xen/memory.h>
#include <xen/hvm/ioreq.h>
@@ -91,6 +92,7 @@ void pci_setup(void)
uint16_t class, vendor_id, device_id;
unsigned int bar, pin, link, isa_irq;
uint8_t pci_devfn_decode_type[256] = {};
+ uint8_t intel_gpu_present = 0;
/* Resources assignable to PCI devices via BARs. */
struct resource {
@@ -170,6 +172,9 @@ void pci_setup(void)
ASSERT((devfn != PCI_ISA_DEVFN) ||
((vendor_id == 0x8086) && (device_id == 0x7000)));
+ if (( vendor_id == 0x8086 ) && (class == 0x0300 || class == 0x0380))
+ intel_gpu_present = 1;
+
switch ( class )
{
case 0x0300:
@@ -548,6 +553,36 @@ void pci_setup(void)
if ( vga_devfn != 256 )
{
+ if ( intel_gpu_present )
+ {
+ uint32_t bar = pci_readl(vga_devfn, PCI_BASE_ADDRESS_0)
+ & PCI_BASE_ADDRESS_MEM_MASK;
+
+ void *pvinfo = (void *)bar + VGT_PVINFO_PAGE;
+ uint64_t *magic = pvinfo;
+
+ if (*magic == VGT_MAGIC) {
+ uint32_t vga_bar = pci_readl(vga_devfn, PCI_BASE_ADDRESS_5)
+ & PCI_BASE_ADDRESS_MEM_MASK;
+ /*
+ * Found VGT device, and use standard VGA bios.
+ */
+ virtual_vga = VGA_vgt;
+
+ /* XXX: we use this hack to tell vGT driver the
+ * top of <4G mem, so vGT can avoid unnecessary
+ * attempts to map the mem hole. This optimization
+ * can speed up guest bootup time and improve Win7
+ * SMP guest's stability.
+ * NOTE: here we're actually trying to write 32 bits
+ * into VENDOR_ID and DEVICE_ID -- we assume normally
+ * sane codes in guest won't do this...
+ */
+ pci_writel(vga_devfn, PCI_VENDOR_ID, hvm_info->low_mem_pgend);
+ /* XXX: Let QEMU legacy VGA emulator know the vga bar address*/
+ pci_writel(0, 0xf8, vga_bar);
+ }
+ }
/*
* VGA registers live in I/O space so ensure that primary VGA
* has IO enabled, even if there is no I/O BAR on that
diff --git a/tools/firmware/hvmloader/rombios.c b/tools/firmware/hvmloader/rombios.c
index 46f331e46596..ba33c0a5caea 100644
--- a/tools/firmware/hvmloader/rombios.c
+++ b/tools/firmware/hvmloader/rombios.c
@@ -78,6 +78,7 @@ static void rombios_load_roms(void)
vgabios_cirrusvga, sizeof(vgabios_cirrusvga));
vgabios_sz = round_option_rom(sizeof(vgabios_cirrusvga));
break;
+ case VGA_vgt:
case VGA_std:
printf("Loading Standard VGABIOS ...\n");
memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
diff --git a/tools/firmware/hvmloader/vgt.h b/tools/firmware/hvmloader/vgt.h
new file mode 100644
index 000000000000..f5b3f3475392
--- /dev/null
+++ b/tools/firmware/hvmloader/vgt.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2012-2013, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _VGT_DEVTABLE_H
+#define _VGT_DEVTABLE_H
+
+#define VGT_PVINFO_PAGE 0x78000
+#define VGT_MAGIC 0x4776544776544776 /* 'vGTvGTvG' */
+
+#endif /* _VGT_DEVTABLE_H */
--
2.44.0