Go to the documentation of this file.
9 #ifndef __XEN_PUBLIC_IO_RING_H__
10 #define __XEN_PUBLIC_IO_RING_H__
15 #define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
16 #define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
17 #define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
18 #define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
19 #define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
27 #define __CONST_RING_SIZE(_s, _sz) \
28 (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
29 sizeof(((struct _s##_sring *)0)->ring[0])))
34 #define __RING_SIZE(_s, _sz) \
35 (__RD32(((_sz) - (long)&(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
71 #define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \
74 union __name##_sring_entry { \
80 struct __name##_sring { \
81 RING_IDX req_prod, req_event; \
82 RING_IDX rsp_prod, rsp_event; \
84 union __name##_sring_entry ring[1]; \
88 struct __name##_front_ring { \
89 RING_IDX req_prod_pvt; \
91 unsigned int nr_ents; \
92 struct __name##_sring *sring; \
96 struct __name##_back_ring { \
97 RING_IDX rsp_prod_pvt; \
99 unsigned int nr_ents; \
100 struct __name##_sring *sring; \
119 #define SHARED_RING_INIT(_s) do { \
120 (_s)->req_prod = (_s)->rsp_prod = 0; \
121 (_s)->req_event = (_s)->rsp_event = 1; \
122 memset((_s)->pad, 0, sizeof((_s)->pad)); \
125 #define FRONT_RING_INIT(_r, _s, __size) do { \
126 (_r)->req_prod_pvt = 0; \
127 (_r)->rsp_cons = 0; \
128 (_r)->nr_ents = __RING_SIZE(_s, __size); \
129 (_r)->sring = (_s); \
132 #define BACK_RING_INIT(_r, _s, __size) do { \
133 (_r)->rsp_prod_pvt = 0; \
134 (_r)->req_cons = 0; \
135 (_r)->nr_ents = __RING_SIZE(_s, __size); \
136 (_r)->sring = (_s); \
140 #define FRONT_RING_ATTACH(_r, _s, __size) do { \
141 (_r)->sring = (_s); \
142 (_r)->req_prod_pvt = (_s)->req_prod; \
143 (_r)->rsp_cons = (_s)->rsp_prod; \
144 (_r)->nr_ents = __RING_SIZE(_s, __size); \
147 #define BACK_RING_ATTACH(_r, _s, __size) do { \
148 (_r)->sring = (_s); \
149 (_r)->rsp_prod_pvt = (_s)->rsp_prod; \
150 (_r)->req_cons = (_s)->req_prod; \
151 (_r)->nr_ents = __RING_SIZE(_s, __size); \
155 #define RING_SIZE(_r) \
159 #define RING_FREE_REQUESTS(_r) \
160 (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
165 #define RING_FULL(_r) \
166 (RING_FREE_REQUESTS(_r) == 0)
169 #define RING_HAS_UNCONSUMED_RESPONSES(_r) \
170 ((_r)->sring->rsp_prod - (_r)->rsp_cons)
172 #define RING_HAS_UNCONSUMED_REQUESTS(_r) \
174 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \
175 unsigned int rsp = RING_SIZE(_r) - \
176 ((_r)->req_cons - (_r)->rsp_prod_pvt); \
177 req < rsp ? req : rsp; \
181 #define RING_GET_REQUEST(_r, _idx) \
182 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
184 #define RING_GET_RESPONSE(_r, _idx) \
185 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
188 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \
189 (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
191 #define RING_PUSH_REQUESTS(_r) do { \
193 (_r)->sring->req_prod = (_r)->req_prod_pvt; \
196 #define RING_PUSH_RESPONSES(_r) do { \
198 (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
231 #define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \
232 RING_IDX __old = (_r)->sring->req_prod; \
233 RING_IDX __new = (_r)->req_prod_pvt; \
235 (_r)->sring->req_prod = __new; \
237 (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
238 (RING_IDX)(__new - __old)); \
241 #define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \
242 RING_IDX __old = (_r)->sring->rsp_prod; \
243 RING_IDX __new = (_r)->rsp_prod_pvt; \
245 (_r)->sring->rsp_prod = __new; \
247 (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
248 (RING_IDX)(__new - __old)); \
251 #define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \
252 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
253 if (_work_to_do) break; \
254 (_r)->sring->req_event = (_r)->req_cons + 1; \
256 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
259 #define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \
260 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
261 if (_work_to_do) break; \
262 (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
264 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \