nouveau_drv.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NOUVEAU_DRV_H__
  3. #define __NOUVEAU_DRV_H__
  4. #define DRIVER_AUTHOR "Nouveau Project"
  5. #define DRIVER_EMAIL "nouveau@lists.freedesktop.org"
  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/drmP.h>
  43. #include <drm/ttm/ttm_bo_api.h>
  44. #include <drm/ttm/ttm_bo_driver.h>
  45. #include <drm/ttm/ttm_placement.h>
  46. #include <drm/ttm/ttm_memory.h>
  47. #include <drm/ttm/ttm_module.h>
  48. #include <drm/ttm/ttm_page_alloc.h>
  49. #include "uapi/drm/nouveau_drm.h"
  50. struct nouveau_channel;
  51. struct platform_device;
  52. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  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. const struct nvif_mclass *mem;
  82. struct list_head head;
  83. void *abi16;
  84. struct list_head objects;
  85. struct list_head notifys;
  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/device.h>
  107. struct nouveau_drm {
  108. struct nouveau_cli master;
  109. struct nouveau_cli client;
  110. struct drm_device *dev;
  111. struct list_head clients;
  112. struct {
  113. struct agp_bridge_data *bridge;
  114. u32 base;
  115. u32 size;
  116. bool cma;
  117. } agp;
  118. /* TTM interface support */
  119. struct {
  120. struct drm_global_reference mem_global_ref;
  121. struct ttm_bo_global_ref bo_global_ref;
  122. struct ttm_bo_device bdev;
  123. atomic_t validate_sequence;
  124. int (*move)(struct nouveau_channel *,
  125. struct ttm_buffer_object *,
  126. struct ttm_mem_reg *, struct ttm_mem_reg *);
  127. struct nouveau_channel *chan;
  128. struct nvif_object copy;
  129. int mtrr;
  130. int type_vram;
  131. int type_host[2];
  132. int type_ncoh[2];
  133. } ttm;
  134. /* GEM interface support */
  135. struct {
  136. u64 vram_available;
  137. u64 gart_available;
  138. } gem;
  139. /* synchronisation */
  140. void *fence;
  141. /* Global channel management. */
  142. struct {
  143. int nr;
  144. u64 context_base;
  145. } chan;
  146. /* context for accelerated drm-internal operations */
  147. struct nouveau_channel *cechan;
  148. struct nouveau_channel *channel;
  149. struct nvkm_gpuobj *notify;
  150. struct nouveau_fbdev *fbcon;
  151. struct nvif_object nvsw;
  152. struct nvif_object ntfy;
  153. struct nvif_notify flip;
  154. /* nv10-nv40 tiling regions */
  155. struct {
  156. struct nouveau_drm_tile reg[15];
  157. spinlock_t lock;
  158. } tile;
  159. /* modesetting */
  160. struct nvbios vbios;
  161. struct nouveau_display *display;
  162. struct backlight_device *backlight;
  163. struct list_head bl_connectors;
  164. struct work_struct hpd_work;
  165. struct work_struct fbcon_work;
  166. int fbcon_new_state;
  167. #ifdef CONFIG_ACPI
  168. struct notifier_block acpi_nb;
  169. #endif
  170. /* power management */
  171. struct nouveau_hwmon *hwmon;
  172. struct nouveau_debugfs *debugfs;
  173. /* led management */
  174. struct nouveau_led *led;
  175. /* display power reference */
  176. bool have_disp_power_ref;
  177. struct dev_pm_domain vga_pm_domain;
  178. };
  179. static inline struct nouveau_drm *
  180. nouveau_drm(struct drm_device *dev)
  181. {
  182. return dev->dev_private;
  183. }
  184. static inline bool
  185. nouveau_drm_use_coherent_gpu_mapping(struct nouveau_drm *drm)
  186. {
  187. struct nvif_mmu *mmu = &drm->client.mmu;
  188. return !(mmu->type[drm->ttm.type_host[0]].type & NVIF_MEM_UNCACHED);
  189. }
  190. int nouveau_pmops_suspend(struct device *);
  191. int nouveau_pmops_resume(struct device *);
  192. bool nouveau_pmops_runtime(void);
  193. #include <nvkm/core/tegra.h>
  194. struct drm_device *
  195. nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
  196. struct platform_device *, struct nvkm_device **);
  197. void nouveau_drm_device_remove(struct drm_device *dev);
  198. #define NV_PRINTK(l,c,f,a...) do { \
  199. struct nouveau_cli *_cli = (c); \
  200. dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a); \
  201. } while(0)
  202. #define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a)
  203. #define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a)
  204. #define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a)
  205. #define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a)
  206. #define NV_DEBUG(drm,f,a...) do { \
  207. if (unlikely(drm_debug & DRM_UT_DRIVER)) \
  208. NV_PRINTK(info, &(drm)->client, f, ##a); \
  209. } while(0)
  210. #define NV_ATOMIC(drm,f,a...) do { \
  211. if (unlikely(drm_debug & DRM_UT_ATOMIC)) \
  212. NV_PRINTK(info, &(drm)->client, f, ##a); \
  213. } while(0)
  214. extern int nouveau_modeset;
  215. #endif