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