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 static inline void
nouveau_alarm_init(struct nouveau_alarm * alarm,void (* func)(struct nouveau_alarm *))14 nouveau_alarm_init(struct nouveau_alarm *alarm,
15 void (*func)(struct nouveau_alarm *))
16 {
17 INIT_LIST_HEAD(&alarm->head);
18 alarm->func = func;
19 }
20
21 bool nouveau_timer_wait_eq(void *, u64 nsec, u32 addr, u32 mask, u32 data);
22 bool nouveau_timer_wait_ne(void *, u64 nsec, u32 addr, u32 mask, u32 data);
23 bool nouveau_timer_wait_cb(void *, u64 nsec, bool (*func)(void *), void *data);
24 void nouveau_timer_alarm(void *, u32 nsec, struct nouveau_alarm *);
25
26 #define NV_WAIT_DEFAULT 2000000000ULL
27 #define nv_wait(o,a,m,v) \
28 nouveau_timer_wait_eq((o), NV_WAIT_DEFAULT, (a), (m), (v))
29 #define nv_wait_ne(o,a,m,v) \
30 nouveau_timer_wait_ne((o), NV_WAIT_DEFAULT, (a), (m), (v))
31 #define nv_wait_cb(o,c,d) \
32 nouveau_timer_wait_cb((o), NV_WAIT_DEFAULT, (c), (d))
33
34 struct nouveau_timer {
35 struct nouveau_subdev base;
36 u64 (*read)(struct nouveau_timer *);
37 void (*alarm)(struct nouveau_timer *, u64 time, struct nouveau_alarm *);
38 };
39
40 static inline struct nouveau_timer *
nouveau_timer(void * obj)41 nouveau_timer(void *obj)
42 {
43 return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_TIMER];
44 }
45
46 #define nouveau_timer_create(p,e,o,d) \
47 nouveau_subdev_create_((p), (e), (o), 0, "PTIMER", "timer", \
48 sizeof(**d), (void **)d)
49 #define nouveau_timer_destroy(p) \
50 nouveau_subdev_destroy(&(p)->base)
51 #define nouveau_timer_init(p) \
52 nouveau_subdev_init(&(p)->base)
53 #define nouveau_timer_fini(p,s) \
54 nouveau_subdev_fini(&(p)->base, (s))
55
56 int nouveau_timer_create_(struct nouveau_object *, struct nouveau_engine *,
57 struct nouveau_oclass *, int size, void **);
58
59 extern struct nouveau_oclass nv04_timer_oclass;
60
61 #endif
62