xref: /openbsd/sys/dev/pv/vioblkreg.h (revision 73471bf0)
1 /*	$OpenBSD: vioblkreg.h,v 1.4 2019/03/24 18:22:36 sf Exp $	*/
2 
3 /*
4  * Copyright (c) 2012 Stefan Fritsch.
5  * Copyright (c) 2010 Minoura Makoto.
6  * Copyright (c) 1998, 2001 Manuel Bouyer.
7  * All rights reserved.
8  *
9  * This code is based in part on the NetBSD ld_virtio driver and the
10  * OpenBSD wd driver.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *	notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *	notice, this list of conditions and the following disclaimer in the
19  *	documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /* Configuration registers */
34 #define VIRTIO_BLK_CONFIG_CAPACITY	0 /* 64bit */
35 #define VIRTIO_BLK_CONFIG_SIZE_MAX	8 /* 32bit */
36 #define VIRTIO_BLK_CONFIG_SEG_MAX	12 /* 32bit */
37 #define VIRTIO_BLK_CONFIG_GEOMETRY_C	16 /* 16bit */
38 #define VIRTIO_BLK_CONFIG_GEOMETRY_H	18 /* 8bit */
39 #define VIRTIO_BLK_CONFIG_GEOMETRY_S	19 /* 8bit */
40 #define VIRTIO_BLK_CONFIG_BLK_SIZE	20 /* 32bit */
41 
42 /* Feature bits */
43 #define VIRTIO_BLK_F_BARRIER		(1ULL<<0)
44 #define VIRTIO_BLK_F_SIZE_MAX		(1ULL<<1)
45 #define VIRTIO_BLK_F_SEG_MAX		(1ULL<<2)
46 #define VIRTIO_BLK_F_GEOMETRY		(1ULL<<4)
47 #define VIRTIO_BLK_F_RO			(1ULL<<5)
48 #define VIRTIO_BLK_F_BLK_SIZE		(1ULL<<6)
49 #define VIRTIO_BLK_F_SCSI		(1ULL<<7)
50 #define VIRTIO_BLK_F_FLUSH		(1ULL<<9)
51 #define VIRTIO_BLK_F_TOPOLOGY		(1ULL<<10)
52 #define VIRTIO_BLK_F_CONFIG_WCE		(1ULL<<11)
53 #define VIRTIO_BLK_F_DISCARD		(1ULL<<12)
54 #define VIRTIO_BLK_F_WRITE_ZEROES	(1ULL<<13)
55 
56 /* Command */
57 #define VIRTIO_BLK_T_IN			0
58 #define VIRTIO_BLK_T_OUT		1
59 #define VIRTIO_BLK_T_SCSI_CMD		2
60 #define VIRTIO_BLK_T_SCSI_CMD_OUT	3
61 #define VIRTIO_BLK_T_FLUSH		4
62 #define VIRTIO_BLK_T_FLUSH_OUT		5
63 #define VIRTIO_BLK_T_GET_ID		8 /* from qemu, not in spec, yet */
64 #define VIRTIO_BLK_T_BARRIER		0x80000000
65 
66 /* Status */
67 #define VIRTIO_BLK_S_OK		0
68 #define VIRTIO_BLK_S_IOERR	1
69 #define VIRTIO_BLK_S_UNSUPP	2
70 
71 #define VIRTIO_BLK_ID_BYTES	20 /* length of serial number */
72 
73 /* Request header structure */
74 struct virtio_blk_req_hdr {
75 	uint32_t	type;	/* VIRTIO_BLK_T_* */
76 	uint32_t	ioprio;
77 	uint64_t	sector;
78 } __packed;
79 /* 512*virtio_blk_req_hdr.sector byte payload and 1 byte status follows */
80 
81 #define VIRTIO_BLK_SECTOR_SIZE	512
82