drmP.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  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. #ifdef __KERNEL__
  35. #ifdef __alpha__
  36. /* add include of current.h so that "current" is defined
  37. * before static inline funcs in wait.h. Doing this so we
  38. * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  39. #include <asm/current.h>
  40. #endif /* __alpha__ */
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/miscdevice.h>
  44. #include <linux/fs.h>
  45. #include <linux/proc_fs.h>
  46. #include <linux/init.h>
  47. #include <linux/file.h>
  48. #include <linux/pci.h>
  49. #include <linux/jiffies.h>
  50. #include <linux/smp_lock.h> /* For (un)lock_kernel */
  51. #include <linux/dma-mapping.h>
  52. #include <linux/mm.h>
  53. #include <linux/cdev.h>
  54. #include <linux/mutex.h>
  55. #if defined(__alpha__) || defined(__powerpc__)
  56. #include <asm/pgtable.h> /* For pte_wrprotect */
  57. #endif
  58. #include <asm/io.h>
  59. #include <asm/mman.h>
  60. #include <asm/uaccess.h>
  61. #ifdef CONFIG_MTRR
  62. #include <asm/mtrr.h>
  63. #endif
  64. #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
  65. #include <linux/types.h>
  66. #include <linux/agp_backend.h>
  67. #endif
  68. #include <linux/workqueue.h>
  69. #include <linux/poll.h>
  70. #include <asm/pgalloc.h>
  71. #include "drm.h"
  72. #include <linux/idr.h>
  73. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  74. #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
  75. struct drm_file;
  76. struct drm_device;
  77. #include "drm_os_linux.h"
  78. #include "drm_hashtab.h"
  79. #include "drm_mm.h"
  80. #define DRM_UT_CORE 0x01
  81. #define DRM_UT_DRIVER 0x02
  82. #define DRM_UT_KMS 0x04
  83. /*
  84. * Three debug levels are defined.
  85. * drm_core, drm_driver, drm_kms
  86. * drm_core level can be used in the generic drm code. For example:
  87. * drm_ioctl, drm_mm, drm_memory
  88. * The macro definiton of DRM_DEBUG is used.
  89. * DRM_DEBUG(fmt, args...)
  90. * The debug info by using the DRM_DEBUG can be obtained by adding
  91. * the boot option of "drm.debug=1".
  92. *
  93. * drm_driver level can be used in the specific drm driver. It is used
  94. * to add the debug info related with the drm driver. For example:
  95. * i915_drv, i915_dma, i915_gem, radeon_drv,
  96. * The macro definition of DRM_DEBUG_DRIVER can be used.
  97. * DRM_DEBUG_DRIVER(fmt, args...)
  98. * The debug info by using the DRM_DEBUG_DRIVER can be obtained by
  99. * adding the boot option of "drm.debug=0x02"
  100. *
  101. * drm_kms level can be used in the KMS code related with specific drm driver.
  102. * It is used to add the debug info related with KMS mode. For example:
  103. * the connector/crtc ,
  104. * The macro definition of DRM_DEBUG_KMS can be used.
  105. * DRM_DEBUG_KMS(fmt, args...)
  106. * The debug info by using the DRM_DEBUG_KMS can be obtained by
  107. * adding the boot option of "drm.debug=0x04"
  108. *
  109. * If we add the boot option of "drm.debug=0x06", we can get the debug info by
  110. * using the DRM_DEBUG_KMS and DRM_DEBUG_DRIVER.
  111. * If we add the boot option of "drm.debug=0x05", we can get the debug info by
  112. * using the DRM_DEBUG_KMS and DRM_DEBUG.
  113. */
  114. extern void drm_ut_debug_printk(unsigned int request_level,
  115. const char *prefix,
  116. const char *function_name,
  117. const char *format, ...);
  118. /***********************************************************************/
  119. /** \name DRM template customization defaults */
  120. /*@{*/
  121. /* driver capabilities and requirements mask */
  122. #define DRIVER_USE_AGP 0x1
  123. #define DRIVER_REQUIRE_AGP 0x2
  124. #define DRIVER_USE_MTRR 0x4
  125. #define DRIVER_PCI_DMA 0x8
  126. #define DRIVER_SG 0x10
  127. #define DRIVER_HAVE_DMA 0x20
  128. #define DRIVER_HAVE_IRQ 0x40
  129. #define DRIVER_IRQ_SHARED 0x80
  130. #define DRIVER_IRQ_VBL 0x100
  131. #define DRIVER_DMA_QUEUE 0x200
  132. #define DRIVER_FB_DMA 0x400
  133. #define DRIVER_IRQ_VBL2 0x800
  134. #define DRIVER_GEM 0x1000
  135. #define DRIVER_MODESET 0x2000
  136. /***********************************************************************/
  137. /** \name Begin the DRM... */
  138. /*@{*/
  139. #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
  140. also include looping detection. */
  141. #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
  142. #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
  143. #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
  144. #define DRM_LOOPING_LIMIT 5000000
  145. #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
  146. #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
  147. #define DRM_FLAG_DEBUG 0x01
  148. #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
  149. #define DRM_MAP_HASH_OFFSET 0x10000000
  150. /*@}*/
  151. /***********************************************************************/
  152. /** \name Macros to make printk easier */
  153. /*@{*/
  154. /**
  155. * Error output.
  156. *
  157. * \param fmt printf() like format string.
  158. * \param arg arguments
  159. */
  160. #define DRM_ERROR(fmt, arg...) \
  161. printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
  162. /**
  163. * Memory error output.
  164. *
  165. * \param area memory area where the error occurred.
  166. * \param fmt printf() like format string.
  167. * \param arg arguments
  168. */
  169. #define DRM_MEM_ERROR(area, fmt, arg...) \
  170. printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
  171. drm_mem_stats[area].name , ##arg)
  172. #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
  173. /**
  174. * Debug output.
  175. *
  176. * \param fmt printf() like format string.
  177. * \param arg arguments
  178. */
  179. #if DRM_DEBUG_CODE
  180. #define DRM_DEBUG(fmt, args...) \
  181. do { \
  182. drm_ut_debug_printk(DRM_UT_CORE, DRM_NAME, \
  183. __func__, fmt, ##args); \
  184. } while (0)
  185. #define DRM_DEBUG_DRIVER(fmt, args...) \
  186. do { \
  187. drm_ut_debug_printk(DRM_UT_DRIVER, DRM_NAME, \
  188. __func__, fmt, ##args); \
  189. } while (0)
  190. #define DRM_DEBUG_KMS(fmt, args...) \
  191. do { \
  192. drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \
  193. __func__, fmt, ##args); \
  194. } while (0)
  195. #define DRM_LOG(fmt, args...) \
  196. do { \
  197. drm_ut_debug_printk(DRM_UT_CORE, NULL, \
  198. NULL, fmt, ##args); \
  199. } while (0)
  200. #define DRM_LOG_KMS(fmt, args...) \
  201. do { \
  202. drm_ut_debug_printk(DRM_UT_KMS, NULL, \
  203. NULL, fmt, ##args); \
  204. } while (0)
  205. #define DRM_LOG_MODE(fmt, args...) \
  206. do { \
  207. drm_ut_debug_printk(DRM_UT_MODE, NULL, \
  208. NULL, fmt, ##args); \
  209. } while (0)
  210. #define DRM_LOG_DRIVER(fmt, args...) \
  211. do { \
  212. drm_ut_debug_printk(DRM_UT_DRIVER, NULL, \
  213. NULL, fmt, ##args); \
  214. } while (0)
  215. #else
  216. #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
  217. #define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
  218. #define DRM_DEBUG(fmt, arg...) do { } while (0)
  219. #define DRM_LOG(fmt, arg...) do { } while (0)
  220. #define DRM_LOG_KMS(fmt, args...) do { } while (0)
  221. #define DRM_LOG_MODE(fmt, arg...) do { } while (0)
  222. #define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
  223. #endif
  224. /*@}*/
  225. /***********************************************************************/
  226. /** \name Internal types and structures */
  227. /*@{*/
  228. #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
  229. #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
  230. #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
  231. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  232. /**
  233. * Test that the hardware lock is held by the caller, returning otherwise.
  234. *
  235. * \param dev DRM device.
  236. * \param filp file pointer of the caller.
  237. */
  238. #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
  239. do { \
  240. if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
  241. _file_priv->master->lock.file_priv != _file_priv) { \
  242. DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
  243. __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  244. _file_priv->master->lock.file_priv, _file_priv); \
  245. return -EINVAL; \
  246. } \
  247. } while (0)
  248. /**
  249. * Ioctl function type.
  250. *
  251. * \param inode device inode.
  252. * \param file_priv DRM file private pointer.
  253. * \param cmd command.
  254. * \param arg argument.
  255. */
  256. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  257. struct drm_file *file_priv);
  258. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  259. unsigned long arg);
  260. #define DRM_AUTH 0x1
  261. #define DRM_MASTER 0x2
  262. #define DRM_ROOT_ONLY 0x4
  263. #define DRM_CONTROL_ALLOW 0x8
  264. struct drm_ioctl_desc {
  265. unsigned int cmd;
  266. int flags;
  267. drm_ioctl_t *func;
  268. };
  269. /**
  270. * Creates a driver or general drm_ioctl_desc array entry for the given
  271. * ioctl, for use by drm_ioctl().
  272. */
  273. #define DRM_IOCTL_DEF(ioctl, _func, _flags) \
  274. [DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags}
  275. struct drm_magic_entry {
  276. struct list_head head;
  277. struct drm_hash_item hash_item;
  278. struct drm_file *priv;
  279. };
  280. struct drm_vma_entry {
  281. struct list_head head;
  282. struct vm_area_struct *vma;
  283. pid_t pid;
  284. };
  285. /**
  286. * DMA buffer.
  287. */
  288. struct drm_buf {
  289. int idx; /**< Index into master buflist */
  290. int total; /**< Buffer size */
  291. int order; /**< log-base-2(total) */
  292. int used; /**< Amount of buffer in use (for DMA) */
  293. unsigned long offset; /**< Byte offset (used internally) */
  294. void *address; /**< Address of buffer */
  295. unsigned long bus_address; /**< Bus address of buffer */
  296. struct drm_buf *next; /**< Kernel-only: used for free list */
  297. __volatile__ int waiting; /**< On kernel DMA queue */
  298. __volatile__ int pending; /**< On hardware DMA queue */
  299. wait_queue_head_t dma_wait; /**< Processes waiting */
  300. struct drm_file *file_priv; /**< Private of holding file descr */
  301. int context; /**< Kernel queue for this buffer */
  302. int while_locked; /**< Dispatch this buffer while locked */
  303. enum {
  304. DRM_LIST_NONE = 0,
  305. DRM_LIST_FREE = 1,
  306. DRM_LIST_WAIT = 2,
  307. DRM_LIST_PEND = 3,
  308. DRM_LIST_PRIO = 4,
  309. DRM_LIST_RECLAIM = 5
  310. } list; /**< Which list we're on */
  311. int dev_priv_size; /**< Size of buffer private storage */
  312. void *dev_private; /**< Per-buffer private storage */
  313. };
  314. /** bufs is one longer than it has to be */
  315. struct drm_waitlist {
  316. int count; /**< Number of possible buffers */
  317. struct drm_buf **bufs; /**< List of pointers to buffers */
  318. struct drm_buf **rp; /**< Read pointer */
  319. struct drm_buf **wp; /**< Write pointer */
  320. struct drm_buf **end; /**< End pointer */
  321. spinlock_t read_lock;
  322. spinlock_t write_lock;
  323. };
  324. struct drm_freelist {
  325. int initialized; /**< Freelist in use */
  326. atomic_t count; /**< Number of free buffers */
  327. struct drm_buf *next; /**< End pointer */
  328. wait_queue_head_t waiting; /**< Processes waiting on free bufs */
  329. int low_mark; /**< Low water mark */
  330. int high_mark; /**< High water mark */
  331. atomic_t wfh; /**< If waiting for high mark */
  332. spinlock_t lock;
  333. };
  334. typedef struct drm_dma_handle {
  335. dma_addr_t busaddr;
  336. void *vaddr;
  337. size_t size;
  338. } drm_dma_handle_t;
  339. /**
  340. * Buffer entry. There is one of this for each buffer size order.
  341. */
  342. struct drm_buf_entry {
  343. int buf_size; /**< size */
  344. int buf_count; /**< number of buffers */
  345. struct drm_buf *buflist; /**< buffer list */
  346. int seg_count;
  347. int page_order;
  348. struct drm_dma_handle **seglist;
  349. struct drm_freelist freelist;
  350. };
  351. /* Event queued up for userspace to read */
  352. struct drm_pending_event {
  353. struct drm_event *event;
  354. struct list_head link;
  355. struct drm_file *file_priv;
  356. void (*destroy)(struct drm_pending_event *event);
  357. };
  358. /** File private data */
  359. struct drm_file {
  360. int authenticated;
  361. pid_t pid;
  362. uid_t uid;
  363. drm_magic_t magic;
  364. unsigned long ioctl_count;
  365. struct list_head lhead;
  366. struct drm_minor *minor;
  367. unsigned long lock_count;
  368. /** Mapping of mm object handles to object pointers. */
  369. struct idr object_idr;
  370. /** Lock for synchronization of access to object_idr. */
  371. spinlock_t table_lock;
  372. struct file *filp;
  373. void *driver_priv;
  374. int is_master; /* this file private is a master for a minor */
  375. struct drm_master *master; /* master this node is currently associated with
  376. N.B. not always minor->master */
  377. struct list_head fbs;
  378. wait_queue_head_t event_wait;
  379. struct list_head event_list;
  380. int event_space;
  381. };
  382. /** Wait queue */
  383. struct drm_queue {
  384. atomic_t use_count; /**< Outstanding uses (+1) */
  385. atomic_t finalization; /**< Finalization in progress */
  386. atomic_t block_count; /**< Count of processes waiting */
  387. atomic_t block_read; /**< Queue blocked for reads */
  388. wait_queue_head_t read_queue; /**< Processes waiting on block_read */
  389. atomic_t block_write; /**< Queue blocked for writes */
  390. wait_queue_head_t write_queue; /**< Processes waiting on block_write */
  391. atomic_t total_queued; /**< Total queued statistic */
  392. atomic_t total_flushed; /**< Total flushes statistic */
  393. atomic_t total_locks; /**< Total locks statistics */
  394. enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
  395. struct drm_waitlist waitlist; /**< Pending buffers */
  396. wait_queue_head_t flush_queue; /**< Processes waiting until flush */
  397. };
  398. /**
  399. * Lock data.
  400. */
  401. struct drm_lock_data {
  402. struct drm_hw_lock *hw_lock; /**< Hardware lock */
  403. /** Private of lock holder's file (NULL=kernel) */
  404. struct drm_file *file_priv;
  405. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  406. unsigned long lock_time; /**< Time of last lock in jiffies */
  407. spinlock_t spinlock;
  408. uint32_t kernel_waiters;
  409. uint32_t user_waiters;
  410. int idle_has_lock;
  411. };
  412. /**
  413. * DMA data.
  414. */
  415. struct drm_device_dma {
  416. struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  417. int buf_count; /**< total number of buffers */
  418. struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  419. int seg_count;
  420. int page_count; /**< number of pages */
  421. unsigned long *pagelist; /**< page list */
  422. unsigned long byte_count;
  423. enum {
  424. _DRM_DMA_USE_AGP = 0x01,
  425. _DRM_DMA_USE_SG = 0x02,
  426. _DRM_DMA_USE_FB = 0x04,
  427. _DRM_DMA_USE_PCI_RO = 0x08
  428. } flags;
  429. };
  430. /**
  431. * AGP memory entry. Stored as a doubly linked list.
  432. */
  433. struct drm_agp_mem {
  434. unsigned long handle; /**< handle */
  435. DRM_AGP_MEM *memory;
  436. unsigned long bound; /**< address */
  437. int pages;
  438. struct list_head head;
  439. };
  440. /**
  441. * AGP data.
  442. *
  443. * \sa drm_agp_init() and drm_device::agp.
  444. */
  445. struct drm_agp_head {
  446. DRM_AGP_KERN agp_info; /**< AGP device information */
  447. struct list_head memory;
  448. unsigned long mode; /**< AGP mode */
  449. struct agp_bridge_data *bridge;
  450. int enabled; /**< whether the AGP bus as been enabled */
  451. int acquired; /**< whether the AGP device has been acquired */
  452. unsigned long base;
  453. int agp_mtrr;
  454. int cant_use_aperture;
  455. unsigned long page_mask;
  456. };
  457. /**
  458. * Scatter-gather memory.
  459. */
  460. struct drm_sg_mem {
  461. unsigned long handle;
  462. void *virtual;
  463. int pages;
  464. struct page **pagelist;
  465. dma_addr_t *busaddr;
  466. };
  467. struct drm_sigdata {
  468. int context;
  469. struct drm_hw_lock *lock;
  470. };
  471. /**
  472. * Kernel side of a mapping
  473. */
  474. struct drm_local_map {
  475. resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
  476. unsigned long size; /**< Requested physical size (bytes) */
  477. enum drm_map_type type; /**< Type of memory to map */
  478. enum drm_map_flags flags; /**< Flags */
  479. void *handle; /**< User-space: "Handle" to pass to mmap() */
  480. /**< Kernel-space: kernel-virtual address */
  481. int mtrr; /**< MTRR slot used */
  482. };
  483. typedef struct drm_local_map drm_local_map_t;
  484. /**
  485. * Mappings list
  486. */
  487. struct drm_map_list {
  488. struct list_head head; /**< list head */
  489. struct drm_hash_item hash;
  490. struct drm_local_map *map; /**< mapping */
  491. uint64_t user_token;
  492. struct drm_master *master;
  493. struct drm_mm_node *file_offset_node; /**< fake offset */
  494. };
  495. /**
  496. * Context handle list
  497. */
  498. struct drm_ctx_list {
  499. struct list_head head; /**< list head */
  500. drm_context_t handle; /**< context handle */
  501. struct drm_file *tag; /**< associated fd private data */
  502. };
  503. /* location of GART table */
  504. #define DRM_ATI_GART_MAIN 1
  505. #define DRM_ATI_GART_FB 2
  506. #define DRM_ATI_GART_PCI 1
  507. #define DRM_ATI_GART_PCIE 2
  508. #define DRM_ATI_GART_IGP 3
  509. struct drm_ati_pcigart_info {
  510. int gart_table_location;
  511. int gart_reg_if;
  512. void *addr;
  513. dma_addr_t bus_addr;
  514. dma_addr_t table_mask;
  515. struct drm_dma_handle *table_handle;
  516. struct drm_local_map mapping;
  517. int table_size;
  518. };
  519. /**
  520. * GEM specific mm private for tracking GEM objects
  521. */
  522. struct drm_gem_mm {
  523. struct drm_mm offset_manager; /**< Offset mgmt for buffer objects */
  524. struct drm_open_hash offset_hash; /**< User token hash table for maps */
  525. };
  526. /**
  527. * This structure defines the drm_mm memory object, which will be used by the
  528. * DRM for its buffer objects.
  529. */
  530. struct drm_gem_object {
  531. /** Reference count of this object */
  532. struct kref refcount;
  533. /** Handle count of this object. Each handle also holds a reference */
  534. struct kref handlecount;
  535. /** Related drm device */
  536. struct drm_device *dev;
  537. /** File representing the shmem storage */
  538. struct file *filp;
  539. /* Mapping info for this object */
  540. struct drm_map_list map_list;
  541. /**
  542. * Size of the object, in bytes. Immutable over the object's
  543. * lifetime.
  544. */
  545. size_t size;
  546. /**
  547. * Global name for this object, starts at 1. 0 means unnamed.
  548. * Access is covered by the object_name_lock in the related drm_device
  549. */
  550. int name;
  551. /**
  552. * Memory domains. These monitor which caches contain read/write data
  553. * related to the object. When transitioning from one set of domains
  554. * to another, the driver is called to ensure that caches are suitably
  555. * flushed and invalidated
  556. */
  557. uint32_t read_domains;
  558. uint32_t write_domain;
  559. /**
  560. * While validating an exec operation, the
  561. * new read/write domain values are computed here.
  562. * They will be transferred to the above values
  563. * at the point that any cache flushing occurs
  564. */
  565. uint32_t pending_read_domains;
  566. uint32_t pending_write_domain;
  567. void *driver_private;
  568. };
  569. #include "drm_crtc.h"
  570. /* per-master structure */
  571. struct drm_master {
  572. struct kref refcount; /* refcount for this master */
  573. struct list_head head; /**< each minor contains a list of masters */
  574. struct drm_minor *minor; /**< link back to minor we are a master for */
  575. char *unique; /**< Unique identifier: e.g., busid */
  576. int unique_len; /**< Length of unique field */
  577. int unique_size; /**< amount allocated */
  578. int blocked; /**< Blocked due to VC switch? */
  579. /** \name Authentication */
  580. /*@{ */
  581. struct drm_open_hash magiclist;
  582. struct list_head magicfree;
  583. /*@} */
  584. struct drm_lock_data lock; /**< Information on hardware lock */
  585. void *driver_priv; /**< Private structure for driver to use */
  586. };
  587. /**
  588. * DRM driver structure. This structure represent the common code for
  589. * a family of cards. There will one drm_device for each card present
  590. * in this family
  591. */
  592. struct drm_driver {
  593. int (*load) (struct drm_device *, unsigned long flags);
  594. int (*firstopen) (struct drm_device *);
  595. int (*open) (struct drm_device *, struct drm_file *);
  596. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  597. void (*postclose) (struct drm_device *, struct drm_file *);
  598. void (*lastclose) (struct drm_device *);
  599. int (*unload) (struct drm_device *);
  600. int (*suspend) (struct drm_device *, pm_message_t state);
  601. int (*resume) (struct drm_device *);
  602. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  603. void (*dma_ready) (struct drm_device *);
  604. int (*dma_quiescent) (struct drm_device *);
  605. int (*context_ctor) (struct drm_device *dev, int context);
  606. int (*context_dtor) (struct drm_device *dev, int context);
  607. int (*kernel_context_switch) (struct drm_device *dev, int old,
  608. int new);
  609. void (*kernel_context_switch_unlock) (struct drm_device *dev);
  610. /**
  611. * get_vblank_counter - get raw hardware vblank counter
  612. * @dev: DRM device
  613. * @crtc: counter to fetch
  614. *
  615. * Driver callback for fetching a raw hardware vblank counter
  616. * for @crtc. If a device doesn't have a hardware counter, the
  617. * driver can simply return the value of drm_vblank_count and
  618. * make the enable_vblank() and disable_vblank() hooks into no-ops,
  619. * leaving interrupts enabled at all times.
  620. *
  621. * Wraparound handling and loss of events due to modesetting is dealt
  622. * with in the DRM core code.
  623. *
  624. * RETURNS
  625. * Raw vblank counter value.
  626. */
  627. u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  628. /**
  629. * enable_vblank - enable vblank interrupt events
  630. * @dev: DRM device
  631. * @crtc: which irq to enable
  632. *
  633. * Enable vblank interrupts for @crtc. If the device doesn't have
  634. * a hardware vblank counter, this routine should be a no-op, since
  635. * interrupts will have to stay on to keep the count accurate.
  636. *
  637. * RETURNS
  638. * Zero on success, appropriate errno if the given @crtc's vblank
  639. * interrupt cannot be enabled.
  640. */
  641. int (*enable_vblank) (struct drm_device *dev, int crtc);
  642. /**
  643. * disable_vblank - disable vblank interrupt events
  644. * @dev: DRM device
  645. * @crtc: which irq to enable
  646. *
  647. * Disable vblank interrupts for @crtc. If the device doesn't have
  648. * a hardware vblank counter, this routine should be a no-op, since
  649. * interrupts will have to stay on to keep the count accurate.
  650. */
  651. void (*disable_vblank) (struct drm_device *dev, int crtc);
  652. /**
  653. * Called by \c drm_device_is_agp. Typically used to determine if a
  654. * card is really attached to AGP or not.
  655. *
  656. * \param dev DRM device handle
  657. *
  658. * \returns
  659. * One of three values is returned depending on whether or not the
  660. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  661. * (return of 1), or may or may not be AGP (return of 2).
  662. */
  663. int (*device_is_agp) (struct drm_device *dev);
  664. /* these have to be filled in */
  665. irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  666. void (*irq_preinstall) (struct drm_device *dev);
  667. int (*irq_postinstall) (struct drm_device *dev);
  668. void (*irq_uninstall) (struct drm_device *dev);
  669. void (*reclaim_buffers) (struct drm_device *dev,
  670. struct drm_file * file_priv);
  671. void (*reclaim_buffers_locked) (struct drm_device *dev,
  672. struct drm_file *file_priv);
  673. void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
  674. struct drm_file *file_priv);
  675. resource_size_t (*get_map_ofs) (struct drm_local_map * map);
  676. resource_size_t (*get_reg_ofs) (struct drm_device *dev);
  677. void (*set_version) (struct drm_device *dev,
  678. struct drm_set_version *sv);
  679. /* Master routines */
  680. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  681. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  682. int (*proc_init)(struct drm_minor *minor);
  683. void (*proc_cleanup)(struct drm_minor *minor);
  684. int (*debugfs_init)(struct drm_minor *minor);
  685. void (*debugfs_cleanup)(struct drm_minor *minor);
  686. /**
  687. * Driver-specific constructor for drm_gem_objects, to set up
  688. * obj->driver_private.
  689. *
  690. * Returns 0 on success.
  691. */
  692. int (*gem_init_object) (struct drm_gem_object *obj);
  693. void (*gem_free_object) (struct drm_gem_object *obj);
  694. /* vga arb irq handler */
  695. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  696. /* Driver private ops for this object */
  697. struct vm_operations_struct *gem_vm_ops;
  698. int major;
  699. int minor;
  700. int patchlevel;
  701. char *name;
  702. char *desc;
  703. char *date;
  704. u32 driver_features;
  705. int dev_priv_size;
  706. struct drm_ioctl_desc *ioctls;
  707. int num_ioctls;
  708. struct file_operations fops;
  709. struct pci_driver pci_driver;
  710. /* List of devices hanging off this driver */
  711. struct list_head device_list;
  712. };
  713. #define DRM_MINOR_UNASSIGNED 0
  714. #define DRM_MINOR_LEGACY 1
  715. #define DRM_MINOR_CONTROL 2
  716. #define DRM_MINOR_RENDER 3
  717. /**
  718. * debugfs node list. This structure represents a debugfs file to
  719. * be created by the drm core
  720. */
  721. struct drm_debugfs_list {
  722. const char *name; /** file name */
  723. int (*show)(struct seq_file*, void*); /** show callback */
  724. u32 driver_features; /**< Required driver features for this entry */
  725. };
  726. /**
  727. * debugfs node structure. This structure represents a debugfs file.
  728. */
  729. struct drm_debugfs_node {
  730. struct list_head list;
  731. struct drm_minor *minor;
  732. struct drm_debugfs_list *debugfs_ent;
  733. struct dentry *dent;
  734. };
  735. /**
  736. * Info file list entry. This structure represents a debugfs or proc file to
  737. * be created by the drm core
  738. */
  739. struct drm_info_list {
  740. const char *name; /** file name */
  741. int (*show)(struct seq_file*, void*); /** show callback */
  742. u32 driver_features; /**< Required driver features for this entry */
  743. void *data;
  744. };
  745. /**
  746. * debugfs node structure. This structure represents a debugfs file.
  747. */
  748. struct drm_info_node {
  749. struct list_head list;
  750. struct drm_minor *minor;
  751. struct drm_info_list *info_ent;
  752. struct dentry *dent;
  753. };
  754. /**
  755. * DRM minor structure. This structure represents a drm minor number.
  756. */
  757. struct drm_minor {
  758. int index; /**< Minor device number */
  759. int type; /**< Control or render */
  760. dev_t device; /**< Device number for mknod */
  761. struct device kdev; /**< Linux device */
  762. struct drm_device *dev;
  763. struct proc_dir_entry *proc_root; /**< proc directory entry */
  764. struct drm_info_node proc_nodes;
  765. struct dentry *debugfs_root;
  766. struct drm_info_node debugfs_nodes;
  767. struct drm_master *master; /* currently active master for this node */
  768. struct list_head master_list;
  769. struct drm_mode_group mode_group;
  770. };
  771. struct drm_pending_vblank_event {
  772. struct drm_pending_event base;
  773. int pipe;
  774. struct drm_event_vblank event;
  775. };
  776. /**
  777. * DRM device structure. This structure represent a complete card that
  778. * may contain multiple heads.
  779. */
  780. struct drm_device {
  781. struct list_head driver_item; /**< list of devices per driver */
  782. char *devname; /**< For /proc/interrupts */
  783. int if_version; /**< Highest interface version set */
  784. /** \name Locks */
  785. /*@{ */
  786. spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
  787. struct mutex struct_mutex; /**< For others */
  788. /*@} */
  789. /** \name Usage Counters */
  790. /*@{ */
  791. int open_count; /**< Outstanding files open */
  792. atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
  793. atomic_t vma_count; /**< Outstanding vma areas open */
  794. int buf_use; /**< Buffers in use -- cannot alloc */
  795. atomic_t buf_alloc; /**< Buffer allocation in progress */
  796. /*@} */
  797. /** \name Performance counters */
  798. /*@{ */
  799. unsigned long counters;
  800. enum drm_stat_type types[15];
  801. atomic_t counts[15];
  802. /*@} */
  803. struct list_head filelist;
  804. /** \name Memory management */
  805. /*@{ */
  806. struct list_head maplist; /**< Linked list of regions */
  807. int map_count; /**< Number of mappable regions */
  808. struct drm_open_hash map_hash; /**< User token hash table for maps */
  809. /** \name Context handle management */
  810. /*@{ */
  811. struct list_head ctxlist; /**< Linked list of context handles */
  812. int ctx_count; /**< Number of context handles */
  813. struct mutex ctxlist_mutex; /**< For ctxlist */
  814. struct idr ctx_idr;
  815. struct list_head vmalist; /**< List of vmas (for debugging) */
  816. /*@} */
  817. /** \name DMA queues (contexts) */
  818. /*@{ */
  819. int queue_count; /**< Number of active DMA queues */
  820. int queue_reserved; /**< Number of reserved DMA queues */
  821. int queue_slots; /**< Actual length of queuelist */
  822. struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */
  823. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  824. /*@} */
  825. /** \name Context support */
  826. /*@{ */
  827. int irq_enabled; /**< True if irq handler is enabled */
  828. __volatile__ long context_flag; /**< Context swapping flag */
  829. __volatile__ long interrupt_flag; /**< Interruption handler flag */
  830. __volatile__ long dma_flag; /**< DMA dispatch flag */
  831. struct timer_list timer; /**< Timer for delaying ctx switch */
  832. wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
  833. int last_checked; /**< Last context checked for DMA */
  834. int last_context; /**< Last current context */
  835. unsigned long last_switch; /**< jiffies at last context switch */
  836. /*@} */
  837. struct work_struct work;
  838. /** \name VBLANK IRQ support */
  839. /*@{ */
  840. /*
  841. * At load time, disabling the vblank interrupt won't be allowed since
  842. * old clients may not call the modeset ioctl and therefore misbehave.
  843. * Once the modeset ioctl *has* been called though, we can safely
  844. * disable them when unused.
  845. */
  846. int vblank_disable_allowed;
  847. wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */
  848. atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
  849. spinlock_t vbl_lock;
  850. atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */
  851. u32 *last_vblank; /* protected by dev->vbl_lock, used */
  852. /* for wraparound handling */
  853. int *vblank_enabled; /* so we don't call enable more than
  854. once per disable */
  855. int *vblank_inmodeset; /* Display driver is setting mode */
  856. u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */
  857. struct timer_list vblank_disable_timer;
  858. u32 max_vblank_count; /**< size of vblank counter register */
  859. /**
  860. * List of events
  861. */
  862. struct list_head vblank_event_list;
  863. spinlock_t event_lock;
  864. /*@} */
  865. cycles_t ctx_start;
  866. cycles_t lck_start;
  867. struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  868. wait_queue_head_t buf_readers; /**< Processes waiting to read */
  869. wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
  870. struct drm_agp_head *agp; /**< AGP data */
  871. struct pci_dev *pdev; /**< PCI device structure */
  872. int pci_vendor; /**< PCI vendor id */
  873. int pci_device; /**< PCI device id */
  874. #ifdef __alpha__
  875. struct pci_controller *hose;
  876. #endif
  877. struct drm_sg_mem *sg; /**< Scatter gather memory */
  878. int num_crtcs; /**< Number of CRTCs on this device */
  879. void *dev_private; /**< device private data */
  880. void *mm_private;
  881. struct address_space *dev_mapping;
  882. struct drm_sigdata sigdata; /**< For block_all_signals */
  883. sigset_t sigmask;
  884. struct drm_driver *driver;
  885. struct drm_local_map *agp_buffer_map;
  886. unsigned int agp_buffer_token;
  887. struct drm_minor *control; /**< Control node for card */
  888. struct drm_minor *primary; /**< render type primary screen head */
  889. /** \name Drawable information */
  890. /*@{ */
  891. spinlock_t drw_lock;
  892. struct idr drw_idr;
  893. /*@} */
  894. struct drm_mode_config mode_config; /**< Current mode config */
  895. /** \name GEM information */
  896. /*@{ */
  897. spinlock_t object_name_lock;
  898. struct idr object_name_idr;
  899. atomic_t object_count;
  900. atomic_t object_memory;
  901. atomic_t pin_count;
  902. atomic_t pin_memory;
  903. atomic_t gtt_count;
  904. atomic_t gtt_memory;
  905. uint32_t gtt_total;
  906. uint32_t invalidate_domains; /* domains pending invalidation */
  907. uint32_t flush_domains; /* domains pending flush */
  908. /*@} */
  909. };
  910. static inline int drm_dev_to_irq(struct drm_device *dev)
  911. {
  912. return dev->pdev->irq;
  913. }
  914. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  915. int feature)
  916. {
  917. return ((dev->driver->driver_features & feature) ? 1 : 0);
  918. }
  919. #ifdef __alpha__
  920. #define drm_get_pci_domain(dev) dev->hose->index
  921. #else
  922. #define drm_get_pci_domain(dev) 0
  923. #endif
  924. #if __OS_HAS_AGP
  925. static inline int drm_core_has_AGP(struct drm_device *dev)
  926. {
  927. return drm_core_check_feature(dev, DRIVER_USE_AGP);
  928. }
  929. #else
  930. #define drm_core_has_AGP(dev) (0)
  931. #endif
  932. #if __OS_HAS_MTRR
  933. static inline int drm_core_has_MTRR(struct drm_device *dev)
  934. {
  935. return drm_core_check_feature(dev, DRIVER_USE_MTRR);
  936. }
  937. #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
  938. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  939. unsigned int flags)
  940. {
  941. return mtrr_add(offset, size, flags, 1);
  942. }
  943. static inline int drm_mtrr_del(int handle, unsigned long offset,
  944. unsigned long size, unsigned int flags)
  945. {
  946. return mtrr_del(handle, offset, size);
  947. }
  948. #else
  949. #define drm_core_has_MTRR(dev) (0)
  950. #define DRM_MTRR_WC 0
  951. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  952. unsigned int flags)
  953. {
  954. return 0;
  955. }
  956. static inline int drm_mtrr_del(int handle, unsigned long offset,
  957. unsigned long size, unsigned int flags)
  958. {
  959. return 0;
  960. }
  961. #endif
  962. /******************************************************************/
  963. /** \name Internal function definitions */
  964. /*@{*/
  965. /* Driver support (drm_drv.h) */
  966. extern int drm_init(struct drm_driver *driver);
  967. extern void drm_exit(struct drm_driver *driver);
  968. extern int drm_ioctl(struct inode *inode, struct file *filp,
  969. unsigned int cmd, unsigned long arg);
  970. extern long drm_compat_ioctl(struct file *filp,
  971. unsigned int cmd, unsigned long arg);
  972. extern int drm_lastclose(struct drm_device *dev);
  973. /* Device support (drm_fops.h) */
  974. extern int drm_open(struct inode *inode, struct file *filp);
  975. extern int drm_stub_open(struct inode *inode, struct file *filp);
  976. extern int drm_fasync(int fd, struct file *filp, int on);
  977. extern ssize_t drm_read(struct file *filp, char __user *buffer,
  978. size_t count, loff_t *offset);
  979. extern int drm_release(struct inode *inode, struct file *filp);
  980. /* Mapping support (drm_vm.h) */
  981. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  982. extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
  983. extern void drm_vm_open_locked(struct vm_area_struct *vma);
  984. extern resource_size_t drm_core_get_map_ofs(struct drm_local_map * map);
  985. extern resource_size_t drm_core_get_reg_ofs(struct drm_device *dev);
  986. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  987. /* Memory management support (drm_memory.h) */
  988. #include "drm_memory.h"
  989. extern void drm_mem_init(void);
  990. extern int drm_mem_info(char *buf, char **start, off_t offset,
  991. int request, int *eof, void *data);
  992. extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
  993. extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
  994. extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
  995. extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
  996. extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
  997. struct page **pages,
  998. unsigned long num_pages,
  999. uint32_t gtt_offset,
  1000. uint32_t type);
  1001. extern int drm_unbind_agp(DRM_AGP_MEM * handle);
  1002. /* Misc. IOCTL support (drm_ioctl.h) */
  1003. extern int drm_irq_by_busid(struct drm_device *dev, void *data,
  1004. struct drm_file *file_priv);
  1005. extern int drm_getunique(struct drm_device *dev, void *data,
  1006. struct drm_file *file_priv);
  1007. extern int drm_setunique(struct drm_device *dev, void *data,
  1008. struct drm_file *file_priv);
  1009. extern int drm_getmap(struct drm_device *dev, void *data,
  1010. struct drm_file *file_priv);
  1011. extern int drm_getclient(struct drm_device *dev, void *data,
  1012. struct drm_file *file_priv);
  1013. extern int drm_getstats(struct drm_device *dev, void *data,
  1014. struct drm_file *file_priv);
  1015. extern int drm_setversion(struct drm_device *dev, void *data,
  1016. struct drm_file *file_priv);
  1017. extern int drm_noop(struct drm_device *dev, void *data,
  1018. struct drm_file *file_priv);
  1019. /* Context IOCTL support (drm_context.h) */
  1020. extern int drm_resctx(struct drm_device *dev, void *data,
  1021. struct drm_file *file_priv);
  1022. extern int drm_addctx(struct drm_device *dev, void *data,
  1023. struct drm_file *file_priv);
  1024. extern int drm_modctx(struct drm_device *dev, void *data,
  1025. struct drm_file *file_priv);
  1026. extern int drm_getctx(struct drm_device *dev, void *data,
  1027. struct drm_file *file_priv);
  1028. extern int drm_switchctx(struct drm_device *dev, void *data,
  1029. struct drm_file *file_priv);
  1030. extern int drm_newctx(struct drm_device *dev, void *data,
  1031. struct drm_file *file_priv);
  1032. extern int drm_rmctx(struct drm_device *dev, void *data,
  1033. struct drm_file *file_priv);
  1034. extern int drm_ctxbitmap_init(struct drm_device *dev);
  1035. extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
  1036. extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
  1037. extern int drm_setsareactx(struct drm_device *dev, void *data,
  1038. struct drm_file *file_priv);
  1039. extern int drm_getsareactx(struct drm_device *dev, void *data,
  1040. struct drm_file *file_priv);
  1041. /* Drawable IOCTL support (drm_drawable.h) */
  1042. extern int drm_adddraw(struct drm_device *dev, void *data,
  1043. struct drm_file *file_priv);
  1044. extern int drm_rmdraw(struct drm_device *dev, void *data,
  1045. struct drm_file *file_priv);
  1046. extern int drm_update_drawable_info(struct drm_device *dev, void *data,
  1047. struct drm_file *file_priv);
  1048. extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
  1049. drm_drawable_t id);
  1050. extern void drm_drawable_free_all(struct drm_device *dev);
  1051. /* Authentication IOCTL support (drm_auth.h) */
  1052. extern int drm_getmagic(struct drm_device *dev, void *data,
  1053. struct drm_file *file_priv);
  1054. extern int drm_authmagic(struct drm_device *dev, void *data,
  1055. struct drm_file *file_priv);
  1056. /* Cache management (drm_cache.c) */
  1057. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  1058. /* Locking IOCTL support (drm_lock.h) */
  1059. extern int drm_lock(struct drm_device *dev, void *data,
  1060. struct drm_file *file_priv);
  1061. extern int drm_unlock(struct drm_device *dev, void *data,
  1062. struct drm_file *file_priv);
  1063. extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
  1064. extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
  1065. extern void drm_idlelock_take(struct drm_lock_data *lock_data);
  1066. extern void drm_idlelock_release(struct drm_lock_data *lock_data);
  1067. /*
  1068. * These are exported to drivers so that they can implement fencing using
  1069. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  1070. */
  1071. extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
  1072. /* Buffer management support (drm_bufs.h) */
  1073. extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
  1074. extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
  1075. extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
  1076. unsigned int size, enum drm_map_type type,
  1077. enum drm_map_flags flags, struct drm_local_map **map_ptr);
  1078. extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
  1079. struct drm_file *file_priv);
  1080. extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
  1081. extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
  1082. extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
  1083. struct drm_file *file_priv);
  1084. extern int drm_addbufs(struct drm_device *dev, void *data,
  1085. struct drm_file *file_priv);
  1086. extern int drm_infobufs(struct drm_device *dev, void *data,
  1087. struct drm_file *file_priv);
  1088. extern int drm_markbufs(struct drm_device *dev, void *data,
  1089. struct drm_file *file_priv);
  1090. extern int drm_freebufs(struct drm_device *dev, void *data,
  1091. struct drm_file *file_priv);
  1092. extern int drm_mapbufs(struct drm_device *dev, void *data,
  1093. struct drm_file *file_priv);
  1094. extern int drm_order(unsigned long size);
  1095. extern resource_size_t drm_get_resource_start(struct drm_device *dev,
  1096. unsigned int resource);
  1097. extern resource_size_t drm_get_resource_len(struct drm_device *dev,
  1098. unsigned int resource);
  1099. /* DMA support (drm_dma.h) */
  1100. extern int drm_dma_setup(struct drm_device *dev);
  1101. extern void drm_dma_takedown(struct drm_device *dev);
  1102. extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
  1103. extern void drm_core_reclaim_buffers(struct drm_device *dev,
  1104. struct drm_file *filp);
  1105. /* IRQ support (drm_irq.h) */
  1106. extern int drm_control(struct drm_device *dev, void *data,
  1107. struct drm_file *file_priv);
  1108. extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
  1109. extern int drm_irq_install(struct drm_device *dev);
  1110. extern int drm_irq_uninstall(struct drm_device *dev);
  1111. extern void drm_driver_irq_preinstall(struct drm_device *dev);
  1112. extern void drm_driver_irq_postinstall(struct drm_device *dev);
  1113. extern void drm_driver_irq_uninstall(struct drm_device *dev);
  1114. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  1115. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  1116. struct drm_file *filp);
  1117. extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
  1118. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  1119. extern void drm_handle_vblank(struct drm_device *dev, int crtc);
  1120. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1121. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1122. extern void drm_vblank_cleanup(struct drm_device *dev);
  1123. /* Modesetting support */
  1124. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1125. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1126. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1127. struct drm_file *file_priv);
  1128. /* AGP/GART support (drm_agpsupport.h) */
  1129. extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
  1130. extern int drm_agp_acquire(struct drm_device *dev);
  1131. extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
  1132. struct drm_file *file_priv);
  1133. extern int drm_agp_release(struct drm_device *dev);
  1134. extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
  1135. struct drm_file *file_priv);
  1136. extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
  1137. extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
  1138. struct drm_file *file_priv);
  1139. extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
  1140. extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
  1141. struct drm_file *file_priv);
  1142. extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
  1143. extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
  1144. struct drm_file *file_priv);
  1145. extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
  1146. extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
  1147. struct drm_file *file_priv);
  1148. extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
  1149. extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
  1150. struct drm_file *file_priv);
  1151. extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
  1152. extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
  1153. struct drm_file *file_priv);
  1154. extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
  1155. extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
  1156. extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
  1157. extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
  1158. extern void drm_agp_chipset_flush(struct drm_device *dev);
  1159. /* Stub support (drm_stub.h) */
  1160. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1161. struct drm_file *file_priv);
  1162. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1163. struct drm_file *file_priv);
  1164. struct drm_master *drm_master_create(struct drm_minor *minor);
  1165. extern struct drm_master *drm_master_get(struct drm_master *master);
  1166. extern void drm_master_put(struct drm_master **master);
  1167. extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
  1168. struct drm_driver *driver);
  1169. extern void drm_put_dev(struct drm_device *dev);
  1170. extern int drm_put_minor(struct drm_minor **minor);
  1171. extern unsigned int drm_debug;
  1172. extern struct class *drm_class;
  1173. extern struct proc_dir_entry *drm_proc_root;
  1174. extern struct dentry *drm_debugfs_root;
  1175. extern struct idr drm_minors_idr;
  1176. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1177. /* Proc support (drm_proc.h) */
  1178. extern int drm_proc_init(struct drm_minor *minor, int minor_id,
  1179. struct proc_dir_entry *root);
  1180. extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
  1181. /* Debugfs support */
  1182. #if defined(CONFIG_DEBUG_FS)
  1183. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1184. struct dentry *root);
  1185. extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
  1186. struct dentry *root, struct drm_minor *minor);
  1187. extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
  1188. struct drm_minor *minor);
  1189. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1190. #endif
  1191. /* Info file support */
  1192. extern int drm_name_info(struct seq_file *m, void *data);
  1193. extern int drm_vm_info(struct seq_file *m, void *data);
  1194. extern int drm_queues_info(struct seq_file *m, void *data);
  1195. extern int drm_bufs_info(struct seq_file *m, void *data);
  1196. extern int drm_vblank_info(struct seq_file *m, void *data);
  1197. extern int drm_clients_info(struct seq_file *m, void* data);
  1198. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1199. extern int drm_gem_object_info(struct seq_file *m, void* data);
  1200. #if DRM_DEBUG_CODE
  1201. extern int drm_vma_info(struct seq_file *m, void *data);
  1202. #endif
  1203. /* Scatter Gather Support (drm_scatter.h) */
  1204. extern void drm_sg_cleanup(struct drm_sg_mem * entry);
  1205. extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
  1206. struct drm_file *file_priv);
  1207. extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
  1208. extern int drm_sg_free(struct drm_device *dev, void *data,
  1209. struct drm_file *file_priv);
  1210. /* ATI PCIGART support (ati_pcigart.h) */
  1211. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1212. struct drm_ati_pcigart_info * gart_info);
  1213. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1214. struct drm_ati_pcigart_info * gart_info);
  1215. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1216. size_t align, dma_addr_t maxaddr);
  1217. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1218. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1219. /* sysfs support (drm_sysfs.c) */
  1220. struct drm_sysfs_class;
  1221. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1222. extern void drm_sysfs_destroy(void);
  1223. extern int drm_sysfs_device_add(struct drm_minor *minor);
  1224. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1225. extern void drm_sysfs_device_remove(struct drm_minor *minor);
  1226. extern char *drm_get_connector_status_name(enum drm_connector_status status);
  1227. extern int drm_sysfs_connector_add(struct drm_connector *connector);
  1228. extern void drm_sysfs_connector_remove(struct drm_connector *connector);
  1229. /* Graphics Execution Manager library functions (drm_gem.c) */
  1230. int drm_gem_init(struct drm_device *dev);
  1231. void drm_gem_destroy(struct drm_device *dev);
  1232. void drm_gem_object_free(struct kref *kref);
  1233. struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
  1234. size_t size);
  1235. void drm_gem_object_handle_free(struct kref *kref);
  1236. void drm_gem_vm_open(struct vm_area_struct *vma);
  1237. void drm_gem_vm_close(struct vm_area_struct *vma);
  1238. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1239. static inline void
  1240. drm_gem_object_reference(struct drm_gem_object *obj)
  1241. {
  1242. kref_get(&obj->refcount);
  1243. }
  1244. static inline void
  1245. drm_gem_object_unreference(struct drm_gem_object *obj)
  1246. {
  1247. if (obj == NULL)
  1248. return;
  1249. kref_put(&obj->refcount, drm_gem_object_free);
  1250. }
  1251. int drm_gem_handle_create(struct drm_file *file_priv,
  1252. struct drm_gem_object *obj,
  1253. u32 *handlep);
  1254. static inline void
  1255. drm_gem_object_handle_reference(struct drm_gem_object *obj)
  1256. {
  1257. drm_gem_object_reference(obj);
  1258. kref_get(&obj->handlecount);
  1259. }
  1260. static inline void
  1261. drm_gem_object_handle_unreference(struct drm_gem_object *obj)
  1262. {
  1263. if (obj == NULL)
  1264. return;
  1265. /*
  1266. * Must bump handle count first as this may be the last
  1267. * ref, in which case the object would disappear before we
  1268. * checked for a name
  1269. */
  1270. kref_put(&obj->handlecount, drm_gem_object_handle_free);
  1271. drm_gem_object_unreference(obj);
  1272. }
  1273. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1274. struct drm_file *filp,
  1275. u32 handle);
  1276. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1277. struct drm_file *file_priv);
  1278. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1279. struct drm_file *file_priv);
  1280. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1281. struct drm_file *file_priv);
  1282. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1283. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1284. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1285. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1286. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1287. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1288. unsigned int token)
  1289. {
  1290. struct drm_map_list *_entry;
  1291. list_for_each_entry(_entry, &dev->maplist, head)
  1292. if (_entry->user_token == token)
  1293. return _entry->map;
  1294. return NULL;
  1295. }
  1296. static __inline__ int drm_device_is_agp(struct drm_device *dev)
  1297. {
  1298. if (dev->driver->device_is_agp != NULL) {
  1299. int err = (*dev->driver->device_is_agp) (dev);
  1300. if (err != 2) {
  1301. return err;
  1302. }
  1303. }
  1304. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1305. }
  1306. static __inline__ int drm_device_is_pcie(struct drm_device *dev)
  1307. {
  1308. return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  1309. }
  1310. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1311. {
  1312. }
  1313. static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
  1314. {
  1315. if (size * nmemb <= PAGE_SIZE)
  1316. return kcalloc(nmemb, size, GFP_KERNEL);
  1317. if (size != 0 && nmemb > ULONG_MAX / size)
  1318. return NULL;
  1319. return __vmalloc(size * nmemb,
  1320. GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
  1321. }
  1322. static __inline void drm_free_large(void *ptr)
  1323. {
  1324. if (!is_vmalloc_addr(ptr))
  1325. return kfree(ptr);
  1326. vfree(ptr);
  1327. }
  1328. /*@}*/
  1329. #endif /* __KERNEL__ */
  1330. #endif