drmP.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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_ioctl(struct inode *inode, struct file *filp,
  677. unsigned int cmd, unsigned long arg);
  678. extern long drm_compat_ioctl(struct file *filp,
  679. unsigned int cmd, unsigned long arg);
  680. extern int drm_takedown(drm_device_t * dev);
  681. /* Device support (drm_fops.h) */
  682. extern int drm_open(struct inode *inode, struct file *filp);
  683. extern int drm_stub_open(struct inode *inode, struct file *filp);
  684. extern int drm_flush(struct file *filp);
  685. extern int drm_fasync(int fd, struct file *filp, int on);
  686. extern int drm_release(struct inode *inode, struct file *filp);
  687. /* Mapping support (drm_vm.h) */
  688. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  689. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  690. /* Memory management support (drm_memory.h) */
  691. #include "drm_memory.h"
  692. extern void drm_mem_init(void);
  693. extern int drm_mem_info(char *buf, char **start, off_t offset,
  694. int request, int *eof, void *data);
  695. extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
  696. int area);
  697. extern unsigned long drm_alloc_pages(int order, int area);
  698. extern void drm_free_pages(unsigned long address, int order,
  699. int area);
  700. extern void *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev);
  701. extern void *drm_ioremap_nocache(unsigned long offset, unsigned long size,
  702. drm_device_t *dev);
  703. extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev);
  704. extern DRM_AGP_MEM *drm_alloc_agp(struct agp_bridge_data *bridge, int pages, u32 type);
  705. extern int drm_free_agp(DRM_AGP_MEM *handle, int pages);
  706. extern int drm_bind_agp(DRM_AGP_MEM *handle, unsigned int start);
  707. extern int drm_unbind_agp(DRM_AGP_MEM *handle);
  708. /* Misc. IOCTL support (drm_ioctl.h) */
  709. extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
  710. unsigned int cmd, unsigned long arg);
  711. extern int drm_getunique(struct inode *inode, struct file *filp,
  712. unsigned int cmd, unsigned long arg);
  713. extern int drm_setunique(struct inode *inode, struct file *filp,
  714. unsigned int cmd, unsigned long arg);
  715. extern int drm_getmap(struct inode *inode, struct file *filp,
  716. unsigned int cmd, unsigned long arg);
  717. extern int drm_getclient(struct inode *inode, struct file *filp,
  718. unsigned int cmd, unsigned long arg);
  719. extern int drm_getstats(struct inode *inode, struct file *filp,
  720. unsigned int cmd, unsigned long arg);
  721. extern int drm_setversion(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. /* Placeholder for ioctls past */
  756. extern int drm_noop(struct inode *inode, struct file *filp,
  757. unsigned int cmd, unsigned long arg);
  758. /* Locking IOCTL support (drm_lock.h) */
  759. extern int drm_lock(struct inode *inode, struct file *filp,
  760. unsigned int cmd, unsigned long arg);
  761. extern int drm_unlock(struct inode *inode, struct file *filp,
  762. unsigned int cmd, unsigned long arg);
  763. extern int drm_lock_take(__volatile__ unsigned int *lock,
  764. unsigned int context);
  765. extern int drm_lock_free(drm_device_t *dev,
  766. __volatile__ unsigned int *lock,
  767. unsigned int context);
  768. /* Buffer management support (drm_bufs.h) */
  769. extern int drm_order( unsigned long size );
  770. extern int drm_addmap( struct inode *inode, struct file *filp,
  771. unsigned int cmd, unsigned long arg );
  772. extern int drm_rmmap( struct inode *inode, struct file *filp,
  773. unsigned int cmd, unsigned long arg );
  774. extern int drm_addbufs( struct inode *inode, struct file *filp,
  775. unsigned int cmd, unsigned long arg );
  776. extern int drm_infobufs( struct inode *inode, struct file *filp,
  777. unsigned int cmd, unsigned long arg );
  778. extern int drm_markbufs( struct inode *inode, struct file *filp,
  779. unsigned int cmd, unsigned long arg );
  780. extern int drm_freebufs( struct inode *inode, struct file *filp,
  781. unsigned int cmd, unsigned long arg );
  782. extern int drm_mapbufs( struct inode *inode, struct file *filp,
  783. unsigned int cmd, unsigned long arg );
  784. /* DMA support (drm_dma.h) */
  785. extern int drm_dma_setup(drm_device_t *dev);
  786. extern void drm_dma_takedown(drm_device_t *dev);
  787. extern void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
  788. extern void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp);
  789. /* IRQ support (drm_irq.h) */
  790. extern int drm_control( struct inode *inode, struct file *filp,
  791. unsigned int cmd, unsigned long arg );
  792. extern int drm_irq_uninstall( drm_device_t *dev );
  793. extern irqreturn_t drm_irq_handler( DRM_IRQ_ARGS );
  794. extern void drm_driver_irq_preinstall( drm_device_t *dev );
  795. extern void drm_driver_irq_postinstall( drm_device_t *dev );
  796. extern void drm_driver_irq_uninstall( drm_device_t *dev );
  797. extern int drm_wait_vblank(struct inode *inode, struct file *filp,
  798. unsigned int cmd, unsigned long arg);
  799. extern int drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
  800. extern void drm_vbl_send_signals( drm_device_t *dev );
  801. /* AGP/GART support (drm_agpsupport.h) */
  802. extern drm_agp_head_t *drm_agp_init(drm_device_t *dev);
  803. extern int drm_agp_acquire(struct inode *inode, struct file *filp,
  804. unsigned int cmd, unsigned long arg);
  805. extern void drm_agp_do_release(drm_device_t *dev);
  806. extern int drm_agp_release(struct inode *inode, struct file *filp,
  807. unsigned int cmd, unsigned long arg);
  808. extern int drm_agp_enable(struct inode *inode, struct file *filp,
  809. unsigned int cmd, unsigned long arg);
  810. extern int drm_agp_info(struct inode *inode, struct file *filp,
  811. unsigned int cmd, unsigned long arg);
  812. extern int drm_agp_alloc(struct inode *inode, struct file *filp,
  813. unsigned int cmd, unsigned long arg);
  814. extern int drm_agp_free(struct inode *inode, struct file *filp,
  815. unsigned int cmd, unsigned long arg);
  816. extern int drm_agp_unbind(struct inode *inode, struct file *filp,
  817. unsigned int cmd, unsigned long arg);
  818. extern int drm_agp_bind(struct inode *inode, struct file *filp,
  819. unsigned int cmd, unsigned long arg);
  820. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
  821. extern int drm_agp_free_memory(DRM_AGP_MEM *handle);
  822. extern int drm_agp_bind_memory(DRM_AGP_MEM *handle, off_t start);
  823. extern int drm_agp_unbind_memory(DRM_AGP_MEM *handle);
  824. /* Stub support (drm_stub.h) */
  825. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  826. struct drm_driver *driver);
  827. extern int drm_put_dev(drm_device_t * dev);
  828. extern int drm_put_head(drm_head_t * head);
  829. extern unsigned int drm_debug;
  830. extern unsigned int drm_cards_limit;
  831. extern drm_head_t **drm_heads;
  832. extern struct drm_sysfs_class *drm_class;
  833. extern struct proc_dir_entry *drm_proc_root;
  834. /* Proc support (drm_proc.h) */
  835. extern int drm_proc_init(drm_device_t *dev,
  836. int minor,
  837. struct proc_dir_entry *root,
  838. struct proc_dir_entry **dev_root);
  839. extern int drm_proc_cleanup(int minor,
  840. struct proc_dir_entry *root,
  841. struct proc_dir_entry *dev_root);
  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. /* ATI PCIGART support (ati_pcigart.h) */
  849. extern int drm_ati_pcigart_init(drm_device_t *dev,
  850. unsigned long *addr,
  851. dma_addr_t *bus_addr);
  852. extern int drm_ati_pcigart_cleanup(drm_device_t *dev,
  853. unsigned long addr,
  854. dma_addr_t bus_addr);
  855. extern void *drm_pci_alloc(drm_device_t * dev, size_t size,
  856. size_t align, dma_addr_t maxaddr,
  857. dma_addr_t * busaddr);
  858. extern void drm_pci_free(drm_device_t * dev, size_t size,
  859. void *vaddr, dma_addr_t busaddr);
  860. /* sysfs support (drm_sysfs.c) */
  861. struct drm_sysfs_class;
  862. extern struct drm_sysfs_class *drm_sysfs_create(struct module *owner,
  863. char *name);
  864. extern void drm_sysfs_destroy(struct drm_sysfs_class *cs);
  865. extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
  866. dev_t dev,
  867. struct device *device,
  868. const char *fmt, ...);
  869. extern void drm_sysfs_device_remove(dev_t dev);
  870. /* Inline replacements for DRM_IOREMAP macros */
  871. static __inline__ void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
  872. {
  873. map->handle = drm_ioremap( map->offset, map->size, dev );
  874. }
  875. static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, struct drm_device *dev)
  876. {
  877. map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
  878. }
  879. static __inline__ void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
  880. {
  881. if ( map->handle && map->size )
  882. drm_ioremapfree( map->handle, map->size, dev );
  883. }
  884. static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
  885. {
  886. struct list_head *_list;
  887. list_for_each( _list, &dev->maplist->head ) {
  888. drm_map_list_t *_entry = list_entry( _list, drm_map_list_t, head );
  889. if ( _entry->map &&
  890. _entry->map->offset == offset ) {
  891. return _entry->map;
  892. }
  893. }
  894. return NULL;
  895. }
  896. static __inline__ void drm_core_dropmap(struct drm_map *map)
  897. {
  898. }
  899. #ifndef DEBUG_MEMORY
  900. /** Wrapper around kmalloc() */
  901. static __inline__ void *drm_alloc(size_t size, int area)
  902. {
  903. return kmalloc(size, GFP_KERNEL);
  904. }
  905. /** Wrapper around kfree() */
  906. static __inline__ void drm_free(void *pt, size_t size, int area)
  907. {
  908. kfree(pt);
  909. }
  910. /** Wrapper around kcalloc() */
  911. static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
  912. {
  913. return kcalloc(nmemb, size, GFP_KERNEL);
  914. }
  915. #else
  916. extern void *drm_alloc(size_t size, int area);
  917. extern void drm_free(void *pt, size_t size, int area);
  918. extern void *drm_calloc(size_t nmemb, size_t size, int area);
  919. #endif
  920. /*@}*/
  921. extern unsigned long drm_core_get_map_ofs(drm_map_t *map);
  922. extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
  923. #endif /* __KERNEL__ */
  924. #endif