1 1.5 riastrad /* $NetBSD: nouveau_drv.h,v 1.5 2024/04/16 14:34:02 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* SPDX-License-Identifier: MIT */ 4 1.1 riastrad #ifndef __NOUVEAU_DRV_H__ 5 1.1 riastrad #define __NOUVEAU_DRV_H__ 6 1.1 riastrad 7 1.1 riastrad #define DRIVER_AUTHOR "Nouveau Project" 8 1.1 riastrad #define DRIVER_EMAIL "nouveau (at) lists.freedesktop.org" 9 1.1 riastrad 10 1.1 riastrad #define DRIVER_NAME "nouveau" 11 1.1 riastrad #define DRIVER_DESC "nVidia Riva/TNT/GeForce/Quadro/Tesla/Tegra K1+" 12 1.1 riastrad #define DRIVER_DATE "20120801" 13 1.1 riastrad 14 1.1 riastrad #define DRIVER_MAJOR 1 15 1.1 riastrad #define DRIVER_MINOR 3 16 1.1 riastrad #define DRIVER_PATCHLEVEL 1 17 1.1 riastrad 18 1.1 riastrad /* 19 1.1 riastrad * 1.1.1: 20 1.1 riastrad * - added support for tiled system memory buffer objects 21 1.1 riastrad * - added support for NOUVEAU_GETPARAM_GRAPH_UNITS on [nvc0,nve0]. 22 1.1 riastrad * - added support for compressed memory storage types on [nvc0,nve0]. 23 1.1 riastrad * - added support for software methods 0x600,0x644,0x6ac on nvc0 24 1.1 riastrad * to control registers on the MPs to enable performance counters, 25 1.1 riastrad * and to control the warp error enable mask (OpenGL requires out of 26 1.1 riastrad * bounds access to local memory to be silently ignored / return 0). 27 1.1 riastrad * 1.1.2: 28 1.1 riastrad * - fixes multiple bugs in flip completion events and timestamping 29 1.1 riastrad * 1.2.0: 30 1.1 riastrad * - object api exposed to userspace 31 1.1 riastrad * - fermi,kepler,maxwell zbc 32 1.1 riastrad * 1.2.1: 33 1.1 riastrad * - allow concurrent access to bo's mapped read/write. 34 1.1 riastrad * 1.2.2: 35 1.1 riastrad * - add NOUVEAU_GEM_DOMAIN_COHERENT flag 36 1.1 riastrad * 1.3.0: 37 1.1 riastrad * - NVIF ABI modified, safe because only (current) users are test 38 1.1 riastrad * programs that get directly linked with NVKM. 39 1.1 riastrad * 1.3.1: 40 1.1 riastrad * - implemented limited ABI16/NVIF interop 41 1.1 riastrad */ 42 1.1 riastrad 43 1.5 riastrad #include <linux/acpi.h> 44 1.1 riastrad #include <linux/notifier.h> 45 1.1 riastrad 46 1.1 riastrad #include <nvif/client.h> 47 1.1 riastrad #include <nvif/device.h> 48 1.1 riastrad #include <nvif/ioctl.h> 49 1.1 riastrad #include <nvif/mmu.h> 50 1.1 riastrad #include <nvif/vmm.h> 51 1.1 riastrad 52 1.1 riastrad #include <drm/drm_connector.h> 53 1.1 riastrad #include <drm/drm_device.h> 54 1.1 riastrad #include <drm/drm_drv.h> 55 1.1 riastrad #include <drm/drm_file.h> 56 1.1 riastrad 57 1.1 riastrad #include <drm/ttm/ttm_bo_api.h> 58 1.1 riastrad #include <drm/ttm/ttm_bo_driver.h> 59 1.1 riastrad #include <drm/ttm/ttm_placement.h> 60 1.1 riastrad #include <drm/ttm/ttm_memory.h> 61 1.1 riastrad #include <drm/ttm/ttm_module.h> 62 1.1 riastrad #include <drm/ttm/ttm_page_alloc.h> 63 1.1 riastrad 64 1.1 riastrad #include <drm/drm_audio_component.h> 65 1.1 riastrad 66 1.1 riastrad #include "uapi/drm/nouveau_drm.h" 67 1.1 riastrad 68 1.1 riastrad struct nouveau_channel; 69 1.1 riastrad struct platform_device; 70 1.1 riastrad 71 1.1 riastrad #include "nouveau_fence.h" 72 1.1 riastrad #include "nouveau_bios.h" 73 1.1 riastrad #include "nouveau_vmm.h" 74 1.1 riastrad 75 1.1 riastrad struct nouveau_drm_tile { 76 1.1 riastrad struct nouveau_fence *fence; 77 1.1 riastrad bool used; 78 1.1 riastrad }; 79 1.1 riastrad 80 1.1 riastrad enum nouveau_drm_object_route { 81 1.1 riastrad NVDRM_OBJECT_NVIF = NVIF_IOCTL_V0_OWNER_NVIF, 82 1.1 riastrad NVDRM_OBJECT_USIF, 83 1.1 riastrad NVDRM_OBJECT_ABI16, 84 1.1 riastrad NVDRM_OBJECT_ANY = NVIF_IOCTL_V0_OWNER_ANY, 85 1.1 riastrad }; 86 1.1 riastrad 87 1.1 riastrad enum nouveau_drm_notify_route { 88 1.1 riastrad NVDRM_NOTIFY_NVIF = 0, 89 1.1 riastrad NVDRM_NOTIFY_USIF 90 1.1 riastrad }; 91 1.1 riastrad 92 1.1 riastrad enum nouveau_drm_handle { 93 1.1 riastrad NVDRM_CHAN = 0xcccc0000, /* |= client chid */ 94 1.1 riastrad NVDRM_NVSW = 0x55550000, 95 1.1 riastrad }; 96 1.1 riastrad 97 1.1 riastrad struct nouveau_cli { 98 1.1 riastrad struct nvif_client base; 99 1.1 riastrad struct nouveau_drm *drm; 100 1.1 riastrad struct mutex mutex; 101 1.1 riastrad 102 1.1 riastrad struct nvif_device device; 103 1.1 riastrad struct nvif_mmu mmu; 104 1.1 riastrad struct nouveau_vmm vmm; 105 1.1 riastrad struct nouveau_vmm svm; 106 1.1 riastrad const struct nvif_mclass *mem; 107 1.1 riastrad 108 1.1 riastrad struct list_head head; 109 1.1 riastrad void *abi16; 110 1.1 riastrad struct list_head objects; 111 1.1 riastrad struct list_head notifys; 112 1.1 riastrad char name[32]; 113 1.1 riastrad 114 1.1 riastrad struct work_struct work; 115 1.1 riastrad struct list_head worker; 116 1.1 riastrad struct mutex lock; 117 1.1 riastrad }; 118 1.1 riastrad 119 1.1 riastrad struct nouveau_cli_work { 120 1.1 riastrad void (*func)(struct nouveau_cli_work *); 121 1.1 riastrad struct nouveau_cli *cli; 122 1.1 riastrad struct list_head head; 123 1.1 riastrad 124 1.1 riastrad struct dma_fence *fence; 125 1.1 riastrad struct dma_fence_cb cb; 126 1.1 riastrad }; 127 1.1 riastrad 128 1.1 riastrad void nouveau_cli_work_queue(struct nouveau_cli *, struct dma_fence *, 129 1.1 riastrad struct nouveau_cli_work *); 130 1.1 riastrad 131 1.1 riastrad static inline struct nouveau_cli * 132 1.1 riastrad nouveau_cli(struct drm_file *fpriv) 133 1.1 riastrad { 134 1.1 riastrad return fpriv ? fpriv->driver_priv : NULL; 135 1.1 riastrad } 136 1.1 riastrad 137 1.1 riastrad #include <nvif/object.h> 138 1.1 riastrad 139 1.1 riastrad struct nouveau_drm { 140 1.1 riastrad struct nouveau_cli master; 141 1.1 riastrad struct nouveau_cli client; 142 1.1 riastrad struct drm_device *dev; 143 1.1 riastrad 144 1.1 riastrad struct list_head clients; 145 1.1 riastrad 146 1.1 riastrad struct { 147 1.1 riastrad struct agp_bridge_data *bridge; 148 1.1 riastrad u32 base; 149 1.1 riastrad u32 size; 150 1.1 riastrad bool cma; 151 1.1 riastrad } agp; 152 1.1 riastrad 153 1.1 riastrad /* TTM interface support */ 154 1.1 riastrad struct { 155 1.1 riastrad struct ttm_bo_device bdev; 156 1.1 riastrad atomic_t validate_sequence; 157 1.1 riastrad int (*move)(struct nouveau_channel *, 158 1.1 riastrad struct ttm_buffer_object *, 159 1.1 riastrad struct ttm_mem_reg *, struct ttm_mem_reg *); 160 1.1 riastrad struct nouveau_channel *chan; 161 1.1 riastrad struct nvif_object copy; 162 1.1 riastrad int mtrr; 163 1.1 riastrad int type_vram; 164 1.1 riastrad int type_host[2]; 165 1.1 riastrad int type_ncoh[2]; 166 1.1 riastrad } ttm; 167 1.1 riastrad 168 1.1 riastrad /* GEM interface support */ 169 1.1 riastrad struct { 170 1.1 riastrad u64 vram_available; 171 1.1 riastrad u64 gart_available; 172 1.1 riastrad } gem; 173 1.1 riastrad 174 1.1 riastrad /* synchronisation */ 175 1.1 riastrad void *fence; 176 1.1 riastrad 177 1.1 riastrad /* Global channel management. */ 178 1.1 riastrad struct { 179 1.1 riastrad int nr; 180 1.1 riastrad u64 context_base; 181 1.1 riastrad } chan; 182 1.1 riastrad 183 1.1 riastrad /* context for accelerated drm-internal operations */ 184 1.1 riastrad struct nouveau_channel *cechan; 185 1.1 riastrad struct nouveau_channel *channel; 186 1.1 riastrad struct nvkm_gpuobj *notify; 187 1.1 riastrad struct nouveau_fbdev *fbcon; 188 1.1 riastrad struct nvif_object nvsw; 189 1.1 riastrad struct nvif_object ntfy; 190 1.1 riastrad 191 1.1 riastrad /* nv10-nv40 tiling regions */ 192 1.1 riastrad struct { 193 1.1 riastrad struct nouveau_drm_tile reg[15]; 194 1.1 riastrad spinlock_t lock; 195 1.1 riastrad } tile; 196 1.1 riastrad 197 1.1 riastrad /* modesetting */ 198 1.1 riastrad struct nvbios vbios; 199 1.1 riastrad struct nouveau_display *display; 200 1.1 riastrad struct work_struct hpd_work; 201 1.1 riastrad struct work_struct fbcon_work; 202 1.1 riastrad int fbcon_new_state; 203 1.1 riastrad #ifdef CONFIG_ACPI 204 1.1 riastrad struct notifier_block acpi_nb; 205 1.1 riastrad #endif 206 1.1 riastrad 207 1.1 riastrad /* power management */ 208 1.1 riastrad struct nouveau_hwmon *hwmon; 209 1.1 riastrad struct nouveau_debugfs *debugfs; 210 1.1 riastrad 211 1.1 riastrad /* led management */ 212 1.1 riastrad struct nouveau_led *led; 213 1.1 riastrad 214 1.1 riastrad struct dev_pm_domain vga_pm_domain; 215 1.1 riastrad 216 1.1 riastrad struct nouveau_svm *svm; 217 1.1 riastrad 218 1.1 riastrad struct nouveau_dmem *dmem; 219 1.1 riastrad 220 1.1 riastrad struct { 221 1.1 riastrad struct drm_audio_component *component; 222 1.1 riastrad bool component_registered; 223 1.1 riastrad } audio; 224 1.1 riastrad }; 225 1.1 riastrad 226 1.1 riastrad static inline struct nouveau_drm * 227 1.1 riastrad nouveau_drm(struct drm_device *dev) 228 1.1 riastrad { 229 1.1 riastrad return dev->dev_private; 230 1.1 riastrad } 231 1.1 riastrad 232 1.1 riastrad static inline bool 233 1.1 riastrad nouveau_drm_use_coherent_gpu_mapping(struct nouveau_drm *drm) 234 1.1 riastrad { 235 1.1 riastrad struct nvif_mmu *mmu = &drm->client.mmu; 236 1.1 riastrad return !(mmu->type[drm->ttm.type_host[0]].type & NVIF_MEM_UNCACHED); 237 1.1 riastrad } 238 1.1 riastrad 239 1.2 riastrad #ifdef __NetBSD__ 240 1.3 riastrad int nouveau_drm_device_init(struct drm_device *); 241 1.3 riastrad void nouveau_drm_device_fini(struct drm_device *); 242 1.2 riastrad int nouveau_pmops_suspend(struct drm_device *); 243 1.2 riastrad int nouveau_pmops_resume(struct drm_device *); 244 1.2 riastrad #else 245 1.1 riastrad int nouveau_pmops_suspend(struct device *); 246 1.1 riastrad int nouveau_pmops_resume(struct device *); 247 1.2 riastrad #endif 248 1.1 riastrad bool nouveau_pmops_runtime(void); 249 1.1 riastrad 250 1.1 riastrad #include <nvkm/core/tegra.h> 251 1.1 riastrad 252 1.1 riastrad struct drm_device * 253 1.1 riastrad nouveau_platform_device_create(const struct nvkm_device_tegra_func *, 254 1.1 riastrad struct platform_device *, struct nvkm_device **); 255 1.1 riastrad void nouveau_drm_device_remove(struct drm_device *dev); 256 1.1 riastrad 257 1.1 riastrad #define NV_PRINTK(l,c,f,a...) do { \ 258 1.1 riastrad struct nouveau_cli *_cli = (c); \ 259 1.1 riastrad dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a); \ 260 1.1 riastrad } while(0) 261 1.1 riastrad 262 1.1 riastrad #define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a) 263 1.1 riastrad #define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a) 264 1.1 riastrad #define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a) 265 1.1 riastrad #define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a) 266 1.1 riastrad 267 1.1 riastrad #define NV_DEBUG(drm,f,a...) do { \ 268 1.1 riastrad if (drm_debug_enabled(DRM_UT_DRIVER)) \ 269 1.1 riastrad NV_PRINTK(info, &(drm)->client, f, ##a); \ 270 1.1 riastrad } while(0) 271 1.1 riastrad #define NV_ATOMIC(drm,f,a...) do { \ 272 1.1 riastrad if (drm_debug_enabled(DRM_UT_ATOMIC)) \ 273 1.1 riastrad NV_PRINTK(info, &(drm)->client, f, ##a); \ 274 1.1 riastrad } while(0) 275 1.1 riastrad 276 1.1 riastrad #define NV_PRINTK_ONCE(l,c,f,a...) NV_PRINTK(l##_once,c,f, ##a) 277 1.1 riastrad 278 1.1 riastrad #define NV_ERROR_ONCE(drm,f,a...) NV_PRINTK_ONCE(err, &(drm)->client, f, ##a) 279 1.1 riastrad #define NV_WARN_ONCE(drm,f,a...) NV_PRINTK_ONCE(warn, &(drm)->client, f, ##a) 280 1.1 riastrad #define NV_INFO_ONCE(drm,f,a...) NV_PRINTK_ONCE(info, &(drm)->client, f, ##a) 281 1.1 riastrad 282 1.1 riastrad extern int nouveau_modeset; 283 1.1 riastrad 284 1.1 riastrad #endif 285