forked from kjliew/qemu-3dfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-qemu411-mesa-glide.patch
389 lines (374 loc) · 11.8 KB
/
01-qemu411-mesa-glide.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
diff -Nru ../orig/qemu-4.1.1/accel/kvm/kvm-all.c ./accel/kvm/kvm-all.c
--- ../orig/qemu-4.1.1/accel/kvm/kvm-all.c 2019-11-14 10:06:20.000000000 -0800
+++ ./accel/kvm/kvm-all.c 2020-11-05 17:16:00.218512000 -0800
@@ -1023,6 +1023,41 @@
kvm_slots_unlock(kml);
}
+void kvm_update_guest_pa_range(hwaddr start_pa, ram_addr_t size, void *host_va, int readonly, int add)
+{
+ KVMState *s = kvm_state;
+ KVMMemoryListener *kml = &s->memory_listener;
+
+ MemoryRegion mr;
+ MemoryRegionSection section;
+ RAMBlock ram_block;
+
+ memset(&ram_block, 0, sizeof(RAMBlock));
+ ram_block.mr = &mr;
+ ram_block.used_length = HOST_PAGE_ALIGN(size);
+ ram_block.max_length = HOST_PAGE_ALIGN(size);
+ ram_block.fd = -1;
+ ram_block.page_size = getpagesize();
+ ram_block.host = host_va;
+ ram_block.flags |= RAM_PREALLOC;
+
+ memory_region_init(&mr, NULL, NULL, HOST_PAGE_ALIGN(size));
+ mr.ram = true;
+ mr.ram_block = &ram_block;
+ mr.readonly = readonly;
+ mr.nonvolatile = false;
+
+ section.mr = &mr;
+ section.fv = 0;
+ section.offset_within_region = 0;
+ section.size = mr.size;
+ section.offset_within_address_space = start_pa;
+ section.readonly = mr.readonly;
+ section.nonvolatile = mr.nonvolatile;
+
+ kvm_set_phys_mem(kml, §ion, add);
+}
+
static void kvm_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
diff -Nru ../orig/qemu-4.1.1/configure ./configure
--- ../orig/qemu-4.1.1/configure 2019-11-14 10:06:20.000000000 -0800
+++ ./configure 2020-11-03 16:16:30.609783400 -0800
@@ -903,6 +903,8 @@
linux_user="yes"
kvm="yes"
QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
+# For MESA/Glide pass-through ##
+ LIBS="-ldl -lXxf86vm -lGLX $LIBS"
supported_os="yes"
libudev="yes"
;;
diff -Nru ../orig/qemu-4.1.1/hw/Makefile.objs ./hw/Makefile.objs
--- ../orig/qemu-4.1.1/hw/Makefile.objs 2019-11-14 10:06:20.000000000 -0800
+++ ./hw/Makefile.objs 2020-11-03 16:19:37.973105600 -0800
@@ -9,6 +9,7 @@
devices-dirs-y += char/
devices-dirs-y += cpu/
devices-dirs-y += display/
+devices-dirs-y += 3dfx/
devices-dirs-y += dma/
devices-dirs-y += gpio/
devices-dirs-$(CONFIG_HYPERV) += hyperv/
@@ -19,6 +20,7 @@
devices-dirs-$(CONFIG_IPACK) += ipack/
devices-dirs-$(CONFIG_IPMI) += ipmi/
devices-dirs-y += isa/
+devices-dirs-y += mesa/
devices-dirs-y += misc/
devices-dirs-y += net/
devices-dirs-y += rdma/
diff -Nru ../orig/qemu-4.1.1/hw/i386/pc.c ./hw/i386/pc.c
--- ../orig/qemu-4.1.1/hw/i386/pc.c 2019-11-14 10:06:20.000000000 -0800
+++ ./hw/i386/pc.c 2020-11-03 16:16:30.634829900 -0800
@@ -2113,6 +2113,28 @@
/* Super I/O */
pc_superio_init(isa_bus, create_fdctrl, no_vmport);
+ /* Glide pass-through */
+ glidept_mm_init();
+ /* MESA pass-through */
+ mesapt_mm_init();
+}
+
+void glidept_mm_init(void)
+{
+ DeviceState *glidept_dev = NULL;
+
+ glidept_dev = qdev_new(TYPE_GLIDEPT);
+ sysbus_realize(SYS_BUS_DEVICE(glidept_dev), &error_fatal);
+ sysbus_mmio_map(SYS_BUS_DEVICE(glidept_dev), 0, GLIDEPT_MM_BASE);
+}
+
+void mesapt_mm_init(void)
+{
+ DeviceState *mesapt_dev = NULL;
+
+ mesapt_dev = qdev_new(TYPE_MESAPT);
+ sysbus_realize(SYS_BUS_DEVICE(mesapt_dev), &error_fatal);
+ sysbus_mmio_map(SYS_BUS_DEVICE(mesapt_dev), 0, MESAPT_MM_BASE);
}
void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
diff -Nru ../orig/qemu-4.1.1/include/hw/i386/pc.h ./include/hw/i386/pc.h
--- ../orig/qemu-4.1.1/include/hw/i386/pc.h 2019-11-14 10:06:20.000000000 -0800
+++ ./include/hw/i386/pc.h 2020-11-03 16:16:30.648773200 -0800
@@ -173,6 +173,22 @@
void gsi_handler(void *opaque, int n, int level);
+#if (((QEMU_VERSION_MAJOR << 8) | \
+ (QEMU_VERSION_MINOR << 4) | \
+ QEMU_VERSION_MICRO) < 0x510)
+#define qdev_new(x) qdev_create(NULL,x)
+#define sysbus_realize(x,y) qdev_init_nofail((DeviceState *)x)
+#endif
+/* GLIDE pass-through */
+#define TYPE_GLIDEPT "glidept"
+#define GLIDEPT_MM_BASE 0xfbdff000
+void glidept_mm_init(void);
+
+/* MESA pass-through */
+#define TYPE_MESAPT "mesapt"
+#define MESAPT_MM_BASE 0xefffe000
+void mesapt_mm_init(void);
+
/* vmport.c */
#define TYPE_VMPORT "vmport"
typedef uint32_t (VMPortReadFunc)(void *opaque, uint32_t address);
diff -Nru ../orig/qemu-4.1.1/include/sysemu/kvm.h ./include/sysemu/kvm.h
--- ../orig/qemu-4.1.1/include/sysemu/kvm.h 2019-11-14 10:06:20.000000000 -0800
+++ ./include/sysemu/kvm.h 2020-11-03 16:16:30.660790700 -0800
@@ -469,6 +469,7 @@
void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
#if !defined(CONFIG_USER_ONLY)
+void kvm_update_guest_pa_range(hwaddr, ram_addr_t, void *, int, int);
int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
hwaddr *phys_addr);
#endif
diff -Nru ../orig/qemu-4.1.1/include/sysemu/whpx.h ./include/sysemu/whpx.h
--- ../orig/qemu-4.1.1/include/sysemu/whpx.h 2019-11-14 10:06:20.000000000 -0800
+++ ./include/sysemu/whpx.h 2020-11-03 16:16:30.670773700 -0800
@@ -27,6 +27,7 @@
#ifdef CONFIG_WHPX
+void whpx_update_guest_pa_range(hwaddr, ram_addr_t, void *, int, int);
int whpx_enabled(void);
#else /* CONFIG_WHPX */
diff -Nru ../orig/qemu-4.1.1/include/ui/console.h ./include/ui/console.h
--- ../orig/qemu-4.1.1/include/ui/console.h 2019-11-14 10:06:20.000000000 -0800
+++ ./include/ui/console.h 2020-11-03 16:16:30.675787800 -0800
@@ -453,4 +453,21 @@
/* input.c */
int index_from_key(const char *key, size_t key_length);
+/* glidewnd.c */
+uintptr_t glide_prepare_window(int w, int h);
+void glide_release_window(void);
+uint32_t glide_window_stat(int);
+int glide_gui_getheight(void);
+int glide_gui_fullscreen(void);
+int is_glide_enabled(void);
+void glide_enabled_set(void);
+void glide_enabled_reset(void);
+
+/* mglcntx.c */
+uintptr_t mesa_prepare_window(void);
+void mesa_release_window(void);
+int is_mesa_enabled(void);
+void mesa_enabled_set(void);
+void mesa_enabled_reset(void);
+
#endif
diff -Nru ../orig/qemu-4.1.1/target/i386/whpx-all.c ./target/i386/whpx-all.c
--- ../orig/qemu-4.1.1/target/i386/whpx-all.c 2019-11-14 10:06:21.000000000 -0800
+++ ./target/i386/whpx-all.c 2020-11-05 17:16:40.789120600 -0800
@@ -10,6 +10,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
+#include "exec/ram_addr.h"
#include "exec/address-spaces.h"
#include "exec/ioport.h"
#include "qemu-common.h"
@@ -1299,6 +1300,38 @@
memory_region_is_rom(mr), mr->name);
}
+void whpx_update_guest_pa_range(hwaddr start_pa, ram_addr_t size, void *host_va, int readonly, int add)
+{
+ MemoryRegion mr;
+ MemoryRegionSection section;
+ RAMBlock ram_block;
+
+ memset(&ram_block, 0, sizeof(RAMBlock));
+ ram_block.mr = &mr;
+ ram_block.used_length = HOST_PAGE_ALIGN(size);
+ ram_block.max_length = HOST_PAGE_ALIGN(size);
+ ram_block.fd = -1;
+ ram_block.page_size = getpagesize();
+ ram_block.host = host_va;
+ ram_block.flags |= RAM_PREALLOC;
+
+ memory_region_init(&mr, NULL, NULL, HOST_PAGE_ALIGN(size));
+ mr.ram = true;
+ mr.ram_block = &ram_block;
+ mr.readonly = readonly;
+ mr.nonvolatile = false;
+
+ section.mr = &mr;
+ section.fv = 0;
+ section.offset_within_region = 0;
+ section.size = mr.size;
+ section.offset_within_address_space = start_pa;
+ section.readonly = mr.readonly;
+ section.nonvolatile = mr.nonvolatile;
+
+ whpx_process_section(§ion, add);
+}
+
static void whpx_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
diff -Nru ../orig/qemu-4.1.1/ui/console.c ./ui/console.c
--- ../orig/qemu-4.1.1/ui/console.c 2019-11-14 10:06:21.000000000 -0800
+++ ./ui/console.c 2020-11-05 02:55:38.320133200 -0800
@@ -259,11 +259,25 @@
ds->have_text = have_text;
}
+static int glide_enabled = 0;
+int is_glide_enabled(void) { return glide_enabled; }
+void glide_enabled_set(void) { glide_enabled = 1; }
+void glide_enabled_reset(void) { glide_enabled = 0; }
+
+static int mesa_enabled = 0;
+int is_mesa_enabled(void) { return mesa_enabled; }
+void mesa_enabled_set(void) { mesa_enabled = 1; }
+void mesa_enabled_reset(void) { mesa_enabled = 0; }
+
void graphic_hw_update(QemuConsole *con)
{
if (!con) {
con = active_console;
}
+ if (is_glide_enabled())
+ return;
+ if (is_mesa_enabled())
+ return;
if (con && con->hw_ops->gfx_update) {
con->hw_ops->gfx_update(con->hw);
}
diff -Nru ../orig/qemu-4.1.1/ui/sdl2.c ./ui/sdl2.c
--- ../orig/qemu-4.1.1/ui/sdl2.c 2019-11-14 10:06:21.000000000 -0800
+++ ./ui/sdl2.c 2020-11-03 16:16:30.720782200 -0800
@@ -36,6 +36,8 @@
static SDL_Surface *guest_sprite_surface;
static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
+static int gui_saved_width;
+static int gui_saved_height;
static int gui_saved_grab;
static int gui_fullscreen;
static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
@@ -528,6 +530,14 @@
sdl2_redraw(scon);
break;
case SDL_WINDOWEVENT_EXPOSED:
+ if (ev->window.data1 && ev->window.data2) {
+ if ((ev->window.data1 == gui_saved_width) &&
+ (ev->window.data2 == gui_saved_height)) {
+ gui_saved_width = 0;
+ gui_saved_height = 0;
+ }
+ SDL_SetWindowSize(scon->real_window, ev->window.data1, ev->window.data2);
+ }
sdl2_redraw(scon);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
@@ -712,6 +722,101 @@
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
+uintptr_t glide_prepare_window(int w, int h)
+{
+ uintptr_t hwndSDL = 0;
+ SDL_SysWMinfo wmi;
+ SDL_Event ev1, *ev = &ev1;
+ int scr_w, scr_h;
+
+ if (!sdl2_console)
+ return hwndSDL;
+
+ SDL_VERSION(&wmi.version);
+ if (SDL_GetWindowWMInfo(sdl2_console[0].real_window, &wmi)) {
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+ hwndSDL = (uintptr_t)wmi.info.win.window;
+#elif defined(SDL_VIDEO_DRIVER_X11)
+ hwndSDL = (uintptr_t)wmi.info.x11.window;
+#else
+#error Unsupported window binding
+#endif
+ }
+ SDL_GetWindowSize(sdl2_console[0].real_window, &scr_w, &scr_h);
+ gui_saved_width = scr_w;
+ gui_saved_height = scr_h;
+
+ glide_enabled_set();
+ smp_mb();
+
+ ev->type = SDL_WINDOWEVENT;
+ ev->window.windowID = SDL_GetWindowID(sdl2_console[0].real_window);
+ ev->window.event = SDL_WINDOWEVENT_EXPOSED;
+ ev->window.data1 = w;
+ ev->window.data2 = h;
+ SDL_PushEvent(ev);
+
+ return hwndSDL;
+}
+
+void glide_release_window(void)
+{
+ glide_enabled_reset();
+ smp_mb();
+ SDL_Event ev1, *ev = &ev1;
+ ev->type = SDL_WINDOWEVENT;
+ ev->window.windowID = SDL_GetWindowID(sdl2_console[0].real_window);
+ ev->window.event = SDL_WINDOWEVENT_EXPOSED;
+ ev->window.data1 = gui_saved_width;
+ ev->window.data2 = gui_saved_height;
+ SDL_PushEvent(ev);
+}
+
+uint32_t glide_window_stat(int activate)
+{
+ int scr_w, scr_h;
+ uint32_t stat;
+ SDL_GetWindowSize(sdl2_console[0].real_window, &scr_w, &scr_h);
+ if (activate)
+ stat = (uint32_t)(((scr_h & 0xFFFFU) << 0x10) | scr_w);
+ else
+ stat = (((gui_saved_height & 0xFFFFU) << 0x10) | gui_saved_width)? 1:0;
+ return stat;
+}
+
+int glide_gui_getheight(void)
+{
+ int scr_w, scr_h;
+ SDL_GetWindowSize(sdl2_console[0].real_window, &scr_w, &scr_h);
+ return scr_h;
+}
+
+int glide_gui_fullscreen(void) { return gui_fullscreen; }
+
+uintptr_t mesa_prepare_window(void)
+{
+ uintptr_t hwndSDL = 0;
+ SDL_SysWMinfo wmi;
+
+ if (!sdl2_console)
+ return hwndSDL;
+
+ SDL_VERSION(&wmi.version);
+ if (SDL_GetWindowWMInfo(sdl2_console[0].real_window, &wmi)) {
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+ hwndSDL = (uintptr_t)wmi.info.win.window;
+#elif defined(SDL_VIDEO_DRIVER_X11)
+ hwndSDL = (uintptr_t)wmi.info.x11.window;
+#else
+#error Unsupported window binding
+#endif
+ }
+
+ return hwndSDL;
+}
+
+void mesa_release_window(void) { }
+
static const DisplayChangeListenerOps dcl_2d_ops = {
.dpy_name = "sdl2-2d",
.dpy_gfx_update = sdl2_2d_update,