drmP.h 37 KB

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