Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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