drmP.h 36 KB

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