posix-clock: Fix return code on the poll method's error path
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / include / nvkm / subdev / timer.h
blob82d3e28918fd11fbf8ab18c0b70c8a1fedec5e50
1 #ifndef __NVKM_TIMER_H__
2 #define __NVKM_TIMER_H__
3 #include <core/subdev.h>
5 struct nvkm_alarm {
6 struct list_head head;
7 u64 timestamp;
8 void (*func)(struct nvkm_alarm *);
9 };
11 static inline void
12 nvkm_alarm_init(struct nvkm_alarm *alarm, void (*func)(struct nvkm_alarm *))
14 INIT_LIST_HEAD(&alarm->head);
15 alarm->func = func;
18 struct nvkm_timer {
19 const struct nvkm_timer_func *func;
20 struct nvkm_subdev subdev;
22 struct list_head alarms;
23 spinlock_t lock;
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); \
43 s64 _taken = 0; \
44 bool _warn = true; \
46 do { \
47 cond \
48 } while (_taken = nvkm_timer_read(_tmr) - _time0, _taken < _nsecs); \
50 if (_taken >= _nsecs) { \
51 if (_warn) { \
52 dev_warn(_device->dev, "timeout at %s:%d/%s()!\n", \
53 __FILE__, __LINE__, __func__); \
54 } \
55 _taken = -ETIMEDOUT; \
56 } \
57 _taken; \
59 #define nvkm_usec(d,u,cond...) nvkm_nsec((d), (u) * 1000, ##cond)
60 #define nvkm_msec(d,m,cond...) nvkm_usec((d), (m) * 1000, ##cond)
62 #define nvkm_wait_nsec(d,n,addr,mask,data) \
63 nvkm_nsec(d, n, \
64 if ((nvkm_rd32(d, (addr)) & (mask)) == (data)) \
65 break; \
67 #define nvkm_wait_usec(d,u,addr,mask,data) \
68 nvkm_wait_nsec((d), (u) * 1000, (addr), (mask), (data))
69 #define nvkm_wait_msec(d,m,addr,mask,data) \
70 nvkm_wait_usec((d), (m) * 1000, (addr), (mask), (data))
72 int nv04_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
73 int nv40_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
74 int nv41_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
75 int gk20a_timer_new(struct nvkm_device *, int, struct nvkm_timer **);
76 #endif