drmP.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  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/kernel.h>
  43. #include <linux/kref.h>
  44. #include <linux/miscdevice.h>
  45. #include <linux/fs.h>
  46. #include <linux/init.h>
  47. #include <linux/file.h>
  48. #include <linux/platform_device.h>
  49. #include <linux/pci.h>
  50. #include <linux/jiffies.h>
  51. #include <linux/dma-mapping.h>
  52. #include <linux/mm.h>
  53. #include <linux/cdev.h>
  54. #include <linux/mutex.h>
  55. #include <linux/io.h>
  56. #include <linux/slab.h>
  57. #include <linux/ratelimit.h>
  58. #if defined(__alpha__) || defined(__powerpc__)
  59. #include <asm/pgtable.h> /* For pte_wrprotect */
  60. #endif
  61. #include <asm/mman.h>
  62. #include <asm/uaccess.h>
  63. #include <linux/types.h>
  64. #include <linux/agp_backend.h>
  65. #include <linux/workqueue.h>
  66. #include <linux/poll.h>
  67. #include <asm/pgalloc.h>
  68. #include <drm/drm.h>
  69. #include <drm/drm_sarea.h>
  70. #include <drm/drm_vma_manager.h>
  71. #include <linux/idr.h>
  72. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  73. struct module;
  74. struct drm_file;
  75. struct drm_device;
  76. struct device_node;
  77. struct videomode;
  78. struct reservation_object;
  79. #include <drm/drm_os_linux.h>
  80. #include <drm/drm_hashtab.h>
  81. #include <drm/drm_mm.h>
  82. /*
  83. * 4 debug categories are defined:
  84. *
  85. * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
  86. * This is the category used by the DRM_DEBUG() macro.
  87. *
  88. * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
  89. * This is the category used by the DRM_DEBUG_DRIVER() macro.
  90. *
  91. * KMS: used in the modesetting code.
  92. * This is the category used by the DRM_DEBUG_KMS() macro.
  93. *
  94. * PRIME: used in the prime code.
  95. * This is the category used by the DRM_DEBUG_PRIME() macro.
  96. *
  97. * Enabling verbose debug messages is done through the drm.debug parameter,
  98. * each category being enabled by a bit.
  99. *
  100. * drm.debug=0x1 will enable CORE messages
  101. * drm.debug=0x2 will enable DRIVER messages
  102. * drm.debug=0x3 will enable CORE and DRIVER messages
  103. * ...
  104. * drm.debug=0xf will enable all messages
  105. *
  106. * An interesting feature is that it's possible to enable verbose logging at
  107. * run-time by echoing the debug value in its sysfs node:
  108. * # echo 0xf > /sys/module/drm/parameters/debug
  109. */
  110. #define DRM_UT_CORE 0x01
  111. #define DRM_UT_DRIVER 0x02
  112. #define DRM_UT_KMS 0x04
  113. #define DRM_UT_PRIME 0x08
  114. extern __printf(2, 3)
  115. void drm_ut_debug_printk(const char *function_name,
  116. const char *format, ...);
  117. extern __printf(2, 3)
  118. int drm_err(const char *func, const char *format, ...);
  119. /***********************************************************************/
  120. /** \name DRM template customization defaults */
  121. /*@{*/
  122. /* driver capabilities and requirements mask */
  123. #define DRIVER_USE_AGP 0x1
  124. #define DRIVER_PCI_DMA 0x8
  125. #define DRIVER_SG 0x10
  126. #define DRIVER_HAVE_DMA 0x20
  127. #define DRIVER_HAVE_IRQ 0x40
  128. #define DRIVER_IRQ_SHARED 0x80
  129. #define DRIVER_GEM 0x1000
  130. #define DRIVER_MODESET 0x2000
  131. #define DRIVER_PRIME 0x4000
  132. #define DRIVER_RENDER 0x8000
  133. /***********************************************************************/
  134. /** \name Begin the DRM... */
  135. /*@{*/
  136. #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
  137. also include looping detection. */
  138. #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
  139. #define DRM_MAP_HASH_OFFSET 0x10000000
  140. /*@}*/
  141. /***********************************************************************/
  142. /** \name Macros to make printk easier */
  143. /*@{*/
  144. /**
  145. * Error output.
  146. *
  147. * \param fmt printf() like format string.
  148. * \param arg arguments
  149. */
  150. #define DRM_ERROR(fmt, ...) \
  151. drm_err(__func__, fmt, ##__VA_ARGS__)
  152. /**
  153. * Rate limited error output. Like DRM_ERROR() but won't flood the log.
  154. *
  155. * \param fmt printf() like format string.
  156. * \param arg arguments
  157. */
  158. #define DRM_ERROR_RATELIMITED(fmt, ...) \
  159. ({ \
  160. static DEFINE_RATELIMIT_STATE(_rs, \
  161. DEFAULT_RATELIMIT_INTERVAL, \
  162. DEFAULT_RATELIMIT_BURST); \
  163. \
  164. if (__ratelimit(&_rs)) \
  165. drm_err(__func__, fmt, ##__VA_ARGS__); \
  166. })
  167. #define DRM_INFO(fmt, ...) \
  168. printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  169. #define DRM_INFO_ONCE(fmt, ...) \
  170. printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  171. /**
  172. * Debug output.
  173. *
  174. * \param fmt printf() like format string.
  175. * \param arg arguments
  176. */
  177. #if DRM_DEBUG_CODE
  178. #define DRM_DEBUG(fmt, args...) \
  179. do { \
  180. if (unlikely(drm_debug & DRM_UT_CORE)) \
  181. drm_ut_debug_printk(__func__, fmt, ##args); \
  182. } while (0)
  183. #define DRM_DEBUG_DRIVER(fmt, args...) \
  184. do { \
  185. if (unlikely(drm_debug & DRM_UT_DRIVER)) \
  186. drm_ut_debug_printk(__func__, fmt, ##args); \
  187. } while (0)
  188. #define DRM_DEBUG_KMS(fmt, args...) \
  189. do { \
  190. if (unlikely(drm_debug & DRM_UT_KMS)) \
  191. drm_ut_debug_printk(__func__, fmt, ##args); \
  192. } while (0)
  193. #define DRM_DEBUG_PRIME(fmt, args...) \
  194. do { \
  195. if (unlikely(drm_debug & DRM_UT_PRIME)) \
  196. drm_ut_debug_printk(__func__, fmt, ##args); \
  197. } while (0)
  198. #else
  199. #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
  200. #define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
  201. #define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
  202. #define DRM_DEBUG(fmt, arg...) do { } while (0)
  203. #endif
  204. /*@}*/
  205. /***********************************************************************/
  206. /** \name Internal types and structures */
  207. /*@{*/
  208. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  209. /**
  210. * Test that the hardware lock is held by the caller, returning otherwise.
  211. *
  212. * \param dev DRM device.
  213. * \param filp file pointer of the caller.
  214. */
  215. #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
  216. do { \
  217. if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
  218. _file_priv->master->lock.file_priv != _file_priv) { \
  219. DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
  220. __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  221. _file_priv->master->lock.file_priv, _file_priv); \
  222. return -EINVAL; \
  223. } \
  224. } while (0)
  225. /**
  226. * Ioctl function type.
  227. *
  228. * \param inode device inode.
  229. * \param file_priv DRM file private pointer.
  230. * \param cmd command.
  231. * \param arg argument.
  232. */
  233. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  234. struct drm_file *file_priv);
  235. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  236. unsigned long arg);
  237. #define DRM_IOCTL_NR(n) _IOC_NR(n)
  238. #define DRM_MAJOR 226
  239. #define DRM_AUTH 0x1
  240. #define DRM_MASTER 0x2
  241. #define DRM_ROOT_ONLY 0x4
  242. #define DRM_CONTROL_ALLOW 0x8
  243. #define DRM_UNLOCKED 0x10
  244. #define DRM_RENDER_ALLOW 0x20
  245. struct drm_ioctl_desc {
  246. unsigned int cmd;
  247. int flags;
  248. drm_ioctl_t *func;
  249. unsigned int cmd_drv;
  250. const char *name;
  251. };
  252. /**
  253. * Creates a driver or general drm_ioctl_desc array entry for the given
  254. * ioctl, for use by drm_ioctl().
  255. */
  256. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
  257. [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
  258. struct drm_magic_entry {
  259. struct list_head head;
  260. struct drm_hash_item hash_item;
  261. struct drm_file *priv;
  262. };
  263. struct drm_vma_entry {
  264. struct list_head head;
  265. struct vm_area_struct *vma;
  266. pid_t pid;
  267. };
  268. /**
  269. * DMA buffer.
  270. */
  271. struct drm_buf {
  272. int idx; /**< Index into master buflist */
  273. int total; /**< Buffer size */
  274. int order; /**< log-base-2(total) */
  275. int used; /**< Amount of buffer in use (for DMA) */
  276. unsigned long offset; /**< Byte offset (used internally) */
  277. void *address; /**< Address of buffer */
  278. unsigned long bus_address; /**< Bus address of buffer */
  279. struct drm_buf *next; /**< Kernel-only: used for free list */
  280. __volatile__ int waiting; /**< On kernel DMA queue */
  281. __volatile__ int pending; /**< On hardware DMA queue */
  282. struct drm_file *file_priv; /**< Private of holding file descr */
  283. int context; /**< Kernel queue for this buffer */
  284. int while_locked; /**< Dispatch this buffer while locked */
  285. enum {
  286. DRM_LIST_NONE = 0,
  287. DRM_LIST_FREE = 1,
  288. DRM_LIST_WAIT = 2,
  289. DRM_LIST_PEND = 3,
  290. DRM_LIST_PRIO = 4,
  291. DRM_LIST_RECLAIM = 5
  292. } list; /**< Which list we're on */
  293. int dev_priv_size; /**< Size of buffer private storage */
  294. void *dev_private; /**< Per-buffer private storage */
  295. };
  296. /** bufs is one longer than it has to be */
  297. struct drm_waitlist {
  298. int count; /**< Number of possible buffers */
  299. struct drm_buf **bufs; /**< List of pointers to buffers */
  300. struct drm_buf **rp; /**< Read pointer */
  301. struct drm_buf **wp; /**< Write pointer */
  302. struct drm_buf **end; /**< End pointer */
  303. spinlock_t read_lock;
  304. spinlock_t write_lock;
  305. };
  306. typedef struct drm_dma_handle {
  307. dma_addr_t busaddr;
  308. void *vaddr;
  309. size_t size;
  310. } drm_dma_handle_t;
  311. /**
  312. * Buffer entry. There is one of this for each buffer size order.
  313. */
  314. struct drm_buf_entry {
  315. int buf_size; /**< size */
  316. int buf_count; /**< number of buffers */
  317. struct drm_buf *buflist; /**< buffer list */
  318. int seg_count;
  319. int page_order;
  320. struct drm_dma_handle **seglist;
  321. int low_mark; /**< Low water mark */
  322. int high_mark; /**< High water mark */
  323. };
  324. /* Event queued up for userspace to read */
  325. struct drm_pending_event {
  326. struct drm_event *event;
  327. struct list_head link;
  328. struct drm_file *file_priv;
  329. pid_t pid; /* pid of requester, no guarantee it's valid by the time
  330. we deliver the event, for tracing only */
  331. void (*destroy)(struct drm_pending_event *event);
  332. };
  333. /* initial implementaton using a linked list - todo hashtab */
  334. struct drm_prime_file_private {
  335. struct list_head head;
  336. struct mutex lock;
  337. };
  338. /** File private data */
  339. struct drm_file {
  340. unsigned authenticated :1;
  341. /* Whether we're master for a minor. Protected by master_mutex */
  342. unsigned is_master :1;
  343. /* true when the client has asked us to expose stereo 3D mode flags */
  344. unsigned stereo_allowed :1;
  345. /*
  346. * true if client understands CRTC primary planes and cursor planes
  347. * in the plane list
  348. */
  349. unsigned universal_planes:1;
  350. struct pid *pid;
  351. kuid_t uid;
  352. drm_magic_t magic;
  353. struct list_head lhead;
  354. struct drm_minor *minor;
  355. unsigned long lock_count;
  356. /** Mapping of mm object handles to object pointers. */
  357. struct idr object_idr;
  358. /** Lock for synchronization of access to object_idr. */
  359. spinlock_t table_lock;
  360. struct file *filp;
  361. void *driver_priv;
  362. struct drm_master *master; /* master this node is currently associated with
  363. N.B. not always minor->master */
  364. /**
  365. * fbs - List of framebuffers associated with this file.
  366. *
  367. * Protected by fbs_lock. Note that the fbs list holds a reference on
  368. * the fb object to prevent it from untimely disappearing.
  369. */
  370. struct list_head fbs;
  371. struct mutex fbs_lock;
  372. wait_queue_head_t event_wait;
  373. struct list_head event_list;
  374. int event_space;
  375. struct drm_prime_file_private prime;
  376. };
  377. /**
  378. * Lock data.
  379. */
  380. struct drm_lock_data {
  381. struct drm_hw_lock *hw_lock; /**< Hardware lock */
  382. /** Private of lock holder's file (NULL=kernel) */
  383. struct drm_file *file_priv;
  384. wait_queue_head_t lock_queue; /**< Queue of blocked processes */
  385. unsigned long lock_time; /**< Time of last lock in jiffies */
  386. spinlock_t spinlock;
  387. uint32_t kernel_waiters;
  388. uint32_t user_waiters;
  389. int idle_has_lock;
  390. };
  391. /**
  392. * DMA data.
  393. */
  394. struct drm_device_dma {
  395. struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  396. int buf_count; /**< total number of buffers */
  397. struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  398. int seg_count;
  399. int page_count; /**< number of pages */
  400. unsigned long *pagelist; /**< page list */
  401. unsigned long byte_count;
  402. enum {
  403. _DRM_DMA_USE_AGP = 0x01,
  404. _DRM_DMA_USE_SG = 0x02,
  405. _DRM_DMA_USE_FB = 0x04,
  406. _DRM_DMA_USE_PCI_RO = 0x08
  407. } flags;
  408. };
  409. /**
  410. * AGP memory entry. Stored as a doubly linked list.
  411. */
  412. struct drm_agp_mem {
  413. unsigned long handle; /**< handle */
  414. struct agp_memory *memory;
  415. unsigned long bound; /**< address */
  416. int pages;
  417. struct list_head head;
  418. };
  419. /**
  420. * AGP data.
  421. *
  422. * \sa drm_agp_init() and drm_device::agp.
  423. */
  424. struct drm_agp_head {
  425. struct agp_kern_info agp_info; /**< AGP device information */
  426. struct list_head memory;
  427. unsigned long mode; /**< AGP mode */
  428. struct agp_bridge_data *bridge;
  429. int enabled; /**< whether the AGP bus as been enabled */
  430. int acquired; /**< whether the AGP device has been acquired */
  431. unsigned long base;
  432. int agp_mtrr;
  433. int cant_use_aperture;
  434. unsigned long page_mask;
  435. };
  436. /**
  437. * Scatter-gather memory.
  438. */
  439. struct drm_sg_mem {
  440. unsigned long handle;
  441. void *virtual;
  442. int pages;
  443. struct page **pagelist;
  444. dma_addr_t *busaddr;
  445. };
  446. struct drm_sigdata {
  447. int context;
  448. struct drm_hw_lock *lock;
  449. };
  450. /**
  451. * Kernel side of a mapping
  452. */
  453. struct drm_local_map {
  454. resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
  455. unsigned long size; /**< Requested physical size (bytes) */
  456. enum drm_map_type type; /**< Type of memory to map */
  457. enum drm_map_flags flags; /**< Flags */
  458. void *handle; /**< User-space: "Handle" to pass to mmap() */
  459. /**< Kernel-space: kernel-virtual address */
  460. int mtrr; /**< MTRR slot used */
  461. };
  462. typedef struct drm_local_map drm_local_map_t;
  463. /**
  464. * Mappings list
  465. */
  466. struct drm_map_list {
  467. struct list_head head; /**< list head */
  468. struct drm_hash_item hash;
  469. struct drm_local_map *map; /**< mapping */
  470. uint64_t user_token;
  471. struct drm_master *master;
  472. };
  473. /* location of GART table */
  474. #define DRM_ATI_GART_MAIN 1
  475. #define DRM_ATI_GART_FB 2
  476. #define DRM_ATI_GART_PCI 1
  477. #define DRM_ATI_GART_PCIE 2
  478. #define DRM_ATI_GART_IGP 3
  479. struct drm_ati_pcigart_info {
  480. int gart_table_location;
  481. int gart_reg_if;
  482. void *addr;
  483. dma_addr_t bus_addr;
  484. dma_addr_t table_mask;
  485. struct drm_dma_handle *table_handle;
  486. struct drm_local_map mapping;
  487. int table_size;
  488. };
  489. /**
  490. * This structure defines the drm_mm memory object, which will be used by the
  491. * DRM for its buffer objects.
  492. */
  493. struct drm_gem_object {
  494. /** Reference count of this object */
  495. struct kref refcount;
  496. /**
  497. * handle_count - gem file_priv handle count of this object
  498. *
  499. * Each handle also holds a reference. Note that when the handle_count
  500. * drops to 0 any global names (e.g. the id in the flink namespace) will
  501. * be cleared.
  502. *
  503. * Protected by dev->object_name_lock.
  504. * */
  505. unsigned handle_count;
  506. /** Related drm device */
  507. struct drm_device *dev;
  508. /** File representing the shmem storage */
  509. struct file *filp;
  510. /* Mapping info for this object */
  511. struct drm_vma_offset_node vma_node;
  512. /**
  513. * Size of the object, in bytes. Immutable over the object's
  514. * lifetime.
  515. */
  516. size_t size;
  517. /**
  518. * Global name for this object, starts at 1. 0 means unnamed.
  519. * Access is covered by the object_name_lock in the related drm_device
  520. */
  521. int name;
  522. /**
  523. * Memory domains. These monitor which caches contain read/write data
  524. * related to the object. When transitioning from one set of domains
  525. * to another, the driver is called to ensure that caches are suitably
  526. * flushed and invalidated
  527. */
  528. uint32_t read_domains;
  529. uint32_t write_domain;
  530. /**
  531. * While validating an exec operation, the
  532. * new read/write domain values are computed here.
  533. * They will be transferred to the above values
  534. * at the point that any cache flushing occurs
  535. */
  536. uint32_t pending_read_domains;
  537. uint32_t pending_write_domain;
  538. /**
  539. * dma_buf - dma buf associated with this GEM object
  540. *
  541. * Pointer to the dma-buf associated with this gem object (either
  542. * through importing or exporting). We break the resulting reference
  543. * loop when the last gem handle for this object is released.
  544. *
  545. * Protected by obj->object_name_lock
  546. */
  547. struct dma_buf *dma_buf;
  548. /**
  549. * import_attach - dma buf attachment backing this object
  550. *
  551. * Any foreign dma_buf imported as a gem object has this set to the
  552. * attachment point for the device. This is invariant over the lifetime
  553. * of a gem object.
  554. *
  555. * The driver's ->gem_free_object callback is responsible for cleaning
  556. * up the dma_buf attachment and references acquired at import time.
  557. *
  558. * Note that the drm gem/prime core does not depend upon drivers setting
  559. * this field any more. So for drivers where this doesn't make sense
  560. * (e.g. virtual devices or a displaylink behind an usb bus) they can
  561. * simply leave it as NULL.
  562. */
  563. struct dma_buf_attachment *import_attach;
  564. };
  565. #include <drm/drm_crtc.h>
  566. /**
  567. * struct drm_master - drm master structure
  568. *
  569. * @refcount: Refcount for this master object.
  570. * @minor: Link back to minor char device we are master for. Immutable.
  571. * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
  572. * @unique_len: Length of unique field. Protected by drm_global_mutex.
  573. * @unique_size: Amount allocated. Protected by drm_global_mutex.
  574. * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
  575. * @magicfree: List of used authentication tokens. Protected by struct_mutex.
  576. * @lock: DRI lock information.
  577. * @driver_priv: Pointer to driver-private information.
  578. */
  579. struct drm_master {
  580. struct kref refcount;
  581. struct drm_minor *minor;
  582. char *unique;
  583. int unique_len;
  584. int unique_size;
  585. struct drm_open_hash magiclist;
  586. struct list_head magicfree;
  587. struct drm_lock_data lock;
  588. void *driver_priv;
  589. };
  590. /* Size of ringbuffer for vblank timestamps. Just double-buffer
  591. * in initial implementation.
  592. */
  593. #define DRM_VBLANKTIME_RBSIZE 2
  594. /* Flags and return codes for get_vblank_timestamp() driver function. */
  595. #define DRM_CALLED_FROM_VBLIRQ 1
  596. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  597. #define DRM_VBLANKTIME_INVBL (1 << 1)
  598. /* get_scanout_position() return flags */
  599. #define DRM_SCANOUTPOS_VALID (1 << 0)
  600. #define DRM_SCANOUTPOS_INVBL (1 << 1)
  601. #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
  602. struct drm_bus {
  603. int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  604. };
  605. /**
  606. * DRM driver structure. This structure represent the common code for
  607. * a family of cards. There will one drm_device for each card present
  608. * in this family
  609. */
  610. struct drm_driver {
  611. int (*load) (struct drm_device *, unsigned long flags);
  612. int (*firstopen) (struct drm_device *);
  613. int (*open) (struct drm_device *, struct drm_file *);
  614. void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  615. void (*postclose) (struct drm_device *, struct drm_file *);
  616. void (*lastclose) (struct drm_device *);
  617. int (*unload) (struct drm_device *);
  618. int (*suspend) (struct drm_device *, pm_message_t state);
  619. int (*resume) (struct drm_device *);
  620. int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  621. int (*dma_quiescent) (struct drm_device *);
  622. int (*context_dtor) (struct drm_device *dev, int context);
  623. /**
  624. * get_vblank_counter - get raw hardware vblank counter
  625. * @dev: DRM device
  626. * @crtc: counter to fetch
  627. *
  628. * Driver callback for fetching a raw hardware vblank counter for @crtc.
  629. * If a device doesn't have a hardware counter, the driver can simply
  630. * return the value of drm_vblank_count. The DRM core will account for
  631. * missed vblank events while interrupts where disabled based on system
  632. * timestamps.
  633. *
  634. * Wraparound handling and loss of events due to modesetting is dealt
  635. * with in the DRM core code.
  636. *
  637. * RETURNS
  638. * Raw vblank counter value.
  639. */
  640. u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  641. /**
  642. * enable_vblank - enable vblank interrupt events
  643. * @dev: DRM device
  644. * @crtc: which irq to enable
  645. *
  646. * Enable vblank interrupts for @crtc. If the device doesn't have
  647. * a hardware vblank counter, this routine should be a no-op, since
  648. * interrupts will have to stay on to keep the count accurate.
  649. *
  650. * RETURNS
  651. * Zero on success, appropriate errno if the given @crtc's vblank
  652. * interrupt cannot be enabled.
  653. */
  654. int (*enable_vblank) (struct drm_device *dev, int crtc);
  655. /**
  656. * disable_vblank - disable vblank interrupt events
  657. * @dev: DRM device
  658. * @crtc: which irq to enable
  659. *
  660. * Disable vblank interrupts for @crtc. If the device doesn't have
  661. * a hardware vblank counter, this routine should be a no-op, since
  662. * interrupts will have to stay on to keep the count accurate.
  663. */
  664. void (*disable_vblank) (struct drm_device *dev, int crtc);
  665. /**
  666. * Called by \c drm_device_is_agp. Typically used to determine if a
  667. * card is really attached to AGP or not.
  668. *
  669. * \param dev DRM device handle
  670. *
  671. * \returns
  672. * One of three values is returned depending on whether or not the
  673. * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  674. * (return of 1), or may or may not be AGP (return of 2).
  675. */
  676. int (*device_is_agp) (struct drm_device *dev);
  677. /**
  678. * Called by vblank timestamping code.
  679. *
  680. * Return the current display scanout position from a crtc, and an
  681. * optional accurate ktime_get timestamp of when position was measured.
  682. *
  683. * \param dev DRM device.
  684. * \param crtc Id of the crtc to query.
  685. * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  686. * \param *vpos Target location for current vertical scanout position.
  687. * \param *hpos Target location for current horizontal scanout position.
  688. * \param *stime Target location for timestamp taken immediately before
  689. * scanout position query. Can be NULL to skip timestamp.
  690. * \param *etime Target location for timestamp taken immediately after
  691. * scanout position query. Can be NULL to skip timestamp.
  692. *
  693. * Returns vpos as a positive number while in active scanout area.
  694. * Returns vpos as a negative number inside vblank, counting the number
  695. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  696. * until start of active scanout / end of vblank."
  697. *
  698. * \return Flags, or'ed together as follows:
  699. *
  700. * DRM_SCANOUTPOS_VALID = Query successful.
  701. * DRM_SCANOUTPOS_INVBL = Inside vblank.
  702. * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  703. * this flag means that returned position may be offset by a constant
  704. * but unknown small number of scanlines wrt. real scanout position.
  705. *
  706. */
  707. int (*get_scanout_position) (struct drm_device *dev, int crtc,
  708. unsigned int flags,
  709. int *vpos, int *hpos, ktime_t *stime,
  710. ktime_t *etime);
  711. /**
  712. * Called by \c drm_get_last_vbltimestamp. Should return a precise
  713. * timestamp when the most recent VBLANK interval ended or will end.
  714. *
  715. * Specifically, the timestamp in @vblank_time should correspond as
  716. * closely as possible to the time when the first video scanline of
  717. * the video frame after the end of VBLANK will start scanning out,
  718. * the time immediately after end of the VBLANK interval. If the
  719. * @crtc is currently inside VBLANK, this will be a time in the future.
  720. * If the @crtc is currently scanning out a frame, this will be the
  721. * past start time of the current scanout. This is meant to adhere
  722. * to the OpenML OML_sync_control extension specification.
  723. *
  724. * \param dev dev DRM device handle.
  725. * \param crtc crtc for which timestamp should be returned.
  726. * \param *max_error Maximum allowable timestamp error in nanoseconds.
  727. * Implementation should strive to provide timestamp
  728. * with an error of at most *max_error nanoseconds.
  729. * Returns true upper bound on error for timestamp.
  730. * \param *vblank_time Target location for returned vblank timestamp.
  731. * \param flags 0 = Defaults, no special treatment needed.
  732. * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  733. * irq handler. Some drivers need to apply some workarounds
  734. * for gpu-specific vblank irq quirks if flag is set.
  735. *
  736. * \returns
  737. * Zero if timestamping isn't supported in current display mode or a
  738. * negative number on failure. A positive status code on success,
  739. * which describes how the vblank_time timestamp was computed.
  740. */
  741. int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
  742. int *max_error,
  743. struct timeval *vblank_time,
  744. unsigned flags);
  745. /* these have to be filled in */
  746. irqreturn_t(*irq_handler) (int irq, void *arg);
  747. void (*irq_preinstall) (struct drm_device *dev);
  748. int (*irq_postinstall) (struct drm_device *dev);
  749. void (*irq_uninstall) (struct drm_device *dev);
  750. /* Master routines */
  751. int (*master_create)(struct drm_device *dev, struct drm_master *master);
  752. void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  753. /**
  754. * master_set is called whenever the minor master is set.
  755. * master_drop is called whenever the minor master is dropped.
  756. */
  757. int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  758. bool from_open);
  759. void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
  760. bool from_release);
  761. int (*debugfs_init)(struct drm_minor *minor);
  762. void (*debugfs_cleanup)(struct drm_minor *minor);
  763. /**
  764. * Driver-specific constructor for drm_gem_objects, to set up
  765. * obj->driver_private.
  766. *
  767. * Returns 0 on success.
  768. */
  769. void (*gem_free_object) (struct drm_gem_object *obj);
  770. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  771. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  772. /* prime: */
  773. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  774. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  775. uint32_t handle, uint32_t flags, int *prime_fd);
  776. /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  777. int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  778. int prime_fd, uint32_t *handle);
  779. /* export GEM -> dmabuf */
  780. struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  781. struct drm_gem_object *obj, int flags);
  782. /* import dmabuf -> GEM */
  783. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  784. struct dma_buf *dma_buf);
  785. /* low-level interface used by drm_gem_prime_{import,export} */
  786. int (*gem_prime_pin)(struct drm_gem_object *obj);
  787. void (*gem_prime_unpin)(struct drm_gem_object *obj);
  788. struct reservation_object * (*gem_prime_res_obj)(
  789. struct drm_gem_object *obj);
  790. struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
  791. struct drm_gem_object *(*gem_prime_import_sg_table)(
  792. struct drm_device *dev, size_t size,
  793. struct sg_table *sgt);
  794. void *(*gem_prime_vmap)(struct drm_gem_object *obj);
  795. void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
  796. int (*gem_prime_mmap)(struct drm_gem_object *obj,
  797. struct vm_area_struct *vma);
  798. /* vga arb irq handler */
  799. void (*vgaarb_irq)(struct drm_device *dev, bool state);
  800. /* dumb alloc support */
  801. int (*dumb_create)(struct drm_file *file_priv,
  802. struct drm_device *dev,
  803. struct drm_mode_create_dumb *args);
  804. int (*dumb_map_offset)(struct drm_file *file_priv,
  805. struct drm_device *dev, uint32_t handle,
  806. uint64_t *offset);
  807. int (*dumb_destroy)(struct drm_file *file_priv,
  808. struct drm_device *dev,
  809. uint32_t handle);
  810. /* Driver private ops for this object */
  811. const struct vm_operations_struct *gem_vm_ops;
  812. int major;
  813. int minor;
  814. int patchlevel;
  815. char *name;
  816. char *desc;
  817. char *date;
  818. u32 driver_features;
  819. int dev_priv_size;
  820. const struct drm_ioctl_desc *ioctls;
  821. int num_ioctls;
  822. const struct file_operations *fops;
  823. struct drm_bus *bus;
  824. /* List of devices hanging off this driver with stealth attach. */
  825. struct list_head legacy_dev_list;
  826. };
  827. enum drm_minor_type {
  828. DRM_MINOR_LEGACY,
  829. DRM_MINOR_CONTROL,
  830. DRM_MINOR_RENDER,
  831. DRM_MINOR_CNT,
  832. };
  833. /**
  834. * Info file list entry. This structure represents a debugfs or proc file to
  835. * be created by the drm core
  836. */
  837. struct drm_info_list {
  838. const char *name; /** file name */
  839. int (*show)(struct seq_file*, void*); /** show callback */
  840. u32 driver_features; /**< Required driver features for this entry */
  841. void *data;
  842. };
  843. /**
  844. * debugfs node structure. This structure represents a debugfs file.
  845. */
  846. struct drm_info_node {
  847. struct list_head list;
  848. struct drm_minor *minor;
  849. const struct drm_info_list *info_ent;
  850. struct dentry *dent;
  851. };
  852. /**
  853. * DRM minor structure. This structure represents a drm minor number.
  854. */
  855. struct drm_minor {
  856. int index; /**< Minor device number */
  857. int type; /**< Control or render */
  858. struct device *kdev; /**< Linux device */
  859. struct drm_device *dev;
  860. struct dentry *debugfs_root;
  861. struct list_head debugfs_list;
  862. struct mutex debugfs_lock; /* Protects debugfs_list. */
  863. /* currently active master for this node. Protected by master_mutex */
  864. struct drm_master *master;
  865. struct drm_mode_group mode_group;
  866. };
  867. struct drm_pending_vblank_event {
  868. struct drm_pending_event base;
  869. int pipe;
  870. struct drm_event_vblank event;
  871. };
  872. struct drm_vblank_crtc {
  873. struct drm_device *dev; /* pointer to the drm_device */
  874. wait_queue_head_t queue; /**< VBLANK wait queue */
  875. struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
  876. struct timer_list disable_timer; /* delayed disable timer */
  877. atomic_t count; /**< number of VBLANK interrupts */
  878. atomic_t refcount; /* number of users of vblank interruptsper crtc */
  879. u32 last; /* protected by dev->vbl_lock, used */
  880. /* for wraparound handling */
  881. u32 last_wait; /* Last vblank seqno waited per CRTC */
  882. unsigned int inmodeset; /* Display driver is setting mode */
  883. int crtc; /* crtc index */
  884. bool enabled; /* so we don't call enable more than
  885. once per disable */
  886. };
  887. /**
  888. * DRM device structure. This structure represent a complete card that
  889. * may contain multiple heads.
  890. */
  891. struct drm_device {
  892. struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
  893. int if_version; /**< Highest interface version set */
  894. /** \name Lifetime Management */
  895. /*@{ */
  896. struct kref ref; /**< Object ref-count */
  897. struct device *dev; /**< Device structure of bus-device */
  898. struct drm_driver *driver; /**< DRM driver managing the device */
  899. void *dev_private; /**< DRM driver private data */
  900. struct drm_minor *control; /**< Control node */
  901. struct drm_minor *primary; /**< Primary node */
  902. struct drm_minor *render; /**< Render node */
  903. atomic_t unplugged; /**< Flag whether dev is dead */
  904. struct inode *anon_inode; /**< inode for private address-space */
  905. char *unique; /**< unique name of the device */
  906. /*@} */
  907. /** \name Locks */
  908. /*@{ */
  909. struct mutex struct_mutex; /**< For others */
  910. struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
  911. /*@} */
  912. /** \name Usage Counters */
  913. /*@{ */
  914. int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
  915. spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
  916. int buf_use; /**< Buffers in use -- cannot alloc */
  917. atomic_t buf_alloc; /**< Buffer allocation in progress */
  918. /*@} */
  919. struct list_head filelist;
  920. /** \name Memory management */
  921. /*@{ */
  922. struct list_head maplist; /**< Linked list of regions */
  923. struct drm_open_hash map_hash; /**< User token hash table for maps */
  924. /** \name Context handle management */
  925. /*@{ */
  926. struct list_head ctxlist; /**< Linked list of context handles */
  927. struct mutex ctxlist_mutex; /**< For ctxlist */
  928. struct idr ctx_idr;
  929. struct list_head vmalist; /**< List of vmas (for debugging) */
  930. /*@} */
  931. /** \name DMA support */
  932. /*@{ */
  933. struct drm_device_dma *dma; /**< Optional pointer for DMA support */
  934. /*@} */
  935. /** \name Context support */
  936. /*@{ */
  937. bool irq_enabled; /**< True if irq handler is enabled */
  938. int irq;
  939. __volatile__ long context_flag; /**< Context swapping flag */
  940. int last_context; /**< Last current context */
  941. /*@} */
  942. /** \name VBLANK IRQ support */
  943. /*@{ */
  944. /*
  945. * At load time, disabling the vblank interrupt won't be allowed since
  946. * old clients may not call the modeset ioctl and therefore misbehave.
  947. * Once the modeset ioctl *has* been called though, we can safely
  948. * disable them when unused.
  949. */
  950. bool vblank_disable_allowed;
  951. /* array of size num_crtcs */
  952. struct drm_vblank_crtc *vblank;
  953. spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
  954. spinlock_t vbl_lock;
  955. u32 max_vblank_count; /**< size of vblank counter register */
  956. /**
  957. * List of events
  958. */
  959. struct list_head vblank_event_list;
  960. spinlock_t event_lock;
  961. /*@} */
  962. struct drm_agp_head *agp; /**< AGP data */
  963. struct pci_dev *pdev; /**< PCI device structure */
  964. #ifdef __alpha__
  965. struct pci_controller *hose;
  966. #endif
  967. struct platform_device *platformdev; /**< Platform device struture */
  968. struct usb_device *usbdev;
  969. struct drm_sg_mem *sg; /**< Scatter gather memory */
  970. unsigned int num_crtcs; /**< Number of CRTCs on this device */
  971. struct drm_sigdata sigdata; /**< For block_all_signals */
  972. sigset_t sigmask;
  973. struct drm_local_map *agp_buffer_map;
  974. unsigned int agp_buffer_token;
  975. struct drm_mode_config mode_config; /**< Current mode config */
  976. /** \name GEM information */
  977. /*@{ */
  978. struct mutex object_name_lock;
  979. struct idr object_name_idr;
  980. struct drm_vma_offset_manager *vma_offset_manager;
  981. /*@} */
  982. int switch_power_state;
  983. };
  984. #define DRM_SWITCH_POWER_ON 0
  985. #define DRM_SWITCH_POWER_OFF 1
  986. #define DRM_SWITCH_POWER_CHANGING 2
  987. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  988. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  989. int feature)
  990. {
  991. return ((dev->driver->driver_features & feature) ? 1 : 0);
  992. }
  993. static inline void drm_device_set_unplugged(struct drm_device *dev)
  994. {
  995. smp_wmb();
  996. atomic_set(&dev->unplugged, 1);
  997. }
  998. static inline int drm_device_is_unplugged(struct drm_device *dev)
  999. {
  1000. int ret = atomic_read(&dev->unplugged);
  1001. smp_rmb();
  1002. return ret;
  1003. }
  1004. static inline bool drm_is_render_client(const struct drm_file *file_priv)
  1005. {
  1006. return file_priv->minor->type == DRM_MINOR_RENDER;
  1007. }
  1008. static inline bool drm_is_control_client(const struct drm_file *file_priv)
  1009. {
  1010. return file_priv->minor->type == DRM_MINOR_CONTROL;
  1011. }
  1012. static inline bool drm_is_primary_client(const struct drm_file *file_priv)
  1013. {
  1014. return file_priv->minor->type == DRM_MINOR_LEGACY;
  1015. }
  1016. /******************************************************************/
  1017. /** \name Internal function definitions */
  1018. /*@{*/
  1019. /* Driver support (drm_drv.h) */
  1020. extern long drm_ioctl(struct file *filp,
  1021. unsigned int cmd, unsigned long arg);
  1022. extern long drm_compat_ioctl(struct file *filp,
  1023. unsigned int cmd, unsigned long arg);
  1024. extern int drm_lastclose(struct drm_device *dev);
  1025. extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  1026. /* Device support (drm_fops.h) */
  1027. extern struct mutex drm_global_mutex;
  1028. extern int drm_open(struct inode *inode, struct file *filp);
  1029. extern ssize_t drm_read(struct file *filp, char __user *buffer,
  1030. size_t count, loff_t *offset);
  1031. extern int drm_release(struct inode *inode, struct file *filp);
  1032. /* Mapping support (drm_vm.h) */
  1033. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  1034. extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
  1035. extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1036. extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1037. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  1038. /* Memory management support (drm_memory.h) */
  1039. #include <drm/drm_memory.h>
  1040. /* Misc. IOCTL support (drm_ioctl.h) */
  1041. extern int drm_irq_by_busid(struct drm_device *dev, void *data,
  1042. struct drm_file *file_priv);
  1043. extern int drm_getunique(struct drm_device *dev, void *data,
  1044. struct drm_file *file_priv);
  1045. extern int drm_setunique(struct drm_device *dev, void *data,
  1046. struct drm_file *file_priv);
  1047. extern int drm_getmap(struct drm_device *dev, void *data,
  1048. struct drm_file *file_priv);
  1049. extern int drm_getclient(struct drm_device *dev, void *data,
  1050. struct drm_file *file_priv);
  1051. extern int drm_getstats(struct drm_device *dev, void *data,
  1052. struct drm_file *file_priv);
  1053. extern int drm_getcap(struct drm_device *dev, void *data,
  1054. struct drm_file *file_priv);
  1055. extern int drm_setclientcap(struct drm_device *dev, void *data,
  1056. struct drm_file *file_priv);
  1057. extern int drm_setversion(struct drm_device *dev, void *data,
  1058. struct drm_file *file_priv);
  1059. extern int drm_noop(struct drm_device *dev, void *data,
  1060. struct drm_file *file_priv);
  1061. /* Authentication IOCTL support (drm_auth.h) */
  1062. extern int drm_getmagic(struct drm_device *dev, void *data,
  1063. struct drm_file *file_priv);
  1064. extern int drm_authmagic(struct drm_device *dev, void *data,
  1065. struct drm_file *file_priv);
  1066. extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
  1067. /* Cache management (drm_cache.c) */
  1068. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  1069. void drm_clflush_sg(struct sg_table *st);
  1070. void drm_clflush_virt_range(void *addr, unsigned long length);
  1071. /* Locking IOCTL support (drm_lock.h) */
  1072. extern int drm_lock(struct drm_device *dev, void *data,
  1073. struct drm_file *file_priv);
  1074. extern int drm_unlock(struct drm_device *dev, void *data,
  1075. struct drm_file *file_priv);
  1076. extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
  1077. extern void drm_idlelock_take(struct drm_lock_data *lock_data);
  1078. extern void drm_idlelock_release(struct drm_lock_data *lock_data);
  1079. /*
  1080. * These are exported to drivers so that they can implement fencing using
  1081. * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  1082. */
  1083. extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
  1084. /* Buffer management support (drm_bufs.h) */
  1085. extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
  1086. extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
  1087. extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
  1088. unsigned int size, enum drm_map_type type,
  1089. enum drm_map_flags flags, struct drm_local_map **map_ptr);
  1090. extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
  1091. struct drm_file *file_priv);
  1092. extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
  1093. extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
  1094. extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
  1095. struct drm_file *file_priv);
  1096. extern int drm_addbufs(struct drm_device *dev, void *data,
  1097. struct drm_file *file_priv);
  1098. extern int drm_infobufs(struct drm_device *dev, void *data,
  1099. struct drm_file *file_priv);
  1100. extern int drm_markbufs(struct drm_device *dev, void *data,
  1101. struct drm_file *file_priv);
  1102. extern int drm_freebufs(struct drm_device *dev, void *data,
  1103. struct drm_file *file_priv);
  1104. extern int drm_mapbufs(struct drm_device *dev, void *data,
  1105. struct drm_file *file_priv);
  1106. extern int drm_dma_ioctl(struct drm_device *dev, void *data,
  1107. struct drm_file *file_priv);
  1108. /* DMA support (drm_dma.h) */
  1109. extern int drm_legacy_dma_setup(struct drm_device *dev);
  1110. extern void drm_legacy_dma_takedown(struct drm_device *dev);
  1111. extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
  1112. extern void drm_core_reclaim_buffers(struct drm_device *dev,
  1113. struct drm_file *filp);
  1114. /* IRQ support (drm_irq.h) */
  1115. extern int drm_control(struct drm_device *dev, void *data,
  1116. struct drm_file *file_priv);
  1117. extern int drm_irq_install(struct drm_device *dev, int irq);
  1118. extern int drm_irq_uninstall(struct drm_device *dev);
  1119. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  1120. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  1121. struct drm_file *filp);
  1122. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  1123. extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
  1124. struct timeval *vblanktime);
  1125. extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
  1126. struct drm_pending_vblank_event *e);
  1127. extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
  1128. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1129. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1130. extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
  1131. extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
  1132. extern void drm_vblank_off(struct drm_device *dev, int crtc);
  1133. extern void drm_vblank_on(struct drm_device *dev, int crtc);
  1134. extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
  1135. extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
  1136. extern void drm_vblank_cleanup(struct drm_device *dev);
  1137. extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
  1138. struct timeval *tvblank, unsigned flags);
  1139. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  1140. int crtc, int *max_error,
  1141. struct timeval *vblank_time,
  1142. unsigned flags,
  1143. const struct drm_crtc *refcrtc,
  1144. const struct drm_display_mode *mode);
  1145. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
  1146. const struct drm_display_mode *mode);
  1147. /* Modesetting support */
  1148. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1149. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1150. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1151. struct drm_file *file_priv);
  1152. /* AGP/GART support (drm_agpsupport.h) */
  1153. #include <drm/drm_agpsupport.h>
  1154. /* Stub support (drm_stub.h) */
  1155. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1156. struct drm_file *file_priv);
  1157. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1158. struct drm_file *file_priv);
  1159. struct drm_master *drm_master_create(struct drm_minor *minor);
  1160. extern struct drm_master *drm_master_get(struct drm_master *master);
  1161. extern void drm_master_put(struct drm_master **master);
  1162. extern void drm_put_dev(struct drm_device *dev);
  1163. extern void drm_unplug_dev(struct drm_device *dev);
  1164. extern unsigned int drm_debug;
  1165. extern unsigned int drm_vblank_offdelay;
  1166. extern unsigned int drm_timestamp_precision;
  1167. extern unsigned int drm_timestamp_monotonic;
  1168. extern struct class *drm_class;
  1169. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1170. /* Debugfs support */
  1171. #if defined(CONFIG_DEBUG_FS)
  1172. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1173. struct dentry *root);
  1174. extern int drm_debugfs_create_files(const struct drm_info_list *files,
  1175. int count, struct dentry *root,
  1176. struct drm_minor *minor);
  1177. extern int drm_debugfs_remove_files(const struct drm_info_list *files,
  1178. int count, struct drm_minor *minor);
  1179. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1180. extern int drm_debugfs_connector_add(struct drm_connector *connector);
  1181. extern void drm_debugfs_connector_remove(struct drm_connector *connector);
  1182. #else
  1183. static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1184. struct dentry *root)
  1185. {
  1186. return 0;
  1187. }
  1188. static inline int drm_debugfs_create_files(const struct drm_info_list *files,
  1189. int count, struct dentry *root,
  1190. struct drm_minor *minor)
  1191. {
  1192. return 0;
  1193. }
  1194. static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
  1195. int count, struct drm_minor *minor)
  1196. {
  1197. return 0;
  1198. }
  1199. static inline int drm_debugfs_cleanup(struct drm_minor *minor)
  1200. {
  1201. return 0;
  1202. }
  1203. static inline int drm_debugfs_connector_add(struct drm_connector *connector)
  1204. {
  1205. return 0;
  1206. }
  1207. static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
  1208. {
  1209. }
  1210. #endif
  1211. /* Info file support */
  1212. extern int drm_name_info(struct seq_file *m, void *data);
  1213. extern int drm_vm_info(struct seq_file *m, void *data);
  1214. extern int drm_bufs_info(struct seq_file *m, void *data);
  1215. extern int drm_vblank_info(struct seq_file *m, void *data);
  1216. extern int drm_clients_info(struct seq_file *m, void* data);
  1217. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1218. extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  1219. struct drm_gem_object *obj, int flags);
  1220. extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  1221. struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  1222. int *prime_fd);
  1223. extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  1224. struct dma_buf *dma_buf);
  1225. extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  1226. struct drm_file *file_priv, int prime_fd, uint32_t *handle);
  1227. extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
  1228. extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
  1229. struct drm_file *file_priv);
  1230. extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
  1231. struct drm_file *file_priv);
  1232. extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  1233. dma_addr_t *addrs, int max_pages);
  1234. extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
  1235. extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
  1236. int drm_gem_dumb_destroy(struct drm_file *file,
  1237. struct drm_device *dev,
  1238. uint32_t handle);
  1239. void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
  1240. void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
  1241. void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
  1242. #if DRM_DEBUG_CODE
  1243. extern int drm_vma_info(struct seq_file *m, void *data);
  1244. #endif
  1245. /* Scatter Gather Support (drm_scatter.h) */
  1246. extern void drm_legacy_sg_cleanup(struct drm_device *dev);
  1247. extern int drm_sg_alloc(struct drm_device *dev, void *data,
  1248. struct drm_file *file_priv);
  1249. extern int drm_sg_free(struct drm_device *dev, void *data,
  1250. struct drm_file *file_priv);
  1251. /* ATI PCIGART support (ati_pcigart.h) */
  1252. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1253. struct drm_ati_pcigart_info * gart_info);
  1254. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1255. struct drm_ati_pcigart_info * gart_info);
  1256. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1257. size_t align);
  1258. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1259. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1260. extern int drm_pci_set_unique(struct drm_device *dev,
  1261. struct drm_master *master,
  1262. struct drm_unique *u);
  1263. /* sysfs support (drm_sysfs.c) */
  1264. struct drm_sysfs_class;
  1265. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1266. extern void drm_sysfs_destroy(void);
  1267. extern struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
  1268. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1269. extern int drm_sysfs_connector_add(struct drm_connector *connector);
  1270. extern void drm_sysfs_connector_remove(struct drm_connector *connector);
  1271. /* Graphics Execution Manager library functions (drm_gem.c) */
  1272. int drm_gem_init(struct drm_device *dev);
  1273. void drm_gem_destroy(struct drm_device *dev);
  1274. void drm_gem_object_release(struct drm_gem_object *obj);
  1275. void drm_gem_object_free(struct kref *kref);
  1276. int drm_gem_object_init(struct drm_device *dev,
  1277. struct drm_gem_object *obj, size_t size);
  1278. void drm_gem_private_object_init(struct drm_device *dev,
  1279. struct drm_gem_object *obj, size_t size);
  1280. void drm_gem_vm_open(struct vm_area_struct *vma);
  1281. void drm_gem_vm_close(struct vm_area_struct *vma);
  1282. int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
  1283. struct vm_area_struct *vma);
  1284. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1285. #include <drm/drm_global.h>
  1286. static inline void
  1287. drm_gem_object_reference(struct drm_gem_object *obj)
  1288. {
  1289. kref_get(&obj->refcount);
  1290. }
  1291. static inline void
  1292. drm_gem_object_unreference(struct drm_gem_object *obj)
  1293. {
  1294. if (obj != NULL)
  1295. kref_put(&obj->refcount, drm_gem_object_free);
  1296. }
  1297. static inline void
  1298. drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
  1299. {
  1300. if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
  1301. struct drm_device *dev = obj->dev;
  1302. mutex_lock(&dev->struct_mutex);
  1303. if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
  1304. drm_gem_object_free(&obj->refcount);
  1305. mutex_unlock(&dev->struct_mutex);
  1306. }
  1307. }
  1308. int drm_gem_handle_create_tail(struct drm_file *file_priv,
  1309. struct drm_gem_object *obj,
  1310. u32 *handlep);
  1311. int drm_gem_handle_create(struct drm_file *file_priv,
  1312. struct drm_gem_object *obj,
  1313. u32 *handlep);
  1314. int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
  1315. void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
  1316. int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
  1317. int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
  1318. struct page **drm_gem_get_pages(struct drm_gem_object *obj);
  1319. void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
  1320. bool dirty, bool accessed);
  1321. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1322. struct drm_file *filp,
  1323. u32 handle);
  1324. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1325. struct drm_file *file_priv);
  1326. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1327. struct drm_file *file_priv);
  1328. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1329. struct drm_file *file_priv);
  1330. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1331. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1332. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1333. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1334. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1335. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1336. unsigned int token)
  1337. {
  1338. struct drm_map_list *_entry;
  1339. list_for_each_entry(_entry, &dev->maplist, head)
  1340. if (_entry->user_token == token)
  1341. return _entry->map;
  1342. return NULL;
  1343. }
  1344. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1345. {
  1346. }
  1347. #include <drm/drm_mem_util.h>
  1348. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  1349. struct device *parent);
  1350. void drm_dev_ref(struct drm_device *dev);
  1351. void drm_dev_unref(struct drm_device *dev);
  1352. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  1353. void drm_dev_unregister(struct drm_device *dev);
  1354. int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
  1355. struct drm_minor *drm_minor_acquire(unsigned int minor_id);
  1356. void drm_minor_release(struct drm_minor *minor);
  1357. /*@}*/
  1358. /* PCI section */
  1359. static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
  1360. {
  1361. if (dev->driver->device_is_agp != NULL) {
  1362. int err = (*dev->driver->device_is_agp) (dev);
  1363. if (err != 2) {
  1364. return err;
  1365. }
  1366. }
  1367. return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1368. }
  1369. void drm_pci_agp_destroy(struct drm_device *dev);
  1370. extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  1371. extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  1372. extern int drm_get_pci_dev(struct pci_dev *pdev,
  1373. const struct pci_device_id *ent,
  1374. struct drm_driver *driver);
  1375. #define DRM_PCIE_SPEED_25 1
  1376. #define DRM_PCIE_SPEED_50 2
  1377. #define DRM_PCIE_SPEED_80 4
  1378. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  1379. /* platform section */
  1380. extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
  1381. /* returns true if currently okay to sleep */
  1382. static __inline__ bool drm_can_sleep(void)
  1383. {
  1384. if (in_atomic() || in_dbg_master() || irqs_disabled())
  1385. return false;
  1386. return true;
  1387. }
  1388. #endif /* __KERNEL__ */
  1389. #endif