drmP.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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/mm.h>
  54. #include <linux/cdev.h>
  55. #include <linux/mutex.h>
  56. #if defined(__alpha__) || defined(__powerpc__)
  57. #include <asm/pgtable.h> /* For pte_wrprotect */
  58. #endif
  59. #include <asm/io.h>
  60. #include <asm/mman.h>
  61. #include <asm/uaccess.h>
  62. #ifdef CONFIG_MTRR
  63. #include <asm/mtrr.h>
  64. #endif
  65. #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
  66. #include <linux/types.h>
  67. #include <linux/agp_backend.h>
  68. #endif
  69. #include <linux/workqueue.h>
  70. #include <linux/poll.h>
  71. #include <asm/pgalloc.h>
  72. #include "drm.h"
  73. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  74. #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
  75. #include "drm_os_linux.h"
  76. #include "drm_hashtab.h"
  77. /***********************************************************************/
  78. /** \name DRM template customization defaults */
  79. /*@{*/
  80. /* driver capabilities and requirements mask */
  81. #define DRIVER_USE_AGP 0x1
  82. #define DRIVER_REQUIRE_AGP 0x2
  83. #define DRIVER_USE_MTRR 0x4
  84. #define DRIVER_PCI_DMA 0x8
  85. #define DRIVER_SG 0x10
  86. #define DRIVER_HAVE_DMA 0x20
  87. #define DRIVER_HAVE_IRQ 0x40
  88. #define DRIVER_IRQ_SHARED 0x80
  89. #define DRIVER_IRQ_VBL 0x100
  90. #define DRIVER_DMA_QUEUE 0x200
  91. #define DRIVER_FB_DMA 0x400
  92. #define DRIVER_IRQ_VBL2 0x800
  93. /***********************************************************************/
  94. /** \name Begin the DRM... */
  95. /*@{*/
  96. #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
  97. also include looping detection. */
  98. #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
  99. #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
  100. #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
  101. #define DRM_LOOPING_LIMIT 5000000
  102. #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
  103. #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
  104. #define DRM_FLAG_DEBUG 0x01
  105. #define DRM_MEM_DMA 0
  106. #define DRM_MEM_SAREA 1
  107. #define DRM_MEM_DRIVER 2
  108. #define DRM_MEM_MAGIC 3
  109. #define DRM_MEM_IOCTLS 4
  110. #define DRM_MEM_MAPS 5
  111. #define DRM_MEM_VMAS 6
  112. #define DRM_MEM_BUFS 7
  113. #define DRM_MEM_SEGS 8
  114. #define DRM_MEM_PAGES 9
  115. #define DRM_MEM_FILES 10
  116. #define DRM_MEM_QUEUES 11
  117. #define DRM_MEM_CMDS 12
  118. #define DRM_MEM_MAPPINGS 13
  119. #define DRM_MEM_BUFLISTS 14
  120. #define DRM_MEM_AGPLISTS 15
  121. #define DRM_MEM_TOTALAGP 16
  122. #define DRM_MEM_BOUNDAGP 17
  123. #define DRM_MEM_CTXBITMAP 18
  124. #define DRM_MEM_STUB 19
  125. #define DRM_MEM_SGLISTS 20
  126. #define DRM_MEM_CTXLIST 21
  127. #define DRM_MEM_MM 22
  128. #define DRM_MEM_HASHTAB 23
  129. #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
  130. #define DRM_MAP_HASH_OFFSET 0x10000000
  131. /*@}*/
  132. /***********************************************************************/
  133. /** \name Macros to make printk easier */
  134. /*@{*/
  135. /**
  136. * Error output.
  137. *
  138. * \param fmt printf() like format string.
  139. * \param arg arguments
  140. */
  141. #define DRM_ERROR(fmt, arg...) \
  142. printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
  143. /**
  144. * Memory error output.
  145. *
  146. * \param area memory area where the error occurred.
  147. * \param fmt printf() like format string.
  148. * \param arg arguments
  149. */
  150. #define DRM_MEM_ERROR(area, fmt, arg...) \
  151. printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
  152. drm_mem_stats[area].name , ##arg)
  153. #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
  154. /**
  155. * Debug output.
  156. *
  157. * \param fmt printf() like format string.
  158. * \param arg arguments
  159. */
  160. #if DRM_DEBUG_CODE
  161. #define DRM_DEBUG(fmt, arg...) \
  162. do { \
  163. if ( drm_debug ) \
  164. printk(KERN_DEBUG \
  165. "[" DRM_NAME ":%s] " fmt , \
  166. __FUNCTION__ , ##arg); \
  167. } while (0)
  168. #else
  169. #define DRM_DEBUG(fmt, arg...) do { } while (0)
  170. #endif
  171. #define DRM_PROC_LIMIT (PAGE_SIZE-80)
  172. #define DRM_PROC_PRINT(fmt, arg...) \
  173. len += sprintf(&buf[len], fmt , ##arg); \
  174. if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
  175. #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
  176. len += sprintf(&buf[len], fmt , ##arg); \
  177. if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
  178. /*@}*/
  179. /***********************************************************************/
  180. /** \name Internal types and structures */
  181. /*@{*/
  182. #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
  183. #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
  184. #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
  185. #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
  186. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  187. /**
  188. * Get the private SAREA mapping.
  189. *
  190. * \param _dev DRM device.
  191. * \param _ctx context number.
  192. * \param _map output mapping.
  193. */
  194. #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
  195. (_map) = (_dev)->context_sareas[_ctx]; \
  196. } while(0)
  197. /**
  198. * Test that the hardware lock is held by the caller, returning otherwise.
  199. *
  200. * \param dev DRM device.
  201. * \param filp file pointer of the caller.
  202. */
  203. #define LOCK_TEST_WITH_RETURN( dev, filp ) \
  204. do { \
  205. if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
  206. dev->lock.filp != filp ) { \
  207. DRM_ERROR( "%s called without lock held\n", \
  208. __FUNCTION__ ); \
  209. return -EINVAL; \
  210. } \
  211. } while (0)
  212. /**
  213. * Copy and IOCTL return string to user space
  214. */
  215. #define DRM_COPY( name, value ) \
  216. len = strlen( value ); \
  217. if ( len > name##_len ) len = name##_len; \
  218. name##_len = strlen( value ); \
  219. if ( len && name ) { \
  220. if ( copy_to_user( name, value, len ) ) \
  221. return -EFAULT; \
  222. }
  223. /**
  224. * Ioctl function type.
  225. *
  226. * \param inode device inode.
  227. * \param filp file pointer.
  228. * \param cmd command.
  229. * \param arg argument.
  230. */
  231. typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
  232. unsigned int cmd, unsigned long arg);
  233. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  234. unsigned long arg);
  235. #define DRM_AUTH 0x1
  236. #define DRM_MASTER 0x2
  237. #define DRM_ROOT_ONLY 0x4
  238. typedef struct drm_ioctl_desc {
  239. drm_ioctl_t *func;
  240. int flags;
  241. } drm_ioctl_desc_t;
  242. typedef struct drm_devstate {
  243. pid_t owner; /**< X server pid holding x_lock */
  244. } drm_devstate_t;
  245. typedef struct drm_magic_entry {
  246. drm_hash_item_t hash_item;
  247. struct list_head head;
  248. struct drm_file *priv;
  249. struct drm_magic_entry *next;
  250. } drm_magic_entry_t;
  251. typedef struct drm_magic_head {
  252. struct drm_magic_entry *head;
  253. struct drm_magic_entry *tail;
  254. } drm_magic_head_t;
  255. typedef struct drm_vma_entry {
  256. struct vm_area_struct *vma;
  257. struct drm_vma_entry *next;
  258. pid_t pid;
  259. } drm_vma_entry_t;
  260. /**
  261. * DMA buffer.
  262. */
  263. typedef struct drm_buf {
  264. int idx; /**< Index into master buflist */
  265. int total; /**< Buffer size */
  266. int order; /**< log-base-2(total) */
  267. int used; /**< Amount of buffer in use (for DMA) */
  268. unsigned long offset; /**< Byte offset (used internally) */
  269. void *address; /**< Address of buffer */
  270. unsigned long bus_address; /**< Bus address of buffer */
  271. struct drm_buf *next; /**< Kernel-only: used for free list */
  272. __volatile__ int waiting; /**< On kernel DMA queue */
  273. __volatile__ int pending; /**< On hardware DMA queue */
  274. wait_queue_head_t dma_wait; /**< Processes waiting */
  275. struct file *filp; /**< Pointer to holding file descr */
  276. int context; /**< Kernel queue for this buffer */
  277. int while_locked; /**< Dispatch this buffer while locked */
  278. enum {
  279. DRM_LIST_NONE = 0,
  280. DRM_LIST_FREE = 1,
  281. DRM_LIST_WAIT = 2,
  282. DRM_LIST_PEND = 3,
  283. DRM_LIST_PRIO = 4,
  284. DRM_LIST_RECLAIM = 5
  285. } list; /**< Which list we're on */
  286. int dev_priv_size; /**< Size of buffer private storage */
  287. void *dev_private; /**< Per-buffer private storage */
  288. } drm_buf_t;
  289. /** bufs is one longer than it has to be */
  290. typedef struct drm_waitlist {
  291. int count; /**< Number of possible buffers */
  292. drm_buf_t **bufs; /**< List of pointers to buffers */
  293. drm_buf_t **rp; /**< Read pointer */
  294. drm_buf_t **wp; /**< Write pointer */
  295. drm_buf_t **end; /**< End pointer */
  296. spinlock_t read_lock;
  297. spinlock_t write_lock;
  298. } drm_waitlist_t;
  299. typedef struct drm_freelist {
  300. int initialized; /**< Freelist in use */
  301. atomic_t count; /**< Number of free buffers */
  302. drm_buf_t *next; /**< End pointer */
  303. wait_queue_head_t waiting; /**< Processes waiting on free bufs */
  304. int low_mark; /**< Low water mark */
  305. int high_mark; /**< High water mark */
  306. atomic_t wfh; /**< If waiting for high mark */
  307. spinlock_t lock;
  308. } drm_freelist_t;
  309. typedef struct drm_dma_handle {
  310. dma_addr_t busaddr;
  311. void *vaddr;
  312. size_t size;
  313. } drm_dma_handle_t;
  314. /**
  315. * Buffer entry. There is one of this for each buffer size order.
  316. */
  317. typedef struct drm_buf_entry {
  318. int buf_size; /**< size */
  319. int buf_count; /**< number of buffers */
  320. drm_buf_t *buflist; /**< buffer list */
  321. int seg_count;
  322. int page_order;
  323. drm_dma_handle_t **seglist;
  324. drm_freelist_t freelist;
  325. } drm_buf_entry_t;
  326. /** File private data */
  327. typedef struct drm_file {
  328. int authenticated;
  329. int master;
  330. int minor;
  331. pid_t pid;
  332. uid_t uid;
  333. drm_magic_t magic;
  334. unsigned long ioctl_count;
  335. struct drm_file *next;
  336. struct drm_file *prev;
  337. struct drm_head *head;
  338. int remove_auth_on_close;
  339. unsigned long lock_count;
  340. void *driver_priv;
  341. } drm_file_t;
  342. /** Wait queue */
  343. typedef struct drm_queue {
  344. atomic_t use_count; /**< Outstanding uses (+1) */
  345. atomic_t finalization; /**< Finalization in progress */
  346. atomic_t block_count; /**< Count of processes waiting */
  347. atomic_t block_read; /**< Queue blocked for reads */
  348. wait_queue_head_t read_queue; /**< Processes waiting on block_read */
  349. atomic_t block_write; /**< Queue blocked for writes */
  350. wait_queue_head_t write_queue; /**< Processes waiting on block_write */
  351. #if 1
  352. atomic_t total_queued; /**< Total queued statistic */
  353. atomic_t total_flushed; /**< Total flushes statistic */
  354. atomic_t total_locks; /**< Total locks statistics */
  355. #endif
  356. drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
  357. drm_waitlist_t waitlist; /**< Pending buffers */
  358. wait_queue_head_t flush_queue; /**< Processes waiting until flush */
  359. } drm_queue_t;
  360. /**
  361. * Lock data.
  362. */
  363. typedef struct drm_lock_data {
  364. drm_hw_lock_t *hw_lock; /**< Hardware lock */
  365. struct file *filp; /**< File descr of lock holder (0=kernel) */
  366. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  367. unsigned long lock_time; /**< Time of last lock in jiffies */
  368. spinlock_t spinlock;
  369. uint32_t kernel_waiters;
  370. uint32_t user_waiters;
  371. int idle_has_lock;
  372. } drm_lock_data_t;
  373. /**
  374. * DMA data.
  375. */
  376. typedef struct drm_device_dma {
  377. drm_buf_entry_t bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  378. int buf_count; /**< total number of buffers */
  379. drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  380. int seg_count;
  381. int page_count; /**< number of pages */
  382. unsigned long *pagelist; /**< page list */
  383. unsigned long byte_count;
  384. enum {
  385. _DRM_DMA_USE_AGP = 0x01,
  386. _DRM_DMA_USE_SG = 0x02,
  387. _DRM_DMA_USE_FB = 0x04,
  388. _DRM_DMA_USE_PCI_RO = 0x08
  389. } flags;
  390. } drm_device_dma_t;
  391. /**
  392. * AGP memory entry. Stored as a doubly linked list.
  393. */
  394. typedef struct drm_agp_mem {
  395. unsigned long handle; /**< handle */
  396. DRM_AGP_MEM *memory;
  397. unsigned long bound; /**< address */
  398. int pages;
  399. struct drm_agp_mem *prev; /**< previous entry */
  400. struct drm_agp_mem *next; /**< next entry */
  401. } drm_agp_mem_t;
  402. /**
  403. * AGP data.
  404. *
  405. * \sa drm_agp_init() and drm_device::agp.
  406. */
  407. typedef struct drm_agp_head {
  408. DRM_AGP_KERN agp_info; /**< AGP device information */
  409. drm_agp_mem_t *memory; /**< memory entries */
  410. unsigned long mode; /**< AGP mode */
  411. struct agp_bridge_data *bridge;
  412. int enabled; /**< whether the AGP bus as been enabled */
  413. int acquired; /**< whether the AGP device has been acquired */
  414. unsigned long base;
  415. int agp_mtrr;
  416. int cant_use_aperture;
  417. unsigned long page_mask;
  418. } drm_agp_head_t;
  419. /**
  420. * Scatter-gather memory.
  421. */
  422. typedef struct drm_sg_mem {
  423. unsigned long handle;
  424. void *virtual;
  425. int pages;
  426. struct page **pagelist;
  427. dma_addr_t *busaddr;
  428. } drm_sg_mem_t;
  429. typedef struct drm_sigdata {
  430. int context;
  431. drm_hw_lock_t *lock;
  432. } drm_sigdata_t;
  433. /**
  434. * Mappings list
  435. */
  436. typedef struct drm_map_list {
  437. struct list_head head; /**< list head */
  438. drm_hash_item_t hash;
  439. drm_map_t *map; /**< mapping */
  440. unsigned int user_token;
  441. } drm_map_list_t;
  442. typedef drm_map_t drm_local_map_t;
  443. /**
  444. * Context handle list
  445. */
  446. typedef struct drm_ctx_list {
  447. struct list_head head; /**< list head */
  448. drm_context_t handle; /**< context handle */
  449. drm_file_t *tag; /**< associated fd private data */
  450. } drm_ctx_list_t;
  451. typedef struct drm_vbl_sig {
  452. struct list_head head;
  453. unsigned int sequence;
  454. struct siginfo info;
  455. struct task_struct *task;
  456. } drm_vbl_sig_t;
  457. /* location of GART table */
  458. #define DRM_ATI_GART_MAIN 1
  459. #define DRM_ATI_GART_FB 2
  460. #define DRM_ATI_GART_PCI 1
  461. #define DRM_ATI_GART_PCIE 2
  462. #define DRM_ATI_GART_IGP 3
  463. typedef struct ati_pcigart_info {
  464. int gart_table_location;
  465. int gart_reg_if;
  466. void *addr;
  467. dma_addr_t bus_addr;
  468. drm_local_map_t mapping;
  469. int table_size;
  470. } drm_ati_pcigart_info;
  471. /*
  472. * Generic memory manager structs
  473. */
  474. typedef struct drm_mm_node {
  475. struct list_head fl_entry;
  476. struct list_head ml_entry;
  477. int free;
  478. unsigned long start;
  479. unsigned long size;
  480. struct drm_mm *mm;
  481. void *private;
  482. } drm_mm_node_t;
  483. typedef struct drm_mm {
  484. struct list_head fl_entry;
  485. struct list_head ml_entry;
  486. } drm_mm_t;
  487. /**
  488. * DRM driver structure. This structure represent the common code for
  489. * a family of cards. There will one drm_device for each card present
  490. * in this family
  491. */
  492. struct drm_device;
  493. struct drm_driver {
  494. int (*load) (struct drm_device *, unsigned long flags);
  495. int (*firstopen) (struct drm_device *);
  496. int (*open) (struct drm_device *, drm_file_t *);
  497. void (*preclose) (struct drm_device *, struct file * filp);
  498. void (*postclose) (struct drm_device *, drm_file_t *);
  499. void (*lastclose) (struct drm_device *);
  500. int (*unload) (struct drm_device *);
  501. int (*dma_ioctl) (DRM_IOCTL_ARGS);
  502. void (*dma_ready) (struct drm_device *);
  503. int (*dma_quiescent) (struct drm_device *);
  504. int (*context_ctor) (struct drm_device * dev, int context);
  505. int (*context_dtor) (struct drm_device * dev, int context);
  506. int (*kernel_context_switch) (struct drm_device * dev, int old,
  507. int new);
  508. void (*kernel_context_switch_unlock) (struct drm_device * dev);
  509. int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
  510. int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
  511. int (*dri_library_name) (struct drm_device *dev, char *buf);
  512. /**
  513. * Called by \c drm_device_is_agp. Typically used to determine if a
  514. * card is really attached to AGP or not.
  515. *
  516. * \param dev DRM device handle
  517. *
  518. * \returns
  519. * One of three values is returned depending on whether or not the
  520. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  521. * (return of 1), or may or may not be AGP (return of 2).
  522. */
  523. int (*device_is_agp) (struct drm_device * dev);
  524. /* these have to be filled in */
  525. irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  526. void (*irq_preinstall) (struct drm_device * dev);
  527. void (*irq_postinstall) (struct drm_device * dev);
  528. void (*irq_uninstall) (struct drm_device * dev);
  529. void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
  530. void (*reclaim_buffers_locked) (struct drm_device *dev,
  531. struct file *filp);
  532. void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
  533. struct file * filp);
  534. unsigned long (*get_map_ofs) (drm_map_t * map);
  535. unsigned long (*get_reg_ofs) (struct drm_device * dev);
  536. void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
  537. int major;
  538. int minor;
  539. int patchlevel;
  540. char *name;
  541. char *desc;
  542. char *date;
  543. u32 driver_features;
  544. int dev_priv_size;
  545. drm_ioctl_desc_t *ioctls;
  546. int num_ioctls;
  547. struct file_operations fops;
  548. struct pci_driver pci_driver;
  549. };
  550. /**
  551. * DRM head structure. This structure represent a video head on a card
  552. * that may contain multiple heads. Embed one per head of these in the
  553. * private drm_device structure.
  554. */
  555. typedef struct drm_head {
  556. int minor; /**< Minor device number */
  557. struct drm_device *dev;
  558. struct proc_dir_entry *dev_root; /**< proc directory entry */
  559. dev_t device; /**< Device number for mknod */
  560. struct class_device *dev_class;
  561. } drm_head_t;
  562. /**
  563. * DRM device structure. This structure represent a complete card that
  564. * may contain multiple heads.
  565. */
  566. typedef struct drm_device {
  567. char *unique; /**< Unique identifier: e.g., busid */
  568. int unique_len; /**< Length of unique field */
  569. char *devname; /**< For /proc/interrupts */
  570. int if_version; /**< Highest interface version set */
  571. int blocked; /**< Blocked due to VC switch? */
  572. /** \name Locks */
  573. /*@{ */
  574. spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
  575. struct mutex struct_mutex; /**< For others */
  576. /*@} */
  577. /** \name Usage Counters */
  578. /*@{ */
  579. int open_count; /**< Outstanding files open */
  580. atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
  581. atomic_t vma_count; /**< Outstanding vma areas open */
  582. int buf_use; /**< Buffers in use -- cannot alloc */
  583. atomic_t buf_alloc; /**< Buffer allocation in progress */
  584. /*@} */
  585. /** \name Performance counters */
  586. /*@{ */
  587. unsigned long counters;
  588. drm_stat_type_t types[15];
  589. atomic_t counts[15];
  590. /*@} */
  591. /** \name Authentication */
  592. /*@{ */
  593. drm_file_t *file_first; /**< file list head */
  594. drm_file_t *file_last; /**< file list tail */
  595. drm_open_hash_t magiclist; /**< magic hash table */
  596. struct list_head magicfree;
  597. /*@} */
  598. /** \name Memory management */
  599. /*@{ */
  600. drm_map_list_t *maplist; /**< Linked list of regions */
  601. int map_count; /**< Number of mappable regions */
  602. drm_open_hash_t map_hash; /**< User token hash table for maps */
  603. /** \name Context handle management */
  604. /*@{ */
  605. drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
  606. int ctx_count; /**< Number of context handles */
  607. struct mutex ctxlist_mutex; /**< For ctxlist */
  608. drm_map_t **context_sareas; /**< per-context SAREA's */
  609. int max_context;
  610. drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
  611. drm_lock_data_t lock; /**< Information on hardware lock */
  612. /*@} */
  613. /** \name DMA queues (contexts) */
  614. /*@{ */
  615. int queue_count; /**< Number of active DMA queues */
  616. int queue_reserved; /**< Number of reserved DMA queues */
  617. int queue_slots; /**< Actual length of queuelist */
  618. drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
  619. drm_device_dma_t *dma; /**< Optional pointer for DMA support */
  620. /*@} */
  621. /** \name Context support */
  622. /*@{ */
  623. int irq; /**< Interrupt used by board */
  624. int irq_enabled; /**< True if irq handler is enabled */
  625. __volatile__ long context_flag; /**< Context swapping flag */
  626. __volatile__ long interrupt_flag; /**< Interruption handler flag */
  627. __volatile__ long dma_flag; /**< DMA dispatch flag */
  628. struct timer_list timer; /**< Timer for delaying ctx switch */
  629. wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
  630. int last_checked; /**< Last context checked for DMA */
  631. int last_context; /**< Last current context */
  632. unsigned long last_switch; /**< jiffies at last context switch */
  633. /*@} */
  634. struct work_struct work;
  635. /** \name VBLANK IRQ support */
  636. /*@{ */
  637. wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
  638. atomic_t vbl_received;
  639. atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
  640. spinlock_t vbl_lock;
  641. drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
  642. drm_vbl_sig_t vbl_sigs2; /**< signals to send on secondary VBLANK */
  643. unsigned int vbl_pending;
  644. spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
  645. void (*locked_tasklet_func)(struct drm_device *dev);
  646. /*@} */
  647. cycles_t ctx_start;
  648. cycles_t lck_start;
  649. struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  650. wait_queue_head_t buf_readers; /**< Processes waiting to read */
  651. wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
  652. drm_agp_head_t *agp; /**< AGP data */
  653. struct pci_dev *pdev; /**< PCI device structure */
  654. int pci_vendor; /**< PCI vendor id */
  655. int pci_device; /**< PCI device id */
  656. #ifdef __alpha__
  657. struct pci_controller *hose;
  658. #endif
  659. drm_sg_mem_t *sg; /**< Scatter gather memory */
  660. unsigned long *ctx_bitmap; /**< context bitmap */
  661. void *dev_private; /**< device private data */
  662. drm_sigdata_t sigdata; /**< For block_all_signals */
  663. sigset_t sigmask;
  664. struct drm_driver *driver;
  665. drm_local_map_t *agp_buffer_map;
  666. unsigned int agp_buffer_token;
  667. drm_head_t primary; /**< primary screen head */
  668. /** \name Drawable information */
  669. /*@{ */
  670. spinlock_t drw_lock;
  671. unsigned int drw_bitfield_length;
  672. u32 *drw_bitfield;
  673. unsigned int drw_info_length;
  674. drm_drawable_info_t **drw_info;
  675. /*@} */
  676. } drm_device_t;
  677. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  678. int feature)
  679. {
  680. return ((dev->driver->driver_features & feature) ? 1 : 0);
  681. }
  682. #ifdef __alpha__
  683. #define drm_get_pci_domain(dev) dev->hose->index
  684. #else
  685. #define drm_get_pci_domain(dev) 0
  686. #endif
  687. #if __OS_HAS_AGP
  688. static inline int drm_core_has_AGP(struct drm_device *dev)
  689. {
  690. return drm_core_check_feature(dev, DRIVER_USE_AGP);
  691. }
  692. #else
  693. #define drm_core_has_AGP(dev) (0)
  694. #endif
  695. #if __OS_HAS_MTRR
  696. static inline int drm_core_has_MTRR(struct drm_device *dev)
  697. {
  698. return drm_core_check_feature(dev, DRIVER_USE_MTRR);
  699. }
  700. #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
  701. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  702. unsigned int flags)
  703. {
  704. return mtrr_add(offset, size, flags, 1);
  705. }
  706. static inline int drm_mtrr_del(int handle, unsigned long offset,
  707. unsigned long size, unsigned int flags)
  708. {
  709. return mtrr_del(handle, offset, size);
  710. }
  711. #else
  712. #define drm_core_has_MTRR(dev) (0)
  713. #define DRM_MTRR_WC 0
  714. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  715. unsigned int flags)
  716. {
  717. return 0;
  718. }
  719. static inline int drm_mtrr_del(int handle, unsigned long offset,
  720. unsigned long size, unsigned int flags)
  721. {
  722. return 0;
  723. }
  724. #endif
  725. /******************************************************************/
  726. /** \name Internal function definitions */
  727. /*@{*/
  728. /* Driver support (drm_drv.h) */
  729. extern int drm_init(struct drm_driver *driver);
  730. extern void drm_exit(struct drm_driver *driver);
  731. extern int drm_ioctl(struct inode *inode, struct file *filp,
  732. unsigned int cmd, unsigned long arg);
  733. extern long drm_compat_ioctl(struct file *filp,
  734. unsigned int cmd, unsigned long arg);
  735. extern int drm_lastclose(drm_device_t *dev);
  736. /* Device support (drm_fops.h) */
  737. extern int drm_open(struct inode *inode, struct file *filp);
  738. extern int drm_stub_open(struct inode *inode, struct file *filp);
  739. extern int drm_fasync(int fd, struct file *filp, int on);
  740. extern int drm_release(struct inode *inode, struct file *filp);
  741. /* Mapping support (drm_vm.h) */
  742. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  743. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  744. /* Memory management support (drm_memory.h) */
  745. #include "drm_memory.h"
  746. extern void drm_mem_init(void);
  747. extern int drm_mem_info(char *buf, char **start, off_t offset,
  748. int request, int *eof, void *data);
  749. extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
  750. extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
  751. extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
  752. extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
  753. extern int drm_unbind_agp(DRM_AGP_MEM * handle);
  754. /* Misc. IOCTL support (drm_ioctl.h) */
  755. extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
  756. unsigned int cmd, unsigned long arg);
  757. extern int drm_getunique(struct inode *inode, struct file *filp,
  758. unsigned int cmd, unsigned long arg);
  759. extern int drm_setunique(struct inode *inode, struct file *filp,
  760. unsigned int cmd, unsigned long arg);
  761. extern int drm_getmap(struct inode *inode, struct file *filp,
  762. unsigned int cmd, unsigned long arg);
  763. extern int drm_getclient(struct inode *inode, struct file *filp,
  764. unsigned int cmd, unsigned long arg);
  765. extern int drm_getstats(struct inode *inode, struct file *filp,
  766. unsigned int cmd, unsigned long arg);
  767. extern int drm_setversion(struct inode *inode, struct file *filp,
  768. unsigned int cmd, unsigned long arg);
  769. extern int drm_noop(struct inode *inode, struct file *filp,
  770. unsigned int cmd, unsigned long arg);
  771. /* Context IOCTL support (drm_context.h) */
  772. extern int drm_resctx(struct inode *inode, struct file *filp,
  773. unsigned int cmd, unsigned long arg);
  774. extern int drm_addctx(struct inode *inode, struct file *filp,
  775. unsigned int cmd, unsigned long arg);
  776. extern int drm_modctx(struct inode *inode, struct file *filp,
  777. unsigned int cmd, unsigned long arg);
  778. extern int drm_getctx(struct inode *inode, struct file *filp,
  779. unsigned int cmd, unsigned long arg);
  780. extern int drm_switchctx(struct inode *inode, struct file *filp,
  781. unsigned int cmd, unsigned long arg);
  782. extern int drm_newctx(struct inode *inode, struct file *filp,
  783. unsigned int cmd, unsigned long arg);
  784. extern int drm_rmctx(struct inode *inode, struct file *filp,
  785. unsigned int cmd, unsigned long arg);
  786. extern int drm_ctxbitmap_init(drm_device_t * dev);
  787. extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
  788. extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
  789. extern int drm_setsareactx(struct inode *inode, struct file *filp,
  790. unsigned int cmd, unsigned long arg);
  791. extern int drm_getsareactx(struct inode *inode, struct file *filp,
  792. unsigned int cmd, unsigned long arg);
  793. /* Drawable IOCTL support (drm_drawable.h) */
  794. extern int drm_adddraw(struct inode *inode, struct file *filp,
  795. unsigned int cmd, unsigned long arg);
  796. extern int drm_rmdraw(struct inode *inode, struct file *filp,
  797. unsigned int cmd, unsigned long arg);
  798. extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
  799. unsigned int cmd, unsigned long arg);
  800. extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
  801. drm_drawable_t id);
  802. /* Authentication IOCTL support (drm_auth.h) */
  803. extern int drm_getmagic(struct inode *inode, struct file *filp,
  804. unsigned int cmd, unsigned long arg);
  805. extern int drm_authmagic(struct inode *inode, struct file *filp,
  806. unsigned int cmd, unsigned long arg);
  807. /* Locking IOCTL support (drm_lock.h) */
  808. extern int drm_lock(struct inode *inode, struct file *filp,
  809. unsigned int cmd, unsigned long arg);
  810. extern int drm_unlock(struct inode *inode, struct file *filp,
  811. unsigned int cmd, unsigned long arg);
  812. extern int drm_lock_take(drm_lock_data_t *lock_data, unsigned int context);
  813. extern int drm_lock_free(drm_lock_data_t *lock_data, unsigned int context);
  814. extern void drm_idlelock_take(drm_lock_data_t *lock_data);
  815. extern void drm_idlelock_release(drm_lock_data_t *lock_data);
  816. /*
  817. * These are exported to drivers so that they can implement fencing using
  818. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  819. */
  820. extern int drm_i_have_hw_lock(struct file *filp);
  821. extern int drm_kernel_take_hw_lock(struct file *filp);
  822. /* Buffer management support (drm_bufs.h) */
  823. extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
  824. extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
  825. extern int drm_addmap(drm_device_t * dev, unsigned int offset,
  826. unsigned int size, drm_map_type_t type,
  827. drm_map_flags_t flags, drm_local_map_t ** map_ptr);
  828. extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
  829. unsigned int cmd, unsigned long arg);
  830. extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
  831. extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
  832. extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
  833. unsigned int cmd, unsigned long arg);
  834. extern int drm_order(unsigned long size);
  835. extern int drm_addbufs(struct inode *inode, struct file *filp,
  836. unsigned int cmd, unsigned long arg);
  837. extern int drm_infobufs(struct inode *inode, struct file *filp,
  838. unsigned int cmd, unsigned long arg);
  839. extern int drm_markbufs(struct inode *inode, struct file *filp,
  840. unsigned int cmd, unsigned long arg);
  841. extern int drm_freebufs(struct inode *inode, struct file *filp,
  842. unsigned int cmd, unsigned long arg);
  843. extern int drm_mapbufs(struct inode *inode, struct file *filp,
  844. unsigned int cmd, unsigned long arg);
  845. extern unsigned long drm_get_resource_start(drm_device_t * dev,
  846. unsigned int resource);
  847. extern unsigned long drm_get_resource_len(drm_device_t * dev,
  848. unsigned int resource);
  849. /* DMA support (drm_dma.h) */
  850. extern int drm_dma_setup(drm_device_t * dev);
  851. extern void drm_dma_takedown(drm_device_t * dev);
  852. extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
  853. extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
  854. /* IRQ support (drm_irq.h) */
  855. extern int drm_control(struct inode *inode, struct file *filp,
  856. unsigned int cmd, unsigned long arg);
  857. extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
  858. extern int drm_irq_uninstall(drm_device_t * dev);
  859. extern void drm_driver_irq_preinstall(drm_device_t * dev);
  860. extern void drm_driver_irq_postinstall(drm_device_t * dev);
  861. extern void drm_driver_irq_uninstall(drm_device_t * dev);
  862. extern int drm_wait_vblank(struct inode *inode, struct file *filp,
  863. unsigned int cmd, unsigned long arg);
  864. extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
  865. extern void drm_vbl_send_signals(drm_device_t * dev);
  866. extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));
  867. /* AGP/GART support (drm_agpsupport.h) */
  868. extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
  869. extern int drm_agp_acquire(drm_device_t * dev);
  870. extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
  871. unsigned int cmd, unsigned long arg);
  872. extern int drm_agp_release(drm_device_t * dev);
  873. extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
  874. unsigned int cmd, unsigned long arg);
  875. extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
  876. extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
  877. unsigned int cmd, unsigned long arg);
  878. extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
  879. extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
  880. unsigned int cmd, unsigned long arg);
  881. extern int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
  882. extern int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
  883. unsigned int cmd, unsigned long arg);
  884. extern int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
  885. extern int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
  886. unsigned int cmd, unsigned long arg);
  887. extern int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
  888. extern int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
  889. unsigned int cmd, unsigned long arg);
  890. extern int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
  891. extern int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
  892. unsigned int cmd, unsigned long arg);
  893. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
  894. size_t pages, u32 type);
  895. extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
  896. extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
  897. extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
  898. /* Stub support (drm_stub.h) */
  899. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  900. struct drm_driver *driver);
  901. extern int drm_put_dev(drm_device_t * dev);
  902. extern int drm_put_head(drm_head_t * head);
  903. extern unsigned int drm_debug;
  904. extern unsigned int drm_cards_limit;
  905. extern drm_head_t **drm_heads;
  906. extern struct class *drm_class;
  907. extern struct proc_dir_entry *drm_proc_root;
  908. /* Proc support (drm_proc.h) */
  909. extern int drm_proc_init(drm_device_t * dev,
  910. int minor,
  911. struct proc_dir_entry *root,
  912. struct proc_dir_entry **dev_root);
  913. extern int drm_proc_cleanup(int minor,
  914. struct proc_dir_entry *root,
  915. struct proc_dir_entry *dev_root);
  916. /* Scatter Gather Support (drm_scatter.h) */
  917. extern void drm_sg_cleanup(drm_sg_mem_t * entry);
  918. extern int drm_sg_alloc(struct inode *inode, struct file *filp,
  919. unsigned int cmd, unsigned long arg);
  920. extern int drm_sg_free(struct inode *inode, struct file *filp,
  921. unsigned int cmd, unsigned long arg);
  922. /* ATI PCIGART support (ati_pcigart.h) */
  923. extern int drm_ati_pcigart_init(drm_device_t * dev,
  924. drm_ati_pcigart_info * gart_info);
  925. extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
  926. drm_ati_pcigart_info * gart_info);
  927. extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
  928. size_t align, dma_addr_t maxaddr);
  929. extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
  930. extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
  931. /* sysfs support (drm_sysfs.c) */
  932. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  933. extern void drm_sysfs_destroy(struct class *cs);
  934. extern struct class_device *drm_sysfs_device_add(struct class *cs,
  935. drm_head_t *head);
  936. extern void drm_sysfs_device_remove(struct class_device *class_dev);
  937. /*
  938. * Basic memory manager support (drm_mm.c)
  939. */
  940. extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
  941. unsigned long size,
  942. unsigned alignment);
  943. void drm_mm_put_block(drm_mm_node_t * cur);
  944. extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
  945. unsigned alignment, int best_match);
  946. extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
  947. extern void drm_mm_takedown(drm_mm_t *mm);
  948. extern int drm_mm_clean(drm_mm_t *mm);
  949. extern unsigned long drm_mm_tail_space(drm_mm_t *mm);
  950. extern int drm_mm_remove_space_from_tail(drm_mm_t *mm, unsigned long size);
  951. extern int drm_mm_add_space_to_tail(drm_mm_t *mm, unsigned long size);
  952. extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
  953. extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
  954. static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
  955. unsigned int token)
  956. {
  957. drm_map_list_t *_entry;
  958. list_for_each_entry(_entry, &dev->maplist->head, head)
  959. if (_entry->user_token == token)
  960. return _entry->map;
  961. return NULL;
  962. }
  963. static __inline__ int drm_device_is_agp(drm_device_t * dev)
  964. {
  965. if (dev->driver->device_is_agp != NULL) {
  966. int err = (*dev->driver->device_is_agp) (dev);
  967. if (err != 2) {
  968. return err;
  969. }
  970. }
  971. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  972. }
  973. static __inline__ int drm_device_is_pcie(drm_device_t * dev)
  974. {
  975. return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  976. }
  977. static __inline__ void drm_core_dropmap(struct drm_map *map)
  978. {
  979. }
  980. #ifndef DEBUG_MEMORY
  981. /** Wrapper around kmalloc() */
  982. static __inline__ void *drm_alloc(size_t size, int area)
  983. {
  984. return kmalloc(size, GFP_KERNEL);
  985. }
  986. /** Wrapper around kfree() */
  987. static __inline__ void drm_free(void *pt, size_t size, int area)
  988. {
  989. kfree(pt);
  990. }
  991. /** Wrapper around kcalloc() */
  992. static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
  993. {
  994. return kcalloc(nmemb, size, GFP_KERNEL);
  995. }
  996. #else
  997. extern void *drm_alloc(size_t size, int area);
  998. extern void drm_free(void *pt, size_t size, int area);
  999. extern void *drm_calloc(size_t nmemb, size_t size, int area);
  1000. #endif
  1001. /*@}*/
  1002. extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
  1003. extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
  1004. #endif /* __KERNEL__ */
  1005. #endif