aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 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 | |
Peter Maydell | 21cbfe5 | 2016-01-26 18:17:06 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Alistair Francis | 47d17c0 | 2018-02-03 09:43:13 +0100 | [diff] [blame] | 26 | #include "qemu/error-report.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 27 | #include "hw/hw.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 28 | #include "hw/boards.h" |
Paul Durrant | 2d0ed5e | 2019-01-08 14:48:46 +0000 | [diff] [blame] | 29 | #include "hw/xen/xen-legacy-backend.h" |
Paul Durrant | 108f7bb | 2019-01-08 14:48:47 +0000 | [diff] [blame] | 30 | #include "hw/xen/xen-bus.h" |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 31 | #include "sysemu/block-backend.h" |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 32 | |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 33 | static void xen_init_pv(MachineState *machine) |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 34 | { |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 35 | DriveInfo *dinfo; |
| 36 | int i; |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 37 | |
aliguori | d94f948 | 2009-04-22 15:19:15 +0000 | [diff] [blame] | 38 | /* Initialize backend core & drivers */ |
| 39 | if (xen_be_init() != 0) { |
Alistair Francis | 47d17c0 | 2018-02-03 09:43:13 +0100 | [diff] [blame] | 40 | error_report("%s: xen backend core setup failed", __func__); |
aliguori | d94f948 | 2009-04-22 15:19:15 +0000 | [diff] [blame] | 41 | exit(1); |
| 42 | } |
aliguori | 9306acb | 2009-04-22 15:19:44 +0000 | [diff] [blame] | 43 | |
| 44 | switch (xen_mode) { |
| 45 | case XEN_ATTACH: |
Anthony PERARD | 1077bca | 2018-09-14 12:18:30 +0100 | [diff] [blame] | 46 | /* nothing to do, libxl handles everything */ |
aliguori | 9306acb | 2009-04-22 15:19:44 +0000 | [diff] [blame] | 47 | break; |
aliguori | 9306acb | 2009-04-22 15:19:44 +0000 | [diff] [blame] | 48 | case XEN_EMULATE: |
Alistair Francis | 47d17c0 | 2018-02-03 09:43:13 +0100 | [diff] [blame] | 49 | error_report("xen emulation not implemented (yet)"); |
aliguori | 9306acb | 2009-04-22 15:19:44 +0000 | [diff] [blame] | 50 | exit(1); |
| 51 | break; |
Ian Campbell | 64a7ad6 | 2016-01-15 13:23:44 +0000 | [diff] [blame] | 52 | default: |
Alistair Francis | 47d17c0 | 2018-02-03 09:43:13 +0100 | [diff] [blame] | 53 | error_report("unhandled xen_mode %d", xen_mode); |
Ian Campbell | 64a7ad6 | 2016-01-15 13:23:44 +0000 | [diff] [blame] | 54 | exit(1); |
| 55 | break; |
aliguori | 9306acb | 2009-04-22 15:19:44 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Juergen Gross | 0e39bb0 | 2016-08-02 08:32:32 +0200 | [diff] [blame] | 58 | xen_be_register_common(); |
aliguori | e7151f8 | 2009-04-22 15:19:25 +0000 | [diff] [blame] | 59 | xen_be_register("vfb", &xen_framebuffer_ops); |
aliguori | e613b06 | 2009-04-22 15:19:35 +0000 | [diff] [blame] | 60 | xen_be_register("qnic", &xen_netdev_ops); |
aliguori | e7151f8 | 2009-04-22 15:19:25 +0000 | [diff] [blame] | 61 | |
aliguori | 94909d9 | 2009-04-22 15:19:53 +0000 | [diff] [blame] | 62 | /* configure framebuffer */ |
| 63 | if (xenfb_enabled) { |
| 64 | xen_config_dev_vfb(0, "vnc"); |
| 65 | xen_config_dev_vkbd(0); |
| 66 | } |
| 67 | |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 68 | /* configure disks */ |
| 69 | for (i = 0; i < 16; i++) { |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 70 | dinfo = drive_get(IF_XEN, 0, i); |
| 71 | if (!dinfo) |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 72 | continue; |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 73 | xen_config_dev_blk(dinfo); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* configure nics */ |
| 77 | for (i = 0; i < nb_nics; i++) { |
| 78 | if (!nd_table[i].model || 0 != strcmp(nd_table[i].model, "xen")) |
| 79 | continue; |
| 80 | xen_config_dev_nic(nd_table + i); |
| 81 | } |
| 82 | |
Paul Durrant | 108f7bb | 2019-01-08 14:48:47 +0000 | [diff] [blame] | 83 | xen_bus_init(); |
| 84 | |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 85 | /* config cleanup hook */ |
Anthony Liguori | 2869548 | 2010-03-21 14:13:02 -0500 | [diff] [blame] | 86 | atexit(xen_config_cleanup); |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 89 | static void xenpv_machine_init(MachineClass *mc) |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 90 | { |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 91 | mc->desc = "Xen Para-virtualized PC"; |
| 92 | mc->init = xen_init_pv; |
| 93 | mc->max_cpus = 1; |
| 94 | mc->default_machine_opts = "accel=xen"; |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 97 | DEFINE_MACHINE("xenpv", xenpv_machine_init) |