drmP.h 35 KB

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