2 * QEMU S390 virtio target
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
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.
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.
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/>.
28 #include "hw/virtio.h"
29 #include "hw/virtio-console.h"
30 #include "hw/sysbus.h"
33 #include "hw/s390-virtio-bus.h"
38 #define dprintf(fmt, ...) \
39 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
41 #define dprintf(fmt, ...) \
45 #define KVM_S390_VIRTIO_NOTIFY 0
46 #define KVM_S390_VIRTIO_RESET 1
47 #define KVM_S390_VIRTIO_SET_STATUS 2
49 #define KERN_IMAGE_START 0x010000UL
50 #define KERN_PARM_AREA 0x010480UL
51 #define INITRD_START 0x800000UL
52 #define INITRD_PARM_START 0x010408UL
53 #define INITRD_PARM_SIZE 0x010410UL
54 #define PARMFILE_START 0x001000UL
56 #define MAX_BLK_DEVS 10
58 static VirtIOS390Bus
*s390_bus
;
59 static CPUState
**ipi_states
;
61 void irq_info(Monitor
*mon
);
62 void pic_info(Monitor
*mon
);
64 void irq_info(Monitor
*mon
)
68 void pic_info(Monitor
*mon
)
72 CPUState
*s390_cpu_addr2state(uint16_t cpu_addr
)
74 if (cpu_addr
>= smp_cpus
) {
78 return ipi_states
[cpu_addr
];
81 int s390_virtio_hypercall(CPUState
*env
)
84 target_ulong mem
= env
->regs
[2];
86 dprintf("KVM hypercall: %ld\n", env
->regs
[1]);
87 switch (env
->regs
[1]) {
88 case KVM_S390_VIRTIO_NOTIFY
:
90 VirtIOS390Device
*dev
= s390_virtio_bus_find_vring(s390_bus
,
93 virtio_queue_notify(dev
->vdev
, i
);
101 case KVM_S390_VIRTIO_RESET
:
103 /* Virtio_reset resets the internal addresses, so we'd have to sync
104 them up again. We don't want to reallocate a vring though, so let's
106 /* virtio_reset(dev->vdev); */
109 case KVM_S390_VIRTIO_SET_STATUS
:
111 VirtIOS390Device
*dev
;
113 dev
= s390_virtio_bus_find_mem(s390_bus
, mem
);
115 s390_virtio_device_update_status(dev
);
130 /* PC hardware initialisation */
131 static void s390_init(ram_addr_t ram_size
,
132 const char *boot_device
,
133 const char *kernel_filename
,
134 const char *kernel_cmdline
,
135 const char *initrd_filename
,
136 const char *cpu_model
)
138 CPUState
*env
= NULL
;
140 ram_addr_t kernel_size
= 0;
141 ram_addr_t initrd_offset
;
142 ram_addr_t initrd_size
= 0;
146 s390_bus
= s390_virtio_bus_init(&ram_size
);
149 ram_addr
= qemu_ram_alloc(ram_size
);
150 cpu_register_physical_memory(0, ram_size
, ram_addr
);
153 if (cpu_model
== NULL
) {
157 ipi_states
= qemu_malloc(sizeof(CPUState
*) * smp_cpus
);
159 for (i
= 0; i
< smp_cpus
; i
++) {
162 tmp_env
= cpu_init(cpu_model
);
166 ipi_states
[i
] = tmp_env
;
168 tmp_env
->exception_index
= EXCP_HLT
;
172 env
->exception_index
= 0;
174 if (kernel_filename
) {
175 kernel_size
= load_image(kernel_filename
, qemu_get_ram_ptr(0));
177 if (lduw_phys(KERN_IMAGE_START
) != 0x0dd0) {
178 fprintf(stderr
, "Specified image is not an s390 boot image\n");
182 cpu_synchronize_state(env
);
183 env
->psw
.addr
= KERN_IMAGE_START
;
184 env
->psw
.mask
= 0x0000000180000000UL
;
187 if (initrd_filename
) {
188 initrd_offset
= INITRD_START
;
189 while (kernel_size
+ 0x100000 > initrd_offset
) {
190 initrd_offset
+= 0x100000;
192 initrd_size
= load_image(initrd_filename
, qemu_get_ram_ptr(initrd_offset
));
194 stq_phys(INITRD_PARM_START
, initrd_offset
);
195 stq_phys(INITRD_PARM_SIZE
, initrd_size
);
198 if (kernel_cmdline
) {
199 cpu_physical_memory_rw(KERN_PARM_AREA
, (uint8_t *)kernel_cmdline
,
200 strlen(kernel_cmdline
), 1);
203 /* Create VirtIO console */
204 qdev_init_nofail(qdev_create((BusState
*)s390_bus
, "virtio-console-s390"));
206 /* Create VirtIO network adapters */
207 for(i
= 0; i
< nb_nics
; i
++) {
208 NICInfo
*nd
= &nd_table
[i
];
212 nd
->model
= (char*)"virtio";
215 if (strcmp(nd
->model
, "virtio")) {
216 fprintf(stderr
, "S390 only supports VirtIO nics\n");
220 dev
= qdev_create((BusState
*)s390_bus
, "virtio-net-s390");
221 qdev_set_nic_properties(dev
, nd
);
222 qdev_init_nofail(dev
);
225 /* Create VirtIO disk drives */
226 for(i
= 0; i
< MAX_BLK_DEVS
; i
++) {
230 dinfo
= drive_get(IF_IDE
, 0, i
);
235 dev
= qdev_create((BusState
*)s390_bus
, "virtio-blk-s390");
236 qdev_prop_set_drive(dev
, "drive", dinfo
);
237 qdev_init_nofail(dev
);
241 static QEMUMachine s390_machine
= {
242 .name
= "s390-virtio",
244 .desc
= "VirtIO based S390 machine",
250 static void s390_machine_init(void)
252 qemu_register_machine(&s390_machine
);
255 machine_init(s390_machine_init
);