1 #ifndef __NVKM_TIMER_H__
2 #define __NVKM_TIMER_H__
3 #include <core/subdev.h>
8 void (*func)(struct nvkm_alarm *);
12 nvkm_alarm_init(struct nvkm_alarm *alarm, void (*func)(struct nvkm_alarm *))
14 INIT_LIST_HEAD(&alarm->head);
19 const struct nvkm_timer_func *func;
20 struct nvkm_subdev subdev;
22 struct list_head alarms;
26 u64 nvkm_timer_read(struct nvkm_timer *);
27 void nvkm_timer_alarm(struct nvkm_timer *, u32 nsec, struct nvkm_alarm *);
28 void nvkm_timer_alarm_cancel(struct nvkm_timer *, struct nvkm_alarm *);
30 /* Delay based on GPU time (ie. PTIMER).
32 * Will return -ETIMEDOUT unless the loop was terminated with 'break',
33 * where it will return the number of nanoseconds taken instead.
35 * NVKM_DELAY can be passed for 'cond' to disable the timeout warning,
36 * which is useful for unconditional delay loops.
38 #define NVKM_DELAY _warn = false;
39 #define nvkm_nsec(d,n,cond...) ({ \
40 struct nvkm_device *_device = (d); \
41 struct nvkm_timer *_tmr = _device->timer; \
42 u64 _nsecs = (n), _time0 = nvkm_timer_read(_tmr); \
48 } while (_taken = nvkm_timer_read(_tmr) - _time0, _taken < _nsecs); \
50 if (_taken >= _nsecs) { \
52 dev_WARN(_device->dev, "timeout\n"); \
53 _taken = -ETIMEDOUT; \
57 #define nvkm_usec(d,u,cond...) nvkm_nsec((d), (u) * 1000, ##cond)
58 #define nvkm_msec(d,m,cond...) nvkm_usec((d), (m) * 1000, ##cond)
60 #define nvkm_wait_nsec(d,n,addr,mask,data) \
62 if ((nvkm_rd32(d, (addr)) & (mask)) == (data)) \
65 #define nvkm_wait_usec(d,u,addr,mask,data) \
66 nvkm_wait_nsec((d), (u) * 1000, (addr), (mask), (data))
67 #define nvkm_wait_msec(d,m,addr,mask,data) \
68 nvkm_wait_usec((d), (m) * 1000, (addr), (mask), (data))
70 int nv04_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
71 int nv40_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
72 int nv41_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
73 int gk20a_timer_new(struct nvkm_device *, int, struct nvkm_timer **);