drmP.h 37 KB

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