drmP.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Internal Header for the Direct Rendering Manager
  3. *
  4. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6. * Copyright (c) 2009-2010, Code Aurora Forum.
  7. * All rights reserved.
  8. *
  9. * Author: Rickard E. (Rik) Faith <faith@valinux.com>
  10. * Author: Gareth Hughes <gareth@valinux.com>
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a
  13. * copy of this software and associated documentation files (the "Software"),
  14. * to deal in the Software without restriction, including without limitation
  15. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  16. * and/or sell copies of the Software, and to permit persons to whom the
  17. * Software is furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice (including the next
  20. * paragraph) shall be included in all copies or substantial portions of the
  21. * Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29. * OTHER DEALINGS IN THE SOFTWARE.
  30. */
  31. #ifndef _DRM_P_H_
  32. #define _DRM_P_H_
  33. #include <linux/agp_backend.h>
  34. #include <linux/cdev.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/file.h>
  37. #include <linux/fs.h>
  38. #include <linux/highmem.h>
  39. #include <linux/idr.h>
  40. #include <linux/init.h>
  41. #include <linux/io.h>
  42. #include <linux/jiffies.h>
  43. #include <linux/kernel.h>
  44. #include <linux/kref.h>
  45. #include <linux/miscdevice.h>
  46. #include <linux/mm.h>
  47. #include <linux/mutex.h>
  48. #include <linux/platform_device.h>
  49. #include <linux/poll.h>
  50. #include <linux/ratelimit.h>
  51. #include <linux/sched.h>
  52. #include <linux/slab.h>
  53. #include <linux/types.h>
  54. #include <linux/vmalloc.h>
  55. #include <linux/workqueue.h>
  56. #include <linux/dma-fence.h>
  57. #include <linux/module.h>
  58. #include <asm/mman.h>
  59. #include <asm/pgalloc.h>
  60. #include <linux/uaccess.h>
  61. #include <uapi/drm/drm.h>
  62. #include <uapi/drm/drm_mode.h>
  63. #include <drm/drm_agpsupport.h>
  64. #include <drm/drm_crtc.h>
  65. #include <drm/drm_fourcc.h>
  66. #include <drm/drm_global.h>
  67. #include <drm/drm_hashtab.h>
  68. #include <drm/drm_mm.h>
  69. #include <drm/drm_os_linux.h>
  70. #include <drm/drm_sarea.h>
  71. #include <drm/drm_drv.h>
  72. #include <drm/drm_prime.h>
  73. #include <drm/drm_pci.h>
  74. #include <drm/drm_file.h>
  75. #include <drm/drm_debugfs.h>
  76. #include <drm/drm_ioctl.h>
  77. #include <drm/drm_sysfs.h>
  78. #include <drm/drm_vblank.h>
  79. #include <drm/drm_irq.h>
  80. #include <drm/drm_device.h>
  81. struct module;
  82. struct device_node;
  83. struct videomode;
  84. struct reservation_object;
  85. struct dma_buf_attachment;
  86. struct pci_dev;
  87. struct pci_controller;
  88. /*
  89. * The following categories are defined:
  90. *
  91. * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
  92. * This is the category used by the DRM_DEBUG() macro.
  93. *
  94. * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
  95. * This is the category used by the DRM_DEBUG_DRIVER() macro.
  96. *
  97. * KMS: used in the modesetting code.
  98. * This is the category used by the DRM_DEBUG_KMS() macro.
  99. *
  100. * PRIME: used in the prime code.
  101. * This is the category used by the DRM_DEBUG_PRIME() macro.
  102. *
  103. * ATOMIC: used in the atomic code.
  104. * This is the category used by the DRM_DEBUG_ATOMIC() macro.
  105. *
  106. * VBL: used for verbose debug message in the vblank code
  107. * This is the category used by the DRM_DEBUG_VBL() macro.
  108. *
  109. * Enabling verbose debug messages is done through the drm.debug parameter,
  110. * each category being enabled by a bit.
  111. *
  112. * drm.debug=0x1 will enable CORE messages
  113. * drm.debug=0x2 will enable DRIVER messages
  114. * drm.debug=0x3 will enable CORE and DRIVER messages
  115. * ...
  116. * drm.debug=0x3f will enable all messages
  117. *
  118. * An interesting feature is that it's possible to enable verbose logging at
  119. * run-time by echoing the debug value in its sysfs node:
  120. * # echo 0xf > /sys/module/drm/parameters/debug
  121. */
  122. #define DRM_UT_NONE 0x00
  123. #define DRM_UT_CORE 0x01
  124. #define DRM_UT_DRIVER 0x02
  125. #define DRM_UT_KMS 0x04
  126. #define DRM_UT_PRIME 0x08
  127. #define DRM_UT_ATOMIC 0x10
  128. #define DRM_UT_VBL 0x20
  129. #define DRM_UT_STATE 0x40
  130. #define DRM_UT_LEASE 0x80
  131. /***********************************************************************/
  132. /** \name DRM template customization defaults */
  133. /*@{*/
  134. /***********************************************************************/
  135. /** \name Macros to make printk easier */
  136. /*@{*/
  137. #define _DRM_PRINTK(once, level, fmt, ...) \
  138. do { \
  139. printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
  140. ##__VA_ARGS__); \
  141. } while (0)
  142. #define DRM_INFO(fmt, ...) \
  143. _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
  144. #define DRM_NOTE(fmt, ...) \
  145. _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
  146. #define DRM_WARN(fmt, ...) \
  147. _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
  148. #define DRM_INFO_ONCE(fmt, ...) \
  149. _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
  150. #define DRM_NOTE_ONCE(fmt, ...) \
  151. _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
  152. #define DRM_WARN_ONCE(fmt, ...) \
  153. _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
  154. /**
  155. * Error output.
  156. *
  157. * \param fmt printf() like format string.
  158. * \param arg arguments
  159. */
  160. #define DRM_DEV_ERROR(dev, fmt, ...) \
  161. drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
  162. fmt, ##__VA_ARGS__)
  163. #define DRM_ERROR(fmt, ...) \
  164. drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
  165. /**
  166. * Rate limited error output. Like DRM_ERROR() but won't flood the log.
  167. *
  168. * \param fmt printf() like format string.
  169. * \param arg arguments
  170. */
  171. #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
  172. ({ \
  173. static DEFINE_RATELIMIT_STATE(_rs, \
  174. DEFAULT_RATELIMIT_INTERVAL, \
  175. DEFAULT_RATELIMIT_BURST); \
  176. \
  177. if (__ratelimit(&_rs)) \
  178. DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
  179. })
  180. #define DRM_ERROR_RATELIMITED(fmt, ...) \
  181. DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
  182. #define DRM_DEV_INFO(dev, fmt, ...) \
  183. drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
  184. ##__VA_ARGS__)
  185. #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
  186. ({ \
  187. static bool __print_once __read_mostly; \
  188. if (!__print_once) { \
  189. __print_once = true; \
  190. DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
  191. } \
  192. })
  193. /**
  194. * Debug output.
  195. *
  196. * \param fmt printf() like format string.
  197. * \param arg arguments
  198. */
  199. #define DRM_DEV_DEBUG(dev, fmt, args...) \
  200. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
  201. ##args)
  202. #define DRM_DEBUG(fmt, ...) \
  203. drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
  204. #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
  205. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
  206. fmt, ##args)
  207. #define DRM_DEBUG_DRIVER(fmt, ...) \
  208. drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
  209. #define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
  210. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
  211. ##args)
  212. #define DRM_DEBUG_KMS(fmt, ...) \
  213. drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
  214. #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
  215. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
  216. fmt, ##args)
  217. #define DRM_DEBUG_PRIME(fmt, ...) \
  218. drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
  219. #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
  220. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
  221. fmt, ##args)
  222. #define DRM_DEBUG_ATOMIC(fmt, ...) \
  223. drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
  224. #define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
  225. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
  226. ##args)
  227. #define DRM_DEBUG_VBL(fmt, ...) \
  228. drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
  229. #define DRM_DEBUG_LEASE(fmt, ...) \
  230. drm_printk(KERN_DEBUG, DRM_UT_LEASE, fmt, ##__VA_ARGS__)
  231. #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
  232. ({ \
  233. static DEFINE_RATELIMIT_STATE(_rs, \
  234. DEFAULT_RATELIMIT_INTERVAL, \
  235. DEFAULT_RATELIMIT_BURST); \
  236. if (__ratelimit(&_rs)) \
  237. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
  238. __func__, "", fmt, ##args); \
  239. })
  240. /**
  241. * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
  242. *
  243. * \param fmt printf() like format string.
  244. * \param arg arguments
  245. */
  246. #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
  247. DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
  248. #define DRM_DEBUG_RATELIMITED(fmt, args...) \
  249. DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
  250. #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
  251. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
  252. #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
  253. DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
  254. #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
  255. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
  256. #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
  257. DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
  258. #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
  259. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
  260. #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
  261. DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
  262. /* Format strings and argument splitters to simplify printing
  263. * various "complex" objects
  264. */
  265. /*@}*/
  266. /***********************************************************************/
  267. /** \name Internal types and structures */
  268. /*@{*/
  269. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  270. /**
  271. * drm_drv_uses_atomic_modeset - check if the driver implements
  272. * atomic_commit()
  273. * @dev: DRM device
  274. *
  275. * This check is useful if drivers do not have DRIVER_ATOMIC set but
  276. * have atomic modesetting internally implemented.
  277. */
  278. static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
  279. {
  280. return dev->mode_config.funcs->atomic_commit != NULL;
  281. }
  282. #define DRM_SWITCH_POWER_ON 0
  283. #define DRM_SWITCH_POWER_OFF 1
  284. #define DRM_SWITCH_POWER_CHANGING 2
  285. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  286. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  287. int feature)
  288. {
  289. return ((dev->driver->driver_features & feature) ? 1 : 0);
  290. }
  291. /******************************************************************/
  292. /** \name Internal function definitions */
  293. /*@{*/
  294. /* Driver support (drm_drv.h) */
  295. /*
  296. * These are exported to drivers so that they can implement fencing using
  297. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  298. */
  299. /*@}*/
  300. /* returns true if currently okay to sleep */
  301. static __inline__ bool drm_can_sleep(void)
  302. {
  303. if (in_atomic() || in_dbg_master() || irqs_disabled())
  304. return false;
  305. return true;
  306. }
  307. /* helper for handling conditionals in various for_each macros */
  308. #define for_each_if(condition) if (!(condition)) {} else
  309. #endif