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