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 23 #include <public/io/ring.h> 24 #include <public/io/blkif.h> 25 #include <public/io/protocols.h> 26 27 /* Not a real protocol. Used to generate ring structs which contain 28 * the elements common to all protocols only. This way we get a 29 * compiler-checkable way to use common struct elements, so we can 30 * avoid using switch(protocol) in a number of places. */ 31 32 /* i386 protocol version */ 33 34 #pragma pack(4) 35 36 struct blkif_x86_32_request { 37 uint8_t operation; /* BLKIF_OP_??? */ 38 uint8_t nr_segments; /* number of segments */ 39 blkif_vdev_t handle; /* only for read/write requests */ 40 uint64_t id; /* private guest value, echoed in resp */ 41 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 42 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 43 }; 44 struct blkif_x86_32_response { 45 uint64_t id; /* copied from request */ 46 uint8_t operation; /* copied from request */ 47 int16_t status; /* BLKIF_RSP_??? */ 48 }; 49 typedef struct blkif_x86_32_request blkif_x86_32_request_t; 50 typedef struct blkif_x86_32_response blkif_x86_32_response_t; 51 52 #pragma pack() 53 54 /* x86_64 protocol version */ 55 struct blkif_x86_64_request { 56 uint8_t operation; /* BLKIF_OP_??? */ 57 uint8_t nr_segments; /* number of segments */ 58 blkif_vdev_t handle; /* only for read/write requests */ 59 #if defined(__GNUC__) 60 uint64_t __attribute__((__aligned__(8))) id; 61 #else 62 uint8_t pad[4]; 63 uint64_t id; 64 #endif 65 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 66 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 67 }; 68 struct blkif_x86_64_response { 69 #if defined(__GNUC__) 70 uint64_t __attribute__((__aligned__(8))) id; 71 #else 72 uint64_t id; 73 #endif 74 uint8_t operation; /* copied from request */ 75 int16_t status; /* BLKIF_RSP_??? */ 76 }; 77 typedef struct blkif_x86_64_request blkif_x86_64_request_t; 78 typedef struct blkif_x86_64_response blkif_x86_64_response_t; 79 80 DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response); 81 DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response); 82 83 enum blkif_protocol { 84 BLKIF_PROTOCOL_NATIVE = 1, 85 BLKIF_PROTOCOL_X86_32 = 2, 86 BLKIF_PROTOCOL_X86_64 = 3, 87 }; 88 89 #define BLKIF_RING_SIZE \ 90 __RING_SIZE((blkif_sring_t *)NULL, PAGESIZE) 91 #define BLKIF_X86_32_RING_SIZE \ 92 __RING_SIZE((blkif_x86_32_sring_t *)NULL, PAGESIZE) 93 #define BLKIF_X86_64_RING_SIZE \ 94 __RING_SIZE((blkif_x86_64_sring_t *)NULL, PAGESIZE) 95 96 #endif /* __XEN_BLKIF_H__ */ 97