drmP.h 51 KB

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