Fix typo that leads to out of bounds array access on big endian systems
[qemu/mini2440.git] / hw / virtio-blk.h
blob5ef6c36054918f65cf9573d05d750a6aaab1b37a
1 /*
2 * Virtio Block Device
4 * Copyright IBM, Corp. 2007
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef _QEMU_VIRTIO_BLK_H
15 #define _QEMU_VIRTIO_BLK_H
17 #include "virtio.h"
18 #include "block.h"
19 #include "pci.h"
21 /* from Linux's linux/virtio_blk.h */
23 /* The ID for virtio_block */
24 #define VIRTIO_ID_BLOCK 2
26 /* Feature bits */
27 #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
28 #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
29 #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
30 #define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
31 #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
32 #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
33 #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
35 struct virtio_blk_config
37 uint64_t capacity;
38 uint32_t size_max;
39 uint32_t seg_max;
40 uint16_t cylinders;
41 uint8_t heads;
42 uint8_t sectors;
43 } __attribute__((packed));
45 /* These two define direction. */
46 #define VIRTIO_BLK_T_IN 0
47 #define VIRTIO_BLK_T_OUT 1
49 /* This bit says it's a scsi command, not an actual read or write. */
50 #define VIRTIO_BLK_T_SCSI_CMD 2
52 /* Barrier before this op. */
53 #define VIRTIO_BLK_T_BARRIER 0x80000000
55 /* This is the first element of the read scatter-gather list. */
56 struct virtio_blk_outhdr
58 /* VIRTIO_BLK_T* */
59 uint32_t type;
60 /* io priority. */
61 uint32_t ioprio;
62 /* Sector (ie. 512 byte offset) */
63 uint64_t sector;
66 #define VIRTIO_BLK_S_OK 0
67 #define VIRTIO_BLK_S_IOERR 1
68 #define VIRTIO_BLK_S_UNSUPP 2
70 /* This is the last element of the write scatter-gather list */
71 struct virtio_blk_inhdr
73 unsigned char status;
76 /* SCSI pass-through header */
77 struct virtio_scsi_inhdr
79 uint32_t errors;
80 uint32_t data_len;
81 uint32_t sense_len;
82 uint32_t residual;
85 void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs);
87 #endif