virtio-blk.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "block.h"
  17. #include "pci.h"
  18. /* from Linux's linux/virtio_blk.h */
  19. /* The ID for virtio_block */
  20. #define VIRTIO_ID_BLOCK 2
  21. /* Feature bits */
  22. #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
  23. #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
  24. #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
  25. #define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
  26. struct virtio_blk_config
  27. {
  28. uint64_t capacity;
  29. uint32_t size_max;
  30. uint32_t seg_max;
  31. uint16_t cylinders;
  32. uint8_t heads;
  33. uint8_t sectors;
  34. } __attribute__((packed));
  35. /* These two define direction. */
  36. #define VIRTIO_BLK_T_IN 0
  37. #define VIRTIO_BLK_T_OUT 1
  38. /* This bit says it's a scsi command, not an actual read or write. */
  39. #define VIRTIO_BLK_T_SCSI_CMD 2
  40. /* Barrier before this op. */
  41. #define VIRTIO_BLK_T_BARRIER 0x80000000
  42. /* This is the first element of the read scatter-gather list. */
  43. struct virtio_blk_outhdr
  44. {
  45. /* VIRTIO_BLK_T* */
  46. uint32_t type;
  47. /* io priority. */
  48. uint32_t ioprio;
  49. /* Sector (ie. 512 byte offset) */
  50. uint64_t sector;
  51. };
  52. #define VIRTIO_BLK_S_OK 0
  53. #define VIRTIO_BLK_S_IOERR 1
  54. #define VIRTIO_BLK_S_UNSUPP 2
  55. /* This is the first element of the write scatter-gather list */
  56. struct virtio_blk_inhdr
  57. {
  58. unsigned char status;
  59. };
  60. void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs);
  61. #endif