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