drmP.h 37 KB

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