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