drmP.h 35 KB

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