root / hw / s390-virtio.c @ 3d53f5c3
History | View | Annotate | Download (6.5 kB)
1 | 8cb310e1 | Alexander Graf | /*
|
---|---|---|---|
2 | 8cb310e1 | Alexander Graf | * QEMU S390 virtio target
|
3 | 8cb310e1 | Alexander Graf | *
|
4 | 8cb310e1 | Alexander Graf | * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
|
5 | 8cb310e1 | Alexander Graf | *
|
6 | 8cb310e1 | Alexander Graf | * This library is free software; you can redistribute it and/or
|
7 | 8cb310e1 | Alexander Graf | * modify it under the terms of the GNU Lesser General Public
|
8 | 8cb310e1 | Alexander Graf | * License as published by the Free Software Foundation; either
|
9 | 8cb310e1 | Alexander Graf | * version 2 of the License, or (at your option) any later version.
|
10 | 8cb310e1 | Alexander Graf | *
|
11 | 8cb310e1 | Alexander Graf | * This library is distributed in the hope that it will be useful,
|
12 | 8cb310e1 | Alexander Graf | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 8cb310e1 | Alexander Graf | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 8cb310e1 | Alexander Graf | * Lesser General Public License for more details.
|
15 | 8cb310e1 | Alexander Graf | *
|
16 | 8cb310e1 | Alexander Graf | * You should have received a copy of the GNU Lesser General Public
|
17 | 8cb310e1 | Alexander Graf | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | 8cb310e1 | Alexander Graf | */
|
19 | 8cb310e1 | Alexander Graf | |
20 | 8cb310e1 | Alexander Graf | #include "hw.h" |
21 | 8cb310e1 | Alexander Graf | #include "block.h" |
22 | 8cb310e1 | Alexander Graf | #include "sysemu.h" |
23 | 8cb310e1 | Alexander Graf | #include "net.h" |
24 | 8cb310e1 | Alexander Graf | #include "boards.h" |
25 | 8cb310e1 | Alexander Graf | #include "monitor.h" |
26 | 8cb310e1 | Alexander Graf | #include "loader.h" |
27 | 8cb310e1 | Alexander Graf | #include "elf.h" |
28 | 8cb310e1 | Alexander Graf | #include "hw/virtio.h" |
29 | 8cb310e1 | Alexander Graf | #include "hw/sysbus.h" |
30 | 8cb310e1 | Alexander Graf | #include "kvm.h" |
31 | 8cb310e1 | Alexander Graf | |
32 | 8cb310e1 | Alexander Graf | #include "hw/s390-virtio-bus.h" |
33 | 8cb310e1 | Alexander Graf | |
34 | 8cb310e1 | Alexander Graf | //#define DEBUG_S390
|
35 | 8cb310e1 | Alexander Graf | |
36 | 8cb310e1 | Alexander Graf | #ifdef DEBUG_S390
|
37 | 8cb310e1 | Alexander Graf | #define dprintf(fmt, ...) \
|
38 | 8cb310e1 | Alexander Graf | do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) |
39 | 8cb310e1 | Alexander Graf | #else
|
40 | 8cb310e1 | Alexander Graf | #define dprintf(fmt, ...) \
|
41 | 8cb310e1 | Alexander Graf | do { } while (0) |
42 | 8cb310e1 | Alexander Graf | #endif
|
43 | 8cb310e1 | Alexander Graf | |
44 | 8cb310e1 | Alexander Graf | #define KVM_S390_VIRTIO_NOTIFY 0 |
45 | 8cb310e1 | Alexander Graf | #define KVM_S390_VIRTIO_RESET 1 |
46 | 8cb310e1 | Alexander Graf | #define KVM_S390_VIRTIO_SET_STATUS 2 |
47 | 8cb310e1 | Alexander Graf | |
48 | 8cb310e1 | Alexander Graf | #define KERN_IMAGE_START 0x010000UL |
49 | 8cb310e1 | Alexander Graf | #define KERN_PARM_AREA 0x010480UL |
50 | 8cb310e1 | Alexander Graf | #define INITRD_START 0x800000UL |
51 | 8cb310e1 | Alexander Graf | #define INITRD_PARM_START 0x010408UL |
52 | 8cb310e1 | Alexander Graf | #define INITRD_PARM_SIZE 0x010410UL |
53 | 8cb310e1 | Alexander Graf | #define PARMFILE_START 0x001000UL |
54 | 8cb310e1 | Alexander Graf | |
55 | 8cb310e1 | Alexander Graf | #define MAX_BLK_DEVS 10 |
56 | 8cb310e1 | Alexander Graf | |
57 | 8cb310e1 | Alexander Graf | static VirtIOS390Bus *s390_bus;
|
58 | 8cb310e1 | Alexander Graf | static CPUState **ipi_states;
|
59 | 8cb310e1 | Alexander Graf | |
60 | 8cb310e1 | Alexander Graf | void irq_info(Monitor *mon);
|
61 | 8cb310e1 | Alexander Graf | void pic_info(Monitor *mon);
|
62 | 8cb310e1 | Alexander Graf | |
63 | 8cb310e1 | Alexander Graf | void irq_info(Monitor *mon)
|
64 | 8cb310e1 | Alexander Graf | { |
65 | 8cb310e1 | Alexander Graf | } |
66 | 8cb310e1 | Alexander Graf | |
67 | 8cb310e1 | Alexander Graf | void pic_info(Monitor *mon)
|
68 | 8cb310e1 | Alexander Graf | { |
69 | 8cb310e1 | Alexander Graf | } |
70 | 8cb310e1 | Alexander Graf | |
71 | 8cb310e1 | Alexander Graf | CPUState *s390_cpu_addr2state(uint16_t cpu_addr) |
72 | 8cb310e1 | Alexander Graf | { |
73 | 8cb310e1 | Alexander Graf | if (cpu_addr >= smp_cpus) {
|
74 | 8cb310e1 | Alexander Graf | return NULL; |
75 | 8cb310e1 | Alexander Graf | } |
76 | 8cb310e1 | Alexander Graf | |
77 | 8cb310e1 | Alexander Graf | return ipi_states[cpu_addr];
|
78 | 8cb310e1 | Alexander Graf | } |
79 | 8cb310e1 | Alexander Graf | |
80 | 8cb310e1 | Alexander Graf | int s390_virtio_hypercall(CPUState *env)
|
81 | 8cb310e1 | Alexander Graf | { |
82 | 8cb310e1 | Alexander Graf | int r = 0, i; |
83 | 8cb310e1 | Alexander Graf | target_ulong mem = env->regs[2];
|
84 | 8cb310e1 | Alexander Graf | |
85 | 8cb310e1 | Alexander Graf | dprintf("KVM hypercall: %ld\n", env->regs[1]); |
86 | 8cb310e1 | Alexander Graf | switch (env->regs[1]) { |
87 | 8cb310e1 | Alexander Graf | case KVM_S390_VIRTIO_NOTIFY:
|
88 | 8cb310e1 | Alexander Graf | if (mem > ram_size) {
|
89 | 8cb310e1 | Alexander Graf | VirtIOS390Device *dev = s390_virtio_bus_find_vring(s390_bus, |
90 | 8cb310e1 | Alexander Graf | mem, &i); |
91 | 8cb310e1 | Alexander Graf | if (dev) {
|
92 | 8cb310e1 | Alexander Graf | virtio_queue_notify(dev->vdev, i); |
93 | 8cb310e1 | Alexander Graf | } else {
|
94 | 8cb310e1 | Alexander Graf | r = -EINVAL; |
95 | 8cb310e1 | Alexander Graf | } |
96 | 8cb310e1 | Alexander Graf | } else {
|
97 | 8cb310e1 | Alexander Graf | /* Early printk */
|
98 | 8cb310e1 | Alexander Graf | } |
99 | 8cb310e1 | Alexander Graf | break;
|
100 | 8cb310e1 | Alexander Graf | case KVM_S390_VIRTIO_RESET:
|
101 | 8cb310e1 | Alexander Graf | { |
102 | baf0b55a | Alexander Graf | VirtIOS390Device *dev; |
103 | baf0b55a | Alexander Graf | |
104 | baf0b55a | Alexander Graf | dev = s390_virtio_bus_find_mem(s390_bus, mem); |
105 | baf0b55a | Alexander Graf | virtio_reset(dev->vdev); |
106 | baf0b55a | Alexander Graf | s390_virtio_device_sync(dev); |
107 | 8cb310e1 | Alexander Graf | break;
|
108 | 8cb310e1 | Alexander Graf | } |
109 | 8cb310e1 | Alexander Graf | case KVM_S390_VIRTIO_SET_STATUS:
|
110 | 8cb310e1 | Alexander Graf | { |
111 | 8cb310e1 | Alexander Graf | VirtIOS390Device *dev; |
112 | 8cb310e1 | Alexander Graf | |
113 | 8cb310e1 | Alexander Graf | dev = s390_virtio_bus_find_mem(s390_bus, mem); |
114 | 8cb310e1 | Alexander Graf | if (dev) {
|
115 | 8cb310e1 | Alexander Graf | s390_virtio_device_update_status(dev); |
116 | 8cb310e1 | Alexander Graf | } else {
|
117 | 8cb310e1 | Alexander Graf | r = -EINVAL; |
118 | 8cb310e1 | Alexander Graf | } |
119 | 8cb310e1 | Alexander Graf | break;
|
120 | 8cb310e1 | Alexander Graf | } |
121 | 8cb310e1 | Alexander Graf | default:
|
122 | 8cb310e1 | Alexander Graf | r = -EINVAL; |
123 | 8cb310e1 | Alexander Graf | break;
|
124 | 8cb310e1 | Alexander Graf | } |
125 | 8cb310e1 | Alexander Graf | |
126 | 8cb310e1 | Alexander Graf | env->regs[2] = r;
|
127 | 8cb310e1 | Alexander Graf | return 0; |
128 | 8cb310e1 | Alexander Graf | } |
129 | 8cb310e1 | Alexander Graf | |
130 | 8cb310e1 | Alexander Graf | /* PC hardware initialisation */
|
131 | 8cb310e1 | Alexander Graf | static void s390_init(ram_addr_t ram_size, |
132 | 8cb310e1 | Alexander Graf | const char *boot_device, |
133 | 8cb310e1 | Alexander Graf | const char *kernel_filename, |
134 | 8cb310e1 | Alexander Graf | const char *kernel_cmdline, |
135 | 8cb310e1 | Alexander Graf | const char *initrd_filename, |
136 | 8cb310e1 | Alexander Graf | const char *cpu_model) |
137 | 8cb310e1 | Alexander Graf | { |
138 | 8cb310e1 | Alexander Graf | CPUState *env = NULL;
|
139 | 8cb310e1 | Alexander Graf | ram_addr_t ram_addr; |
140 | 8cb310e1 | Alexander Graf | ram_addr_t kernel_size = 0;
|
141 | 8cb310e1 | Alexander Graf | ram_addr_t initrd_offset; |
142 | 8cb310e1 | Alexander Graf | ram_addr_t initrd_size = 0;
|
143 | 8cb310e1 | Alexander Graf | int i;
|
144 | 8cb310e1 | Alexander Graf | |
145 | e249651c | Alexander Graf | /* XXX we only work on KVM for now */
|
146 | e249651c | Alexander Graf | |
147 | e249651c | Alexander Graf | if (!kvm_enabled()) {
|
148 | e249651c | Alexander Graf | fprintf(stderr, "The S390 target only works with KVM enabled\n");
|
149 | e249651c | Alexander Graf | exit(1);
|
150 | e249651c | Alexander Graf | } |
151 | e249651c | Alexander Graf | |
152 | 8cb310e1 | Alexander Graf | /* get a BUS */
|
153 | 8cb310e1 | Alexander Graf | s390_bus = s390_virtio_bus_init(&ram_size); |
154 | 8cb310e1 | Alexander Graf | |
155 | 8cb310e1 | Alexander Graf | /* allocate RAM */
|
156 | 8cb310e1 | Alexander Graf | ram_addr = qemu_ram_alloc(ram_size); |
157 | 8cb310e1 | Alexander Graf | cpu_register_physical_memory(0, ram_size, ram_addr);
|
158 | 8cb310e1 | Alexander Graf | |
159 | 8cb310e1 | Alexander Graf | /* init CPUs */
|
160 | 8cb310e1 | Alexander Graf | if (cpu_model == NULL) { |
161 | 8cb310e1 | Alexander Graf | cpu_model = "host";
|
162 | 8cb310e1 | Alexander Graf | } |
163 | 8cb310e1 | Alexander Graf | |
164 | 8cb310e1 | Alexander Graf | ipi_states = qemu_malloc(sizeof(CPUState *) * smp_cpus);
|
165 | 8cb310e1 | Alexander Graf | |
166 | 8cb310e1 | Alexander Graf | for (i = 0; i < smp_cpus; i++) { |
167 | 8cb310e1 | Alexander Graf | CPUState *tmp_env; |
168 | 8cb310e1 | Alexander Graf | |
169 | 8cb310e1 | Alexander Graf | tmp_env = cpu_init(cpu_model); |
170 | 8cb310e1 | Alexander Graf | if (!env) {
|
171 | 8cb310e1 | Alexander Graf | env = tmp_env; |
172 | 8cb310e1 | Alexander Graf | } |
173 | 8cb310e1 | Alexander Graf | ipi_states[i] = tmp_env; |
174 | 8cb310e1 | Alexander Graf | tmp_env->halted = 1;
|
175 | 8cb310e1 | Alexander Graf | tmp_env->exception_index = EXCP_HLT; |
176 | 8cb310e1 | Alexander Graf | } |
177 | 8cb310e1 | Alexander Graf | |
178 | 8cb310e1 | Alexander Graf | env->halted = 0;
|
179 | 8cb310e1 | Alexander Graf | env->exception_index = 0;
|
180 | 8cb310e1 | Alexander Graf | |
181 | 8cb310e1 | Alexander Graf | if (kernel_filename) {
|
182 | 8cb310e1 | Alexander Graf | kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0));
|
183 | 8cb310e1 | Alexander Graf | |
184 | 8cb310e1 | Alexander Graf | if (lduw_phys(KERN_IMAGE_START) != 0x0dd0) { |
185 | 8cb310e1 | Alexander Graf | fprintf(stderr, "Specified image is not an s390 boot image\n");
|
186 | 8cb310e1 | Alexander Graf | exit(1);
|
187 | 8cb310e1 | Alexander Graf | } |
188 | 8cb310e1 | Alexander Graf | |
189 | 8cb310e1 | Alexander Graf | env->psw.addr = KERN_IMAGE_START; |
190 | 0435d393 | Michael S. Tsirkin | env->psw.mask = 0x0000000180000000ULL;
|
191 | 8cb310e1 | Alexander Graf | } |
192 | 8cb310e1 | Alexander Graf | |
193 | 8cb310e1 | Alexander Graf | if (initrd_filename) {
|
194 | 8cb310e1 | Alexander Graf | initrd_offset = INITRD_START; |
195 | 8cb310e1 | Alexander Graf | while (kernel_size + 0x100000 > initrd_offset) { |
196 | 8cb310e1 | Alexander Graf | initrd_offset += 0x100000;
|
197 | 8cb310e1 | Alexander Graf | } |
198 | 8cb310e1 | Alexander Graf | initrd_size = load_image(initrd_filename, qemu_get_ram_ptr(initrd_offset)); |
199 | 8cb310e1 | Alexander Graf | |
200 | 8cb310e1 | Alexander Graf | stq_phys(INITRD_PARM_START, initrd_offset); |
201 | 8cb310e1 | Alexander Graf | stq_phys(INITRD_PARM_SIZE, initrd_size); |
202 | 8cb310e1 | Alexander Graf | } |
203 | 8cb310e1 | Alexander Graf | |
204 | 8cb310e1 | Alexander Graf | if (kernel_cmdline) {
|
205 | 8cb310e1 | Alexander Graf | cpu_physical_memory_rw(KERN_PARM_AREA, (uint8_t *)kernel_cmdline, |
206 | 8cb310e1 | Alexander Graf | strlen(kernel_cmdline), 1);
|
207 | 8cb310e1 | Alexander Graf | } |
208 | 8cb310e1 | Alexander Graf | |
209 | 8cb310e1 | Alexander Graf | /* Create VirtIO network adapters */
|
210 | 8cb310e1 | Alexander Graf | for(i = 0; i < nb_nics; i++) { |
211 | 8cb310e1 | Alexander Graf | NICInfo *nd = &nd_table[i]; |
212 | 8cb310e1 | Alexander Graf | DeviceState *dev; |
213 | 8cb310e1 | Alexander Graf | |
214 | 8cb310e1 | Alexander Graf | if (!nd->model) {
|
215 | 5a2b3fc5 | Stefan Weil | nd->model = qemu_strdup("virtio");
|
216 | 8cb310e1 | Alexander Graf | } |
217 | 8cb310e1 | Alexander Graf | |
218 | 8cb310e1 | Alexander Graf | if (strcmp(nd->model, "virtio")) { |
219 | 8cb310e1 | Alexander Graf | fprintf(stderr, "S390 only supports VirtIO nics\n");
|
220 | 8cb310e1 | Alexander Graf | exit(1);
|
221 | 8cb310e1 | Alexander Graf | } |
222 | 8cb310e1 | Alexander Graf | |
223 | 8cb310e1 | Alexander Graf | dev = qdev_create((BusState *)s390_bus, "virtio-net-s390");
|
224 | 8cb310e1 | Alexander Graf | qdev_set_nic_properties(dev, nd); |
225 | 8cb310e1 | Alexander Graf | qdev_init_nofail(dev); |
226 | 8cb310e1 | Alexander Graf | } |
227 | 8cb310e1 | Alexander Graf | |
228 | 8cb310e1 | Alexander Graf | /* Create VirtIO disk drives */
|
229 | 8cb310e1 | Alexander Graf | for(i = 0; i < MAX_BLK_DEVS; i++) { |
230 | 8cb310e1 | Alexander Graf | DriveInfo *dinfo; |
231 | 8cb310e1 | Alexander Graf | DeviceState *dev; |
232 | 8cb310e1 | Alexander Graf | |
233 | 8cb310e1 | Alexander Graf | dinfo = drive_get(IF_IDE, 0, i);
|
234 | 8cb310e1 | Alexander Graf | if (!dinfo) {
|
235 | 8cb310e1 | Alexander Graf | continue;
|
236 | 8cb310e1 | Alexander Graf | } |
237 | 8cb310e1 | Alexander Graf | |
238 | 8cb310e1 | Alexander Graf | dev = qdev_create((BusState *)s390_bus, "virtio-blk-s390");
|
239 | 8cb310e1 | Alexander Graf | qdev_prop_set_drive(dev, "drive", dinfo);
|
240 | 8cb310e1 | Alexander Graf | qdev_init_nofail(dev); |
241 | 8cb310e1 | Alexander Graf | } |
242 | 8cb310e1 | Alexander Graf | } |
243 | 8cb310e1 | Alexander Graf | |
244 | 8cb310e1 | Alexander Graf | static QEMUMachine s390_machine = {
|
245 | 8cb310e1 | Alexander Graf | .name = "s390-virtio",
|
246 | 8cb310e1 | Alexander Graf | .alias = "s390",
|
247 | 8cb310e1 | Alexander Graf | .desc = "VirtIO based S390 machine",
|
248 | 8cb310e1 | Alexander Graf | .init = s390_init, |
249 | 986c5f78 | Gerd Hoffmann | .no_serial = 1,
|
250 | 986c5f78 | Gerd Hoffmann | .no_parallel = 1,
|
251 | cf708987 | Michael S. Tsirkin | .use_virtcon = 1,
|
252 | 986c5f78 | Gerd Hoffmann | .no_vga = 1,
|
253 | 8cb310e1 | Alexander Graf | .max_cpus = 255,
|
254 | 8cb310e1 | Alexander Graf | .is_default = 1,
|
255 | 8cb310e1 | Alexander Graf | }; |
256 | 8cb310e1 | Alexander Graf | |
257 | 8cb310e1 | Alexander Graf | static void s390_machine_init(void) |
258 | 8cb310e1 | Alexander Graf | { |
259 | 8cb310e1 | Alexander Graf | qemu_register_machine(&s390_machine); |
260 | 8cb310e1 | Alexander Graf | } |
261 | 8cb310e1 | Alexander Graf | |
262 | 8cb310e1 | Alexander Graf | machine_init(s390_machine_init); |