drmP.h 24 KB

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