blob: 23ad74caec22c5679fcb3a895249560327d7f0bc [file] [log] [blame]
aliguori6e02c382008-12-04 19:52:44 +00001/*
2 * Virtio Block Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14#ifndef _QEMU_VIRTIO_BLK_H
15#define _QEMU_VIRTIO_BLK_H
16
17#include "virtio.h"
18#include "block.h"
aliguori6e02c382008-12-04 19:52:44 +000019
20/* from Linux's linux/virtio_blk.h */
21
22/* The ID for virtio_block */
23#define VIRTIO_ID_BLOCK 2
24
25/* Feature bits */
26#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
27#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
28#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
29#define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
Christoph Hellwig1063b8b2009-04-27 10:29:14 +020030#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
31#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
32#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
john cooperbf011292009-06-22 14:26:51 -040033#define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */
Christoph Hellwigaa659be2009-09-04 19:02:23 +020034#define VIRTIO_BLK_F_WCACHE 9 /* write cache enabled */
john cooperbf011292009-06-22 14:26:51 -040035
36#define VIRTIO_BLK_ID_LEN 256 /* length of identify u16 array */
37#define VIRTIO_BLK_ID_SN 10 /* start of char * serial# */
38#define VIRTIO_BLK_ID_SN_BYTES 20 /* length in bytes of serial# */
aliguori6e02c382008-12-04 19:52:44 +000039
40struct virtio_blk_config
41{
42 uint64_t capacity;
43 uint32_t size_max;
44 uint32_t seg_max;
45 uint16_t cylinders;
46 uint8_t heads;
47 uint8_t sectors;
john cooperbf011292009-06-22 14:26:51 -040048 uint32_t _blk_size; /* structure pad, currently unused */
49 uint16_t identify[VIRTIO_BLK_ID_LEN];
aliguori6e02c382008-12-04 19:52:44 +000050} __attribute__((packed));
51
52/* These two define direction. */
53#define VIRTIO_BLK_T_IN 0
54#define VIRTIO_BLK_T_OUT 1
55
56/* This bit says it's a scsi command, not an actual read or write. */
57#define VIRTIO_BLK_T_SCSI_CMD 2
58
Christoph Hellwigaa659be2009-09-04 19:02:23 +020059/* Flush the volatile write cache */
60#define VIRTIO_BLK_T_FLUSH 4
61
aliguori6e02c382008-12-04 19:52:44 +000062/* Barrier before this op. */
63#define VIRTIO_BLK_T_BARRIER 0x80000000
64
65/* This is the first element of the read scatter-gather list. */
66struct virtio_blk_outhdr
67{
68 /* VIRTIO_BLK_T* */
69 uint32_t type;
70 /* io priority. */
71 uint32_t ioprio;
72 /* Sector (ie. 512 byte offset) */
73 uint64_t sector;
74};
75
76#define VIRTIO_BLK_S_OK 0
77#define VIRTIO_BLK_S_IOERR 1
78#define VIRTIO_BLK_S_UNSUPP 2
79
Christoph Hellwig8b914082009-04-23 12:58:51 +020080/* This is the last element of the write scatter-gather list */
aliguori6e02c382008-12-04 19:52:44 +000081struct virtio_blk_inhdr
82{
83 unsigned char status;
84};
85
Christoph Hellwig1063b8b2009-04-27 10:29:14 +020086/* SCSI pass-through header */
87struct virtio_scsi_inhdr
88{
89 uint32_t errors;
90 uint32_t data_len;
91 uint32_t sense_len;
92 uint32_t residual;
93};
94
aliguori6e02c382008-12-04 19:52:44 +000095#endif