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