drmP.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  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/pci.h>
  49. #include <linux/platform_device.h>
  50. #include <linux/poll.h>
  51. #include <linux/ratelimit.h>
  52. #include <linux/rbtree.h>
  53. #include <linux/sched.h>
  54. #include <linux/slab.h>
  55. #include <linux/types.h>
  56. #include <linux/vmalloc.h>
  57. #include <linux/workqueue.h>
  58. #include <linux/fence.h>
  59. #include <asm/mman.h>
  60. #include <asm/pgalloc.h>
  61. #include <asm/uaccess.h>
  62. #include <uapi/drm/drm.h>
  63. #include <uapi/drm/drm_mode.h>
  64. #include <drm/drm_agpsupport.h>
  65. #include <drm/drm_crtc.h>
  66. #include <drm/drm_fourcc.h>
  67. #include <drm/drm_global.h>
  68. #include <drm/drm_hashtab.h>
  69. #include <drm/drm_mem_util.h>
  70. #include <drm/drm_mm.h>
  71. #include <drm/drm_os_linux.h>
  72. #include <drm/drm_sarea.h>
  73. #include <drm/drm_vma_manager.h>
  74. struct module;
  75. struct drm_file;
  76. struct drm_device;
  77. struct drm_agp_head;
  78. struct drm_local_map;
  79. struct drm_device_dma;
  80. struct drm_dma_handle;
  81. struct drm_gem_object;
  82. struct drm_master;
  83. struct drm_vblank_crtc;
  84. struct device_node;
  85. struct videomode;
  86. struct reservation_object;
  87. struct dma_buf_attachment;
  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. extern __printf(6, 7)
  130. void drm_dev_printk(const struct device *dev, const char *level,
  131. unsigned int category, const char *function_name,
  132. const char *prefix, const char *format, ...);
  133. extern __printf(3, 4)
  134. void drm_printk(const char *level, unsigned int category,
  135. const char *format, ...);
  136. /***********************************************************************/
  137. /** \name DRM template customization defaults */
  138. /*@{*/
  139. /* driver capabilities and requirements mask */
  140. #define DRIVER_USE_AGP 0x1
  141. #define DRIVER_LEGACY 0x2
  142. #define DRIVER_PCI_DMA 0x8
  143. #define DRIVER_SG 0x10
  144. #define DRIVER_HAVE_DMA 0x20
  145. #define DRIVER_HAVE_IRQ 0x40
  146. #define DRIVER_IRQ_SHARED 0x80
  147. #define DRIVER_GEM 0x1000
  148. #define DRIVER_MODESET 0x2000
  149. #define DRIVER_PRIME 0x4000
  150. #define DRIVER_RENDER 0x8000
  151. #define DRIVER_ATOMIC 0x10000
  152. #define DRIVER_KMS_LEGACY_CONTEXT 0x20000
  153. /***********************************************************************/
  154. /** \name Macros to make printk easier */
  155. /*@{*/
  156. #define _DRM_PRINTK(once, level, fmt, ...) \
  157. do { \
  158. printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
  159. ##__VA_ARGS__); \
  160. } while (0)
  161. #define DRM_INFO(fmt, ...) \
  162. _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
  163. #define DRM_NOTE(fmt, ...) \
  164. _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
  165. #define DRM_WARN(fmt, ...) \
  166. _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
  167. #define DRM_INFO_ONCE(fmt, ...) \
  168. _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
  169. #define DRM_NOTE_ONCE(fmt, ...) \
  170. _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
  171. #define DRM_WARN_ONCE(fmt, ...) \
  172. _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
  173. /**
  174. * Error output.
  175. *
  176. * \param fmt printf() like format string.
  177. * \param arg arguments
  178. */
  179. #define DRM_DEV_ERROR(dev, fmt, ...) \
  180. drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
  181. fmt, ##__VA_ARGS__)
  182. #define DRM_ERROR(fmt, ...) \
  183. drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
  184. /**
  185. * Rate limited error output. Like DRM_ERROR() but won't flood the log.
  186. *
  187. * \param fmt printf() like format string.
  188. * \param arg arguments
  189. */
  190. #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
  191. ({ \
  192. static DEFINE_RATELIMIT_STATE(_rs, \
  193. DEFAULT_RATELIMIT_INTERVAL, \
  194. DEFAULT_RATELIMIT_BURST); \
  195. \
  196. if (__ratelimit(&_rs)) \
  197. DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
  198. })
  199. #define DRM_ERROR_RATELIMITED(fmt, ...) \
  200. DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
  201. #define DRM_DEV_INFO(dev, fmt, ...) \
  202. drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
  203. ##__VA_ARGS__)
  204. #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
  205. ({ \
  206. static bool __print_once __read_mostly; \
  207. if (!__print_once) { \
  208. __print_once = true; \
  209. DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
  210. } \
  211. })
  212. /**
  213. * Debug output.
  214. *
  215. * \param fmt printf() like format string.
  216. * \param arg arguments
  217. */
  218. #define DRM_DEV_DEBUG(dev, fmt, args...) \
  219. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
  220. ##args)
  221. #define DRM_DEBUG(fmt, ...) \
  222. drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
  223. #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
  224. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
  225. fmt, ##args)
  226. #define DRM_DEBUG_DRIVER(fmt, ...) \
  227. drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
  228. #define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
  229. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
  230. ##args)
  231. #define DRM_DEBUG_KMS(fmt, ...) \
  232. drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
  233. #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
  234. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
  235. fmt, ##args)
  236. #define DRM_DEBUG_PRIME(fmt, ...) \
  237. drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
  238. #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
  239. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
  240. fmt, ##args)
  241. #define DRM_DEBUG_ATOMIC(fmt, ...) \
  242. drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
  243. #define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
  244. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
  245. ##args)
  246. #define DRM_DEBUG_VBL(fmt, ...) \
  247. drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
  248. #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
  249. ({ \
  250. static DEFINE_RATELIMIT_STATE(_rs, \
  251. DEFAULT_RATELIMIT_INTERVAL, \
  252. DEFAULT_RATELIMIT_BURST); \
  253. if (__ratelimit(&_rs)) \
  254. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
  255. __func__, "", fmt, ##args); \
  256. })
  257. /**
  258. * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
  259. *
  260. * \param fmt printf() like format string.
  261. * \param arg arguments
  262. */
  263. #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
  264. DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
  265. #define DRM_DEBUG_RATELIMITED(fmt, args...) \
  266. DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
  267. #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
  268. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
  269. #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
  270. DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
  271. #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
  272. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
  273. #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
  274. DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
  275. #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
  276. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
  277. #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
  278. DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
  279. /*@}*/
  280. /***********************************************************************/
  281. /** \name Internal types and structures */
  282. /*@{*/
  283. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  284. /**
  285. * Ioctl function type.
  286. *
  287. * \param inode device inode.
  288. * \param file_priv DRM file private pointer.
  289. * \param cmd command.
  290. * \param arg argument.
  291. */
  292. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  293. struct drm_file *file_priv);
  294. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  295. unsigned long arg);
  296. #define DRM_IOCTL_NR(n) _IOC_NR(n)
  297. #define DRM_MAJOR 226
  298. #define DRM_AUTH 0x1
  299. #define DRM_MASTER 0x2
  300. #define DRM_ROOT_ONLY 0x4
  301. #define DRM_CONTROL_ALLOW 0x8
  302. #define DRM_UNLOCKED 0x10
  303. #define DRM_RENDER_ALLOW 0x20
  304. struct drm_ioctl_desc {
  305. unsigned int cmd;
  306. int flags;
  307. drm_ioctl_t *func;
  308. const char *name;
  309. };
  310. /**
  311. * Creates a driver or general drm_ioctl_desc array entry for the given
  312. * ioctl, for use by drm_ioctl().
  313. */
  314. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
  315. [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
  316. .cmd = DRM_IOCTL_##ioctl, \
  317. .func = _func, \
  318. .flags = _flags, \
  319. .name = #ioctl \
  320. }
  321. /* Event queued up for userspace to read */
  322. struct drm_pending_event {
  323. struct completion *completion;
  324. void (*completion_release)(struct completion *completion);
  325. struct drm_event *event;
  326. struct fence *fence;
  327. struct list_head link;
  328. struct list_head pending_link;
  329. struct drm_file *file_priv;
  330. pid_t pid; /* pid of requester, no guarantee it's valid by the time
  331. we deliver the event, for tracing only */
  332. };
  333. struct drm_prime_file_private {
  334. struct mutex lock;
  335. struct rb_root dmabufs;
  336. struct rb_root handles;
  337. };
  338. /** File private data */
  339. struct drm_file {
  340. unsigned authenticated :1;
  341. /* true when the client has asked us to expose stereo 3D mode flags */
  342. unsigned stereo_allowed :1;
  343. /*
  344. * true if client understands CRTC primary planes and cursor planes
  345. * in the plane list
  346. */
  347. unsigned universal_planes:1;
  348. /* true if client understands atomic properties */
  349. unsigned atomic:1;
  350. /*
  351. * This client is the creator of @master.
  352. * Protected by struct drm_device::master_mutex.
  353. */
  354. unsigned is_master:1;
  355. struct pid *pid;
  356. drm_magic_t magic;
  357. struct list_head lhead;
  358. struct drm_minor *minor;
  359. unsigned long lock_count;
  360. /** Mapping of mm object handles to object pointers. */
  361. struct idr object_idr;
  362. /** Lock for synchronization of access to object_idr. */
  363. spinlock_t table_lock;
  364. struct file *filp;
  365. void *driver_priv;
  366. struct drm_master *master; /* master this node is currently associated with
  367. N.B. not always dev->master */
  368. /**
  369. * fbs - List of framebuffers associated with this file.
  370. *
  371. * Protected by fbs_lock. Note that the fbs list holds a reference on
  372. * the fb object to prevent it from untimely disappearing.
  373. */
  374. struct list_head fbs;
  375. struct mutex fbs_lock;
  376. /** User-created blob properties; this retains a reference on the
  377. * property. */
  378. struct list_head blobs;
  379. wait_queue_head_t event_wait;
  380. struct list_head pending_event_list;
  381. struct list_head event_list;
  382. int event_space;
  383. struct mutex event_read_lock;
  384. struct drm_prime_file_private prime;
  385. };
  386. /**
  387. * Lock data.
  388. */
  389. struct drm_lock_data {
  390. struct drm_hw_lock *hw_lock; /**< Hardware lock */
  391. /** Private of lock holder's file (NULL=kernel) */
  392. struct drm_file *file_priv;
  393. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  394. unsigned long lock_time; /**< Time of last lock in jiffies */
  395. spinlock_t spinlock;
  396. uint32_t kernel_waiters;
  397. uint32_t user_waiters;
  398. int idle_has_lock;
  399. };
  400. /* Flags and return codes for get_vblank_timestamp() driver function. */
  401. #define DRM_CALLED_FROM_VBLIRQ 1
  402. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  403. #define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
  404. /* get_scanout_position() return flags */
  405. #define DRM_SCANOUTPOS_VALID (1 << 0)
  406. #define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
  407. #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
  408. /**
  409. * DRM driver structure. This structure represent the common code for
  410. * a family of cards. There will one drm_device for each card present
  411. * in this family
  412. */
  413. struct drm_driver {
  414. int (*load) (struct drm_device *, unsigned long flags);
  415. int (*firstopen) (struct drm_device *);
  416. int (*open) (struct drm_device *, struct drm_file *);
  417. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  418. void (*postclose) (struct drm_device *, struct drm_file *);
  419. void (*lastclose) (struct drm_device *);
  420. int (*unload) (struct drm_device *);
  421. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  422. int (*dma_quiescent) (struct drm_device *);
  423. int (*context_dtor) (struct drm_device *dev, int context);
  424. int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  425. /**
  426. * get_vblank_counter - get raw hardware vblank counter
  427. * @dev: DRM device
  428. * @pipe: counter to fetch
  429. *
  430. * Driver callback for fetching a raw hardware vblank counter for @crtc.
  431. * If a device doesn't have a hardware counter, the driver can simply
  432. * use drm_vblank_no_hw_counter() function. The DRM core will account for
  433. * missed vblank events while interrupts where disabled based on system
  434. * timestamps.
  435. *
  436. * Wraparound handling and loss of events due to modesetting is dealt
  437. * with in the DRM core code.
  438. *
  439. * RETURNS
  440. * Raw vblank counter value.
  441. */
  442. u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
  443. /**
  444. * enable_vblank - enable vblank interrupt events
  445. * @dev: DRM device
  446. * @pipe: which irq to enable
  447. *
  448. * Enable vblank interrupts for @crtc. If the device doesn't have
  449. * a hardware vblank counter, the driver should use the
  450. * drm_vblank_no_hw_counter() function that keeps a virtual counter.
  451. *
  452. * RETURNS
  453. * Zero on success, appropriate errno if the given @crtc's vblank
  454. * interrupt cannot be enabled.
  455. */
  456. int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
  457. /**
  458. * disable_vblank - disable vblank interrupt events
  459. * @dev: DRM device
  460. * @pipe: which irq to enable
  461. *
  462. * Disable vblank interrupts for @crtc. If the device doesn't have
  463. * a hardware vblank counter, the driver should use the
  464. * drm_vblank_no_hw_counter() function that keeps a virtual counter.
  465. */
  466. void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
  467. /**
  468. * Called by \c drm_device_is_agp. Typically used to determine if a
  469. * card is really attached to AGP or not.
  470. *
  471. * \param dev DRM device handle
  472. *
  473. * \returns
  474. * One of three values is returned depending on whether or not the
  475. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  476. * (return of 1), or may or may not be AGP (return of 2).
  477. */
  478. int (*device_is_agp) (struct drm_device *dev);
  479. /**
  480. * Called by vblank timestamping code.
  481. *
  482. * Return the current display scanout position from a crtc, and an
  483. * optional accurate ktime_get timestamp of when position was measured.
  484. *
  485. * \param dev DRM device.
  486. * \param pipe Id of the crtc to query.
  487. * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  488. * \param *vpos Target location for current vertical scanout position.
  489. * \param *hpos Target location for current horizontal scanout position.
  490. * \param *stime Target location for timestamp taken immediately before
  491. * scanout position query. Can be NULL to skip timestamp.
  492. * \param *etime Target location for timestamp taken immediately after
  493. * scanout position query. Can be NULL to skip timestamp.
  494. * \param mode Current display timings.
  495. *
  496. * Returns vpos as a positive number while in active scanout area.
  497. * Returns vpos as a negative number inside vblank, counting the number
  498. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  499. * until start of active scanout / end of vblank."
  500. *
  501. * \return Flags, or'ed together as follows:
  502. *
  503. * DRM_SCANOUTPOS_VALID = Query successful.
  504. * DRM_SCANOUTPOS_INVBL = Inside vblank.
  505. * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  506. * this flag means that returned position may be offset by a constant
  507. * but unknown small number of scanlines wrt. real scanout position.
  508. *
  509. */
  510. int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
  511. unsigned int flags, int *vpos, int *hpos,
  512. ktime_t *stime, ktime_t *etime,
  513. const struct drm_display_mode *mode);
  514. /**
  515. * Called by \c drm_get_last_vbltimestamp. Should return a precise
  516. * timestamp when the most recent VBLANK interval ended or will end.
  517. *
  518. * Specifically, the timestamp in @vblank_time should correspond as
  519. * closely as possible to the time when the first video scanline of
  520. * the video frame after the end of VBLANK will start scanning out,
  521. * the time immediately after end of the VBLANK interval. If the
  522. * @crtc is currently inside VBLANK, this will be a time in the future.
  523. * If the @crtc is currently scanning out a frame, this will be the
  524. * past start time of the current scanout. This is meant to adhere
  525. * to the OpenML OML_sync_control extension specification.
  526. *
  527. * \param dev dev DRM device handle.
  528. * \param pipe crtc for which timestamp should be returned.
  529. * \param *max_error Maximum allowable timestamp error in nanoseconds.
  530. * Implementation should strive to provide timestamp
  531. * with an error of at most *max_error nanoseconds.
  532. * Returns true upper bound on error for timestamp.
  533. * \param *vblank_time Target location for returned vblank timestamp.
  534. * \param flags 0 = Defaults, no special treatment needed.
  535. * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  536. * irq handler. Some drivers need to apply some workarounds
  537. * for gpu-specific vblank irq quirks if flag is set.
  538. *
  539. * \returns
  540. * Zero if timestamping isn't supported in current display mode or a
  541. * negative number on failure. A positive status code on success,
  542. * which describes how the vblank_time timestamp was computed.
  543. */
  544. int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
  545. int *max_error,
  546. struct timeval *vblank_time,
  547. unsigned flags);
  548. /* these have to be filled in */
  549. irqreturn_t(*irq_handler) (int irq, void *arg);
  550. void (*irq_preinstall) (struct drm_device *dev);
  551. int (*irq_postinstall) (struct drm_device *dev);
  552. void (*irq_uninstall) (struct drm_device *dev);
  553. /* Master routines */
  554. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  555. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  556. /**
  557. * master_set is called whenever the minor master is set.
  558. * master_drop is called whenever the minor master is dropped.
  559. */
  560. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  561. bool from_open);
  562. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
  563. int (*debugfs_init)(struct drm_minor *minor);
  564. void (*debugfs_cleanup)(struct drm_minor *minor);
  565. /**
  566. * @gem_free_object: deconstructor for drm_gem_objects
  567. *
  568. * This is deprecated and should not be used by new drivers. Use
  569. * @gem_free_object_unlocked instead.
  570. */
  571. void (*gem_free_object) (struct drm_gem_object *obj);
  572. /**
  573. * @gem_free_object_unlocked: deconstructor for drm_gem_objects
  574. *
  575. * This is for drivers which are not encumbered with dev->struct_mutex
  576. * legacy locking schemes. Use this hook instead of @gem_free_object.
  577. */
  578. void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
  579. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  580. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  581. /**
  582. * Hook for allocating the GEM object struct, for use by core
  583. * helpers.
  584. */
  585. struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  586. size_t size);
  587. /* prime: */
  588. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  589. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  590. uint32_t handle, uint32_t flags, int *prime_fd);
  591. /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  592. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  593. int prime_fd, uint32_t *handle);
  594. /* export GEM -> dmabuf */
  595. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  596. struct drm_gem_object *obj, int flags);
  597. /* import dmabuf -> GEM */
  598. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  599. struct dma_buf *dma_buf);
  600. /* low-level interface used by drm_gem_prime_{import,export} */
  601. int (*gem_prime_pin)(struct drm_gem_object *obj);
  602. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  603. struct reservation_object * (*gem_prime_res_obj)(
  604. struct drm_gem_object *obj);
  605. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  606. struct drm_gem_object *(*gem_prime_import_sg_table)(
  607. struct drm_device *dev,
  608. struct dma_buf_attachment *attach,
  609. struct sg_table *sgt);
  610. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  611. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  612. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  613. struct vm_area_struct *vma);
  614. /* vga arb irq handler */
  615. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  616. /* dumb alloc support */
  617. int (*dumb_create)(struct drm_file *file_priv,
  618. struct drm_device *dev,
  619. struct drm_mode_create_dumb *args);
  620. int (*dumb_map_offset)(struct drm_file *file_priv,
  621. struct drm_device *dev, uint32_t handle,
  622. uint64_t *offset);
  623. int (*dumb_destroy)(struct drm_file *file_priv,
  624. struct drm_device *dev,
  625. uint32_t handle);
  626. /* Driver private ops for this object */
  627. const struct vm_operations_struct *gem_vm_ops;
  628. int major;
  629. int minor;
  630. int patchlevel;
  631. char *name;
  632. char *desc;
  633. char *date;
  634. u32 driver_features;
  635. int dev_priv_size;
  636. const struct drm_ioctl_desc *ioctls;
  637. int num_ioctls;
  638. const struct file_operations *fops;
  639. /* List of devices hanging off this driver with stealth attach. */
  640. struct list_head legacy_dev_list;
  641. };
  642. enum drm_minor_type {
  643. DRM_MINOR_PRIMARY,
  644. DRM_MINOR_CONTROL,
  645. DRM_MINOR_RENDER,
  646. DRM_MINOR_CNT,
  647. };
  648. /**
  649. * Info file list entry. This structure represents a debugfs or proc file to
  650. * be created by the drm core
  651. */
  652. struct drm_info_list {
  653. const char *name; /** file name */
  654. int (*show)(struct seq_file*, void*); /** show callback */
  655. u32 driver_features; /**< Required driver features for this entry */
  656. void *data;
  657. };
  658. /**
  659. * debugfs node structure. This structure represents a debugfs file.
  660. */
  661. struct drm_info_node {
  662. struct list_head list;
  663. struct drm_minor *minor;
  664. const struct drm_info_list *info_ent;
  665. struct dentry *dent;
  666. };
  667. /**
  668. * DRM minor structure. This structure represents a drm minor number.
  669. */
  670. struct drm_minor {
  671. int index; /**< Minor device number */
  672. int type; /**< Control or render */
  673. struct device *kdev; /**< Linux device */
  674. struct drm_device *dev;
  675. struct dentry *debugfs_root;
  676. struct list_head debugfs_list;
  677. struct mutex debugfs_lock; /* Protects debugfs_list. */
  678. };
  679. /**
  680. * DRM device structure. This structure represent a complete card that
  681. * may contain multiple heads.
  682. */
  683. struct drm_device {
  684. struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
  685. int if_version; /**< Highest interface version set */
  686. /** \name Lifetime Management */
  687. /*@{ */
  688. struct kref ref; /**< Object ref-count */
  689. struct device *dev; /**< Device structure of bus-device */
  690. struct drm_driver *driver; /**< DRM driver managing the device */
  691. void *dev_private; /**< DRM driver private data */
  692. struct drm_minor *control; /**< Control node */
  693. struct drm_minor *primary; /**< Primary node */
  694. struct drm_minor *render; /**< Render node */
  695. bool registered;
  696. /* currently active master for this device. Protected by master_mutex */
  697. struct drm_master *master;
  698. atomic_t unplugged; /**< Flag whether dev is dead */
  699. struct inode *anon_inode; /**< inode for private address-space */
  700. char *unique; /**< unique name of the device */
  701. /*@} */
  702. /** \name Locks */
  703. /*@{ */
  704. struct mutex struct_mutex; /**< For others */
  705. struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
  706. /*@} */
  707. /** \name Usage Counters */
  708. /*@{ */
  709. int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
  710. spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
  711. int buf_use; /**< Buffers in use -- cannot alloc */
  712. atomic_t buf_alloc; /**< Buffer allocation in progress */
  713. /*@} */
  714. struct mutex filelist_mutex;
  715. struct list_head filelist;
  716. /** \name Memory management */
  717. /*@{ */
  718. struct list_head maplist; /**< Linked list of regions */
  719. struct drm_open_hash map_hash; /**< User token hash table for maps */
  720. /** \name Context handle management */
  721. /*@{ */
  722. struct list_head ctxlist; /**< Linked list of context handles */
  723. struct mutex ctxlist_mutex; /**< For ctxlist */
  724. struct idr ctx_idr;
  725. struct list_head vmalist; /**< List of vmas (for debugging) */
  726. /*@} */
  727. /** \name DMA support */
  728. /*@{ */
  729. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  730. /*@} */
  731. /** \name Context support */
  732. /*@{ */
  733. __volatile__ long context_flag; /**< Context swapping flag */
  734. int last_context; /**< Last current context */
  735. /*@} */
  736. /** \name VBLANK IRQ support */
  737. /*@{ */
  738. bool irq_enabled;
  739. int irq;
  740. /*
  741. * If true, vblank interrupt will be disabled immediately when the
  742. * refcount drops to zero, as opposed to via the vblank disable
  743. * timer.
  744. * This can be set to true it the hardware has a working vblank
  745. * counter and the driver uses drm_vblank_on() and drm_vblank_off()
  746. * appropriately.
  747. */
  748. bool vblank_disable_immediate;
  749. /* array of size num_crtcs */
  750. struct drm_vblank_crtc *vblank;
  751. spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
  752. spinlock_t vbl_lock;
  753. u32 max_vblank_count; /**< size of vblank counter register */
  754. /**
  755. * List of events
  756. */
  757. struct list_head vblank_event_list;
  758. spinlock_t event_lock;
  759. /*@} */
  760. struct drm_agp_head *agp; /**< AGP data */
  761. struct pci_dev *pdev; /**< PCI device structure */
  762. #ifdef __alpha__
  763. struct pci_controller *hose;
  764. #endif
  765. struct platform_device *platformdev; /**< Platform device struture */
  766. struct virtio_device *virtdev;
  767. struct drm_sg_mem *sg; /**< Scatter gather memory */
  768. unsigned int num_crtcs; /**< Number of CRTCs on this device */
  769. struct {
  770. int context;
  771. struct drm_hw_lock *lock;
  772. } sigdata;
  773. struct drm_local_map *agp_buffer_map;
  774. unsigned int agp_buffer_token;
  775. struct drm_mode_config mode_config; /**< Current mode config */
  776. /** \name GEM information */
  777. /*@{ */
  778. struct mutex object_name_lock;
  779. struct idr object_name_idr;
  780. struct drm_vma_offset_manager *vma_offset_manager;
  781. /*@} */
  782. int switch_power_state;
  783. };
  784. #include <drm/drm_irq.h>
  785. #define DRM_SWITCH_POWER_ON 0
  786. #define DRM_SWITCH_POWER_OFF 1
  787. #define DRM_SWITCH_POWER_CHANGING 2
  788. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  789. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  790. int feature)
  791. {
  792. return ((dev->driver->driver_features & feature) ? 1 : 0);
  793. }
  794. static inline void drm_device_set_unplugged(struct drm_device *dev)
  795. {
  796. smp_wmb();
  797. atomic_set(&dev->unplugged, 1);
  798. }
  799. static inline int drm_device_is_unplugged(struct drm_device *dev)
  800. {
  801. int ret = atomic_read(&dev->unplugged);
  802. smp_rmb();
  803. return ret;
  804. }
  805. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  806. {
  807. return file_priv->minor->type == DRM_MINOR_RENDER;
  808. }
  809. static inline bool drm_is_control_client(const struct drm_file *file_priv)
  810. {
  811. return file_priv->minor->type == DRM_MINOR_CONTROL;
  812. }
  813. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  814. {
  815. return file_priv->minor->type == DRM_MINOR_PRIMARY;
  816. }
  817. /******************************************************************/
  818. /** \name Internal function definitions */
  819. /*@{*/
  820. /* Driver support (drm_drv.h) */
  821. extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
  822. extern long drm_ioctl(struct file *filp,
  823. unsigned int cmd, unsigned long arg);
  824. extern long drm_compat_ioctl(struct file *filp,
  825. unsigned int cmd, unsigned long arg);
  826. extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  827. /* File Operations (drm_fops.c) */
  828. int drm_open(struct inode *inode, struct file *filp);
  829. ssize_t drm_read(struct file *filp, char __user *buffer,
  830. size_t count, loff_t *offset);
  831. int drm_release(struct inode *inode, struct file *filp);
  832. unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  833. int drm_event_reserve_init_locked(struct drm_device *dev,
  834. struct drm_file *file_priv,
  835. struct drm_pending_event *p,
  836. struct drm_event *e);
  837. int drm_event_reserve_init(struct drm_device *dev,
  838. struct drm_file *file_priv,
  839. struct drm_pending_event *p,
  840. struct drm_event *e);
  841. void drm_event_cancel_free(struct drm_device *dev,
  842. struct drm_pending_event *p);
  843. void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
  844. void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
  845. /* Misc. IOCTL support (drm_ioctl.c) */
  846. int drm_noop(struct drm_device *dev, void *data,
  847. struct drm_file *file_priv);
  848. int drm_invalid_op(struct drm_device *dev, void *data,
  849. struct drm_file *file_priv);
  850. /* Cache management (drm_cache.c) */
  851. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  852. void drm_clflush_sg(struct sg_table *st);
  853. void drm_clflush_virt_range(void *addr, unsigned long length);
  854. /*
  855. * These are exported to drivers so that they can implement fencing using
  856. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  857. */
  858. /* Modesetting support */
  859. extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
  860. extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
  861. /* drm_drv.c */
  862. void drm_put_dev(struct drm_device *dev);
  863. void drm_unplug_dev(struct drm_device *dev);
  864. extern unsigned int drm_debug;
  865. /* Debugfs support */
  866. #if defined(CONFIG_DEBUG_FS)
  867. extern int drm_debugfs_create_files(const struct drm_info_list *files,
  868. int count, struct dentry *root,
  869. struct drm_minor *minor);
  870. extern int drm_debugfs_remove_files(const struct drm_info_list *files,
  871. int count, struct drm_minor *minor);
  872. #else
  873. static inline int drm_debugfs_create_files(const struct drm_info_list *files,
  874. int count, struct dentry *root,
  875. struct drm_minor *minor)
  876. {
  877. return 0;
  878. }
  879. static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
  880. int count, struct drm_minor *minor)
  881. {
  882. return 0;
  883. }
  884. #endif
  885. struct dma_buf_export_info;
  886. extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  887. struct drm_gem_object *obj,
  888. int flags);
  889. extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  890. struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  891. int *prime_fd);
  892. extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  893. struct dma_buf *dma_buf);
  894. extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  895. struct drm_file *file_priv, int prime_fd, uint32_t *handle);
  896. struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
  897. struct dma_buf_export_info *exp_info);
  898. extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
  899. extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  900. dma_addr_t *addrs, int max_pages);
  901. extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
  902. extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
  903. extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
  904. size_t align);
  905. extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
  906. /* sysfs support (drm_sysfs.c) */
  907. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  908. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  909. struct device *parent);
  910. int drm_dev_init(struct drm_device *dev,
  911. struct drm_driver *driver,
  912. struct device *parent);
  913. void drm_dev_ref(struct drm_device *dev);
  914. void drm_dev_unref(struct drm_device *dev);
  915. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  916. void drm_dev_unregister(struct drm_device *dev);
  917. struct drm_minor *drm_minor_acquire(unsigned int minor_id);
  918. void drm_minor_release(struct drm_minor *minor);
  919. /*@}*/
  920. /* PCI section */
  921. static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
  922. {
  923. if (dev->driver->device_is_agp != NULL) {
  924. int err = (*dev->driver->device_is_agp) (dev);
  925. if (err != 2) {
  926. return err;
  927. }
  928. }
  929. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  930. }
  931. void drm_pci_agp_destroy(struct drm_device *dev);
  932. extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  933. extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  934. #ifdef CONFIG_PCI
  935. extern int drm_get_pci_dev(struct pci_dev *pdev,
  936. const struct pci_device_id *ent,
  937. struct drm_driver *driver);
  938. extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
  939. #else
  940. static inline int drm_get_pci_dev(struct pci_dev *pdev,
  941. const struct pci_device_id *ent,
  942. struct drm_driver *driver)
  943. {
  944. return -ENOSYS;
  945. }
  946. static inline int drm_pci_set_busid(struct drm_device *dev,
  947. struct drm_master *master)
  948. {
  949. return -ENOSYS;
  950. }
  951. #endif
  952. #define DRM_PCIE_SPEED_25 1
  953. #define DRM_PCIE_SPEED_50 2
  954. #define DRM_PCIE_SPEED_80 4
  955. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  956. extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
  957. /* platform section */
  958. extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
  959. /* returns true if currently okay to sleep */
  960. static __inline__ bool drm_can_sleep(void)
  961. {
  962. if (in_atomic() || in_dbg_master() || irqs_disabled())
  963. return false;
  964. return true;
  965. }
  966. /* helper for handling conditionals in various for_each macros */
  967. #define for_each_if(condition) if (!(condition)) {} else
  968. #endif