drmP.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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. * All rights reserved.
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice (including the next
  21. * paragraph) shall be included in all copies or substantial portions of the
  22. * Software.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  27. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  28. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  29. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  30. * OTHER DEALINGS IN THE SOFTWARE.
  31. */
  32. #ifndef _DRM_P_H_
  33. #define _DRM_P_H_
  34. #ifdef __KERNEL__
  35. #ifdef __alpha__
  36. /* add include of current.h so that "current" is defined
  37. * before static inline funcs in wait.h. Doing this so we
  38. * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  39. #include <asm/current.h>
  40. #endif /* __alpha__ */
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/miscdevice.h>
  44. #include <linux/fs.h>
  45. #include <linux/proc_fs.h>
  46. #include <linux/init.h>
  47. #include <linux/file.h>
  48. #include <linux/pci.h>
  49. #include <linux/jiffies.h>
  50. #include <linux/smp_lock.h> /* For (un)lock_kernel */
  51. #include <linux/dma-mapping.h>
  52. #include <linux/mm.h>
  53. #include <linux/cdev.h>
  54. #include <linux/mutex.h>
  55. #if defined(__alpha__) || defined(__powerpc__)
  56. #include <asm/pgtable.h> /* For pte_wrprotect */
  57. #endif
  58. #include <asm/io.h>
  59. #include <asm/mman.h>
  60. #include <asm/uaccess.h>
  61. #ifdef CONFIG_MTRR
  62. #include <asm/mtrr.h>
  63. #endif
  64. #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
  65. #include <linux/types.h>
  66. #include <linux/agp_backend.h>
  67. #endif
  68. #include <linux/workqueue.h>
  69. #include <linux/poll.h>
  70. #include <asm/pgalloc.h>
  71. #include "drm.h"
  72. #include <linux/idr.h>
  73. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  74. #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
  75. struct drm_file;
  76. struct drm_device;
  77. #include "drm_os_linux.h"
  78. #include "drm_hashtab.h"
  79. #include "drm_mm.h"
  80. #define DRM_UT_CORE 0x01
  81. #define DRM_UT_DRIVER 0x02
  82. #define DRM_UT_KMS 0x04
  83. #define DRM_UT_MODE 0x08
  84. extern void drm_ut_debug_printk(unsigned int request_level,
  85. const char *prefix,
  86. const char *function_name,
  87. const char *format, ...);
  88. /***********************************************************************/
  89. /** \name DRM template customization defaults */
  90. /*@{*/
  91. /* driver capabilities and requirements mask */
  92. #define DRIVER_USE_AGP 0x1
  93. #define DRIVER_REQUIRE_AGP 0x2
  94. #define DRIVER_USE_MTRR 0x4
  95. #define DRIVER_PCI_DMA 0x8
  96. #define DRIVER_SG 0x10
  97. #define DRIVER_HAVE_DMA 0x20
  98. #define DRIVER_HAVE_IRQ 0x40
  99. #define DRIVER_IRQ_SHARED 0x80
  100. #define DRIVER_IRQ_VBL 0x100
  101. #define DRIVER_DMA_QUEUE 0x200
  102. #define DRIVER_FB_DMA 0x400
  103. #define DRIVER_IRQ_VBL2 0x800
  104. #define DRIVER_GEM 0x1000
  105. #define DRIVER_MODESET 0x2000
  106. /***********************************************************************/
  107. /** \name Begin the DRM... */
  108. /*@{*/
  109. #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
  110. also include looping detection. */
  111. #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
  112. #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
  113. #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
  114. #define DRM_LOOPING_LIMIT 5000000
  115. #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
  116. #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
  117. #define DRM_FLAG_DEBUG 0x01
  118. #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
  119. #define DRM_MAP_HASH_OFFSET 0x10000000
  120. /*@}*/
  121. /***********************************************************************/
  122. /** \name Macros to make printk easier */
  123. /*@{*/
  124. /**
  125. * Error output.
  126. *
  127. * \param fmt printf() like format string.
  128. * \param arg arguments
  129. */
  130. #define DRM_ERROR(fmt, arg...) \
  131. printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
  132. /**
  133. * Memory error output.
  134. *
  135. * \param area memory area where the error occurred.
  136. * \param fmt printf() like format string.
  137. * \param arg arguments
  138. */
  139. #define DRM_MEM_ERROR(area, fmt, arg...) \
  140. printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
  141. drm_mem_stats[area].name , ##arg)
  142. #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
  143. /**
  144. * Debug output.
  145. *
  146. * \param fmt printf() like format string.
  147. * \param arg arguments
  148. */
  149. #if DRM_DEBUG_CODE
  150. #define DRM_DEBUG(fmt, args...) \
  151. do { \
  152. drm_ut_debug_printk(DRM_UT_CORE, DRM_NAME, \
  153. __func__, fmt, ##args); \
  154. } while (0)
  155. #define DRM_DEBUG_DRIVER(prefix, fmt, args...) \
  156. do { \
  157. drm_ut_debug_printk(DRM_UT_DRIVER, prefix, \
  158. __func__, fmt, ##args); \
  159. } while (0)
  160. #define DRM_DEBUG_KMS(prefix, fmt, args...) \
  161. do { \
  162. drm_ut_debug_printk(DRM_UT_KMS, prefix, \
  163. __func__, fmt, ##args); \
  164. } while (0)
  165. #define DRM_DEBUG_MODE(prefix, fmt, args...) \
  166. do { \
  167. drm_ut_debug_printk(DRM_UT_MODE, prefix, \
  168. __func__, fmt, ##args); \
  169. } while (0)
  170. #define DRM_LOG(fmt, args...) \
  171. do { \
  172. drm_ut_debug_printk(DRM_UT_CORE, NULL, \
  173. NULL, fmt, ##args); \
  174. } while (0)
  175. #define DRM_LOG_KMS(fmt, args...) \
  176. do { \
  177. drm_ut_debug_printk(DRM_UT_KMS, NULL, \
  178. NULL, fmt, ##args); \
  179. } while (0)
  180. #define DRM_LOG_MODE(fmt, args...) \
  181. do { \
  182. drm_ut_debug_printk(DRM_UT_MODE, NULL, \
  183. NULL, fmt, ##args); \
  184. } while (0)
  185. #define DRM_LOG_DRIVER(fmt, args...) \
  186. do { \
  187. drm_ut_debug_printk(DRM_UT_DRIVER, NULL, \
  188. NULL, fmt, ##args); \
  189. } while (0)
  190. #else
  191. #define DRM_DEBUG_DRIVER(prefix, fmt, args...) do { } while (0)
  192. #define DRM_DEBUG_KMS(prefix, fmt, args...) do { } while (0)
  193. #define DRM_DEBUG_MODE(prefix, fmt, args...) do { } while (0)
  194. #define DRM_DEBUG(fmt, arg...) do { } while (0)
  195. #define DRM_LOG(fmt, arg...) do { } while (0)
  196. #define DRM_LOG_KMS(fmt, args...) do { } while (0)
  197. #define DRM_LOG_MODE(fmt, arg...) do { } while (0)
  198. #define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
  199. #endif
  200. #define DRM_PROC_LIMIT (PAGE_SIZE-80)
  201. #define DRM_PROC_PRINT(fmt, arg...) \
  202. len += sprintf(&buf[len], fmt , ##arg); \
  203. if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
  204. #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
  205. len += sprintf(&buf[len], fmt , ##arg); \
  206. if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
  207. /*@}*/
  208. /***********************************************************************/
  209. /** \name Internal types and structures */
  210. /*@{*/
  211. #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
  212. #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
  213. #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
  214. #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
  215. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  216. /**
  217. * Get the private SAREA mapping.
  218. *
  219. * \param _dev DRM device.
  220. * \param _ctx context number.
  221. * \param _map output mapping.
  222. */
  223. #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
  224. (_map) = (_dev)->context_sareas[_ctx]; \
  225. } while(0)
  226. /**
  227. * Test that the hardware lock is held by the caller, returning otherwise.
  228. *
  229. * \param dev DRM device.
  230. * \param filp file pointer of the caller.
  231. */
  232. #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
  233. do { \
  234. if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
  235. _file_priv->master->lock.file_priv != _file_priv) { \
  236. DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
  237. __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  238. _file_priv->master->lock.file_priv, _file_priv); \
  239. return -EINVAL; \
  240. } \
  241. } while (0)
  242. /**
  243. * Copy and IOCTL return string to user space
  244. */
  245. #define DRM_COPY( name, value ) \
  246. len = strlen( value ); \
  247. if ( len > name##_len ) len = name##_len; \
  248. name##_len = strlen( value ); \
  249. if ( len && name ) { \
  250. if ( copy_to_user( name, value, len ) ) \
  251. return -EFAULT; \
  252. }
  253. /**
  254. * Ioctl function type.
  255. *
  256. * \param inode device inode.
  257. * \param file_priv DRM file private pointer.
  258. * \param cmd command.
  259. * \param arg argument.
  260. */
  261. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  262. struct drm_file *file_priv);
  263. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  264. unsigned long arg);
  265. #define DRM_AUTH 0x1
  266. #define DRM_MASTER 0x2
  267. #define DRM_ROOT_ONLY 0x4
  268. #define DRM_CONTROL_ALLOW 0x8
  269. struct drm_ioctl_desc {
  270. unsigned int cmd;
  271. int flags;
  272. drm_ioctl_t *func;
  273. };
  274. /**
  275. * Creates a driver or general drm_ioctl_desc array entry for the given
  276. * ioctl, for use by drm_ioctl().
  277. */
  278. #define DRM_IOCTL_DEF(ioctl, _func, _flags) \
  279. [DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags}
  280. struct drm_magic_entry {
  281. struct list_head head;
  282. struct drm_hash_item hash_item;
  283. struct drm_file *priv;
  284. };
  285. struct drm_vma_entry {
  286. struct list_head head;
  287. struct vm_area_struct *vma;
  288. pid_t pid;
  289. };
  290. /**
  291. * DMA buffer.
  292. */
  293. struct drm_buf {
  294. int idx; /**< Index into master buflist */
  295. int total; /**< Buffer size */
  296. int order; /**< log-base-2(total) */
  297. int used; /**< Amount of buffer in use (for DMA) */
  298. unsigned long offset; /**< Byte offset (used internally) */
  299. void *address; /**< Address of buffer */
  300. unsigned long bus_address; /**< Bus address of buffer */
  301. struct drm_buf *next; /**< Kernel-only: used for free list */
  302. __volatile__ int waiting; /**< On kernel DMA queue */
  303. __volatile__ int pending; /**< On hardware DMA queue */
  304. wait_queue_head_t dma_wait; /**< Processes waiting */
  305. struct drm_file *file_priv; /**< Private of holding file descr */
  306. int context; /**< Kernel queue for this buffer */
  307. int while_locked; /**< Dispatch this buffer while locked */
  308. enum {
  309. DRM_LIST_NONE = 0,
  310. DRM_LIST_FREE = 1,
  311. DRM_LIST_WAIT = 2,
  312. DRM_LIST_PEND = 3,
  313. DRM_LIST_PRIO = 4,
  314. DRM_LIST_RECLAIM = 5
  315. } list; /**< Which list we're on */
  316. int dev_priv_size; /**< Size of buffer private storage */
  317. void *dev_private; /**< Per-buffer private storage */
  318. };
  319. /** bufs is one longer than it has to be */
  320. struct drm_waitlist {
  321. int count; /**< Number of possible buffers */
  322. struct drm_buf **bufs; /**< List of pointers to buffers */
  323. struct drm_buf **rp; /**< Read pointer */
  324. struct drm_buf **wp; /**< Write pointer */
  325. struct drm_buf **end; /**< End pointer */
  326. spinlock_t read_lock;
  327. spinlock_t write_lock;
  328. };
  329. struct drm_freelist {
  330. int initialized; /**< Freelist in use */
  331. atomic_t count; /**< Number of free buffers */
  332. struct drm_buf *next; /**< End pointer */
  333. wait_queue_head_t waiting; /**< Processes waiting on free bufs */
  334. int low_mark; /**< Low water mark */
  335. int high_mark; /**< High water mark */
  336. atomic_t wfh; /**< If waiting for high mark */
  337. spinlock_t lock;
  338. };
  339. typedef struct drm_dma_handle {
  340. dma_addr_t busaddr;
  341. void *vaddr;
  342. size_t size;
  343. } drm_dma_handle_t;
  344. /**
  345. * Buffer entry. There is one of this for each buffer size order.
  346. */
  347. struct drm_buf_entry {
  348. int buf_size; /**< size */
  349. int buf_count; /**< number of buffers */
  350. struct drm_buf *buflist; /**< buffer list */
  351. int seg_count;
  352. int page_order;
  353. struct drm_dma_handle **seglist;
  354. struct drm_freelist freelist;
  355. };
  356. /** File private data */
  357. struct drm_file {
  358. int authenticated;
  359. pid_t pid;
  360. uid_t uid;
  361. drm_magic_t magic;
  362. unsigned long ioctl_count;
  363. struct list_head lhead;
  364. struct drm_minor *minor;
  365. unsigned long lock_count;
  366. /** Mapping of mm object handles to object pointers. */
  367. struct idr object_idr;
  368. /** Lock for synchronization of access to object_idr. */
  369. spinlock_t table_lock;
  370. struct file *filp;
  371. void *driver_priv;
  372. int is_master; /* this file private is a master for a minor */
  373. struct drm_master *master; /* master this node is currently associated with
  374. N.B. not always minor->master */
  375. struct list_head fbs;
  376. };
  377. /** Wait queue */
  378. struct drm_queue {
  379. atomic_t use_count; /**< Outstanding uses (+1) */
  380. atomic_t finalization; /**< Finalization in progress */
  381. atomic_t block_count; /**< Count of processes waiting */
  382. atomic_t block_read; /**< Queue blocked for reads */
  383. wait_queue_head_t read_queue; /**< Processes waiting on block_read */
  384. atomic_t block_write; /**< Queue blocked for writes */
  385. wait_queue_head_t write_queue; /**< Processes waiting on block_write */
  386. atomic_t total_queued; /**< Total queued statistic */
  387. atomic_t total_flushed; /**< Total flushes statistic */
  388. atomic_t total_locks; /**< Total locks statistics */
  389. enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
  390. struct drm_waitlist waitlist; /**< Pending buffers */
  391. wait_queue_head_t flush_queue; /**< Processes waiting until flush */
  392. };
  393. /**
  394. * Lock data.
  395. */
  396. struct drm_lock_data {
  397. struct drm_hw_lock *hw_lock; /**< Hardware lock */
  398. /** Private of lock holder's file (NULL=kernel) */
  399. struct drm_file *file_priv;
  400. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  401. unsigned long lock_time; /**< Time of last lock in jiffies */
  402. spinlock_t spinlock;
  403. uint32_t kernel_waiters;
  404. uint32_t user_waiters;
  405. int idle_has_lock;
  406. };
  407. /**
  408. * DMA data.
  409. */
  410. struct drm_device_dma {
  411. struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  412. int buf_count; /**< total number of buffers */
  413. struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  414. int seg_count;
  415. int page_count; /**< number of pages */
  416. unsigned long *pagelist; /**< page list */
  417. unsigned long byte_count;
  418. enum {
  419. _DRM_DMA_USE_AGP = 0x01,
  420. _DRM_DMA_USE_SG = 0x02,
  421. _DRM_DMA_USE_FB = 0x04,
  422. _DRM_DMA_USE_PCI_RO = 0x08
  423. } flags;
  424. };
  425. /**
  426. * AGP memory entry. Stored as a doubly linked list.
  427. */
  428. struct drm_agp_mem {
  429. unsigned long handle; /**< handle */
  430. DRM_AGP_MEM *memory;
  431. unsigned long bound; /**< address */
  432. int pages;
  433. struct list_head head;
  434. };
  435. /**
  436. * AGP data.
  437. *
  438. * \sa drm_agp_init() and drm_device::agp.
  439. */
  440. struct drm_agp_head {
  441. DRM_AGP_KERN agp_info; /**< AGP device information */
  442. struct list_head memory;
  443. unsigned long mode; /**< AGP mode */
  444. struct agp_bridge_data *bridge;
  445. int enabled; /**< whether the AGP bus as been enabled */
  446. int acquired; /**< whether the AGP device has been acquired */
  447. unsigned long base;
  448. int agp_mtrr;
  449. int cant_use_aperture;
  450. unsigned long page_mask;
  451. };
  452. /**
  453. * Scatter-gather memory.
  454. */
  455. struct drm_sg_mem {
  456. unsigned long handle;
  457. void *virtual;
  458. int pages;
  459. struct page **pagelist;
  460. dma_addr_t *busaddr;
  461. };
  462. struct drm_sigdata {
  463. int context;
  464. struct drm_hw_lock *lock;
  465. };
  466. /**
  467. * Kernel side of a mapping
  468. */
  469. struct drm_local_map {
  470. resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
  471. unsigned long size; /**< Requested physical size (bytes) */
  472. enum drm_map_type type; /**< Type of memory to map */
  473. enum drm_map_flags flags; /**< Flags */
  474. void *handle; /**< User-space: "Handle" to pass to mmap() */
  475. /**< Kernel-space: kernel-virtual address */
  476. int mtrr; /**< MTRR slot used */
  477. };
  478. typedef struct drm_local_map drm_local_map_t;
  479. /**
  480. * Mappings list
  481. */
  482. struct drm_map_list {
  483. struct list_head head; /**< list head */
  484. struct drm_hash_item hash;
  485. struct drm_local_map *map; /**< mapping */
  486. uint64_t user_token;
  487. struct drm_master *master;
  488. struct drm_mm_node *file_offset_node; /**< fake offset */
  489. };
  490. /**
  491. * Context handle list
  492. */
  493. struct drm_ctx_list {
  494. struct list_head head; /**< list head */
  495. drm_context_t handle; /**< context handle */
  496. struct drm_file *tag; /**< associated fd private data */
  497. };
  498. /* location of GART table */
  499. #define DRM_ATI_GART_MAIN 1
  500. #define DRM_ATI_GART_FB 2
  501. #define DRM_ATI_GART_PCI 1
  502. #define DRM_ATI_GART_PCIE 2
  503. #define DRM_ATI_GART_IGP 3
  504. struct drm_ati_pcigart_info {
  505. int gart_table_location;
  506. int gart_reg_if;
  507. void *addr;
  508. dma_addr_t bus_addr;
  509. dma_addr_t table_mask;
  510. struct drm_dma_handle *table_handle;
  511. struct drm_local_map mapping;
  512. int table_size;
  513. };
  514. /**
  515. * GEM specific mm private for tracking GEM objects
  516. */
  517. struct drm_gem_mm {
  518. struct drm_mm offset_manager; /**< Offset mgmt for buffer objects */
  519. struct drm_open_hash offset_hash; /**< User token hash table for maps */
  520. };
  521. /**
  522. * This structure defines the drm_mm memory object, which will be used by the
  523. * DRM for its buffer objects.
  524. */
  525. struct drm_gem_object {
  526. /** Reference count of this object */
  527. struct kref refcount;
  528. /** Handle count of this object. Each handle also holds a reference */
  529. struct kref handlecount;
  530. /** Related drm device */
  531. struct drm_device *dev;
  532. /** File representing the shmem storage */
  533. struct file *filp;
  534. /* Mapping info for this object */
  535. struct drm_map_list map_list;
  536. /**
  537. * Size of the object, in bytes. Immutable over the object's
  538. * lifetime.
  539. */
  540. size_t size;
  541. /**
  542. * Global name for this object, starts at 1. 0 means unnamed.
  543. * Access is covered by the object_name_lock in the related drm_device
  544. */
  545. int name;
  546. /**
  547. * Memory domains. These monitor which caches contain read/write data
  548. * related to the object. When transitioning from one set of domains
  549. * to another, the driver is called to ensure that caches are suitably
  550. * flushed and invalidated
  551. */
  552. uint32_t read_domains;
  553. uint32_t write_domain;
  554. /**
  555. * While validating an exec operation, the
  556. * new read/write domain values are computed here.
  557. * They will be transferred to the above values
  558. * at the point that any cache flushing occurs
  559. */
  560. uint32_t pending_read_domains;
  561. uint32_t pending_write_domain;
  562. void *driver_private;
  563. };
  564. #include "drm_crtc.h"
  565. /* per-master structure */
  566. struct drm_master {
  567. struct kref refcount; /* refcount for this master */
  568. struct list_head head; /**< each minor contains a list of masters */
  569. struct drm_minor *minor; /**< link back to minor we are a master for */
  570. char *unique; /**< Unique identifier: e.g., busid */
  571. int unique_len; /**< Length of unique field */
  572. int unique_size; /**< amount allocated */
  573. int blocked; /**< Blocked due to VC switch? */
  574. /** \name Authentication */
  575. /*@{ */
  576. struct drm_open_hash magiclist;
  577. struct list_head magicfree;
  578. /*@} */
  579. struct drm_lock_data lock; /**< Information on hardware lock */
  580. void *driver_priv; /**< Private structure for driver to use */
  581. };
  582. /**
  583. * DRM driver structure. This structure represent the common code for
  584. * a family of cards. There will one drm_device for each card present
  585. * in this family
  586. */
  587. struct drm_driver {
  588. int (*load) (struct drm_device *, unsigned long flags);
  589. int (*firstopen) (struct drm_device *);
  590. int (*open) (struct drm_device *, struct drm_file *);
  591. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  592. void (*postclose) (struct drm_device *, struct drm_file *);
  593. void (*lastclose) (struct drm_device *);
  594. int (*unload) (struct drm_device *);
  595. int (*suspend) (struct drm_device *, pm_message_t state);
  596. int (*resume) (struct drm_device *);
  597. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  598. void (*dma_ready) (struct drm_device *);
  599. int (*dma_quiescent) (struct drm_device *);
  600. int (*context_ctor) (struct drm_device *dev, int context);
  601. int (*context_dtor) (struct drm_device *dev, int context);
  602. int (*kernel_context_switch) (struct drm_device *dev, int old,
  603. int new);
  604. void (*kernel_context_switch_unlock) (struct drm_device *dev);
  605. /**
  606. * get_vblank_counter - get raw hardware vblank counter
  607. * @dev: DRM device
  608. * @crtc: counter to fetch
  609. *
  610. * Driver callback for fetching a raw hardware vblank counter
  611. * for @crtc. If a device doesn't have a hardware counter, the
  612. * driver can simply return the value of drm_vblank_count and
  613. * make the enable_vblank() and disable_vblank() hooks into no-ops,
  614. * leaving interrupts enabled at all times.
  615. *
  616. * Wraparound handling and loss of events due to modesetting is dealt
  617. * with in the DRM core code.
  618. *
  619. * RETURNS
  620. * Raw vblank counter value.
  621. */
  622. u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  623. /**
  624. * enable_vblank - enable vblank interrupt events
  625. * @dev: DRM device
  626. * @crtc: which irq to enable
  627. *
  628. * Enable vblank interrupts for @crtc. If the device doesn't have
  629. * a hardware vblank counter, this routine should be a no-op, since
  630. * interrupts will have to stay on to keep the count accurate.
  631. *
  632. * RETURNS
  633. * Zero on success, appropriate errno if the given @crtc's vblank
  634. * interrupt cannot be enabled.
  635. */
  636. int (*enable_vblank) (struct drm_device *dev, int crtc);
  637. /**
  638. * disable_vblank - disable vblank interrupt events
  639. * @dev: DRM device
  640. * @crtc: which irq to enable
  641. *
  642. * Disable vblank interrupts for @crtc. If the device doesn't have
  643. * a hardware vblank counter, this routine should be a no-op, since
  644. * interrupts will have to stay on to keep the count accurate.
  645. */
  646. void (*disable_vblank) (struct drm_device *dev, int crtc);
  647. /**
  648. * Called by \c drm_device_is_agp. Typically used to determine if a
  649. * card is really attached to AGP or not.
  650. *
  651. * \param dev DRM device handle
  652. *
  653. * \returns
  654. * One of three values is returned depending on whether or not the
  655. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  656. * (return of 1), or may or may not be AGP (return of 2).
  657. */
  658. int (*device_is_agp) (struct drm_device *dev);
  659. /* these have to be filled in */
  660. irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  661. void (*irq_preinstall) (struct drm_device *dev);
  662. int (*irq_postinstall) (struct drm_device *dev);
  663. void (*irq_uninstall) (struct drm_device *dev);
  664. void (*reclaim_buffers) (struct drm_device *dev,
  665. struct drm_file * file_priv);
  666. void (*reclaim_buffers_locked) (struct drm_device *dev,
  667. struct drm_file *file_priv);
  668. void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
  669. struct drm_file *file_priv);
  670. resource_size_t (*get_map_ofs) (struct drm_local_map * map);
  671. resource_size_t (*get_reg_ofs) (struct drm_device *dev);
  672. void (*set_version) (struct drm_device *dev,
  673. struct drm_set_version *sv);
  674. /* Master routines */
  675. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  676. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  677. int (*proc_init)(struct drm_minor *minor);
  678. void (*proc_cleanup)(struct drm_minor *minor);
  679. int (*debugfs_init)(struct drm_minor *minor);
  680. void (*debugfs_cleanup)(struct drm_minor *minor);
  681. /**
  682. * Driver-specific constructor for drm_gem_objects, to set up
  683. * obj->driver_private.
  684. *
  685. * Returns 0 on success.
  686. */
  687. int (*gem_init_object) (struct drm_gem_object *obj);
  688. void (*gem_free_object) (struct drm_gem_object *obj);
  689. /* Driver private ops for this object */
  690. struct vm_operations_struct *gem_vm_ops;
  691. int major;
  692. int minor;
  693. int patchlevel;
  694. char *name;
  695. char *desc;
  696. char *date;
  697. u32 driver_features;
  698. int dev_priv_size;
  699. struct drm_ioctl_desc *ioctls;
  700. int num_ioctls;
  701. struct file_operations fops;
  702. struct pci_driver pci_driver;
  703. /* List of devices hanging off this driver */
  704. struct list_head device_list;
  705. };
  706. #define DRM_MINOR_UNASSIGNED 0
  707. #define DRM_MINOR_LEGACY 1
  708. #define DRM_MINOR_CONTROL 2
  709. #define DRM_MINOR_RENDER 3
  710. /**
  711. * debugfs node list. This structure represents a debugfs file to
  712. * be created by the drm core
  713. */
  714. struct drm_debugfs_list {
  715. const char *name; /** file name */
  716. int (*show)(struct seq_file*, void*); /** show callback */
  717. u32 driver_features; /**< Required driver features for this entry */
  718. };
  719. /**
  720. * debugfs node structure. This structure represents a debugfs file.
  721. */
  722. struct drm_debugfs_node {
  723. struct list_head list;
  724. struct drm_minor *minor;
  725. struct drm_debugfs_list *debugfs_ent;
  726. struct dentry *dent;
  727. };
  728. /**
  729. * Info file list entry. This structure represents a debugfs or proc file to
  730. * be created by the drm core
  731. */
  732. struct drm_info_list {
  733. const char *name; /** file name */
  734. int (*show)(struct seq_file*, void*); /** show callback */
  735. u32 driver_features; /**< Required driver features for this entry */
  736. void *data;
  737. };
  738. /**
  739. * debugfs node structure. This structure represents a debugfs file.
  740. */
  741. struct drm_info_node {
  742. struct list_head list;
  743. struct drm_minor *minor;
  744. struct drm_info_list *info_ent;
  745. struct dentry *dent;
  746. };
  747. /**
  748. * DRM minor structure. This structure represents a drm minor number.
  749. */
  750. struct drm_minor {
  751. int index; /**< Minor device number */
  752. int type; /**< Control or render */
  753. dev_t device; /**< Device number for mknod */
  754. struct device kdev; /**< Linux device */
  755. struct drm_device *dev;
  756. struct proc_dir_entry *proc_root; /**< proc directory entry */
  757. struct drm_info_node proc_nodes;
  758. struct dentry *debugfs_root;
  759. struct drm_info_node debugfs_nodes;
  760. struct drm_master *master; /* currently active master for this node */
  761. struct list_head master_list;
  762. struct drm_mode_group mode_group;
  763. };
  764. /**
  765. * DRM device structure. This structure represent a complete card that
  766. * may contain multiple heads.
  767. */
  768. struct drm_device {
  769. struct list_head driver_item; /**< list of devices per driver */
  770. char *devname; /**< For /proc/interrupts */
  771. int if_version; /**< Highest interface version set */
  772. /** \name Locks */
  773. /*@{ */
  774. spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
  775. struct mutex struct_mutex; /**< For others */
  776. /*@} */
  777. /** \name Usage Counters */
  778. /*@{ */
  779. int open_count; /**< Outstanding files open */
  780. atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
  781. atomic_t vma_count; /**< Outstanding vma areas open */
  782. int buf_use; /**< Buffers in use -- cannot alloc */
  783. atomic_t buf_alloc; /**< Buffer allocation in progress */
  784. /*@} */
  785. /** \name Performance counters */
  786. /*@{ */
  787. unsigned long counters;
  788. enum drm_stat_type types[15];
  789. atomic_t counts[15];
  790. /*@} */
  791. struct list_head filelist;
  792. /** \name Memory management */
  793. /*@{ */
  794. struct list_head maplist; /**< Linked list of regions */
  795. int map_count; /**< Number of mappable regions */
  796. struct drm_open_hash map_hash; /**< User token hash table for maps */
  797. /** \name Context handle management */
  798. /*@{ */
  799. struct list_head ctxlist; /**< Linked list of context handles */
  800. int ctx_count; /**< Number of context handles */
  801. struct mutex ctxlist_mutex; /**< For ctxlist */
  802. struct idr ctx_idr;
  803. struct list_head vmalist; /**< List of vmas (for debugging) */
  804. /*@} */
  805. /** \name DMA queues (contexts) */
  806. /*@{ */
  807. int queue_count; /**< Number of active DMA queues */
  808. int queue_reserved; /**< Number of reserved DMA queues */
  809. int queue_slots; /**< Actual length of queuelist */
  810. struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */
  811. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  812. /*@} */
  813. /** \name Context support */
  814. /*@{ */
  815. int irq_enabled; /**< True if irq handler is enabled */
  816. __volatile__ long context_flag; /**< Context swapping flag */
  817. __volatile__ long interrupt_flag; /**< Interruption handler flag */
  818. __volatile__ long dma_flag; /**< DMA dispatch flag */
  819. struct timer_list timer; /**< Timer for delaying ctx switch */
  820. wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
  821. int last_checked; /**< Last context checked for DMA */
  822. int last_context; /**< Last current context */
  823. unsigned long last_switch; /**< jiffies at last context switch */
  824. /*@} */
  825. struct work_struct work;
  826. /** \name VBLANK IRQ support */
  827. /*@{ */
  828. /*
  829. * At load time, disabling the vblank interrupt won't be allowed since
  830. * old clients may not call the modeset ioctl and therefore misbehave.
  831. * Once the modeset ioctl *has* been called though, we can safely
  832. * disable them when unused.
  833. */
  834. int vblank_disable_allowed;
  835. wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */
  836. atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
  837. spinlock_t vbl_lock;
  838. atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */
  839. u32 *last_vblank; /* protected by dev->vbl_lock, used */
  840. /* for wraparound handling */
  841. int *vblank_enabled; /* so we don't call enable more than
  842. once per disable */
  843. int *vblank_inmodeset; /* Display driver is setting mode */
  844. u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */
  845. struct timer_list vblank_disable_timer;
  846. u32 max_vblank_count; /**< size of vblank counter register */
  847. /*@} */
  848. cycles_t ctx_start;
  849. cycles_t lck_start;
  850. struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  851. wait_queue_head_t buf_readers; /**< Processes waiting to read */
  852. wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
  853. struct drm_agp_head *agp; /**< AGP data */
  854. struct pci_dev *pdev; /**< PCI device structure */
  855. int pci_vendor; /**< PCI vendor id */
  856. int pci_device; /**< PCI device id */
  857. #ifdef __alpha__
  858. struct pci_controller *hose;
  859. #endif
  860. struct drm_sg_mem *sg; /**< Scatter gather memory */
  861. int num_crtcs; /**< Number of CRTCs on this device */
  862. void *dev_private; /**< device private data */
  863. void *mm_private;
  864. struct address_space *dev_mapping;
  865. struct drm_sigdata sigdata; /**< For block_all_signals */
  866. sigset_t sigmask;
  867. struct drm_driver *driver;
  868. struct drm_local_map *agp_buffer_map;
  869. unsigned int agp_buffer_token;
  870. struct drm_minor *control; /**< Control node for card */
  871. struct drm_minor *primary; /**< render type primary screen head */
  872. /** \name Drawable information */
  873. /*@{ */
  874. spinlock_t drw_lock;
  875. struct idr drw_idr;
  876. /*@} */
  877. struct drm_mode_config mode_config; /**< Current mode config */
  878. /** \name GEM information */
  879. /*@{ */
  880. spinlock_t object_name_lock;
  881. struct idr object_name_idr;
  882. atomic_t object_count;
  883. atomic_t object_memory;
  884. atomic_t pin_count;
  885. atomic_t pin_memory;
  886. atomic_t gtt_count;
  887. atomic_t gtt_memory;
  888. uint32_t gtt_total;
  889. uint32_t invalidate_domains; /* domains pending invalidation */
  890. uint32_t flush_domains; /* domains pending flush */
  891. /*@} */
  892. };
  893. static inline int drm_dev_to_irq(struct drm_device *dev)
  894. {
  895. return dev->pdev->irq;
  896. }
  897. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  898. int feature)
  899. {
  900. return ((dev->driver->driver_features & feature) ? 1 : 0);
  901. }
  902. #ifdef __alpha__
  903. #define drm_get_pci_domain(dev) dev->hose->index
  904. #else
  905. #define drm_get_pci_domain(dev) 0
  906. #endif
  907. #if __OS_HAS_AGP
  908. static inline int drm_core_has_AGP(struct drm_device *dev)
  909. {
  910. return drm_core_check_feature(dev, DRIVER_USE_AGP);
  911. }
  912. #else
  913. #define drm_core_has_AGP(dev) (0)
  914. #endif
  915. #if __OS_HAS_MTRR
  916. static inline int drm_core_has_MTRR(struct drm_device *dev)
  917. {
  918. return drm_core_check_feature(dev, DRIVER_USE_MTRR);
  919. }
  920. #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
  921. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  922. unsigned int flags)
  923. {
  924. return mtrr_add(offset, size, flags, 1);
  925. }
  926. static inline int drm_mtrr_del(int handle, unsigned long offset,
  927. unsigned long size, unsigned int flags)
  928. {
  929. return mtrr_del(handle, offset, size);
  930. }
  931. #else
  932. #define drm_core_has_MTRR(dev) (0)
  933. #define DRM_MTRR_WC 0
  934. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  935. unsigned int flags)
  936. {
  937. return 0;
  938. }
  939. static inline int drm_mtrr_del(int handle, unsigned long offset,
  940. unsigned long size, unsigned int flags)
  941. {
  942. return 0;
  943. }
  944. #endif
  945. /******************************************************************/
  946. /** \name Internal function definitions */
  947. /*@{*/
  948. /* Driver support (drm_drv.h) */
  949. extern int drm_init(struct drm_driver *driver);
  950. extern void drm_exit(struct drm_driver *driver);
  951. extern int drm_ioctl(struct inode *inode, struct file *filp,
  952. unsigned int cmd, unsigned long arg);
  953. extern long drm_compat_ioctl(struct file *filp,
  954. unsigned int cmd, unsigned long arg);
  955. extern int drm_lastclose(struct drm_device *dev);
  956. /* Device support (drm_fops.h) */
  957. extern int drm_open(struct inode *inode, struct file *filp);
  958. extern int drm_stub_open(struct inode *inode, struct file *filp);
  959. extern int drm_fasync(int fd, struct file *filp, int on);
  960. extern int drm_release(struct inode *inode, struct file *filp);
  961. /* Mapping support (drm_vm.h) */
  962. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  963. extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
  964. extern void drm_vm_open_locked(struct vm_area_struct *vma);
  965. extern resource_size_t drm_core_get_map_ofs(struct drm_local_map * map);
  966. extern resource_size_t drm_core_get_reg_ofs(struct drm_device *dev);
  967. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  968. /* Memory management support (drm_memory.h) */
  969. #include "drm_memory.h"
  970. extern void drm_mem_init(void);
  971. extern int drm_mem_info(char *buf, char **start, off_t offset,
  972. int request, int *eof, void *data);
  973. extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
  974. extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
  975. extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
  976. extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
  977. extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
  978. struct page **pages,
  979. unsigned long num_pages,
  980. uint32_t gtt_offset,
  981. uint32_t type);
  982. extern int drm_unbind_agp(DRM_AGP_MEM * handle);
  983. /* Misc. IOCTL support (drm_ioctl.h) */
  984. extern int drm_irq_by_busid(struct drm_device *dev, void *data,
  985. struct drm_file *file_priv);
  986. extern int drm_getunique(struct drm_device *dev, void *data,
  987. struct drm_file *file_priv);
  988. extern int drm_setunique(struct drm_device *dev, void *data,
  989. struct drm_file *file_priv);
  990. extern int drm_getmap(struct drm_device *dev, void *data,
  991. struct drm_file *file_priv);
  992. extern int drm_getclient(struct drm_device *dev, void *data,
  993. struct drm_file *file_priv);
  994. extern int drm_getstats(struct drm_device *dev, void *data,
  995. struct drm_file *file_priv);
  996. extern int drm_setversion(struct drm_device *dev, void *data,
  997. struct drm_file *file_priv);
  998. extern int drm_noop(struct drm_device *dev, void *data,
  999. struct drm_file *file_priv);
  1000. /* Context IOCTL support (drm_context.h) */
  1001. extern int drm_resctx(struct drm_device *dev, void *data,
  1002. struct drm_file *file_priv);
  1003. extern int drm_addctx(struct drm_device *dev, void *data,
  1004. struct drm_file *file_priv);
  1005. extern int drm_modctx(struct drm_device *dev, void *data,
  1006. struct drm_file *file_priv);
  1007. extern int drm_getctx(struct drm_device *dev, void *data,
  1008. struct drm_file *file_priv);
  1009. extern int drm_switchctx(struct drm_device *dev, void *data,
  1010. struct drm_file *file_priv);
  1011. extern int drm_newctx(struct drm_device *dev, void *data,
  1012. struct drm_file *file_priv);
  1013. extern int drm_rmctx(struct drm_device *dev, void *data,
  1014. struct drm_file *file_priv);
  1015. extern int drm_ctxbitmap_init(struct drm_device *dev);
  1016. extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
  1017. extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
  1018. extern int drm_setsareactx(struct drm_device *dev, void *data,
  1019. struct drm_file *file_priv);
  1020. extern int drm_getsareactx(struct drm_device *dev, void *data,
  1021. struct drm_file *file_priv);
  1022. /* Drawable IOCTL support (drm_drawable.h) */
  1023. extern int drm_adddraw(struct drm_device *dev, void *data,
  1024. struct drm_file *file_priv);
  1025. extern int drm_rmdraw(struct drm_device *dev, void *data,
  1026. struct drm_file *file_priv);
  1027. extern int drm_update_drawable_info(struct drm_device *dev, void *data,
  1028. struct drm_file *file_priv);
  1029. extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
  1030. drm_drawable_t id);
  1031. extern void drm_drawable_free_all(struct drm_device *dev);
  1032. /* Authentication IOCTL support (drm_auth.h) */
  1033. extern int drm_getmagic(struct drm_device *dev, void *data,
  1034. struct drm_file *file_priv);
  1035. extern int drm_authmagic(struct drm_device *dev, void *data,
  1036. struct drm_file *file_priv);
  1037. /* Cache management (drm_cache.c) */
  1038. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  1039. /* Locking IOCTL support (drm_lock.h) */
  1040. extern int drm_lock(struct drm_device *dev, void *data,
  1041. struct drm_file *file_priv);
  1042. extern int drm_unlock(struct drm_device *dev, void *data,
  1043. struct drm_file *file_priv);
  1044. extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
  1045. extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
  1046. extern void drm_idlelock_take(struct drm_lock_data *lock_data);
  1047. extern void drm_idlelock_release(struct drm_lock_data *lock_data);
  1048. /*
  1049. * These are exported to drivers so that they can implement fencing using
  1050. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  1051. */
  1052. extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
  1053. /* Buffer management support (drm_bufs.h) */
  1054. extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
  1055. extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
  1056. extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
  1057. unsigned int size, enum drm_map_type type,
  1058. enum drm_map_flags flags, struct drm_local_map **map_ptr);
  1059. extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
  1060. struct drm_file *file_priv);
  1061. extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
  1062. extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
  1063. extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
  1064. struct drm_file *file_priv);
  1065. extern int drm_addbufs(struct drm_device *dev, void *data,
  1066. struct drm_file *file_priv);
  1067. extern int drm_infobufs(struct drm_device *dev, void *data,
  1068. struct drm_file *file_priv);
  1069. extern int drm_markbufs(struct drm_device *dev, void *data,
  1070. struct drm_file *file_priv);
  1071. extern int drm_freebufs(struct drm_device *dev, void *data,
  1072. struct drm_file *file_priv);
  1073. extern int drm_mapbufs(struct drm_device *dev, void *data,
  1074. struct drm_file *file_priv);
  1075. extern int drm_order(unsigned long size);
  1076. extern resource_size_t drm_get_resource_start(struct drm_device *dev,
  1077. unsigned int resource);
  1078. extern resource_size_t drm_get_resource_len(struct drm_device *dev,
  1079. unsigned int resource);
  1080. /* DMA support (drm_dma.h) */
  1081. extern int drm_dma_setup(struct drm_device *dev);
  1082. extern void drm_dma_takedown(struct drm_device *dev);
  1083. extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
  1084. extern void drm_core_reclaim_buffers(struct drm_device *dev,
  1085. struct drm_file *filp);
  1086. /* IRQ support (drm_irq.h) */
  1087. extern int drm_control(struct drm_device *dev, void *data,
  1088. struct drm_file *file_priv);
  1089. extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
  1090. extern int drm_irq_install(struct drm_device *dev);
  1091. extern int drm_irq_uninstall(struct drm_device *dev);
  1092. extern void drm_driver_irq_preinstall(struct drm_device *dev);
  1093. extern void drm_driver_irq_postinstall(struct drm_device *dev);
  1094. extern void drm_driver_irq_uninstall(struct drm_device *dev);
  1095. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  1096. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  1097. struct drm_file *filp);
  1098. extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
  1099. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  1100. extern void drm_handle_vblank(struct drm_device *dev, int crtc);
  1101. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1102. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1103. extern void drm_vblank_cleanup(struct drm_device *dev);
  1104. /* Modesetting support */
  1105. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1106. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1107. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1108. struct drm_file *file_priv);
  1109. /* AGP/GART support (drm_agpsupport.h) */
  1110. extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
  1111. extern int drm_agp_acquire(struct drm_device *dev);
  1112. extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
  1113. struct drm_file *file_priv);
  1114. extern int drm_agp_release(struct drm_device *dev);
  1115. extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
  1116. struct drm_file *file_priv);
  1117. extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
  1118. extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
  1119. struct drm_file *file_priv);
  1120. extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
  1121. extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
  1122. struct drm_file *file_priv);
  1123. extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
  1124. extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
  1125. struct drm_file *file_priv);
  1126. extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
  1127. extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
  1128. struct drm_file *file_priv);
  1129. extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
  1130. extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
  1131. struct drm_file *file_priv);
  1132. extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
  1133. extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
  1134. struct drm_file *file_priv);
  1135. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
  1136. extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
  1137. extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
  1138. extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
  1139. extern void drm_agp_chipset_flush(struct drm_device *dev);
  1140. /* Stub support (drm_stub.h) */
  1141. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1142. struct drm_file *file_priv);
  1143. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1144. struct drm_file *file_priv);
  1145. struct drm_master *drm_master_create(struct drm_minor *minor);
  1146. extern struct drm_master *drm_master_get(struct drm_master *master);
  1147. extern void drm_master_put(struct drm_master **master);
  1148. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  1149. struct drm_driver *driver);
  1150. extern void drm_put_dev(struct drm_device *dev);
  1151. extern int drm_put_minor(struct drm_minor **minor);
  1152. extern unsigned int drm_debug;
  1153. extern struct class *drm_class;
  1154. extern struct proc_dir_entry *drm_proc_root;
  1155. extern struct dentry *drm_debugfs_root;
  1156. extern struct idr drm_minors_idr;
  1157. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1158. /* Proc support (drm_proc.h) */
  1159. extern int drm_proc_init(struct drm_minor *minor, int minor_id,
  1160. struct proc_dir_entry *root);
  1161. extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
  1162. /* Debugfs support */
  1163. #if defined(CONFIG_DEBUG_FS)
  1164. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1165. struct dentry *root);
  1166. extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
  1167. struct dentry *root, struct drm_minor *minor);
  1168. extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
  1169. struct drm_minor *minor);
  1170. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1171. #endif
  1172. /* Info file support */
  1173. extern int drm_name_info(struct seq_file *m, void *data);
  1174. extern int drm_vm_info(struct seq_file *m, void *data);
  1175. extern int drm_queues_info(struct seq_file *m, void *data);
  1176. extern int drm_bufs_info(struct seq_file *m, void *data);
  1177. extern int drm_vblank_info(struct seq_file *m, void *data);
  1178. extern int drm_clients_info(struct seq_file *m, void* data);
  1179. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1180. extern int drm_gem_object_info(struct seq_file *m, void* data);
  1181. #if DRM_DEBUG_CODE
  1182. extern int drm_vma_info(struct seq_file *m, void *data);
  1183. #endif
  1184. /* Scatter Gather Support (drm_scatter.h) */
  1185. extern void drm_sg_cleanup(struct drm_sg_mem * entry);
  1186. extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
  1187. struct drm_file *file_priv);
  1188. extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
  1189. extern int drm_sg_free(struct drm_device *dev, void *data,
  1190. struct drm_file *file_priv);
  1191. /* ATI PCIGART support (ati_pcigart.h) */
  1192. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1193. struct drm_ati_pcigart_info * gart_info);
  1194. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1195. struct drm_ati_pcigart_info * gart_info);
  1196. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1197. size_t align, dma_addr_t maxaddr);
  1198. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1199. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1200. /* sysfs support (drm_sysfs.c) */
  1201. struct drm_sysfs_class;
  1202. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1203. extern void drm_sysfs_destroy(void);
  1204. extern int drm_sysfs_device_add(struct drm_minor *minor);
  1205. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1206. extern void drm_sysfs_device_remove(struct drm_minor *minor);
  1207. extern char *drm_get_connector_status_name(enum drm_connector_status status);
  1208. extern int drm_sysfs_connector_add(struct drm_connector *connector);
  1209. extern void drm_sysfs_connector_remove(struct drm_connector *connector);
  1210. /* Graphics Execution Manager library functions (drm_gem.c) */
  1211. int drm_gem_init(struct drm_device *dev);
  1212. void drm_gem_destroy(struct drm_device *dev);
  1213. void drm_gem_object_free(struct kref *kref);
  1214. struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
  1215. size_t size);
  1216. void drm_gem_object_handle_free(struct kref *kref);
  1217. void drm_gem_vm_open(struct vm_area_struct *vma);
  1218. void drm_gem_vm_close(struct vm_area_struct *vma);
  1219. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1220. static inline void
  1221. drm_gem_object_reference(struct drm_gem_object *obj)
  1222. {
  1223. kref_get(&obj->refcount);
  1224. }
  1225. static inline void
  1226. drm_gem_object_unreference(struct drm_gem_object *obj)
  1227. {
  1228. if (obj == NULL)
  1229. return;
  1230. kref_put(&obj->refcount, drm_gem_object_free);
  1231. }
  1232. int drm_gem_handle_create(struct drm_file *file_priv,
  1233. struct drm_gem_object *obj,
  1234. int *handlep);
  1235. static inline void
  1236. drm_gem_object_handle_reference(struct drm_gem_object *obj)
  1237. {
  1238. drm_gem_object_reference(obj);
  1239. kref_get(&obj->handlecount);
  1240. }
  1241. static inline void
  1242. drm_gem_object_handle_unreference(struct drm_gem_object *obj)
  1243. {
  1244. if (obj == NULL)
  1245. return;
  1246. /*
  1247. * Must bump handle count first as this may be the last
  1248. * ref, in which case the object would disappear before we
  1249. * checked for a name
  1250. */
  1251. kref_put(&obj->handlecount, drm_gem_object_handle_free);
  1252. drm_gem_object_unreference(obj);
  1253. }
  1254. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1255. struct drm_file *filp,
  1256. int handle);
  1257. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1258. struct drm_file *file_priv);
  1259. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1260. struct drm_file *file_priv);
  1261. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1262. struct drm_file *file_priv);
  1263. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1264. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1265. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1266. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1267. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1268. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1269. unsigned int token)
  1270. {
  1271. struct drm_map_list *_entry;
  1272. list_for_each_entry(_entry, &dev->maplist, head)
  1273. if (_entry->user_token == token)
  1274. return _entry->map;
  1275. return NULL;
  1276. }
  1277. static __inline__ int drm_device_is_agp(struct drm_device *dev)
  1278. {
  1279. if (dev->driver->device_is_agp != NULL) {
  1280. int err = (*dev->driver->device_is_agp) (dev);
  1281. if (err != 2) {
  1282. return err;
  1283. }
  1284. }
  1285. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1286. }
  1287. static __inline__ int drm_device_is_pcie(struct drm_device *dev)
  1288. {
  1289. return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  1290. }
  1291. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1292. {
  1293. }
  1294. static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
  1295. {
  1296. if (size * nmemb <= PAGE_SIZE)
  1297. return kcalloc(nmemb, size, GFP_KERNEL);
  1298. if (size != 0 && nmemb > ULONG_MAX / size)
  1299. return NULL;
  1300. return __vmalloc(size * nmemb,
  1301. GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
  1302. }
  1303. static __inline void drm_free_large(void *ptr)
  1304. {
  1305. if (!is_vmalloc_addr(ptr))
  1306. return kfree(ptr);
  1307. vfree(ptr);
  1308. }
  1309. /*@}*/
  1310. #endif /* __KERNEL__ */
  1311. #endif