1 /* SPDX-License-Identifier: MIT */ 2 #ifndef __NVKM_DEVICE_H__ 3 #define __NVKM_DEVICE_H__ 4 #include <core/oclass.h> 5 enum nvkm_subdev_type; 6 7 enum nvkm_device_type { 8 NVKM_DEVICE_PCI, 9 NVKM_DEVICE_AGP, 10 NVKM_DEVICE_PCIE, 11 NVKM_DEVICE_TEGRA, 12 }; 13 14 struct nvkm_device { 15 const struct nvkm_device_func *func; 16 const struct nvkm_device_quirk *quirk; 17 struct device *dev; 18 enum nvkm_device_type type; 19 u64 handle; 20 const char *name; 21 const char *cfgopt; 22 const char *dbgopt; 23 24 struct list_head head; 25 struct mutex mutex; 26 int refcount; 27 28 void __iomem *pri; 29 30 u32 debug; 31 32 const struct nvkm_device_chip *chip; 33 enum { 34 NV_04 = 0x04, 35 NV_10 = 0x10, 36 NV_11 = 0x11, 37 NV_20 = 0x20, 38 NV_30 = 0x30, 39 NV_40 = 0x40, 40 NV_50 = 0x50, 41 NV_C0 = 0xc0, 42 NV_E0 = 0xe0, 43 GM100 = 0x110, 44 GP100 = 0x130, 45 GV100 = 0x140, 46 TU100 = 0x160, 47 GA100 = 0x170, 48 } card_type; 49 u32 chipset; 50 u8 chiprev; 51 u32 crystal; 52 53 struct { 54 struct notifier_block nb; 55 } acpi; 56 57 #define NVKM_LAYOUT_ONCE(type,data,ptr) data *ptr; 58 #define NVKM_LAYOUT_INST(type,data,ptr,cnt) data *ptr[cnt]; 59 #include <core/layout.h> 60 #undef NVKM_LAYOUT_INST 61 #undef NVKM_LAYOUT_ONCE 62 struct list_head subdev; 63 }; 64 65 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int type, int inst); 66 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int type, int inst); 67 68 struct nvkm_device_func { 69 struct nvkm_device_pci *(*pci)(struct nvkm_device *); 70 struct nvkm_device_tegra *(*tegra)(struct nvkm_device *); 71 void *(*dtor)(struct nvkm_device *); 72 int (*preinit)(struct nvkm_device *); 73 int (*init)(struct nvkm_device *); 74 void (*fini)(struct nvkm_device *, bool suspend); 75 resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar); 76 resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar); 77 bool cpu_coherent; 78 }; 79 80 struct nvkm_device_quirk { 81 u8 tv_pin_mask; 82 u8 tv_gpio; 83 }; 84 85 struct nvkm_device_chip { 86 const char *name; 87 #define NVKM_LAYOUT_ONCE(type,data,ptr,...) \ 88 struct { \ 89 u32 inst; \ 90 int (*ctor)(struct nvkm_device *, enum nvkm_subdev_type, int inst, data **); \ 91 } ptr; 92 #define NVKM_LAYOUT_INST(A...) NVKM_LAYOUT_ONCE(A) 93 #include <core/layout.h> 94 #undef NVKM_LAYOUT_INST 95 #undef NVKM_LAYOUT_ONCE 96 }; 97 98 struct nvkm_device *nvkm_device_find(u64 name); 99 int nvkm_device_list(u64 *name, int size); 100 101 /* privileged register interface accessor macros */ 102 #define nvkm_rd08(d,a) ioread8((d)->pri + (a)) 103 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a)) 104 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a)) 105 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a)) 106 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a)) 107 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a)) 108 #define nvkm_mask(d,a,m,v) ({ \ 109 struct nvkm_device *_device = (d); \ 110 u32 _addr = (a), _temp = nvkm_rd32(_device, _addr); \ 111 nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v)); \ 112 _temp; \ 113 }) 114 115 void nvkm_device_del(struct nvkm_device **); 116 117 struct nvkm_device_oclass { 118 int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *, 119 void *data, u32 size, struct nvkm_object **); 120 struct nvkm_sclass base; 121 }; 122 123 extern const struct nvkm_sclass nvkm_udevice_sclass; 124 125 /* device logging */ 126 #define nvdev_printk_(d,l,p,f,a...) do { \ 127 const struct nvkm_device *_device = (d); \ 128 if (_device->debug >= (l)) \ 129 dev_##p(_device->dev, f, ##a); \ 130 } while(0) 131 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a) 132 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL, crit, f, ##a) 133 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR, err, f, ##a) 134 #define nvdev_warn(d,f,a...) nvdev_printk((d), WARN, notice, f, ##a) 135 #define nvdev_info(d,f,a...) nvdev_printk((d), INFO, info, f, ##a) 136 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG, info, f, ##a) 137 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE, info, f, ##a) 138 #define nvdev_spam(d,f,a...) nvdev_printk((d), SPAM, dbg, f, ##a) 139 #endif 140