]>
git.proxmox.com Git - mirror_qemu.git/blob - arch_init.c
4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 #include "arch_init.h"
33 #include "audio/audio.h"
36 #include "hw/audiodev.h"
38 #include "migration.h"
41 #include "hw/smbios.h"
44 int graphic_width
= 1024;
45 int graphic_height
= 768;
46 int graphic_depth
= 8;
48 int graphic_width
= 800;
49 int graphic_height
= 600;
50 int graphic_depth
= 15;
53 const char arch_config_name
[] = CONFIG_QEMU_CONFDIR
"/target-" TARGET_ARCH
".conf";
55 #if defined(TARGET_ALPHA)
56 #define QEMU_ARCH QEMU_ARCH_ALPHA
57 #elif defined(TARGET_ARM)
58 #define QEMU_ARCH QEMU_ARCH_ARM
59 #elif defined(TARGET_CRIS)
60 #define QEMU_ARCH QEMU_ARCH_CRIS
61 #elif defined(TARGET_I386)
62 #define QEMU_ARCH QEMU_ARCH_I386
63 #elif defined(TARGET_M68K)
64 #define QEMU_ARCH QEMU_ARCH_M68K
65 #elif defined(TARGET_MICROBLAZE)
66 #define QEMU_ARCH QEMU_ARCH_MICROBLAZE
67 #elif defined(TARGET_MIPS)
68 #define QEMU_ARCH QEMU_ARCH_MIPS
69 #elif defined(TARGET_PPC)
70 #define QEMU_ARCH QEMU_ARCH_PPC
71 #elif defined(TARGET_S390X)
72 #define QEMU_ARCH QEMU_ARCH_S390X
73 #elif defined(TARGET_SH4)
74 #define QEMU_ARCH QEMU_ARCH_SH4
75 #elif defined(TARGET_SPARC)
76 #define QEMU_ARCH QEMU_ARCH_SPARC
79 const uint32_t arch_type
= QEMU_ARCH
;
81 /***********************************************************/
82 /* ram save/restore */
84 #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
85 #define RAM_SAVE_FLAG_COMPRESS 0x02
86 #define RAM_SAVE_FLAG_MEM_SIZE 0x04
87 #define RAM_SAVE_FLAG_PAGE 0x08
88 #define RAM_SAVE_FLAG_EOS 0x10
90 static int is_dup_page(uint8_t *page
, uint8_t ch
)
92 uint32_t val
= ch
<< 24 | ch
<< 16 | ch
<< 8 | ch
;
93 uint32_t *array
= (uint32_t *)page
;
96 for (i
= 0; i
< (TARGET_PAGE_SIZE
/ 4); i
++) {
97 if (array
[i
] != val
) {
105 static int ram_save_block(QEMUFile
*f
)
107 static ram_addr_t current_addr
= 0;
108 ram_addr_t saved_addr
= current_addr
;
112 while (addr
< last_ram_offset
) {
113 if (cpu_physical_memory_get_dirty(current_addr
, MIGRATION_DIRTY_FLAG
)) {
116 cpu_physical_memory_reset_dirty(current_addr
,
117 current_addr
+ TARGET_PAGE_SIZE
,
118 MIGRATION_DIRTY_FLAG
);
120 p
= qemu_get_ram_ptr(current_addr
);
122 if (is_dup_page(p
, *p
)) {
123 qemu_put_be64(f
, current_addr
| RAM_SAVE_FLAG_COMPRESS
);
124 qemu_put_byte(f
, *p
);
126 qemu_put_be64(f
, current_addr
| RAM_SAVE_FLAG_PAGE
);
127 qemu_put_buffer(f
, p
, TARGET_PAGE_SIZE
);
133 addr
+= TARGET_PAGE_SIZE
;
134 current_addr
= (saved_addr
+ addr
) % last_ram_offset
;
140 static uint64_t bytes_transferred
;
142 static ram_addr_t
ram_save_remaining(void)
145 ram_addr_t count
= 0;
147 for (addr
= 0; addr
< last_ram_offset
; addr
+= TARGET_PAGE_SIZE
) {
148 if (cpu_physical_memory_get_dirty(addr
, MIGRATION_DIRTY_FLAG
)) {
156 uint64_t ram_bytes_remaining(void)
158 return ram_save_remaining() * TARGET_PAGE_SIZE
;
161 uint64_t ram_bytes_transferred(void)
163 return bytes_transferred
;
166 uint64_t ram_bytes_total(void)
168 return last_ram_offset
;
171 int ram_save_live(Monitor
*mon
, QEMUFile
*f
, int stage
, void *opaque
)
174 uint64_t bytes_transferred_last
;
176 uint64_t expected_time
= 0;
179 cpu_physical_memory_set_dirty_tracking(0);
183 if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX
) != 0) {
184 qemu_file_set_error(f
);
189 bytes_transferred
= 0;
191 /* Make sure all dirty bits are set */
192 for (addr
= 0; addr
< last_ram_offset
; addr
+= TARGET_PAGE_SIZE
) {
193 if (!cpu_physical_memory_get_dirty(addr
, MIGRATION_DIRTY_FLAG
)) {
194 cpu_physical_memory_set_dirty(addr
);
198 /* Enable dirty memory tracking */
199 cpu_physical_memory_set_dirty_tracking(1);
201 qemu_put_be64(f
, last_ram_offset
| RAM_SAVE_FLAG_MEM_SIZE
);
204 bytes_transferred_last
= bytes_transferred
;
205 bwidth
= qemu_get_clock_ns(rt_clock
);
207 while (!qemu_file_rate_limit(f
)) {
210 ret
= ram_save_block(f
);
211 bytes_transferred
+= ret
* TARGET_PAGE_SIZE
;
212 if (ret
== 0) { /* no more blocks */
217 bwidth
= qemu_get_clock_ns(rt_clock
) - bwidth
;
218 bwidth
= (bytes_transferred
- bytes_transferred_last
) / bwidth
;
220 /* if we haven't transferred anything this round, force expected_time to a
221 * a very high value, but without crashing */
226 /* try transferring iterative blocks of memory */
228 /* flush all remaining blocks regardless of rate limiting */
229 while (ram_save_block(f
) != 0) {
230 bytes_transferred
+= TARGET_PAGE_SIZE
;
232 cpu_physical_memory_set_dirty_tracking(0);
235 qemu_put_be64(f
, RAM_SAVE_FLAG_EOS
);
237 expected_time
= ram_save_remaining() * TARGET_PAGE_SIZE
/ bwidth
;
239 return (stage
== 2) && (expected_time
<= migrate_max_downtime());
242 int ram_load(QEMUFile
*f
, void *opaque
, int version_id
)
247 if (version_id
!= 3) {
252 addr
= qemu_get_be64(f
);
254 flags
= addr
& ~TARGET_PAGE_MASK
;
255 addr
&= TARGET_PAGE_MASK
;
257 if (flags
& RAM_SAVE_FLAG_MEM_SIZE
) {
258 if (addr
!= last_ram_offset
) {
263 if (flags
& RAM_SAVE_FLAG_COMPRESS
) {
264 uint8_t ch
= qemu_get_byte(f
);
265 memset(qemu_get_ram_ptr(addr
), ch
, TARGET_PAGE_SIZE
);
268 (!kvm_enabled() || kvm_has_sync_mmu())) {
269 madvise(qemu_get_ram_ptr(addr
), TARGET_PAGE_SIZE
,
273 } else if (flags
& RAM_SAVE_FLAG_PAGE
) {
274 qemu_get_buffer(f
, qemu_get_ram_ptr(addr
), TARGET_PAGE_SIZE
);
276 if (qemu_file_has_error(f
)) {
279 } while (!(flags
& RAM_SAVE_FLAG_EOS
));
284 void qemu_service_io(void)
290 struct soundhw soundhw
[] = {
291 #ifdef HAS_AUDIO_CHOICE
292 #if defined(TARGET_I386) || defined(TARGET_MIPS)
298 { .init_isa
= pcspk_audio_init
}
305 "Creative Sound Blaster 16",
308 { .init_isa
= SB16_init
}
312 #ifdef CONFIG_CS4231A
318 { .init_isa
= cs4231a_init
}
326 "Yamaha YMF262 (OPL3)",
328 "Yamaha YM3812 (OPL2)",
332 { .init_isa
= Adlib_init
}
339 "Gravis Ultrasound GF1",
342 { .init_isa
= GUS_init
}
349 "Intel 82801AA AC97 Audio",
352 { .init_pci
= ac97_init
}
359 "ENSONIQ AudioPCI ES1370",
362 { .init_pci
= es1370_init
}
366 #endif /* HAS_AUDIO_CHOICE */
368 { NULL
, NULL
, 0, 0, { NULL
} }
371 void select_soundhw(const char *optarg
)
375 if (*optarg
== '?') {
378 printf("Valid sound card names (comma separated):\n");
379 for (c
= soundhw
; c
->name
; ++c
) {
380 printf ("%-11s %s\n", c
->name
, c
->descr
);
382 printf("\n-soundhw all will enable all of the above\n");
383 exit(*optarg
!= '?');
391 if (!strcmp(optarg
, "all")) {
392 for (c
= soundhw
; c
->name
; ++c
) {
401 l
= !e
? strlen(p
) : (size_t) (e
- p
);
403 for (c
= soundhw
; c
->name
; ++c
) {
404 if (!strncmp(c
->name
, p
, l
) && !c
->name
[l
]) {
413 "Unknown sound card name (too big to show)\n");
416 fprintf(stderr
, "Unknown sound card name `%.*s'\n",
421 p
+= l
+ (e
!= NULL
);
425 goto show_valid_cards
;
430 void select_soundhw(const char *optarg
)
435 int qemu_uuid_parse(const char *str
, uint8_t *uuid
)
439 if (strlen(str
) != 36) {
443 ret
= sscanf(str
, UUID_FMT
, &uuid
[0], &uuid
[1], &uuid
[2], &uuid
[3],
444 &uuid
[4], &uuid
[5], &uuid
[6], &uuid
[7], &uuid
[8], &uuid
[9],
445 &uuid
[10], &uuid
[11], &uuid
[12], &uuid
[13], &uuid
[14],
452 smbios_add_field(1, offsetof(struct smbios_type_1
, uuid
), 16, uuid
);
457 void do_acpitable_option(const char *optarg
)
460 if (acpi_table_add(optarg
) < 0) {
461 fprintf(stderr
, "Wrong acpi table provided\n");
467 void do_smbios_option(const char *optarg
)
470 if (smbios_entry_add(optarg
) < 0) {
471 fprintf(stderr
, "Wrong smbios provided\n");
477 void cpudef_init(void)
479 #if defined(cpudef_setup)
480 cpudef_setup(); /* parse cpu definitions in target config file */
484 int audio_available(void)
493 int kvm_available(void)
502 int xen_available(void)