Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 #ifndef __NVKM_TIMER_H__
0003 #define __NVKM_TIMER_H__
0004 #include <core/subdev.h>
0005 
0006 struct nvkm_alarm {
0007     struct list_head head;
0008     struct list_head exec;
0009     u64 timestamp;
0010     void (*func)(struct nvkm_alarm *);
0011 };
0012 
0013 static inline void
0014 nvkm_alarm_init(struct nvkm_alarm *alarm, void (*func)(struct nvkm_alarm *))
0015 {
0016     INIT_LIST_HEAD(&alarm->head);
0017     alarm->func = func;
0018 }
0019 
0020 struct nvkm_timer {
0021     const struct nvkm_timer_func *func;
0022     struct nvkm_subdev subdev;
0023 
0024     struct list_head alarms;
0025     spinlock_t lock;
0026 };
0027 
0028 u64 nvkm_timer_read(struct nvkm_timer *);
0029 void nvkm_timer_alarm(struct nvkm_timer *, u32 nsec, struct nvkm_alarm *);
0030 
0031 struct nvkm_timer_wait {
0032     struct nvkm_timer *tmr;
0033     u64 limit;
0034     u64 time0;
0035     u64 time1;
0036     int reads;
0037 };
0038 
0039 void nvkm_timer_wait_init(struct nvkm_device *, u64 nsec,
0040               struct nvkm_timer_wait *);
0041 s64 nvkm_timer_wait_test(struct nvkm_timer_wait *);
0042 
0043 /* Delay based on GPU time (ie. PTIMER).
0044  *
0045  * Will return -ETIMEDOUT unless the loop was terminated with 'break',
0046  * where it will return the number of nanoseconds taken instead.
0047  *
0048  * NVKM_DELAY can be passed for 'cond' to disable the timeout warning,
0049  * which is useful for unconditional delay loops.
0050  */
0051 #define NVKM_DELAY _warn = false;
0052 #define nvkm_nsec(d,n,cond...) ({                                              \
0053     struct nvkm_timer_wait _wait;                                          \
0054     bool _warn = true;                                                     \
0055     s64 _taken = 0;                                                        \
0056                                                                                \
0057     nvkm_timer_wait_init((d), (n), &_wait);                                \
0058     do {                                                                   \
0059         cond                                                           \
0060     } while ((_taken = nvkm_timer_wait_test(&_wait)) >= 0);                \
0061                                                                                \
0062     if (_warn && _taken < 0)                                               \
0063         dev_WARN(_wait.tmr->subdev.device->dev, "timeout\n");          \
0064     _taken;                                                                \
0065 })
0066 #define nvkm_usec(d, u, cond...) nvkm_nsec((d), (u) * 1000ULL, ##cond)
0067 #define nvkm_msec(d, m, cond...) nvkm_usec((d), (m) * 1000ULL, ##cond)
0068 
0069 #define nvkm_wait_nsec(d,n,addr,mask,data)                                     \
0070     nvkm_nsec(d, n,                                                        \
0071         if ((nvkm_rd32(d, (addr)) & (mask)) == (data))                 \
0072             break;                                                 \
0073         )
0074 #define nvkm_wait_usec(d,u,addr,mask,data)                                     \
0075     nvkm_wait_nsec((d), (u) * 1000, (addr), (mask), (data))
0076 #define nvkm_wait_msec(d,m,addr,mask,data)                                     \
0077     nvkm_wait_usec((d), (m) * 1000, (addr), (mask), (data))
0078 
0079 int nv04_timer_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_timer **);
0080 int nv40_timer_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_timer **);
0081 int nv41_timer_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_timer **);
0082 int gk20a_timer_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_timer **);
0083 #endif