1 /*	$NetBSD: device.h,v 1.3 2021/12/18 23:45:33 riastradh Exp $	*/
2 
3 /* SPDX-License-Identifier: MIT */
4 #ifndef __NVIF_DEVICE_H__
5 #define __NVIF_DEVICE_H__
6 
7 #include <nvif/object.h>
8 #include <nvif/cl0080.h>
9 #include <nvif/user.h>
10 
11 struct nvif_device {
12 	struct nvif_object object;
13 	struct nv_device_info_v0 info;
14 
15 	struct nvif_fifo_runlist {
16 		u64 engines;
17 	} *runlist;
18 	int runlists;
19 
20 	struct nvif_user user;
21 };
22 
23 int  nvif_device_init(struct nvif_object *, u32 handle, s32 oclass, void *, u32,
24 		      struct nvif_device *);
25 void nvif_device_fini(struct nvif_device *);
26 u64  nvif_device_time(struct nvif_device *);
27 
28 /* Delay based on GPU time (ie. PTIMER).
29  *
30  * Will return -ETIMEDOUT unless the loop was terminated with 'break',
31  * where it will return the number of nanoseconds taken instead.
32  */
33 #define nvif_nsec(d,n,cond...) ({                                              \
34 	struct nvif_device *_device = (d);                                     \
35 	u64 _nsecs = (n), _time0 = nvif_device_time(_device);                  \
36 	s64 _taken = 0;                                                        \
37                                                                                \
38 	do {                                                                   \
39 		cond                                                           \
40 	} while (_taken = nvif_device_time(_device) - _time0, _taken < _nsecs);\
41                                                                                \
42 	if (_taken >= _nsecs)                                                  \
43 		_taken = -ETIMEDOUT;                                           \
44 	_taken;                                                                \
45 })
46 #define nvif_usec(d,u,cond...) nvif_nsec((d), (u) * 1000, ##cond)
47 #define nvif_msec(d,m,cond...) nvif_usec((d), (m) * 1000, ##cond)
48 
49 /*XXX*/
50 #include <subdev/bios.h>
51 #include <subdev/fb.h>
52 #include <subdev/bar.h>
53 #include <subdev/gpio.h>
54 #include <subdev/clk.h>
55 #include <subdev/i2c.h>
56 #include <subdev/timer.h>
57 #include <subdev/therm.h>
58 #include <subdev/pci.h>
59 
60 #define nvxx_device(a) ({                                                      \
61 	struct nvif_device *_device = (a);                                     \
62 	struct {                                                               \
63 		struct nvkm_object object;                                     \
64 		struct nvkm_device *device;                                    \
65 	} *_udevice = _device->object.priv;                                    \
66 	_udevice->device;                                                      \
67 })
68 #define nvxx_bios(a) nvxx_device(a)->bios
69 #define nvxx_fb(a) nvxx_device(a)->fb
70 #define nvxx_gpio(a) nvxx_device(a)->gpio
71 #define nvxx_clk(a) nvxx_device(a)->clk
72 #define nvxx_i2c(a) nvxx_device(a)->i2c
73 #define nvxx_iccsense(a) nvxx_device(a)->iccsense
74 #define nvxx_therm(a) nvxx_device(a)->therm
75 #define nvxx_volt(a) nvxx_device(a)->volt
76 
77 #include <engine/fifo.h>
78 #include <engine/gr.h>
79 
80 #define nvxx_gr(a) nvxx_device(a)->gr
81 #endif
82