]>
Commit | Line | Data |
---|---|---|
2a6a4076 MA |
1 | #ifndef XEN_BLKIF_H |
2 | #define XEN_BLKIF_H | |
62d23efa AL |
3 | |
4 | #include <xen/io/ring.h> | |
5 | #include <xen/io/blkif.h> | |
6 | #include <xen/io/protocols.h> | |
7 | ||
0d8e5894 JG |
8 | /* |
9 | * Not a real protocol. Used to generate ring structs which contain | |
62d23efa AL |
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 | |
0d8e5894 JG |
12 | * avoid using switch(protocol) in a number of places. |
13 | */ | |
62d23efa | 14 | struct blkif_common_request { |
0d8e5894 | 15 | char dummy; |
62d23efa AL |
16 | }; |
17 | struct blkif_common_response { | |
0d8e5894 | 18 | char dummy; |
62d23efa AL |
19 | }; |
20 | ||
21 | /* i386 protocol version */ | |
22 | #pragma pack(push, 4) | |
23 | struct blkif_x86_32_request { | |
0d8e5894 JG |
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]; | |
62d23efa | 30 | }; |
16246018 JG |
31 | struct blkif_x86_32_request_discard { |
32 | uint8_t operation; /* BLKIF_OP_DISCARD */ | |
33 | uint8_t flag; /* nr_segments in request struct */ | |
34 | blkif_vdev_t handle; /* only for read/write requests */ | |
35 | uint64_t id; /* private guest value, echoed in resp */ | |
36 | blkif_sector_t sector_number; /* start sector idx on disk (r/w only) */ | |
37 | uint64_t nr_sectors; /* # of contiguous sectors to discard */ | |
38 | }; | |
62d23efa | 39 | struct blkif_x86_32_response { |
0d8e5894 JG |
40 | uint64_t id; /* copied from request */ |
41 | uint8_t operation; /* copied from request */ | |
42 | int16_t status; /* BLKIF_RSP_??? */ | |
62d23efa AL |
43 | }; |
44 | typedef struct blkif_x86_32_request blkif_x86_32_request_t; | |
45 | typedef struct blkif_x86_32_response blkif_x86_32_response_t; | |
46 | #pragma pack(pop) | |
47 | ||
48 | /* x86_64 protocol version */ | |
49 | struct blkif_x86_64_request { | |
0d8e5894 JG |
50 | uint8_t operation; /* BLKIF_OP_??? */ |
51 | uint8_t nr_segments; /* number of segments */ | |
52 | blkif_vdev_t handle; /* only for read/write requests */ | |
53 | uint64_t __attribute__((__aligned__(8))) id; | |
54 | blkif_sector_t sector_number; /* start sector idx on disk (r/w only) */ | |
55 | struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | |
62d23efa | 56 | }; |
16246018 JG |
57 | struct blkif_x86_64_request_discard { |
58 | uint8_t operation; /* BLKIF_OP_DISCARD */ | |
59 | uint8_t flag; /* nr_segments in request struct */ | |
60 | blkif_vdev_t handle; /* only for read/write requests */ | |
61 | uint64_t __attribute__((__aligned__(8))) id; | |
62 | blkif_sector_t sector_number; /* start sector idx on disk (r/w only) */ | |
63 | uint64_t nr_sectors; /* # of contiguous sectors to discard */ | |
64 | }; | |
62d23efa | 65 | struct blkif_x86_64_response { |
0d8e5894 JG |
66 | uint64_t __attribute__((__aligned__(8))) id; |
67 | uint8_t operation; /* copied from request */ | |
68 | int16_t status; /* BLKIF_RSP_??? */ | |
62d23efa AL |
69 | }; |
70 | typedef struct blkif_x86_64_request blkif_x86_64_request_t; | |
71 | typedef struct blkif_x86_64_response blkif_x86_64_response_t; | |
72 | ||
0d8e5894 JG |
73 | DEFINE_RING_TYPES(blkif_common, struct blkif_common_request, |
74 | struct blkif_common_response); | |
75 | DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, | |
76 | struct blkif_x86_32_response); | |
77 | DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, | |
78 | struct blkif_x86_64_response); | |
62d23efa AL |
79 | |
80 | union blkif_back_rings { | |
0d8e5894 JG |
81 | blkif_back_ring_t native; |
82 | blkif_common_back_ring_t common; | |
83 | blkif_x86_32_back_ring_t x86_32_part; | |
84 | blkif_x86_64_back_ring_t x86_64_part; | |
62d23efa AL |
85 | }; |
86 | typedef union blkif_back_rings blkif_back_rings_t; | |
87 | ||
88 | enum blkif_protocol { | |
0d8e5894 JG |
89 | BLKIF_PROTOCOL_NATIVE = 1, |
90 | BLKIF_PROTOCOL_X86_32 = 2, | |
91 | BLKIF_PROTOCOL_X86_64 = 3, | |
62d23efa AL |
92 | }; |
93 | ||
0d8e5894 JG |
94 | static inline void blkif_get_x86_32_req(blkif_request_t *dst, |
95 | blkif_x86_32_request_t *src) | |
62d23efa | 96 | { |
0d8e5894 | 97 | int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST; |
62d23efa | 98 | |
0d8e5894 JG |
99 | dst->operation = src->operation; |
100 | dst->nr_segments = src->nr_segments; | |
101 | dst->handle = src->handle; | |
102 | dst->id = src->id; | |
103 | dst->sector_number = src->sector_number; | |
104 | /* Prevent the compiler from using src->... instead. */ | |
105 | barrier(); | |
106 | if (dst->operation == BLKIF_OP_DISCARD) { | |
16246018 | 107 | struct blkif_x86_32_request_discard *s = (void *)src; |
0d8e5894 JG |
108 | struct blkif_request_discard *d = (void *)dst; |
109 | d->nr_sectors = s->nr_sectors; | |
110 | return; | |
111 | } | |
112 | if (n > dst->nr_segments) { | |
113 | n = dst->nr_segments; | |
114 | } | |
115 | for (i = 0; i < n; i++) { | |
116 | dst->seg[i] = src->seg[i]; | |
117 | } | |
62d23efa AL |
118 | } |
119 | ||
0d8e5894 JG |
120 | static inline void blkif_get_x86_64_req(blkif_request_t *dst, |
121 | blkif_x86_64_request_t *src) | |
62d23efa | 122 | { |
0d8e5894 | 123 | int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST; |
62d23efa | 124 | |
0d8e5894 JG |
125 | dst->operation = src->operation; |
126 | dst->nr_segments = src->nr_segments; | |
127 | dst->handle = src->handle; | |
128 | dst->id = src->id; | |
129 | dst->sector_number = src->sector_number; | |
130 | /* Prevent the compiler from using src->... instead. */ | |
131 | barrier(); | |
132 | if (dst->operation == BLKIF_OP_DISCARD) { | |
16246018 | 133 | struct blkif_x86_64_request_discard *s = (void *)src; |
0d8e5894 JG |
134 | struct blkif_request_discard *d = (void *)dst; |
135 | d->nr_sectors = s->nr_sectors; | |
136 | return; | |
137 | } | |
138 | if (n > dst->nr_segments) { | |
139 | n = dst->nr_segments; | |
140 | } | |
141 | for (i = 0; i < n; i++) { | |
142 | dst->seg[i] = src->seg[i]; | |
143 | } | |
62d23efa AL |
144 | } |
145 | ||
2a6a4076 | 146 | #endif /* XEN_BLKIF_H */ |