2
0

xen_machine_pv.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * QEMU Xen PV Machine
  3. *
  4. * Copyright (c) 2007 Red Hat
  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 "hw.h"
  25. #include "pc.h"
  26. #include "boards.h"
  27. #include "xen_backend.h"
  28. #include "xen_domainbuild.h"
  29. #include "sysemu/blockdev.h"
  30. static void xen_init_pv(QEMUMachineInitArgs *args)
  31. {
  32. const char *cpu_model = args->cpu_model;
  33. const char *kernel_filename = args->kernel_filename;
  34. const char *kernel_cmdline = args->kernel_cmdline;
  35. const char *initrd_filename = args->initrd_filename;
  36. X86CPU *cpu;
  37. CPUX86State *env;
  38. DriveInfo *dinfo;
  39. int i;
  40. /* Initialize a dummy CPU */
  41. if (cpu_model == NULL) {
  42. #ifdef TARGET_X86_64
  43. cpu_model = "qemu64";
  44. #else
  45. cpu_model = "qemu32";
  46. #endif
  47. }
  48. cpu = cpu_x86_init(cpu_model);
  49. env = &cpu->env;
  50. env->halted = 1;
  51. /* Initialize backend core & drivers */
  52. if (xen_be_init() != 0) {
  53. fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
  54. exit(1);
  55. }
  56. switch (xen_mode) {
  57. case XEN_ATTACH:
  58. /* nothing to do, xend handles everything */
  59. break;
  60. case XEN_CREATE:
  61. if (xen_domain_build_pv(kernel_filename, initrd_filename,
  62. kernel_cmdline) < 0) {
  63. fprintf(stderr, "xen pv domain creation failed\n");
  64. exit(1);
  65. }
  66. break;
  67. case XEN_EMULATE:
  68. fprintf(stderr, "xen emulation not implemented (yet)\n");
  69. exit(1);
  70. break;
  71. }
  72. xen_be_register("console", &xen_console_ops);
  73. xen_be_register("vkbd", &xen_kbdmouse_ops);
  74. xen_be_register("vfb", &xen_framebuffer_ops);
  75. xen_be_register("qdisk", &xen_blkdev_ops);
  76. xen_be_register("qnic", &xen_netdev_ops);
  77. /* configure framebuffer */
  78. if (xenfb_enabled) {
  79. xen_config_dev_vfb(0, "vnc");
  80. xen_config_dev_vkbd(0);
  81. }
  82. /* configure disks */
  83. for (i = 0; i < 16; i++) {
  84. dinfo = drive_get(IF_XEN, 0, i);
  85. if (!dinfo)
  86. continue;
  87. xen_config_dev_blk(dinfo);
  88. }
  89. /* configure nics */
  90. for (i = 0; i < nb_nics; i++) {
  91. if (!nd_table[i].model || 0 != strcmp(nd_table[i].model, "xen"))
  92. continue;
  93. xen_config_dev_nic(nd_table + i);
  94. }
  95. /* config cleanup hook */
  96. atexit(xen_config_cleanup);
  97. /* setup framebuffer */
  98. xen_init_display(xen_domid);
  99. }
  100. static QEMUMachine xenpv_machine = {
  101. .name = "xenpv",
  102. .desc = "Xen Para-virtualized PC",
  103. .init = xen_init_pv,
  104. .max_cpus = 1,
  105. .default_machine_opts = "accel=xen",
  106. DEFAULT_MACHINE_OPTIONS,
  107. };
  108. static void xenpv_machine_init(void)
  109. {
  110. qemu_register_machine(&xenpv_machine);
  111. }
  112. machine_init(xenpv_machine_init);