drmP.h 36 KB

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