1 #ifndef __XEN_BLKIF_H__
2 #define __XEN_BLKIF_H__
4 #include <xen/io/ring.h>
5 #include <xen/io/blkif.h>
6 #include <xen/io/protocols.h>
9 * Not a real protocol. Used to generate ring structs which contain
10 * the elements common to all protocols only. This way we get a
11 * compiler-checkable way to use common struct elements, so we can
12 * avoid using switch(protocol) in a number of places.
14 struct blkif_common_request
{
17 struct blkif_common_response
{
21 /* i386 protocol version */
23 struct blkif_x86_32_request
{
24 uint8_t operation
; /* BLKIF_OP_??? */
25 uint8_t nr_segments
; /* number of segments */
26 blkif_vdev_t handle
; /* only for read/write requests */
27 uint64_t id
; /* private guest value, echoed in resp */
28 blkif_sector_t sector_number
; /* start sector idx on disk (r/w only) */
29 struct blkif_request_segment seg
[BLKIF_MAX_SEGMENTS_PER_REQUEST
];
31 struct blkif_x86_32_response
{
32 uint64_t id
; /* copied from request */
33 uint8_t operation
; /* copied from request */
34 int16_t status
; /* BLKIF_RSP_??? */
36 typedef struct blkif_x86_32_request blkif_x86_32_request_t
;
37 typedef struct blkif_x86_32_response blkif_x86_32_response_t
;
40 /* x86_64 protocol version */
41 struct blkif_x86_64_request
{
42 uint8_t operation
; /* BLKIF_OP_??? */
43 uint8_t nr_segments
; /* number of segments */
44 blkif_vdev_t handle
; /* only for read/write requests */
45 uint64_t __attribute__((__aligned__(8))) id
;
46 blkif_sector_t sector_number
; /* start sector idx on disk (r/w only) */
47 struct blkif_request_segment seg
[BLKIF_MAX_SEGMENTS_PER_REQUEST
];
49 struct blkif_x86_64_response
{
50 uint64_t __attribute__((__aligned__(8))) id
;
51 uint8_t operation
; /* copied from request */
52 int16_t status
; /* BLKIF_RSP_??? */
54 typedef struct blkif_x86_64_request blkif_x86_64_request_t
;
55 typedef struct blkif_x86_64_response blkif_x86_64_response_t
;
57 DEFINE_RING_TYPES(blkif_common
, struct blkif_common_request
,
58 struct blkif_common_response
);
59 DEFINE_RING_TYPES(blkif_x86_32
, struct blkif_x86_32_request
,
60 struct blkif_x86_32_response
);
61 DEFINE_RING_TYPES(blkif_x86_64
, struct blkif_x86_64_request
,
62 struct blkif_x86_64_response
);
64 union blkif_back_rings
{
65 blkif_back_ring_t native
;
66 blkif_common_back_ring_t common
;
67 blkif_x86_32_back_ring_t x86_32_part
;
68 blkif_x86_64_back_ring_t x86_64_part
;
70 typedef union blkif_back_rings blkif_back_rings_t
;
73 BLKIF_PROTOCOL_NATIVE
= 1,
74 BLKIF_PROTOCOL_X86_32
= 2,
75 BLKIF_PROTOCOL_X86_64
= 3,
78 static inline void blkif_get_x86_32_req(blkif_request_t
*dst
,
79 blkif_x86_32_request_t
*src
)
81 int i
, n
= BLKIF_MAX_SEGMENTS_PER_REQUEST
;
83 dst
->operation
= src
->operation
;
84 dst
->nr_segments
= src
->nr_segments
;
85 dst
->handle
= src
->handle
;
87 dst
->sector_number
= src
->sector_number
;
88 /* Prevent the compiler from using src->... instead. */
90 if (dst
->operation
== BLKIF_OP_DISCARD
) {
91 struct blkif_request_discard
*s
= (void *)src
;
92 struct blkif_request_discard
*d
= (void *)dst
;
93 d
->nr_sectors
= s
->nr_sectors
;
96 if (n
> dst
->nr_segments
) {
99 for (i
= 0; i
< n
; i
++) {
100 dst
->seg
[i
] = src
->seg
[i
];
104 static inline void blkif_get_x86_64_req(blkif_request_t
*dst
,
105 blkif_x86_64_request_t
*src
)
107 int i
, n
= BLKIF_MAX_SEGMENTS_PER_REQUEST
;
109 dst
->operation
= src
->operation
;
110 dst
->nr_segments
= src
->nr_segments
;
111 dst
->handle
= src
->handle
;
113 dst
->sector_number
= src
->sector_number
;
114 /* Prevent the compiler from using src->... instead. */
116 if (dst
->operation
== BLKIF_OP_DISCARD
) {
117 struct blkif_request_discard
*s
= (void *)src
;
118 struct blkif_request_discard
*d
= (void *)dst
;
119 d
->nr_sectors
= s
->nr_sectors
;
122 if (n
> dst
->nr_segments
) {
123 n
= dst
->nr_segments
;
125 for (i
= 0; i
< n
; i
++) {
126 dst
->seg
[i
] = src
->seg
[i
];
130 #endif /* __XEN_BLKIF_H__ */