drmP.h 35 KB

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