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