Lines Matching refs:ctrl
75 static int init_gnt_srv(struct libxenvchan *ctrl, int domain) in init_gnt_srv() argument
77 int pages_left = ctrl->read.order >= PAGE_SHIFT ? 1 << (ctrl->read.order - PAGE_SHIFT) : 0; in init_gnt_srv()
78 int pages_right = ctrl->write.order >= PAGE_SHIFT ? 1 << (ctrl->write.order - PAGE_SHIFT) : 0; in init_gnt_srv()
82 ring = xengntshr_share_page_notify(ctrl->gntshr, domain, in init_gnt_srv()
84 ctrl->event_port); in init_gnt_srv()
91 ctrl->ring = ring; in init_gnt_srv()
92 ctrl->read.shr = &ctrl->ring->left; in init_gnt_srv()
93 ctrl->write.shr = &ctrl->ring->right; in init_gnt_srv()
94 ctrl->ring->left_order = ctrl->read.order; in init_gnt_srv()
95 ctrl->ring->right_order = ctrl->write.order; in init_gnt_srv()
96 ctrl->ring->cli_live = 2; in init_gnt_srv()
97 ctrl->ring->srv_live = 1; in init_gnt_srv()
98 ctrl->ring->cli_notify = VCHAN_NOTIFY_WRITE; in init_gnt_srv()
100 switch (ctrl->read.order) { in init_gnt_srv()
102 ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET; in init_gnt_srv()
105 ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET; in init_gnt_srv()
108 ctrl->read.buffer = xengntshr_share_pages(ctrl->gntshr, domain, in init_gnt_srv()
109 pages_left, ctrl->ring->grants, 1); in init_gnt_srv()
110 if (!ctrl->read.buffer) in init_gnt_srv()
114 switch (ctrl->write.order) { in init_gnt_srv()
116 ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET; in init_gnt_srv()
119 ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET; in init_gnt_srv()
122 ctrl->write.buffer = xengntshr_share_pages(ctrl->gntshr, domain, in init_gnt_srv()
123 pages_right, ctrl->ring->grants + pages_left, 1); in init_gnt_srv()
124 if (!ctrl->write.buffer) in init_gnt_srv()
132 xengntshr_unshare(ctrl->gntshr, ctrl->read.buffer, pages_left); in init_gnt_srv()
134 xengntshr_unshare(ctrl->gntshr, ring, 1); in init_gnt_srv()
136 ctrl->ring = NULL; in init_gnt_srv()
137 ctrl->write.order = ctrl->read.order = 0; in init_gnt_srv()
141 static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref) in init_gnt_cli() argument
146 ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab, in init_gnt_cli()
148 offsetof(struct vchan_interface, cli_live), ctrl->event_port); in init_gnt_cli()
150 if (!ctrl->ring) in init_gnt_cli()
153 ctrl->write.order = ctrl->ring->left_order; in init_gnt_cli()
154 ctrl->read.order = ctrl->ring->right_order; in init_gnt_cli()
155 ctrl->write.shr = &ctrl->ring->left; in init_gnt_cli()
156 ctrl->read.shr = &ctrl->ring->right; in init_gnt_cli()
157 if (ctrl->write.order < SMALL_RING_SHIFT || ctrl->write.order > MAX_RING_SHIFT) in init_gnt_cli()
159 if (ctrl->read.order < SMALL_RING_SHIFT || ctrl->read.order > MAX_RING_SHIFT) in init_gnt_cli()
161 if (ctrl->read.order == ctrl->write.order && ctrl->read.order < PAGE_SHIFT) in init_gnt_cli()
164 grants = ctrl->ring->grants; in init_gnt_cli()
166 switch (ctrl->write.order) { in init_gnt_cli()
168 ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET; in init_gnt_cli()
171 ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET; in init_gnt_cli()
175 int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT); in init_gnt_cli()
176 ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab, in init_gnt_cli()
178 if (!ctrl->write.buffer) in init_gnt_cli()
184 switch (ctrl->read.order) { in init_gnt_cli()
186 ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET; in init_gnt_cli()
189 ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET; in init_gnt_cli()
193 int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT); in init_gnt_cli()
194 ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab, in init_gnt_cli()
196 if (!ctrl->read.buffer) in init_gnt_cli()
205 if (ctrl->write.order >= PAGE_SHIFT) in init_gnt_cli()
206 xengnttab_unmap(ctrl->gnttab, ctrl->write.buffer, in init_gnt_cli()
207 1 << (ctrl->write.order - PAGE_SHIFT)); in init_gnt_cli()
209 xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1); in init_gnt_cli()
210 ctrl->ring = 0; in init_gnt_cli()
211 ctrl->write.order = ctrl->read.order = 0; in init_gnt_cli()
216 static int init_evt_srv(struct libxenvchan *ctrl, int domain, in init_evt_srv() argument
221 ctrl->event = xenevtchn_open(logger, 0); in init_evt_srv()
222 if (!ctrl->event) in init_evt_srv()
225 port = xenevtchn_bind_unbound_port(ctrl->event, domain); in init_evt_srv()
228 ctrl->event_port = port; in init_evt_srv()
230 if (xenevtchn_unmask(ctrl->event, ctrl->event_port)) in init_evt_srv()
237 xenevtchn_unbind(ctrl->event, port); in init_evt_srv()
239 xenevtchn_close(ctrl->event); in init_evt_srv()
240 ctrl->event = NULL; in init_evt_srv()
245 static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base, int ring_ref) in init_xs_srv() argument
281 snprintf(ref, sizeof ref, "%d", ctrl->event_port); in init_xs_srv()
313 struct libxenvchan *ctrl; in libxenvchan_server_init() local
318 ctrl = malloc(sizeof(*ctrl)); in libxenvchan_server_init()
319 if (!ctrl) in libxenvchan_server_init()
322 ctrl->ring = NULL; in libxenvchan_server_init()
323 ctrl->event = NULL; in libxenvchan_server_init()
324 ctrl->is_server = 1; in libxenvchan_server_init()
325 ctrl->server_persist = 0; in libxenvchan_server_init()
327 ctrl->read.order = min_order(left_min); in libxenvchan_server_init()
328 ctrl->write.order = min_order(right_min); in libxenvchan_server_init()
332 ctrl->read.order = SMALL_RING_SHIFT; in libxenvchan_server_init()
333 ctrl->write.order = LARGE_RING_SHIFT; in libxenvchan_server_init()
335 ctrl->read.order = LARGE_RING_SHIFT; in libxenvchan_server_init()
336 ctrl->write.order = SMALL_RING_SHIFT; in libxenvchan_server_init()
338 ctrl->read.order = LARGE_RING_SHIFT; in libxenvchan_server_init()
340 ctrl->write.order = LARGE_RING_SHIFT; in libxenvchan_server_init()
343 ctrl->gntshr = xengntshr_open(logger, 0); in libxenvchan_server_init()
344 if (!ctrl->gntshr) { in libxenvchan_server_init()
345 free(ctrl); in libxenvchan_server_init()
349 if (init_evt_srv(ctrl, domain, logger)) in libxenvchan_server_init()
351 ring_ref = init_gnt_srv(ctrl, domain); in libxenvchan_server_init()
354 if (init_xs_srv(ctrl, domain, xs_path, ring_ref)) in libxenvchan_server_init()
356 return ctrl; in libxenvchan_server_init()
358 libxenvchan_close(ctrl); in libxenvchan_server_init()
362 static int init_evt_cli(struct libxenvchan *ctrl, int domain, in init_evt_cli() argument
367 ctrl->event = xenevtchn_open(logger, 0); in init_evt_cli()
368 if (!ctrl->event) in init_evt_cli()
371 port = xenevtchn_bind_interdomain(ctrl->event, in init_evt_cli()
372 domain, ctrl->event_port); in init_evt_cli()
375 ctrl->event_port = port; in init_evt_cli()
377 if (xenevtchn_unmask(ctrl->event, ctrl->event_port)) in init_evt_cli()
384 xenevtchn_unbind(ctrl->event, port); in init_evt_cli()
386 xenevtchn_close(ctrl->event); in init_evt_cli()
387 ctrl->event = NULL; in init_evt_cli()
396 struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan)); in libxenvchan_client_init() local
403 if (!ctrl) in libxenvchan_client_init()
405 ctrl->ring = NULL; in libxenvchan_client_init()
406 ctrl->event = NULL; in libxenvchan_client_init()
407 ctrl->gnttab = NULL; in libxenvchan_client_init()
408 ctrl->write.order = ctrl->read.order = 0; in libxenvchan_client_init()
409 ctrl->is_server = 0; in libxenvchan_client_init()
430 ctrl->event_port = atoi(ref); in libxenvchan_client_init()
432 if (!ctrl->event_port) in libxenvchan_client_init()
435 ctrl->gnttab = xengnttab_open(logger, 0); in libxenvchan_client_init()
436 if (!ctrl->gnttab) in libxenvchan_client_init()
440 if (init_evt_cli(ctrl, domain, logger)) in libxenvchan_client_init()
444 if (init_gnt_cli(ctrl, domain, ring_ref)) in libxenvchan_client_init()
447 ctrl->ring->cli_live = 1; in libxenvchan_client_init()
448 ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE; in libxenvchan_client_init()
451 xenevtchn_notify(ctrl->event, ctrl->event_port); in libxenvchan_client_init()
456 return ctrl; in libxenvchan_client_init()
458 libxenvchan_close(ctrl); in libxenvchan_client_init()
459 ctrl = NULL; in libxenvchan_client_init()