1 /* SPDX-License-Identifier: GPL-2.0 */
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 /* Delay based on GPU time (ie. PTIMER).
33 * Will return -ETIMEDOUT unless the loop was terminated with 'break',
34 * where it will return the number of nanoseconds taken instead.
36 * NVKM_DELAY can be passed for 'cond' to disable the timeout warning,
37 * which is useful for unconditional delay loops.
39 #define NVKM_DELAY _warn = false;
40 #define nvkm_nsec(d,n,cond...) ({ \
41 struct nvkm_device *_device = (d); \
42 struct nvkm_timer *_tmr = _device->timer; \
43 u64 _nsecs = (n), _time0 = nvkm_timer_read(_tmr); \
49 } while (_taken = nvkm_timer_read(_tmr) - _time0, _taken < _nsecs); \
51 if (_taken >= _nsecs) { \
53 dev_WARN(_device->dev, "timeout\n"); \
54 _taken = -ETIMEDOUT; \
58 #define nvkm_usec(d,u,cond...) nvkm_nsec((d), (u) * 1000, ##cond)
59 #define nvkm_msec(d,m,cond...) nvkm_usec((d), (m) * 1000, ##cond)
61 #define nvkm_wait_nsec(d,n,addr,mask,data) \
63 if ((nvkm_rd32(d, (addr)) & (mask)) == (data)) \
66 #define nvkm_wait_usec(d,u,addr,mask,data) \
67 nvkm_wait_nsec((d), (u) * 1000, (addr), (mask), (data))
68 #define nvkm_wait_msec(d,m,addr,mask,data) \
69 nvkm_wait_usec((d), (m) * 1000, (addr), (mask), (data))
71 int nv04_timer_new(struct nvkm_device
*, int, struct nvkm_timer
**);
72 int nv40_timer_new(struct nvkm_device
*, int, struct nvkm_timer
**);
73 int nv41_timer_new(struct nvkm_device
*, int, struct nvkm_timer
**);
74 int gk20a_timer_new(struct nvkm_device
*, int, struct nvkm_timer
**);