arch_init.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * QEMU System Emulator
  3. *
  4. * Copyright (c) 2003-2008 Fabrice Bellard
  5. *
  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:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  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
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "sysemu/sysemu.h"
  26. #include "sysemu/arch_init.h"
  27. #include "hw/pci/pci.h"
  28. #include "hw/audio/audio.h"
  29. #include "hw/smbios/smbios.h"
  30. #include "qemu/config-file.h"
  31. #include "qemu/error-report.h"
  32. #include "qmp-commands.h"
  33. #include "hw/acpi/acpi.h"
  34. #ifdef TARGET_SPARC
  35. int graphic_width = 1024;
  36. int graphic_height = 768;
  37. int graphic_depth = 8;
  38. #else
  39. int graphic_width = 800;
  40. int graphic_height = 600;
  41. int graphic_depth = 32;
  42. #endif
  43. #if defined(TARGET_ALPHA)
  44. #define QEMU_ARCH QEMU_ARCH_ALPHA
  45. #elif defined(TARGET_ARM)
  46. #define QEMU_ARCH QEMU_ARCH_ARM
  47. #elif defined(TARGET_CRIS)
  48. #define QEMU_ARCH QEMU_ARCH_CRIS
  49. #elif defined(TARGET_I386)
  50. #define QEMU_ARCH QEMU_ARCH_I386
  51. #elif defined(TARGET_M68K)
  52. #define QEMU_ARCH QEMU_ARCH_M68K
  53. #elif defined(TARGET_LM32)
  54. #define QEMU_ARCH QEMU_ARCH_LM32
  55. #elif defined(TARGET_MICROBLAZE)
  56. #define QEMU_ARCH QEMU_ARCH_MICROBLAZE
  57. #elif defined(TARGET_MIPS)
  58. #define QEMU_ARCH QEMU_ARCH_MIPS
  59. #elif defined(TARGET_MOXIE)
  60. #define QEMU_ARCH QEMU_ARCH_MOXIE
  61. #elif defined(TARGET_OPENRISC)
  62. #define QEMU_ARCH QEMU_ARCH_OPENRISC
  63. #elif defined(TARGET_PPC)
  64. #define QEMU_ARCH QEMU_ARCH_PPC
  65. #elif defined(TARGET_S390X)
  66. #define QEMU_ARCH QEMU_ARCH_S390X
  67. #elif defined(TARGET_SH4)
  68. #define QEMU_ARCH QEMU_ARCH_SH4
  69. #elif defined(TARGET_SPARC)
  70. #define QEMU_ARCH QEMU_ARCH_SPARC
  71. #elif defined(TARGET_XTENSA)
  72. #define QEMU_ARCH QEMU_ARCH_XTENSA
  73. #elif defined(TARGET_UNICORE32)
  74. #define QEMU_ARCH QEMU_ARCH_UNICORE32
  75. #elif defined(TARGET_TRICORE)
  76. #define QEMU_ARCH QEMU_ARCH_TRICORE
  77. #endif
  78. const uint32_t arch_type = QEMU_ARCH;
  79. static struct defconfig_file {
  80. const char *filename;
  81. /* Indicates it is an user config file (disabled by -no-user-config) */
  82. bool userconfig;
  83. } default_config_files[] = {
  84. { CONFIG_QEMU_CONFDIR "/qemu.conf", true },
  85. { NULL }, /* end of list */
  86. };
  87. int qemu_read_default_config_files(bool userconfig)
  88. {
  89. int ret;
  90. struct defconfig_file *f;
  91. for (f = default_config_files; f->filename; f++) {
  92. if (!userconfig && f->userconfig) {
  93. continue;
  94. }
  95. ret = qemu_read_config_file(f->filename);
  96. if (ret < 0 && ret != -ENOENT) {
  97. return ret;
  98. }
  99. }
  100. return 0;
  101. }
  102. struct soundhw {
  103. const char *name;
  104. const char *descr;
  105. int enabled;
  106. int isa;
  107. union {
  108. int (*init_isa) (ISABus *bus);
  109. int (*init_pci) (PCIBus *bus);
  110. } init;
  111. };
  112. static struct soundhw soundhw[9];
  113. static int soundhw_count;
  114. void isa_register_soundhw(const char *name, const char *descr,
  115. int (*init_isa)(ISABus *bus))
  116. {
  117. assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
  118. soundhw[soundhw_count].name = name;
  119. soundhw[soundhw_count].descr = descr;
  120. soundhw[soundhw_count].isa = 1;
  121. soundhw[soundhw_count].init.init_isa = init_isa;
  122. soundhw_count++;
  123. }
  124. void pci_register_soundhw(const char *name, const char *descr,
  125. int (*init_pci)(PCIBus *bus))
  126. {
  127. assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
  128. soundhw[soundhw_count].name = name;
  129. soundhw[soundhw_count].descr = descr;
  130. soundhw[soundhw_count].isa = 0;
  131. soundhw[soundhw_count].init.init_pci = init_pci;
  132. soundhw_count++;
  133. }
  134. void select_soundhw(const char *optarg)
  135. {
  136. struct soundhw *c;
  137. if (is_help_option(optarg)) {
  138. show_valid_cards:
  139. if (soundhw_count) {
  140. printf("Valid sound card names (comma separated):\n");
  141. for (c = soundhw; c->name; ++c) {
  142. printf ("%-11s %s\n", c->name, c->descr);
  143. }
  144. printf("\n-soundhw all will enable all of the above\n");
  145. } else {
  146. printf("Machine has no user-selectable audio hardware "
  147. "(it may or may not have always-present audio hardware).\n");
  148. }
  149. exit(!is_help_option(optarg));
  150. }
  151. else {
  152. size_t l;
  153. const char *p;
  154. char *e;
  155. int bad_card = 0;
  156. if (!strcmp(optarg, "all")) {
  157. for (c = soundhw; c->name; ++c) {
  158. c->enabled = 1;
  159. }
  160. return;
  161. }
  162. p = optarg;
  163. while (*p) {
  164. e = strchr(p, ',');
  165. l = !e ? strlen(p) : (size_t) (e - p);
  166. for (c = soundhw; c->name; ++c) {
  167. if (!strncmp(c->name, p, l) && !c->name[l]) {
  168. c->enabled = 1;
  169. break;
  170. }
  171. }
  172. if (!c->name) {
  173. if (l > 80) {
  174. error_report("Unknown sound card name (too big to show)");
  175. }
  176. else {
  177. error_report("Unknown sound card name `%.*s'",
  178. (int) l, p);
  179. }
  180. bad_card = 1;
  181. }
  182. p += l + (e != NULL);
  183. }
  184. if (bad_card) {
  185. goto show_valid_cards;
  186. }
  187. }
  188. }
  189. void audio_init(void)
  190. {
  191. struct soundhw *c;
  192. ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
  193. PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
  194. for (c = soundhw; c->name; ++c) {
  195. if (c->enabled) {
  196. if (c->isa) {
  197. if (!isa_bus) {
  198. error_report("ISA bus not available for %s", c->name);
  199. exit(1);
  200. }
  201. c->init.init_isa(isa_bus);
  202. } else {
  203. if (!pci_bus) {
  204. error_report("PCI bus not available for %s", c->name);
  205. exit(1);
  206. }
  207. c->init.init_pci(pci_bus);
  208. }
  209. }
  210. }
  211. }
  212. int qemu_uuid_parse(const char *str, uint8_t *uuid)
  213. {
  214. int ret;
  215. if (strlen(str) != 36) {
  216. return -1;
  217. }
  218. ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
  219. &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
  220. &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
  221. &uuid[15]);
  222. if (ret != 16) {
  223. return -1;
  224. }
  225. return 0;
  226. }
  227. void do_acpitable_option(const QemuOpts *opts)
  228. {
  229. #ifdef TARGET_I386
  230. Error *err = NULL;
  231. acpi_table_add(opts, &err);
  232. if (err) {
  233. error_reportf_err(err, "Wrong acpi table provided: ");
  234. exit(1);
  235. }
  236. #endif
  237. }
  238. void do_smbios_option(QemuOpts *opts)
  239. {
  240. #ifdef TARGET_I386
  241. smbios_entry_add(opts);
  242. #endif
  243. }
  244. void cpudef_init(void)
  245. {
  246. #if defined(cpudef_setup)
  247. cpudef_setup(); /* parse cpu definitions in target config file */
  248. #endif
  249. }
  250. int kvm_available(void)
  251. {
  252. #ifdef CONFIG_KVM
  253. return 1;
  254. #else
  255. return 0;
  256. #endif
  257. }
  258. int xen_available(void)
  259. {
  260. #ifdef CONFIG_XEN
  261. return 1;
  262. #else
  263. return 0;
  264. #endif
  265. }
  266. TargetInfo *qmp_query_target(Error **errp)
  267. {
  268. TargetInfo *info = g_malloc0(sizeof(*info));
  269. info->arch = g_strdup(TARGET_NAME);
  270. return info;
  271. }