Loading...
Searching...
No Matches
11#ifndef __XEN_PUBLIC_IO_RING_H__
12#define __XEN_PUBLIC_IO_RING_H__
14#include "../xen-compat.h"
16#if __XEN_INTERFACE_VERSION__ < 0x00030208
18#define xen_rmb() rmb()
19#define xen_wmb() wmb()
22typedef UINT32 RING_IDX;
25#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
26#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
27#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
28#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
29#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
37#define __CONST_RING_SIZE(_s, _sz) \
38 (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
39 sizeof(((struct _s##_sring *)0)->ring[0])))
44#define __RING_SIZE(_s, _sz) \
45 (__RD32(((_sz) - (INTN)(_s)->ring + (INTN)(_s)) / sizeof((_s)->ring[0])))
79#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \
82union __name##_sring_entry { \
88struct __name##_sring { \
89 RING_IDX req_prod, req_event; \
90 RING_IDX rsp_prod, rsp_event; \
93 UINT8 smartpoll_active; \
101 union __name##_sring_entry ring[1]; \
105struct __name##_front_ring { \
106 RING_IDX req_prod_pvt; \
109 struct __name##_sring *sring; \
113struct __name##_back_ring { \
114 RING_IDX rsp_prod_pvt; \
117 struct __name##_sring *sring; \
121typedef struct __name##_sring __name##_sring_t; \
122typedef struct __name##_front_ring __name##_front_ring_t; \
123typedef struct __name##_back_ring __name##_back_ring_t
141#define SHARED_RING_INIT(_s) do { \
142 (_s)->req_prod = (_s)->rsp_prod = 0; \
143 (_s)->req_event = (_s)->rsp_event = 1; \
144 (VOID)ZeroMem((_s)->private.pvt_pad, sizeof((_s)->private.pvt_pad)); \
145 (VOID)ZeroMem((_s)->__pad, sizeof((_s)->__pad)); \
148#define FRONT_RING_INIT(_r, _s, __size) do { \
149 (_r)->req_prod_pvt = 0; \
150 (_r)->rsp_cons = 0; \
151 (_r)->nr_ents = __RING_SIZE(_s, __size); \
152 (_r)->sring = (_s); \
155#define BACK_RING_INIT(_r, _s, __size) do { \
156 (_r)->rsp_prod_pvt = 0; \
157 (_r)->req_cons = 0; \
158 (_r)->nr_ents = __RING_SIZE(_s, __size); \
159 (_r)->sring = (_s); \
163#define RING_SIZE(_r) \
167#define RING_FREE_REQUESTS(_r) \
168 (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
173#define RING_FULL(_r) \
174 (RING_FREE_REQUESTS(_r) == 0)
177#define RING_HAS_UNCONSUMED_RESPONSES(_r) \
178 ((_r)->sring->rsp_prod - (_r)->rsp_cons)
181#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \
182 UINT32 req = (_r)->sring->req_prod - (_r)->req_cons; \
183 UINT32 rsp = RING_SIZE(_r) - \
184 ((_r)->req_cons - (_r)->rsp_prod_pvt); \
185 req < rsp ? req : rsp; \
189#define RING_HAS_UNCONSUMED_REQUESTS(_r) \
190 ((((_r)->sring->req_prod - (_r)->req_cons) < \
191 (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \
192 ((_r)->sring->req_prod - (_r)->req_cons) : \
193 (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt)))
197#define RING_GET_REQUEST(_r, _idx) \
198 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
200#define RING_GET_RESPONSE(_r, _idx) \
201 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
204#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \
205 (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
208#define RING_REQUEST_PROD_OVERFLOW(_r, _prod) \
209 (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
211#define RING_PUSH_REQUESTS(_r) do { \
213 (_r)->sring->req_prod = (_r)->req_prod_pvt; \
216#define RING_PUSH_RESPONSES(_r) do { \
218 (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
251#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \
252 RING_IDX __old = (_r)->sring->req_prod; \
253 RING_IDX __new = (_r)->req_prod_pvt; \
255 (_r)->sring->req_prod = __new; \
257 (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
258 (RING_IDX)(__new - __old)); \
261#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \
262 RING_IDX __old = (_r)->sring->rsp_prod; \
263 RING_IDX __new = (_r)->rsp_prod_pvt; \
265 (_r)->sring->rsp_prod = __new; \
267 (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
268 (RING_IDX)(__new - __old)); \
271#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \
272 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
273 if (_work_to_do) break; \
274 (_r)->sring->req_event = (_r)->req_cons + 1; \
276 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
279#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \
280 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
281 if (_work_to_do) break; \
282 (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
284 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \