drmP.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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/jiffies.h>
  53. #include <linux/smp_lock.h> /* For (un)lock_kernel */
  54. #include <linux/mm.h>
  55. #include <linux/cdev.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_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. #define DRM_RPR_ARG(vma) vma,
  143. #define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
  144. /*@}*/
  145. /***********************************************************************/
  146. /** \name Macros to make printk easier */
  147. /*@{*/
  148. /**
  149. * Error output.
  150. *
  151. * \param fmt printf() like format string.
  152. * \param arg arguments
  153. */
  154. #define DRM_ERROR(fmt, arg...) \
  155. printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
  156. /**
  157. * Memory error output.
  158. *
  159. * \param area memory area where the error occurred.
  160. * \param fmt printf() like format string.
  161. * \param arg arguments
  162. */
  163. #define DRM_MEM_ERROR(area, fmt, arg...) \
  164. printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
  165. drm_mem_stats[area].name , ##arg)
  166. #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
  167. /**
  168. * Debug output.
  169. *
  170. * \param fmt printf() like format string.
  171. * \param arg arguments
  172. */
  173. #if DRM_DEBUG_CODE
  174. #define DRM_DEBUG(fmt, arg...) \
  175. do { \
  176. if ( drm_debug ) \
  177. printk(KERN_DEBUG \
  178. "[" DRM_NAME ":%s] " fmt , \
  179. __FUNCTION__ , ##arg); \
  180. } while (0)
  181. #else
  182. #define DRM_DEBUG(fmt, arg...) do { } while (0)
  183. #endif
  184. #define DRM_PROC_LIMIT (PAGE_SIZE-80)
  185. #define DRM_PROC_PRINT(fmt, arg...) \
  186. len += sprintf(&buf[len], fmt , ##arg); \
  187. if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
  188. #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
  189. len += sprintf(&buf[len], fmt , ##arg); \
  190. if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
  191. /*@}*/
  192. /***********************************************************************/
  193. /** \name Internal types and structures */
  194. /*@{*/
  195. #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
  196. #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
  197. #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
  198. #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
  199. #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
  200. #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
  201. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  202. /**
  203. * Get the private SAREA mapping.
  204. *
  205. * \param _dev DRM device.
  206. * \param _ctx context number.
  207. * \param _map output mapping.
  208. */
  209. #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
  210. (_map) = (_dev)->context_sareas[_ctx]; \
  211. } while(0)
  212. /**
  213. * Test that the hardware lock is held by the caller, returning otherwise.
  214. *
  215. * \param dev DRM device.
  216. * \param filp file pointer of the caller.
  217. */
  218. #define LOCK_TEST_WITH_RETURN( dev, filp ) \
  219. do { \
  220. if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
  221. dev->lock.filp != filp ) { \
  222. DRM_ERROR( "%s called without lock held\n", \
  223. __FUNCTION__ ); \
  224. return -EINVAL; \
  225. } \
  226. } while (0)
  227. /**
  228. * Copy and IOCTL return string to user space
  229. */
  230. #define DRM_COPY( name, value ) \
  231. len = strlen( value ); \
  232. if ( len > name##_len ) len = name##_len; \
  233. name##_len = strlen( value ); \
  234. if ( len && name ) { \
  235. if ( copy_to_user( name, value, len ) ) \
  236. return -EFAULT; \
  237. }
  238. /**
  239. * Ioctl function type.
  240. *
  241. * \param inode device inode.
  242. * \param filp file pointer.
  243. * \param cmd command.
  244. * \param arg argument.
  245. */
  246. typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
  247. unsigned int cmd, unsigned long arg );
  248. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  249. unsigned long arg);
  250. typedef struct drm_ioctl_desc {
  251. drm_ioctl_t *func;
  252. int auth_needed;
  253. int root_only;
  254. } drm_ioctl_desc_t;
  255. typedef struct drm_devstate {
  256. pid_t owner; /**< X server pid holding x_lock */
  257. } drm_devstate_t;
  258. typedef struct drm_magic_entry {
  259. drm_magic_t magic;
  260. struct drm_file *priv;
  261. struct drm_magic_entry *next;
  262. } drm_magic_entry_t;
  263. typedef struct drm_magic_head {
  264. struct drm_magic_entry *head;
  265. struct drm_magic_entry *tail;
  266. } drm_magic_head_t;
  267. typedef struct drm_vma_entry {
  268. struct vm_area_struct *vma;
  269. struct drm_vma_entry *next;
  270. pid_t pid;
  271. } drm_vma_entry_t;
  272. /**
  273. * DMA buffer.
  274. */
  275. typedef struct drm_buf {
  276. int idx; /**< Index into master buflist */
  277. int total; /**< Buffer size */
  278. int order; /**< log-base-2(total) */
  279. int used; /**< Amount of buffer in use (for DMA) */
  280. unsigned long offset; /**< Byte offset (used internally) */
  281. void *address; /**< Address of buffer */
  282. unsigned long bus_address; /**< Bus address of buffer */
  283. struct drm_buf *next; /**< Kernel-only: used for free list */
  284. __volatile__ int waiting; /**< On kernel DMA queue */
  285. __volatile__ int pending; /**< On hardware DMA queue */
  286. wait_queue_head_t dma_wait; /**< Processes waiting */
  287. struct file *filp; /**< Pointer to holding file descr */
  288. int context; /**< Kernel queue for this buffer */
  289. int while_locked;/**< Dispatch this buffer while locked */
  290. enum {
  291. DRM_LIST_NONE = 0,
  292. DRM_LIST_FREE = 1,
  293. DRM_LIST_WAIT = 2,
  294. DRM_LIST_PEND = 3,
  295. DRM_LIST_PRIO = 4,
  296. DRM_LIST_RECLAIM = 5
  297. } list; /**< Which list we're on */
  298. int dev_priv_size; /**< Size of buffer private storage */
  299. void *dev_private; /**< Per-buffer private storage */
  300. } drm_buf_t;
  301. /** bufs is one longer than it has to be */
  302. typedef struct drm_waitlist {
  303. int count; /**< Number of possible buffers */
  304. drm_buf_t **bufs; /**< List of pointers to buffers */
  305. drm_buf_t **rp; /**< Read pointer */
  306. drm_buf_t **wp; /**< Write pointer */
  307. drm_buf_t **end; /**< End pointer */
  308. spinlock_t read_lock;
  309. spinlock_t write_lock;
  310. } drm_waitlist_t;
  311. typedef struct drm_freelist {
  312. int initialized; /**< Freelist in use */
  313. atomic_t count; /**< Number of free buffers */
  314. drm_buf_t *next; /**< End pointer */
  315. wait_queue_head_t waiting; /**< Processes waiting on free bufs */
  316. int low_mark; /**< Low water mark */
  317. int high_mark; /**< High water mark */
  318. atomic_t wfh; /**< If waiting for high mark */
  319. spinlock_t lock;
  320. } drm_freelist_t;
  321. /**
  322. * Buffer entry. There is one of this for each buffer size order.
  323. */
  324. typedef struct drm_buf_entry {
  325. int buf_size; /**< size */
  326. int buf_count; /**< number of buffers */
  327. drm_buf_t *buflist; /**< buffer list */
  328. int seg_count;
  329. int page_order;
  330. unsigned long *seglist;
  331. drm_freelist_t freelist;
  332. } drm_buf_entry_t;
  333. /** File private data */
  334. typedef struct drm_file {
  335. int authenticated;
  336. int minor;
  337. pid_t pid;
  338. uid_t uid;
  339. drm_magic_t magic;
  340. unsigned long ioctl_count;
  341. struct drm_file *next;
  342. struct drm_file *prev;
  343. struct drm_head *head;
  344. int remove_auth_on_close;
  345. unsigned long lock_count;
  346. void *driver_priv;
  347. } drm_file_t;
  348. /** Wait queue */
  349. typedef struct drm_queue {
  350. atomic_t use_count; /**< Outstanding uses (+1) */
  351. atomic_t finalization; /**< Finalization in progress */
  352. atomic_t block_count; /**< Count of processes waiting */
  353. atomic_t block_read; /**< Queue blocked for reads */
  354. wait_queue_head_t read_queue; /**< Processes waiting on block_read */
  355. atomic_t block_write; /**< Queue blocked for writes */
  356. wait_queue_head_t write_queue; /**< Processes waiting on block_write */
  357. #if 1
  358. atomic_t total_queued; /**< Total queued statistic */
  359. atomic_t total_flushed;/**< Total flushes statistic */
  360. atomic_t total_locks; /**< Total locks statistics */
  361. #endif
  362. drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
  363. drm_waitlist_t waitlist; /**< Pending buffers */
  364. wait_queue_head_t flush_queue; /**< Processes waiting until flush */
  365. } drm_queue_t;
  366. /**
  367. * Lock data.
  368. */
  369. typedef struct drm_lock_data {
  370. drm_hw_lock_t *hw_lock; /**< Hardware lock */
  371. struct file *filp; /**< File descr of lock holder (0=kernel) */
  372. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  373. unsigned long lock_time; /**< Time of last lock in jiffies */
  374. } drm_lock_data_t;
  375. /**
  376. * DMA data.
  377. */
  378. typedef struct drm_device_dma {
  379. drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; /**< buffers, grouped by their size order */
  380. int buf_count; /**< total number of buffers */
  381. drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  382. int seg_count;
  383. int page_count; /**< number of pages */
  384. unsigned long *pagelist; /**< page list */
  385. unsigned long byte_count;
  386. enum {
  387. _DRM_DMA_USE_AGP = 0x01,
  388. _DRM_DMA_USE_SG = 0x02,
  389. _DRM_DMA_USE_FB = 0x04
  390. } flags;
  391. } drm_device_dma_t;
  392. /**
  393. * AGP memory entry. Stored as a doubly linked list.
  394. */
  395. typedef struct drm_agp_mem {
  396. unsigned long handle; /**< handle */
  397. DRM_AGP_MEM *memory;
  398. unsigned long bound; /**< address */
  399. int pages;
  400. struct drm_agp_mem *prev; /**< previous entry */
  401. struct drm_agp_mem *next; /**< next entry */
  402. } drm_agp_mem_t;
  403. /**
  404. * AGP data.
  405. *
  406. * \sa drm_agp_init() and drm_device::agp.
  407. */
  408. typedef struct drm_agp_head {
  409. DRM_AGP_KERN agp_info; /**< AGP device information */
  410. drm_agp_mem_t *memory; /**< memory entries */
  411. unsigned long mode; /**< AGP mode */
  412. struct agp_bridge_data *bridge;
  413. int enabled; /**< whether the AGP bus as been enabled */
  414. int acquired; /**< whether the AGP device has been acquired */
  415. unsigned long base;
  416. int agp_mtrr;
  417. int cant_use_aperture;
  418. unsigned long page_mask;
  419. } drm_agp_head_t;
  420. /**
  421. * Scatter-gather memory.
  422. */
  423. typedef struct drm_sg_mem {
  424. unsigned long handle;
  425. void *virtual;
  426. int pages;
  427. struct page **pagelist;
  428. dma_addr_t *busaddr;
  429. } drm_sg_mem_t;
  430. typedef struct drm_sigdata {
  431. int context;
  432. drm_hw_lock_t *lock;
  433. } drm_sigdata_t;
  434. typedef struct drm_dma_handle {
  435. dma_addr_t busaddr;
  436. void *vaddr;
  437. size_t size;
  438. } drm_dma_handle_t;
  439. /**
  440. * Mappings list
  441. */
  442. typedef struct drm_map_list {
  443. struct list_head head; /**< list head */
  444. drm_map_t *map; /**< mapping */
  445. unsigned int user_token;
  446. } drm_map_list_t;
  447. typedef drm_map_t drm_local_map_t;
  448. /**
  449. * Context handle list
  450. */
  451. typedef struct drm_ctx_list {
  452. struct list_head head; /**< list head */
  453. drm_context_t handle; /**< context handle */
  454. drm_file_t *tag; /**< associated fd private data */
  455. } drm_ctx_list_t;
  456. typedef struct drm_vbl_sig {
  457. struct list_head head;
  458. unsigned int sequence;
  459. struct siginfo info;
  460. struct task_struct *task;
  461. } drm_vbl_sig_t;
  462. /**
  463. * DRM driver structure. This structure represent the common code for
  464. * a family of cards. There will one drm_device for each card present
  465. * in this family
  466. */
  467. struct drm_device;
  468. struct drm_driver {
  469. int (*preinit)(struct drm_device *, unsigned long flags);
  470. void (*prerelease)(struct drm_device *, struct file *filp);
  471. void (*pretakedown)(struct drm_device *);
  472. int (*postcleanup)(struct drm_device *);
  473. int (*presetup)(struct drm_device *);
  474. int (*postsetup)(struct drm_device *);
  475. int (*dma_ioctl)( DRM_IOCTL_ARGS );
  476. int (*open_helper)(struct drm_device *, drm_file_t *);
  477. void (*free_filp_priv)(struct drm_device *, drm_file_t *);
  478. void (*release)(struct drm_device *, struct file *filp);
  479. void (*dma_ready)(struct drm_device *);
  480. int (*dma_quiescent)(struct drm_device *);
  481. int (*context_ctor)(struct drm_device *dev, int context);
  482. int (*context_dtor)(struct drm_device *dev, int context);
  483. int (*kernel_context_switch)(struct drm_device *dev, int old, int new);
  484. void (*kernel_context_switch_unlock)(struct drm_device *dev, drm_lock_t *lock);
  485. int (*vblank_wait)(struct drm_device *dev, unsigned int *sequence);
  486. /**
  487. * Called by \c drm_device_is_agp. Typically used to determine if a
  488. * card is really attached to AGP or not.
  489. *
  490. * \param dev DRM device handle
  491. *
  492. * \returns
  493. * One of three values is returned depending on whether or not the
  494. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  495. * (return of 1), or may or may not be AGP (return of 2).
  496. */
  497. int (*device_is_agp) (struct drm_device * dev);
  498. /* these have to be filled in */
  499. int (*postinit)(struct drm_device *, unsigned long flags);
  500. irqreturn_t (*irq_handler)( DRM_IRQ_ARGS );
  501. void (*irq_preinstall)(struct drm_device *dev);
  502. void (*irq_postinstall)(struct drm_device *dev);
  503. void (*irq_uninstall)(struct drm_device *dev);
  504. void (*reclaim_buffers)(struct drm_device *dev, struct file *filp);
  505. unsigned long (*get_map_ofs)(drm_map_t *map);
  506. unsigned long (*get_reg_ofs)(struct drm_device *dev);
  507. void (*set_version)(struct drm_device *dev, drm_set_version_t *sv);
  508. int (*version)(drm_version_t *version);
  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 semaphore struct_sem; /**< 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 semaphore ctxlist_sem; /**< 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. char buf[DRM_BSZ]; /**< Output buffer */
  610. char *buf_rp; /**< Read pointer */
  611. char *buf_wp; /**< Write pointer */
  612. char *buf_end; /**< End pointer */
  613. struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  614. wait_queue_head_t buf_readers; /**< Processes waiting to read */
  615. wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
  616. drm_agp_head_t *agp; /**< AGP data */
  617. struct pci_dev *pdev; /**< PCI device structure */
  618. int pci_domain; /**< PCI bus domain number */
  619. int pci_bus; /**< PCI bus number */
  620. int pci_slot; /**< PCI slot number */
  621. int pci_func; /**< PCI function number */
  622. #ifdef __alpha__
  623. struct pci_controller *hose;
  624. #endif
  625. drm_sg_mem_t *sg; /**< Scatter gather memory */
  626. unsigned long *ctx_bitmap; /**< context bitmap */
  627. void *dev_private; /**< device private data */
  628. drm_sigdata_t sigdata; /**< For block_all_signals */
  629. sigset_t sigmask;
  630. struct drm_driver *driver;
  631. drm_local_map_t *agp_buffer_map;
  632. unsigned int agp_buffer_token;
  633. drm_head_t primary; /**< primary screen head */
  634. } drm_device_t;
  635. static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature)
  636. {
  637. return ((dev->driver->driver_features & feature) ? 1 : 0);
  638. }
  639. #if __OS_HAS_AGP
  640. static inline int drm_core_has_AGP(struct drm_device *dev)
  641. {
  642. return drm_core_check_feature(dev, DRIVER_USE_AGP);
  643. }
  644. #else
  645. #define drm_core_has_AGP(dev) (0)
  646. #endif
  647. #if __OS_HAS_MTRR
  648. static inline int drm_core_has_MTRR(struct drm_device *dev)
  649. {
  650. return drm_core_check_feature(dev, DRIVER_USE_MTRR);
  651. }
  652. #else
  653. #define drm_core_has_MTRR(dev) (0)
  654. #endif
  655. /******************************************************************/
  656. /** \name Internal function definitions */
  657. /*@{*/
  658. /* Misc. support (drm_init.h) */
  659. extern int drm_flags;
  660. extern void drm_parse_options( char *s );
  661. extern int drm_cpu_valid( void );
  662. /* Driver support (drm_drv.h) */
  663. extern int drm_init(struct drm_driver *driver);
  664. extern void drm_exit(struct drm_driver *driver);
  665. extern int drm_ioctl(struct inode *inode, struct file *filp,
  666. unsigned int cmd, unsigned long arg);
  667. extern long drm_compat_ioctl(struct file *filp,
  668. unsigned int cmd, unsigned long arg);
  669. extern int drm_takedown(drm_device_t * dev);
  670. /* Device support (drm_fops.h) */
  671. extern int drm_open(struct inode *inode, struct file *filp);
  672. extern int drm_stub_open(struct inode *inode, struct file *filp);
  673. extern int drm_flush(struct file *filp);
  674. extern int drm_fasync(int fd, struct file *filp, int on);
  675. extern int drm_release(struct inode *inode, struct file *filp);
  676. /* Mapping support (drm_vm.h) */
  677. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  678. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  679. /* Memory management support (drm_memory.h) */
  680. #include "drm_memory.h"
  681. extern void drm_mem_init(void);
  682. extern int drm_mem_info(char *buf, char **start, off_t offset,
  683. int request, int *eof, void *data);
  684. extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
  685. int area);
  686. extern unsigned long drm_alloc_pages(int order, int area);
  687. extern void drm_free_pages(unsigned long address, int order,
  688. int area);
  689. extern void *drm_ioremap(unsigned long offset, unsigned long size, drm_device_t *dev);
  690. extern void *drm_ioremap_nocache(unsigned long offset, unsigned long size,
  691. drm_device_t *dev);
  692. extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t *dev);
  693. extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t *dev, int pages, u32 type);
  694. extern int drm_free_agp(DRM_AGP_MEM *handle, int pages);
  695. extern int drm_bind_agp(DRM_AGP_MEM *handle, unsigned int start);
  696. extern int drm_unbind_agp(DRM_AGP_MEM *handle);
  697. /* Misc. IOCTL support (drm_ioctl.h) */
  698. extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
  699. unsigned int cmd, unsigned long arg);
  700. extern int drm_getunique(struct inode *inode, struct file *filp,
  701. unsigned int cmd, unsigned long arg);
  702. extern int drm_setunique(struct inode *inode, struct file *filp,
  703. unsigned int cmd, unsigned long arg);
  704. extern int drm_getmap(struct inode *inode, struct file *filp,
  705. unsigned int cmd, unsigned long arg);
  706. extern int drm_getclient(struct inode *inode, struct file *filp,
  707. unsigned int cmd, unsigned long arg);
  708. extern int drm_getstats(struct inode *inode, struct file *filp,
  709. unsigned int cmd, unsigned long arg);
  710. extern int drm_setversion(struct inode *inode, struct file *filp,
  711. unsigned int cmd, unsigned long arg);
  712. /* Context IOCTL support (drm_context.h) */
  713. extern int drm_resctx( struct inode *inode, struct file *filp,
  714. unsigned int cmd, unsigned long arg );
  715. extern int drm_addctx( struct inode *inode, struct file *filp,
  716. unsigned int cmd, unsigned long arg );
  717. extern int drm_modctx( struct inode *inode, struct file *filp,
  718. unsigned int cmd, unsigned long arg );
  719. extern int drm_getctx( struct inode *inode, struct file *filp,
  720. unsigned int cmd, unsigned long arg );
  721. extern int drm_switchctx( struct inode *inode, struct file *filp,
  722. unsigned int cmd, unsigned long arg );
  723. extern int drm_newctx( struct inode *inode, struct file *filp,
  724. unsigned int cmd, unsigned long arg );
  725. extern int drm_rmctx( struct inode *inode, struct file *filp,
  726. unsigned int cmd, unsigned long arg );
  727. extern int drm_ctxbitmap_init( drm_device_t *dev );
  728. extern void drm_ctxbitmap_cleanup( drm_device_t *dev );
  729. extern void drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle );
  730. extern int drm_setsareactx( struct inode *inode, struct file *filp,
  731. unsigned int cmd, unsigned long arg );
  732. extern int drm_getsareactx( struct inode *inode, struct file *filp,
  733. unsigned int cmd, unsigned long arg );
  734. /* Drawable IOCTL support (drm_drawable.h) */
  735. extern int drm_adddraw(struct inode *inode, struct file *filp,
  736. unsigned int cmd, unsigned long arg);
  737. extern int drm_rmdraw(struct inode *inode, struct file *filp,
  738. unsigned int cmd, unsigned long arg);
  739. /* Authentication IOCTL support (drm_auth.h) */
  740. extern int drm_getmagic(struct inode *inode, struct file *filp,
  741. unsigned int cmd, unsigned long arg);
  742. extern int drm_authmagic(struct inode *inode, struct file *filp,
  743. unsigned int cmd, unsigned long arg);
  744. /* Placeholder for ioctls past */
  745. extern int drm_noop(struct inode *inode, struct file *filp,
  746. unsigned int cmd, unsigned long arg);
  747. /* Locking IOCTL support (drm_lock.h) */
  748. extern int drm_lock(struct inode *inode, struct file *filp,
  749. unsigned int cmd, unsigned long arg);
  750. extern int drm_unlock(struct inode *inode, struct file *filp,
  751. unsigned int cmd, unsigned long arg);
  752. extern int drm_lock_take(__volatile__ unsigned int *lock,
  753. unsigned int context);
  754. extern int drm_lock_free(drm_device_t *dev,
  755. __volatile__ unsigned int *lock,
  756. unsigned int context);
  757. /* Buffer management support (drm_bufs.h) */
  758. extern int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
  759. extern int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
  760. extern int drm_addmap(drm_device_t *dev, unsigned int offset,
  761. unsigned int size, drm_map_type_t type,
  762. drm_map_flags_t flags, drm_local_map_t **map_ptr);
  763. extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
  764. unsigned int cmd, unsigned long arg);
  765. extern int drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
  766. extern int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map);
  767. extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
  768. unsigned int cmd, unsigned long arg);
  769. extern int drm_order( unsigned long size );
  770. extern int drm_addbufs( struct inode *inode, struct file *filp,
  771. unsigned int cmd, unsigned long arg );
  772. extern int drm_infobufs( struct inode *inode, struct file *filp,
  773. unsigned int cmd, unsigned long arg );
  774. extern int drm_markbufs( struct inode *inode, struct file *filp,
  775. unsigned int cmd, unsigned long arg );
  776. extern int drm_freebufs( struct inode *inode, struct file *filp,
  777. unsigned int cmd, unsigned long arg );
  778. extern int drm_mapbufs( struct inode *inode, struct file *filp,
  779. unsigned int cmd, unsigned long arg );
  780. extern unsigned long drm_get_resource_start(drm_device_t *dev,
  781. unsigned int resource);
  782. extern unsigned long drm_get_resource_len(drm_device_t *dev,
  783. unsigned int resource);
  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(drm_device_t * dev);
  804. extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
  805. unsigned int cmd, unsigned long arg);
  806. extern int drm_agp_release(drm_device_t *dev);
  807. extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
  808. unsigned int cmd, unsigned long arg);
  809. extern int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
  810. extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
  811. unsigned int cmd, unsigned long arg);
  812. extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
  813. extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
  814. unsigned int cmd, unsigned long arg);
  815. extern int drm_agp_alloc(struct inode *inode, struct file *filp,
  816. unsigned int cmd, unsigned long arg);
  817. extern int drm_agp_free(struct inode *inode, struct file *filp,
  818. unsigned int cmd, unsigned long arg);
  819. extern int drm_agp_unbind(struct inode *inode, struct file *filp,
  820. unsigned int cmd, unsigned long arg);
  821. extern int drm_agp_bind(struct inode *inode, struct file *filp,
  822. unsigned int cmd, unsigned long arg);
  823. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
  824. extern int drm_agp_free_memory(DRM_AGP_MEM *handle);
  825. extern int drm_agp_bind_memory(DRM_AGP_MEM *handle, off_t start);
  826. extern int drm_agp_unbind_memory(DRM_AGP_MEM *handle);
  827. /* Stub support (drm_stub.h) */
  828. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  829. struct drm_driver *driver);
  830. extern int drm_put_dev(drm_device_t * dev);
  831. extern int drm_put_head(drm_head_t * head);
  832. extern unsigned int drm_debug;
  833. extern unsigned int drm_cards_limit;
  834. extern drm_head_t **drm_heads;
  835. extern struct drm_sysfs_class *drm_class;
  836. extern struct proc_dir_entry *drm_proc_root;
  837. /* Proc support (drm_proc.h) */
  838. extern int drm_proc_init(drm_device_t *dev,
  839. int minor,
  840. struct proc_dir_entry *root,
  841. struct proc_dir_entry **dev_root);
  842. extern int drm_proc_cleanup(int minor,
  843. struct proc_dir_entry *root,
  844. struct proc_dir_entry *dev_root);
  845. /* Scatter Gather Support (drm_scatter.h) */
  846. extern void drm_sg_cleanup(drm_sg_mem_t *entry);
  847. extern int drm_sg_alloc(struct inode *inode, struct file *filp,
  848. unsigned int cmd, unsigned long arg);
  849. extern int drm_sg_free(struct inode *inode, struct file *filp,
  850. unsigned int cmd, unsigned long arg);
  851. /* ATI PCIGART support (ati_pcigart.h) */
  852. extern int drm_ati_pcigart_init(drm_device_t *dev,
  853. unsigned long *addr,
  854. dma_addr_t *bus_addr);
  855. extern int drm_ati_pcigart_cleanup(drm_device_t *dev,
  856. unsigned long addr,
  857. dma_addr_t bus_addr);
  858. extern drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size,
  859. size_t align, dma_addr_t maxaddr);
  860. extern void __drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
  861. extern void drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
  862. /* sysfs support (drm_sysfs.c) */
  863. struct drm_sysfs_class;
  864. extern struct drm_sysfs_class *drm_sysfs_create(struct module *owner,
  865. char *name);
  866. extern void drm_sysfs_destroy(struct drm_sysfs_class *cs);
  867. extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
  868. dev_t dev,
  869. struct device *device,
  870. const char *fmt, ...);
  871. extern void drm_sysfs_device_remove(dev_t dev);
  872. /* Inline replacements for DRM_IOREMAP macros */
  873. static __inline__ void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
  874. {
  875. map->handle = drm_ioremap( map->offset, map->size, dev );
  876. }
  877. static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, struct drm_device *dev)
  878. {
  879. map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
  880. }
  881. static __inline__ void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
  882. {
  883. if ( map->handle && map->size )
  884. drm_ioremapfree( map->handle, map->size, dev );
  885. }
  886. static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsigned int token)
  887. {
  888. drm_map_list_t *_entry;
  889. list_for_each_entry(_entry, &dev->maplist->head, head)
  890. if (_entry->user_token == token)
  891. return _entry->map;
  892. return NULL;
  893. }
  894. static __inline__ int drm_device_is_agp(drm_device_t *dev)
  895. {
  896. if ( dev->driver->device_is_agp != NULL ) {
  897. int err = (*dev->driver->device_is_agp)( dev );
  898. if (err != 2) {
  899. return err;
  900. }
  901. }
  902. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  903. }
  904. static __inline__ void drm_core_dropmap(struct drm_map *map)
  905. {
  906. }
  907. #ifndef DEBUG_MEMORY
  908. /** Wrapper around kmalloc() */
  909. static __inline__ void *drm_alloc(size_t size, int area)
  910. {
  911. return kmalloc(size, GFP_KERNEL);
  912. }
  913. /** Wrapper around kfree() */
  914. static __inline__ void drm_free(void *pt, size_t size, int area)
  915. {
  916. kfree(pt);
  917. }
  918. /** Wrapper around kcalloc() */
  919. static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
  920. {
  921. return kcalloc(nmemb, size, GFP_KERNEL);
  922. }
  923. #else
  924. extern void *drm_alloc(size_t size, int area);
  925. extern void drm_free(void *pt, size_t size, int area);
  926. extern void *drm_calloc(size_t nmemb, size_t size, int area);
  927. #endif
  928. /*@}*/
  929. extern unsigned long drm_core_get_map_ofs(drm_map_t *map);
  930. extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
  931. #ifndef pci_pretty_name
  932. #define pci_pretty_name(dev) ""
  933. #endif
  934. #endif /* __KERNEL__ */
  935. #endif