1 /** @file 2 3 Virtio Block Device specific type and macro definitions corresponding to the 4 virtio-0.9.5 specification. 5 6 Copyright (C) 2012, Red Hat, Inc. 7 8 This program and the accompanying materials are licensed and made available 9 under the terms and conditions of the BSD License which accompanies this 10 distribution. The full text of the license may be found at 11 http://opensource.org/licenses/bsd-license.php 12 13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT 14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 16 **/ 17 18 #ifndef _VIRTIO_BLK_H_ 19 #define _VIRTIO_BLK_H_ 20 21 #include <IndustryStandard/Virtio.h> 22 23 24 // 25 // virtio-0.9.5, Appendix D: Block Device 26 // 27 #pragma pack(1) 28 typedef struct { 29 UINT8 PhysicalBlockExp; // # of logical blocks per physical block (log2) 30 UINT8 AlignmentOffset; // offset of first aligned logical block 31 UINT16 MinIoSize; // suggested minimum I/O size in blocks 32 UINT32 OptIoSize; // optimal (suggested maximum) I/O size in blocks 33 } VIRTIO_BLK_TOPOLOGY; 34 35 typedef struct { 36 UINT64 Capacity; 37 UINT32 SizeMax; 38 UINT32 SegMax; 39 UINT16 Cylinders; 40 UINT8 Heads; 41 UINT8 Sectors; 42 UINT32 BlkSize; 43 VIRTIO_BLK_TOPOLOGY Topology; 44 } VIRTIO_BLK_CONFIG; 45 #pragma pack() 46 47 #define OFFSET_OF_VBLK(Field) OFFSET_OF (VIRTIO_BLK_CONFIG, Field) 48 #define SIZE_OF_VBLK(Field) (sizeof ((VIRTIO_BLK_CONFIG *) 0)->Field) 49 50 #define VIRTIO_BLK_F_BARRIER BIT0 51 #define VIRTIO_BLK_F_SIZE_MAX BIT1 52 #define VIRTIO_BLK_F_SEG_MAX BIT2 53 #define VIRTIO_BLK_F_GEOMETRY BIT4 54 #define VIRTIO_BLK_F_RO BIT5 55 #define VIRTIO_BLK_F_BLK_SIZE BIT6 // treated as "logical block size" in 56 // practice; actual host side 57 // implementation negotiates "optimal" 58 // block size separately, via 59 // VIRTIO_BLK_F_TOPOLOGY 60 #define VIRTIO_BLK_F_SCSI BIT7 61 #define VIRTIO_BLK_F_FLUSH BIT9 // identical to "write cache enabled" 62 #define VIRTIO_BLK_F_TOPOLOGY BIT10 // information on optimal I/O alignment 63 64 // 65 // We keep the status byte separate from the rest of the virtio-blk request 66 // header. See description of historical scattering at the end of Appendix D: 67 // we're going to put the status byte in a separate VRING_DESC. 68 // 69 #pragma pack(1) 70 typedef struct { 71 UINT32 Type; 72 UINT32 IoPrio; 73 UINT64 Sector; 74 } VIRTIO_BLK_REQ; 75 #pragma pack() 76 77 #define VIRTIO_BLK_T_IN 0x00000000 78 #define VIRTIO_BLK_T_OUT 0x00000001 79 #define VIRTIO_BLK_T_SCSI_CMD 0x00000002 80 #define VIRTIO_BLK_T_SCSI_CMD_OUT 0x00000003 81 #define VIRTIO_BLK_T_FLUSH 0x00000004 82 #define VIRTIO_BLK_T_FLUSH_OUT 0x00000005 83 #define VIRTIO_BLK_T_BARRIER BIT31 84 85 #define VIRTIO_BLK_S_OK 0x00 86 #define VIRTIO_BLK_S_IOERR 0x01 87 #define VIRTIO_BLK_S_UNSUPP 0x02 88 89 #endif // _VIRTIO_BLK_H_ 90