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>
45 NVKM_ENGINE_CE_LAST = NVKM_ENGINE_CE8,
63 NVKM_ENGINE_NVENC_LAST = NVKM_ENGINE_NVENC2,
68 NVKM_ENGINE_NVDEC_LAST = NVKM_ENGINE_NVDEC2,
80 enum nvkm_device_type {
88 const struct nvkm_device_func *func;
89 const struct nvkm_device_quirk *quirk;
91 enum nvkm_device_type type;
97 struct list_head head;
103 struct nvkm_event event;
108 const struct nvkm_device_chip *chip;
130 struct notifier_block nb;
133 struct nvkm_acr *acr;
134 struct nvkm_bar *bar;
135 struct nvkm_bios *bios;
136 struct nvkm_bus *bus;
137 struct nvkm_clk *clk;
138 struct nvkm_devinit *devinit;
139 struct nvkm_fault *fault;
141 struct nvkm_fuse *fuse;
142 struct nvkm_gpio *gpio;
143 struct nvkm_gsp *gsp;
144 struct nvkm_i2c *i2c;
145 struct nvkm_subdev *ibus;
146 struct nvkm_iccsense *iccsense;
147 struct nvkm_instmem *imem;
148 struct nvkm_ltc *ltc;
150 struct nvkm_mmu *mmu;
151 struct nvkm_subdev *mxm;
152 struct nvkm_pci *pci;
153 struct nvkm_pmu *pmu;
154 struct nvkm_therm *therm;
155 struct nvkm_timer *timer;
156 struct nvkm_top *top;
157 struct nvkm_volt *volt;
159 struct nvkm_engine *bsp;
160 struct nvkm_engine *ce[9];
161 struct nvkm_engine *cipher;
162 struct nvkm_disp *disp;
163 struct nvkm_dma *dma;
164 struct nvkm_fifo *fifo;
166 struct nvkm_engine *ifb;
167 struct nvkm_engine *me;
168 struct nvkm_engine *mpeg;
169 struct nvkm_engine *msenc;
170 struct nvkm_engine *mspdec;
171 struct nvkm_engine *msppp;
172 struct nvkm_engine *msvld;
173 struct nvkm_nvenc *nvenc[3];
174 struct nvkm_nvdec *nvdec[3];
176 struct nvkm_engine *sec;
177 struct nvkm_sec2 *sec2;
179 struct nvkm_engine *vic;
180 struct nvkm_engine *vp;
183 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int index);
184 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int index);
186 struct nvkm_device_func {
187 struct nvkm_device_pci *(*pci)(struct nvkm_device *);
188 struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
189 void *(*dtor)(struct nvkm_device *);
190 int (*preinit)(struct nvkm_device *);
191 int (*init)(struct nvkm_device *);
192 void (*fini)(struct nvkm_device *, bool suspend);
193 resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
194 resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
198 struct nvkm_device_quirk {
203 struct nvkm_device_chip {
206 int (*acr )(struct nvkm_device *, int idx, struct nvkm_acr **);
207 int (*bar )(struct nvkm_device *, int idx, struct nvkm_bar **);
208 int (*bios )(struct nvkm_device *, int idx, struct nvkm_bios **);
209 int (*bus )(struct nvkm_device *, int idx, struct nvkm_bus **);
210 int (*clk )(struct nvkm_device *, int idx, struct nvkm_clk **);
211 int (*devinit )(struct nvkm_device *, int idx, struct nvkm_devinit **);
212 int (*fault )(struct nvkm_device *, int idx, struct nvkm_fault **);
213 int (*fb )(struct nvkm_device *, int idx, struct nvkm_fb **);
214 int (*fuse )(struct nvkm_device *, int idx, struct nvkm_fuse **);
215 int (*gpio )(struct nvkm_device *, int idx, struct nvkm_gpio **);
216 int (*gsp )(struct nvkm_device *, int idx, struct nvkm_gsp **);
217 int (*i2c )(struct nvkm_device *, int idx, struct nvkm_i2c **);
218 int (*ibus )(struct nvkm_device *, int idx, struct nvkm_subdev **);
219 int (*iccsense)(struct nvkm_device *, int idx, struct nvkm_iccsense **);
220 int (*imem )(struct nvkm_device *, int idx, struct nvkm_instmem **);
221 int (*ltc )(struct nvkm_device *, int idx, struct nvkm_ltc **);
222 int (*mc )(struct nvkm_device *, int idx, struct nvkm_mc **);
223 int (*mmu )(struct nvkm_device *, int idx, struct nvkm_mmu **);
224 int (*mxm )(struct nvkm_device *, int idx, struct nvkm_subdev **);
225 int (*pci )(struct nvkm_device *, int idx, struct nvkm_pci **);
226 int (*pmu )(struct nvkm_device *, int idx, struct nvkm_pmu **);
227 int (*therm )(struct nvkm_device *, int idx, struct nvkm_therm **);
228 int (*timer )(struct nvkm_device *, int idx, struct nvkm_timer **);
229 int (*top )(struct nvkm_device *, int idx, struct nvkm_top **);
230 int (*volt )(struct nvkm_device *, int idx, struct nvkm_volt **);
232 int (*bsp )(struct nvkm_device *, int idx, struct nvkm_engine **);
233 int (*ce[9] )(struct nvkm_device *, int idx, struct nvkm_engine **);
234 int (*cipher )(struct nvkm_device *, int idx, struct nvkm_engine **);
235 int (*disp )(struct nvkm_device *, int idx, struct nvkm_disp **);
236 int (*dma )(struct nvkm_device *, int idx, struct nvkm_dma **);
237 int (*fifo )(struct nvkm_device *, int idx, struct nvkm_fifo **);
238 int (*gr )(struct nvkm_device *, int idx, struct nvkm_gr **);
239 int (*ifb )(struct nvkm_device *, int idx, struct nvkm_engine **);
240 int (*me )(struct nvkm_device *, int idx, struct nvkm_engine **);
241 int (*mpeg )(struct nvkm_device *, int idx, struct nvkm_engine **);
242 int (*msenc )(struct nvkm_device *, int idx, struct nvkm_engine **);
243 int (*mspdec )(struct nvkm_device *, int idx, struct nvkm_engine **);
244 int (*msppp )(struct nvkm_device *, int idx, struct nvkm_engine **);
245 int (*msvld )(struct nvkm_device *, int idx, struct nvkm_engine **);
246 int (*nvenc[3])(struct nvkm_device *, int idx, struct nvkm_nvenc **);
247 int (*nvdec[3])(struct nvkm_device *, int idx, struct nvkm_nvdec **);
248 int (*pm )(struct nvkm_device *, int idx, struct nvkm_pm **);
249 int (*sec )(struct nvkm_device *, int idx, struct nvkm_engine **);
250 int (*sec2 )(struct nvkm_device *, int idx, struct nvkm_sec2 **);
251 int (*sw )(struct nvkm_device *, int idx, struct nvkm_sw **);
252 int (*vic )(struct nvkm_device *, int idx, struct nvkm_engine **);
253 int (*vp )(struct nvkm_device *, int idx, struct nvkm_engine **);
256 struct nvkm_device *nvkm_device_find(u64 name);
257 int nvkm_device_list(u64 *name, int size);
259 /* privileged register interface accessor macros */
260 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
261 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
262 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
263 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
264 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
265 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
266 #define nvkm_mask(d,a,m,v) ({ \
267 struct nvkm_device *_device = (d); \
268 u32 _addr = (a), _temp = nvkm_rd32(_device, _addr); \
269 nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v)); \
273 void nvkm_device_del(struct nvkm_device **);
275 struct nvkm_device_oclass {
276 int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
277 void *data, u32 size, struct nvkm_object **);
278 struct nvkm_sclass base;
281 extern const struct nvkm_sclass nvkm_udevice_sclass;
284 #define nvdev_printk_(d,l,p,f,a...) do { \
285 const struct nvkm_device *_device = (d); \
286 if (_device->debug >= (l)) \
287 dev_##p(_device->dev, f, ##a); \
289 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
290 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL, crit, f, ##a)
291 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR, err, f, ##a)
292 #define nvdev_warn(d,f,a...) nvdev_printk((d), WARN, notice, f, ##a)
293 #define nvdev_info(d,f,a...) nvdev_printk((d), INFO, info, f, ##a)
294 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG, info, f, ##a)
295 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE, info, f, ##a)
296 #define nvdev_spam(d,f,a...) nvdev_printk((d), SPAM, dbg, f, ##a)