1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_TIMER_H__
3 #define __NVKM_TIMER_H__
4 #include <core/subdev.h>
10 void (*func)(struct nvkm_alarm *);
14 nvkm_alarm_init(struct nvkm_alarm *alarm, void (*func)(struct nvkm_alarm *))
16 INIT_LIST_HEAD(&alarm->head);
21 const struct nvkm_timer_func *func;
22 struct nvkm_subdev subdev;
24 struct list_head alarms;
28 u64 nvkm_timer_read(struct nvkm_timer *);
29 void nvkm_timer_alarm(struct nvkm_timer *, u32 nsec, struct nvkm_alarm *);
31 struct nvkm_timer_wait {
32 struct nvkm_timer *tmr;
39 void nvkm_timer_wait_init(struct nvkm_device *, u64 nsec,
40 struct nvkm_timer_wait *);
41 s64 nvkm_timer_wait_test(struct nvkm_timer_wait *);
43 /* Delay based on GPU time (ie. PTIMER).
45 * Will return -ETIMEDOUT unless the loop was terminated with 'break',
46 * where it will return the number of nanoseconds taken instead.
48 * NVKM_DELAY can be passed for 'cond' to disable the timeout warning,
49 * which is useful for unconditional delay loops.
51 #define NVKM_DELAY _warn = false;
52 #define nvkm_nsec(d,n,cond...) ({ \
53 struct nvkm_timer_wait _wait; \
57 nvkm_timer_wait_init((d), (n), &_wait); \
60 } while ((_taken = nvkm_timer_wait_test(&_wait)) >= 0); \
62 if (_warn && _taken < 0) \
63 dev_WARN(_wait.tmr->subdev.device->dev, "timeout\n"); \
66 #define nvkm_usec(d,u,cond...) nvkm_nsec((d), (u) * 1000, ##cond)
67 #define nvkm_msec(d,m,cond...) nvkm_usec((d), (m) * 1000, ##cond)
69 #define nvkm_wait_nsec(d,n,addr,mask,data) \
71 if ((nvkm_rd32(d, (addr)) & (mask)) == (data)) \
74 #define nvkm_wait_usec(d,u,addr,mask,data) \
75 nvkm_wait_nsec((d), (u) * 1000, (addr), (mask), (data))
76 #define nvkm_wait_msec(d,m,addr,mask,data) \
77 nvkm_wait_usec((d), (m) * 1000, (addr), (mask), (data))
79 int nv04_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
80 int nv40_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
81 int nv41_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
82 int gk20a_timer_new(struct nvkm_device *, int, struct nvkm_timer **);