forked from kjliew/qemu-3dfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-qemu311-mesa-glide.patch
494 lines (478 loc) · 14.7 KB
/
02-qemu311-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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
diff -Nru ../orig/qemu-3.1.1.1/accel/kvm/kvm-all.c ./accel/kvm/kvm-all.c
--- ../orig/qemu-3.1.1.1/accel/kvm/kvm-all.c 2019-10-01 15:31:43.000000000 -0700
+++ ./accel/kvm/kvm-all.c 2020-11-05 17:12:40.133513400 -0800
@@ -819,6 +819,41 @@
}
}
+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-3.1.1.1/configure ./configure
--- ../orig/qemu-3.1.1.1/configure 2019-10-01 15:31:44.000000000 -0700
+++ ./configure 2020-11-03 15:54:39.132654500 -0800
@@ -881,6 +881,8 @@
vhost_scsi="yes"
vhost_vsock="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-3.1.1.1/hw/Makefile.objs ./hw/Makefile.objs
--- ../orig/qemu-3.1.1.1/hw/Makefile.objs 2019-10-01 15:31:44.000000000 -0700
+++ ./hw/Makefile.objs 2020-06-01 18:34:16.581486000 -0700
@@ -7,6 +7,7 @@
devices-dirs-$(CONFIG_SOFTMMU) += char/
devices-dirs-$(CONFIG_SOFTMMU) += cpu/
devices-dirs-$(CONFIG_SOFTMMU) += display/
+devices-dirs-$(CONFIG_SOFTMMU) += 3dfx/
devices-dirs-$(CONFIG_SOFTMMU) += dma/
devices-dirs-$(CONFIG_SOFTMMU) += gpio/
devices-dirs-$(CONFIG_HYPERV) += hyperv/
@@ -17,6 +18,7 @@
devices-dirs-$(CONFIG_IPACK) += ipack/
devices-dirs-$(CONFIG_IPMI) += ipmi/
devices-dirs-$(CONFIG_SOFTMMU) += isa/
+devices-dirs-$(CONFIG_SOFTMMU) += mesa/
devices-dirs-$(CONFIG_SOFTMMU) += misc/
devices-dirs-$(CONFIG_SOFTMMU) += net/
devices-dirs-$(CONFIG_SOFTMMU) += rdma/
diff -Nru ../orig/qemu-3.1.1.1/hw/i386/pc.c ./hw/i386/pc.c
--- ../orig/qemu-3.1.1.1/hw/i386/pc.c 2019-10-01 15:31:44.000000000 -0700
+++ ./hw/i386/pc.c 2020-08-14 01:47:55.734263100 -0700
@@ -1636,6 +1636,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-3.1.1.1/include/hw/i386/pc.h ./include/hw/i386/pc.h
--- ../orig/qemu-3.1.1.1/include/hw/i386/pc.h 2019-10-01 15:31:45.000000000 -0700
+++ ./include/hw/i386/pc.h 2020-08-14 01:45:02.237365100 -0700
@@ -165,6 +165,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-3.1.1.1/include/sysemu/kvm.h ./include/sysemu/kvm.h
--- ../orig/qemu-3.1.1.1/include/sysemu/kvm.h 2019-10-01 15:31:45.000000000 -0700
+++ ./include/sysemu/kvm.h 2020-11-03 12:15:14.421898600 -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-3.1.1.1/include/sysemu/whpx.h ./include/sysemu/whpx.h
--- ../orig/qemu-3.1.1.1/include/sysemu/whpx.h 2019-10-01 15:31:45.000000000 -0700
+++ ./include/sysemu/whpx.h 2020-11-03 14:16:35.980888000 -0800
@@ -29,6 +29,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-3.1.1.1/include/ui/console.h ./include/ui/console.h
--- ../orig/qemu-3.1.1.1/include/ui/console.h 2019-10-01 15:31:45.000000000 -0700
+++ ./include/ui/console.h 2020-10-06 22:57:11.337593800 -0700
@@ -464,4 +464,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-3.1.1.1/target/i386/whpx-all.c ./target/i386/whpx-all.c
--- ../orig/qemu-3.1.1.1/target/i386/whpx-all.c 2019-10-01 15:31:46.000000000 -0700
+++ ./target/i386/whpx-all.c 2020-11-05 15:14:00.596654800 -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"
@@ -1300,6 +1301,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-3.1.1.1/ui/console.c ./ui/console.c
--- ../orig/qemu-3.1.1.1/ui/console.c 2019-10-01 15:31:46.000000000 -0700
+++ ./ui/console.c 2020-11-05 02:56:13.405910500 -0800
@@ -258,11 +258,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-3.1.1.1/ui/sdl.c ./ui/sdl.c
--- ../orig/qemu-3.1.1.1/ui/sdl.c 2019-10-01 15:31:46.000000000 -0700
+++ ./ui/sdl.c 2020-11-03 14:00:24.050235800 -0800
@@ -822,6 +822,10 @@
break;
case SDL_VIDEORESIZE:
sdl_scale(ev->resize.w, ev->resize.h);
+ if ((ev->resize.w == gui_saved_width) && (ev->resize.h == gui_saved_height)) {
+ gui_saved_width = 0;
+ gui_saved_height = 0;
+ }
graphic_hw_invalidate(NULL);
graphic_hw_update(NULL);
break;
@@ -892,6 +896,90 @@
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
+uintptr_t glide_prepare_window(int w, int h)
+{
+ uintptr_t hwndSDL = 0;
+ SDL_SysWMinfo wmi;
+
+ if (!guest_screen)
+ return hwndSDL;
+
+ SDL_VERSION(&wmi.version);
+ if(SDL_GetWMInfo(&wmi)) {
+#if defined(SDL_VIDEO_DRIVER_X11)
+ hwndSDL = (uintptr_t)wmi.info.x11.window;
+#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW)
+ hwndSDL = (uintptr_t)wmi.window;
+#else
+#error Unsupported window binding
+#endif
+ }
+ gui_saved_width = real_screen->w;
+ gui_saved_height = real_screen->h;
+
+ glide_enabled_set();
+ smp_mb();
+
+ SDL_Event ev1, *ev = &ev1;
+ ev->type = SDL_VIDEORESIZE;
+ ev->resize.w = w;
+ ev->resize.h = h;
+ SDL_PushEvent(ev);
+
+ return hwndSDL;
+}
+
+void glide_release_window(void)
+{
+ glide_enabled_reset();
+ smp_mb();
+ SDL_Event ev1, *ev = &ev1;
+ ev->type = SDL_VIDEORESIZE;
+ ev->resize.w = gui_saved_width;
+ ev->resize.h = gui_saved_height;
+ SDL_PushEvent(ev);
+}
+
+uint32_t glide_window_stat(int activate)
+{
+ int scr_w, scr_h;
+ uint32_t stat;
+ scr_w = real_screen->w;
+ scr_h = real_screen->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) { return real_screen->h; }
+int glide_gui_fullscreen(void) { return gui_fullscreen; }
+
+uintptr_t mesa_prepare_window(void)
+{
+ uintptr_t hwndSDL = 0;
+ SDL_SysWMinfo wmi;
+
+ if (!guest_screen)
+ return hwndSDL;
+
+ SDL_VERSION(&wmi.version);
+ if(SDL_GetWMInfo(&wmi)) {
+#if defined(SDL_VIDEO_DRIVER_X11)
+ hwndSDL = (uintptr_t)wmi.info.x11.window;
+#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW)
+ hwndSDL = (uintptr_t)wmi.window;
+#else
+#error Unsupported window binding
+#endif
+ }
+
+ return hwndSDL;
+}
+
+void mesa_release_window(void) { }
+
static const DisplayChangeListenerOps dcl_ops = {
.dpy_name = "sdl",
.dpy_gfx_update = sdl_update,
diff -Nru ../orig/qemu-3.1.1.1/ui/sdl2.c ./ui/sdl2.c
--- ../orig/qemu-3.1.1.1/ui/sdl2.c 2019-10-01 15:31:46.000000000 -0700
+++ ./ui/sdl2.c 2020-11-03 14:10:04.611516100 -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_keysym;
@@ -535,6 +537,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:
@@ -719,6 +729,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,