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 if (index >= event->index_nr)
46 spin_lock_irqsave(&event->lock, flags);
47 nouveau_event_put_locked(event, index, handler);
48 spin_unlock_irqrestore(&event->lock, flags);
52 nouveau_event_get(struct nouveau_event *event, int index,
53 struct nouveau_eventh *handler)
57 if (index >= event->index_nr)
60 spin_lock_irqsave(&event->lock, flags);
61 list_add(&handler->head, &event->index[index].list);
62 if (!event->index[index].refs++) {
64 event->enable(event, index);
66 spin_unlock_irqrestore(&event->lock, flags);
70 nouveau_event_trigger(struct nouveau_event *event, int index)
72 struct nouveau_eventh *handler, *temp;
75 if (index >= event->index_nr)
78 spin_lock_irqsave(&event->lock, flags);
79 list_for_each_entry_safe(handler, temp, &event->index[index].list, head) {
80 if (handler->func(handler, index) == NVKM_EVENT_DROP) {
81 nouveau_event_put_locked(event, index, handler);
84 spin_unlock_irqrestore(&event->lock, flags);
88 nouveau_event_destroy(struct nouveau_event **pevent)
90 struct nouveau_event *event = *pevent;
98 nouveau_event_create(int index_nr, struct nouveau_event **pevent)
100 struct nouveau_event *event;
103 event = *pevent = kzalloc(sizeof(*event) + index_nr *
104 sizeof(event->index[0]), GFP_KERNEL);
108 spin_lock_init(&event->lock);
109 for (i = 0; i < index_nr; i++)
110 INIT_LIST_HEAD(&event->index[i].list);
111 event->index_nr = index_nr;