drmP.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662
  1. /**
  2. * \file drmP.h
  3. * Private header for Direct Rendering Manager
  4. *
  5. * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6. * \author Gareth Hughes <gareth@valinux.com>
  7. */
  8. /*
  9. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  10. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  11. * Copyright (c) 2009-2010, Code Aurora Forum.
  12. * All rights reserved.
  13. *
  14. * Permission is hereby granted, free of charge, to any person obtaining a
  15. * copy of this software and associated documentation files (the "Software"),
  16. * to deal in the Software without restriction, including without limitation
  17. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  18. * and/or sell copies of the Software, and to permit persons to whom the
  19. * Software is furnished to do so, subject to the following conditions:
  20. *
  21. * The above copyright notice and this permission notice (including the next
  22. * paragraph) shall be included in all copies or substantial portions of the
  23. * Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  28. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  29. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  30. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  31. * OTHER DEALINGS IN THE SOFTWARE.
  32. */
  33. #ifndef _DRM_P_H_
  34. #define _DRM_P_H_
  35. #ifdef __KERNEL__
  36. #ifdef __alpha__
  37. /* add include of current.h so that "current" is defined
  38. * before static inline funcs in wait.h. Doing this so we
  39. * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  40. #include <asm/current.h>
  41. #endif /* __alpha__ */
  42. #include <linux/kernel.h>
  43. #include <linux/kref.h>
  44. #include <linux/miscdevice.h>
  45. #include <linux/fs.h>
  46. #include <linux/init.h>
  47. #include <linux/file.h>
  48. #include <linux/platform_device.h>
  49. #include <linux/pci.h>
  50. #include <linux/jiffies.h>
  51. #include <linux/dma-mapping.h>
  52. #include <linux/mm.h>
  53. #include <linux/cdev.h>
  54. #include <linux/mutex.h>
  55. #include <linux/io.h>
  56. #include <linux/slab.h>
  57. #include <linux/ratelimit.h>
  58. #if defined(__alpha__) || defined(__powerpc__)
  59. #include <asm/pgtable.h> /* For pte_wrprotect */
  60. #endif
  61. #include <asm/mman.h>
  62. #include <asm/uaccess.h>
  63. #include <linux/types.h>
  64. #include <linux/agp_backend.h>
  65. #include <linux/workqueue.h>
  66. #include <linux/poll.h>
  67. #include <asm/pgalloc.h>
  68. #include <drm/drm.h>
  69. #include <drm/drm_sarea.h>
  70. #include <drm/drm_vma_manager.h>
  71. #include <linux/idr.h>
  72. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  73. struct module;
  74. struct drm_file;
  75. struct drm_device;
  76. struct device_node;
  77. struct videomode;
  78. #include <drm/drm_os_linux.h>
  79. #include <drm/drm_hashtab.h>
  80. #include <drm/drm_mm.h>
  81. /*
  82. * 4 debug categories are defined:
  83. *
  84. * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
  85. * This is the category used by the DRM_DEBUG() macro.
  86. *
  87. * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
  88. * This is the category used by the DRM_DEBUG_DRIVER() macro.
  89. *
  90. * KMS: used in the modesetting code.
  91. * This is the category used by the DRM_DEBUG_KMS() macro.
  92. *
  93. * PRIME: used in the prime code.
  94. * This is the category used by the DRM_DEBUG_PRIME() macro.
  95. *
  96. * Enabling verbose debug messages is done through the drm.debug parameter,
  97. * each category being enabled by a bit.
  98. *
  99. * drm.debug=0x1 will enable CORE messages
  100. * drm.debug=0x2 will enable DRIVER messages
  101. * drm.debug=0x3 will enable CORE and DRIVER messages
  102. * ...
  103. * drm.debug=0xf will enable all messages
  104. *
  105. * An interesting feature is that it's possible to enable verbose logging at
  106. * run-time by echoing the debug value in its sysfs node:
  107. * # echo 0xf > /sys/module/drm/parameters/debug
  108. */
  109. #define DRM_UT_CORE 0x01
  110. #define DRM_UT_DRIVER 0x02
  111. #define DRM_UT_KMS 0x04
  112. #define DRM_UT_PRIME 0x08
  113. extern __printf(2, 3)
  114. void drm_ut_debug_printk(const char *function_name,
  115. const char *format, ...);
  116. extern __printf(2, 3)
  117. int drm_err(const char *func, const char *format, ...);
  118. /***********************************************************************/
  119. /** \name DRM template customization defaults */
  120. /*@{*/
  121. /* driver capabilities and requirements mask */
  122. #define DRIVER_USE_AGP 0x1
  123. #define DRIVER_PCI_DMA 0x8
  124. #define DRIVER_SG 0x10
  125. #define DRIVER_HAVE_DMA 0x20
  126. #define DRIVER_HAVE_IRQ 0x40
  127. #define DRIVER_IRQ_SHARED 0x80
  128. #define DRIVER_GEM 0x1000
  129. #define DRIVER_MODESET 0x2000
  130. #define DRIVER_PRIME 0x4000
  131. #define DRIVER_RENDER 0x8000
  132. /***********************************************************************/
  133. /** \name Begin the DRM... */
  134. /*@{*/
  135. #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
  136. also include looping detection. */
  137. #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
  138. #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
  139. #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
  140. #define DRM_MAP_HASH_OFFSET 0x10000000
  141. /*@}*/
  142. /***********************************************************************/
  143. /** \name Macros to make printk easier */
  144. /*@{*/
  145. /**
  146. * Error output.
  147. *
  148. * \param fmt printf() like format string.
  149. * \param arg arguments
  150. */
  151. #define DRM_ERROR(fmt, ...) \
  152. drm_err(__func__, fmt, ##__VA_ARGS__)
  153. /**
  154. * Rate limited error output. Like DRM_ERROR() but won't flood the log.
  155. *
  156. * \param fmt printf() like format string.
  157. * \param arg arguments
  158. */
  159. #define DRM_ERROR_RATELIMITED(fmt, ...) \
  160. ({ \
  161. static DEFINE_RATELIMIT_STATE(_rs, \
  162. DEFAULT_RATELIMIT_INTERVAL, \
  163. DEFAULT_RATELIMIT_BURST); \
  164. \
  165. if (__ratelimit(&_rs)) \
  166. drm_err(__func__, fmt, ##__VA_ARGS__); \
  167. })
  168. #define DRM_INFO(fmt, ...) \
  169. printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  170. #define DRM_INFO_ONCE(fmt, ...) \
  171. printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  172. /**
  173. * Debug output.
  174. *
  175. * \param fmt printf() like format string.
  176. * \param arg arguments
  177. */
  178. #if DRM_DEBUG_CODE
  179. #define DRM_DEBUG(fmt, args...) \
  180. do { \
  181. if (unlikely(drm_debug & DRM_UT_CORE)) \
  182. drm_ut_debug_printk(__func__, fmt, ##args); \
  183. } while (0)
  184. #define DRM_DEBUG_DRIVER(fmt, args...) \
  185. do { \
  186. if (unlikely(drm_debug & DRM_UT_DRIVER)) \
  187. drm_ut_debug_printk(__func__, fmt, ##args); \
  188. } while (0)
  189. #define DRM_DEBUG_KMS(fmt, args...) \
  190. do { \
  191. if (unlikely(drm_debug & DRM_UT_KMS)) \
  192. drm_ut_debug_printk(__func__, fmt, ##args); \
  193. } while (0)
  194. #define DRM_DEBUG_PRIME(fmt, args...) \
  195. do { \
  196. if (unlikely(drm_debug & DRM_UT_PRIME)) \
  197. drm_ut_debug_printk(__func__, fmt, ##args); \
  198. } while (0)
  199. #else
  200. #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
  201. #define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
  202. #define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
  203. #define DRM_DEBUG(fmt, arg...) do { } while (0)
  204. #endif
  205. /*@}*/
  206. /***********************************************************************/
  207. /** \name Internal types and structures */
  208. /*@{*/
  209. #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
  210. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  211. /**
  212. * Test that the hardware lock is held by the caller, returning otherwise.
  213. *
  214. * \param dev DRM device.
  215. * \param filp file pointer of the caller.
  216. */
  217. #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
  218. do { \
  219. if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
  220. _file_priv->master->lock.file_priv != _file_priv) { \
  221. DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
  222. __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  223. _file_priv->master->lock.file_priv, _file_priv); \
  224. return -EINVAL; \
  225. } \
  226. } while (0)
  227. /**
  228. * Ioctl function type.
  229. *
  230. * \param inode device inode.
  231. * \param file_priv DRM file private pointer.
  232. * \param cmd command.
  233. * \param arg argument.
  234. */
  235. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  236. struct drm_file *file_priv);
  237. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  238. unsigned long arg);
  239. #define DRM_IOCTL_NR(n) _IOC_NR(n)
  240. #define DRM_MAJOR 226
  241. #define DRM_AUTH 0x1
  242. #define DRM_MASTER 0x2
  243. #define DRM_ROOT_ONLY 0x4
  244. #define DRM_CONTROL_ALLOW 0x8
  245. #define DRM_UNLOCKED 0x10
  246. #define DRM_RENDER_ALLOW 0x20
  247. struct drm_ioctl_desc {
  248. unsigned int cmd;
  249. int flags;
  250. drm_ioctl_t *func;
  251. unsigned int cmd_drv;
  252. const char *name;
  253. };
  254. /**
  255. * Creates a driver or general drm_ioctl_desc array entry for the given
  256. * ioctl, for use by drm_ioctl().
  257. */
  258. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
  259. [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
  260. struct drm_magic_entry {
  261. struct list_head head;
  262. struct drm_hash_item hash_item;
  263. struct drm_file *priv;
  264. };
  265. struct drm_vma_entry {
  266. struct list_head head;
  267. struct vm_area_struct *vma;
  268. pid_t pid;
  269. };
  270. /**
  271. * DMA buffer.
  272. */
  273. struct drm_buf {
  274. int idx; /**< Index into master buflist */
  275. int total; /**< Buffer size */
  276. int order; /**< log-base-2(total) */
  277. int used; /**< Amount of buffer in use (for DMA) */
  278. unsigned long offset; /**< Byte offset (used internally) */
  279. void *address; /**< Address of buffer */
  280. unsigned long bus_address; /**< Bus address of buffer */
  281. struct drm_buf *next; /**< Kernel-only: used for free list */
  282. __volatile__ int waiting; /**< On kernel DMA queue */
  283. __volatile__ int pending; /**< On hardware DMA queue */
  284. struct drm_file *file_priv; /**< Private of holding file descr */
  285. int context; /**< Kernel queue for this buffer */
  286. int while_locked; /**< Dispatch this buffer while locked */
  287. enum {
  288. DRM_LIST_NONE = 0,
  289. DRM_LIST_FREE = 1,
  290. DRM_LIST_WAIT = 2,
  291. DRM_LIST_PEND = 3,
  292. DRM_LIST_PRIO = 4,
  293. DRM_LIST_RECLAIM = 5
  294. } list; /**< Which list we're on */
  295. int dev_priv_size; /**< Size of buffer private storage */
  296. void *dev_private; /**< Per-buffer private storage */
  297. };
  298. /** bufs is one longer than it has to be */
  299. struct drm_waitlist {
  300. int count; /**< Number of possible buffers */
  301. struct drm_buf **bufs; /**< List of pointers to buffers */
  302. struct drm_buf **rp; /**< Read pointer */
  303. struct drm_buf **wp; /**< Write pointer */
  304. struct drm_buf **end; /**< End pointer */
  305. spinlock_t read_lock;
  306. spinlock_t write_lock;
  307. };
  308. struct drm_freelist {
  309. int initialized; /**< Freelist in use */
  310. atomic_t count; /**< Number of free buffers */
  311. struct drm_buf *next; /**< End pointer */
  312. wait_queue_head_t waiting; /**< Processes waiting on free bufs */
  313. int low_mark; /**< Low water mark */
  314. int high_mark; /**< High water mark */
  315. atomic_t wfh; /**< If waiting for high mark */
  316. spinlock_t lock;
  317. };
  318. typedef struct drm_dma_handle {
  319. dma_addr_t busaddr;
  320. void *vaddr;
  321. size_t size;
  322. } drm_dma_handle_t;
  323. /**
  324. * Buffer entry. There is one of this for each buffer size order.
  325. */
  326. struct drm_buf_entry {
  327. int buf_size; /**< size */
  328. int buf_count; /**< number of buffers */
  329. struct drm_buf *buflist; /**< buffer list */
  330. int seg_count;
  331. int page_order;
  332. struct drm_dma_handle **seglist;
  333. struct drm_freelist freelist;
  334. };
  335. /* Event queued up for userspace to read */
  336. struct drm_pending_event {
  337. struct drm_event *event;
  338. struct list_head link;
  339. struct drm_file *file_priv;
  340. pid_t pid; /* pid of requester, no guarantee it's valid by the time
  341. we deliver the event, for tracing only */
  342. void (*destroy)(struct drm_pending_event *event);
  343. };
  344. /* initial implementaton using a linked list - todo hashtab */
  345. struct drm_prime_file_private {
  346. struct list_head head;
  347. struct mutex lock;
  348. };
  349. /** File private data */
  350. struct drm_file {
  351. unsigned always_authenticated :1;
  352. unsigned authenticated :1;
  353. /* Whether we're master for a minor. Protected by master_mutex */
  354. unsigned is_master :1;
  355. /* true when the client has asked us to expose stereo 3D mode flags */
  356. unsigned stereo_allowed :1;
  357. /*
  358. * true if client understands CRTC primary planes and cursor planes
  359. * in the plane list
  360. */
  361. unsigned universal_planes:1;
  362. struct pid *pid;
  363. kuid_t uid;
  364. drm_magic_t magic;
  365. struct list_head lhead;
  366. struct drm_minor *minor;
  367. unsigned long lock_count;
  368. /** Mapping of mm object handles to object pointers. */
  369. struct idr object_idr;
  370. /** Lock for synchronization of access to object_idr. */
  371. spinlock_t table_lock;
  372. struct file *filp;
  373. void *driver_priv;
  374. struct drm_master *master; /* master this node is currently associated with
  375. N.B. not always minor->master */
  376. /**
  377. * fbs - List of framebuffers associated with this file.
  378. *
  379. * Protected by fbs_lock. Note that the fbs list holds a reference on
  380. * the fb object to prevent it from untimely disappearing.
  381. */
  382. struct list_head fbs;
  383. struct mutex fbs_lock;
  384. wait_queue_head_t event_wait;
  385. struct list_head event_list;
  386. int event_space;
  387. struct drm_prime_file_private prime;
  388. };
  389. /** Wait queue */
  390. struct drm_queue {
  391. atomic_t use_count; /**< Outstanding uses (+1) */
  392. atomic_t finalization; /**< Finalization in progress */
  393. atomic_t block_count; /**< Count of processes waiting */
  394. atomic_t block_read; /**< Queue blocked for reads */
  395. wait_queue_head_t read_queue; /**< Processes waiting on block_read */
  396. atomic_t block_write; /**< Queue blocked for writes */
  397. wait_queue_head_t write_queue; /**< Processes waiting on block_write */
  398. atomic_t total_queued; /**< Total queued statistic */
  399. atomic_t total_flushed; /**< Total flushes statistic */
  400. atomic_t total_locks; /**< Total locks statistics */
  401. enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
  402. struct drm_waitlist waitlist; /**< Pending buffers */
  403. wait_queue_head_t flush_queue; /**< Processes waiting until flush */
  404. };
  405. /**
  406. * Lock data.
  407. */
  408. struct drm_lock_data {
  409. struct drm_hw_lock *hw_lock; /**< Hardware lock */
  410. /** Private of lock holder's file (NULL=kernel) */
  411. struct drm_file *file_priv;
  412. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  413. unsigned long lock_time; /**< Time of last lock in jiffies */
  414. spinlock_t spinlock;
  415. uint32_t kernel_waiters;
  416. uint32_t user_waiters;
  417. int idle_has_lock;
  418. };
  419. /**
  420. * DMA data.
  421. */
  422. struct drm_device_dma {
  423. struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  424. int buf_count; /**< total number of buffers */
  425. struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  426. int seg_count;
  427. int page_count; /**< number of pages */
  428. unsigned long *pagelist; /**< page list */
  429. unsigned long byte_count;
  430. enum {
  431. _DRM_DMA_USE_AGP = 0x01,
  432. _DRM_DMA_USE_SG = 0x02,
  433. _DRM_DMA_USE_FB = 0x04,
  434. _DRM_DMA_USE_PCI_RO = 0x08
  435. } flags;
  436. };
  437. /**
  438. * AGP memory entry. Stored as a doubly linked list.
  439. */
  440. struct drm_agp_mem {
  441. unsigned long handle; /**< handle */
  442. struct agp_memory *memory;
  443. unsigned long bound; /**< address */
  444. int pages;
  445. struct list_head head;
  446. };
  447. /**
  448. * AGP data.
  449. *
  450. * \sa drm_agp_init() and drm_device::agp.
  451. */
  452. struct drm_agp_head {
  453. struct agp_kern_info agp_info; /**< AGP device information */
  454. struct list_head memory;
  455. unsigned long mode; /**< AGP mode */
  456. struct agp_bridge_data *bridge;
  457. int enabled; /**< whether the AGP bus as been enabled */
  458. int acquired; /**< whether the AGP device has been acquired */
  459. unsigned long base;
  460. int agp_mtrr;
  461. int cant_use_aperture;
  462. unsigned long page_mask;
  463. };
  464. /**
  465. * Scatter-gather memory.
  466. */
  467. struct drm_sg_mem {
  468. unsigned long handle;
  469. void *virtual;
  470. int pages;
  471. struct page **pagelist;
  472. dma_addr_t *busaddr;
  473. };
  474. struct drm_sigdata {
  475. int context;
  476. struct drm_hw_lock *lock;
  477. };
  478. /**
  479. * Kernel side of a mapping
  480. */
  481. struct drm_local_map {
  482. resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
  483. unsigned long size; /**< Requested physical size (bytes) */
  484. enum drm_map_type type; /**< Type of memory to map */
  485. enum drm_map_flags flags; /**< Flags */
  486. void *handle; /**< User-space: "Handle" to pass to mmap() */
  487. /**< Kernel-space: kernel-virtual address */
  488. int mtrr; /**< MTRR slot used */
  489. };
  490. typedef struct drm_local_map drm_local_map_t;
  491. /**
  492. * Mappings list
  493. */
  494. struct drm_map_list {
  495. struct list_head head; /**< list head */
  496. struct drm_hash_item hash;
  497. struct drm_local_map *map; /**< mapping */
  498. uint64_t user_token;
  499. struct drm_master *master;
  500. };
  501. /**
  502. * Context handle list
  503. */
  504. struct drm_ctx_list {
  505. struct list_head head; /**< list head */
  506. drm_context_t handle; /**< context handle */
  507. struct drm_file *tag; /**< associated fd private data */
  508. };
  509. /* location of GART table */
  510. #define DRM_ATI_GART_MAIN 1
  511. #define DRM_ATI_GART_FB 2
  512. #define DRM_ATI_GART_PCI 1
  513. #define DRM_ATI_GART_PCIE 2
  514. #define DRM_ATI_GART_IGP 3
  515. struct drm_ati_pcigart_info {
  516. int gart_table_location;
  517. int gart_reg_if;
  518. void *addr;
  519. dma_addr_t bus_addr;
  520. dma_addr_t table_mask;
  521. struct drm_dma_handle *table_handle;
  522. struct drm_local_map mapping;
  523. int table_size;
  524. };
  525. /**
  526. * This structure defines the drm_mm memory object, which will be used by the
  527. * DRM for its buffer objects.
  528. */
  529. struct drm_gem_object {
  530. /** Reference count of this object */
  531. struct kref refcount;
  532. /**
  533. * handle_count - gem file_priv handle count of this object
  534. *
  535. * Each handle also holds a reference. Note that when the handle_count
  536. * drops to 0 any global names (e.g. the id in the flink namespace) will
  537. * be cleared.
  538. *
  539. * Protected by dev->object_name_lock.
  540. * */
  541. unsigned handle_count;
  542. /** Related drm device */
  543. struct drm_device *dev;
  544. /** File representing the shmem storage */
  545. struct file *filp;
  546. /* Mapping info for this object */
  547. struct drm_vma_offset_node vma_node;
  548. /**
  549. * Size of the object, in bytes. Immutable over the object's
  550. * lifetime.
  551. */
  552. size_t size;
  553. /**
  554. * Global name for this object, starts at 1. 0 means unnamed.
  555. * Access is covered by the object_name_lock in the related drm_device
  556. */
  557. int name;
  558. /**
  559. * Memory domains. These monitor which caches contain read/write data
  560. * related to the object. When transitioning from one set of domains
  561. * to another, the driver is called to ensure that caches are suitably
  562. * flushed and invalidated
  563. */
  564. uint32_t read_domains;
  565. uint32_t write_domain;
  566. /**
  567. * While validating an exec operation, the
  568. * new read/write domain values are computed here.
  569. * They will be transferred to the above values
  570. * at the point that any cache flushing occurs
  571. */
  572. uint32_t pending_read_domains;
  573. uint32_t pending_write_domain;
  574. /**
  575. * dma_buf - dma buf associated with this GEM object
  576. *
  577. * Pointer to the dma-buf associated with this gem object (either
  578. * through importing or exporting). We break the resulting reference
  579. * loop when the last gem handle for this object is released.
  580. *
  581. * Protected by obj->object_name_lock
  582. */
  583. struct dma_buf *dma_buf;
  584. /**
  585. * import_attach - dma buf attachment backing this object
  586. *
  587. * Any foreign dma_buf imported as a gem object has this set to the
  588. * attachment point for the device. This is invariant over the lifetime
  589. * of a gem object.
  590. *
  591. * The driver's ->gem_free_object callback is responsible for cleaning
  592. * up the dma_buf attachment and references acquired at import time.
  593. *
  594. * Note that the drm gem/prime core does not depend upon drivers setting
  595. * this field any more. So for drivers where this doesn't make sense
  596. * (e.g. virtual devices or a displaylink behind an usb bus) they can
  597. * simply leave it as NULL.
  598. */
  599. struct dma_buf_attachment *import_attach;
  600. };
  601. #include <drm/drm_crtc.h>
  602. /**
  603. * struct drm_master - drm master structure
  604. *
  605. * @refcount: Refcount for this master object.
  606. * @minor: Link back to minor char device we are master for. Immutable.
  607. * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
  608. * @unique_len: Length of unique field. Protected by drm_global_mutex.
  609. * @unique_size: Amount allocated. Protected by drm_global_mutex.
  610. * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
  611. * @magicfree: List of used authentication tokens. Protected by struct_mutex.
  612. * @lock: DRI lock information.
  613. * @driver_priv: Pointer to driver-private information.
  614. */
  615. struct drm_master {
  616. struct kref refcount;
  617. struct drm_minor *minor;
  618. char *unique;
  619. int unique_len;
  620. int unique_size;
  621. struct drm_open_hash magiclist;
  622. struct list_head magicfree;
  623. struct drm_lock_data lock;
  624. void *driver_priv;
  625. };
  626. /* Size of ringbuffer for vblank timestamps. Just double-buffer
  627. * in initial implementation.
  628. */
  629. #define DRM_VBLANKTIME_RBSIZE 2
  630. /* Flags and return codes for get_vblank_timestamp() driver function. */
  631. #define DRM_CALLED_FROM_VBLIRQ 1
  632. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  633. #define DRM_VBLANKTIME_INVBL (1 << 1)
  634. /* get_scanout_position() return flags */
  635. #define DRM_SCANOUTPOS_VALID (1 << 0)
  636. #define DRM_SCANOUTPOS_INVBL (1 << 1)
  637. #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
  638. struct drm_bus {
  639. int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  640. };
  641. /**
  642. * DRM driver structure. This structure represent the common code for
  643. * a family of cards. There will one drm_device for each card present
  644. * in this family
  645. */
  646. struct drm_driver {
  647. int (*load) (struct drm_device *, unsigned long flags);
  648. int (*firstopen) (struct drm_device *);
  649. int (*open) (struct drm_device *, struct drm_file *);
  650. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  651. void (*postclose) (struct drm_device *, struct drm_file *);
  652. void (*lastclose) (struct drm_device *);
  653. int (*unload) (struct drm_device *);
  654. int (*suspend) (struct drm_device *, pm_message_t state);
  655. int (*resume) (struct drm_device *);
  656. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  657. int (*dma_quiescent) (struct drm_device *);
  658. int (*context_dtor) (struct drm_device *dev, int context);
  659. /**
  660. * get_vblank_counter - get raw hardware vblank counter
  661. * @dev: DRM device
  662. * @crtc: counter to fetch
  663. *
  664. * Driver callback for fetching a raw hardware vblank counter for @crtc.
  665. * If a device doesn't have a hardware counter, the driver can simply
  666. * return the value of drm_vblank_count. The DRM core will account for
  667. * missed vblank events while interrupts where disabled based on system
  668. * timestamps.
  669. *
  670. * Wraparound handling and loss of events due to modesetting is dealt
  671. * with in the DRM core code.
  672. *
  673. * RETURNS
  674. * Raw vblank counter value.
  675. */
  676. u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  677. /**
  678. * enable_vblank - enable vblank interrupt events
  679. * @dev: DRM device
  680. * @crtc: which irq to enable
  681. *
  682. * Enable vblank interrupts for @crtc. If the device doesn't have
  683. * a hardware vblank counter, this routine should be a no-op, since
  684. * interrupts will have to stay on to keep the count accurate.
  685. *
  686. * RETURNS
  687. * Zero on success, appropriate errno if the given @crtc's vblank
  688. * interrupt cannot be enabled.
  689. */
  690. int (*enable_vblank) (struct drm_device *dev, int crtc);
  691. /**
  692. * disable_vblank - disable vblank interrupt events
  693. * @dev: DRM device
  694. * @crtc: which irq to enable
  695. *
  696. * Disable vblank interrupts for @crtc. If the device doesn't have
  697. * a hardware vblank counter, this routine should be a no-op, since
  698. * interrupts will have to stay on to keep the count accurate.
  699. */
  700. void (*disable_vblank) (struct drm_device *dev, int crtc);
  701. /**
  702. * Called by \c drm_device_is_agp. Typically used to determine if a
  703. * card is really attached to AGP or not.
  704. *
  705. * \param dev DRM device handle
  706. *
  707. * \returns
  708. * One of three values is returned depending on whether or not the
  709. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  710. * (return of 1), or may or may not be AGP (return of 2).
  711. */
  712. int (*device_is_agp) (struct drm_device *dev);
  713. /**
  714. * Called by vblank timestamping code.
  715. *
  716. * Return the current display scanout position from a crtc, and an
  717. * optional accurate ktime_get timestamp of when position was measured.
  718. *
  719. * \param dev DRM device.
  720. * \param crtc Id of the crtc to query.
  721. * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  722. * \param *vpos Target location for current vertical scanout position.
  723. * \param *hpos Target location for current horizontal scanout position.
  724. * \param *stime Target location for timestamp taken immediately before
  725. * scanout position query. Can be NULL to skip timestamp.
  726. * \param *etime Target location for timestamp taken immediately after
  727. * scanout position query. Can be NULL to skip timestamp.
  728. *
  729. * Returns vpos as a positive number while in active scanout area.
  730. * Returns vpos as a negative number inside vblank, counting the number
  731. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  732. * until start of active scanout / end of vblank."
  733. *
  734. * \return Flags, or'ed together as follows:
  735. *
  736. * DRM_SCANOUTPOS_VALID = Query successful.
  737. * DRM_SCANOUTPOS_INVBL = Inside vblank.
  738. * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  739. * this flag means that returned position may be offset by a constant
  740. * but unknown small number of scanlines wrt. real scanout position.
  741. *
  742. */
  743. int (*get_scanout_position) (struct drm_device *dev, int crtc,
  744. unsigned int flags,
  745. int *vpos, int *hpos, ktime_t *stime,
  746. ktime_t *etime);
  747. /**
  748. * Called by \c drm_get_last_vbltimestamp. Should return a precise
  749. * timestamp when the most recent VBLANK interval ended or will end.
  750. *
  751. * Specifically, the timestamp in @vblank_time should correspond as
  752. * closely as possible to the time when the first video scanline of
  753. * the video frame after the end of VBLANK will start scanning out,
  754. * the time immediately after end of the VBLANK interval. If the
  755. * @crtc is currently inside VBLANK, this will be a time in the future.
  756. * If the @crtc is currently scanning out a frame, this will be the
  757. * past start time of the current scanout. This is meant to adhere
  758. * to the OpenML OML_sync_control extension specification.
  759. *
  760. * \param dev dev DRM device handle.
  761. * \param crtc crtc for which timestamp should be returned.
  762. * \param *max_error Maximum allowable timestamp error in nanoseconds.
  763. * Implementation should strive to provide timestamp
  764. * with an error of at most *max_error nanoseconds.
  765. * Returns true upper bound on error for timestamp.
  766. * \param *vblank_time Target location for returned vblank timestamp.
  767. * \param flags 0 = Defaults, no special treatment needed.
  768. * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  769. * irq handler. Some drivers need to apply some workarounds
  770. * for gpu-specific vblank irq quirks if flag is set.
  771. *
  772. * \returns
  773. * Zero if timestamping isn't supported in current display mode or a
  774. * negative number on failure. A positive status code on success,
  775. * which describes how the vblank_time timestamp was computed.
  776. */
  777. int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
  778. int *max_error,
  779. struct timeval *vblank_time,
  780. unsigned flags);
  781. /* these have to be filled in */
  782. irqreturn_t(*irq_handler) (int irq, void *arg);
  783. void (*irq_preinstall) (struct drm_device *dev);
  784. int (*irq_postinstall) (struct drm_device *dev);
  785. void (*irq_uninstall) (struct drm_device *dev);
  786. /* Master routines */
  787. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  788. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  789. /**
  790. * master_set is called whenever the minor master is set.
  791. * master_drop is called whenever the minor master is dropped.
  792. */
  793. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  794. bool from_open);
  795. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
  796. bool from_release);
  797. int (*debugfs_init)(struct drm_minor *minor);
  798. void (*debugfs_cleanup)(struct drm_minor *minor);
  799. /**
  800. * Driver-specific constructor for drm_gem_objects, to set up
  801. * obj->driver_private.
  802. *
  803. * Returns 0 on success.
  804. */
  805. void (*gem_free_object) (struct drm_gem_object *obj);
  806. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  807. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  808. /* prime: */
  809. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  810. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  811. uint32_t handle, uint32_t flags, int *prime_fd);
  812. /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  813. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  814. int prime_fd, uint32_t *handle);
  815. /* export GEM -> dmabuf */
  816. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  817. struct drm_gem_object *obj, int flags);
  818. /* import dmabuf -> GEM */
  819. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  820. struct dma_buf *dma_buf);
  821. /* low-level interface used by drm_gem_prime_{import,export} */
  822. int (*gem_prime_pin)(struct drm_gem_object *obj);
  823. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  824. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  825. struct drm_gem_object *(*gem_prime_import_sg_table)(
  826. struct drm_device *dev, size_t size,
  827. struct sg_table *sgt);
  828. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  829. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  830. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  831. struct vm_area_struct *vma);
  832. /* vga arb irq handler */
  833. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  834. /* dumb alloc support */
  835. int (*dumb_create)(struct drm_file *file_priv,
  836. struct drm_device *dev,
  837. struct drm_mode_create_dumb *args);
  838. int (*dumb_map_offset)(struct drm_file *file_priv,
  839. struct drm_device *dev, uint32_t handle,
  840. uint64_t *offset);
  841. int (*dumb_destroy)(struct drm_file *file_priv,
  842. struct drm_device *dev,
  843. uint32_t handle);
  844. /* Driver private ops for this object */
  845. const struct vm_operations_struct *gem_vm_ops;
  846. int major;
  847. int minor;
  848. int patchlevel;
  849. char *name;
  850. char *desc;
  851. char *date;
  852. u32 driver_features;
  853. int dev_priv_size;
  854. const struct drm_ioctl_desc *ioctls;
  855. int num_ioctls;
  856. const struct file_operations *fops;
  857. struct drm_bus *bus;
  858. /* List of devices hanging off this driver with stealth attach. */
  859. struct list_head legacy_dev_list;
  860. };
  861. enum drm_minor_type {
  862. DRM_MINOR_LEGACY,
  863. DRM_MINOR_CONTROL,
  864. DRM_MINOR_RENDER,
  865. DRM_MINOR_CNT,
  866. };
  867. /**
  868. * Info file list entry. This structure represents a debugfs or proc file to
  869. * be created by the drm core
  870. */
  871. struct drm_info_list {
  872. const char *name; /** file name */
  873. int (*show)(struct seq_file*, void*); /** show callback */
  874. u32 driver_features; /**< Required driver features for this entry */
  875. void *data;
  876. };
  877. /**
  878. * debugfs node structure. This structure represents a debugfs file.
  879. */
  880. struct drm_info_node {
  881. struct list_head list;
  882. struct drm_minor *minor;
  883. const struct drm_info_list *info_ent;
  884. struct dentry *dent;
  885. };
  886. /**
  887. * DRM minor structure. This structure represents a drm minor number.
  888. */
  889. struct drm_minor {
  890. int index; /**< Minor device number */
  891. int type; /**< Control or render */
  892. struct device *kdev; /**< Linux device */
  893. struct drm_device *dev;
  894. struct dentry *debugfs_root;
  895. struct list_head debugfs_list;
  896. struct mutex debugfs_lock; /* Protects debugfs_list. */
  897. /* currently active master for this node. Protected by master_mutex */
  898. struct drm_master *master;
  899. struct drm_mode_group mode_group;
  900. };
  901. struct drm_pending_vblank_event {
  902. struct drm_pending_event base;
  903. int pipe;
  904. struct drm_event_vblank event;
  905. };
  906. struct drm_vblank_crtc {
  907. wait_queue_head_t queue; /**< VBLANK wait queue */
  908. struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
  909. atomic_t count; /**< number of VBLANK interrupts */
  910. atomic_t refcount; /* number of users of vblank interruptsper crtc */
  911. u32 last; /* protected by dev->vbl_lock, used */
  912. /* for wraparound handling */
  913. u32 last_wait; /* Last vblank seqno waited per CRTC */
  914. unsigned int inmodeset; /* Display driver is setting mode */
  915. bool enabled; /* so we don't call enable more than
  916. once per disable */
  917. };
  918. /**
  919. * DRM device structure. This structure represent a complete card that
  920. * may contain multiple heads.
  921. */
  922. struct drm_device {
  923. struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
  924. int if_version; /**< Highest interface version set */
  925. /** \name Lifetime Management */
  926. /*@{ */
  927. struct kref ref; /**< Object ref-count */
  928. struct device *dev; /**< Device structure of bus-device */
  929. struct drm_driver *driver; /**< DRM driver managing the device */
  930. void *dev_private; /**< DRM driver private data */
  931. struct drm_minor *control; /**< Control node */
  932. struct drm_minor *primary; /**< Primary node */
  933. struct drm_minor *render; /**< Render node */
  934. atomic_t unplugged; /**< Flag whether dev is dead */
  935. struct inode *anon_inode; /**< inode for private address-space */
  936. /*@} */
  937. /** \name Locks */
  938. /*@{ */
  939. struct mutex struct_mutex; /**< For others */
  940. struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
  941. /*@} */
  942. /** \name Usage Counters */
  943. /*@{ */
  944. int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
  945. spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
  946. int buf_use; /**< Buffers in use -- cannot alloc */
  947. atomic_t buf_alloc; /**< Buffer allocation in progress */
  948. /*@} */
  949. struct list_head filelist;
  950. /** \name Memory management */
  951. /*@{ */
  952. struct list_head maplist; /**< Linked list of regions */
  953. struct drm_open_hash map_hash; /**< User token hash table for maps */
  954. /** \name Context handle management */
  955. /*@{ */
  956. struct list_head ctxlist; /**< Linked list of context handles */
  957. struct mutex ctxlist_mutex; /**< For ctxlist */
  958. struct idr ctx_idr;
  959. struct list_head vmalist; /**< List of vmas (for debugging) */
  960. /*@} */
  961. /** \name DMA support */
  962. /*@{ */
  963. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  964. /*@} */
  965. /** \name Context support */
  966. /*@{ */
  967. bool irq_enabled; /**< True if irq handler is enabled */
  968. int irq;
  969. __volatile__ long context_flag; /**< Context swapping flag */
  970. int last_context; /**< Last current context */
  971. /*@} */
  972. /** \name VBLANK IRQ support */
  973. /*@{ */
  974. /*
  975. * At load time, disabling the vblank interrupt won't be allowed since
  976. * old clients may not call the modeset ioctl and therefore misbehave.
  977. * Once the modeset ioctl *has* been called though, we can safely
  978. * disable them when unused.
  979. */
  980. bool vblank_disable_allowed;
  981. /* array of size num_crtcs */
  982. struct drm_vblank_crtc *vblank;
  983. spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
  984. spinlock_t vbl_lock;
  985. struct timer_list vblank_disable_timer;
  986. u32 max_vblank_count; /**< size of vblank counter register */
  987. /**
  988. * List of events
  989. */
  990. struct list_head vblank_event_list;
  991. spinlock_t event_lock;
  992. /*@} */
  993. struct drm_agp_head *agp; /**< AGP data */
  994. struct pci_dev *pdev; /**< PCI device structure */
  995. #ifdef __alpha__
  996. struct pci_controller *hose;
  997. #endif
  998. struct platform_device *platformdev; /**< Platform device struture */
  999. struct usb_device *usbdev;
  1000. struct drm_sg_mem *sg; /**< Scatter gather memory */
  1001. unsigned int num_crtcs; /**< Number of CRTCs on this device */
  1002. struct drm_sigdata sigdata; /**< For block_all_signals */
  1003. sigset_t sigmask;
  1004. struct drm_local_map *agp_buffer_map;
  1005. unsigned int agp_buffer_token;
  1006. struct drm_mode_config mode_config; /**< Current mode config */
  1007. /** \name GEM information */
  1008. /*@{ */
  1009. struct mutex object_name_lock;
  1010. struct idr object_name_idr;
  1011. struct drm_vma_offset_manager *vma_offset_manager;
  1012. /*@} */
  1013. int switch_power_state;
  1014. };
  1015. #define DRM_SWITCH_POWER_ON 0
  1016. #define DRM_SWITCH_POWER_OFF 1
  1017. #define DRM_SWITCH_POWER_CHANGING 2
  1018. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  1019. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  1020. int feature)
  1021. {
  1022. return ((dev->driver->driver_features & feature) ? 1 : 0);
  1023. }
  1024. static inline void drm_device_set_unplugged(struct drm_device *dev)
  1025. {
  1026. smp_wmb();
  1027. atomic_set(&dev->unplugged, 1);
  1028. }
  1029. static inline int drm_device_is_unplugged(struct drm_device *dev)
  1030. {
  1031. int ret = atomic_read(&dev->unplugged);
  1032. smp_rmb();
  1033. return ret;
  1034. }
  1035. static inline bool drm_modeset_is_locked(struct drm_device *dev)
  1036. {
  1037. return mutex_is_locked(&dev->mode_config.mutex);
  1038. }
  1039. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  1040. {
  1041. return file_priv->minor->type == DRM_MINOR_RENDER;
  1042. }
  1043. static inline bool drm_is_control_client(const struct drm_file *file_priv)
  1044. {
  1045. return file_priv->minor->type == DRM_MINOR_CONTROL;
  1046. }
  1047. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  1048. {
  1049. return file_priv->minor->type == DRM_MINOR_LEGACY;
  1050. }
  1051. /******************************************************************/
  1052. /** \name Internal function definitions */
  1053. /*@{*/
  1054. /* Driver support (drm_drv.h) */
  1055. extern long drm_ioctl(struct file *filp,
  1056. unsigned int cmd, unsigned long arg);
  1057. extern long drm_compat_ioctl(struct file *filp,
  1058. unsigned int cmd, unsigned long arg);
  1059. extern int drm_lastclose(struct drm_device *dev);
  1060. extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  1061. /* Device support (drm_fops.h) */
  1062. extern struct mutex drm_global_mutex;
  1063. extern int drm_open(struct inode *inode, struct file *filp);
  1064. extern int drm_stub_open(struct inode *inode, struct file *filp);
  1065. extern ssize_t drm_read(struct file *filp, char __user *buffer,
  1066. size_t count, loff_t *offset);
  1067. extern int drm_release(struct inode *inode, struct file *filp);
  1068. /* Mapping support (drm_vm.h) */
  1069. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  1070. extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
  1071. extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1072. extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1073. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  1074. /* Memory management support (drm_memory.h) */
  1075. #include <drm/drm_memory.h>
  1076. /* Misc. IOCTL support (drm_ioctl.h) */
  1077. extern int drm_irq_by_busid(struct drm_device *dev, void *data,
  1078. struct drm_file *file_priv);
  1079. extern int drm_getunique(struct drm_device *dev, void *data,
  1080. struct drm_file *file_priv);
  1081. extern int drm_setunique(struct drm_device *dev, void *data,
  1082. struct drm_file *file_priv);
  1083. extern int drm_getmap(struct drm_device *dev, void *data,
  1084. struct drm_file *file_priv);
  1085. extern int drm_getclient(struct drm_device *dev, void *data,
  1086. struct drm_file *file_priv);
  1087. extern int drm_getstats(struct drm_device *dev, void *data,
  1088. struct drm_file *file_priv);
  1089. extern int drm_getcap(struct drm_device *dev, void *data,
  1090. struct drm_file *file_priv);
  1091. extern int drm_setclientcap(struct drm_device *dev, void *data,
  1092. struct drm_file *file_priv);
  1093. extern int drm_setversion(struct drm_device *dev, void *data,
  1094. struct drm_file *file_priv);
  1095. extern int drm_noop(struct drm_device *dev, void *data,
  1096. struct drm_file *file_priv);
  1097. /* Context IOCTL support (drm_context.h) */
  1098. extern int drm_resctx(struct drm_device *dev, void *data,
  1099. struct drm_file *file_priv);
  1100. extern int drm_addctx(struct drm_device *dev, void *data,
  1101. struct drm_file *file_priv);
  1102. extern int drm_getctx(struct drm_device *dev, void *data,
  1103. struct drm_file *file_priv);
  1104. extern int drm_switchctx(struct drm_device *dev, void *data,
  1105. struct drm_file *file_priv);
  1106. extern int drm_newctx(struct drm_device *dev, void *data,
  1107. struct drm_file *file_priv);
  1108. extern int drm_rmctx(struct drm_device *dev, void *data,
  1109. struct drm_file *file_priv);
  1110. extern int drm_ctxbitmap_init(struct drm_device *dev);
  1111. extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
  1112. extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
  1113. extern int drm_setsareactx(struct drm_device *dev, void *data,
  1114. struct drm_file *file_priv);
  1115. extern int drm_getsareactx(struct drm_device *dev, void *data,
  1116. struct drm_file *file_priv);
  1117. /* Authentication IOCTL support (drm_auth.h) */
  1118. extern int drm_getmagic(struct drm_device *dev, void *data,
  1119. struct drm_file *file_priv);
  1120. extern int drm_authmagic(struct drm_device *dev, void *data,
  1121. struct drm_file *file_priv);
  1122. extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
  1123. /* Cache management (drm_cache.c) */
  1124. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  1125. void drm_clflush_sg(struct sg_table *st);
  1126. void drm_clflush_virt_range(void *addr, unsigned long length);
  1127. /* Locking IOCTL support (drm_lock.h) */
  1128. extern int drm_lock(struct drm_device *dev, void *data,
  1129. struct drm_file *file_priv);
  1130. extern int drm_unlock(struct drm_device *dev, void *data,
  1131. struct drm_file *file_priv);
  1132. extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
  1133. extern void drm_idlelock_take(struct drm_lock_data *lock_data);
  1134. extern void drm_idlelock_release(struct drm_lock_data *lock_data);
  1135. /*
  1136. * These are exported to drivers so that they can implement fencing using
  1137. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  1138. */
  1139. extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
  1140. /* Buffer management support (drm_bufs.h) */
  1141. extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
  1142. extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
  1143. extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
  1144. unsigned int size, enum drm_map_type type,
  1145. enum drm_map_flags flags, struct drm_local_map **map_ptr);
  1146. extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
  1147. struct drm_file *file_priv);
  1148. extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
  1149. extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
  1150. extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
  1151. struct drm_file *file_priv);
  1152. extern int drm_addbufs(struct drm_device *dev, void *data,
  1153. struct drm_file *file_priv);
  1154. extern int drm_infobufs(struct drm_device *dev, void *data,
  1155. struct drm_file *file_priv);
  1156. extern int drm_markbufs(struct drm_device *dev, void *data,
  1157. struct drm_file *file_priv);
  1158. extern int drm_freebufs(struct drm_device *dev, void *data,
  1159. struct drm_file *file_priv);
  1160. extern int drm_mapbufs(struct drm_device *dev, void *data,
  1161. struct drm_file *file_priv);
  1162. extern int drm_dma_ioctl(struct drm_device *dev, void *data,
  1163. struct drm_file *file_priv);
  1164. /* DMA support (drm_dma.h) */
  1165. extern int drm_legacy_dma_setup(struct drm_device *dev);
  1166. extern void drm_legacy_dma_takedown(struct drm_device *dev);
  1167. extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
  1168. extern void drm_core_reclaim_buffers(struct drm_device *dev,
  1169. struct drm_file *filp);
  1170. /* IRQ support (drm_irq.h) */
  1171. extern int drm_control(struct drm_device *dev, void *data,
  1172. struct drm_file *file_priv);
  1173. extern int drm_irq_install(struct drm_device *dev, int irq);
  1174. extern int drm_irq_uninstall(struct drm_device *dev);
  1175. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  1176. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  1177. struct drm_file *filp);
  1178. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  1179. extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
  1180. struct timeval *vblanktime);
  1181. extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
  1182. struct drm_pending_vblank_event *e);
  1183. extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
  1184. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1185. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1186. extern void drm_vblank_off(struct drm_device *dev, int crtc);
  1187. extern void drm_vblank_cleanup(struct drm_device *dev);
  1188. extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
  1189. struct timeval *tvblank, unsigned flags);
  1190. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  1191. int crtc, int *max_error,
  1192. struct timeval *vblank_time,
  1193. unsigned flags,
  1194. const struct drm_crtc *refcrtc,
  1195. const struct drm_display_mode *mode);
  1196. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
  1197. const struct drm_display_mode *mode);
  1198. /* Modesetting support */
  1199. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1200. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1201. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1202. struct drm_file *file_priv);
  1203. /* AGP/GART support (drm_agpsupport.h) */
  1204. #include <drm/drm_agpsupport.h>
  1205. /* Stub support (drm_stub.h) */
  1206. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1207. struct drm_file *file_priv);
  1208. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1209. struct drm_file *file_priv);
  1210. struct drm_master *drm_master_create(struct drm_minor *minor);
  1211. extern struct drm_master *drm_master_get(struct drm_master *master);
  1212. extern void drm_master_put(struct drm_master **master);
  1213. extern void drm_put_dev(struct drm_device *dev);
  1214. extern void drm_unplug_dev(struct drm_device *dev);
  1215. extern unsigned int drm_debug;
  1216. extern unsigned int drm_rnodes;
  1217. extern unsigned int drm_universal_planes;
  1218. extern unsigned int drm_vblank_offdelay;
  1219. extern unsigned int drm_timestamp_precision;
  1220. extern unsigned int drm_timestamp_monotonic;
  1221. extern struct class *drm_class;
  1222. extern struct dentry *drm_debugfs_root;
  1223. extern struct idr drm_minors_idr;
  1224. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1225. /* Debugfs support */
  1226. #if defined(CONFIG_DEBUG_FS)
  1227. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1228. struct dentry *root);
  1229. extern int drm_debugfs_create_files(const struct drm_info_list *files,
  1230. int count, struct dentry *root,
  1231. struct drm_minor *minor);
  1232. extern int drm_debugfs_remove_files(const struct drm_info_list *files,
  1233. int count, struct drm_minor *minor);
  1234. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1235. #else
  1236. static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1237. struct dentry *root)
  1238. {
  1239. return 0;
  1240. }
  1241. static inline int drm_debugfs_create_files(const struct drm_info_list *files,
  1242. int count, struct dentry *root,
  1243. struct drm_minor *minor)
  1244. {
  1245. return 0;
  1246. }
  1247. static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
  1248. int count, struct drm_minor *minor)
  1249. {
  1250. return 0;
  1251. }
  1252. static inline int drm_debugfs_cleanup(struct drm_minor *minor)
  1253. {
  1254. return 0;
  1255. }
  1256. #endif
  1257. /* Info file support */
  1258. extern int drm_name_info(struct seq_file *m, void *data);
  1259. extern int drm_vm_info(struct seq_file *m, void *data);
  1260. extern int drm_bufs_info(struct seq_file *m, void *data);
  1261. extern int drm_vblank_info(struct seq_file *m, void *data);
  1262. extern int drm_clients_info(struct seq_file *m, void* data);
  1263. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1264. extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  1265. struct drm_gem_object *obj, int flags);
  1266. extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  1267. struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  1268. int *prime_fd);
  1269. extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  1270. struct dma_buf *dma_buf);
  1271. extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  1272. struct drm_file *file_priv, int prime_fd, uint32_t *handle);
  1273. extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
  1274. extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
  1275. struct drm_file *file_priv);
  1276. extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
  1277. struct drm_file *file_priv);
  1278. extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  1279. dma_addr_t *addrs, int max_pages);
  1280. extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
  1281. extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
  1282. int drm_gem_dumb_destroy(struct drm_file *file,
  1283. struct drm_device *dev,
  1284. uint32_t handle);
  1285. void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
  1286. void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
  1287. void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
  1288. #if DRM_DEBUG_CODE
  1289. extern int drm_vma_info(struct seq_file *m, void *data);
  1290. #endif
  1291. /* Scatter Gather Support (drm_scatter.h) */
  1292. extern void drm_legacy_sg_cleanup(struct drm_device *dev);
  1293. extern int drm_sg_alloc(struct drm_device *dev, void *data,
  1294. struct drm_file *file_priv);
  1295. extern int drm_sg_free(struct drm_device *dev, void *data,
  1296. struct drm_file *file_priv);
  1297. /* ATI PCIGART support (ati_pcigart.h) */
  1298. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1299. struct drm_ati_pcigart_info * gart_info);
  1300. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1301. struct drm_ati_pcigart_info * gart_info);
  1302. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1303. size_t align);
  1304. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1305. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1306. extern int drm_pci_set_unique(struct drm_device *dev,
  1307. struct drm_master *master,
  1308. struct drm_unique *u);
  1309. /* sysfs support (drm_sysfs.c) */
  1310. struct drm_sysfs_class;
  1311. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1312. extern void drm_sysfs_destroy(void);
  1313. extern int drm_sysfs_device_add(struct drm_minor *minor);
  1314. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1315. extern void drm_sysfs_device_remove(struct drm_minor *minor);
  1316. extern int drm_sysfs_connector_add(struct drm_connector *connector);
  1317. extern void drm_sysfs_connector_remove(struct drm_connector *connector);
  1318. /* Graphics Execution Manager library functions (drm_gem.c) */
  1319. int drm_gem_init(struct drm_device *dev);
  1320. void drm_gem_destroy(struct drm_device *dev);
  1321. void drm_gem_object_release(struct drm_gem_object *obj);
  1322. void drm_gem_object_free(struct kref *kref);
  1323. int drm_gem_object_init(struct drm_device *dev,
  1324. struct drm_gem_object *obj, size_t size);
  1325. void drm_gem_private_object_init(struct drm_device *dev,
  1326. struct drm_gem_object *obj, size_t size);
  1327. void drm_gem_vm_open(struct vm_area_struct *vma);
  1328. void drm_gem_vm_close(struct vm_area_struct *vma);
  1329. int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
  1330. struct vm_area_struct *vma);
  1331. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1332. #include <drm/drm_global.h>
  1333. static inline void
  1334. drm_gem_object_reference(struct drm_gem_object *obj)
  1335. {
  1336. kref_get(&obj->refcount);
  1337. }
  1338. static inline void
  1339. drm_gem_object_unreference(struct drm_gem_object *obj)
  1340. {
  1341. if (obj != NULL)
  1342. kref_put(&obj->refcount, drm_gem_object_free);
  1343. }
  1344. static inline void
  1345. drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
  1346. {
  1347. if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
  1348. struct drm_device *dev = obj->dev;
  1349. mutex_lock(&dev->struct_mutex);
  1350. if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
  1351. drm_gem_object_free(&obj->refcount);
  1352. mutex_unlock(&dev->struct_mutex);
  1353. }
  1354. }
  1355. int drm_gem_handle_create_tail(struct drm_file *file_priv,
  1356. struct drm_gem_object *obj,
  1357. u32 *handlep);
  1358. int drm_gem_handle_create(struct drm_file *file_priv,
  1359. struct drm_gem_object *obj,
  1360. u32 *handlep);
  1361. int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
  1362. void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
  1363. int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
  1364. int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
  1365. struct page **drm_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  1366. void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
  1367. bool dirty, bool accessed);
  1368. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1369. struct drm_file *filp,
  1370. u32 handle);
  1371. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1372. struct drm_file *file_priv);
  1373. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1374. struct drm_file *file_priv);
  1375. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1376. struct drm_file *file_priv);
  1377. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1378. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1379. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1380. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1381. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1382. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1383. unsigned int token)
  1384. {
  1385. struct drm_map_list *_entry;
  1386. list_for_each_entry(_entry, &dev->maplist, head)
  1387. if (_entry->user_token == token)
  1388. return _entry->map;
  1389. return NULL;
  1390. }
  1391. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1392. {
  1393. }
  1394. #include <drm/drm_mem_util.h>
  1395. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  1396. struct device *parent);
  1397. void drm_dev_ref(struct drm_device *dev);
  1398. void drm_dev_unref(struct drm_device *dev);
  1399. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  1400. void drm_dev_unregister(struct drm_device *dev);
  1401. struct drm_minor *drm_minor_acquire(unsigned int minor_id);
  1402. void drm_minor_release(struct drm_minor *minor);
  1403. /*@}*/
  1404. /* PCI section */
  1405. static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
  1406. {
  1407. if (dev->driver->device_is_agp != NULL) {
  1408. int err = (*dev->driver->device_is_agp) (dev);
  1409. if (err != 2) {
  1410. return err;
  1411. }
  1412. }
  1413. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1414. }
  1415. void drm_pci_agp_destroy(struct drm_device *dev);
  1416. extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  1417. extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  1418. extern int drm_get_pci_dev(struct pci_dev *pdev,
  1419. const struct pci_device_id *ent,
  1420. struct drm_driver *driver);
  1421. #define DRM_PCIE_SPEED_25 1
  1422. #define DRM_PCIE_SPEED_50 2
  1423. #define DRM_PCIE_SPEED_80 4
  1424. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  1425. /* platform section */
  1426. extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
  1427. /* returns true if currently okay to sleep */
  1428. static __inline__ bool drm_can_sleep(void)
  1429. {
  1430. if (in_atomic() || in_dbg_master() || irqs_disabled())
  1431. return false;
  1432. return true;
  1433. }
  1434. #endif /* __KERNEL__ */
  1435. #endif