2 * Copyright 2013 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <core/event.h>
27 nouveau_event_put_locked(struct nouveau_event *event, int index,
28 struct nouveau_eventh *handler)
30 if (!--event->index[index].refs) {
32 event->disable(event, index);
34 list_del(&handler->head);
38 nouveau_event_put(struct nouveau_event *event, int index,
39 struct nouveau_eventh *handler)
43 spin_lock_irqsave(&event->lock, flags);
44 if (index < event->index_nr)
45 nouveau_event_put_locked(event, index, handler);
46 spin_unlock_irqrestore(&event->lock, flags);
50 nouveau_event_get(struct nouveau_event *event, int index,
51 struct nouveau_eventh *handler)
55 spin_lock_irqsave(&event->lock, flags);
56 if (index < event->index_nr) {
57 list_add(&handler->head, &event->index[index].list);
58 if (!event->index[index].refs++) {
60 event->enable(event, index);
63 spin_unlock_irqrestore(&event->lock, flags);
67 nouveau_event_trigger(struct nouveau_event *event, int index)
69 struct nouveau_eventh *handler, *temp;
72 if (index >= event->index_nr)
75 spin_lock_irqsave(&event->lock, flags);
76 list_for_each_entry_safe(handler, temp, &event->index[index].list, head) {
77 if (handler->func(handler, index) == NVKM_EVENT_DROP) {
78 nouveau_event_put_locked(event, index, handler);
81 spin_unlock_irqrestore(&event->lock, flags);
85 nouveau_event_destroy(struct nouveau_event **pevent)
87 struct nouveau_event *event = *pevent;
95 nouveau_event_create(int index_nr, struct nouveau_event **pevent)
97 struct nouveau_event *event;
100 event = *pevent = kzalloc(sizeof(*event) + index_nr *
101 sizeof(event->index[0]), GFP_KERNEL);
105 spin_lock_init(&event->lock);
106 for (i = 0; i < index_nr; i++)
107 INIT_LIST_HEAD(&event->index[i].list);
108 event->index_nr = index_nr;