drmP.h 45 KB

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