drmP.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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. void *private;
  473. } drm_mm_node_t;
  474. typedef struct drm_mm {
  475. drm_mm_node_t root_node;
  476. } drm_mm_t;
  477. /**
  478. * DRM driver structure. This structure represent the common code for
  479. * a family of cards. There will one drm_device for each card present
  480. * in this family
  481. */
  482. struct drm_device;
  483. struct drm_driver {
  484. int (*load) (struct drm_device *, unsigned long flags);
  485. int (*firstopen) (struct drm_device *);
  486. int (*open) (struct drm_device *, drm_file_t *);
  487. void (*preclose) (struct drm_device *, struct file * filp);
  488. void (*postclose) (struct drm_device *, drm_file_t *);
  489. void (*lastclose) (struct drm_device *);
  490. int (*unload) (struct drm_device *);
  491. int (*dma_ioctl) (DRM_IOCTL_ARGS);
  492. void (*dma_ready) (struct drm_device *);
  493. int (*dma_quiescent) (struct drm_device *);
  494. int (*context_ctor) (struct drm_device * dev, int context);
  495. int (*context_dtor) (struct drm_device * dev, int context);
  496. int (*kernel_context_switch) (struct drm_device * dev, int old,
  497. int new);
  498. void (*kernel_context_switch_unlock) (struct drm_device * dev);
  499. int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
  500. int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
  501. int (*dri_library_name) (struct drm_device *dev, char *buf);
  502. /**
  503. * Called by \c drm_device_is_agp. Typically used to determine if a
  504. * card is really attached to AGP or not.
  505. *
  506. * \param dev DRM device handle
  507. *
  508. * \returns
  509. * One of three values is returned depending on whether or not the
  510. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  511. * (return of 1), or may or may not be AGP (return of 2).
  512. */
  513. int (*device_is_agp) (struct drm_device * dev);
  514. /* these have to be filled in */
  515. irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  516. void (*irq_preinstall) (struct drm_device * dev);
  517. void (*irq_postinstall) (struct drm_device * dev);
  518. void (*irq_uninstall) (struct drm_device * dev);
  519. void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
  520. void (*reclaim_buffers_locked) (struct drm_device *dev,
  521. struct file *filp);
  522. unsigned long (*get_map_ofs) (drm_map_t * map);
  523. unsigned long (*get_reg_ofs) (struct drm_device * dev);
  524. void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
  525. int major;
  526. int minor;
  527. int patchlevel;
  528. char *name;
  529. char *desc;
  530. char *date;
  531. u32 driver_features;
  532. int dev_priv_size;
  533. drm_ioctl_desc_t *ioctls;
  534. int num_ioctls;
  535. struct file_operations fops;
  536. struct pci_driver pci_driver;
  537. };
  538. /**
  539. * DRM head structure. This structure represent a video head on a card
  540. * that may contain multiple heads. Embed one per head of these in the
  541. * private drm_device structure.
  542. */
  543. typedef struct drm_head {
  544. int minor; /**< Minor device number */
  545. struct drm_device *dev;
  546. struct proc_dir_entry *dev_root; /**< proc directory entry */
  547. dev_t device; /**< Device number for mknod */
  548. struct class_device *dev_class;
  549. } drm_head_t;
  550. /**
  551. * DRM device structure. This structure represent a complete card that
  552. * may contain multiple heads.
  553. */
  554. typedef struct drm_device {
  555. char *unique; /**< Unique identifier: e.g., busid */
  556. int unique_len; /**< Length of unique field */
  557. char *devname; /**< For /proc/interrupts */
  558. int if_version; /**< Highest interface version set */
  559. int blocked; /**< Blocked due to VC switch? */
  560. /** \name Locks */
  561. /*@{ */
  562. spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
  563. struct mutex struct_mutex; /**< For others */
  564. /*@} */
  565. /** \name Usage Counters */
  566. /*@{ */
  567. int open_count; /**< Outstanding files open */
  568. atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
  569. atomic_t vma_count; /**< Outstanding vma areas open */
  570. int buf_use; /**< Buffers in use -- cannot alloc */
  571. atomic_t buf_alloc; /**< Buffer allocation in progress */
  572. /*@} */
  573. /** \name Performance counters */
  574. /*@{ */
  575. unsigned long counters;
  576. drm_stat_type_t types[15];
  577. atomic_t counts[15];
  578. /*@} */
  579. /** \name Authentication */
  580. /*@{ */
  581. drm_file_t *file_first; /**< file list head */
  582. drm_file_t *file_last; /**< file list tail */
  583. drm_open_hash_t magiclist; /**< magic hash table */
  584. struct list_head magicfree;
  585. /*@} */
  586. /** \name Memory management */
  587. /*@{ */
  588. drm_map_list_t *maplist; /**< Linked list of regions */
  589. int map_count; /**< Number of mappable regions */
  590. drm_open_hash_t map_hash; /**< User token hash table for maps */
  591. /** \name Context handle management */
  592. /*@{ */
  593. drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
  594. int ctx_count; /**< Number of context handles */
  595. struct mutex ctxlist_mutex; /**< For ctxlist */
  596. drm_map_t **context_sareas; /**< per-context SAREA's */
  597. int max_context;
  598. drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
  599. drm_lock_data_t lock; /**< Information on hardware lock */
  600. /*@} */
  601. /** \name DMA queues (contexts) */
  602. /*@{ */
  603. int queue_count; /**< Number of active DMA queues */
  604. int queue_reserved; /**< Number of reserved DMA queues */
  605. int queue_slots; /**< Actual length of queuelist */
  606. drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
  607. drm_device_dma_t *dma; /**< Optional pointer for DMA support */
  608. /*@} */
  609. /** \name Context support */
  610. /*@{ */
  611. int irq; /**< Interrupt used by board */
  612. int irq_enabled; /**< True if irq handler is enabled */
  613. __volatile__ long context_flag; /**< Context swapping flag */
  614. __volatile__ long interrupt_flag; /**< Interruption handler flag */
  615. __volatile__ long dma_flag; /**< DMA dispatch flag */
  616. struct timer_list timer; /**< Timer for delaying ctx switch */
  617. wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
  618. int last_checked; /**< Last context checked for DMA */
  619. int last_context; /**< Last current context */
  620. unsigned long last_switch; /**< jiffies at last context switch */
  621. /*@} */
  622. struct work_struct work;
  623. /** \name VBLANK IRQ support */
  624. /*@{ */
  625. wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
  626. atomic_t vbl_received;
  627. atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
  628. spinlock_t vbl_lock;
  629. drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
  630. drm_vbl_sig_t vbl_sigs2; /**< signals to send on secondary VBLANK */
  631. unsigned int vbl_pending;
  632. spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
  633. void (*locked_tasklet_func)(struct drm_device *dev);
  634. /*@} */
  635. cycles_t ctx_start;
  636. cycles_t lck_start;
  637. struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  638. wait_queue_head_t buf_readers; /**< Processes waiting to read */
  639. wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
  640. drm_agp_head_t *agp; /**< AGP data */
  641. struct pci_dev *pdev; /**< PCI device structure */
  642. int pci_vendor; /**< PCI vendor id */
  643. int pci_device; /**< PCI device id */
  644. #ifdef __alpha__
  645. struct pci_controller *hose;
  646. #endif
  647. drm_sg_mem_t *sg; /**< Scatter gather memory */
  648. unsigned long *ctx_bitmap; /**< context bitmap */
  649. void *dev_private; /**< device private data */
  650. drm_sigdata_t sigdata; /**< For block_all_signals */
  651. sigset_t sigmask;
  652. struct drm_driver *driver;
  653. drm_local_map_t *agp_buffer_map;
  654. unsigned int agp_buffer_token;
  655. drm_head_t primary; /**< primary screen head */
  656. /** \name Drawable information */
  657. /*@{ */
  658. spinlock_t drw_lock;
  659. unsigned int drw_bitfield_length;
  660. u32 *drw_bitfield;
  661. unsigned int drw_info_length;
  662. drm_drawable_info_t **drw_info;
  663. /*@} */
  664. } drm_device_t;
  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->bus->number
  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(drm_device_t *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 void *drm_ioremap(unsigned long offset, unsigned long size,
  739. drm_device_t * dev);
  740. extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev);
  741. extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
  742. extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
  743. extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
  744. extern int drm_unbind_agp(DRM_AGP_MEM * handle);
  745. /* Misc. IOCTL support (drm_ioctl.h) */
  746. extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
  747. unsigned int cmd, unsigned long arg);
  748. extern int drm_getunique(struct inode *inode, struct file *filp,
  749. unsigned int cmd, unsigned long arg);
  750. extern int drm_setunique(struct inode *inode, struct file *filp,
  751. unsigned int cmd, unsigned long arg);
  752. extern int drm_getmap(struct inode *inode, struct file *filp,
  753. unsigned int cmd, unsigned long arg);
  754. extern int drm_getclient(struct inode *inode, struct file *filp,
  755. unsigned int cmd, unsigned long arg);
  756. extern int drm_getstats(struct inode *inode, struct file *filp,
  757. unsigned int cmd, unsigned long arg);
  758. extern int drm_setversion(struct inode *inode, struct file *filp,
  759. unsigned int cmd, unsigned long arg);
  760. extern int drm_noop(struct inode *inode, struct file *filp,
  761. unsigned int cmd, unsigned long arg);
  762. /* Context IOCTL support (drm_context.h) */
  763. extern int drm_resctx(struct inode *inode, struct file *filp,
  764. unsigned int cmd, unsigned long arg);
  765. extern int drm_addctx(struct inode *inode, struct file *filp,
  766. unsigned int cmd, unsigned long arg);
  767. extern int drm_modctx(struct inode *inode, struct file *filp,
  768. unsigned int cmd, unsigned long arg);
  769. extern int drm_getctx(struct inode *inode, struct file *filp,
  770. unsigned int cmd, unsigned long arg);
  771. extern int drm_switchctx(struct inode *inode, struct file *filp,
  772. unsigned int cmd, unsigned long arg);
  773. extern int drm_newctx(struct inode *inode, struct file *filp,
  774. unsigned int cmd, unsigned long arg);
  775. extern int drm_rmctx(struct inode *inode, struct file *filp,
  776. unsigned int cmd, unsigned long arg);
  777. extern int drm_ctxbitmap_init(drm_device_t * dev);
  778. extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
  779. extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
  780. extern int drm_setsareactx(struct inode *inode, struct file *filp,
  781. unsigned int cmd, unsigned long arg);
  782. extern int drm_getsareactx(struct inode *inode, struct file *filp,
  783. unsigned int cmd, unsigned long arg);
  784. /* Drawable IOCTL support (drm_drawable.h) */
  785. extern int drm_adddraw(struct inode *inode, struct file *filp,
  786. unsigned int cmd, unsigned long arg);
  787. extern int drm_rmdraw(struct inode *inode, struct file *filp,
  788. unsigned int cmd, unsigned long arg);
  789. extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
  790. unsigned int cmd, unsigned long arg);
  791. extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
  792. drm_drawable_t id);
  793. /* Authentication IOCTL support (drm_auth.h) */
  794. extern int drm_getmagic(struct inode *inode, struct file *filp,
  795. unsigned int cmd, unsigned long arg);
  796. extern int drm_authmagic(struct inode *inode, struct file *filp,
  797. unsigned int cmd, unsigned long arg);
  798. /* Locking IOCTL support (drm_lock.h) */
  799. extern int drm_lock(struct inode *inode, struct file *filp,
  800. unsigned int cmd, unsigned long arg);
  801. extern int drm_unlock(struct inode *inode, struct file *filp,
  802. unsigned int cmd, unsigned long arg);
  803. extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
  804. extern int drm_lock_free(drm_device_t * dev,
  805. __volatile__ unsigned int *lock, unsigned int context);
  806. /* Buffer management support (drm_bufs.h) */
  807. extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
  808. extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
  809. extern int drm_addmap(drm_device_t * dev, unsigned int offset,
  810. unsigned int size, drm_map_type_t type,
  811. drm_map_flags_t flags, drm_local_map_t ** map_ptr);
  812. extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
  813. unsigned int cmd, unsigned long arg);
  814. extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
  815. extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
  816. extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
  817. unsigned int cmd, unsigned long arg);
  818. extern int drm_order(unsigned long size);
  819. extern int drm_addbufs(struct inode *inode, struct file *filp,
  820. unsigned int cmd, unsigned long arg);
  821. extern int drm_infobufs(struct inode *inode, struct file *filp,
  822. unsigned int cmd, unsigned long arg);
  823. extern int drm_markbufs(struct inode *inode, struct file *filp,
  824. unsigned int cmd, unsigned long arg);
  825. extern int drm_freebufs(struct inode *inode, struct file *filp,
  826. unsigned int cmd, unsigned long arg);
  827. extern int drm_mapbufs(struct inode *inode, struct file *filp,
  828. unsigned int cmd, unsigned long arg);
  829. extern unsigned long drm_get_resource_start(drm_device_t * dev,
  830. unsigned int resource);
  831. extern unsigned long drm_get_resource_len(drm_device_t * dev,
  832. unsigned int resource);
  833. /* DMA support (drm_dma.h) */
  834. extern int drm_dma_setup(drm_device_t * dev);
  835. extern void drm_dma_takedown(drm_device_t * dev);
  836. extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
  837. extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
  838. /* IRQ support (drm_irq.h) */
  839. extern int drm_control(struct inode *inode, struct file *filp,
  840. unsigned int cmd, unsigned long arg);
  841. extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
  842. extern int drm_irq_uninstall(drm_device_t * dev);
  843. extern void drm_driver_irq_preinstall(drm_device_t * dev);
  844. extern void drm_driver_irq_postinstall(drm_device_t * dev);
  845. extern void drm_driver_irq_uninstall(drm_device_t * dev);
  846. extern int drm_wait_vblank(struct inode *inode, struct file *filp,
  847. unsigned int cmd, unsigned long arg);
  848. extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
  849. extern void drm_vbl_send_signals(drm_device_t * dev);
  850. extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));
  851. /* AGP/GART support (drm_agpsupport.h) */
  852. extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
  853. extern int drm_agp_acquire(drm_device_t * dev);
  854. extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
  855. unsigned int cmd, unsigned long arg);
  856. extern int drm_agp_release(drm_device_t * dev);
  857. extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
  858. unsigned int cmd, unsigned long arg);
  859. extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
  860. extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
  861. unsigned int cmd, unsigned long arg);
  862. extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
  863. extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
  864. unsigned int cmd, unsigned long arg);
  865. extern int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
  866. extern int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
  867. unsigned int cmd, unsigned long arg);
  868. extern int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
  869. extern int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
  870. unsigned int cmd, unsigned long arg);
  871. extern int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
  872. extern int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
  873. unsigned int cmd, unsigned long arg);
  874. extern int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
  875. extern int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
  876. unsigned int cmd, unsigned long arg);
  877. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
  878. size_t pages, u32 type);
  879. extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
  880. extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
  881. extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
  882. /* Stub support (drm_stub.h) */
  883. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  884. struct drm_driver *driver);
  885. extern int drm_put_dev(drm_device_t * dev);
  886. extern int drm_put_head(drm_head_t * head);
  887. extern unsigned int drm_debug;
  888. extern unsigned int drm_cards_limit;
  889. extern drm_head_t **drm_heads;
  890. extern struct class *drm_class;
  891. extern struct proc_dir_entry *drm_proc_root;
  892. /* Proc support (drm_proc.h) */
  893. extern int drm_proc_init(drm_device_t * dev,
  894. int minor,
  895. struct proc_dir_entry *root,
  896. struct proc_dir_entry **dev_root);
  897. extern int drm_proc_cleanup(int minor,
  898. struct proc_dir_entry *root,
  899. struct proc_dir_entry *dev_root);
  900. /* Scatter Gather Support (drm_scatter.h) */
  901. extern void drm_sg_cleanup(drm_sg_mem_t * entry);
  902. extern int drm_sg_alloc(struct inode *inode, struct file *filp,
  903. unsigned int cmd, unsigned long arg);
  904. extern int drm_sg_free(struct inode *inode, struct file *filp,
  905. unsigned int cmd, unsigned long arg);
  906. /* ATI PCIGART support (ati_pcigart.h) */
  907. extern int drm_ati_pcigart_init(drm_device_t * dev,
  908. drm_ati_pcigart_info * gart_info);
  909. extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
  910. drm_ati_pcigart_info * gart_info);
  911. extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
  912. size_t align, dma_addr_t maxaddr);
  913. extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
  914. extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
  915. /* sysfs support (drm_sysfs.c) */
  916. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  917. extern void drm_sysfs_destroy(struct class *cs);
  918. extern struct class_device *drm_sysfs_device_add(struct class *cs,
  919. drm_head_t *head);
  920. extern void drm_sysfs_device_remove(struct class_device *class_dev);
  921. /*
  922. * Basic memory manager support (drm_mm.c)
  923. */
  924. extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
  925. unsigned long size,
  926. unsigned alignment);
  927. extern void drm_mm_put_block(drm_mm_t *mm, drm_mm_node_t *cur);
  928. extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
  929. unsigned alignment, int best_match);
  930. extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
  931. extern void drm_mm_takedown(drm_mm_t *mm);
  932. /* Inline replacements for DRM_IOREMAP macros */
  933. static __inline__ void drm_core_ioremap(struct drm_map *map,
  934. struct drm_device *dev)
  935. {
  936. map->handle = drm_ioremap(map->offset, map->size, dev);
  937. }
  938. #if 0
  939. static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
  940. struct drm_device *dev)
  941. {
  942. map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
  943. }
  944. #endif /* 0 */
  945. static __inline__ void drm_core_ioremapfree(struct drm_map *map,
  946. struct drm_device *dev)
  947. {
  948. if (map->handle && map->size)
  949. drm_ioremapfree(map->handle, map->size, dev);
  950. }
  951. static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
  952. unsigned int token)
  953. {
  954. drm_map_list_t *_entry;
  955. list_for_each_entry(_entry, &dev->maplist->head, head)
  956. if (_entry->user_token == token)
  957. return _entry->map;
  958. return NULL;
  959. }
  960. static __inline__ int drm_device_is_agp(drm_device_t * dev)
  961. {
  962. if (dev->driver->device_is_agp != NULL) {
  963. int err = (*dev->driver->device_is_agp) (dev);
  964. if (err != 2) {
  965. return err;
  966. }
  967. }
  968. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  969. }
  970. static __inline__ int drm_device_is_pcie(drm_device_t * dev)
  971. {
  972. return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  973. }
  974. static __inline__ void drm_core_dropmap(struct drm_map *map)
  975. {
  976. }
  977. #ifndef DEBUG_MEMORY
  978. /** Wrapper around kmalloc() */
  979. static __inline__ void *drm_alloc(size_t size, int area)
  980. {
  981. return kmalloc(size, GFP_KERNEL);
  982. }
  983. /** Wrapper around kfree() */
  984. static __inline__ void drm_free(void *pt, size_t size, int area)
  985. {
  986. kfree(pt);
  987. }
  988. /** Wrapper around kcalloc() */
  989. static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
  990. {
  991. return kcalloc(nmemb, size, GFP_KERNEL);
  992. }
  993. #else
  994. extern void *drm_alloc(size_t size, int area);
  995. extern void drm_free(void *pt, size_t size, int area);
  996. extern void *drm_calloc(size_t nmemb, size_t size, int area);
  997. #endif
  998. /*@}*/
  999. extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
  1000. extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
  1001. #endif /* __KERNEL__ */
  1002. #endif