virtio-blk.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  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. #ifndef _QEMU_VIRTIO_BLK_H
  14. #define _QEMU_VIRTIO_BLK_H
  15. #include "virtio.h"
  16. #include "hw/block-common.h"
  17. /* from Linux's linux/virtio_blk.h */
  18. /* The ID for virtio_block */
  19. #define VIRTIO_ID_BLOCK 2
  20. /* Feature bits */
  21. #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
  22. #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
  23. #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
  24. #define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
  25. #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
  26. #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
  27. #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
  28. /* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */
  29. #define VIRTIO_BLK_F_WCE 9 /* write cache enabled */
  30. #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
  31. #define VIRTIO_BLK_F_CONFIG_WCE 11 /* write cache configurable */
  32. #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
  33. struct virtio_blk_config
  34. {
  35. uint64_t capacity;
  36. uint32_t size_max;
  37. uint32_t seg_max;
  38. uint16_t cylinders;
  39. uint8_t heads;
  40. uint8_t sectors;
  41. uint32_t blk_size;
  42. uint8_t physical_block_exp;
  43. uint8_t alignment_offset;
  44. uint16_t min_io_size;
  45. uint32_t opt_io_size;
  46. uint8_t wce;
  47. } QEMU_PACKED;
  48. /* These two define direction. */
  49. #define VIRTIO_BLK_T_IN 0
  50. #define VIRTIO_BLK_T_OUT 1
  51. /* This bit says it's a scsi command, not an actual read or write. */
  52. #define VIRTIO_BLK_T_SCSI_CMD 2
  53. /* Flush the volatile write cache */
  54. #define VIRTIO_BLK_T_FLUSH 4
  55. /* return the device ID string */
  56. #define VIRTIO_BLK_T_GET_ID 8
  57. /* Barrier before this op. */
  58. #define VIRTIO_BLK_T_BARRIER 0x80000000
  59. /* This is the first element of the read scatter-gather list. */
  60. struct virtio_blk_outhdr
  61. {
  62. /* VIRTIO_BLK_T* */
  63. uint32_t type;
  64. /* io priority. */
  65. uint32_t ioprio;
  66. /* Sector (ie. 512 byte offset) */
  67. uint64_t sector;
  68. };
  69. #define VIRTIO_BLK_S_OK 0
  70. #define VIRTIO_BLK_S_IOERR 1
  71. #define VIRTIO_BLK_S_UNSUPP 2
  72. /* This is the last element of the write scatter-gather list */
  73. struct virtio_blk_inhdr
  74. {
  75. unsigned char status;
  76. };
  77. /* SCSI pass-through header */
  78. struct virtio_scsi_inhdr
  79. {
  80. uint32_t errors;
  81. uint32_t data_len;
  82. uint32_t sense_len;
  83. uint32_t residual;
  84. };
  85. struct VirtIOBlkConf
  86. {
  87. BlockConf conf;
  88. char *serial;
  89. uint32_t scsi;
  90. uint32_t config_wce;
  91. };
  92. #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
  93. DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
  94. DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)
  95. #endif