drmP.h 35 KB

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