1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_DEVICE_H__
3 #define __NVKM_DEVICE_H__
4 #include <core/oclass.h>
5 #include <core/event.h>
8 #define nvkm_devidx nvkm_subdev_type
10 enum nvkm_device_type {
18 const struct nvkm_device_func *func;
19 const struct nvkm_device_quirk *quirk;
21 enum nvkm_device_type type;
27 struct list_head head;
33 struct nvkm_event event;
38 const struct nvkm_device_chip *chip;
60 struct notifier_block nb;
64 struct nvkm_therm *therm;
65 struct nvkm_timer *timer;
67 struct nvkm_volt *volt;
69 struct nvkm_engine *bsp;
70 struct nvkm_engine *ce[9];
71 struct nvkm_engine *cipher;
72 struct nvkm_disp *disp;
74 struct nvkm_fifo *fifo;
76 struct nvkm_engine *ifb;
77 struct nvkm_engine *me;
78 struct nvkm_engine *mpeg;
79 struct nvkm_engine *msenc;
80 struct nvkm_engine *mspdec;
81 struct nvkm_engine *msppp;
82 struct nvkm_engine *msvld;
83 struct nvkm_nvenc *nvenc[3];
84 struct nvkm_nvdec *nvdec[3];
86 struct nvkm_engine *sec;
87 struct nvkm_sec2 *sec2;
89 struct nvkm_engine *vic;
90 struct nvkm_engine *vp;
92 #define NVKM_LAYOUT_ONCE(type,data,ptr) data *ptr;
93 #define NVKM_LAYOUT_INST(type,data,ptr,cnt) data *ptr[cnt];
94 #include <core/layout.h>
95 #undef NVKM_LAYOUT_INST
96 #undef NVKM_LAYOUT_ONCE
97 struct list_head subdev;
100 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int type, int inst);
101 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int type, int inst);
103 struct nvkm_device_func {
104 struct nvkm_device_pci *(*pci)(struct nvkm_device *);
105 struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
106 void *(*dtor)(struct nvkm_device *);
107 int (*preinit)(struct nvkm_device *);
108 int (*init)(struct nvkm_device *);
109 void (*fini)(struct nvkm_device *, bool suspend);
110 resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
111 resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
115 struct nvkm_device_quirk {
120 struct nvkm_device_chip {
122 #define NVKM_LAYOUT_ONCE(type,data,ptr,...) \
125 int (*ctor)(struct nvkm_device *, enum nvkm_subdev_type, int inst, data **); \
127 #define NVKM_LAYOUT_INST(A...) NVKM_LAYOUT_ONCE(A)
128 #include <core/layout.h>
129 #undef NVKM_LAYOUT_INST
130 #undef NVKM_LAYOUT_ONCE
131 int (*pmu )(struct nvkm_device *, int idx, struct nvkm_pmu **);
132 int (*therm )(struct nvkm_device *, int idx, struct nvkm_therm **);
133 int (*timer )(struct nvkm_device *, int idx, struct nvkm_timer **);
134 int (*top )(struct nvkm_device *, int idx, struct nvkm_top **);
135 int (*volt )(struct nvkm_device *, int idx, struct nvkm_volt **);
137 int (*bsp )(struct nvkm_device *, int idx, struct nvkm_engine **);
138 int (*ce[9] )(struct nvkm_device *, int idx, struct nvkm_engine **);
139 int (*cipher )(struct nvkm_device *, int idx, struct nvkm_engine **);
140 int (*disp )(struct nvkm_device *, int idx, struct nvkm_disp **);
141 int (*dma )(struct nvkm_device *, int idx, struct nvkm_dma **);
142 int (*fifo )(struct nvkm_device *, int idx, struct nvkm_fifo **);
143 int (*gr )(struct nvkm_device *, int idx, struct nvkm_gr **);
144 int (*ifb )(struct nvkm_device *, int idx, struct nvkm_engine **);
145 int (*me )(struct nvkm_device *, int idx, struct nvkm_engine **);
146 int (*mpeg )(struct nvkm_device *, int idx, struct nvkm_engine **);
147 int (*msenc )(struct nvkm_device *, int idx, struct nvkm_engine **);
148 int (*mspdec )(struct nvkm_device *, int idx, struct nvkm_engine **);
149 int (*msppp )(struct nvkm_device *, int idx, struct nvkm_engine **);
150 int (*msvld )(struct nvkm_device *, int idx, struct nvkm_engine **);
151 int (*nvenc[3])(struct nvkm_device *, int idx, struct nvkm_nvenc **);
152 int (*nvdec[3])(struct nvkm_device *, int idx, struct nvkm_nvdec **);
153 int (*pm )(struct nvkm_device *, int idx, struct nvkm_pm **);
154 int (*sec )(struct nvkm_device *, int idx, struct nvkm_engine **);
155 int (*sec2 )(struct nvkm_device *, int idx, struct nvkm_sec2 **);
156 int (*sw )(struct nvkm_device *, int idx, struct nvkm_sw **);
157 int (*vic )(struct nvkm_device *, int idx, struct nvkm_engine **);
158 int (*vp )(struct nvkm_device *, int idx, struct nvkm_engine **);
161 struct nvkm_device *nvkm_device_find(u64 name);
162 int nvkm_device_list(u64 *name, int size);
164 /* privileged register interface accessor macros */
165 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
166 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
167 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
168 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
169 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
170 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
171 #define nvkm_mask(d,a,m,v) ({ \
172 struct nvkm_device *_device = (d); \
173 u32 _addr = (a), _temp = nvkm_rd32(_device, _addr); \
174 nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v)); \
178 void nvkm_device_del(struct nvkm_device **);
180 struct nvkm_device_oclass {
181 int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
182 void *data, u32 size, struct nvkm_object **);
183 struct nvkm_sclass base;
186 extern const struct nvkm_sclass nvkm_udevice_sclass;
189 #define nvdev_printk_(d,l,p,f,a...) do { \
190 const struct nvkm_device *_device = (d); \
191 if (_device->debug >= (l)) \
192 dev_##p(_device->dev, f, ##a); \
194 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
195 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL, crit, f, ##a)
196 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR, err, f, ##a)
197 #define nvdev_warn(d,f,a...) nvdev_printk((d), WARN, notice, f, ##a)
198 #define nvdev_info(d,f,a...) nvdev_printk((d), INFO, info, f, ##a)
199 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG, info, f, ##a)
200 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE, info, f, ##a)
201 #define nvdev_spam(d,f,a...) nvdev_printk((d), SPAM, dbg, f, ##a)