Statistics
| Branch: | Revision:

root / hw / xen_machine_pv.c @ 43ad7e3e

History | View | Annotate | Download (3.5 kB)

1 e37630ca aliguori
/*
2 e37630ca aliguori
 * QEMU Xen PV Machine
3 e37630ca aliguori
 *
4 e37630ca aliguori
 * Copyright (c) 2007 Red Hat
5 e37630ca aliguori
 *
6 e37630ca aliguori
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 e37630ca aliguori
 * of this software and associated documentation files (the "Software"), to deal
8 e37630ca aliguori
 * in the Software without restriction, including without limitation the rights
9 e37630ca aliguori
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 e37630ca aliguori
 * copies of the Software, and to permit persons to whom the Software is
11 e37630ca aliguori
 * furnished to do so, subject to the following conditions:
12 e37630ca aliguori
 *
13 e37630ca aliguori
 * The above copyright notice and this permission notice shall be included in
14 e37630ca aliguori
 * all copies or substantial portions of the Software.
15 e37630ca aliguori
 *
16 e37630ca aliguori
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 e37630ca aliguori
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 e37630ca aliguori
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 e37630ca aliguori
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 e37630ca aliguori
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 e37630ca aliguori
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 e37630ca aliguori
 * THE SOFTWARE.
23 e37630ca aliguori
 */
24 e37630ca aliguori
25 e37630ca aliguori
#include "hw.h"
26 e37630ca aliguori
#include "pc.h"
27 e37630ca aliguori
#include "sysemu.h"
28 e37630ca aliguori
#include "boards.h"
29 d94f9486 aliguori
#include "xen_backend.h"
30 9306acb5 aliguori
#include "xen_domainbuild.h"
31 2446333c Blue Swirl
#include "blockdev.h"
32 e37630ca aliguori
33 c227f099 Anthony Liguori
static void xen_init_pv(ram_addr_t ram_size,
34 e37630ca aliguori
                        const char *boot_device,
35 e37630ca aliguori
                        const char *kernel_filename,
36 e37630ca aliguori
                        const char *kernel_cmdline,
37 e37630ca aliguori
                        const char *initrd_filename,
38 e37630ca aliguori
                        const char *cpu_model)
39 e37630ca aliguori
{
40 e37630ca aliguori
    CPUState *env;
41 751c6a17 Gerd Hoffmann
    DriveInfo *dinfo;
42 751c6a17 Gerd Hoffmann
    int i;
43 e37630ca aliguori
44 e37630ca aliguori
    /* Initialize a dummy CPU */
45 e37630ca aliguori
    if (cpu_model == NULL) {
46 e37630ca aliguori
#ifdef TARGET_X86_64
47 e37630ca aliguori
        cpu_model = "qemu64";
48 e37630ca aliguori
#else
49 e37630ca aliguori
        cpu_model = "qemu32";
50 e37630ca aliguori
#endif
51 e37630ca aliguori
    }
52 e37630ca aliguori
    env = cpu_init(cpu_model);
53 e37630ca aliguori
    env->halted = 1;
54 d94f9486 aliguori
55 d94f9486 aliguori
    /* Initialize backend core & drivers */
56 d94f9486 aliguori
    if (xen_be_init() != 0) {
57 d94f9486 aliguori
        fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
58 d94f9486 aliguori
        exit(1);
59 d94f9486 aliguori
    }
60 9306acb5 aliguori
61 9306acb5 aliguori
    switch (xen_mode) {
62 9306acb5 aliguori
    case XEN_ATTACH:
63 9306acb5 aliguori
        /* nothing to do, xend handles everything */
64 9306acb5 aliguori
        break;
65 9306acb5 aliguori
    case XEN_CREATE:
66 9306acb5 aliguori
        if (xen_domain_build_pv(kernel_filename, initrd_filename,
67 9306acb5 aliguori
                                kernel_cmdline) < 0) {
68 9306acb5 aliguori
            fprintf(stderr, "xen pv domain creation failed\n");
69 9306acb5 aliguori
            exit(1);
70 9306acb5 aliguori
        }
71 9306acb5 aliguori
        break;
72 9306acb5 aliguori
    case XEN_EMULATE:
73 9306acb5 aliguori
        fprintf(stderr, "xen emulation not implemented (yet)\n");
74 9306acb5 aliguori
        exit(1);
75 9306acb5 aliguori
        break;
76 9306acb5 aliguori
    }
77 9306acb5 aliguori
78 e57dd20b aliguori
    xen_be_register("console", &xen_console_ops);
79 e7151f83 aliguori
    xen_be_register("vkbd", &xen_kbdmouse_ops);
80 e7151f83 aliguori
    xen_be_register("vfb", &xen_framebuffer_ops);
81 62d23efa aliguori
    xen_be_register("qdisk", &xen_blkdev_ops);
82 e613b064 aliguori
    xen_be_register("qnic", &xen_netdev_ops);
83 e7151f83 aliguori
84 94909d9f aliguori
    /* configure framebuffer */
85 94909d9f aliguori
    if (xenfb_enabled) {
86 94909d9f aliguori
        xen_config_dev_vfb(0, "vnc");
87 94909d9f aliguori
        xen_config_dev_vkbd(0);
88 94909d9f aliguori
    }
89 94909d9f aliguori
90 2c8b24a3 aliguori
    /* configure disks */
91 2c8b24a3 aliguori
    for (i = 0; i < 16; i++) {
92 751c6a17 Gerd Hoffmann
        dinfo = drive_get(IF_XEN, 0, i);
93 751c6a17 Gerd Hoffmann
        if (!dinfo)
94 2c8b24a3 aliguori
            continue;
95 751c6a17 Gerd Hoffmann
        xen_config_dev_blk(dinfo);
96 2c8b24a3 aliguori
    }
97 2c8b24a3 aliguori
98 2c8b24a3 aliguori
    /* configure nics */
99 2c8b24a3 aliguori
    for (i = 0; i < nb_nics; i++) {
100 2c8b24a3 aliguori
        if (!nd_table[i].model || 0 != strcmp(nd_table[i].model, "xen"))
101 2c8b24a3 aliguori
            continue;
102 2c8b24a3 aliguori
        xen_config_dev_nic(nd_table + i);
103 2c8b24a3 aliguori
    }
104 2c8b24a3 aliguori
105 2c8b24a3 aliguori
    /* config cleanup hook */
106 28695489 Anthony Liguori
    atexit(xen_config_cleanup);
107 2c8b24a3 aliguori
108 e7151f83 aliguori
    /* setup framebuffer */
109 e7151f83 aliguori
    xen_init_display(xen_domid);
110 e37630ca aliguori
}
111 e37630ca aliguori
112 f80f9ec9 Anthony Liguori
static QEMUMachine xenpv_machine = {
113 e37630ca aliguori
    .name = "xenpv",
114 e37630ca aliguori
    .desc = "Xen Para-virtualized PC",
115 e37630ca aliguori
    .init = xen_init_pv,
116 e37630ca aliguori
    .max_cpus = 1,
117 e37630ca aliguori
};
118 f80f9ec9 Anthony Liguori
119 f80f9ec9 Anthony Liguori
static void xenpv_machine_init(void)
120 f80f9ec9 Anthony Liguori
{
121 f80f9ec9 Anthony Liguori
    qemu_register_machine(&xenpv_machine);
122 f80f9ec9 Anthony Liguori
}
123 f80f9ec9 Anthony Liguori
124 f80f9ec9 Anthony Liguori
machine_init(xenpv_machine_init);