forked from kjliew/qemu-3dfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00-qemu520-mesa-glide.patch
386 lines (368 loc) · 12.8 KB
/
00-qemu520-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
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/accel/kvm/kvm-all.c ./accel/kvm/kvm-all.c
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/accel/kvm/kvm-all.c 2020-12-08 08:59:44.000000000 -0800
+++ ./accel/kvm/kvm-all.c 2020-12-11 10:46:03.183884800 -0800
@@ -1216,6 +1216,41 @@
kvm_slots_unlock(kml);
}
+void kvm_update_guest_pa_range(uint64_t start_pa, uint64_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 /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/meson.build ./meson.build
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/meson.build 2020-12-08 08:59:44.000000000 -0800
+++ ./meson.build 2020-12-11 11:39:30.806505200 -0800
@@ -1740,6 +1740,7 @@
target_inc = [include_directories('target' / config_target['TARGET_BASE_ARCH'])]
if targetos == 'linux'
target_inc += include_directories('linux-headers', is_system: true)
+ link_args += ['-ldl', '-lXxf86vm', '-lGLX']
endif
if target.endswith('-softmmu')
qemu_target_name = 'qemu-system-' + target_name
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/hw/meson.build ./hw/meson.build
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/hw/meson.build 2020-12-08 08:59:44.000000000 -0800
+++ ./hw/meson.build 2020-12-11 10:46:03.184640500 -0800
@@ -42,6 +42,9 @@
subdir('xen')
subdir('xenpv')
+subdir('3dfx')
+subdir('mesa')
+
subdir('alpha')
subdir('arm')
subdir('avr')
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/hw/i386/pc.c ./hw/i386/pc.c
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/hw/i386/pc.c 2020-12-08 08:59:44.000000000 -0800
+++ ./hw/i386/pc.c 2020-12-11 10:46:03.186284900 -0800
@@ -1190,6 +1190,28 @@
/* Super I/O */
pc_superio_init(isa_bus, create_fdctrl, pcms->vmport != ON_OFF_AUTO_ON);
+ /* 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 /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/hw/i386/pc.h ./include/hw/i386/pc.h
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/hw/i386/pc.h 2020-12-08 08:59:44.000000000 -0800
+++ ./include/hw/i386/pc.h 2020-12-11 10:46:03.187591200 -0800
@@ -182,6 +182,22 @@
#define TYPE_PORT92 "port92"
+#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);
+
/* pc_sysfw.c */
void pc_system_flash_create(PCMachineState *pcms);
void pc_system_flash_cleanup_unused(PCMachineState *pcms);
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/sysemu/kvm.h ./include/sysemu/kvm.h
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/sysemu/kvm.h 2020-12-08 08:59:44.000000000 -0800
+++ ./include/sysemu/kvm.h 2020-12-11 11:06:17.227556600 -0800
@@ -480,6 +480,8 @@
#endif /* NEED_CPU_H */
+void kvm_update_guest_pa_range(uint64_t start_pa, uint64_t size, void *host_va, int readonly, int add);
+
void kvm_cpu_synchronize_state(CPUState *cpu);
void kvm_init_cpu_signals(CPUState *cpu);
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/sysemu/whpx.h ./include/sysemu/whpx.h
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/sysemu/whpx.h 2020-12-08 08:59:44.000000000 -0800
+++ ./include/sysemu/whpx.h 2020-12-11 12:06:30.641972100 -0800
@@ -15,6 +15,8 @@
#ifdef CONFIG_WHPX
+void whpx_update_guest_pa_range(uint64_t start_pa, uint64_t size, void *host_va, int readonly, int add);
+
int whpx_enabled(void);
#else /* CONFIG_WHPX */
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/ui/console.h ./include/ui/console.h
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/include/ui/console.h 2020-12-08 08:59:44.000000000 -0800
+++ ./include/ui/console.h 2020-12-11 10:46:03.190942000 -0800
@@ -446,4 +446,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 /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/target/i386/whpx-all.c ./target/i386/whpx-all.c
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/target/i386/whpx-all.c 2020-12-08 08:59:44.000000000 -0800
+++ ./target/i386/whpx-all.c 2020-12-11 10:46:03.193264200 -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"
@@ -1440,6 +1441,38 @@
memory_region_is_rom(mr), mr->name);
}
+void whpx_update_guest_pa_range(uint64_t start_pa, uint64_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 /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/ui/console.c ./ui/console.c
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/ui/console.c 2020-12-08 08:59:44.000000000 -0800
+++ ./ui/console.c 2020-12-11 10:46:03.195010700 -0800
@@ -262,6 +262,16 @@
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_done(QemuConsole *con)
{
if (con) {
@@ -276,6 +286,10 @@
if (!con) {
return;
}
+ if (is_glide_enabled())
+ return;
+ if (is_mesa_enabled())
+ return;
if (con->hw_ops->gfx_update) {
con->hw_ops->gfx_update(con->hw);
async = con->hw_ops->gfx_update_async;
diff -Nru /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/ui/sdl2.c ./ui/sdl2.c
--- /home/kliew/MyData/GnuSW/msys/2.0/home/kliew1/src/qemu/orig/qemu-5.2.0/ui/sdl2.c 2020-12-08 08:59:44.000000000 -0800
+++ ./ui/sdl2.c 2020-12-11 10:46:03.196146900 -0800
@@ -39,6 +39,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;
@@ -563,6 +565,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:
@@ -755,6 +765,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,