xen_blkif.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef __XEN_BLKIF_H__
  2. #define __XEN_BLKIF_H__
  3. #include <xen/io/ring.h>
  4. #include <xen/io/blkif.h>
  5. #include <xen/io/protocols.h>
  6. /* Not a real protocol. Used to generate ring structs which contain
  7. * the elements common to all protocols only. This way we get a
  8. * compiler-checkable way to use common struct elements, so we can
  9. * avoid using switch(protocol) in a number of places. */
  10. struct blkif_common_request {
  11. char dummy;
  12. };
  13. struct blkif_common_response {
  14. char dummy;
  15. };
  16. /* i386 protocol version */
  17. #pragma pack(push, 4)
  18. struct blkif_x86_32_request {
  19. uint8_t operation; /* BLKIF_OP_??? */
  20. uint8_t nr_segments; /* number of segments */
  21. blkif_vdev_t handle; /* only for read/write requests */
  22. uint64_t id; /* private guest value, echoed in resp */
  23. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  24. struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  25. };
  26. struct blkif_x86_32_response {
  27. uint64_t id; /* copied from request */
  28. uint8_t operation; /* copied from request */
  29. int16_t status; /* BLKIF_RSP_??? */
  30. };
  31. typedef struct blkif_x86_32_request blkif_x86_32_request_t;
  32. typedef struct blkif_x86_32_response blkif_x86_32_response_t;
  33. #pragma pack(pop)
  34. /* x86_64 protocol version */
  35. struct blkif_x86_64_request {
  36. uint8_t operation; /* BLKIF_OP_??? */
  37. uint8_t nr_segments; /* number of segments */
  38. blkif_vdev_t handle; /* only for read/write requests */
  39. uint64_t __attribute__((__aligned__(8))) id;
  40. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  41. struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  42. };
  43. struct blkif_x86_64_response {
  44. uint64_t __attribute__((__aligned__(8))) id;
  45. uint8_t operation; /* copied from request */
  46. int16_t status; /* BLKIF_RSP_??? */
  47. };
  48. typedef struct blkif_x86_64_request blkif_x86_64_request_t;
  49. typedef struct blkif_x86_64_response blkif_x86_64_response_t;
  50. DEFINE_RING_TYPES(blkif_common, struct blkif_common_request, struct blkif_common_response);
  51. DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response);
  52. DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response);
  53. union blkif_back_rings {
  54. blkif_back_ring_t native;
  55. blkif_common_back_ring_t common;
  56. blkif_x86_32_back_ring_t x86_32_part;
  57. blkif_x86_64_back_ring_t x86_64_part;
  58. };
  59. typedef union blkif_back_rings blkif_back_rings_t;
  60. enum blkif_protocol {
  61. BLKIF_PROTOCOL_NATIVE = 1,
  62. BLKIF_PROTOCOL_X86_32 = 2,
  63. BLKIF_PROTOCOL_X86_64 = 3,
  64. };
  65. static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_request_t *src)
  66. {
  67. int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
  68. dst->operation = src->operation;
  69. dst->nr_segments = src->nr_segments;
  70. dst->handle = src->handle;
  71. dst->id = src->id;
  72. dst->sector_number = src->sector_number;
  73. if (n > src->nr_segments)
  74. n = src->nr_segments;
  75. for (i = 0; i < n; i++)
  76. dst->seg[i] = src->seg[i];
  77. }
  78. static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_request_t *src)
  79. {
  80. int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
  81. dst->operation = src->operation;
  82. dst->nr_segments = src->nr_segments;
  83. dst->handle = src->handle;
  84. dst->id = src->id;
  85. dst->sector_number = src->sector_number;
  86. if (n > src->nr_segments)
  87. n = src->nr_segments;
  88. for (i = 0; i < n; i++)
  89. dst->seg[i] = src->seg[i];
  90. }
  91. #endif /* __XEN_BLKIF_H__ */