drmP.h 32 KB

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