drm/nouveau: port remainder of drm code, and rip out compat layer
[cascardo/linux.git] / drivers / gpu / drm / nouveau / core / include / subdev / timer.h
1 #ifndef __NOUVEAU_TIMER_H__
2 #define __NOUVEAU_TIMER_H__
3
4 #include <core/subdev.h>
5 #include <core/device.h>
6
7 struct nouveau_alarm {
8         struct list_head head;
9         u64 timestamp;
10         void (*func)(struct nouveau_alarm *);
11 };
12
13 bool nouveau_timer_wait_eq(void *, u64 nsec, u32 addr, u32 mask, u32 data);
14 bool nouveau_timer_wait_ne(void *, u64 nsec, u32 addr, u32 mask, u32 data);
15 bool nouveau_timer_wait_cb(void *, u64 nsec, bool (*func)(void *), void *data);
16 void nouveau_timer_alarm(void *, u32 nsec, struct nouveau_alarm *);
17
18 #define NV_WAIT_DEFAULT 2000000000ULL
19 #define nv_wait(o,a,m,v)                                                       \
20         nouveau_timer_wait_eq((o), NV_WAIT_DEFAULT, (a), (m), (v))
21 #define nv_wait_ne(o,a,m,v)                                                    \
22         nouveau_timer_wait_ne((o), NV_WAIT_DEFAULT, (a), (m), (v))
23 #define nv_wait_cb(o,c,d)                                                      \
24         nouveau_timer_wait_cb((o), NV_WAIT_DEFAULT, (c), (d))
25
26 struct nouveau_timer {
27         struct nouveau_subdev base;
28         u64  (*read)(struct nouveau_timer *);
29         void (*alarm)(struct nouveau_timer *, u32 time, struct nouveau_alarm *);
30 };
31
32 static inline struct nouveau_timer *
33 nouveau_timer(void *obj)
34 {
35         return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_TIMER];
36 }
37
38 #define nouveau_timer_create(p,e,o,d)                                          \
39         nouveau_subdev_create_((p), (e), (o), 0, "PTIMER", "timer",            \
40                                sizeof(**d), (void **)d)
41 #define nouveau_timer_destroy(p)                                               \
42         nouveau_subdev_destroy(&(p)->base)
43 #define nouveau_timer_init(p)                                                  \
44         nouveau_subdev_init(&(p)->base)
45 #define nouveau_timer_fini(p,s)                                                \
46         nouveau_subdev_fini(&(p)->base, (s))
47
48 int nouveau_timer_create_(struct nouveau_object *, struct nouveau_engine *,
49                           struct nouveau_oclass *, int size, void **);
50
51 extern struct nouveau_oclass nv04_timer_oclass;
52
53 #endif