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> 6 7 enum nvkm_devidx { 8 NVKM_SUBDEV_PCI, 9 NVKM_SUBDEV_VBIOS, 10 NVKM_SUBDEV_DEVINIT, 11 NVKM_SUBDEV_TOP, 12 NVKM_SUBDEV_IBUS, 13 NVKM_SUBDEV_GPIO, 14 NVKM_SUBDEV_I2C, 15 NVKM_SUBDEV_FUSE, 16 NVKM_SUBDEV_MXM, 17 NVKM_SUBDEV_MC, 18 NVKM_SUBDEV_BUS, 19 NVKM_SUBDEV_TIMER, 20 NVKM_SUBDEV_INSTMEM, 21 NVKM_SUBDEV_FB, 22 NVKM_SUBDEV_LTC, 23 NVKM_SUBDEV_MMU, 24 NVKM_SUBDEV_BAR, 25 NVKM_SUBDEV_FAULT, 26 NVKM_SUBDEV_PMU, 27 NVKM_SUBDEV_VOLT, 28 NVKM_SUBDEV_ICCSENSE, 29 NVKM_SUBDEV_THERM, 30 NVKM_SUBDEV_CLK, 31 NVKM_SUBDEV_GSP, 32 NVKM_SUBDEV_SECBOOT, 33 34 NVKM_ENGINE_BSP, 35 36 NVKM_ENGINE_CE0, 37 NVKM_ENGINE_CE1, 38 NVKM_ENGINE_CE2, 39 NVKM_ENGINE_CE3, 40 NVKM_ENGINE_CE4, 41 NVKM_ENGINE_CE5, 42 NVKM_ENGINE_CE6, 43 NVKM_ENGINE_CE7, 44 NVKM_ENGINE_CE8, 45 NVKM_ENGINE_CE_LAST = NVKM_ENGINE_CE8, 46 47 NVKM_ENGINE_CIPHER, 48 NVKM_ENGINE_DISP, 49 NVKM_ENGINE_DMAOBJ, 50 NVKM_ENGINE_FIFO, 51 NVKM_ENGINE_GR, 52 NVKM_ENGINE_IFB, 53 NVKM_ENGINE_ME, 54 NVKM_ENGINE_MPEG, 55 NVKM_ENGINE_MSENC, 56 NVKM_ENGINE_MSPDEC, 57 NVKM_ENGINE_MSPPP, 58 NVKM_ENGINE_MSVLD, 59 60 NVKM_ENGINE_NVENC0, 61 NVKM_ENGINE_NVENC1, 62 NVKM_ENGINE_NVENC2, 63 NVKM_ENGINE_NVENC_LAST = NVKM_ENGINE_NVENC2, 64 65 NVKM_ENGINE_NVDEC0, 66 NVKM_ENGINE_NVDEC1, 67 NVKM_ENGINE_NVDEC2, 68 NVKM_ENGINE_NVDEC_LAST = NVKM_ENGINE_NVDEC2, 69 70 NVKM_ENGINE_PM, 71 NVKM_ENGINE_SEC, 72 NVKM_ENGINE_SEC2, 73 NVKM_ENGINE_SW, 74 NVKM_ENGINE_VIC, 75 NVKM_ENGINE_VP, 76 77 NVKM_SUBDEV_NR 78 }; 79 80 enum nvkm_device_type { 81 NVKM_DEVICE_PCI, 82 NVKM_DEVICE_AGP, 83 NVKM_DEVICE_PCIE, 84 NVKM_DEVICE_TEGRA, 85 }; 86 87 struct nvkm_device { 88 const struct nvkm_device_func *func; 89 const struct nvkm_device_quirk *quirk; 90 struct device *dev; 91 enum nvkm_device_type type; 92 u64 handle; 93 const char *name; 94 const char *cfgopt; 95 const char *dbgopt; 96 97 struct list_head head; 98 struct mutex mutex; 99 int refcount; 100 101 void __iomem *pri; 102 103 struct nvkm_event event; 104 105 u64 disable_mask; 106 u32 debug; 107 108 const struct nvkm_device_chip *chip; 109 enum { 110 NV_04 = 0x04, 111 NV_10 = 0x10, 112 NV_11 = 0x11, 113 NV_20 = 0x20, 114 NV_30 = 0x30, 115 NV_40 = 0x40, 116 NV_50 = 0x50, 117 NV_C0 = 0xc0, 118 NV_E0 = 0xe0, 119 GM100 = 0x110, 120 GP100 = 0x130, 121 GV100 = 0x140, 122 TU100 = 0x160, 123 } card_type; 124 u32 chipset; 125 u8 chiprev; 126 u32 crystal; 127 128 struct { 129 struct notifier_block nb; 130 } acpi; 131 132 struct nvkm_bar *bar; 133 struct nvkm_bios *bios; 134 struct nvkm_bus *bus; 135 struct nvkm_clk *clk; 136 struct nvkm_devinit *devinit; 137 struct nvkm_fault *fault; 138 struct nvkm_fb *fb; 139 struct nvkm_fuse *fuse; 140 struct nvkm_gpio *gpio; 141 struct nvkm_gsp *gsp; 142 struct nvkm_i2c *i2c; 143 struct nvkm_subdev *ibus; 144 struct nvkm_iccsense *iccsense; 145 struct nvkm_instmem *imem; 146 struct nvkm_ltc *ltc; 147 struct nvkm_mc *mc; 148 struct nvkm_mmu *mmu; 149 struct nvkm_subdev *mxm; 150 struct nvkm_pci *pci; 151 struct nvkm_pmu *pmu; 152 struct nvkm_secboot *secboot; 153 struct nvkm_therm *therm; 154 struct nvkm_timer *timer; 155 struct nvkm_top *top; 156 struct nvkm_volt *volt; 157 158 struct nvkm_engine *bsp; 159 struct nvkm_engine *ce[9]; 160 struct nvkm_engine *cipher; 161 struct nvkm_disp *disp; 162 struct nvkm_dma *dma; 163 struct nvkm_fifo *fifo; 164 struct nvkm_gr *gr; 165 struct nvkm_engine *ifb; 166 struct nvkm_engine *me; 167 struct nvkm_engine *mpeg; 168 struct nvkm_engine *msenc; 169 struct nvkm_engine *mspdec; 170 struct nvkm_engine *msppp; 171 struct nvkm_engine *msvld; 172 struct nvkm_engine *nvenc[3]; 173 struct nvkm_nvdec *nvdec[3]; 174 struct nvkm_pm *pm; 175 struct nvkm_engine *sec; 176 struct nvkm_sec2 *sec2; 177 struct nvkm_sw *sw; 178 struct nvkm_engine *vic; 179 struct nvkm_engine *vp; 180 }; 181 182 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int index); 183 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int index); 184 185 struct nvkm_device_func { 186 struct nvkm_device_pci *(*pci)(struct nvkm_device *); 187 struct nvkm_device_tegra *(*tegra)(struct nvkm_device *); 188 void *(*dtor)(struct nvkm_device *); 189 int (*preinit)(struct nvkm_device *); 190 int (*init)(struct nvkm_device *); 191 void (*fini)(struct nvkm_device *, bool suspend); 192 resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar); 193 resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar); 194 bool cpu_coherent; 195 }; 196 197 struct nvkm_device_quirk { 198 u8 tv_pin_mask; 199 u8 tv_gpio; 200 }; 201 202 struct nvkm_device_chip { 203 const char *name; 204 205 int (*bar )(struct nvkm_device *, int idx, struct nvkm_bar **); 206 int (*bios )(struct nvkm_device *, int idx, struct nvkm_bios **); 207 int (*bus )(struct nvkm_device *, int idx, struct nvkm_bus **); 208 int (*clk )(struct nvkm_device *, int idx, struct nvkm_clk **); 209 int (*devinit )(struct nvkm_device *, int idx, struct nvkm_devinit **); 210 int (*fault )(struct nvkm_device *, int idx, struct nvkm_fault **); 211 int (*fb )(struct nvkm_device *, int idx, struct nvkm_fb **); 212 int (*fuse )(struct nvkm_device *, int idx, struct nvkm_fuse **); 213 int (*gpio )(struct nvkm_device *, int idx, struct nvkm_gpio **); 214 int (*gsp )(struct nvkm_device *, int idx, struct nvkm_gsp **); 215 int (*i2c )(struct nvkm_device *, int idx, struct nvkm_i2c **); 216 int (*ibus )(struct nvkm_device *, int idx, struct nvkm_subdev **); 217 int (*iccsense)(struct nvkm_device *, int idx, struct nvkm_iccsense **); 218 int (*imem )(struct nvkm_device *, int idx, struct nvkm_instmem **); 219 int (*ltc )(struct nvkm_device *, int idx, struct nvkm_ltc **); 220 int (*mc )(struct nvkm_device *, int idx, struct nvkm_mc **); 221 int (*mmu )(struct nvkm_device *, int idx, struct nvkm_mmu **); 222 int (*mxm )(struct nvkm_device *, int idx, struct nvkm_subdev **); 223 int (*pci )(struct nvkm_device *, int idx, struct nvkm_pci **); 224 int (*pmu )(struct nvkm_device *, int idx, struct nvkm_pmu **); 225 int (*secboot )(struct nvkm_device *, int idx, struct nvkm_secboot **); 226 int (*therm )(struct nvkm_device *, int idx, struct nvkm_therm **); 227 int (*timer )(struct nvkm_device *, int idx, struct nvkm_timer **); 228 int (*top )(struct nvkm_device *, int idx, struct nvkm_top **); 229 int (*volt )(struct nvkm_device *, int idx, struct nvkm_volt **); 230 231 int (*bsp )(struct nvkm_device *, int idx, struct nvkm_engine **); 232 int (*ce[9] )(struct nvkm_device *, int idx, struct nvkm_engine **); 233 int (*cipher )(struct nvkm_device *, int idx, struct nvkm_engine **); 234 int (*disp )(struct nvkm_device *, int idx, struct nvkm_disp **); 235 int (*dma )(struct nvkm_device *, int idx, struct nvkm_dma **); 236 int (*fifo )(struct nvkm_device *, int idx, struct nvkm_fifo **); 237 int (*gr )(struct nvkm_device *, int idx, struct nvkm_gr **); 238 int (*ifb )(struct nvkm_device *, int idx, struct nvkm_engine **); 239 int (*me )(struct nvkm_device *, int idx, struct nvkm_engine **); 240 int (*mpeg )(struct nvkm_device *, int idx, struct nvkm_engine **); 241 int (*msenc )(struct nvkm_device *, int idx, struct nvkm_engine **); 242 int (*mspdec )(struct nvkm_device *, int idx, struct nvkm_engine **); 243 int (*msppp )(struct nvkm_device *, int idx, struct nvkm_engine **); 244 int (*msvld )(struct nvkm_device *, int idx, struct nvkm_engine **); 245 int (*nvenc[3])(struct nvkm_device *, int idx, struct nvkm_engine **); 246 int (*nvdec[3])(struct nvkm_device *, int idx, struct nvkm_nvdec **); 247 int (*pm )(struct nvkm_device *, int idx, struct nvkm_pm **); 248 int (*sec )(struct nvkm_device *, int idx, struct nvkm_engine **); 249 int (*sec2 )(struct nvkm_device *, int idx, struct nvkm_sec2 **); 250 int (*sw )(struct nvkm_device *, int idx, struct nvkm_sw **); 251 int (*vic )(struct nvkm_device *, int idx, struct nvkm_engine **); 252 int (*vp )(struct nvkm_device *, int idx, struct nvkm_engine **); 253 }; 254 255 struct nvkm_device *nvkm_device_find(u64 name); 256 int nvkm_device_list(u64 *name, int size); 257 258 /* privileged register interface accessor macros */ 259 #define nvkm_rd08(d,a) ioread8((d)->pri + (a)) 260 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a)) 261 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a)) 262 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a)) 263 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a)) 264 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a)) 265 #define nvkm_mask(d,a,m,v) ({ \ 266 struct nvkm_device *_device = (d); \ 267 u32 _addr = (a), _temp = nvkm_rd32(_device, _addr); \ 268 nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v)); \ 269 _temp; \ 270 }) 271 272 void nvkm_device_del(struct nvkm_device **); 273 274 struct nvkm_device_oclass { 275 int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *, 276 void *data, u32 size, struct nvkm_object **); 277 struct nvkm_sclass base; 278 }; 279 280 extern const struct nvkm_sclass nvkm_udevice_sclass; 281 282 /* device logging */ 283 #define nvdev_printk_(d,l,p,f,a...) do { \ 284 const struct nvkm_device *_device = (d); \ 285 if (_device->debug >= (l)) \ 286 dev_##p(_device->dev, f, ##a); \ 287 } while(0) 288 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a) 289 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL, crit, f, ##a) 290 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR, err, f, ##a) 291 #define nvdev_warn(d,f,a...) nvdev_printk((d), WARN, notice, f, ##a) 292 #define nvdev_info(d,f,a...) nvdev_printk((d), INFO, info, f, ##a) 293 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG, info, f, ##a) 294 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE, info, f, ##a) 295 #define nvdev_spam(d,f,a...) nvdev_printk((d), SPAM, dbg, f, ##a) 296 #endif 297