Lines Matching refs:counter

60 	struct counter_device *const counter = filp->private_data;  in counter_chrdev_read()  local
64 if (!counter->ops) in counter_chrdev_read()
71 if (kfifo_is_empty(&counter->events)) { in counter_chrdev_read()
75 err = wait_event_interruptible(counter->events_wait, in counter_chrdev_read()
76 !kfifo_is_empty(&counter->events) || in counter_chrdev_read()
77 !counter->ops); in counter_chrdev_read()
80 if (!counter->ops) in counter_chrdev_read()
84 if (mutex_lock_interruptible(&counter->events_out_lock)) in counter_chrdev_read()
86 err = kfifo_to_user(&counter->events, buf, len, &copied); in counter_chrdev_read()
87 mutex_unlock(&counter->events_out_lock); in counter_chrdev_read()
98 struct counter_device *const counter = filp->private_data; in counter_chrdev_poll() local
101 if (!counter->ops) in counter_chrdev_poll()
104 poll_wait(filp, &counter->events_wait, pollt); in counter_chrdev_poll()
106 if (!kfifo_is_empty(&counter->events)) in counter_chrdev_poll()
130 static int counter_set_event_node(struct counter_device *const counter, in counter_set_event_node() argument
139 list_for_each_entry(event_node, &counter->next_events_list, l) in counter_set_event_node()
145 if (&event_node->l == &counter->next_events_list) { in counter_set_event_node()
155 list_add(&event_node->l, &counter->next_events_list); in counter_set_event_node()
187 static int counter_enable_events(struct counter_device *const counter) in counter_enable_events() argument
192 mutex_lock(&counter->n_events_list_lock); in counter_enable_events()
193 spin_lock_irqsave(&counter->events_list_lock, flags); in counter_enable_events()
195 counter_events_list_free(&counter->events_list); in counter_enable_events()
196 list_replace_init(&counter->next_events_list, in counter_enable_events()
197 &counter->events_list); in counter_enable_events()
199 if (counter->ops->events_configure) in counter_enable_events()
200 err = counter->ops->events_configure(counter); in counter_enable_events()
202 spin_unlock_irqrestore(&counter->events_list_lock, flags); in counter_enable_events()
203 mutex_unlock(&counter->n_events_list_lock); in counter_enable_events()
208 static int counter_disable_events(struct counter_device *const counter) in counter_disable_events() argument
213 spin_lock_irqsave(&counter->events_list_lock, flags); in counter_disable_events()
215 counter_events_list_free(&counter->events_list); in counter_disable_events()
217 if (counter->ops->events_configure) in counter_disable_events()
218 err = counter->ops->events_configure(counter); in counter_disable_events()
220 spin_unlock_irqrestore(&counter->events_list_lock, flags); in counter_disable_events()
222 mutex_lock(&counter->n_events_list_lock); in counter_disable_events()
224 counter_events_list_free(&counter->next_events_list); in counter_disable_events()
226 mutex_unlock(&counter->n_events_list_lock); in counter_disable_events()
231 static int counter_add_watch(struct counter_device *const counter, in counter_add_watch() argument
253 ext = counter->ext; in counter_add_watch()
254 num_ext = counter->num_ext; in counter_add_watch()
257 if (parent >= counter->num_signals) in counter_add_watch()
259 parent = array_index_nospec(parent, counter->num_signals); in counter_add_watch()
261 comp_node.parent = counter->signals + parent; in counter_add_watch()
263 ext = counter->signals[parent].ext; in counter_add_watch()
264 num_ext = counter->signals[parent].num_ext; in counter_add_watch()
267 if (parent >= counter->num_counts) in counter_add_watch()
269 parent = array_index_nospec(parent, counter->num_counts); in counter_add_watch()
271 comp_node.parent = counter->counts + parent; in counter_add_watch()
273 ext = counter->counts[parent].ext; in counter_add_watch()
274 num_ext = counter->counts[parent].num_ext; in counter_add_watch()
289 comp_node.comp.signal_u32_read = counter->ops->signal_read; in counter_add_watch()
296 comp_node.comp.count_u64_read = counter->ops->count_read; in counter_add_watch()
303 comp_node.comp.count_u32_read = counter->ops->function_read; in counter_add_watch()
308 if (id >= counter->counts[parent].num_synapses) in counter_add_watch()
310 id = array_index_nospec(id, counter->counts[parent].num_synapses); in counter_add_watch()
313 comp_node.comp.action_read = counter->ops->action_read; in counter_add_watch()
314 comp_node.comp.priv = counter->counts[parent].synapses + id; in counter_add_watch()
330 mutex_lock(&counter->n_events_list_lock); in counter_add_watch()
332 if (counter->ops->watch_validate) { in counter_add_watch()
333 err = counter->ops->watch_validate(counter, &watch); in counter_add_watch()
340 err = counter_set_event_node(counter, &watch, &comp_node); in counter_add_watch()
343 mutex_unlock(&counter->n_events_list_lock); in counter_add_watch()
351 struct counter_device *const counter = filp->private_data; in counter_chrdev_ioctl() local
354 mutex_lock(&counter->ops_exist_lock); in counter_chrdev_ioctl()
356 if (!counter->ops) in counter_chrdev_ioctl()
361 ret = counter_add_watch(counter, arg); in counter_chrdev_ioctl()
364 ret = counter_enable_events(counter); in counter_chrdev_ioctl()
367 ret = counter_disable_events(counter); in counter_chrdev_ioctl()
375 mutex_unlock(&counter->ops_exist_lock); in counter_chrdev_ioctl()
382 struct counter_device *const counter = container_of(inode->i_cdev, in counter_chrdev_open() local
383 typeof(*counter), in counter_chrdev_open()
386 get_device(&counter->dev); in counter_chrdev_open()
387 filp->private_data = counter; in counter_chrdev_open()
394 struct counter_device *const counter = filp->private_data; in counter_chrdev_release() local
397 mutex_lock(&counter->ops_exist_lock); in counter_chrdev_release()
399 if (!counter->ops) { in counter_chrdev_release()
401 counter_events_list_free(&counter->events_list); in counter_chrdev_release()
402 counter_events_list_free(&counter->next_events_list); in counter_chrdev_release()
407 ret = counter_disable_events(counter); in counter_chrdev_release()
409 mutex_unlock(&counter->ops_exist_lock); in counter_chrdev_release()
414 mutex_unlock(&counter->ops_exist_lock); in counter_chrdev_release()
416 put_device(&counter->dev); in counter_chrdev_release()
431 int counter_chrdev_add(struct counter_device *const counter) in counter_chrdev_add() argument
434 INIT_LIST_HEAD(&counter->events_list); in counter_chrdev_add()
435 INIT_LIST_HEAD(&counter->next_events_list); in counter_chrdev_add()
436 spin_lock_init(&counter->events_list_lock); in counter_chrdev_add()
437 mutex_init(&counter->n_events_list_lock); in counter_chrdev_add()
438 init_waitqueue_head(&counter->events_wait); in counter_chrdev_add()
439 spin_lock_init(&counter->events_in_lock); in counter_chrdev_add()
440 mutex_init(&counter->events_out_lock); in counter_chrdev_add()
443 cdev_init(&counter->chrdev, &counter_fops); in counter_chrdev_add()
446 return kfifo_alloc(&counter->events, 64, GFP_KERNEL); in counter_chrdev_add()
449 void counter_chrdev_remove(struct counter_device *const counter) in counter_chrdev_remove() argument
451 kfifo_free(&counter->events); in counter_chrdev_remove()
454 static int counter_get_data(struct counter_device *const counter, in counter_get_data() argument
472 ret = comp->device_u8_read(counter, &value_u8); in counter_get_data()
475 ret = comp->signal_u8_read(counter, parent, &value_u8); in counter_get_data()
478 ret = comp->count_u8_read(counter, parent, &value_u8); in counter_get_data()
490 ret = comp->device_u32_read(counter, &value_u32); in counter_get_data()
493 ret = comp->signal_u32_read(counter, parent, in counter_get_data()
497 ret = comp->count_u32_read(counter, parent, &value_u32); in counter_get_data()
505 return comp->device_u64_read(counter, value); in counter_get_data()
507 return comp->signal_u64_read(counter, parent, value); in counter_get_data()
509 return comp->count_u64_read(counter, parent, value); in counter_get_data()
514 ret = comp->action_read(counter, parent, comp->priv, in counter_get_data()
532 void counter_push_event(struct counter_device *const counter, const u8 event, in counter_push_event() argument
546 spin_lock_irqsave(&counter->events_list_lock, flags); in counter_push_event()
549 list_for_each_entry(event_node, &counter->events_list, l) in counter_push_event()
555 if (&event_node->l == &counter->events_list) in counter_push_event()
561 ev.status = -counter_get_data(counter, comp_node, &ev.value); in counter_push_event()
563 copied += kfifo_in_spinlocked_noirqsave(&counter->events, &ev, in counter_push_event()
564 1, &counter->events_in_lock); in counter_push_event()
568 spin_unlock_irqrestore(&counter->events_list_lock, flags); in counter_push_event()
571 wake_up_poll(&counter->events_wait, EPOLLIN); in counter_push_event()