Lines Matching full:u
95 static unsigned int evtchn_ring_offset(struct per_user_data *u, in evtchn_ring_offset() argument
98 return idx & (u->ring_size - 1); in evtchn_ring_offset()
101 static evtchn_port_t *evtchn_ring_entry(struct per_user_data *u, in evtchn_ring_entry() argument
104 return u->ring + evtchn_ring_offset(u, idx); in evtchn_ring_entry()
107 static int add_evtchn(struct per_user_data *u, struct user_evtchn *evtchn) in add_evtchn() argument
109 struct rb_node **new = &(u->evtchns.rb_node), *parent = NULL; in add_evtchn()
111 u->nr_evtchns++; in add_evtchn()
129 rb_insert_color(&evtchn->node, &u->evtchns); in add_evtchn()
134 static void del_evtchn(struct per_user_data *u, struct user_evtchn *evtchn) in del_evtchn() argument
136 u->nr_evtchns--; in del_evtchn()
137 rb_erase(&evtchn->node, &u->evtchns); in del_evtchn()
141 static struct user_evtchn *find_evtchn(struct per_user_data *u, in find_evtchn() argument
144 struct rb_node *node = u->evtchns.rb_node; in find_evtchn()
164 struct per_user_data *u = evtchn->user; in evtchn_interrupt() local
167 "Interrupt for port %u, but apparently not enabled; per-user %p\n", in evtchn_interrupt()
168 evtchn->port, u); in evtchn_interrupt()
172 spin_lock(&u->ring_prod_lock); in evtchn_interrupt()
174 if ((u->ring_prod - u->ring_cons) < u->ring_size) { in evtchn_interrupt()
175 *evtchn_ring_entry(u, u->ring_prod) = evtchn->port; in evtchn_interrupt()
177 if (u->ring_cons == u->ring_prod++) { in evtchn_interrupt()
178 wake_up_interruptible(&u->evtchn_wait); in evtchn_interrupt()
179 kill_fasync(&u->evtchn_async_queue, in evtchn_interrupt()
183 u->ring_overflow = 1; in evtchn_interrupt()
185 spin_unlock(&u->ring_prod_lock); in evtchn_interrupt()
195 struct per_user_data *u = file->private_data; in evtchn_read() local
207 mutex_lock(&u->ring_cons_mutex); in evtchn_read()
210 if (u->ring_overflow) in evtchn_read()
213 c = u->ring_cons; in evtchn_read()
214 p = u->ring_prod; in evtchn_read()
218 mutex_unlock(&u->ring_cons_mutex); in evtchn_read()
223 rc = wait_event_interruptible(u->evtchn_wait, in evtchn_read()
224 u->ring_cons != u->ring_prod); in evtchn_read()
230 if (((c ^ p) & u->ring_size) != 0) { in evtchn_read()
231 bytes1 = (u->ring_size - evtchn_ring_offset(u, c)) * in evtchn_read()
233 bytes2 = evtchn_ring_offset(u, p) * sizeof(evtchn_port_t); in evtchn_read()
249 if (copy_to_user(buf, evtchn_ring_entry(u, c), bytes1) || in evtchn_read()
251 copy_to_user(&buf[bytes1], &u->ring[0], bytes2))) in evtchn_read()
254 u->ring_cons += (bytes1 + bytes2) / sizeof(evtchn_port_t); in evtchn_read()
258 mutex_unlock(&u->ring_cons_mutex); in evtchn_read()
267 struct per_user_data *u = file->private_data; in evtchn_write() local
286 mutex_lock(&u->bind_mutex); in evtchn_write()
292 evtchn = find_evtchn(u, port); in evtchn_write()
299 mutex_unlock(&u->bind_mutex); in evtchn_write()
308 static int evtchn_resize_ring(struct per_user_data *u) in evtchn_resize_ring() argument
317 if (u->nr_evtchns <= u->ring_size) in evtchn_resize_ring()
320 if (u->ring_size == 0) in evtchn_resize_ring()
323 new_size = 2 * u->ring_size; in evtchn_resize_ring()
329 old_ring = u->ring; in evtchn_resize_ring()
335 mutex_lock(&u->ring_cons_mutex); in evtchn_resize_ring()
336 spin_lock_irq(&u->ring_prod_lock); in evtchn_resize_ring()
349 memcpy(new_ring, old_ring, u->ring_size * sizeof(*u->ring)); in evtchn_resize_ring()
350 memcpy(new_ring + u->ring_size, old_ring, in evtchn_resize_ring()
351 u->ring_size * sizeof(*u->ring)); in evtchn_resize_ring()
353 u->ring = new_ring; in evtchn_resize_ring()
354 u->ring_size = new_size; in evtchn_resize_ring()
356 spin_unlock_irq(&u->ring_prod_lock); in evtchn_resize_ring()
357 mutex_unlock(&u->ring_cons_mutex); in evtchn_resize_ring()
364 static int evtchn_bind_to_user(struct per_user_data *u, evtchn_port_t port) in evtchn_bind_to_user() argument
383 evtchn->user = u; in evtchn_bind_to_user()
387 rc = add_evtchn(u, evtchn); in evtchn_bind_to_user()
391 rc = evtchn_resize_ring(u); in evtchn_bind_to_user()
396 u->name, evtchn); in evtchn_bind_to_user()
408 del_evtchn(u, evtchn); in evtchn_bind_to_user()
412 static void evtchn_unbind_from_user(struct per_user_data *u, in evtchn_unbind_from_user() argument
421 del_evtchn(u, evtchn); in evtchn_unbind_from_user()
458 struct per_user_data *u = file->private_data; in evtchn_ioctl() local
462 mutex_lock(&u->bind_mutex); in evtchn_ioctl()
470 if (u->restrict_domid != UNRESTRICTED_DOMID) in evtchn_ioctl()
484 rc = evtchn_bind_to_user(u, bind_virq.port); in evtchn_ioctl()
499 if (u->restrict_domid != UNRESTRICTED_DOMID && in evtchn_ioctl()
500 u->restrict_domid != bind.remote_domain) in evtchn_ioctl()
510 rc = evtchn_bind_to_user(u, bind_interdomain.local_port); in evtchn_ioctl()
523 if (u->restrict_domid != UNRESTRICTED_DOMID) in evtchn_ioctl()
537 rc = evtchn_bind_to_user(u, alloc_unbound.port); in evtchn_ioctl()
556 evtchn = find_evtchn(u, unbind.port); in evtchn_ioctl()
561 evtchn_unbind_from_user(u, evtchn); in evtchn_ioctl()
575 evtchn = find_evtchn(u, notify.port); in evtchn_ioctl()
585 mutex_lock(&u->ring_cons_mutex); in evtchn_ioctl()
586 spin_lock_irq(&u->ring_prod_lock); in evtchn_ioctl()
587 u->ring_cons = u->ring_prod = u->ring_overflow = 0; in evtchn_ioctl()
588 spin_unlock_irq(&u->ring_prod_lock); in evtchn_ioctl()
589 mutex_unlock(&u->ring_cons_mutex); in evtchn_ioctl()
598 if (u->restrict_domid != UNRESTRICTED_DOMID) in evtchn_ioctl()
609 u->restrict_domid = ierd.domid; in evtchn_ioctl()
619 mutex_unlock(&u->bind_mutex); in evtchn_ioctl()
627 struct per_user_data *u = file->private_data; in evtchn_poll() local
629 poll_wait(file, &u->evtchn_wait, wait); in evtchn_poll()
630 if (u->ring_cons != u->ring_prod) in evtchn_poll()
632 if (u->ring_overflow) in evtchn_poll()
639 struct per_user_data *u = filp->private_data; in evtchn_fasync() local
640 return fasync_helper(fd, filp, on, &u->evtchn_async_queue); in evtchn_fasync()
645 struct per_user_data *u; in evtchn_open() local
647 u = kzalloc(sizeof(*u), GFP_KERNEL); in evtchn_open()
648 if (u == NULL) in evtchn_open()
651 u->name = kasprintf(GFP_KERNEL, "evtchn:%s", current->comm); in evtchn_open()
652 if (u->name == NULL) { in evtchn_open()
653 kfree(u); in evtchn_open()
657 init_waitqueue_head(&u->evtchn_wait); in evtchn_open()
659 mutex_init(&u->bind_mutex); in evtchn_open()
660 mutex_init(&u->ring_cons_mutex); in evtchn_open()
661 spin_lock_init(&u->ring_prod_lock); in evtchn_open()
663 u->restrict_domid = UNRESTRICTED_DOMID; in evtchn_open()
665 filp->private_data = u; in evtchn_open()
672 struct per_user_data *u = filp->private_data; in evtchn_release() local
675 while ((node = u->evtchns.rb_node)) { in evtchn_release()
680 evtchn_unbind_from_user(u, evtchn); in evtchn_release()
683 evtchn_free_ring(u->ring); in evtchn_release()
684 kfree(u->name); in evtchn_release()
685 kfree(u); in evtchn_release()