drmP.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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/dma-fence.h>
  59. #include <asm/mman.h>
  60. #include <asm/pgalloc.h>
  61. #include <linux/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. #include <drm/drm_drv.h>
  75. struct module;
  76. struct drm_file;
  77. struct drm_device;
  78. struct drm_agp_head;
  79. struct drm_local_map;
  80. struct drm_device_dma;
  81. struct drm_dma_handle;
  82. struct drm_gem_object;
  83. struct drm_master;
  84. struct drm_vblank_crtc;
  85. struct device_node;
  86. struct videomode;
  87. struct reservation_object;
  88. struct dma_buf_attachment;
  89. /*
  90. * The following categories are defined:
  91. *
  92. * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
  93. * This is the category used by the DRM_DEBUG() macro.
  94. *
  95. * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
  96. * This is the category used by the DRM_DEBUG_DRIVER() macro.
  97. *
  98. * KMS: used in the modesetting code.
  99. * This is the category used by the DRM_DEBUG_KMS() macro.
  100. *
  101. * PRIME: used in the prime code.
  102. * This is the category used by the DRM_DEBUG_PRIME() macro.
  103. *
  104. * ATOMIC: used in the atomic code.
  105. * This is the category used by the DRM_DEBUG_ATOMIC() macro.
  106. *
  107. * VBL: used for verbose debug message in the vblank code
  108. * This is the category used by the DRM_DEBUG_VBL() macro.
  109. *
  110. * Enabling verbose debug messages is done through the drm.debug parameter,
  111. * each category being enabled by a bit.
  112. *
  113. * drm.debug=0x1 will enable CORE messages
  114. * drm.debug=0x2 will enable DRIVER messages
  115. * drm.debug=0x3 will enable CORE and DRIVER messages
  116. * ...
  117. * drm.debug=0x3f will enable all messages
  118. *
  119. * An interesting feature is that it's possible to enable verbose logging at
  120. * run-time by echoing the debug value in its sysfs node:
  121. * # echo 0xf > /sys/module/drm/parameters/debug
  122. */
  123. #define DRM_UT_NONE 0x00
  124. #define DRM_UT_CORE 0x01
  125. #define DRM_UT_DRIVER 0x02
  126. #define DRM_UT_KMS 0x04
  127. #define DRM_UT_PRIME 0x08
  128. #define DRM_UT_ATOMIC 0x10
  129. #define DRM_UT_VBL 0x20
  130. #define DRM_UT_STATE 0x40
  131. /***********************************************************************/
  132. /** \name DRM template customization defaults */
  133. /*@{*/
  134. /***********************************************************************/
  135. /** \name Macros to make printk easier */
  136. /*@{*/
  137. #define _DRM_PRINTK(once, level, fmt, ...) \
  138. do { \
  139. printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
  140. ##__VA_ARGS__); \
  141. } while (0)
  142. #define DRM_INFO(fmt, ...) \
  143. _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
  144. #define DRM_NOTE(fmt, ...) \
  145. _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
  146. #define DRM_WARN(fmt, ...) \
  147. _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
  148. #define DRM_INFO_ONCE(fmt, ...) \
  149. _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
  150. #define DRM_NOTE_ONCE(fmt, ...) \
  151. _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
  152. #define DRM_WARN_ONCE(fmt, ...) \
  153. _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
  154. /**
  155. * Error output.
  156. *
  157. * \param fmt printf() like format string.
  158. * \param arg arguments
  159. */
  160. #define DRM_DEV_ERROR(dev, fmt, ...) \
  161. drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
  162. fmt, ##__VA_ARGS__)
  163. #define DRM_ERROR(fmt, ...) \
  164. drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
  165. /**
  166. * Rate limited error output. Like DRM_ERROR() but won't flood the log.
  167. *
  168. * \param fmt printf() like format string.
  169. * \param arg arguments
  170. */
  171. #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
  172. ({ \
  173. static DEFINE_RATELIMIT_STATE(_rs, \
  174. DEFAULT_RATELIMIT_INTERVAL, \
  175. DEFAULT_RATELIMIT_BURST); \
  176. \
  177. if (__ratelimit(&_rs)) \
  178. DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
  179. })
  180. #define DRM_ERROR_RATELIMITED(fmt, ...) \
  181. DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
  182. #define DRM_DEV_INFO(dev, fmt, ...) \
  183. drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
  184. ##__VA_ARGS__)
  185. #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
  186. ({ \
  187. static bool __print_once __read_mostly; \
  188. if (!__print_once) { \
  189. __print_once = true; \
  190. DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
  191. } \
  192. })
  193. /**
  194. * Debug output.
  195. *
  196. * \param fmt printf() like format string.
  197. * \param arg arguments
  198. */
  199. #define DRM_DEV_DEBUG(dev, fmt, args...) \
  200. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
  201. ##args)
  202. #define DRM_DEBUG(fmt, ...) \
  203. drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
  204. #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
  205. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
  206. fmt, ##args)
  207. #define DRM_DEBUG_DRIVER(fmt, ...) \
  208. drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
  209. #define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
  210. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
  211. ##args)
  212. #define DRM_DEBUG_KMS(fmt, ...) \
  213. drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
  214. #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
  215. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
  216. fmt, ##args)
  217. #define DRM_DEBUG_PRIME(fmt, ...) \
  218. drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
  219. #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
  220. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
  221. fmt, ##args)
  222. #define DRM_DEBUG_ATOMIC(fmt, ...) \
  223. drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
  224. #define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
  225. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
  226. ##args)
  227. #define DRM_DEBUG_VBL(fmt, ...) \
  228. drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
  229. #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
  230. ({ \
  231. static DEFINE_RATELIMIT_STATE(_rs, \
  232. DEFAULT_RATELIMIT_INTERVAL, \
  233. DEFAULT_RATELIMIT_BURST); \
  234. if (__ratelimit(&_rs)) \
  235. drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
  236. __func__, "", fmt, ##args); \
  237. })
  238. /**
  239. * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
  240. *
  241. * \param fmt printf() like format string.
  242. * \param arg arguments
  243. */
  244. #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
  245. DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
  246. #define DRM_DEBUG_RATELIMITED(fmt, args...) \
  247. DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
  248. #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
  249. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
  250. #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
  251. DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
  252. #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
  253. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
  254. #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
  255. DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
  256. #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
  257. _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
  258. #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
  259. DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
  260. /* Format strings and argument splitters to simplify printing
  261. * various "complex" objects
  262. */
  263. #define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
  264. #define DRM_MODE_ARG(m) \
  265. (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
  266. (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
  267. (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
  268. (m)->type, (m)->flags
  269. #define DRM_RECT_FMT "%dx%d%+d%+d"
  270. #define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
  271. /* for rect's in fixed-point format: */
  272. #define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
  273. #define DRM_RECT_FP_ARG(r) \
  274. drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
  275. drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
  276. (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
  277. (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
  278. /*@}*/
  279. /***********************************************************************/
  280. /** \name Internal types and structures */
  281. /*@{*/
  282. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  283. /**
  284. * Ioctl function type.
  285. *
  286. * \param inode device inode.
  287. * \param file_priv DRM file private pointer.
  288. * \param cmd command.
  289. * \param arg argument.
  290. */
  291. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  292. struct drm_file *file_priv);
  293. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  294. unsigned long arg);
  295. #define DRM_IOCTL_NR(n) _IOC_NR(n)
  296. #define DRM_MAJOR 226
  297. #define DRM_AUTH 0x1
  298. #define DRM_MASTER 0x2
  299. #define DRM_ROOT_ONLY 0x4
  300. #define DRM_CONTROL_ALLOW 0x8
  301. #define DRM_UNLOCKED 0x10
  302. #define DRM_RENDER_ALLOW 0x20
  303. struct drm_ioctl_desc {
  304. unsigned int cmd;
  305. int flags;
  306. drm_ioctl_t *func;
  307. const char *name;
  308. };
  309. /**
  310. * Creates a driver or general drm_ioctl_desc array entry for the given
  311. * ioctl, for use by drm_ioctl().
  312. */
  313. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
  314. [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
  315. .cmd = DRM_IOCTL_##ioctl, \
  316. .func = _func, \
  317. .flags = _flags, \
  318. .name = #ioctl \
  319. }
  320. /* Event queued up for userspace to read */
  321. struct drm_pending_event {
  322. struct completion *completion;
  323. void (*completion_release)(struct completion *completion);
  324. struct drm_event *event;
  325. struct dma_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. enum drm_minor_type {
  408. DRM_MINOR_PRIMARY,
  409. DRM_MINOR_CONTROL,
  410. DRM_MINOR_RENDER,
  411. DRM_MINOR_CNT,
  412. };
  413. /**
  414. * Info file list entry. This structure represents a debugfs or proc file to
  415. * be created by the drm core
  416. */
  417. struct drm_info_list {
  418. const char *name; /** file name */
  419. int (*show)(struct seq_file*, void*); /** show callback */
  420. u32 driver_features; /**< Required driver features for this entry */
  421. void *data;
  422. };
  423. /**
  424. * debugfs node structure. This structure represents a debugfs file.
  425. */
  426. struct drm_info_node {
  427. struct list_head list;
  428. struct drm_minor *minor;
  429. const struct drm_info_list *info_ent;
  430. struct dentry *dent;
  431. };
  432. /**
  433. * DRM minor structure. This structure represents a drm minor number.
  434. */
  435. struct drm_minor {
  436. int index; /**< Minor device number */
  437. int type; /**< Control or render */
  438. struct device *kdev; /**< Linux device */
  439. struct drm_device *dev;
  440. struct dentry *debugfs_root;
  441. struct list_head debugfs_list;
  442. struct mutex debugfs_lock; /* Protects debugfs_list. */
  443. };
  444. /**
  445. * DRM device structure. This structure represent a complete card that
  446. * may contain multiple heads.
  447. */
  448. struct drm_device {
  449. struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
  450. int if_version; /**< Highest interface version set */
  451. /** \name Lifetime Management */
  452. /*@{ */
  453. struct kref ref; /**< Object ref-count */
  454. struct device *dev; /**< Device structure of bus-device */
  455. struct drm_driver *driver; /**< DRM driver managing the device */
  456. void *dev_private; /**< DRM driver private data */
  457. struct drm_minor *control; /**< Control node */
  458. struct drm_minor *primary; /**< Primary node */
  459. struct drm_minor *render; /**< Render node */
  460. /* currently active master for this device. Protected by master_mutex */
  461. struct drm_master *master;
  462. atomic_t unplugged; /**< Flag whether dev is dead */
  463. struct inode *anon_inode; /**< inode for private address-space */
  464. char *unique; /**< unique name of the device */
  465. /*@} */
  466. /** \name Locks */
  467. /*@{ */
  468. struct mutex struct_mutex; /**< For others */
  469. struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
  470. /*@} */
  471. /** \name Usage Counters */
  472. /*@{ */
  473. int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
  474. spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
  475. int buf_use; /**< Buffers in use -- cannot alloc */
  476. atomic_t buf_alloc; /**< Buffer allocation in progress */
  477. /*@} */
  478. struct mutex filelist_mutex;
  479. struct list_head filelist;
  480. /** \name Memory management */
  481. /*@{ */
  482. struct list_head maplist; /**< Linked list of regions */
  483. struct drm_open_hash map_hash; /**< User token hash table for maps */
  484. /** \name Context handle management */
  485. /*@{ */
  486. struct list_head ctxlist; /**< Linked list of context handles */
  487. struct mutex ctxlist_mutex; /**< For ctxlist */
  488. struct idr ctx_idr;
  489. struct list_head vmalist; /**< List of vmas (for debugging) */
  490. /*@} */
  491. /** \name DMA support */
  492. /*@{ */
  493. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  494. /*@} */
  495. /** \name Context support */
  496. /*@{ */
  497. __volatile__ long context_flag; /**< Context swapping flag */
  498. int last_context; /**< Last current context */
  499. /*@} */
  500. /** \name VBLANK IRQ support */
  501. /*@{ */
  502. bool irq_enabled;
  503. int irq;
  504. /*
  505. * If true, vblank interrupt will be disabled immediately when the
  506. * refcount drops to zero, as opposed to via the vblank disable
  507. * timer.
  508. * This can be set to true it the hardware has a working vblank
  509. * counter and the driver uses drm_vblank_on() and drm_vblank_off()
  510. * appropriately.
  511. */
  512. bool vblank_disable_immediate;
  513. /* array of size num_crtcs */
  514. struct drm_vblank_crtc *vblank;
  515. spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
  516. spinlock_t vbl_lock;
  517. u32 max_vblank_count; /**< size of vblank counter register */
  518. /**
  519. * List of events
  520. */
  521. struct list_head vblank_event_list;
  522. spinlock_t event_lock;
  523. /*@} */
  524. struct drm_agp_head *agp; /**< AGP data */
  525. struct pci_dev *pdev; /**< PCI device structure */
  526. #ifdef __alpha__
  527. struct pci_controller *hose;
  528. #endif
  529. struct platform_device *platformdev; /**< Platform device struture */
  530. struct virtio_device *virtdev;
  531. struct drm_sg_mem *sg; /**< Scatter gather memory */
  532. unsigned int num_crtcs; /**< Number of CRTCs on this device */
  533. struct {
  534. int context;
  535. struct drm_hw_lock *lock;
  536. } sigdata;
  537. struct drm_local_map *agp_buffer_map;
  538. unsigned int agp_buffer_token;
  539. struct drm_mode_config mode_config; /**< Current mode config */
  540. /** \name GEM information */
  541. /*@{ */
  542. struct mutex object_name_lock;
  543. struct idr object_name_idr;
  544. struct drm_vma_offset_manager *vma_offset_manager;
  545. /*@} */
  546. int switch_power_state;
  547. };
  548. /**
  549. * drm_drv_uses_atomic_modeset - check if the driver implements
  550. * atomic_commit()
  551. * @dev: DRM device
  552. *
  553. * This check is useful if drivers do not have DRIVER_ATOMIC set but
  554. * have atomic modesetting internally implemented.
  555. */
  556. static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
  557. {
  558. return dev->mode_config.funcs->atomic_commit != NULL;
  559. }
  560. #include <drm/drm_irq.h>
  561. #define DRM_SWITCH_POWER_ON 0
  562. #define DRM_SWITCH_POWER_OFF 1
  563. #define DRM_SWITCH_POWER_CHANGING 2
  564. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  565. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  566. int feature)
  567. {
  568. return ((dev->driver->driver_features & feature) ? 1 : 0);
  569. }
  570. static inline void drm_device_set_unplugged(struct drm_device *dev)
  571. {
  572. smp_wmb();
  573. atomic_set(&dev->unplugged, 1);
  574. }
  575. static inline int drm_device_is_unplugged(struct drm_device *dev)
  576. {
  577. int ret = atomic_read(&dev->unplugged);
  578. smp_rmb();
  579. return ret;
  580. }
  581. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  582. {
  583. return file_priv->minor->type == DRM_MINOR_RENDER;
  584. }
  585. static inline bool drm_is_control_client(const struct drm_file *file_priv)
  586. {
  587. return file_priv->minor->type == DRM_MINOR_CONTROL;
  588. }
  589. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  590. {
  591. return file_priv->minor->type == DRM_MINOR_PRIMARY;
  592. }
  593. /******************************************************************/
  594. /** \name Internal function definitions */
  595. /*@{*/
  596. /* Driver support (drm_drv.h) */
  597. extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
  598. extern long drm_ioctl(struct file *filp,
  599. unsigned int cmd, unsigned long arg);
  600. #ifdef CONFIG_COMPAT
  601. extern long drm_compat_ioctl(struct file *filp,
  602. unsigned int cmd, unsigned long arg);
  603. #else
  604. /* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
  605. #define drm_compat_ioctl NULL
  606. #endif
  607. extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  608. /* File Operations (drm_fops.c) */
  609. int drm_open(struct inode *inode, struct file *filp);
  610. ssize_t drm_read(struct file *filp, char __user *buffer,
  611. size_t count, loff_t *offset);
  612. int drm_release(struct inode *inode, struct file *filp);
  613. unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  614. int drm_event_reserve_init_locked(struct drm_device *dev,
  615. struct drm_file *file_priv,
  616. struct drm_pending_event *p,
  617. struct drm_event *e);
  618. int drm_event_reserve_init(struct drm_device *dev,
  619. struct drm_file *file_priv,
  620. struct drm_pending_event *p,
  621. struct drm_event *e);
  622. void drm_event_cancel_free(struct drm_device *dev,
  623. struct drm_pending_event *p);
  624. void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
  625. void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
  626. /* Misc. IOCTL support (drm_ioctl.c) */
  627. int drm_noop(struct drm_device *dev, void *data,
  628. struct drm_file *file_priv);
  629. int drm_invalid_op(struct drm_device *dev, void *data,
  630. struct drm_file *file_priv);
  631. /*
  632. * These are exported to drivers so that they can implement fencing using
  633. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  634. */
  635. /* Debugfs support */
  636. #if defined(CONFIG_DEBUG_FS)
  637. extern int drm_debugfs_create_files(const struct drm_info_list *files,
  638. int count, struct dentry *root,
  639. struct drm_minor *minor);
  640. extern int drm_debugfs_remove_files(const struct drm_info_list *files,
  641. int count, struct drm_minor *minor);
  642. #else
  643. static inline int drm_debugfs_create_files(const struct drm_info_list *files,
  644. int count, struct dentry *root,
  645. struct drm_minor *minor)
  646. {
  647. return 0;
  648. }
  649. static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
  650. int count, struct drm_minor *minor)
  651. {
  652. return 0;
  653. }
  654. #endif
  655. struct dma_buf_export_info;
  656. extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  657. struct drm_gem_object *obj,
  658. int flags);
  659. extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  660. struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  661. int *prime_fd);
  662. extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  663. struct dma_buf *dma_buf);
  664. extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  665. struct drm_file *file_priv, int prime_fd, uint32_t *handle);
  666. struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
  667. struct dma_buf_export_info *exp_info);
  668. extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
  669. extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  670. dma_addr_t *addrs, int max_pages);
  671. extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
  672. extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
  673. extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
  674. size_t align);
  675. extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
  676. /* sysfs support (drm_sysfs.c) */
  677. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  678. /*@}*/
  679. /* PCI section */
  680. static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
  681. {
  682. if (dev->driver->device_is_agp != NULL) {
  683. int err = (*dev->driver->device_is_agp) (dev);
  684. if (err != 2) {
  685. return err;
  686. }
  687. }
  688. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  689. }
  690. void drm_pci_agp_destroy(struct drm_device *dev);
  691. extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  692. extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  693. #ifdef CONFIG_PCI
  694. extern int drm_get_pci_dev(struct pci_dev *pdev,
  695. const struct pci_device_id *ent,
  696. struct drm_driver *driver);
  697. extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
  698. #else
  699. static inline int drm_get_pci_dev(struct pci_dev *pdev,
  700. const struct pci_device_id *ent,
  701. struct drm_driver *driver)
  702. {
  703. return -ENOSYS;
  704. }
  705. static inline int drm_pci_set_busid(struct drm_device *dev,
  706. struct drm_master *master)
  707. {
  708. return -ENOSYS;
  709. }
  710. #endif
  711. #define DRM_PCIE_SPEED_25 1
  712. #define DRM_PCIE_SPEED_50 2
  713. #define DRM_PCIE_SPEED_80 4
  714. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  715. extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
  716. /* platform section */
  717. extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
  718. /* returns true if currently okay to sleep */
  719. static __inline__ bool drm_can_sleep(void)
  720. {
  721. if (in_atomic() || in_dbg_master() || irqs_disabled())
  722. return false;
  723. return true;
  724. }
  725. /* helper for handling conditionals in various for_each macros */
  726. #define for_each_if(condition) if (!(condition)) {} else
  727. #endif