drmP.h 37 KB

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