FILE
nouveau_drv.h
File preview with syntax highlighting.
linux-6.19.14/drivers/gpu/drm/nouveau/nouveau_drv.h
1/* SPDX-License-Identifier: MIT */ 2#ifndef __NOUVEAU_DRV_H__ 3#define __NOUVEAU_DRV_H__ 4 5#define DRIVER_AUTHOR "Nouveau Project" 6#define DRIVER_EMAIL "nouveau@lists.freedesktop.org" 7 8#define DRIVER_NAME "nouveau" 9#define DRIVER_DESC "nVidia Riva/TNT/GeForce/Quadro/Tesla/Tegra K1+" 10 11#define DRIVER_MAJOR 1 12#define DRIVER_MINOR 4 13#define DRIVER_PATCHLEVEL 1 14 15/* 16 * 1.1.1: 17 * - added support for tiled system memory buffer objects 18 * - added support for NOUVEAU_GETPARAM_GRAPH_UNITS on [nvc0,nve0]. 19 * - added support for compressed memory storage types on [nvc0,nve0]. 20 * - added support for software methods 0x600,0x644,0x6ac on nvc0 21 * to control registers on the MPs to enable performance counters, 22 * and to control the warp error enable mask (OpenGL requires out of 23 * bounds access to local memory to be silently ignored / return 0). 24 * 1.1.2: 25 * - fixes multiple bugs in flip completion events and timestamping 26 * 1.2.0: 27 * - object api exposed to userspace 28 * - fermi,kepler,maxwell zbc 29 * 1.2.1: 30 * - allow concurrent access to bo's mapped read/write. 31 * 1.2.2: 32 * - add NOUVEAU_GEM_DOMAIN_COHERENT flag 33 * 1.3.0: 34 * - NVIF ABI modified, safe because only (current) users are test 35 * programs that get directly linked with NVKM. 36 * 1.3.1: 37 * - implemented limited ABI16/NVIF interop 38 * 1.4.1: 39 * - add variable page sizes and compression for Turing+ 40 */ 41 42#include <linux/notifier.h> 43 44#include <nvif/client.h> 45#include <nvif/device.h> 46#include <nvif/ioctl.h> 47#include <nvif/mmu.h> 48#include <nvif/vmm.h> 49 50#include <drm/drm_connector.h> 51#include <drm/drm_device.h> 52#include <drm/drm_drv.h> 53#include <drm/drm_file.h> 54#include <drm/drm_print.h> 55 56#include <drm/ttm/ttm_bo.h> 57#include <drm/ttm/ttm_placement.h> 58 59#include <drm/drm_audio_component.h> 60 61#include "uapi/drm/nouveau_drm.h" 62 63struct nouveau_channel; 64struct platform_device; 65 66#include "nouveau_fence.h" 67#include "nouveau_bios.h" 68#include "nouveau_sched.h" 69#include "nouveau_vmm.h" 70#include "nouveau_uvmm.h" 71 72struct nouveau_drm_tile { 73 struct nouveau_fence *fence; 74 bool used; 75}; 76 77enum nouveau_drm_object_route { 78 NVDRM_OBJECT_NVIF = NVIF_IOCTL_V0_OWNER_NVIF, 79 NVDRM_OBJECT_USIF, 80 NVDRM_OBJECT_ABI16, 81 NVDRM_OBJECT_ANY = NVIF_IOCTL_V0_OWNER_ANY, 82}; 83 84enum nouveau_drm_handle { 85 NVDRM_CHAN = 0xcccc0000, /* |= client chid */ 86 NVDRM_NVSW = 0x55550000, 87}; 88 89struct nouveau_cli { 90 struct nvif_client base; 91 struct nouveau_drm *drm; 92 struct mutex mutex; 93 94 struct nvif_device device; 95 struct nvif_mmu mmu; 96 struct nouveau_vmm vmm; 97 struct nouveau_vmm svm; 98 struct { 99 struct nouveau_uvmm *ptr; 100 bool disabled; 101 } uvmm; 102 103 struct nouveau_sched *sched; 104 105 const struct nvif_mclass *mem; 106 107 struct list_head head; 108 void *abi16; 109 struct list_head objects; 110 char name[32]; 111 112 struct work_struct work; 113 struct list_head worker; 114 struct mutex lock; 115}; 116 117struct nouveau_cli_work { 118 void (*func)(struct nouveau_cli_work *); 119 struct nouveau_cli *cli; 120 struct list_head head; 121 122 struct dma_fence *fence; 123 struct dma_fence_cb cb; 124}; 125 126static inline struct nouveau_uvmm * 127nouveau_cli_uvmm(struct nouveau_cli *cli) 128{ 129 return cli ? cli->uvmm.ptr : NULL; 130} 131 132static inline struct nouveau_uvmm * 133nouveau_cli_uvmm_locked(struct nouveau_cli *cli) 134{ 135 struct nouveau_uvmm *uvmm; 136 137 mutex_lock(&cli->mutex); 138 uvmm = nouveau_cli_uvmm(cli); 139 mutex_unlock(&cli->mutex); 140 141 return uvmm; 142} 143 144static inline struct nouveau_vmm * 145nouveau_cli_vmm(struct nouveau_cli *cli) 146{ 147 struct nouveau_uvmm *uvmm; 148 149 uvmm = nouveau_cli_uvmm(cli); 150 if (uvmm) 151 return &uvmm->vmm; 152 153 if (cli->svm.cli) 154 return &cli->svm; 155 156 return &cli->vmm; 157} 158 159static inline void 160__nouveau_cli_disable_uvmm_noinit(struct nouveau_cli *cli) 161{ 162 struct nouveau_uvmm *uvmm = nouveau_cli_uvmm(cli); 163 164 if (!uvmm) 165 cli->uvmm.disabled = true; 166} 167 168static inline void 169nouveau_cli_disable_uvmm_noinit(struct nouveau_cli *cli) 170{ 171 mutex_lock(&cli->mutex); 172 __nouveau_cli_disable_uvmm_noinit(cli); 173 mutex_unlock(&cli->mutex); 174} 175 176void nouveau_cli_work_queue(struct nouveau_cli *, struct dma_fence *, 177 struct nouveau_cli_work *); 178 179static inline struct nouveau_cli * 180nouveau_cli(struct drm_file *fpriv) 181{ 182 return fpriv ? fpriv->driver_priv : NULL; 183} 184 185static inline void 186u_free(void *addr) 187{ 188 kvfree(addr); 189} 190 191static inline void * 192u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size) 193{ 194 void __user *userptr = u64_to_user_ptr(user); 195 size_t bytes; 196 197 if (unlikely(check_mul_overflow(nmemb, size, &bytes))) 198 return ERR_PTR(-EOVERFLOW); 199 return vmemdup_user(userptr, bytes); 200} 201 202#include <nvif/object.h> 203#include <nvif/parent.h> 204 205struct nouveau_drm { 206 struct nvkm_device *nvkm; 207 struct nvif_parent parent; 208 struct mutex client_mutex; 209 struct nvif_client _client; 210 struct nvif_device device; 211 struct nvif_mmu mmu; 212 213 struct nouveau_cli client; 214 struct drm_device *dev; 215 216 struct list_head clients; 217 218 /** 219 * @clients_lock: Protects access to the @clients list of &struct nouveau_cli. 220 */ 221 struct mutex clients_lock; 222 223 u8 old_pm_cap; 224 225 struct { 226 struct agp_bridge_data *bridge; 227 u32 base; 228 u32 size; 229 bool cma; 230 } agp; 231 232 /* TTM interface support */ 233 struct { 234 struct ttm_device bdev; 235 atomic_t validate_sequence; 236 int (*move)(struct nouveau_channel *, 237 struct ttm_buffer_object *, 238 struct ttm_resource *, struct ttm_resource *); 239 struct nouveau_channel *chan; 240 struct nvif_object copy; 241 int mtrr; 242 int type_vram; 243 int type_host[2]; 244 int type_ncoh[2]; 245 struct mutex io_reserve_mutex; 246 struct list_head io_reserve_lru; 247 } ttm; 248 249 /* GEM interface support */ 250 struct { 251 u64 vram_available; 252 u64 gart_available; 253 } gem; 254 255 /* synchronisation */ 256 void *fence; 257 258 /* Global channel management. */ 259 int chan_total; /* Number of channels across all runlists. */ 260 int chan_nr; /* 0 if per-runlist CHIDs. */ 261 int runl_nr; 262 struct { 263 int chan_nr; 264 int chan_id_base; 265 u64 context_base; 266 } *runl; 267 268 /* Workqueue used for channel schedulers. */ 269 struct workqueue_struct *sched_wq; 270 271 /* context for accelerated drm-internal operations */ 272 struct nouveau_channel *cechan; 273 struct nouveau_channel *channel; 274 struct nvkm_gpuobj *notify; 275 struct nvif_object ntfy; 276 277 /* nv10-nv40 tiling regions */ 278 struct { 279 struct nouveau_drm_tile reg[15]; 280 spinlock_t lock; 281 } tile; 282 283 /* modesetting */ 284 struct nvbios vbios; 285 struct nouveau_display *display; 286 bool headless; 287 struct work_struct hpd_work; 288 spinlock_t hpd_lock; 289 u32 hpd_pending; 290#ifdef CONFIG_ACPI 291 struct notifier_block acpi_nb; 292#endif 293 294 /* power management */ 295 struct nouveau_hwmon *hwmon; 296 struct nouveau_debugfs *debugfs; 297 298 /* led management */ 299 struct nouveau_led *led; 300 301 struct dev_pm_domain vga_pm_domain; 302 303 struct nouveau_svm *svm; 304 305 struct nouveau_dmem *dmem; 306 307 struct { 308 struct drm_audio_component *component; 309 struct mutex lock; 310 bool component_registered; 311 } audio; 312}; 313 314static inline struct nouveau_drm * 315nouveau_drm(struct drm_device *dev) 316{ 317 return dev->dev_private; 318} 319 320static inline bool 321nouveau_drm_use_coherent_gpu_mapping(struct nouveau_drm *drm) 322{ 323 struct nvif_mmu *mmu = &drm->client.mmu; 324 return !(mmu->type[drm->ttm.type_host[0]].type & NVIF_MEM_UNCACHED); 325} 326 327int nouveau_pmops_suspend(struct device *); 328int nouveau_pmops_resume(struct device *); 329bool nouveau_pmops_runtime(void); 330 331#include <nvkm/core/tegra.h> 332 333struct drm_device * 334nouveau_platform_device_create(const struct nvkm_device_tegra_func *, 335 struct platform_device *, struct nvkm_device **); 336void nouveau_drm_device_remove(struct nouveau_drm *); 337 338#define NV_PRINTK(l,c,f,a...) do { \ 339 struct nouveau_cli *_cli = (c); \ 340 dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a); \ 341} while(0) 342 343#define NV_PRINTK_(l,drm,f,a...) do { \ 344 dev_##l((drm)->nvkm->dev, "drm: "f, ##a); \ 345} while(0) 346#define NV_FATAL(drm,f,a...) NV_PRINTK_(crit, (drm), f, ##a) 347#define NV_ERROR(drm,f,a...) NV_PRINTK_(err, (drm), f, ##a) 348#define NV_WARN(drm,f,a...) NV_PRINTK_(warn, (drm), f, ##a) 349#define NV_INFO(drm,f,a...) NV_PRINTK_(info, (drm), f, ##a) 350 351#define NV_DEBUG(drm,f,a...) do { \ 352 if (drm_debug_enabled(DRM_UT_DRIVER)) \ 353 NV_PRINTK_(info, (drm), f, ##a); \ 354} while(0) 355#define NV_ATOMIC(drm,f,a...) do { \ 356 if (drm_debug_enabled(DRM_UT_ATOMIC)) \ 357 NV_PRINTK_(info, (drm), f, ##a); \ 358} while(0) 359 360#define NV_PRINTK_ONCE(l,c,f,a...) NV_PRINTK(l##_once,c,f, ##a) 361 362#define NV_ERROR_ONCE(drm,f,a...) NV_PRINTK_ONCE(err, &(drm)->client, f, ##a) 363#define NV_WARN_ONCE(drm,f,a...) NV_PRINTK_ONCE(warn, &(drm)->client, f, ##a) 364#define NV_INFO_ONCE(drm,f,a...) NV_PRINTK_ONCE(info, &(drm)->client, f, ##a) 365 366extern int nouveau_modeset; 367 368/*XXX: Don't use these in new code. 369 * 370 * These accessors are used in a few places (mostly older code paths) 371 * to get direct access to NVKM structures, where a more well-defined 372 * interface doesn't exist. Outside of the current use, these should 373 * not be relied on, and instead be implemented as NVIF. 374 * 375 * This is especially important when considering GSP-RM, as a lot the 376 * modules don't exist, or are "stub" implementations that just allow 377 * the GSP-RM paths to be bootstrapped. 378 */ 379#include <subdev/bios.h> 380#include <subdev/fb.h> 381#include <subdev/gpio.h> 382#include <subdev/clk.h> 383#include <subdev/i2c.h> 384#include <subdev/timer.h> 385#include <subdev/therm.h> 386 387static inline struct nvkm_device * 388nvxx_device(struct nouveau_drm *drm) 389{ 390 return drm->nvkm; 391} 392 393#define nvxx_bios(a) nvxx_device(a)->bios 394#define nvxx_fb(a) nvxx_device(a)->fb 395#define nvxx_gpio(a) nvxx_device(a)->gpio 396#define nvxx_clk(a) nvxx_device(a)->clk 397#define nvxx_i2c(a) nvxx_device(a)->i2c 398#define nvxx_iccsense(a) nvxx_device(a)->iccsense 399#define nvxx_therm(a) nvxx_device(a)->therm 400#define nvxx_volt(a) nvxx_device(a)->volt 401 402#include <engine/gr.h> 403 404#define nvxx_gr(a) nvxx_device(a)->gr 405#endif
~/
Read-only file preview.