drmP.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:33k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
  2.  * Created: Mon Jan  4 10:05:05 1999 by faith@precisioninsight.com
  3.  *
  4.  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5.  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted, free of charge, to any person obtaining a
  9.  * copy of this software and associated documentation files (the "Software"),
  10.  * to deal in the Software without restriction, including without limitation
  11.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12.  * and/or sell copies of the Software, and to permit persons to whom the
  13.  * Software is furnished to do so, subject to the following conditions:
  14.  *
  15.  * The above copyright notice and this permission notice (including the next
  16.  * paragraph) shall be included in all copies or substantial portions of the
  17.  * Software.
  18.  *
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25.  * OTHER DEALINGS IN THE SOFTWARE.
  26.  *
  27.  * Authors:
  28.  *    Rickard E. (Rik) Faith <faith@valinux.com>
  29.  *    Gareth Hughes <gareth@valinux.com>
  30.  */
  31. #ifndef _DRM_P_H_
  32. #define _DRM_P_H_
  33. #ifdef __KERNEL__
  34. #ifdef __alpha__
  35. /* add include of current.h so that "current" is defined
  36.  * before static inline funcs in wait.h. Doing this so we
  37.  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  38. #include <asm/current.h>
  39. #endif /* __alpha__ */
  40. #include <linux/config.h>
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/miscdevice.h>
  44. #include <linux/fs.h>
  45. #include <linux/proc_fs.h>
  46. #include <linux/init.h>
  47. #include <linux/file.h>
  48. #include <linux/pci.h>
  49. #include <linux/wrapper.h>
  50. #include <linux/version.h>
  51. #include <linux/sched.h>
  52. #include <linux/smp_lock.h> /* For (un)lock_kernel */
  53. #include <linux/mm.h>
  54. #if defined(__alpha__) || defined(__powerpc__)
  55. #include <asm/pgtable.h> /* For pte_wrprotect */
  56. #endif
  57. #include <asm/io.h>
  58. #include <asm/mman.h>
  59. #include <asm/uaccess.h>
  60. #ifdef CONFIG_MTRR
  61. #include <asm/mtrr.h>
  62. #endif
  63. #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
  64. #include <linux/types.h>
  65. #include <linux/agp_backend.h>
  66. #endif
  67. #include <linux/tqueue.h>
  68. #include <linux/poll.h>
  69. #include <asm/pgalloc.h>
  70. #include "drm.h"
  71. /* page_to_bus for earlier kernels, not optimal in all cases */
  72. #ifndef page_to_bus
  73. #define page_to_bus(page) ((unsigned int)(virt_to_bus(page_address(page))))
  74. #endif
  75. /* DRM template customization defaults
  76.  */
  77. #ifndef __HAVE_AGP
  78. #define __HAVE_AGP 0
  79. #endif
  80. #ifndef __HAVE_MTRR
  81. #define __HAVE_MTRR 0
  82. #endif
  83. #ifndef __HAVE_CTX_BITMAP
  84. #define __HAVE_CTX_BITMAP 0
  85. #endif
  86. #ifndef __HAVE_DMA
  87. #define __HAVE_DMA 0
  88. #endif
  89. #ifndef __HAVE_DMA_IRQ
  90. #define __HAVE_DMA_IRQ 0
  91. #endif
  92. #ifndef __HAVE_DMA_WAITLIST
  93. #define __HAVE_DMA_WAITLIST 0
  94. #endif
  95. #ifndef __HAVE_DMA_FREELIST
  96. #define __HAVE_DMA_FREELIST 0
  97. #endif
  98. #ifndef __HAVE_DMA_HISTOGRAM
  99. #define __HAVE_DMA_HISTOGRAM 0
  100. #endif
  101. #define __REALLY_HAVE_AGP (__HAVE_AGP && (defined(CONFIG_AGP) || 
  102. defined(CONFIG_AGP_MODULE)))
  103. #define __REALLY_HAVE_MTRR (__HAVE_MTRR && defined(CONFIG_MTRR))
  104. /* Generic cmpxchg added in 2.3.x */
  105. #ifndef __HAVE_ARCH_CMPXCHG
  106. /* Include this here so that driver can be
  107.                                    used with older kernels. */
  108. #if defined(__alpha__)
  109. static __inline__ unsigned long
  110. __cmpxchg_u32(volatile int *m, int old, int new)
  111. {
  112. unsigned long prev, cmp;
  113. __asm__ __volatile__(
  114. "1: ldl_l %0,%2n"
  115. " cmpeq %0,%3,%1n"
  116. " beq %1,2fn"
  117. " mov %4,%1n"
  118. " stl_c %1,%2n"
  119. " beq %1,3fn"
  120. "2: mbn"
  121. ".subsection 2n"
  122. "3: br 1bn"
  123. ".previous"
  124. : "=&r"(prev), "=&r"(cmp), "=m"(*m)
  125. : "r"((long) old), "r"(new), "m"(*m));
  126. return prev;
  127. }
  128. static __inline__ unsigned long
  129. __cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
  130. {
  131. unsigned long prev, cmp;
  132. __asm__ __volatile__(
  133. "1: ldq_l %0,%2n"
  134. " cmpeq %0,%3,%1n"
  135. " beq %1,2fn"
  136. " mov %4,%1n"
  137. " stq_c %1,%2n"
  138. " beq %1,3fn"
  139. "2: mbn"
  140. ".subsection 2n"
  141. "3: br 1bn"
  142. ".previous"
  143. : "=&r"(prev), "=&r"(cmp), "=m"(*m)
  144. : "r"((long) old), "r"(new), "m"(*m));
  145. return prev;
  146. }
  147. static __inline__ unsigned long
  148. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  149. {
  150. switch (size) {
  151. case 4:
  152. return __cmpxchg_u32(ptr, old, new);
  153. case 8:
  154. return __cmpxchg_u64(ptr, old, new);
  155. }
  156. return old;
  157. }
  158. #define cmpxchg(ptr,o,n)  
  159.   ({  
  160.      __typeof__(*(ptr)) _o_ = (o);  
  161.      __typeof__(*(ptr)) _n_ = (n);  
  162.      (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,  
  163.     (unsigned long)_n_, sizeof(*(ptr))); 
  164.   })
  165. #elif __i386__
  166. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  167.       unsigned long new, int size)
  168. {
  169. unsigned long prev;
  170. switch (size) {
  171. case 1:
  172. __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
  173.      : "=a"(prev)
  174.      : "q"(new), "m"(*__xg(ptr)), "0"(old)
  175.      : "memory");
  176. return prev;
  177. case 2:
  178. __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
  179.      : "=a"(prev)
  180.      : "q"(new), "m"(*__xg(ptr)), "0"(old)
  181.      : "memory");
  182. return prev;
  183. case 4:
  184. __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
  185.      : "=a"(prev)
  186.      : "q"(new), "m"(*__xg(ptr)), "0"(old)
  187.      : "memory");
  188. return prev;
  189. }
  190. return old;
  191. }
  192. #define cmpxchg(ptr,o,n)
  193.   ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),
  194.  (unsigned long)(n),sizeof(*(ptr))))
  195. #endif /* i386 & alpha */
  196. #endif
  197. /* Begin the DRM...
  198.  */
  199. #define DRM_DEBUG_CODE 2   /* Include debugging code (if > 1, then
  200.      also include looping detection. */
  201. #define DRM_HASH_SIZE       16 /* Size of key hash table   */
  202. #define DRM_KERNEL_CONTEXT    0  /* Change drm_resctx if changed   */
  203. #define DRM_RESERVED_CONTEXTS 1  /* Change drm_resctx if changed   */
  204. #define DRM_LOOPING_LIMIT     5000000
  205. #define DRM_BSZ       1024 /* Buffer size for /dev/drm? output   */
  206. #define DRM_TIME_SLICE       (HZ/20)  /* Time slice for GLXContexts   */
  207. #define DRM_LOCK_SLICE       1 /* Time slice for lock, in jiffies   */
  208. #define DRM_FLAG_DEBUG   0x01
  209. #define DRM_FLAG_NOCTX   0x02
  210. #define DRM_MEM_DMA    0
  211. #define DRM_MEM_SAREA    1
  212. #define DRM_MEM_DRIVER    2
  213. #define DRM_MEM_MAGIC    3
  214. #define DRM_MEM_IOCTLS    4
  215. #define DRM_MEM_MAPS    5
  216. #define DRM_MEM_VMAS    6
  217. #define DRM_MEM_BUFS    7
  218. #define DRM_MEM_SEGS    8
  219. #define DRM_MEM_PAGES    9
  220. #define DRM_MEM_FILES   10
  221. #define DRM_MEM_QUEUES   11
  222. #define DRM_MEM_CMDS   12
  223. #define DRM_MEM_MAPPINGS  13
  224. #define DRM_MEM_BUFLISTS  14
  225. #define DRM_MEM_AGPLISTS  15
  226. #define DRM_MEM_TOTALAGP  16
  227. #define DRM_MEM_BOUNDAGP  17
  228. #define DRM_MEM_CTXBITMAP 18
  229. #define DRM_MEM_STUB      19
  230. #define DRM_MEM_SGLISTS   20
  231. #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
  232. #define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
  233. /* Macros to make printk easier */
  234. #if ( __GNUC__ > 2 )
  235. #define DRM_ERROR(fmt, arg...) 
  236. printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__, ##arg)
  237. #define DRM_MEM_ERROR(area, fmt, arg...) 
  238. printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, 
  239.        DRM(mem_stats)[area].name , ##arg)
  240. #define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
  241. #if DRM_DEBUG_CODE
  242. #define DRM_DEBUG(fmt, arg...)
  243. do {
  244. if ( DRM(flags) & DRM_FLAG_DEBUG )
  245. printk(KERN_DEBUG
  246.        "[" DRM_NAME ":%s] " fmt ,
  247.        __FUNCTION__,
  248.        ##arg);
  249. } while (0)
  250. #else
  251. #define DRM_DEBUG(fmt, arg...)  do { } while (0)
  252. #endif
  253. #else /* Gcc 2.x */
  254. /* Work around a C preprocessor bug */
  255. /* Macros to make printk easier */
  256. #define DRM_ERROR(fmt, arg...) 
  257. printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg)
  258. #define DRM_MEM_ERROR(area, fmt, arg...) 
  259. printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , 
  260.        DRM(mem_stats)[area].name , ##arg)
  261. #define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
  262. #if DRM_DEBUG_CODE
  263. #define DRM_DEBUG(fmt, arg...)
  264. do {
  265. if ( DRM(flags) & DRM_FLAG_DEBUG )
  266. printk(KERN_DEBUG
  267.        "[" DRM_NAME ":" __FUNCTION__ "] " fmt ,
  268.        ##arg);
  269. } while (0)
  270. #else
  271. #define DRM_DEBUG(fmt, arg...)  do { } while (0)
  272. #endif
  273. #endif /* Gcc 2.x */
  274. #define DRM_PROC_LIMIT (PAGE_SIZE-80)
  275. #define DRM_PROC_PRINT(fmt, arg...)
  276.    len += sprintf(&buf[len], fmt , ##arg);
  277.    if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
  278. #define DRM_PROC_PRINT_RET(ret, fmt, arg...)
  279.    len += sprintf(&buf[len], fmt , ##arg);
  280.    if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
  281. /* Mapping helper macros */
  282. #define DRM_IOREMAP(map)
  283. (map)->handle = DRM(ioremap)( (map)->offset, (map)->size )
  284. #define DRM_IOREMAPFREE(map)
  285. do {
  286. if ( (map)->handle && (map)->size )
  287. DRM(ioremapfree)( (map)->handle, (map)->size );
  288. } while (0)
  289. #define DRM_FIND_MAP(_map, _o)
  290. do {
  291. struct list_head *_list;
  292. list_for_each( _list, &dev->maplist->head ) {
  293. drm_map_list_t *_entry = (drm_map_list_t *)_list;
  294. if ( _entry->map &&
  295.      _entry->map->offset == (_o) ) {
  296. (_map) = _entry->map;
  297. break;
  298.   }
  299. }
  300. } while(0)
  301. /* Internal types and structures */
  302. #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
  303. #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
  304. #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
  305. #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
  306. #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
  307. #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
  308. #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {
  309. (_map) = (_dev)->context_sareas[_ctx];
  310. } while(0)
  311. typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
  312.  unsigned int cmd, unsigned long arg );
  313. typedef struct drm_pci_list {
  314. u16 vendor;
  315. u16 device;
  316. } drm_pci_list_t;
  317. typedef struct drm_ioctl_desc {
  318. drm_ioctl_t      *func;
  319. int      auth_needed;
  320. int      root_only;
  321. } drm_ioctl_desc_t;
  322. typedef struct drm_devstate {
  323. pid_t   owner; /* X server pid holding x_lock */
  324. } drm_devstate_t;
  325. typedef struct drm_magic_entry {
  326. drm_magic_t        magic;
  327. struct drm_file        *priv;
  328. struct drm_magic_entry *next;
  329. } drm_magic_entry_t;
  330. typedef struct drm_magic_head {
  331. struct drm_magic_entry *head;
  332. struct drm_magic_entry *tail;
  333. } drm_magic_head_t;
  334. typedef struct drm_vma_entry {
  335. struct vm_area_struct *vma;
  336. struct drm_vma_entry  *next;
  337. pid_t       pid;
  338. } drm_vma_entry_t;
  339. typedef struct drm_buf {
  340. int   idx;        /* Index into master buflist      */
  341. int   total;       /* Buffer size      */
  342. int   order;       /* log-base-2(total)      */
  343. int   used;        /* Amount of buffer in use (for DMA)  */
  344. unsigned long   offset;      /* Byte offset (used internally)      */
  345. void   *address;    /* Address of buffer      */
  346. unsigned long   bus_address; /* Bus address of buffer      */
  347. struct drm_buf   *next;       /* Kernel-only: used for free list    */
  348. __volatile__ int  waiting;     /* On kernel DMA queue      */
  349. __volatile__ int  pending;     /* On hardware DMA queue      */
  350. wait_queue_head_t dma_wait;    /* Processes waiting      */
  351. pid_t   pid;        /* PID of holding process      */
  352. int   context;     /* Kernel queue for this buffer      */
  353. int   while_locked;/* Dispatch this buffer while locked  */
  354. enum {
  355. DRM_LIST_NONE  = 0,
  356. DRM_LIST_FREE  = 1,
  357. DRM_LIST_WAIT  = 2,
  358. DRM_LIST_PEND  = 3,
  359. DRM_LIST_PRIO  = 4,
  360. DRM_LIST_RECLAIM = 5
  361. }   list;        /* Which list we're on      */
  362. #if DRM_DMA_HISTOGRAM
  363. cycles_t   time_queued;    /* Queued to kernel DMA queue     */
  364. cycles_t   time_dispatched; /* Dispatched to hardware      */
  365. cycles_t   time_completed;  /* Completed by hardware      */
  366. cycles_t   time_freed;    /* Back on freelist      */
  367. #endif
  368. int   dev_priv_size; /* Size of buffer private stoarge   */
  369. void   *dev_private;  /* Per-buffer private storage       */
  370. } drm_buf_t;
  371. #if DRM_DMA_HISTOGRAM
  372. #define DRM_DMA_HISTOGRAM_SLOTS   9
  373. #define DRM_DMA_HISTOGRAM_INITIAL  10
  374. #define DRM_DMA_HISTOGRAM_NEXT(current)  ((current)*10)
  375. typedef struct drm_histogram {
  376. atomic_t   total;
  377. atomic_t   queued_to_dispatched[DRM_DMA_HISTOGRAM_SLOTS];
  378. atomic_t   dispatched_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
  379. atomic_t   completed_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
  380. atomic_t   queued_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
  381. atomic_t   queued_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
  382. atomic_t   dma[DRM_DMA_HISTOGRAM_SLOTS];
  383. atomic_t   schedule[DRM_DMA_HISTOGRAM_SLOTS];
  384. atomic_t   ctx[DRM_DMA_HISTOGRAM_SLOTS];
  385. atomic_t   lacq[DRM_DMA_HISTOGRAM_SLOTS];
  386. atomic_t   lhld[DRM_DMA_HISTOGRAM_SLOTS];
  387. } drm_histogram_t;
  388. #endif
  389. /* bufs is one longer than it has to be */
  390. typedef struct drm_waitlist {
  391. int   count; /* Number of possible buffers    */
  392. drm_buf_t   **bufs; /* List of pointers to buffers    */
  393. drm_buf_t   **rp; /* Read pointer    */
  394. drm_buf_t   **wp; /* Write pointer    */
  395. drm_buf_t   **end; /* End pointer    */
  396. spinlock_t   read_lock;
  397. spinlock_t   write_lock;
  398. } drm_waitlist_t;
  399. typedef struct drm_freelist {
  400. int   initialized; /* Freelist in use    */
  401. atomic_t   count;       /* Number of free buffers    */
  402. drm_buf_t   *next;       /* End pointer    */
  403. wait_queue_head_t waiting;     /* Processes waiting on free bufs   */
  404. int   low_mark;    /* Low water mark    */
  405. int   high_mark;   /* High water mark    */
  406. atomic_t   wfh;        /* If waiting for high mark    */
  407. spinlock_t        lock;
  408. } drm_freelist_t;
  409. typedef struct drm_buf_entry {
  410. int   buf_size;
  411. int   buf_count;
  412. drm_buf_t   *buflist;
  413. int   seg_count;
  414. int   page_order;
  415. unsigned long   *seglist;
  416. drm_freelist_t   freelist;
  417. } drm_buf_entry_t;
  418. typedef struct drm_hw_lock {
  419. __volatile__ unsigned int lock;
  420. char   padding[60]; /* Pad to cache line */
  421. } drm_hw_lock_t;
  422. typedef struct drm_file {
  423. int   authenticated;
  424. int   minor;
  425. pid_t   pid;
  426. uid_t   uid;
  427. drm_magic_t   magic;
  428. unsigned long   ioctl_count;
  429. struct drm_file   *next;
  430. struct drm_file   *prev;
  431. struct drm_device *dev;
  432. int    remove_auth_on_close;
  433. } drm_file_t;
  434. typedef struct drm_queue {
  435. atomic_t   use_count; /* Outstanding uses (+1)     */
  436. atomic_t   finalization; /* Finalization in progress     */
  437. atomic_t   block_count; /* Count of processes waiting     */
  438. atomic_t   block_read; /* Queue blocked for reads     */
  439. wait_queue_head_t read_queue; /* Processes waiting on block_read  */
  440. atomic_t   block_write; /* Queue blocked for writes     */
  441. wait_queue_head_t write_queue; /* Processes waiting on block_write */
  442. #if 1
  443. atomic_t   total_queued; /* Total queued statistic     */
  444. atomic_t   total_flushed;/* Total flushes statistic     */
  445. atomic_t   total_locks; /* Total locks statistics     */
  446. #endif
  447. drm_ctx_flags_t   flags; /* Context preserving and 2D-only   */
  448. drm_waitlist_t   waitlist; /* Pending buffers     */
  449. wait_queue_head_t flush_queue; /* Processes waiting until flush    */
  450. } drm_queue_t;
  451. typedef struct drm_lock_data {
  452. drm_hw_lock_t   *hw_lock; /* Hardware lock    */
  453. pid_t   pid; /* PID of lock holder (0=kernel)   */
  454. wait_queue_head_t lock_queue; /* Queue of blocked processes    */
  455. unsigned long   lock_time; /* Time of last lock in jiffies    */
  456. } drm_lock_data_t;
  457. typedef struct drm_device_dma {
  458. #if 0
  459. /* Performance Counters */
  460. atomic_t   total_prio; /* Total DRM_DMA_PRIORITY    */
  461. atomic_t   total_bytes; /* Total bytes DMA'd    */
  462. atomic_t   total_dmas; /* Total DMA buffers dispatched    */
  463. atomic_t   total_missed_dma;  /* Missed drm_do_dma     */
  464. atomic_t   total_missed_lock; /* Missed lock in drm_do_dma   */
  465. atomic_t   total_missed_free; /* Missed drm_free_this_buffer */
  466. atomic_t   total_missed_sched;/* Missed drm_dma_schedule     */
  467. atomic_t   total_tried; /* Tried next_buffer     */
  468. atomic_t   total_hit; /* Sent next_buffer     */
  469. atomic_t   total_lost; /* Lost interrupt     */
  470. #endif
  471. drm_buf_entry_t   bufs[DRM_MAX_ORDER+1];
  472. int   buf_count;
  473. drm_buf_t   **buflist; /* Vector of pointers info bufs    */
  474. int   seg_count;
  475. int   page_count;
  476. unsigned long   *pagelist;
  477. unsigned long   byte_count;
  478. enum {
  479. _DRM_DMA_USE_AGP = 0x01,
  480. _DRM_DMA_USE_SG  = 0x02
  481. } flags;
  482. /* DMA support */
  483. drm_buf_t   *this_buffer; /* Buffer being sent    */
  484. drm_buf_t   *next_buffer; /* Selected buffer to send    */
  485. drm_queue_t   *next_queue; /* Queue from which buffer selected*/
  486. wait_queue_head_t waiting; /* Processes waiting on free bufs  */
  487. } drm_device_dma_t;
  488. #if __REALLY_HAVE_AGP
  489. typedef struct drm_agp_mem {
  490. unsigned long      handle;
  491. agp_memory         *memory;
  492. unsigned long      bound; /* address */
  493. int                pages;
  494. struct drm_agp_mem *prev;
  495. struct drm_agp_mem *next;
  496. } drm_agp_mem_t;
  497. typedef struct drm_agp_head {
  498. agp_kern_info      agp_info;
  499. const char         *chipset;
  500. drm_agp_mem_t      *memory;
  501. unsigned long      mode;
  502. int                enabled;
  503. int                acquired;
  504. unsigned long      base;
  505.     int     agp_mtrr;
  506. int    cant_use_aperture;
  507. unsigned long    page_mask;
  508. } drm_agp_head_t;
  509. #endif
  510. typedef struct drm_sg_mem {
  511. unsigned long   handle;
  512. void            *virtual;
  513. int             pages;
  514. struct page     **pagelist;
  515. dma_addr_t *busaddr;
  516. } drm_sg_mem_t;
  517. typedef struct drm_sigdata {
  518. int           context;
  519. drm_hw_lock_t *lock;
  520. } drm_sigdata_t;
  521. typedef struct drm_map_list {
  522. struct list_head head;
  523. drm_map_t *map;
  524. } drm_map_list_t;
  525. typedef struct drm_device {
  526. const char   *name; /* Simple driver name    */
  527. char   *unique; /* Unique identifier: e.g., busid  */
  528. int   unique_len; /* Length of unique field    */
  529. dev_t   device; /* Device number for mknod    */
  530. char   *devname; /* For /proc/interrupts    */
  531. int   blocked; /* Blocked due to VC switch?    */
  532. struct proc_dir_entry *root; /* Root for this device's entries  */
  533. /* Locks */
  534. spinlock_t   count_lock; /* For inuse, open_count, buf_use  */
  535. struct semaphore  struct_sem; /* For others    */
  536. /* Usage Counters */
  537. int   open_count; /* Outstanding files open    */
  538. atomic_t   ioctl_count; /* Outstanding IOCTLs pending    */
  539. atomic_t   vma_count; /* Outstanding vma areas open    */
  540. int   buf_use; /* Buffers in use -- cannot alloc  */
  541. atomic_t   buf_alloc; /* Buffer allocation in progress   */
  542. /* Performance counters */
  543. unsigned long     counters;
  544. drm_stat_type_t   types[15];
  545. atomic_t          counts[15];
  546. /* Authentication */
  547. drm_file_t   *file_first;
  548. drm_file_t   *file_last;
  549. drm_magic_head_t  magiclist[DRM_HASH_SIZE];
  550. /* Memory management */
  551. drm_map_list_t   *maplist; /* Linked list of regions    */
  552. int   map_count; /* Number of mappable regions    */
  553. drm_map_t   **context_sareas;
  554. int   max_context;
  555. drm_vma_entry_t   *vmalist; /* List of vmas (for debugging)    */
  556. drm_lock_data_t   lock; /* Information on hardware lock    */
  557. /* DMA queues (contexts) */
  558. int   queue_count; /* Number of active DMA queues    */
  559. int   queue_reserved; /* Number of reserved DMA queues */
  560. int   queue_slots; /* Actual length of queuelist    */
  561. drm_queue_t   **queuelist; /* Vector of pointers to DMA queues */
  562. drm_device_dma_t  *dma; /* Optional pointer for DMA support */
  563. /* Context support */
  564. int   irq; /* Interrupt used by board    */
  565. __volatile__ long context_flag; /* Context swapping flag    */
  566. __volatile__ long interrupt_flag; /* Interruption handler flag    */
  567. __volatile__ long dma_flag; /* DMA dispatch flag    */
  568. struct timer_list timer; /* Timer for delaying ctx switch   */
  569. wait_queue_head_t context_wait; /* Processes waiting on ctx switch */
  570. int   last_checked; /* Last context checked for DMA    */
  571. int   last_context; /* Last current context    */
  572. unsigned long   last_switch; /* jiffies at last context switch  */
  573. struct tq_struct  tq;
  574. cycles_t   ctx_start;
  575. cycles_t   lck_start;
  576. #if __HAVE_DMA_HISTOGRAM
  577. drm_histogram_t   histo;
  578. #endif
  579. /* Callback to X server for context switch
  580.    and for heavy-handed reset. */
  581. char   buf[DRM_BSZ]; /* Output buffer    */
  582. char   *buf_rp; /* Read pointer    */
  583. char   *buf_wp; /* Write pointer    */
  584. char   *buf_end; /* End pointer    */
  585. struct fasync_struct *buf_async;/* Processes waiting for SIGIO    */
  586. wait_queue_head_t buf_readers; /* Processes waiting to read    */
  587. wait_queue_head_t buf_writers; /* Processes waiting to ctx switch */
  588. #if __REALLY_HAVE_AGP
  589. drm_agp_head_t    *agp;
  590. #endif
  591. struct pci_dev *pdev;
  592. #ifdef __alpha__
  593. struct pci_controller *hose;
  594. #endif
  595. drm_sg_mem_t      *sg;  /* Scatter gather memory */
  596. unsigned long     *ctx_bitmap;
  597. void   *dev_private;
  598. drm_sigdata_t     sigdata; /* For block_all_signals */
  599. sigset_t          sigmask;
  600. } drm_device_t;
  601. /* ================================================================
  602.  * Internal function definitions
  603.  */
  604. /* Misc. support (drm_init.h) */
  605. extern int      DRM(flags);
  606. extern void      DRM(parse_options)( char *s );
  607. extern int           DRM(cpu_valid)( void );
  608. /* Driver support (drm_drv.h) */
  609. extern int           DRM(version)(struct inode *inode, struct file *filp,
  610.   unsigned int cmd, unsigned long arg);
  611. extern int           DRM(open)(struct inode *inode, struct file *filp);
  612. extern int           DRM(release)(struct inode *inode, struct file *filp);
  613. extern int           DRM(ioctl)(struct inode *inode, struct file *filp,
  614. unsigned int cmd, unsigned long arg);
  615. extern int           DRM(lock)(struct inode *inode, struct file *filp,
  616.        unsigned int cmd, unsigned long arg);
  617. extern int           DRM(unlock)(struct inode *inode, struct file *filp,
  618.  unsigned int cmd, unsigned long arg);
  619. /* Device support (drm_fops.h) */
  620. extern int      DRM(open_helper)(struct inode *inode, struct file *filp,
  621.       drm_device_t *dev);
  622. extern int      DRM(flush)(struct file *filp);
  623. extern int      DRM(release_fuck)(struct inode *inode, struct file *filp);
  624. extern int      DRM(fasync)(int fd, struct file *filp, int on);
  625. extern ssize_t      DRM(read)(struct file *filp, char *buf, size_t count,
  626.        loff_t *off);
  627. extern int      DRM(write_string)(drm_device_t *dev, const char *s);
  628. extern unsigned int  DRM(poll)(struct file *filp,
  629.        struct poll_table_struct *wait);
  630. /* Mapping support (drm_vm.h) */
  631. extern struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
  632.    unsigned long address,
  633.    int unused);
  634. extern struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
  635.        unsigned long address,
  636.        int unused);
  637. extern struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
  638.        unsigned long address,
  639.        int unused);
  640. extern struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma,
  641.       unsigned long address,
  642.       int unused);
  643. extern void      DRM(vm_open)(struct vm_area_struct *vma);
  644. extern void      DRM(vm_close)(struct vm_area_struct *vma);
  645. extern void      DRM(vm_shm_close)(struct vm_area_struct *vma);
  646. extern int      DRM(mmap_dma)(struct file *filp,
  647.    struct vm_area_struct *vma);
  648. extern int      DRM(mmap)(struct file *filp, struct vm_area_struct *vma);
  649. /* Memory management support (drm_memory.h) */
  650. extern void      DRM(mem_init)(void);
  651. extern int      DRM(mem_info)(char *buf, char **start, off_t offset,
  652.    int request, int *eof, void *data);
  653. extern void      *DRM(alloc)(size_t size, int area);
  654. extern void      *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
  655.    int area);
  656. extern char      *DRM(strdup)(const char *s, int area);
  657. extern void      DRM(strfree)(const char *s, int area);
  658. extern void      DRM(free)(void *pt, size_t size, int area);
  659. extern unsigned long DRM(alloc_pages)(int order, int area);
  660. extern void      DRM(free_pages)(unsigned long address, int order,
  661.      int area);
  662. extern void      *DRM(ioremap)(unsigned long offset, unsigned long size);
  663. extern void      DRM(ioremapfree)(void *pt, unsigned long size);
  664. #if __REALLY_HAVE_AGP
  665. extern agp_memory    *DRM(alloc_agp)(int pages, u32 type);
  666. extern int           DRM(free_agp)(agp_memory *handle, int pages);
  667. extern int           DRM(bind_agp)(agp_memory *handle, unsigned int start);
  668. extern int           DRM(unbind_agp)(agp_memory *handle);
  669. #endif
  670. /* Misc. IOCTL support (drm_ioctl.h) */
  671. extern int      DRM(irq_busid)(struct inode *inode, struct file *filp,
  672.     unsigned int cmd, unsigned long arg);
  673. extern int      DRM(getunique)(struct inode *inode, struct file *filp,
  674.     unsigned int cmd, unsigned long arg);
  675. extern int      DRM(setunique)(struct inode *inode, struct file *filp,
  676.     unsigned int cmd, unsigned long arg);
  677. extern int      DRM(getmap)(struct inode *inode, struct file *filp,
  678.  unsigned int cmd, unsigned long arg);
  679. extern int      DRM(getclient)(struct inode *inode, struct file *filp,
  680.     unsigned int cmd, unsigned long arg);
  681. extern int      DRM(getstats)(struct inode *inode, struct file *filp,
  682.    unsigned int cmd, unsigned long arg);
  683. /* Context IOCTL support (drm_context.h) */
  684. extern int      DRM(resctx)( struct inode *inode, struct file *filp,
  685.   unsigned int cmd, unsigned long arg );
  686. extern int      DRM(addctx)( struct inode *inode, struct file *filp,
  687.   unsigned int cmd, unsigned long arg );
  688. extern int      DRM(modctx)( struct inode *inode, struct file *filp,
  689.   unsigned int cmd, unsigned long arg );
  690. extern int      DRM(getctx)( struct inode *inode, struct file *filp,
  691.   unsigned int cmd, unsigned long arg );
  692. extern int      DRM(switchctx)( struct inode *inode, struct file *filp,
  693.      unsigned int cmd, unsigned long arg );
  694. extern int      DRM(newctx)( struct inode *inode, struct file *filp,
  695.   unsigned int cmd, unsigned long arg );
  696. extern int      DRM(rmctx)( struct inode *inode, struct file *filp,
  697.  unsigned int cmd, unsigned long arg );
  698. extern int      DRM(context_switch)(drm_device_t *dev, int old, int new);
  699. extern int      DRM(context_switch_complete)(drm_device_t *dev, int new);
  700. #if __HAVE_CTX_BITMAP
  701. extern int      DRM(ctxbitmap_init)( drm_device_t *dev );
  702. extern void      DRM(ctxbitmap_cleanup)( drm_device_t *dev );
  703. #endif
  704. extern int      DRM(setsareactx)( struct inode *inode, struct file *filp,
  705.        unsigned int cmd, unsigned long arg );
  706. extern int      DRM(getsareactx)( struct inode *inode, struct file *filp,
  707.        unsigned int cmd, unsigned long arg );
  708. /* Drawable IOCTL support (drm_drawable.h) */
  709. extern int      DRM(adddraw)(struct inode *inode, struct file *filp,
  710.   unsigned int cmd, unsigned long arg);
  711. extern int      DRM(rmdraw)(struct inode *inode, struct file *filp,
  712.  unsigned int cmd, unsigned long arg);
  713. /* Authentication IOCTL support (drm_auth.h) */
  714. extern int      DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
  715.     drm_magic_t magic);
  716. extern int      DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
  717. extern int      DRM(getmagic)(struct inode *inode, struct file *filp,
  718.    unsigned int cmd, unsigned long arg);
  719. extern int      DRM(authmagic)(struct inode *inode, struct file *filp,
  720.     unsigned int cmd, unsigned long arg);
  721. /* Locking IOCTL support (drm_lock.h) */
  722. extern int      DRM(block)(struct inode *inode, struct file *filp,
  723. unsigned int cmd, unsigned long arg);
  724. extern int      DRM(unblock)(struct inode *inode, struct file *filp,
  725.   unsigned int cmd, unsigned long arg);
  726. extern int      DRM(lock_take)(__volatile__ unsigned int *lock,
  727.     unsigned int context);
  728. extern int      DRM(lock_transfer)(drm_device_t *dev,
  729. __volatile__ unsigned int *lock,
  730. unsigned int context);
  731. extern int      DRM(lock_free)(drm_device_t *dev,
  732.     __volatile__ unsigned int *lock,
  733.     unsigned int context);
  734. extern int      DRM(finish)(struct inode *inode, struct file *filp,
  735.  unsigned int cmd, unsigned long arg);
  736. extern int      DRM(flush_unblock)(drm_device_t *dev, int context,
  737. drm_lock_flags_t flags);
  738. extern int      DRM(flush_block_and_flush)(drm_device_t *dev, int context,
  739. drm_lock_flags_t flags);
  740. extern int           DRM(notifier)(void *priv);
  741. /* Buffer management support (drm_bufs.h) */
  742. extern int      DRM(order)( unsigned long size );
  743. extern int      DRM(addmap)( struct inode *inode, struct file *filp,
  744.   unsigned int cmd, unsigned long arg );
  745. extern int      DRM(rmmap)( struct inode *inode, struct file *filp,
  746.  unsigned int cmd, unsigned long arg );
  747. #if __HAVE_DMA
  748. extern int      DRM(addbufs)( struct inode *inode, struct file *filp,
  749.    unsigned int cmd, unsigned long arg );
  750. extern int      DRM(infobufs)( struct inode *inode, struct file *filp,
  751.     unsigned int cmd, unsigned long arg );
  752. extern int      DRM(markbufs)( struct inode *inode, struct file *filp,
  753.     unsigned int cmd, unsigned long arg );
  754. extern int      DRM(freebufs)( struct inode *inode, struct file *filp,
  755.     unsigned int cmd, unsigned long arg );
  756. extern int      DRM(mapbufs)( struct inode *inode, struct file *filp,
  757.    unsigned int cmd, unsigned long arg );
  758. /* DMA support (drm_dma.h) */
  759. extern int      DRM(dma_setup)(drm_device_t *dev);
  760. extern void      DRM(dma_takedown)(drm_device_t *dev);
  761. extern void      DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
  762. extern void      DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid);
  763. #if __HAVE_OLD_DMA
  764. /* GH: This is a dirty hack for now...
  765.  */
  766. extern void      DRM(clear_next_buffer)(drm_device_t *dev);
  767. extern int      DRM(select_queue)(drm_device_t *dev,
  768.        void (*wrapper)(unsigned long));
  769. extern int      DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *dma);
  770. extern int      DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma);
  771. #endif
  772. #if __HAVE_DMA_IRQ
  773. extern int           DRM(control)( struct inode *inode, struct file *filp,
  774.    unsigned int cmd, unsigned long arg );
  775. extern int           DRM(irq_install)( drm_device_t *dev, int irq );
  776. extern int           DRM(irq_uninstall)( drm_device_t *dev );
  777. extern void          DRM(dma_service)( int irq, void *device,
  778.        struct pt_regs *regs );
  779. #if __HAVE_DMA_IRQ_BH
  780. extern void          DRM(dma_immediate_bh)( void *dev );
  781. #endif
  782. #endif
  783. #if DRM_DMA_HISTOGRAM
  784. extern int      DRM(histogram_slot)(unsigned long count);
  785. extern void      DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf);
  786. #endif
  787. /* Buffer list support (drm_lists.h) */
  788. #if __HAVE_DMA_WAITLIST
  789. extern int      DRM(waitlist_create)(drm_waitlist_t *bl, int count);
  790. extern int      DRM(waitlist_destroy)(drm_waitlist_t *bl);
  791. extern int      DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf);
  792. extern drm_buf_t     *DRM(waitlist_get)(drm_waitlist_t *bl);
  793. #endif
  794. #if __HAVE_DMA_FREELIST
  795. extern int      DRM(freelist_create)(drm_freelist_t *bl, int count);
  796. extern int      DRM(freelist_destroy)(drm_freelist_t *bl);
  797. extern int      DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl,
  798.        drm_buf_t *buf);
  799. extern drm_buf_t     *DRM(freelist_get)(drm_freelist_t *bl, int block);
  800. #endif
  801. #endif /* __HAVE_DMA */
  802. #if __REALLY_HAVE_AGP
  803. /* AGP/GART support (drm_agpsupport.h) */
  804. extern drm_agp_head_t *DRM(agp_init)(void);
  805. extern void           DRM(agp_uninit)(void);
  806. extern int            DRM(agp_acquire)(struct inode *inode, struct file *filp,
  807.        unsigned int cmd, unsigned long arg);
  808. extern void           DRM(agp_do_release)(void);
  809. extern int            DRM(agp_release)(struct inode *inode, struct file *filp,
  810.        unsigned int cmd, unsigned long arg);
  811. extern int            DRM(agp_enable)(struct inode *inode, struct file *filp,
  812.       unsigned int cmd, unsigned long arg);
  813. extern int            DRM(agp_info)(struct inode *inode, struct file *filp,
  814.     unsigned int cmd, unsigned long arg);
  815. extern int            DRM(agp_alloc)(struct inode *inode, struct file *filp,
  816.      unsigned int cmd, unsigned long arg);
  817. extern int            DRM(agp_free)(struct inode *inode, struct file *filp,
  818.     unsigned int cmd, unsigned long arg);
  819. extern int            DRM(agp_unbind)(struct inode *inode, struct file *filp,
  820.       unsigned int cmd, unsigned long arg);
  821. extern int            DRM(agp_bind)(struct inode *inode, struct file *filp,
  822.     unsigned int cmd, unsigned long arg);
  823. extern agp_memory     *DRM(agp_allocate_memory)(size_t pages, u32 type);
  824. extern int            DRM(agp_free_memory)(agp_memory *handle);
  825. extern int            DRM(agp_bind_memory)(agp_memory *handle, off_t start);
  826. extern int            DRM(agp_unbind_memory)(agp_memory *handle);
  827. #endif
  828. /* Stub support (drm_stub.h) */
  829. int                   DRM(stub_register)(const char *name,
  830.  struct file_operations *fops,
  831.  drm_device_t *dev);
  832. int                   DRM(stub_unregister)(int minor);
  833. /* Proc support (drm_proc.h) */
  834. extern struct proc_dir_entry *DRM(proc_init)(drm_device_t *dev,
  835.      int minor,
  836.      struct proc_dir_entry *root,
  837.      struct proc_dir_entry **dev_root);
  838. extern int            DRM(proc_cleanup)(int minor,
  839. struct proc_dir_entry *root,
  840. struct proc_dir_entry *dev_root);
  841. #if __HAVE_SG
  842. /* Scatter Gather Support (drm_scatter.h) */
  843. extern void           DRM(sg_cleanup)(drm_sg_mem_t *entry);
  844. extern int            DRM(sg_alloc)(struct inode *inode, struct file *filp,
  845.     unsigned int cmd, unsigned long arg);
  846. extern int            DRM(sg_free)(struct inode *inode, struct file *filp,
  847.    unsigned int cmd, unsigned long arg);
  848. #endif
  849.                                /* ATI PCIGART support (ati_pcigart.h) */
  850. extern int            DRM(ati_pcigart_init)(drm_device_t *dev,
  851.     unsigned long *addr,
  852.     dma_addr_t *bus_addr);
  853. extern int            DRM(ati_pcigart_cleanup)(drm_device_t *dev,
  854.        unsigned long addr,
  855.        dma_addr_t bus_addr);
  856. #endif /* __KERNEL__ */
  857. #endif