drmP.h 34 KB

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