nouveau_drv.h 7.0 KB

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