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