drmP.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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. } drm_lock_data_t;
  369. /**
  370. * DMA data.
  371. */
  372. typedef struct drm_device_dma {
  373. drm_buf_entry_t bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  374. int buf_count; /**< total number of buffers */
  375. drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  376. int seg_count;
  377. int page_count; /**< number of pages */
  378. unsigned long *pagelist; /**< page list */
  379. unsigned long byte_count;
  380. enum {
  381. _DRM_DMA_USE_AGP = 0x01,
  382. _DRM_DMA_USE_SG = 0x02,
  383. _DRM_DMA_USE_FB = 0x04,
  384. _DRM_DMA_USE_PCI_RO = 0x08
  385. } flags;
  386. } drm_device_dma_t;
  387. /**
  388. * AGP memory entry. Stored as a doubly linked list.
  389. */
  390. typedef struct drm_agp_mem {
  391. unsigned long handle; /**< handle */
  392. DRM_AGP_MEM *memory;
  393. unsigned long bound; /**< address */
  394. int pages;
  395. struct drm_agp_mem *prev; /**< previous entry */
  396. struct drm_agp_mem *next; /**< next entry */
  397. } drm_agp_mem_t;
  398. /**
  399. * AGP data.
  400. *
  401. * \sa drm_agp_init() and drm_device::agp.
  402. */
  403. typedef struct drm_agp_head {
  404. DRM_AGP_KERN agp_info; /**< AGP device information */
  405. drm_agp_mem_t *memory; /**< memory entries */
  406. unsigned long mode; /**< AGP mode */
  407. struct agp_bridge_data *bridge;
  408. int enabled; /**< whether the AGP bus as been enabled */
  409. int acquired; /**< whether the AGP device has been acquired */
  410. unsigned long base;
  411. int agp_mtrr;
  412. int cant_use_aperture;
  413. unsigned long page_mask;
  414. } drm_agp_head_t;
  415. /**
  416. * Scatter-gather memory.
  417. */
  418. typedef struct drm_sg_mem {
  419. unsigned long handle;
  420. void *virtual;
  421. int pages;
  422. struct page **pagelist;
  423. dma_addr_t *busaddr;
  424. } drm_sg_mem_t;
  425. typedef struct drm_sigdata {
  426. int context;
  427. drm_hw_lock_t *lock;
  428. } drm_sigdata_t;
  429. /**
  430. * Mappings list
  431. */
  432. typedef struct drm_map_list {
  433. struct list_head head; /**< list head */
  434. drm_hash_item_t hash;
  435. drm_map_t *map; /**< mapping */
  436. unsigned int user_token;
  437. } drm_map_list_t;
  438. typedef drm_map_t drm_local_map_t;
  439. /**
  440. * Context handle list
  441. */
  442. typedef struct drm_ctx_list {
  443. struct list_head head; /**< list head */
  444. drm_context_t handle; /**< context handle */
  445. drm_file_t *tag; /**< associated fd private data */
  446. } drm_ctx_list_t;
  447. typedef struct drm_vbl_sig {
  448. struct list_head head;
  449. unsigned int sequence;
  450. struct siginfo info;
  451. struct task_struct *task;
  452. } drm_vbl_sig_t;
  453. /* location of GART table */
  454. #define DRM_ATI_GART_MAIN 1
  455. #define DRM_ATI_GART_FB 2
  456. typedef struct ati_pcigart_info {
  457. int gart_table_location;
  458. int is_pcie;
  459. void *addr;
  460. dma_addr_t bus_addr;
  461. drm_local_map_t mapping;
  462. } drm_ati_pcigart_info;
  463. /*
  464. * Generic memory manager structs
  465. */
  466. typedef 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. } drm_mm_node_t;
  475. typedef struct drm_mm {
  476. struct list_head fl_entry;
  477. struct list_head ml_entry;
  478. } drm_mm_t;
  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 *, drm_file_t *);
  489. void (*preclose) (struct drm_device *, struct file * filp);
  490. void (*postclose) (struct drm_device *, drm_file_t *);
  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. unsigned long (*get_map_ofs) (drm_map_t * map);
  525. unsigned long (*get_reg_ofs) (struct drm_device * dev);
  526. void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
  527. int major;
  528. int minor;
  529. int patchlevel;
  530. char *name;
  531. char *desc;
  532. char *date;
  533. u32 driver_features;
  534. int dev_priv_size;
  535. drm_ioctl_desc_t *ioctls;
  536. int num_ioctls;
  537. struct file_operations fops;
  538. struct pci_driver pci_driver;
  539. };
  540. /**
  541. * DRM head structure. This structure represent a video head on a card
  542. * that may contain multiple heads. Embed one per head of these in the
  543. * private drm_device structure.
  544. */
  545. typedef struct drm_head {
  546. int minor; /**< Minor device number */
  547. struct drm_device *dev;
  548. struct proc_dir_entry *dev_root; /**< proc directory entry */
  549. dev_t device; /**< Device number for mknod */
  550. struct class_device *dev_class;
  551. } drm_head_t;
  552. /**
  553. * DRM device structure. This structure represent a complete card that
  554. * may contain multiple heads.
  555. */
  556. typedef struct drm_device {
  557. char *unique; /**< Unique identifier: e.g., busid */
  558. int unique_len; /**< Length of unique field */
  559. char *devname; /**< For /proc/interrupts */
  560. int if_version; /**< Highest interface version set */
  561. int blocked; /**< Blocked due to VC switch? */
  562. /** \name Locks */
  563. /*@{ */
  564. spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
  565. struct mutex struct_mutex; /**< For others */
  566. /*@} */
  567. /** \name Usage Counters */
  568. /*@{ */
  569. int open_count; /**< Outstanding files open */
  570. atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
  571. atomic_t vma_count; /**< Outstanding vma areas open */
  572. int buf_use; /**< Buffers in use -- cannot alloc */
  573. atomic_t buf_alloc; /**< Buffer allocation in progress */
  574. /*@} */
  575. /** \name Performance counters */
  576. /*@{ */
  577. unsigned long counters;
  578. drm_stat_type_t types[15];
  579. atomic_t counts[15];
  580. /*@} */
  581. /** \name Authentication */
  582. /*@{ */
  583. drm_file_t *file_first; /**< file list head */
  584. drm_file_t *file_last; /**< file list tail */
  585. drm_open_hash_t magiclist; /**< magic hash table */
  586. struct list_head magicfree;
  587. /*@} */
  588. /** \name Memory management */
  589. /*@{ */
  590. drm_map_list_t *maplist; /**< Linked list of regions */
  591. int map_count; /**< Number of mappable regions */
  592. drm_open_hash_t map_hash; /**< User token hash table for maps */
  593. /** \name Context handle management */
  594. /*@{ */
  595. drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
  596. int ctx_count; /**< Number of context handles */
  597. struct mutex ctxlist_mutex; /**< For ctxlist */
  598. drm_map_t **context_sareas; /**< per-context SAREA's */
  599. int max_context;
  600. drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
  601. drm_lock_data_t lock; /**< Information on hardware lock */
  602. /*@} */
  603. /** \name DMA queues (contexts) */
  604. /*@{ */
  605. int queue_count; /**< Number of active DMA queues */
  606. int queue_reserved; /**< Number of reserved DMA queues */
  607. int queue_slots; /**< Actual length of queuelist */
  608. drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
  609. drm_device_dma_t *dma; /**< Optional pointer for DMA support */
  610. /*@} */
  611. /** \name Context support */
  612. /*@{ */
  613. int irq; /**< Interrupt used by board */
  614. int irq_enabled; /**< True if irq handler is enabled */
  615. __volatile__ long context_flag; /**< Context swapping flag */
  616. __volatile__ long interrupt_flag; /**< Interruption handler flag */
  617. __volatile__ long dma_flag; /**< DMA dispatch flag */
  618. struct timer_list timer; /**< Timer for delaying ctx switch */
  619. wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
  620. int last_checked; /**< Last context checked for DMA */
  621. int last_context; /**< Last current context */
  622. unsigned long last_switch; /**< jiffies at last context switch */
  623. /*@} */
  624. struct work_struct work;
  625. /** \name VBLANK IRQ support */
  626. /*@{ */
  627. wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
  628. atomic_t vbl_received;
  629. atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
  630. spinlock_t vbl_lock;
  631. drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
  632. drm_vbl_sig_t vbl_sigs2; /**< signals to send on secondary VBLANK */
  633. unsigned int vbl_pending;
  634. spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
  635. void (*locked_tasklet_func)(struct drm_device *dev);
  636. /*@} */
  637. cycles_t ctx_start;
  638. cycles_t lck_start;
  639. struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  640. wait_queue_head_t buf_readers; /**< Processes waiting to read */
  641. wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
  642. drm_agp_head_t *agp; /**< AGP data */
  643. struct pci_dev *pdev; /**< PCI device structure */
  644. int pci_vendor; /**< PCI vendor id */
  645. int pci_device; /**< PCI device id */
  646. #ifdef __alpha__
  647. struct pci_controller *hose;
  648. #endif
  649. drm_sg_mem_t *sg; /**< Scatter gather memory */
  650. unsigned long *ctx_bitmap; /**< context bitmap */
  651. void *dev_private; /**< device private data */
  652. drm_sigdata_t sigdata; /**< For block_all_signals */
  653. sigset_t sigmask;
  654. struct drm_driver *driver;
  655. drm_local_map_t *agp_buffer_map;
  656. unsigned int agp_buffer_token;
  657. drm_head_t primary; /**< primary screen head */
  658. /** \name Drawable information */
  659. /*@{ */
  660. spinlock_t drw_lock;
  661. unsigned int drw_bitfield_length;
  662. u32 *drw_bitfield;
  663. unsigned int drw_info_length;
  664. drm_drawable_info_t **drw_info;
  665. /*@} */
  666. } drm_device_t;
  667. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  668. int feature)
  669. {
  670. return ((dev->driver->driver_features & feature) ? 1 : 0);
  671. }
  672. #ifdef __alpha__
  673. #define drm_get_pci_domain(dev) dev->hose->bus->number
  674. #else
  675. #define drm_get_pci_domain(dev) 0
  676. #endif
  677. #if __OS_HAS_AGP
  678. static inline int drm_core_has_AGP(struct drm_device *dev)
  679. {
  680. return drm_core_check_feature(dev, DRIVER_USE_AGP);
  681. }
  682. #else
  683. #define drm_core_has_AGP(dev) (0)
  684. #endif
  685. #if __OS_HAS_MTRR
  686. static inline int drm_core_has_MTRR(struct drm_device *dev)
  687. {
  688. return drm_core_check_feature(dev, DRIVER_USE_MTRR);
  689. }
  690. #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
  691. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  692. unsigned int flags)
  693. {
  694. return mtrr_add(offset, size, flags, 1);
  695. }
  696. static inline int drm_mtrr_del(int handle, unsigned long offset,
  697. unsigned long size, unsigned int flags)
  698. {
  699. return mtrr_del(handle, offset, size);
  700. }
  701. #else
  702. #define drm_core_has_MTRR(dev) (0)
  703. #define DRM_MTRR_WC 0
  704. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  705. unsigned int flags)
  706. {
  707. return 0;
  708. }
  709. static inline int drm_mtrr_del(int handle, unsigned long offset,
  710. unsigned long size, unsigned int flags)
  711. {
  712. return 0;
  713. }
  714. #endif
  715. /******************************************************************/
  716. /** \name Internal function definitions */
  717. /*@{*/
  718. /* Driver support (drm_drv.h) */
  719. extern int drm_init(struct drm_driver *driver);
  720. extern void drm_exit(struct drm_driver *driver);
  721. extern int drm_ioctl(struct inode *inode, struct file *filp,
  722. unsigned int cmd, unsigned long arg);
  723. extern long drm_compat_ioctl(struct file *filp,
  724. unsigned int cmd, unsigned long arg);
  725. extern int drm_lastclose(drm_device_t *dev);
  726. /* Device support (drm_fops.h) */
  727. extern int drm_open(struct inode *inode, struct file *filp);
  728. extern int drm_stub_open(struct inode *inode, struct file *filp);
  729. extern int drm_fasync(int fd, struct file *filp, int on);
  730. extern int drm_release(struct inode *inode, struct file *filp);
  731. /* Mapping support (drm_vm.h) */
  732. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  733. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  734. /* Memory management support (drm_memory.h) */
  735. #include "drm_memory.h"
  736. extern void drm_mem_init(void);
  737. extern int drm_mem_info(char *buf, char **start, off_t offset,
  738. int request, int *eof, void *data);
  739. extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
  740. extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
  741. extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
  742. extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
  743. extern int drm_unbind_agp(DRM_AGP_MEM * handle);
  744. /* Misc. IOCTL support (drm_ioctl.h) */
  745. extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
  746. unsigned int cmd, unsigned long arg);
  747. extern int drm_getunique(struct inode *inode, struct file *filp,
  748. unsigned int cmd, unsigned long arg);
  749. extern int drm_setunique(struct inode *inode, struct file *filp,
  750. unsigned int cmd, unsigned long arg);
  751. extern int drm_getmap(struct inode *inode, struct file *filp,
  752. unsigned int cmd, unsigned long arg);
  753. extern int drm_getclient(struct inode *inode, struct file *filp,
  754. unsigned int cmd, unsigned long arg);
  755. extern int drm_getstats(struct inode *inode, struct file *filp,
  756. unsigned int cmd, unsigned long arg);
  757. extern int drm_setversion(struct inode *inode, struct file *filp,
  758. unsigned int cmd, unsigned long arg);
  759. extern int drm_noop(struct inode *inode, struct file *filp,
  760. unsigned int cmd, unsigned long arg);
  761. /* Context IOCTL support (drm_context.h) */
  762. extern int drm_resctx(struct inode *inode, struct file *filp,
  763. unsigned int cmd, unsigned long arg);
  764. extern int drm_addctx(struct inode *inode, struct file *filp,
  765. unsigned int cmd, unsigned long arg);
  766. extern int drm_modctx(struct inode *inode, struct file *filp,
  767. unsigned int cmd, unsigned long arg);
  768. extern int drm_getctx(struct inode *inode, struct file *filp,
  769. unsigned int cmd, unsigned long arg);
  770. extern int drm_switchctx(struct inode *inode, struct file *filp,
  771. unsigned int cmd, unsigned long arg);
  772. extern int drm_newctx(struct inode *inode, struct file *filp,
  773. unsigned int cmd, unsigned long arg);
  774. extern int drm_rmctx(struct inode *inode, struct file *filp,
  775. unsigned int cmd, unsigned long arg);
  776. extern int drm_ctxbitmap_init(drm_device_t * dev);
  777. extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
  778. extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
  779. extern int drm_setsareactx(struct inode *inode, struct file *filp,
  780. unsigned int cmd, unsigned long arg);
  781. extern int drm_getsareactx(struct inode *inode, struct file *filp,
  782. unsigned int cmd, unsigned long arg);
  783. /* Drawable IOCTL support (drm_drawable.h) */
  784. extern int drm_adddraw(struct inode *inode, struct file *filp,
  785. unsigned int cmd, unsigned long arg);
  786. extern int drm_rmdraw(struct inode *inode, struct file *filp,
  787. unsigned int cmd, unsigned long arg);
  788. extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
  789. unsigned int cmd, unsigned long arg);
  790. extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
  791. drm_drawable_t id);
  792. /* Authentication IOCTL support (drm_auth.h) */
  793. extern int drm_getmagic(struct inode *inode, struct file *filp,
  794. unsigned int cmd, unsigned long arg);
  795. extern int drm_authmagic(struct inode *inode, struct file *filp,
  796. unsigned int cmd, unsigned long arg);
  797. /* Locking IOCTL support (drm_lock.h) */
  798. extern int drm_lock(struct inode *inode, struct file *filp,
  799. unsigned int cmd, unsigned long arg);
  800. extern int drm_unlock(struct inode *inode, struct file *filp,
  801. unsigned int cmd, unsigned long arg);
  802. extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
  803. extern int drm_lock_free(drm_device_t * dev,
  804. __volatile__ unsigned int *lock, unsigned int context);
  805. /* Buffer management support (drm_bufs.h) */
  806. extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
  807. extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
  808. extern int drm_addmap(drm_device_t * dev, unsigned int offset,
  809. unsigned int size, drm_map_type_t type,
  810. drm_map_flags_t flags, drm_local_map_t ** map_ptr);
  811. extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
  812. unsigned int cmd, unsigned long arg);
  813. extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
  814. extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
  815. extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
  816. unsigned int cmd, unsigned long arg);
  817. extern int drm_order(unsigned long size);
  818. extern int drm_addbufs(struct inode *inode, struct file *filp,
  819. unsigned int cmd, unsigned long arg);
  820. extern int drm_infobufs(struct inode *inode, struct file *filp,
  821. unsigned int cmd, unsigned long arg);
  822. extern int drm_markbufs(struct inode *inode, struct file *filp,
  823. unsigned int cmd, unsigned long arg);
  824. extern int drm_freebufs(struct inode *inode, struct file *filp,
  825. unsigned int cmd, unsigned long arg);
  826. extern int drm_mapbufs(struct inode *inode, struct file *filp,
  827. unsigned int cmd, unsigned long arg);
  828. extern unsigned long drm_get_resource_start(drm_device_t * dev,
  829. unsigned int resource);
  830. extern unsigned long drm_get_resource_len(drm_device_t * dev,
  831. unsigned int resource);
  832. /* DMA support (drm_dma.h) */
  833. extern int drm_dma_setup(drm_device_t * dev);
  834. extern void drm_dma_takedown(drm_device_t * dev);
  835. extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
  836. extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
  837. /* IRQ support (drm_irq.h) */
  838. extern int drm_control(struct inode *inode, struct file *filp,
  839. unsigned int cmd, unsigned long arg);
  840. extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
  841. extern int drm_irq_uninstall(drm_device_t * dev);
  842. extern void drm_driver_irq_preinstall(drm_device_t * dev);
  843. extern void drm_driver_irq_postinstall(drm_device_t * dev);
  844. extern void drm_driver_irq_uninstall(drm_device_t * dev);
  845. extern int drm_wait_vblank(struct inode *inode, struct file *filp,
  846. unsigned int cmd, unsigned long arg);
  847. extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
  848. extern void drm_vbl_send_signals(drm_device_t * dev);
  849. extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));
  850. /* AGP/GART support (drm_agpsupport.h) */
  851. extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
  852. extern int drm_agp_acquire(drm_device_t * dev);
  853. extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
  854. unsigned int cmd, unsigned long arg);
  855. extern int drm_agp_release(drm_device_t * dev);
  856. extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
  857. unsigned int cmd, unsigned long arg);
  858. extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
  859. extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
  860. unsigned int cmd, unsigned long arg);
  861. extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
  862. extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
  863. unsigned int cmd, unsigned long arg);
  864. extern int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
  865. extern int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
  866. unsigned int cmd, unsigned long arg);
  867. extern int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
  868. extern int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
  869. unsigned int cmd, unsigned long arg);
  870. extern int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
  871. extern int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
  872. unsigned int cmd, unsigned long arg);
  873. extern int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
  874. extern int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
  875. unsigned int cmd, unsigned long arg);
  876. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
  877. size_t pages, u32 type);
  878. extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
  879. extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
  880. extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
  881. /* Stub support (drm_stub.h) */
  882. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  883. struct drm_driver *driver);
  884. extern int drm_put_dev(drm_device_t * dev);
  885. extern int drm_put_head(drm_head_t * head);
  886. extern unsigned int drm_debug;
  887. extern unsigned int drm_cards_limit;
  888. extern drm_head_t **drm_heads;
  889. extern struct class *drm_class;
  890. extern struct proc_dir_entry *drm_proc_root;
  891. /* Proc support (drm_proc.h) */
  892. extern int drm_proc_init(drm_device_t * dev,
  893. int minor,
  894. struct proc_dir_entry *root,
  895. struct proc_dir_entry **dev_root);
  896. extern int drm_proc_cleanup(int minor,
  897. struct proc_dir_entry *root,
  898. struct proc_dir_entry *dev_root);
  899. /* Scatter Gather Support (drm_scatter.h) */
  900. extern void drm_sg_cleanup(drm_sg_mem_t * entry);
  901. extern int drm_sg_alloc(struct inode *inode, struct file *filp,
  902. unsigned int cmd, unsigned long arg);
  903. extern int drm_sg_free(struct inode *inode, struct file *filp,
  904. unsigned int cmd, unsigned long arg);
  905. /* ATI PCIGART support (ati_pcigart.h) */
  906. extern int drm_ati_pcigart_init(drm_device_t * dev,
  907. drm_ati_pcigart_info * gart_info);
  908. extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
  909. drm_ati_pcigart_info * gart_info);
  910. extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
  911. size_t align, dma_addr_t maxaddr);
  912. extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
  913. extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
  914. /* sysfs support (drm_sysfs.c) */
  915. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  916. extern void drm_sysfs_destroy(struct class *cs);
  917. extern struct class_device *drm_sysfs_device_add(struct class *cs,
  918. drm_head_t *head);
  919. extern void drm_sysfs_device_remove(struct class_device *class_dev);
  920. /*
  921. * Basic memory manager support (drm_mm.c)
  922. */
  923. extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
  924. unsigned long size,
  925. unsigned alignment);
  926. void drm_mm_put_block(drm_mm_node_t * cur);
  927. extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
  928. unsigned alignment, int best_match);
  929. extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
  930. extern void drm_mm_takedown(drm_mm_t *mm);
  931. extern int drm_mm_clean(drm_mm_t *mm);
  932. extern unsigned long drm_mm_tail_space(drm_mm_t *mm);
  933. extern int drm_mm_remove_space_from_tail(drm_mm_t *mm, unsigned long size);
  934. extern int drm_mm_add_space_to_tail(drm_mm_t *mm, unsigned long size);
  935. extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
  936. extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
  937. static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
  938. unsigned int token)
  939. {
  940. drm_map_list_t *_entry;
  941. list_for_each_entry(_entry, &dev->maplist->head, head)
  942. if (_entry->user_token == token)
  943. return _entry->map;
  944. return NULL;
  945. }
  946. static __inline__ int drm_device_is_agp(drm_device_t * dev)
  947. {
  948. if (dev->driver->device_is_agp != NULL) {
  949. int err = (*dev->driver->device_is_agp) (dev);
  950. if (err != 2) {
  951. return err;
  952. }
  953. }
  954. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  955. }
  956. static __inline__ int drm_device_is_pcie(drm_device_t * dev)
  957. {
  958. return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  959. }
  960. static __inline__ void drm_core_dropmap(struct drm_map *map)
  961. {
  962. }
  963. #ifndef DEBUG_MEMORY
  964. /** Wrapper around kmalloc() */
  965. static __inline__ void *drm_alloc(size_t size, int area)
  966. {
  967. return kmalloc(size, GFP_KERNEL);
  968. }
  969. /** Wrapper around kfree() */
  970. static __inline__ void drm_free(void *pt, size_t size, int area)
  971. {
  972. kfree(pt);
  973. }
  974. /** Wrapper around kcalloc() */
  975. static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
  976. {
  977. return kcalloc(nmemb, size, GFP_KERNEL);
  978. }
  979. #else
  980. extern void *drm_alloc(size_t size, int area);
  981. extern void drm_free(void *pt, size_t size, int area);
  982. extern void *drm_calloc(size_t nmemb, size_t size, int area);
  983. #endif
  984. /*@}*/
  985. extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
  986. extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
  987. #endif /* __KERNEL__ */
  988. #endif