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