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
9
10
11
12struct blkif_common_request {
13 char dummy;
14};
15struct blkif_common_response {
16 char dummy;
17};
18
19
20#pragma pack(push, 4)
21struct blkif_x86_32_request {
22 uint8_t operation;
23 uint8_t nr_segments;
24 blkif_vdev_t handle;
25 uint64_t id;
26 blkif_sector_t sector_number;
27 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
28};
29struct blkif_x86_32_response {
30 uint64_t id;
31 uint8_t operation;
32 int16_t status;
33};
34typedef struct blkif_x86_32_request blkif_x86_32_request_t;
35typedef struct blkif_x86_32_response blkif_x86_32_response_t;
36#pragma pack(pop)
37
38
39struct blkif_x86_64_request {
40 uint8_t operation;
41 uint8_t nr_segments;
42 blkif_vdev_t handle;
43 uint64_t __attribute__((__aligned__(8))) id;
44 blkif_sector_t sector_number;
45 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
46};
47struct blkif_x86_64_response {
48 uint64_t __attribute__((__aligned__(8))) id;
49 uint8_t operation;
50 int16_t status;
51};
52typedef struct blkif_x86_64_request blkif_x86_64_request_t;
53typedef struct blkif_x86_64_response blkif_x86_64_response_t;
54
55DEFINE_RING_TYPES(blkif_common, struct blkif_common_request, struct blkif_common_response);
56DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response);
57DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response);
58
59union 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};
65typedef union blkif_back_rings blkif_back_rings_t;
66
67enum blkif_protocol {
68 BLKIF_PROTOCOL_NATIVE = 1,
69 BLKIF_PROTOCOL_X86_32 = 2,
70 BLKIF_PROTOCOL_X86_64 = 3,
71};
72
73static 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
88static 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
104