drmP.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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. struct drm_event *event;
  325. struct fence *fence;
  326. struct list_head link;
  327. struct list_head pending_link;
  328. struct drm_file *file_priv;
  329. pid_t pid; /* pid of requester, no guarantee it's valid by the time
  330. we deliver the event, for tracing only */
  331. };
  332. struct drm_prime_file_private {
  333. struct mutex lock;
  334. struct rb_root dmabufs;
  335. struct rb_root handles;
  336. };
  337. /** File private data */
  338. struct drm_file {
  339. unsigned authenticated :1;
  340. /* true when the client has asked us to expose stereo 3D mode flags */
  341. unsigned stereo_allowed :1;
  342. /*
  343. * true if client understands CRTC primary planes and cursor planes
  344. * in the plane list
  345. */
  346. unsigned universal_planes:1;
  347. /* true if client understands atomic properties */
  348. unsigned atomic:1;
  349. /*
  350. * This client is the creator of @master.
  351. * Protected by struct drm_device::master_mutex.
  352. */
  353. unsigned is_master:1;
  354. struct pid *pid;
  355. drm_magic_t magic;
  356. struct list_head lhead;
  357. struct drm_minor *minor;
  358. unsigned long lock_count;
  359. /** Mapping of mm object handles to object pointers. */
  360. struct idr object_idr;
  361. /** Lock for synchronization of access to object_idr. */
  362. spinlock_t table_lock;
  363. struct file *filp;
  364. void *driver_priv;
  365. struct drm_master *master; /* master this node is currently associated with
  366. N.B. not always dev->master */
  367. /**
  368. * fbs - List of framebuffers associated with this file.
  369. *
  370. * Protected by fbs_lock. Note that the fbs list holds a reference on
  371. * the fb object to prevent it from untimely disappearing.
  372. */
  373. struct list_head fbs;
  374. struct mutex fbs_lock;
  375. /** User-created blob properties; this retains a reference on the
  376. * property. */
  377. struct list_head blobs;
  378. wait_queue_head_t event_wait;
  379. struct list_head pending_event_list;
  380. struct list_head event_list;
  381. int event_space;
  382. struct mutex event_read_lock;
  383. struct drm_prime_file_private prime;
  384. };
  385. /**
  386. * Lock data.
  387. */
  388. struct drm_lock_data {
  389. struct drm_hw_lock *hw_lock; /**< Hardware lock */
  390. /** Private of lock holder's file (NULL=kernel) */
  391. struct drm_file *file_priv;
  392. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  393. unsigned long lock_time; /**< Time of last lock in jiffies */
  394. spinlock_t spinlock;
  395. uint32_t kernel_waiters;
  396. uint32_t user_waiters;
  397. int idle_has_lock;
  398. };
  399. /* Flags and return codes for get_vblank_timestamp() driver function. */
  400. #define DRM_CALLED_FROM_VBLIRQ 1
  401. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  402. #define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
  403. /* get_scanout_position() return flags */
  404. #define DRM_SCANOUTPOS_VALID (1 << 0)
  405. #define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
  406. #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
  407. /**
  408. * DRM driver structure. This structure represent the common code for
  409. * a family of cards. There will one drm_device for each card present
  410. * in this family
  411. */
  412. struct drm_driver {
  413. int (*load) (struct drm_device *, unsigned long flags);
  414. int (*firstopen) (struct drm_device *);
  415. int (*open) (struct drm_device *, struct drm_file *);
  416. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  417. void (*postclose) (struct drm_device *, struct drm_file *);
  418. void (*lastclose) (struct drm_device *);
  419. int (*unload) (struct drm_device *);
  420. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  421. int (*dma_quiescent) (struct drm_device *);
  422. int (*context_dtor) (struct drm_device *dev, int context);
  423. int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  424. /**
  425. * get_vblank_counter - get raw hardware vblank counter
  426. * @dev: DRM device
  427. * @pipe: counter to fetch
  428. *
  429. * Driver callback for fetching a raw hardware vblank counter for @crtc.
  430. * If a device doesn't have a hardware counter, the driver can simply
  431. * use drm_vblank_no_hw_counter() function. The DRM core will account for
  432. * missed vblank events while interrupts where disabled based on system
  433. * timestamps.
  434. *
  435. * Wraparound handling and loss of events due to modesetting is dealt
  436. * with in the DRM core code.
  437. *
  438. * RETURNS
  439. * Raw vblank counter value.
  440. */
  441. u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
  442. /**
  443. * enable_vblank - enable vblank interrupt events
  444. * @dev: DRM device
  445. * @pipe: which irq to enable
  446. *
  447. * Enable vblank interrupts for @crtc. If the device doesn't have
  448. * a hardware vblank counter, the driver should use the
  449. * drm_vblank_no_hw_counter() function that keeps a virtual counter.
  450. *
  451. * RETURNS
  452. * Zero on success, appropriate errno if the given @crtc's vblank
  453. * interrupt cannot be enabled.
  454. */
  455. int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
  456. /**
  457. * disable_vblank - disable vblank interrupt events
  458. * @dev: DRM device
  459. * @pipe: which irq to enable
  460. *
  461. * Disable vblank interrupts for @crtc. If the device doesn't have
  462. * a hardware vblank counter, the driver should use the
  463. * drm_vblank_no_hw_counter() function that keeps a virtual counter.
  464. */
  465. void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
  466. /**
  467. * Called by \c drm_device_is_agp. Typically used to determine if a
  468. * card is really attached to AGP or not.
  469. *
  470. * \param dev DRM device handle
  471. *
  472. * \returns
  473. * One of three values is returned depending on whether or not the
  474. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  475. * (return of 1), or may or may not be AGP (return of 2).
  476. */
  477. int (*device_is_agp) (struct drm_device *dev);
  478. /**
  479. * Called by vblank timestamping code.
  480. *
  481. * Return the current display scanout position from a crtc, and an
  482. * optional accurate ktime_get timestamp of when position was measured.
  483. *
  484. * \param dev DRM device.
  485. * \param pipe Id of the crtc to query.
  486. * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  487. * \param *vpos Target location for current vertical scanout position.
  488. * \param *hpos Target location for current horizontal scanout position.
  489. * \param *stime Target location for timestamp taken immediately before
  490. * scanout position query. Can be NULL to skip timestamp.
  491. * \param *etime Target location for timestamp taken immediately after
  492. * scanout position query. Can be NULL to skip timestamp.
  493. * \param mode Current display timings.
  494. *
  495. * Returns vpos as a positive number while in active scanout area.
  496. * Returns vpos as a negative number inside vblank, counting the number
  497. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  498. * until start of active scanout / end of vblank."
  499. *
  500. * \return Flags, or'ed together as follows:
  501. *
  502. * DRM_SCANOUTPOS_VALID = Query successful.
  503. * DRM_SCANOUTPOS_INVBL = Inside vblank.
  504. * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  505. * this flag means that returned position may be offset by a constant
  506. * but unknown small number of scanlines wrt. real scanout position.
  507. *
  508. */
  509. int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
  510. unsigned int flags, int *vpos, int *hpos,
  511. ktime_t *stime, ktime_t *etime,
  512. const struct drm_display_mode *mode);
  513. /**
  514. * Called by \c drm_get_last_vbltimestamp. Should return a precise
  515. * timestamp when the most recent VBLANK interval ended or will end.
  516. *
  517. * Specifically, the timestamp in @vblank_time should correspond as
  518. * closely as possible to the time when the first video scanline of
  519. * the video frame after the end of VBLANK will start scanning out,
  520. * the time immediately after end of the VBLANK interval. If the
  521. * @crtc is currently inside VBLANK, this will be a time in the future.
  522. * If the @crtc is currently scanning out a frame, this will be the
  523. * past start time of the current scanout. This is meant to adhere
  524. * to the OpenML OML_sync_control extension specification.
  525. *
  526. * \param dev dev DRM device handle.
  527. * \param pipe crtc for which timestamp should be returned.
  528. * \param *max_error Maximum allowable timestamp error in nanoseconds.
  529. * Implementation should strive to provide timestamp
  530. * with an error of at most *max_error nanoseconds.
  531. * Returns true upper bound on error for timestamp.
  532. * \param *vblank_time Target location for returned vblank timestamp.
  533. * \param flags 0 = Defaults, no special treatment needed.
  534. * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  535. * irq handler. Some drivers need to apply some workarounds
  536. * for gpu-specific vblank irq quirks if flag is set.
  537. *
  538. * \returns
  539. * Zero if timestamping isn't supported in current display mode or a
  540. * negative number on failure. A positive status code on success,
  541. * which describes how the vblank_time timestamp was computed.
  542. */
  543. int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
  544. int *max_error,
  545. struct timeval *vblank_time,
  546. unsigned flags);
  547. /* these have to be filled in */
  548. irqreturn_t(*irq_handler) (int irq, void *arg);
  549. void (*irq_preinstall) (struct drm_device *dev);
  550. int (*irq_postinstall) (struct drm_device *dev);
  551. void (*irq_uninstall) (struct drm_device *dev);
  552. /* Master routines */
  553. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  554. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  555. /**
  556. * master_set is called whenever the minor master is set.
  557. * master_drop is called whenever the minor master is dropped.
  558. */
  559. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  560. bool from_open);
  561. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
  562. int (*debugfs_init)(struct drm_minor *minor);
  563. void (*debugfs_cleanup)(struct drm_minor *minor);
  564. /**
  565. * @gem_free_object: deconstructor for drm_gem_objects
  566. *
  567. * This is deprecated and should not be used by new drivers. Use
  568. * @gem_free_object_unlocked instead.
  569. */
  570. void (*gem_free_object) (struct drm_gem_object *obj);
  571. /**
  572. * @gem_free_object_unlocked: deconstructor for drm_gem_objects
  573. *
  574. * This is for drivers which are not encumbered with dev->struct_mutex
  575. * legacy locking schemes. Use this hook instead of @gem_free_object.
  576. */
  577. void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
  578. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  579. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  580. /**
  581. * Hook for allocating the GEM object struct, for use by core
  582. * helpers.
  583. */
  584. struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  585. size_t size);
  586. /* prime: */
  587. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  588. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  589. uint32_t handle, uint32_t flags, int *prime_fd);
  590. /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  591. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  592. int prime_fd, uint32_t *handle);
  593. /* export GEM -> dmabuf */
  594. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  595. struct drm_gem_object *obj, int flags);
  596. /* import dmabuf -> GEM */
  597. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  598. struct dma_buf *dma_buf);
  599. /* low-level interface used by drm_gem_prime_{import,export} */
  600. int (*gem_prime_pin)(struct drm_gem_object *obj);
  601. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  602. struct reservation_object * (*gem_prime_res_obj)(
  603. struct drm_gem_object *obj);
  604. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  605. struct drm_gem_object *(*gem_prime_import_sg_table)(
  606. struct drm_device *dev,
  607. struct dma_buf_attachment *attach,
  608. struct sg_table *sgt);
  609. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  610. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  611. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  612. struct vm_area_struct *vma);
  613. /* vga arb irq handler */
  614. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  615. /* dumb alloc support */
  616. int (*dumb_create)(struct drm_file *file_priv,
  617. struct drm_device *dev,
  618. struct drm_mode_create_dumb *args);
  619. int (*dumb_map_offset)(struct drm_file *file_priv,
  620. struct drm_device *dev, uint32_t handle,
  621. uint64_t *offset);
  622. int (*dumb_destroy)(struct drm_file *file_priv,
  623. struct drm_device *dev,
  624. uint32_t handle);
  625. /* Driver private ops for this object */
  626. const struct vm_operations_struct *gem_vm_ops;
  627. int major;
  628. int minor;
  629. int patchlevel;
  630. char *name;
  631. char *desc;
  632. char *date;
  633. u32 driver_features;
  634. int dev_priv_size;
  635. const struct drm_ioctl_desc *ioctls;
  636. int num_ioctls;
  637. const struct file_operations *fops;
  638. /* List of devices hanging off this driver with stealth attach. */
  639. struct list_head legacy_dev_list;
  640. };
  641. enum drm_minor_type {
  642. DRM_MINOR_PRIMARY,
  643. DRM_MINOR_CONTROL,
  644. DRM_MINOR_RENDER,
  645. DRM_MINOR_CNT,
  646. };
  647. /**
  648. * Info file list entry. This structure represents a debugfs or proc file to
  649. * be created by the drm core
  650. */
  651. struct drm_info_list {
  652. const char *name; /** file name */
  653. int (*show)(struct seq_file*, void*); /** show callback */
  654. u32 driver_features; /**< Required driver features for this entry */
  655. void *data;
  656. };
  657. /**
  658. * debugfs node structure. This structure represents a debugfs file.
  659. */
  660. struct drm_info_node {
  661. struct list_head list;
  662. struct drm_minor *minor;
  663. const struct drm_info_list *info_ent;
  664. struct dentry *dent;
  665. };
  666. /**
  667. * DRM minor structure. This structure represents a drm minor number.
  668. */
  669. struct drm_minor {
  670. int index; /**< Minor device number */
  671. int type; /**< Control or render */
  672. struct device *kdev; /**< Linux device */
  673. struct drm_device *dev;
  674. struct dentry *debugfs_root;
  675. struct list_head debugfs_list;
  676. struct mutex debugfs_lock; /* Protects debugfs_list. */
  677. };
  678. /**
  679. * DRM device structure. This structure represent a complete card that
  680. * may contain multiple heads.
  681. */
  682. struct drm_device {
  683. struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
  684. int if_version; /**< Highest interface version set */
  685. /** \name Lifetime Management */
  686. /*@{ */
  687. struct kref ref; /**< Object ref-count */
  688. struct device *dev; /**< Device structure of bus-device */
  689. struct drm_driver *driver; /**< DRM driver managing the device */
  690. void *dev_private; /**< DRM driver private data */
  691. struct drm_minor *control; /**< Control node */
  692. struct drm_minor *primary; /**< Primary node */
  693. struct drm_minor *render; /**< Render node */
  694. /* currently active master for this device. Protected by master_mutex */
  695. struct drm_master *master;
  696. atomic_t unplugged; /**< Flag whether dev is dead */
  697. struct inode *anon_inode; /**< inode for private address-space */
  698. char *unique; /**< unique name of the device */
  699. /*@} */
  700. /** \name Locks */
  701. /*@{ */
  702. struct mutex struct_mutex; /**< For others */
  703. struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
  704. /*@} */
  705. /** \name Usage Counters */
  706. /*@{ */
  707. int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
  708. spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
  709. int buf_use; /**< Buffers in use -- cannot alloc */
  710. atomic_t buf_alloc; /**< Buffer allocation in progress */
  711. /*@} */
  712. struct mutex filelist_mutex;
  713. struct list_head filelist;
  714. /** \name Memory management */
  715. /*@{ */
  716. struct list_head maplist; /**< Linked list of regions */
  717. struct drm_open_hash map_hash; /**< User token hash table for maps */
  718. /** \name Context handle management */
  719. /*@{ */
  720. struct list_head ctxlist; /**< Linked list of context handles */
  721. struct mutex ctxlist_mutex; /**< For ctxlist */
  722. struct idr ctx_idr;
  723. struct list_head vmalist; /**< List of vmas (for debugging) */
  724. /*@} */
  725. /** \name DMA support */
  726. /*@{ */
  727. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  728. /*@} */
  729. /** \name Context support */
  730. /*@{ */
  731. __volatile__ long context_flag; /**< Context swapping flag */
  732. int last_context; /**< Last current context */
  733. /*@} */
  734. /** \name VBLANK IRQ support */
  735. /*@{ */
  736. bool irq_enabled;
  737. int irq;
  738. /*
  739. * If true, vblank interrupt will be disabled immediately when the
  740. * refcount drops to zero, as opposed to via the vblank disable
  741. * timer.
  742. * This can be set to true it the hardware has a working vblank
  743. * counter and the driver uses drm_vblank_on() and drm_vblank_off()
  744. * appropriately.
  745. */
  746. bool vblank_disable_immediate;
  747. /* array of size num_crtcs */
  748. struct drm_vblank_crtc *vblank;
  749. spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
  750. spinlock_t vbl_lock;
  751. u32 max_vblank_count; /**< size of vblank counter register */
  752. /**
  753. * List of events
  754. */
  755. struct list_head vblank_event_list;
  756. spinlock_t event_lock;
  757. /*@} */
  758. struct drm_agp_head *agp; /**< AGP data */
  759. struct pci_dev *pdev; /**< PCI device structure */
  760. #ifdef __alpha__
  761. struct pci_controller *hose;
  762. #endif
  763. struct platform_device *platformdev; /**< Platform device struture */
  764. struct virtio_device *virtdev;
  765. struct drm_sg_mem *sg; /**< Scatter gather memory */
  766. unsigned int num_crtcs; /**< Number of CRTCs on this device */
  767. struct {
  768. int context;
  769. struct drm_hw_lock *lock;
  770. } sigdata;
  771. struct drm_local_map *agp_buffer_map;
  772. unsigned int agp_buffer_token;
  773. struct drm_mode_config mode_config; /**< Current mode config */
  774. /** \name GEM information */
  775. /*@{ */
  776. struct mutex object_name_lock;
  777. struct idr object_name_idr;
  778. struct drm_vma_offset_manager *vma_offset_manager;
  779. /*@} */
  780. int switch_power_state;
  781. };
  782. #include <drm/drm_irq.h>
  783. #define DRM_SWITCH_POWER_ON 0
  784. #define DRM_SWITCH_POWER_OFF 1
  785. #define DRM_SWITCH_POWER_CHANGING 2
  786. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  787. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  788. int feature)
  789. {
  790. return ((dev->driver->driver_features & feature) ? 1 : 0);
  791. }
  792. static inline void drm_device_set_unplugged(struct drm_device *dev)
  793. {
  794. smp_wmb();
  795. atomic_set(&dev->unplugged, 1);
  796. }
  797. static inline int drm_device_is_unplugged(struct drm_device *dev)
  798. {
  799. int ret = atomic_read(&dev->unplugged);
  800. smp_rmb();
  801. return ret;
  802. }
  803. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  804. {
  805. return file_priv->minor->type == DRM_MINOR_RENDER;
  806. }
  807. static inline bool drm_is_control_client(const struct drm_file *file_priv)
  808. {
  809. return file_priv->minor->type == DRM_MINOR_CONTROL;
  810. }
  811. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  812. {
  813. return file_priv->minor->type == DRM_MINOR_PRIMARY;
  814. }
  815. /******************************************************************/
  816. /** \name Internal function definitions */
  817. /*@{*/
  818. /* Driver support (drm_drv.h) */
  819. extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
  820. extern long drm_ioctl(struct file *filp,
  821. unsigned int cmd, unsigned long arg);
  822. extern long drm_compat_ioctl(struct file *filp,
  823. unsigned int cmd, unsigned long arg);
  824. extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  825. /* File Operations (drm_fops.c) */
  826. int drm_open(struct inode *inode, struct file *filp);
  827. ssize_t drm_read(struct file *filp, char __user *buffer,
  828. size_t count, loff_t *offset);
  829. int drm_release(struct inode *inode, struct file *filp);
  830. unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  831. int drm_event_reserve_init_locked(struct drm_device *dev,
  832. struct drm_file *file_priv,
  833. struct drm_pending_event *p,
  834. struct drm_event *e);
  835. int drm_event_reserve_init(struct drm_device *dev,
  836. struct drm_file *file_priv,
  837. struct drm_pending_event *p,
  838. struct drm_event *e);
  839. void drm_event_cancel_free(struct drm_device *dev,
  840. struct drm_pending_event *p);
  841. void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
  842. void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
  843. /* Misc. IOCTL support (drm_ioctl.c) */
  844. int drm_noop(struct drm_device *dev, void *data,
  845. struct drm_file *file_priv);
  846. int drm_invalid_op(struct drm_device *dev, void *data,
  847. struct drm_file *file_priv);
  848. /* Cache management (drm_cache.c) */
  849. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  850. void drm_clflush_sg(struct sg_table *st);
  851. void drm_clflush_virt_range(void *addr, unsigned long length);
  852. /*
  853. * These are exported to drivers so that they can implement fencing using
  854. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  855. */
  856. /* Modesetting support */
  857. extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
  858. extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
  859. /* drm_drv.c */
  860. void drm_put_dev(struct drm_device *dev);
  861. void drm_unplug_dev(struct drm_device *dev);
  862. extern unsigned int drm_debug;
  863. /* Debugfs support */
  864. #if defined(CONFIG_DEBUG_FS)
  865. extern int drm_debugfs_create_files(const struct drm_info_list *files,
  866. int count, struct dentry *root,
  867. struct drm_minor *minor);
  868. extern int drm_debugfs_remove_files(const struct drm_info_list *files,
  869. int count, struct drm_minor *minor);
  870. #else
  871. static inline int drm_debugfs_create_files(const struct drm_info_list *files,
  872. int count, struct dentry *root,
  873. struct drm_minor *minor)
  874. {
  875. return 0;
  876. }
  877. static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
  878. int count, struct drm_minor *minor)
  879. {
  880. return 0;
  881. }
  882. #endif
  883. struct dma_buf_export_info;
  884. extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  885. struct drm_gem_object *obj,
  886. int flags);
  887. extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  888. struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  889. int *prime_fd);
  890. extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  891. struct dma_buf *dma_buf);
  892. extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  893. struct drm_file *file_priv, int prime_fd, uint32_t *handle);
  894. struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
  895. struct dma_buf_export_info *exp_info);
  896. extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
  897. extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  898. dma_addr_t *addrs, int max_pages);
  899. extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
  900. extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
  901. extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
  902. size_t align);
  903. extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
  904. /* sysfs support (drm_sysfs.c) */
  905. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  906. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  907. struct device *parent);
  908. int drm_dev_init(struct drm_device *dev,
  909. struct drm_driver *driver,
  910. struct device *parent);
  911. void drm_dev_ref(struct drm_device *dev);
  912. void drm_dev_unref(struct drm_device *dev);
  913. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  914. void drm_dev_unregister(struct drm_device *dev);
  915. struct drm_minor *drm_minor_acquire(unsigned int minor_id);
  916. void drm_minor_release(struct drm_minor *minor);
  917. /*@}*/
  918. /* PCI section */
  919. static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
  920. {
  921. if (dev->driver->device_is_agp != NULL) {
  922. int err = (*dev->driver->device_is_agp) (dev);
  923. if (err != 2) {
  924. return err;
  925. }
  926. }
  927. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  928. }
  929. void drm_pci_agp_destroy(struct drm_device *dev);
  930. extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  931. extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  932. #ifdef CONFIG_PCI
  933. extern int drm_get_pci_dev(struct pci_dev *pdev,
  934. const struct pci_device_id *ent,
  935. struct drm_driver *driver);
  936. extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
  937. #else
  938. static inline int drm_get_pci_dev(struct pci_dev *pdev,
  939. const struct pci_device_id *ent,
  940. struct drm_driver *driver)
  941. {
  942. return -ENOSYS;
  943. }
  944. static inline int drm_pci_set_busid(struct drm_device *dev,
  945. struct drm_master *master)
  946. {
  947. return -ENOSYS;
  948. }
  949. #endif
  950. #define DRM_PCIE_SPEED_25 1
  951. #define DRM_PCIE_SPEED_50 2
  952. #define DRM_PCIE_SPEED_80 4
  953. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  954. extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
  955. /* platform section */
  956. extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
  957. /* returns true if currently okay to sleep */
  958. static __inline__ bool drm_can_sleep(void)
  959. {
  960. if (in_atomic() || in_dbg_master() || irqs_disabled())
  961. return false;
  962. return true;
  963. }
  964. /* helper for handling conditionals in various for_each macros */
  965. #define for_each_if(condition) if (!(condition)) {} else
  966. #endif