xen_machine_pv.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. CPUState *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. env = cpu_init(cpu_model);
  49. env->halted = 1;
  50. /* Initialize backend core & drivers */
  51. if (xen_be_init() != 0) {
  52. fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
  53. exit(1);
  54. }
  55. switch (xen_mode) {
  56. case XEN_ATTACH:
  57. /* nothing to do, xend handles everything */
  58. break;
  59. case XEN_CREATE:
  60. if (xen_domain_build_pv(kernel_filename, initrd_filename,
  61. kernel_cmdline) < 0) {
  62. fprintf(stderr, "xen pv domain creation failed\n");
  63. exit(1);
  64. }
  65. break;
  66. case XEN_EMULATE:
  67. fprintf(stderr, "xen emulation not implemented (yet)\n");
  68. exit(1);
  69. break;
  70. }
  71. xen_be_register("console", &xen_console_ops);
  72. xen_be_register("vkbd", &xen_kbdmouse_ops);
  73. xen_be_register("vfb", &xen_framebuffer_ops);
  74. xen_be_register("qdisk", &xen_blkdev_ops);
  75. xen_be_register("qnic", &xen_netdev_ops);
  76. /* configure framebuffer */
  77. if (xenfb_enabled) {
  78. xen_config_dev_vfb(0, "vnc");
  79. xen_config_dev_vkbd(0);
  80. }
  81. /* configure disks */
  82. for (i = 0; i < 16; i++) {
  83. dinfo = drive_get(IF_XEN, 0, i);
  84. if (!dinfo)
  85. continue;
  86. xen_config_dev_blk(dinfo);
  87. }
  88. /* configure nics */
  89. for (i = 0; i < nb_nics; i++) {
  90. if (!nd_table[i].model || 0 != strcmp(nd_table[i].model, "xen"))
  91. continue;
  92. xen_config_dev_nic(nd_table + i);
  93. }
  94. /* config cleanup hook */
  95. atexit(xen_config_cleanup);
  96. /* setup framebuffer */
  97. xen_init_display(xen_domid);
  98. }
  99. static QEMUMachine xenpv_machine = {
  100. .name = "xenpv",
  101. .desc = "Xen Para-virtualized PC",
  102. .init = xen_init_pv,
  103. .max_cpus = 1,
  104. .default_machine_opts = "accel=xen",
  105. };
  106. static void xenpv_machine_init(void)
  107. {
  108. qemu_register_machine(&xenpv_machine);
  109. }
  110. machine_init(xenpv_machine_init);