blkif.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3. * of this software and associated documentation files (the "Software"), to
  4. * deal in the Software without restriction, including without limitation the
  5. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  6. * sell copies of the Software, and to permit persons to whom the Software is
  7. * furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in
  10. * all copies or substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. * DEALINGS IN THE SOFTWARE.
  19. */
  20. #ifndef __XEN_BLKIF_H__
  21. #define __XEN_BLKIF_H__
  22. #include <xen/interface/io/ring.h>
  23. #include <xen/interface/io/blkif.h>
  24. #include <xen/interface/io/protocols.h>
  25. /* Not a real protocol. Used to generate ring structs which contain
  26. * the elements common to all protocols only. This way we get a
  27. * compiler-checkable way to use common struct elements, so we can
  28. * avoid using switch(protocol) in a number of places. */
  29. struct blkif_common_request {
  30. char dummy;
  31. };
  32. struct blkif_common_response {
  33. char dummy;
  34. };
  35. /* i386 protocol version */
  36. #pragma pack(push, 4)
  37. struct blkif_x86_32_request {
  38. uint8_t operation; /* BLKIF_OP_??? */
  39. uint8_t nr_segments; /* number of segments */
  40. blkif_vdev_t handle; /* only for read/write requests */
  41. uint64_t id; /* private guest value, echoed in resp */
  42. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  43. struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  44. };
  45. struct blkif_x86_32_response {
  46. uint64_t id; /* copied from request */
  47. uint8_t operation; /* copied from request */
  48. int16_t status; /* BLKIF_RSP_??? */
  49. };
  50. typedef struct blkif_x86_32_request blkif_x86_32_request_t;
  51. typedef struct blkif_x86_32_response blkif_x86_32_response_t;
  52. #pragma pack(pop)
  53. /* x86_64 protocol version */
  54. struct blkif_x86_64_request {
  55. uint8_t operation; /* BLKIF_OP_??? */
  56. uint8_t nr_segments; /* number of segments */
  57. blkif_vdev_t handle; /* only for read/write requests */
  58. uint64_t __attribute__((__aligned__(8))) id;
  59. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  60. struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  61. };
  62. struct blkif_x86_64_response {
  63. uint64_t __attribute__((__aligned__(8))) id;
  64. uint8_t operation; /* copied from request */
  65. int16_t status; /* BLKIF_RSP_??? */
  66. };
  67. typedef struct blkif_x86_64_request blkif_x86_64_request_t;
  68. typedef struct blkif_x86_64_response blkif_x86_64_response_t;
  69. DEFINE_RING_TYPES(blkif_common, struct blkif_common_request,
  70. struct blkif_common_response);
  71. DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request,
  72. struct blkif_x86_32_response);
  73. DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request,
  74. struct blkif_x86_64_response);
  75. union blkif_back_rings {
  76. struct blkif_back_ring native;
  77. struct blkif_common_back_ring common;
  78. struct blkif_x86_32_back_ring x86_32;
  79. struct blkif_x86_64_back_ring x86_64;
  80. };
  81. enum blkif_protocol {
  82. BLKIF_PROTOCOL_NATIVE = 1,
  83. BLKIF_PROTOCOL_X86_32 = 2,
  84. BLKIF_PROTOCOL_X86_64 = 3,
  85. };
  86. #endif /* __XEN_BLKIF_H__ */