| 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 |
| 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 | void nouveau_timer_alarm_cancel(void *, struct nouveau_alarm *); |
| 26 | |
| 27 | #define NV_WAIT_DEFAULT 2000000000ULL |
| 28 | #define nv_wait(o,a,m,v) \ |
| 29 | nouveau_timer_wait_eq((o), NV_WAIT_DEFAULT, (a), (m), (v)) |
| 30 | #define nv_wait_ne(o,a,m,v) \ |
| 31 | nouveau_timer_wait_ne((o), NV_WAIT_DEFAULT, (a), (m), (v)) |
| 32 | #define nv_wait_cb(o,c,d) \ |
| 33 | nouveau_timer_wait_cb((o), NV_WAIT_DEFAULT, (c), (d)) |
| 34 | |
| 35 | struct nouveau_timer { |
| 36 | struct nouveau_subdev base; |
| 37 | u64 (*read)(struct nouveau_timer *); |
| 38 | void (*alarm)(struct nouveau_timer *, u64 time, struct nouveau_alarm *); |
| 39 | void (*alarm_cancel)(struct nouveau_timer *, struct nouveau_alarm *); |
| 40 | }; |
| 41 | |
| 42 | static inline struct nouveau_timer * |
| 43 | nouveau_timer(void *obj) |
| 44 | { |
| 45 | return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_TIMER]; |
| 46 | } |
| 47 | |
| 48 | #define nouveau_timer_create(p,e,o,d) \ |
| 49 | nouveau_subdev_create_((p), (e), (o), 0, "PTIMER", "timer", \ |
| 50 | sizeof(**d), (void **)d) |
| 51 | #define nouveau_timer_destroy(p) \ |
| 52 | nouveau_subdev_destroy(&(p)->base) |
| 53 | #define nouveau_timer_init(p) \ |
| 54 | nouveau_subdev_init(&(p)->base) |
| 55 | #define nouveau_timer_fini(p,s) \ |
| 56 | nouveau_subdev_fini(&(p)->base, (s)) |
| 57 | |
| 58 | int nouveau_timer_create_(struct nouveau_object *, struct nouveau_engine *, |
| 59 | struct nouveau_oclass *, int size, void **); |
| 60 | |
| 61 | extern struct nouveau_oclass nv04_timer_oclass; |
| 62 | extern struct nouveau_oclass gk20a_timer_oclass; |
| 63 | |
| 64 | #endif |
| 65 | |