blob: dcaf2a01a321241f66712930d9fe361435f585cd [file] [log] [blame]
aliguorie37630c2009-04-22 15:19:10 +00001/*
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 Maydell21cbfe52016-01-26 18:17:06 +000025#include "qemu/osdep.h"
Alistair Francis47d17c02018-02-03 09:43:13 +010026#include "qemu/error-report.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010027#include "hw/hw.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010028#include "hw/boards.h"
Paul Durrant2d0ed5e2019-01-08 14:48:46 +000029#include "hw/xen/xen-legacy-backend.h"
Paul Durrant108f7bb2019-01-08 14:48:47 +000030#include "hw/xen/xen-bus.h"
Markus Armbruster4be74632014-10-07 13:59:18 +020031#include "sysemu/block-backend.h"
aliguorie37630c2009-04-22 15:19:10 +000032
Marcel Apfelbaum3ef96222014-05-07 17:42:57 +030033static void xen_init_pv(MachineState *machine)
aliguorie37630c2009-04-22 15:19:10 +000034{
Gerd Hoffmann751c6a12009-07-22 16:42:57 +020035 DriveInfo *dinfo;
36 int i;
aliguorie37630c2009-04-22 15:19:10 +000037
aliguorid94f9482009-04-22 15:19:15 +000038 /* Initialize backend core & drivers */
39 if (xen_be_init() != 0) {
Alistair Francis47d17c02018-02-03 09:43:13 +010040 error_report("%s: xen backend core setup failed", __func__);
aliguorid94f9482009-04-22 15:19:15 +000041 exit(1);
42 }
aliguori9306acb2009-04-22 15:19:44 +000043
44 switch (xen_mode) {
45 case XEN_ATTACH:
Anthony PERARD1077bca2018-09-14 12:18:30 +010046 /* nothing to do, libxl handles everything */
aliguori9306acb2009-04-22 15:19:44 +000047 break;
aliguori9306acb2009-04-22 15:19:44 +000048 case XEN_EMULATE:
Alistair Francis47d17c02018-02-03 09:43:13 +010049 error_report("xen emulation not implemented (yet)");
aliguori9306acb2009-04-22 15:19:44 +000050 exit(1);
51 break;
Ian Campbell64a7ad62016-01-15 13:23:44 +000052 default:
Alistair Francis47d17c02018-02-03 09:43:13 +010053 error_report("unhandled xen_mode %d", xen_mode);
Ian Campbell64a7ad62016-01-15 13:23:44 +000054 exit(1);
55 break;
aliguori9306acb2009-04-22 15:19:44 +000056 }
57
Juergen Gross0e39bb02016-08-02 08:32:32 +020058 xen_be_register_common();
aliguorie7151f82009-04-22 15:19:25 +000059 xen_be_register("vfb", &xen_framebuffer_ops);
aliguorie613b062009-04-22 15:19:35 +000060 xen_be_register("qnic", &xen_netdev_ops);
aliguorie7151f82009-04-22 15:19:25 +000061
aliguori94909d92009-04-22 15:19:53 +000062 /* configure framebuffer */
63 if (xenfb_enabled) {
64 xen_config_dev_vfb(0, "vnc");
65 xen_config_dev_vkbd(0);
66 }
67
aliguori2c8b24a2009-04-22 15:19:39 +000068 /* configure disks */
69 for (i = 0; i < 16; i++) {
Gerd Hoffmann751c6a12009-07-22 16:42:57 +020070 dinfo = drive_get(IF_XEN, 0, i);
71 if (!dinfo)
aliguori2c8b24a2009-04-22 15:19:39 +000072 continue;
Gerd Hoffmann751c6a12009-07-22 16:42:57 +020073 xen_config_dev_blk(dinfo);
aliguori2c8b24a2009-04-22 15:19:39 +000074 }
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 Durrant108f7bb2019-01-08 14:48:47 +000083 xen_bus_init();
84
aliguori2c8b24a2009-04-22 15:19:39 +000085 /* config cleanup hook */
Anthony Liguori28695482010-03-21 14:13:02 -050086 atexit(xen_config_cleanup);
aliguorie37630c2009-04-22 15:19:10 +000087}
88
Eduardo Habkoste264d292015-09-04 15:37:08 -030089static void xenpv_machine_init(MachineClass *mc)
Anthony Liguorif80f9ec2009-05-20 18:38:09 -050090{
Eduardo Habkoste264d292015-09-04 15:37:08 -030091 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 Liguorif80f9ec2009-05-20 18:38:09 -050095}
96
Eduardo Habkoste264d292015-09-04 15:37:08 -030097DEFINE_MACHINE("xenpv", xenpv_machine_init)