ia64/xen-unstable

view tools/ioemu/patches/shared-vram @ 10808:b4d5a36e380b

[qemu] Initialize vga from within qemu for when the bios doesn't do so.
On xen/x86, vga bios is copied to 0xC0000 by guest firmware.
However on ia64 platform, native firmware depends on some
initialization vga state at power on and so does guest firmware.
That's why that vga bios initialization stub is required for vti
domain, to match platform requirement.

Signed-off-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Wed Jul 26 15:20:30 2006 +0100 (2006-07-26)
parents f20f1e7091a4
children f3d6a5281617
line source
1 Index: ioemu/hw/cirrus_vga.c
2 ===================================================================
3 --- ioemu.orig/hw/cirrus_vga.c 2006-07-26 15:17:35.230806831 +0100
4 +++ ioemu/hw/cirrus_vga.c 2006-07-26 15:17:39.819307015 +0100
5 @@ -28,6 +28,9 @@
6 */
7 #include "vl.h"
8 #include "vga_int.h"
9 +#ifndef _WIN32
10 +#include <sys/mman.h>
11 +#endif
13 /*
14 * TODO:
15 @@ -231,6 +234,8 @@
16 int cirrus_linear_io_addr;
17 int cirrus_linear_bitblt_io_addr;
18 int cirrus_mmio_io_addr;
19 + unsigned long cirrus_lfb_addr;
20 + unsigned long cirrus_lfb_end;
21 uint32_t cirrus_addr_mask;
22 uint32_t linear_mmio_mask;
23 uint8_t cirrus_shadow_gr0;
24 @@ -267,6 +272,8 @@
25 int last_hw_cursor_y_end;
26 int real_vram_size; /* XXX: suppress that */
27 CPUWriteMemoryFunc **cirrus_linear_write;
28 + unsigned long map_addr;
29 + unsigned long map_end;
30 } CirrusVGAState;
32 typedef struct PCICirrusVGAState {
33 @@ -276,6 +283,8 @@
35 static uint8_t rop_to_index[256];
37 +void *shared_vram;
38 +
39 /***************************************
40 *
41 * prototypes.
42 @@ -2520,6 +2529,80 @@
43 cirrus_linear_bitblt_writel,
44 };
46 +static void *set_vram_mapping(unsigned long begin, unsigned long end)
47 +{
48 + xen_pfn_t *extent_start = NULL;
49 + unsigned long nr_extents;
50 + void *vram_pointer = NULL;
51 + int i;
52 +
53 + /* align begin and end address */
54 + begin = begin & TARGET_PAGE_MASK;
55 + end = begin + VGA_RAM_SIZE;
56 + end = (end + TARGET_PAGE_SIZE -1 ) & TARGET_PAGE_MASK;
57 + nr_extents = (end - begin) >> TARGET_PAGE_BITS;
58 +
59 + extent_start = malloc(sizeof(xen_pfn_t) * nr_extents);
60 + if (extent_start == NULL) {
61 + fprintf(stderr, "Failed malloc on set_vram_mapping\n");
62 + return NULL;
63 + }
64 +
65 + memset(extent_start, 0, sizeof(xen_pfn_t) * nr_extents);
66 +
67 + for (i = 0; i < nr_extents; i++)
68 + extent_start[i] = (begin + i * TARGET_PAGE_SIZE) >> TARGET_PAGE_BITS;
69 +
70 + set_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
71 +
72 + vram_pointer = xc_map_foreign_batch(xc_handle, domid,
73 + PROT_READ|PROT_WRITE,
74 + extent_start, nr_extents);
75 + if (vram_pointer == NULL) {
76 + fprintf(logfile, "xc_map_foreign_batch vgaram returned error %d\n",
77 + errno);
78 + return NULL;
79 + }
80 +
81 + memset(vram_pointer, 0, nr_extents * TARGET_PAGE_SIZE);
82 +
83 + free(extent_start);
84 +
85 + return vram_pointer;
86 +}
87 +
88 +static int unset_vram_mapping(unsigned long begin, unsigned long end)
89 +{
90 + xen_pfn_t *extent_start = NULL;
91 + unsigned long nr_extents;
92 + int i;
93 +
94 + /* align begin and end address */
95 +
96 + end = begin + VGA_RAM_SIZE;
97 + begin = begin & TARGET_PAGE_MASK;
98 + end = (end + TARGET_PAGE_SIZE -1 ) & TARGET_PAGE_MASK;
99 + nr_extents = (end - begin) >> TARGET_PAGE_BITS;
100 +
101 + extent_start = malloc(sizeof(xen_pfn_t) * nr_extents);
102 +
103 + if (extent_start == NULL) {
104 + fprintf(stderr, "Failed malloc on set_mm_mapping\n");
105 + return -1;
106 + }
107 +
108 + memset(extent_start, 0, sizeof(xen_pfn_t) * nr_extents);
109 +
110 + for (i = 0; i < nr_extents; i++)
111 + extent_start[i] = (begin + (i * TARGET_PAGE_SIZE)) >> TARGET_PAGE_BITS;
112 +
113 + unset_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
114 +
115 + free(extent_start);
116 +
117 + return 0;
118 +}
119 +
120 /* Compute the memory access functions */
121 static void cirrus_update_memory_access(CirrusVGAState *s)
122 {
123 @@ -2538,11 +2621,39 @@
125 mode = s->gr[0x05] & 0x7;
126 if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
127 + if (s->cirrus_lfb_addr && s->cirrus_lfb_end && !s->map_addr) {
128 + void *vram_pointer, *old_vram;
129 +
130 + vram_pointer = set_vram_mapping(s->cirrus_lfb_addr,
131 + s->cirrus_lfb_end);
132 + if (!vram_pointer)
133 + fprintf(stderr, "NULL vram_pointer\n");
134 + else {
135 + old_vram = vga_update_vram((VGAState *)s, vram_pointer,
136 + VGA_RAM_SIZE);
137 + qemu_free(old_vram);
138 + }
139 + s->map_addr = s->cirrus_lfb_addr;
140 + s->map_end = s->cirrus_lfb_end;
141 + }
142 s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
143 s->cirrus_linear_write[1] = cirrus_linear_mem_writew;
144 s->cirrus_linear_write[2] = cirrus_linear_mem_writel;
145 } else {
146 generic_io:
147 + if (s->cirrus_lfb_addr && s->cirrus_lfb_end && s->map_addr) {
148 + int error;
149 + void *old_vram = NULL;
150 +
151 + error = unset_vram_mapping(s->cirrus_lfb_addr,
152 + s->cirrus_lfb_end);
153 + if (!error)
154 + old_vram = vga_update_vram((VGAState *)s, NULL,
155 + VGA_RAM_SIZE);
156 + if (old_vram)
157 + munmap(old_vram, s->map_addr - s->map_end);
158 + s->map_addr = s->map_end = 0;
159 + }
160 s->cirrus_linear_write[0] = cirrus_linear_writeb;
161 s->cirrus_linear_write[1] = cirrus_linear_writew;
162 s->cirrus_linear_write[2] = cirrus_linear_writel;
163 @@ -3136,6 +3247,13 @@
164 /* XXX: add byte swapping apertures */
165 cpu_register_physical_memory(addr, s->vram_size,
166 s->cirrus_linear_io_addr);
167 + s->cirrus_lfb_addr = addr;
168 + s->cirrus_lfb_end = addr + VGA_RAM_SIZE;
169 +
170 + if (s->map_addr && (s->cirrus_lfb_addr != s->map_addr) &&
171 + (s->cirrus_lfb_end != s->map_end))
172 + fprintf(logfile, "cirrus vga map change while on lfb mode\n");
173 +
174 cpu_register_physical_memory(addr + 0x1000000, 0x400000,
175 s->cirrus_linear_bitblt_io_addr);
176 }
177 Index: ioemu/hw/pc.c
178 ===================================================================
179 --- ioemu.orig/hw/pc.c 2006-07-26 15:17:39.752314312 +0100
180 +++ ioemu/hw/pc.c 2006-07-26 15:17:39.820306906 +0100
181 @@ -783,14 +783,14 @@
182 if (cirrus_vga_enabled) {
183 if (pci_enabled) {
184 pci_cirrus_vga_init(pci_bus,
185 - ds, phys_ram_base + ram_size, ram_size,
186 + ds, NULL, ram_size,
187 vga_ram_size);
188 } else {
189 - isa_cirrus_vga_init(ds, phys_ram_base + ram_size, ram_size,
190 + isa_cirrus_vga_init(ds, NULL, ram_size,
191 vga_ram_size);
192 }
193 } else {
194 - vga_initialize(pci_bus, ds, phys_ram_base + ram_size, ram_size,
195 + vga_initialize(pci_bus, ds, NULL, ram_size,
196 vga_ram_size, 0, 0);
197 }
199 Index: ioemu/hw/vga.c
200 ===================================================================
201 --- ioemu.orig/hw/vga.c 2006-07-26 15:17:39.352357879 +0100
202 +++ ioemu/hw/vga.c 2006-07-26 15:17:39.821306797 +0100
203 @@ -1799,6 +1799,7 @@
204 /* TODO: add vbe support if enabled */
205 }
207 +/* when used on xen environment, the vga_ram_base is not used */
208 void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
209 unsigned long vga_ram_offset, int vga_ram_size)
210 {
211 @@ -1829,7 +1830,7 @@
213 vga_reset(s);
215 - s->vram_ptr = vga_ram_base;
216 + s->vram_ptr = qemu_malloc(vga_ram_size);
217 s->vram_offset = vga_ram_offset;
218 s->vram_size = vga_ram_size;
219 s->ds = ds;
220 @@ -1941,6 +1942,31 @@
221 return 0;
222 }
224 +void *vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size)
225 +{
226 + uint8_t *old_pointer;
227 +
228 + if (s->vram_size != vga_ram_size) {
229 + fprintf(stderr, "No support to change vga_ram_size\n");
230 + return NULL;
231 + }
232 +
233 + if (!vga_ram_base) {
234 + vga_ram_base = qemu_malloc(vga_ram_size);
235 + if (!vga_ram_base) {
236 + fprintf(stderr, "reallocate error\n");
237 + return NULL;
238 + }
239 + }
240 +
241 + /* XXX lock needed? */
242 + memcpy(vga_ram_base, s->vram_ptr, vga_ram_size);
243 + old_pointer = s->vram_ptr;
244 + s->vram_ptr = vga_ram_base;
245 +
246 + return old_pointer;
247 +}
248 +
249 /********************************************************/
250 /* vga screen dump */
252 Index: ioemu/hw/vga_int.h
253 ===================================================================
254 --- ioemu.orig/hw/vga_int.h 2006-07-26 15:17:38.201483242 +0100
255 +++ ioemu/hw/vga_int.h 2006-07-26 15:17:39.822306688 +0100
256 @@ -166,5 +166,6 @@
257 unsigned int color0, unsigned int color1,
258 unsigned int color_xor);
260 +void *vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size);
261 extern const uint8_t sr_mask[8];
262 extern const uint8_t gr_mask[16];
263 Index: ioemu/vl.c
264 ===================================================================
265 --- ioemu.orig/vl.c 2006-07-26 15:17:39.755313985 +0100
266 +++ ioemu/vl.c 2006-07-26 15:17:39.824306470 +0100
267 @@ -5148,6 +5148,78 @@
269 #define MAX_NET_CLIENTS 32
271 +#include <xg_private.h>
272 +
273 +/* FIXME Flush the shadow page */
274 +int unset_mm_mapping(int xc_handle, uint32_t domid,
275 + unsigned long nr_pages, unsigned int address_bits,
276 + xen_pfn_t *extent_start)
277 +{
278 + int err = 0;
279 + xc_dominfo_t info;
280 +
281 + err = xc_domain_memory_decrease_reservation(xc_handle, domid,
282 + nr_pages, 0, extent_start);
283 + if (err)
284 + fprintf(stderr, "Failed to decrease physmap\n");
285 +
286 + xc_domain_getinfo(xc_handle, domid, 1, &info);
287 +
288 + if ((info.nr_pages - nr_pages) <= 0) {
289 + fprintf(stderr, "unset_mm_mapping: error nr_pages\n");
290 + err = -1;
291 + }
292 +
293 + if (xc_domain_setmaxmem(xc_handle, domid, (info.nr_pages - nr_pages) *
294 + PAGE_SIZE/1024) != 0) {
295 + fprintf(logfile, "set maxmem returned error %d\n", errno);
296 + err = -1;
297 + }
298 +
299 + return err;
300 +}
301 +
302 +int set_mm_mapping(int xc_handle, uint32_t domid,
303 + unsigned long nr_pages, unsigned int address_bits,
304 + xen_pfn_t *extent_start)
305 +{
306 +#if 0
307 + int i;
308 +#endif
309 + xc_dominfo_t info;
310 + int err = 0;
311 +
312 + xc_domain_getinfo(xc_handle, domid, 1, &info);
313 +
314 + if (xc_domain_setmaxmem(xc_handle, domid, info.max_memkb +
315 + nr_pages * PAGE_SIZE/1024) != 0) {
316 + fprintf(logfile, "set maxmem returned error %d\n", errno);
317 + return -1;
318 + }
319 +
320 + err = xc_domain_memory_populate_physmap(xc_handle, domid, nr_pages, 0,
321 + address_bits, extent_start);
322 + if (err) {
323 + fprintf(stderr, "Failed to populate physmap\n");
324 + return -1;
325 + }
326 +
327 + err = xc_domain_translate_gpfn_list(xc_handle, domid, nr_pages,
328 + extent_start, extent_start);
329 + if (err) {
330 + fprintf(stderr, "Failed to translate gpfn list\n");
331 + return -1;
332 + }
333 +
334 +#if 0 /* Generates lots of log file output - turn on for debugging */
335 + for (i = 0; i < nr_pages; i++)
336 + fprintf(stderr, "set_map result i %x result %lx\n", i,
337 + extent_start[i]);
338 +#endif
339 +
340 + return 0;
341 +}
342 +
343 int main(int argc, char **argv)
344 {
345 #ifdef CONFIG_GDBSTUB
346 Index: ioemu/vl.h
347 ===================================================================
348 --- ioemu.orig/vl.h 2006-07-26 15:17:39.621328580 +0100
349 +++ ioemu/vl.h 2006-07-26 15:17:39.825306361 +0100
350 @@ -136,6 +136,13 @@
352 void main_loop_wait(int timeout);
354 +int unset_mm_mapping(int xc_handle, uint32_t domid, unsigned long nr_pages,
355 + unsigned int address_bits, unsigned long *extent_start);
356 +int set_mm_mapping(int xc_handle, uint32_t domid, unsigned long nr_pages,
357 + unsigned int address_bits, unsigned long *extent_start);
358 +
359 +extern void *shared_vram;
360 +
361 extern FILE *logfile;
363 extern int xc_handle;