virtio-rng: hardware random number generator device
[qemu.git] / hw / s390-virtio-bus.h
1 /*
2 * QEMU S390x VirtIO BUS definitions
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 "virtio-blk.h"
21 #include "virtio-net.h"
22 #include "virtio-rng.h"
23 #include "virtio-serial.h"
24 #include "virtio-scsi.h"
25
26 #define VIRTIO_DEV_OFFS_TYPE 0 /* 8 bits */
27 #define VIRTIO_DEV_OFFS_NUM_VQ 1 /* 8 bits */
28 #define VIRTIO_DEV_OFFS_FEATURE_LEN 2 /* 8 bits */
29 #define VIRTIO_DEV_OFFS_CONFIG_LEN 3 /* 8 bits */
30 #define VIRTIO_DEV_OFFS_STATUS 4 /* 8 bits */
31 #define VIRTIO_DEV_OFFS_CONFIG 5 /* dynamic */
32
33 #define VIRTIO_VQCONFIG_OFFS_TOKEN 0 /* 64 bits */
34 #define VIRTIO_VQCONFIG_OFFS_ADDRESS 8 /* 64 bits */
35 #define VIRTIO_VQCONFIG_OFFS_NUM 16 /* 16 bits */
36 #define VIRTIO_VQCONFIG_LEN 24
37
38 #define VIRTIO_RING_LEN (TARGET_PAGE_SIZE * 3)
39 #define VIRTIO_VRING_AVAIL_IDX_OFFS 2
40 #define VIRTIO_VRING_USED_IDX_OFFS 2
41 #define S390_DEVICE_PAGES 512
42
43 #define VIRTIO_PARAM_MASK 0xff
44 #define VIRTIO_PARAM_VRING_INTERRUPT 0x0
45 #define VIRTIO_PARAM_CONFIG_CHANGED 0x1
46 #define VIRTIO_PARAM_DEV_ADD 0x2
47
48 #define TYPE_VIRTIO_S390_DEVICE "virtio-s390-device"
49 #define VIRTIO_S390_DEVICE(obj) \
50 OBJECT_CHECK(VirtIOS390Device, (obj), TYPE_VIRTIO_S390_DEVICE)
51 #define VIRTIO_S390_DEVICE_CLASS(klass) \
52 OBJECT_CLASS_CHECK(VirtIOS390DeviceClass, (klass), TYPE_VIRTIO_S390_DEVICE)
53 #define VIRTIO_S390_DEVICE_GET_CLASS(obj) \
54 OBJECT_GET_CLASS(VirtIOS390DeviceClass, (obj), TYPE_VIRTIO_S390_DEVICE)
55
56 #define TYPE_S390_VIRTIO_BUS "s390-virtio-bus"
57 #define S390_VIRTIO_BUS(obj) \
58 OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS)
59
60 typedef struct VirtIOS390Device VirtIOS390Device;
61
62 typedef struct VirtIOS390DeviceClass {
63 DeviceClass qdev;
64 int (*init)(VirtIOS390Device *dev);
65 } VirtIOS390DeviceClass;
66
67 struct VirtIOS390Device {
68 DeviceState qdev;
69 ram_addr_t dev_offs;
70 ram_addr_t feat_offs;
71 uint8_t feat_len;
72 VirtIODevice *vdev;
73 VirtIOBlkConf blk;
74 NICConf nic;
75 uint32_t host_features;
76 virtio_serial_conf serial;
77 virtio_net_conf net;
78 VirtIOSCSIConf scsi;
79 VirtIORNGConf rng;
80 };
81
82 typedef struct VirtIOS390Bus {
83 BusState bus;
84
85 VirtIOS390Device *console;
86 ram_addr_t dev_page;
87 ram_addr_t dev_offs;
88 ram_addr_t next_ring;
89 } VirtIOS390Bus;
90
91
92 void s390_virtio_device_update_status(VirtIOS390Device *dev);
93
94 VirtIOS390Device *s390_virtio_bus_console(VirtIOS390Bus *bus);
95 VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size);
96
97 VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
98 ram_addr_t mem, int *vq_num);
99 VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem);
100 void s390_virtio_device_sync(VirtIOS390Device *dev);
101 void s390_virtio_reset_idx(VirtIOS390Device *dev);
102