162306a36Sopenharmony_ci#ifndef __NVIF_TIMER_H__ 262306a36Sopenharmony_ci#define __NVIF_TIMER_H__ 362306a36Sopenharmony_ci#include <nvif/os.h> 462306a36Sopenharmony_ci 562306a36Sopenharmony_cistruct nvif_timer_wait { 662306a36Sopenharmony_ci struct nvif_device *device; 762306a36Sopenharmony_ci u64 limit; 862306a36Sopenharmony_ci u64 time0; 962306a36Sopenharmony_ci u64 time1; 1062306a36Sopenharmony_ci int reads; 1162306a36Sopenharmony_ci}; 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_civoid nvif_timer_wait_init(struct nvif_device *, u64 nsec, 1462306a36Sopenharmony_ci struct nvif_timer_wait *); 1562306a36Sopenharmony_cis64 nvif_timer_wait_test(struct nvif_timer_wait *); 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* Delay based on GPU time (ie. PTIMER). 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * Will return -ETIMEDOUT unless the loop was terminated with 'break', 2062306a36Sopenharmony_ci * where it will return the number of nanoseconds taken instead. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#define nvif_nsec(d,n,cond...) ({ \ 2362306a36Sopenharmony_ci struct nvif_timer_wait _wait; \ 2462306a36Sopenharmony_ci s64 _taken = 0; \ 2562306a36Sopenharmony_ci \ 2662306a36Sopenharmony_ci nvif_timer_wait_init((d), (n), &_wait); \ 2762306a36Sopenharmony_ci do { \ 2862306a36Sopenharmony_ci cond \ 2962306a36Sopenharmony_ci } while ((_taken = nvif_timer_wait_test(&_wait)) >= 0); \ 3062306a36Sopenharmony_ci \ 3162306a36Sopenharmony_ci _taken; \ 3262306a36Sopenharmony_ci}) 3362306a36Sopenharmony_ci#define nvif_usec(d,u,cond...) nvif_nsec((d), (u) * 1000, ##cond) 3462306a36Sopenharmony_ci#define nvif_msec(d,m,cond...) nvif_usec((d), (m) * 1000, ##cond) 3562306a36Sopenharmony_ci#endif 36