Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging
[qemu/ar7.git] / hw / block / xen_blkif.h
blob711b69274255bedda4b5d51901e372757e78883a
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>
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;
15 struct blkif_common_response {
16 char dummy;
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];
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_??? */
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)
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];
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_??? */
52 typedef struct blkif_x86_64_request blkif_x86_64_request_t;
53 typedef struct blkif_x86_64_response blkif_x86_64_response_t;
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);
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;
65 typedef union blkif_back_rings blkif_back_rings_t;
67 enum blkif_protocol {
68 BLKIF_PROTOCOL_NATIVE = 1,
69 BLKIF_PROTOCOL_X86_32 = 2,
70 BLKIF_PROTOCOL_X86_64 = 3,
73 static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_request_t *src)
75 int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
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 (src->operation == BLKIF_OP_DISCARD) {
83 struct blkif_request_discard *s = (void *)src;
84 struct blkif_request_discard *d = (void *)dst;
85 d->nr_sectors = s->nr_sectors;
86 return;
88 if (n > src->nr_segments)
89 n = src->nr_segments;
90 for (i = 0; i < n; i++)
91 dst->seg[i] = src->seg[i];
94 static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_request_t *src)
96 int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
98 dst->operation = src->operation;
99 dst->nr_segments = src->nr_segments;
100 dst->handle = src->handle;
101 dst->id = src->id;
102 dst->sector_number = src->sector_number;
103 if (src->operation == BLKIF_OP_DISCARD) {
104 struct blkif_request_discard *s = (void *)src;
105 struct blkif_request_discard *d = (void *)dst;
106 d->nr_sectors = s->nr_sectors;
107 return;
109 if (n > src->nr_segments)
110 n = src->nr_segments;
111 for (i = 0; i < n; i++)
112 dst->seg[i] = src->seg[i];
115 #endif /* __XEN_BLKIF_H__ */