2 * Copyright 2014 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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
25 #include <core/client.h>
26 #include <core/event.h>
27 #include <core/notify.h>
29 #include <nvif/unpack.h>
30 #include <nvif/event.h>
33 nvkm_notify_put_locked(struct nvkm_notify
*notify
)
35 if (notify
->block
++ == 0)
36 nvkm_event_put(notify
->event
, notify
->types
, notify
->index
);
40 nvkm_notify_put(struct nvkm_notify
*notify
)
42 struct nvkm_event
*event
= notify
->event
;
45 test_and_clear_bit(NVKM_NOTIFY_USER
, ¬ify
->flags
)) {
46 spin_lock_irqsave(&event
->refs_lock
, flags
);
47 nvkm_notify_put_locked(notify
);
48 spin_unlock_irqrestore(&event
->refs_lock
, flags
);
49 if (test_bit(NVKM_NOTIFY_WORK
, ¬ify
->flags
))
50 flush_work(¬ify
->work
);
55 nvkm_notify_get_locked(struct nvkm_notify
*notify
)
57 if (--notify
->block
== 0)
58 nvkm_event_get(notify
->event
, notify
->types
, notify
->index
);
62 nvkm_notify_get(struct nvkm_notify
*notify
)
64 struct nvkm_event
*event
= notify
->event
;
67 !test_and_set_bit(NVKM_NOTIFY_USER
, ¬ify
->flags
)) {
68 spin_lock_irqsave(&event
->refs_lock
, flags
);
69 nvkm_notify_get_locked(notify
);
70 spin_unlock_irqrestore(&event
->refs_lock
, flags
);
75 nvkm_notify_func(struct nvkm_notify
*notify
)
77 struct nvkm_event
*event
= notify
->event
;
78 int ret
= notify
->func(notify
);
80 if ((ret
== NVKM_NOTIFY_KEEP
) ||
81 !test_and_clear_bit(NVKM_NOTIFY_USER
, ¬ify
->flags
)) {
82 spin_lock_irqsave(&event
->refs_lock
, flags
);
83 nvkm_notify_get_locked(notify
);
84 spin_unlock_irqrestore(&event
->refs_lock
, flags
);
89 nvkm_notify_work(struct work_struct
*work
)
91 struct nvkm_notify
*notify
= container_of(work
, typeof(*notify
), work
);
92 nvkm_notify_func(notify
);
96 nvkm_notify_send(struct nvkm_notify
*notify
, void *data
, u32 size
)
98 struct nvkm_event
*event
= notify
->event
;
101 assert_spin_locked(&event
->list_lock
);
102 BUG_ON(size
!= notify
->size
);
104 spin_lock_irqsave(&event
->refs_lock
, flags
);
106 spin_unlock_irqrestore(&event
->refs_lock
, flags
);
109 nvkm_notify_put_locked(notify
);
110 spin_unlock_irqrestore(&event
->refs_lock
, flags
);
112 if (test_bit(NVKM_NOTIFY_WORK
, ¬ify
->flags
)) {
113 memcpy((void *)notify
->data
, data
, size
);
114 schedule_work(¬ify
->work
);
117 nvkm_notify_func(notify
);
123 nvkm_notify_fini(struct nvkm_notify
*notify
)
127 nvkm_notify_put(notify
);
128 spin_lock_irqsave(¬ify
->event
->list_lock
, flags
);
129 list_del(¬ify
->head
);
130 spin_unlock_irqrestore(¬ify
->event
->list_lock
, flags
);
131 kfree((void *)notify
->data
);
132 notify
->event
= NULL
;
137 nvkm_notify_init(struct nouveau_object
*object
, struct nvkm_event
*event
,
138 int (*func
)(struct nvkm_notify
*), bool work
,
139 void *data
, u32 size
, u32 reply
,
140 struct nvkm_notify
*notify
)
144 if ((notify
->event
= event
), event
->refs
) {
145 ret
= event
->func
->ctor(object
, data
, size
, notify
);
146 if (ret
== 0 && (ret
= -EINVAL
, notify
->size
== reply
)) {
152 INIT_WORK(¬ify
->work
, nvkm_notify_work
);
153 set_bit(NVKM_NOTIFY_WORK
, ¬ify
->flags
);
154 notify
->data
= kmalloc(reply
, GFP_KERNEL
);
160 spin_lock_irqsave(&event
->list_lock
, flags
);
161 list_add_tail(¬ify
->head
, &event
->list
);
162 spin_unlock_irqrestore(&event
->list_lock
, flags
);
166 notify
->event
= NULL
;
This page took 0.066591 seconds and 5 git commands to generate.