blob: 3b7fda557b8dd16635a84568efba9cf36618446e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
Dave Airlieb5e89ed2005-09-25 14:28:13 +10002 * \file drmP.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Private header for Direct Rendering Manager
Dave Airlieb5e89ed2005-09-25 14:28:13 +10004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 */
8
9/*
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
Jordan Crousedcdb1672010-05-27 13:40:25 -060012 * Copyright (c) 2009-2010, Code Aurora Forum.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * All rights reserved.
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
21 *
22 * The above copyright notice and this permission notice (including the next
23 * paragraph) shall be included in all copies or substantial portions of the
24 * Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
33 */
34
35#ifndef _DRM_P_H_
36#define _DRM_P_H_
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#ifdef __KERNEL__
39#ifdef __alpha__
40/* add include of current.h so that "current" is defined
41 * before static inline funcs in wait.h. Doing this so we
42 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
43#include <asm/current.h>
Dave Airlieb5e89ed2005-09-25 14:28:13 +100044#endif /* __alpha__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/kernel.h>
46#include <linux/miscdevice.h>
47#include <linux/fs.h>
48#include <linux/proc_fs.h>
49#include <linux/init.h>
50#include <linux/file.h>
Jordan Crousedcdb1672010-05-27 13:40:25 -060051#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <linux/jiffies.h>
Dave Airlieb05c2382008-03-17 10:24:24 +100054#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/mm.h>
56#include <linux/cdev.h>
Dave Airlie30e2fb12006-02-02 19:37:46 +110057#include <linux/mutex.h>
Andy Lutomirski03dae7c2013-05-13 23:58:47 +000058#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090059#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#if defined(__alpha__) || defined(__powerpc__)
Dave Airlieb5e89ed2005-09-25 14:28:13 +100061#include <asm/pgtable.h> /* For pte_wrprotect */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <asm/mman.h>
64#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
66#include <linux/types.h>
67#include <linux/agp_backend.h>
68#endif
69#include <linux/workqueue.h>
70#include <linux/poll.h>
71#include <asm/pgalloc.h>
David Howells19218e42012-10-02 18:01:03 +010072#include <drm/drm.h>
73#include <drm/drm_sarea.h>
David Herrmann0de23972013-07-24 21:07:52 +020074#include <drm/drm_vma_manager.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Dave Airlie62968142007-07-17 10:46:52 +100076#include <linux/idr.h>
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
79#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
80
Paul Gortmakerde477252011-05-26 13:46:22 -040081struct module;
82
Eric Anholtc153f452007-09-03 12:06:45 +100083struct drm_file;
84struct drm_device;
85
Steffen Trumtraredb37a92012-10-28 18:28:06 +010086struct device_node;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010087struct videomode;
88
David Howellsa1ce3922012-10-02 18:01:25 +010089#include <drm/drm_os_linux.h>
90#include <drm/drm_hashtab.h>
91#include <drm/drm_mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
yakui_zhao4fefcb22009-06-02 14:09:47 +080093#define DRM_UT_CORE 0x01
94#define DRM_UT_DRIVER 0x02
95#define DRM_UT_KMS 0x04
Dave Airlie32488772011-11-25 15:21:02 +000096#define DRM_UT_PRIME 0x08
Zhao Yakui87fdff82009-07-20 13:48:06 +080097/*
98 * Three debug levels are defined.
99 * drm_core, drm_driver, drm_kms
100 * drm_core level can be used in the generic drm code. For example:
101 * drm_ioctl, drm_mm, drm_memory
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300102 * The macro definition of DRM_DEBUG is used.
Zhao Yakui87fdff82009-07-20 13:48:06 +0800103 * DRM_DEBUG(fmt, args...)
104 * The debug info by using the DRM_DEBUG can be obtained by adding
105 * the boot option of "drm.debug=1".
106 *
107 * drm_driver level can be used in the specific drm driver. It is used
108 * to add the debug info related with the drm driver. For example:
109 * i915_drv, i915_dma, i915_gem, radeon_drv,
110 * The macro definition of DRM_DEBUG_DRIVER can be used.
111 * DRM_DEBUG_DRIVER(fmt, args...)
112 * The debug info by using the DRM_DEBUG_DRIVER can be obtained by
113 * adding the boot option of "drm.debug=0x02"
114 *
115 * drm_kms level can be used in the KMS code related with specific drm driver.
116 * It is used to add the debug info related with KMS mode. For example:
117 * the connector/crtc ,
118 * The macro definition of DRM_DEBUG_KMS can be used.
119 * DRM_DEBUG_KMS(fmt, args...)
120 * The debug info by using the DRM_DEBUG_KMS can be obtained by
121 * adding the boot option of "drm.debug=0x04"
122 *
123 * If we add the boot option of "drm.debug=0x06", we can get the debug info by
124 * using the DRM_DEBUG_KMS and DRM_DEBUG_DRIVER.
125 * If we add the boot option of "drm.debug=0x05", we can get the debug info by
126 * using the DRM_DEBUG_KMS and DRM_DEBUG.
127 */
yakui_zhao4fefcb22009-06-02 14:09:47 +0800128
Joe Perchesb9075fa2011-10-31 17:11:33 -0700129extern __printf(4, 5)
Joe Perchesbbb0aef2011-04-17 20:35:52 -0700130void drm_ut_debug_printk(unsigned int request_level,
Joe Perchesb9075fa2011-10-31 17:11:33 -0700131 const char *prefix,
132 const char *function_name,
133 const char *format, ...);
134extern __printf(2, 3)
Joe Perches5ad3d882011-04-17 20:35:51 -0700135int drm_err(const char *func, const char *format, ...);
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/***********************************************************************/
138/** \name DRM template customization defaults */
139/*@{*/
140
141/* driver capabilities and requirements mask */
142#define DRIVER_USE_AGP 0x1
143#define DRIVER_REQUIRE_AGP 0x2
144#define DRIVER_USE_MTRR 0x4
145#define DRIVER_PCI_DMA 0x8
146#define DRIVER_SG 0x10
147#define DRIVER_HAVE_DMA 0x20
148#define DRIVER_HAVE_IRQ 0x40
149#define DRIVER_IRQ_SHARED 0x80
Dave Airlieaf6061a2008-05-07 12:15:39 +1000150#define DRIVER_IRQ_VBL 0x100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define DRIVER_DMA_QUEUE 0x200
Dave Airlieb84397d62005-07-10 14:46:12 +1000152#define DRIVER_FB_DMA 0x400
Dave Airlieaf6061a2008-05-07 12:15:39 +1000153#define DRIVER_IRQ_VBL2 0x800
Eric Anholt673a3942008-07-30 12:06:12 -0700154#define DRIVER_GEM 0x1000
Dave Airlief453ba02008-11-07 14:05:41 -0800155#define DRIVER_MODESET 0x2000
Dave Airlie32488772011-11-25 15:21:02 +0000156#define DRIVER_PRIME 0x4000
Dave Airlie8410ea32010-12-15 03:16:38 +1000157
158#define DRIVER_BUS_PCI 0x1
159#define DRIVER_BUS_PLATFORM 0x2
160#define DRIVER_BUS_USB 0x3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162/***********************************************************************/
163/** \name Begin the DRM... */
164/*@{*/
165
166#define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
167 also include looping detection. */
168
Thomas Hellstrom8669cbc2006-08-07 22:22:10 +1000169#define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
171#define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
172#define DRM_LOOPING_LIMIT 5000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
174#define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
175
176#define DRM_FLAG_DEBUG 0x01
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
Thomas Hellstrom8d153f72006-08-07 22:36:47 +1000179#define DRM_MAP_HASH_OFFSET 0x10000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000181/*@}*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183/***********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/** \name Macros to make printk easier */
185/*@{*/
186
187/**
188 * Error output.
189 *
190 * \param fmt printf() like format string.
191 * \param arg arguments
192 */
Joe Perches5ad3d882011-04-17 20:35:51 -0700193#define DRM_ERROR(fmt, ...) \
194 drm_err(__func__, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Joe Perches5ad3d882011-04-17 20:35:51 -0700196#define DRM_INFO(fmt, ...) \
197 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199/**
200 * Debug output.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000201 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 * \param fmt printf() like format string.
203 * \param arg arguments
204 */
205#if DRM_DEBUG_CODE
yakui_zhao4fefcb22009-06-02 14:09:47 +0800206#define DRM_DEBUG(fmt, args...) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 do { \
yakui_zhao4fefcb22009-06-02 14:09:47 +0800208 drm_ut_debug_printk(DRM_UT_CORE, DRM_NAME, \
209 __func__, fmt, ##args); \
210 } while (0)
211
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800212#define DRM_DEBUG_DRIVER(fmt, args...) \
yakui_zhao4fefcb22009-06-02 14:09:47 +0800213 do { \
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800214 drm_ut_debug_printk(DRM_UT_DRIVER, DRM_NAME, \
yakui_zhao4fefcb22009-06-02 14:09:47 +0800215 __func__, fmt, ##args); \
216 } while (0)
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800217#define DRM_DEBUG_KMS(fmt, args...) \
yakui_zhao4fefcb22009-06-02 14:09:47 +0800218 do { \
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800219 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \
yakui_zhao4fefcb22009-06-02 14:09:47 +0800220 __func__, fmt, ##args); \
221 } while (0)
Dave Airlie32488772011-11-25 15:21:02 +0000222#define DRM_DEBUG_PRIME(fmt, args...) \
223 do { \
224 drm_ut_debug_printk(DRM_UT_PRIME, DRM_NAME, \
225 __func__, fmt, ##args); \
226 } while (0)
yakui_zhao4fefcb22009-06-02 14:09:47 +0800227#define DRM_LOG(fmt, args...) \
228 do { \
229 drm_ut_debug_printk(DRM_UT_CORE, NULL, \
230 NULL, fmt, ##args); \
231 } while (0)
232#define DRM_LOG_KMS(fmt, args...) \
233 do { \
234 drm_ut_debug_printk(DRM_UT_KMS, NULL, \
235 NULL, fmt, ##args); \
236 } while (0)
237#define DRM_LOG_MODE(fmt, args...) \
238 do { \
239 drm_ut_debug_printk(DRM_UT_MODE, NULL, \
240 NULL, fmt, ##args); \
241 } while (0)
242#define DRM_LOG_DRIVER(fmt, args...) \
243 do { \
244 drm_ut_debug_printk(DRM_UT_DRIVER, NULL, \
245 NULL, fmt, ##args); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 } while (0)
247#else
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800248#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
249#define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
Dave Airlie32488772011-11-25 15:21:02 +0000250#define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define DRM_DEBUG(fmt, arg...) do { } while (0)
yakui_zhao4fefcb22009-06-02 14:09:47 +0800252#define DRM_LOG(fmt, arg...) do { } while (0)
253#define DRM_LOG_KMS(fmt, args...) do { } while (0)
254#define DRM_LOG_MODE(fmt, arg...) do { } while (0)
255#define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#endif
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/*@}*/
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/***********************************************************************/
262/** \name Internal types and structures */
263/*@{*/
264
Dave Airlie99a26572005-09-25 13:25:41 +1000265#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
268#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272/**
273 * Test that the hardware lock is held by the caller, returning otherwise.
274 *
275 * \param dev DRM device.
276 * \param filp file pointer of the caller.
277 */
Roel Kluindcae3622009-06-10 12:43:48 -0700278#define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
279do { \
280 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
281 _file_priv->master->lock.file_priv != _file_priv) { \
Eric Anholtc153f452007-09-03 12:06:45 +1000282 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
Roel Kluindcae3622009-06-10 12:43:48 -0700283 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
284 _file_priv->master->lock.file_priv, _file_priv); \
285 return -EINVAL; \
286 } \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287} while (0)
288
289/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 * Ioctl function type.
291 *
292 * \param inode device inode.
Eric Anholt6c340ea2007-08-25 20:23:09 +1000293 * \param file_priv DRM file private pointer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 * \param cmd command.
295 * \param arg argument.
296 */
Eric Anholtc153f452007-09-03 12:06:45 +1000297typedef int drm_ioctl_t(struct drm_device *dev, void *data,
298 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Dave Airlie9a186642005-06-23 21:29:18 +1000300typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
301 unsigned long arg);
302
Kristian Høgsberg1a959162009-12-02 12:13:48 -0500303#define DRM_IOCTL_NR(n) _IOC_NR(n)
304#define DRM_MAJOR 226
305
Dave Airliea7a2cc32006-01-02 13:54:04 +1100306#define DRM_AUTH 0x1
307#define DRM_MASTER 0x2
308#define DRM_ROOT_ONLY 0x4
Dave Airlief453ba02008-11-07 14:05:41 -0800309#define DRM_CONTROL_ALLOW 0x8
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000310#define DRM_UNLOCKED 0x10
Dave Airliea7a2cc32006-01-02 13:54:04 +1100311
Eric Anholtc153f452007-09-03 12:06:45 +1000312struct drm_ioctl_desc {
313 unsigned int cmd;
Dave Airliea7a2cc32006-01-02 13:54:04 +1100314 int flags;
Richard Kennedyc972d752009-03-18 17:26:44 +0000315 drm_ioctl_t *func;
Dave Airlie1b2f1482010-08-14 20:20:34 +1000316 unsigned int cmd_drv;
Chris Cumminsb9434d02013-05-09 14:20:40 +0100317 const char *name;
Eric Anholtc153f452007-09-03 12:06:45 +1000318};
319
320/**
321 * Creates a driver or general drm_ioctl_desc array entry for the given
322 * ioctl, for use by drm_ioctl().
323 */
Dave Airlie1b2f1482010-08-14 20:20:34 +1000324
325#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
Chris Cumminsb9434d02013-05-09 14:20:40 +0100326 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Dave Airlie8fc2fdf2007-07-11 16:21:47 +1000328struct drm_magic_entry {
Thomas Hellstrom8669cbc2006-08-07 22:22:10 +1000329 struct list_head head;
Dave Airliee0be4282007-07-12 10:26:44 +1000330 struct drm_hash_item hash_item;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000331 struct drm_file *priv;
Dave Airlie8fc2fdf2007-07-11 16:21:47 +1000332};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Dave Airlie8fc2fdf2007-07-11 16:21:47 +1000334struct drm_vma_entry {
Dave Airliebd1b3312007-05-26 05:01:51 +1000335 struct list_head head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 struct vm_area_struct *vma;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000337 pid_t pid;
Dave Airlie8fc2fdf2007-07-11 16:21:47 +1000338};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340/**
341 * DMA buffer.
342 */
Dave Airlie056219e2007-07-11 16:17:42 +1000343struct drm_buf {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000344 int idx; /**< Index into master buflist */
345 int total; /**< Buffer size */
346 int order; /**< log-base-2(total) */
347 int used; /**< Amount of buffer in use (for DMA) */
348 unsigned long offset; /**< Byte offset (used internally) */
349 void *address; /**< Address of buffer */
350 unsigned long bus_address; /**< Bus address of buffer */
351 struct drm_buf *next; /**< Kernel-only: used for free list */
352 __volatile__ int waiting; /**< On kernel DMA queue */
353 __volatile__ int pending; /**< On hardware DMA queue */
Eric Anholt6c340ea2007-08-25 20:23:09 +1000354 struct drm_file *file_priv; /**< Private of holding file descr */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000355 int context; /**< Kernel queue for this buffer */
356 int while_locked; /**< Dispatch this buffer while locked */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 enum {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000358 DRM_LIST_NONE = 0,
359 DRM_LIST_FREE = 1,
360 DRM_LIST_WAIT = 2,
361 DRM_LIST_PEND = 3,
362 DRM_LIST_PRIO = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 DRM_LIST_RECLAIM = 5
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000364 } list; /**< Which list we're on */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000366 int dev_priv_size; /**< Size of buffer private storage */
367 void *dev_private; /**< Per-buffer private storage */
Dave Airlie056219e2007-07-11 16:17:42 +1000368};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/** bufs is one longer than it has to be */
Dave Airliecdd55a22007-07-11 16:32:08 +1000371struct drm_waitlist {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000372 int count; /**< Number of possible buffers */
Dave Airlie056219e2007-07-11 16:17:42 +1000373 struct drm_buf **bufs; /**< List of pointers to buffers */
374 struct drm_buf **rp; /**< Read pointer */
375 struct drm_buf **wp; /**< Write pointer */
376 struct drm_buf **end; /**< End pointer */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000377 spinlock_t read_lock;
378 spinlock_t write_lock;
Dave Airliecdd55a22007-07-11 16:32:08 +1000379};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Dave Airliecdd55a22007-07-11 16:32:08 +1000381struct drm_freelist {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000382 int initialized; /**< Freelist in use */
383 atomic_t count; /**< Number of free buffers */
Dave Airlie056219e2007-07-11 16:17:42 +1000384 struct drm_buf *next; /**< End pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000387 int low_mark; /**< Low water mark */
388 int high_mark; /**< High water mark */
389 atomic_t wfh; /**< If waiting for high mark */
390 spinlock_t lock;
Dave Airliecdd55a22007-07-11 16:32:08 +1000391};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Dave Airlieddf19b92006-03-19 18:56:12 +1100393typedef struct drm_dma_handle {
394 dma_addr_t busaddr;
395 void *vaddr;
396 size_t size;
397} drm_dma_handle_t;
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399/**
400 * Buffer entry. There is one of this for each buffer size order.
401 */
Dave Airliecdd55a22007-07-11 16:32:08 +1000402struct drm_buf_entry {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000403 int buf_size; /**< size */
404 int buf_count; /**< number of buffers */
Dave Airlie056219e2007-07-11 16:17:42 +1000405 struct drm_buf *buflist; /**< buffer list */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000406 int seg_count;
407 int page_order;
Dave Airliecdd55a22007-07-11 16:32:08 +1000408 struct drm_dma_handle **seglist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Dave Airliecdd55a22007-07-11 16:32:08 +1000410 struct drm_freelist freelist;
411};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000413/* Event queued up for userspace to read */
414struct drm_pending_event {
415 struct drm_event *event;
416 struct list_head link;
417 struct drm_file *file_priv;
Jesse Barnesb9c2c9a2010-07-01 16:48:09 -0700418 pid_t pid; /* pid of requester, no guarantee it's valid by the time
419 we deliver the event, for tracing only */
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000420 void (*destroy)(struct drm_pending_event *event);
421};
422
Dave Airlie32488772011-11-25 15:21:02 +0000423/* initial implementaton using a linked list - todo hashtab */
424struct drm_prime_file_private {
425 struct list_head head;
426 struct mutex lock;
427};
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429/** File private data */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000430struct drm_file {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000431 int authenticated;
Eric W. Biederman5fce5e02012-02-07 16:47:26 -0800432 struct pid *pid;
433 kuid_t uid;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000434 drm_magic_t magic;
435 unsigned long ioctl_count;
Dave Airliebd1b3312007-05-26 05:01:51 +1000436 struct list_head lhead;
Dave Airlie2c14f282008-04-21 16:47:32 +1000437 struct drm_minor *minor;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000438 unsigned long lock_count;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000439
Eric Anholt673a3942008-07-30 12:06:12 -0700440 /** Mapping of mm object handles to object pointers. */
441 struct idr object_idr;
442 /** Lock for synchronization of access to object_idr. */
443 spinlock_t table_lock;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000444
Eric Anholt6c340ea2007-08-25 20:23:09 +1000445 struct file *filp;
Dave Airlie8562b3f2007-11-05 12:37:41 +1000446 void *driver_priv;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000447
448 int is_master; /* this file private is a master for a minor */
449 struct drm_master *master; /* master this node is currently associated with
450 N.B. not always minor->master */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100451
452 /**
453 * fbs - List of framebuffers associated with this file.
454 *
455 * Protected by fbs_lock. Note that the fbs list holds a reference on
456 * the fb object to prevent it from untimely disappearing.
457 */
Dave Airlief453ba02008-11-07 14:05:41 -0800458 struct list_head fbs;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100459 struct mutex fbs_lock;
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000460
461 wait_queue_head_t event_wait;
462 struct list_head event_list;
463 int event_space;
Dave Airlie32488772011-11-25 15:21:02 +0000464
465 struct drm_prime_file_private prime;
Dave Airlie84b1fd12007-07-11 15:53:27 +1000466};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468/** Wait queue */
Dave Airliecdd55a22007-07-11 16:32:08 +1000469struct drm_queue {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000470 atomic_t use_count; /**< Outstanding uses (+1) */
471 atomic_t finalization; /**< Finalization in progress */
472 atomic_t block_count; /**< Count of processes waiting */
473 atomic_t block_read; /**< Queue blocked for reads */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000475 atomic_t block_write; /**< Queue blocked for writes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000477 atomic_t total_queued; /**< Total queued statistic */
478 atomic_t total_flushed; /**< Total flushes statistic */
479 atomic_t total_locks; /**< Total locks statistics */
Dave Airliec60ce622007-07-11 15:27:12 +1000480 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
Dave Airliecdd55a22007-07-11 16:32:08 +1000481 struct drm_waitlist waitlist; /**< Pending buffers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
Dave Airliecdd55a22007-07-11 16:32:08 +1000483};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485/**
486 * Lock data.
487 */
Dave Airlie55910512007-07-11 16:53:40 +1000488struct drm_lock_data {
Dave Airliec60ce622007-07-11 15:27:12 +1000489 struct drm_hw_lock *hw_lock; /**< Hardware lock */
Dave Airlie8562b3f2007-11-05 12:37:41 +1000490 /** Private of lock holder's file (NULL=kernel) */
491 struct drm_file *file_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000493 unsigned long lock_time; /**< Time of last lock in jiffies */
Thomas Hellstrom040ac322007-03-23 13:28:33 +1100494 spinlock_t spinlock;
495 uint32_t kernel_waiters;
496 uint32_t user_waiters;
497 int idle_has_lock;
Dave Airlie55910512007-07-11 16:53:40 +1000498};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500/**
501 * DMA data.
502 */
Dave Airliecdd55a22007-07-11 16:32:08 +1000503struct drm_device_dma {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Dave Airliecdd55a22007-07-11 16:32:08 +1000505 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000506 int buf_count; /**< total number of buffers */
Dave Airlie056219e2007-07-11 16:17:42 +1000507 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000508 int seg_count;
509 int page_count; /**< number of pages */
510 unsigned long *pagelist; /**< page list */
511 unsigned long byte_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 enum {
513 _DRM_DMA_USE_AGP = 0x01,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000514 _DRM_DMA_USE_SG = 0x02,
George Sapountzis3417f332006-10-24 12:03:04 -0700515 _DRM_DMA_USE_FB = 0x04,
516 _DRM_DMA_USE_PCI_RO = 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 } flags;
518
Dave Airliecdd55a22007-07-11 16:32:08 +1000519};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000521/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 * AGP memory entry. Stored as a doubly linked list.
523 */
Dave Airlie55910512007-07-11 16:53:40 +1000524struct drm_agp_mem {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000525 unsigned long handle; /**< handle */
526 DRM_AGP_MEM *memory;
527 unsigned long bound; /**< address */
528 int pages;
Dave Airliebd1b3312007-05-26 05:01:51 +1000529 struct list_head head;
Dave Airlie55910512007-07-11 16:53:40 +1000530};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532/**
533 * AGP data.
534 *
535 * \sa drm_agp_init() and drm_device::agp.
536 */
Dave Airlie55910512007-07-11 16:53:40 +1000537struct drm_agp_head {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000538 DRM_AGP_KERN agp_info; /**< AGP device information */
Dave Airliebd1b3312007-05-26 05:01:51 +1000539 struct list_head memory;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000540 unsigned long mode; /**< AGP mode */
541 struct agp_bridge_data *bridge;
542 int enabled; /**< whether the AGP bus as been enabled */
543 int acquired; /**< whether the AGP device has been acquired */
544 unsigned long base;
545 int agp_mtrr;
546 int cant_use_aperture;
547 unsigned long page_mask;
Dave Airlie55910512007-07-11 16:53:40 +1000548};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550/**
551 * Scatter-gather memory.
552 */
Dave Airlie55910512007-07-11 16:53:40 +1000553struct drm_sg_mem {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000554 unsigned long handle;
555 void *virtual;
556 int pages;
557 struct page **pagelist;
558 dma_addr_t *busaddr;
Dave Airlie55910512007-07-11 16:53:40 +1000559};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Dave Airlie55910512007-07-11 16:53:40 +1000561struct drm_sigdata {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000562 int context;
Dave Airliec60ce622007-07-11 15:27:12 +1000563 struct drm_hw_lock *lock;
Dave Airlie55910512007-07-11 16:53:40 +1000564};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Dave Airlie8562b3f2007-11-05 12:37:41 +1000566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567/**
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +1100568 * Kernel side of a mapping
569 */
570struct drm_local_map {
Benjamin Herrenschmidt41c2e752009-02-02 16:55:47 +1100571 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +1100572 unsigned long size; /**< Requested physical size (bytes) */
573 enum drm_map_type type; /**< Type of memory to map */
574 enum drm_map_flags flags; /**< Flags */
575 void *handle; /**< User-space: "Handle" to pass to mmap() */
576 /**< Kernel-space: kernel-virtual address */
577 int mtrr; /**< MTRR slot used */
578};
579
580typedef struct drm_local_map drm_local_map_t;
581
582/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 * Mappings list
584 */
Dave Airlie55910512007-07-11 16:53:40 +1000585struct drm_map_list {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000586 struct list_head head; /**< list head */
Dave Airliee0be4282007-07-12 10:26:44 +1000587 struct drm_hash_item hash;
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +1100588 struct drm_local_map *map; /**< mapping */
Dave Airlie8562b3f2007-11-05 12:37:41 +1000589 uint64_t user_token;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000590 struct drm_master *master;
Dave Airlie55910512007-07-11 16:53:40 +1000591};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593/**
594 * Context handle list
595 */
Dave Airlie55910512007-07-11 16:53:40 +1000596struct drm_ctx_list {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000597 struct list_head head; /**< list head */
598 drm_context_t handle; /**< context handle */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000599 struct drm_file *tag; /**< associated fd private data */
Dave Airlie55910512007-07-11 16:53:40 +1000600};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Dave Airlieea98a922005-09-11 20:28:11 +1000602/* location of GART table */
603#define DRM_ATI_GART_MAIN 1
604#define DRM_ATI_GART_FB 2
605
Dave Airlief2b04cd2007-05-08 15:19:23 +1000606#define DRM_ATI_GART_PCI 1
607#define DRM_ATI_GART_PCIE 2
608#define DRM_ATI_GART_IGP 3
609
Dave Airlie55910512007-07-11 16:53:40 +1000610struct drm_ati_pcigart_info {
Dave Airlieea98a922005-09-11 20:28:11 +1000611 int gart_table_location;
Dave Airlief2b04cd2007-05-08 15:19:23 +1000612 int gart_reg_if;
Dave Airlief26c4732006-01-02 17:18:39 +1100613 void *addr;
Dave Airlieea98a922005-09-11 20:28:11 +1000614 dma_addr_t bus_addr;
Dave Airlieb05c2382008-03-17 10:24:24 +1000615 dma_addr_t table_mask;
616 struct drm_dma_handle *table_handle;
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +1100617 struct drm_local_map mapping;
Dave Airlief2b04cd2007-05-08 15:19:23 +1000618 int table_size;
Dave Airlie55910512007-07-11 16:53:40 +1000619};
Dave Airlieea98a922005-09-11 20:28:11 +1000620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621/**
Jesse Barnesa2c0a972008-11-05 10:31:53 -0800622 * GEM specific mm private for tracking GEM objects
623 */
624struct drm_gem_mm {
David Herrmann0de23972013-07-24 21:07:52 +0200625 struct drm_vma_offset_manager vma_manager;
Jesse Barnesa2c0a972008-11-05 10:31:53 -0800626};
627
628/**
Eric Anholt673a3942008-07-30 12:06:12 -0700629 * This structure defines the drm_mm memory object, which will be used by the
630 * DRM for its buffer objects.
631 */
632struct drm_gem_object {
633 /** Reference count of this object */
634 struct kref refcount;
635
636 /** Handle count of this object. Each handle also holds a reference */
Dave Airlie29d08b32010-09-27 16:17:17 +1000637 atomic_t handle_count; /* number of handles on this object */
Eric Anholt673a3942008-07-30 12:06:12 -0700638
639 /** Related drm device */
640 struct drm_device *dev;
641
642 /** File representing the shmem storage */
643 struct file *filp;
644
Jesse Barnesa2c0a972008-11-05 10:31:53 -0800645 /* Mapping info for this object */
David Herrmann0de23972013-07-24 21:07:52 +0200646 struct drm_vma_offset_node vma_node;
Jesse Barnesa2c0a972008-11-05 10:31:53 -0800647
Eric Anholt673a3942008-07-30 12:06:12 -0700648 /**
649 * Size of the object, in bytes. Immutable over the object's
650 * lifetime.
651 */
652 size_t size;
653
654 /**
655 * Global name for this object, starts at 1. 0 means unnamed.
656 * Access is covered by the object_name_lock in the related drm_device
657 */
658 int name;
659
660 /**
661 * Memory domains. These monitor which caches contain read/write data
662 * related to the object. When transitioning from one set of domains
663 * to another, the driver is called to ensure that caches are suitably
664 * flushed and invalidated
665 */
666 uint32_t read_domains;
667 uint32_t write_domain;
668
669 /**
670 * While validating an exec operation, the
671 * new read/write domain values are computed here.
672 * They will be transferred to the above values
673 * at the point that any cache flushing occurs
674 */
675 uint32_t pending_read_domains;
676 uint32_t pending_write_domain;
677
678 void *driver_private;
Dave Airlie32488772011-11-25 15:21:02 +0000679
680 /* dma buf exported from this GEM object */
681 struct dma_buf *export_dma_buf;
682
683 /* dma buf attachment backing this object */
684 struct dma_buf_attachment *import_attach;
Eric Anholt673a3942008-07-30 12:06:12 -0700685};
686
David Howellsa1ce3922012-10-02 18:01:25 +0100687#include <drm/drm_crtc.h>
Dave Airlief453ba02008-11-07 14:05:41 -0800688
Dave Airlie7c1c2872008-11-28 14:22:24 +1000689/* per-master structure */
690struct drm_master {
691
692 struct kref refcount; /* refcount for this master */
693
694 struct list_head head; /**< each minor contains a list of masters */
695 struct drm_minor *minor; /**< link back to minor we are a master for */
696
697 char *unique; /**< Unique identifier: e.g., busid */
698 int unique_len; /**< Length of unique field */
Vegard Nossum1147c9c2008-12-02 13:38:47 +1000699 int unique_size; /**< amount allocated */
Dave Airlie7c1c2872008-11-28 14:22:24 +1000700
701 int blocked; /**< Blocked due to VC switch? */
702
703 /** \name Authentication */
704 /*@{ */
705 struct drm_open_hash magiclist;
706 struct list_head magicfree;
707 /*@} */
708
709 struct drm_lock_data lock; /**< Information on hardware lock */
710
711 void *driver_priv; /**< Private structure for driver to use */
712};
713
Mario Kleiner27641c32010-10-23 04:20:23 +0200714/* Size of ringbuffer for vblank timestamps. Just double-buffer
715 * in initial implementation.
716 */
717#define DRM_VBLANKTIME_RBSIZE 2
718
719/* Flags and return codes for get_vblank_timestamp() driver function. */
720#define DRM_CALLED_FROM_VBLIRQ 1
721#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
722#define DRM_VBLANKTIME_INVBL (1 << 1)
723
724/* get_scanout_position() return flags */
725#define DRM_SCANOUTPOS_VALID (1 << 0)
726#define DRM_SCANOUTPOS_INVBL (1 << 1)
727#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
728
Dave Airlie8410ea32010-12-15 03:16:38 +1000729struct drm_bus {
730 int bus_type;
731 int (*get_irq)(struct drm_device *dev);
732 const char *(*get_name)(struct drm_device *dev);
733 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
734 int (*set_unique)(struct drm_device *dev, struct drm_master *master,
735 struct drm_unique *unique);
736 int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
737 /* hooks that are for PCI */
738 int (*agp_init)(struct drm_device *dev);
739
740};
741
Eric Anholt673a3942008-07-30 12:06:12 -0700742/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 * DRM driver structure. This structure represent the common code for
744 * a family of cards. There will one drm_device for each card present
745 * in this family
746 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747struct drm_driver {
Dave Airlie22eae942005-11-10 22:16:34 +1100748 int (*load) (struct drm_device *, unsigned long flags);
749 int (*firstopen) (struct drm_device *);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000750 int (*open) (struct drm_device *, struct drm_file *);
Eric Anholt6c340ea2007-08-25 20:23:09 +1000751 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000752 void (*postclose) (struct drm_device *, struct drm_file *);
Dave Airlie22eae942005-11-10 22:16:34 +1100753 void (*lastclose) (struct drm_device *);
754 int (*unload) (struct drm_device *);
Dave Airlieb932ccb2008-02-20 10:02:20 +1000755 int (*suspend) (struct drm_device *, pm_message_t state);
Jesse Barnese8b962b2007-11-22 14:02:38 +1000756 int (*resume) (struct drm_device *);
Eric Anholtc153f452007-09-03 12:06:45 +1000757 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000758 int (*dma_quiescent) (struct drm_device *);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000759 int (*context_dtor) (struct drm_device *dev, int context);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000760
Dave Airliecda17382005-07-10 17:31:26 +1000761 /**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700762 * get_vblank_counter - get raw hardware vblank counter
763 * @dev: DRM device
764 * @crtc: counter to fetch
765 *
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200766 * Driver callback for fetching a raw hardware vblank counter for @crtc.
767 * If a device doesn't have a hardware counter, the driver can simply
768 * return the value of drm_vblank_count. The DRM core will account for
769 * missed vblank events while interrupts where disabled based on system
770 * timestamps.
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700771 *
772 * Wraparound handling and loss of events due to modesetting is dealt
773 * with in the DRM core code.
774 *
775 * RETURNS
776 * Raw vblank counter value.
777 */
778 u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
779
780 /**
781 * enable_vblank - enable vblank interrupt events
782 * @dev: DRM device
783 * @crtc: which irq to enable
784 *
785 * Enable vblank interrupts for @crtc. If the device doesn't have
786 * a hardware vblank counter, this routine should be a no-op, since
787 * interrupts will have to stay on to keep the count accurate.
788 *
789 * RETURNS
790 * Zero on success, appropriate errno if the given @crtc's vblank
791 * interrupt cannot be enabled.
792 */
793 int (*enable_vblank) (struct drm_device *dev, int crtc);
794
795 /**
796 * disable_vblank - disable vblank interrupt events
797 * @dev: DRM device
798 * @crtc: which irq to enable
799 *
800 * Disable vblank interrupts for @crtc. If the device doesn't have
801 * a hardware vblank counter, this routine should be a no-op, since
802 * interrupts will have to stay on to keep the count accurate.
803 */
804 void (*disable_vblank) (struct drm_device *dev, int crtc);
805
806 /**
Dave Airliecda17382005-07-10 17:31:26 +1000807 * Called by \c drm_device_is_agp. Typically used to determine if a
808 * card is really attached to AGP or not.
809 *
810 * \param dev DRM device handle
811 *
812 * \returns
813 * One of three values is returned depending on whether or not the
814 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
815 * (return of 1), or may or may not be AGP (return of 2).
816 */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000817 int (*device_is_agp) (struct drm_device *dev);
Dave Airliecda17382005-07-10 17:31:26 +1000818
Mario Kleiner27641c32010-10-23 04:20:23 +0200819 /**
820 * Called by vblank timestamping code.
821 *
822 * Return the current display scanout position from a crtc.
823 *
824 * \param dev DRM device.
825 * \param crtc Id of the crtc to query.
826 * \param *vpos Target location for current vertical scanout position.
827 * \param *hpos Target location for current horizontal scanout position.
828 *
829 * Returns vpos as a positive number while in active scanout area.
830 * Returns vpos as a negative number inside vblank, counting the number
831 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
832 * until start of active scanout / end of vblank."
833 *
834 * \return Flags, or'ed together as follows:
835 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300836 * DRM_SCANOUTPOS_VALID = Query successful.
Mario Kleiner27641c32010-10-23 04:20:23 +0200837 * DRM_SCANOUTPOS_INVBL = Inside vblank.
838 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
839 * this flag means that returned position may be offset by a constant
840 * but unknown small number of scanlines wrt. real scanout position.
841 *
842 */
843 int (*get_scanout_position) (struct drm_device *dev, int crtc,
844 int *vpos, int *hpos);
845
846 /**
847 * Called by \c drm_get_last_vbltimestamp. Should return a precise
848 * timestamp when the most recent VBLANK interval ended or will end.
849 *
850 * Specifically, the timestamp in @vblank_time should correspond as
851 * closely as possible to the time when the first video scanline of
852 * the video frame after the end of VBLANK will start scanning out,
Justin P. Mattock42b2aa82011-11-28 20:31:00 -0800853 * the time immediately after end of the VBLANK interval. If the
Mario Kleiner27641c32010-10-23 04:20:23 +0200854 * @crtc is currently inside VBLANK, this will be a time in the future.
855 * If the @crtc is currently scanning out a frame, this will be the
856 * past start time of the current scanout. This is meant to adhere
857 * to the OpenML OML_sync_control extension specification.
858 *
859 * \param dev dev DRM device handle.
860 * \param crtc crtc for which timestamp should be returned.
861 * \param *max_error Maximum allowable timestamp error in nanoseconds.
862 * Implementation should strive to provide timestamp
863 * with an error of at most *max_error nanoseconds.
864 * Returns true upper bound on error for timestamp.
865 * \param *vblank_time Target location for returned vblank timestamp.
866 * \param flags 0 = Defaults, no special treatment needed.
867 * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
868 * irq handler. Some drivers need to apply some workarounds
869 * for gpu-specific vblank irq quirks if flag is set.
870 *
871 * \returns
872 * Zero if timestamping isn't supported in current display mode or a
873 * negative number on failure. A positive status code on success,
874 * which describes how the vblank_time timestamp was computed.
875 */
876 int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
877 int *max_error,
878 struct timeval *vblank_time,
879 unsigned flags);
880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 /* these have to be filled in */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000882
Dave Airlie22eae942005-11-10 22:16:34 +1100883 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000884 void (*irq_preinstall) (struct drm_device *dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700885 int (*irq_postinstall) (struct drm_device *dev);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000886 void (*irq_uninstall) (struct drm_device *dev);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000887 void (*set_version) (struct drm_device *dev,
Dave Airliec60ce622007-07-11 15:27:12 +1000888 struct drm_set_version *sv);
Dave Airlie22eae942005-11-10 22:16:34 +1100889
Dave Airlie7c1c2872008-11-28 14:22:24 +1000890 /* Master routines */
891 int (*master_create)(struct drm_device *dev, struct drm_master *master);
892 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
Thomas Hellstrom862302f2009-12-02 18:15:25 +0000893 /**
894 * master_set is called whenever the minor master is set.
895 * master_drop is called whenever the minor master is dropped.
896 */
897
898 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
899 bool from_open);
900 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
901 bool from_release);
Dave Airlie7c1c2872008-11-28 14:22:24 +1000902
Ben Gamari955b12d2009-02-17 20:08:49 -0500903 int (*debugfs_init)(struct drm_minor *minor);
904 void (*debugfs_cleanup)(struct drm_minor *minor);
Eric Anholt673a3942008-07-30 12:06:12 -0700905
906 /**
907 * Driver-specific constructor for drm_gem_objects, to set up
908 * obj->driver_private.
909 *
910 * Returns 0 on success.
911 */
912 int (*gem_init_object) (struct drm_gem_object *obj);
913 void (*gem_free_object) (struct drm_gem_object *obj);
Ben Skeggs304eda32011-06-09 00:24:59 +0000914 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
915 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
Eric Anholt673a3942008-07-30 12:06:12 -0700916
Dave Airlie32488772011-11-25 15:21:02 +0000917 /* prime: */
918 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
919 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
920 uint32_t handle, uint32_t flags, int *prime_fd);
921 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
922 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
923 int prime_fd, uint32_t *handle);
924 /* export GEM -> dmabuf */
925 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
926 struct drm_gem_object *obj, int flags);
927 /* import dmabuf -> GEM */
928 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
929 struct dma_buf *dma_buf);
Aaron Plattner89177642013-01-15 20:47:42 +0000930 /* low-level interface used by drm_gem_prime_{import,export} */
931 int (*gem_prime_pin)(struct drm_gem_object *obj);
Maarten Lankhorst102d6db2013-04-09 09:18:44 +0200932 void (*gem_prime_unpin)(struct drm_gem_object *obj);
Aaron Plattner89177642013-01-15 20:47:42 +0000933 struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
934 struct drm_gem_object *(*gem_prime_import_sg_table)(
935 struct drm_device *dev, size_t size,
936 struct sg_table *sgt);
937 void *(*gem_prime_vmap)(struct drm_gem_object *obj);
938 void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
Joonyoung Shim7c397cd2013-06-28 14:24:53 +0900939 int (*gem_prime_mmap)(struct drm_gem_object *obj,
940 struct vm_area_struct *vma);
Dave Airlie32488772011-11-25 15:21:02 +0000941
Dave Airlie28d52042009-09-21 14:33:58 +1000942 /* vga arb irq handler */
943 void (*vgaarb_irq)(struct drm_device *dev, bool state);
944
Dave Airlieff72145b2011-02-07 12:16:14 +1000945 /* dumb alloc support */
946 int (*dumb_create)(struct drm_file *file_priv,
947 struct drm_device *dev,
948 struct drm_mode_create_dumb *args);
949 int (*dumb_map_offset)(struct drm_file *file_priv,
950 struct drm_device *dev, uint32_t handle,
951 uint64_t *offset);
952 int (*dumb_destroy)(struct drm_file *file_priv,
953 struct drm_device *dev,
954 uint32_t handle);
955
Jesse Barnesa2c0a972008-11-05 10:31:53 -0800956 /* Driver private ops for this object */
Laurent Pinchart78b68552012-05-17 13:27:22 +0200957 const struct vm_operations_struct *gem_vm_ops;
Jesse Barnesa2c0a972008-11-05 10:31:53 -0800958
Dave Airlie22eae942005-11-10 22:16:34 +1100959 int major;
960 int minor;
961 int patchlevel;
962 char *name;
963 char *desc;
964 char *date;
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 u32 driver_features;
967 int dev_priv_size;
Eric Anholtc153f452007-09-03 12:06:45 +1000968 struct drm_ioctl_desc *ioctls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 int num_ioctls;
Arjan van de Vene08e96d2011-10-31 07:28:57 -0700970 const struct file_operations *fops;
Dave Airlie8410ea32010-12-15 03:16:38 +1000971 union {
972 struct pci_driver *pci;
973 struct platform_device *platform_device;
Dave Airliea250b9f2010-12-15 07:13:55 +1000974 struct usb_driver *usb;
Dave Airlie8410ea32010-12-15 03:16:38 +1000975 } kdriver;
976 struct drm_bus *bus;
977
Dave Airliee7f7ab42008-11-28 13:43:47 +1000978 /* List of devices hanging off this driver */
979 struct list_head device_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980};
981
Dave Airlie2c14f282008-04-21 16:47:32 +1000982#define DRM_MINOR_UNASSIGNED 0
983#define DRM_MINOR_LEGACY 1
Dave Airlief453ba02008-11-07 14:05:41 -0800984#define DRM_MINOR_CONTROL 2
985#define DRM_MINOR_RENDER 3
Dave Airlie2c14f282008-04-21 16:47:32 +1000986
Ben Gamari955b12d2009-02-17 20:08:49 -0500987
988/**
989 * debugfs node list. This structure represents a debugfs file to
990 * be created by the drm core
991 */
992struct drm_debugfs_list {
993 const char *name; /** file name */
994 int (*show)(struct seq_file*, void*); /** show callback */
995 u32 driver_features; /**< Required driver features for this entry */
996};
997
998/**
999 * debugfs node structure. This structure represents a debugfs file.
1000 */
1001struct drm_debugfs_node {
1002 struct list_head list;
1003 struct drm_minor *minor;
1004 struct drm_debugfs_list *debugfs_ent;
1005 struct dentry *dent;
1006};
1007
1008/**
1009 * Info file list entry. This structure represents a debugfs or proc file to
1010 * be created by the drm core
1011 */
1012struct drm_info_list {
1013 const char *name; /** file name */
1014 int (*show)(struct seq_file*, void*); /** show callback */
1015 u32 driver_features; /**< Required driver features for this entry */
1016 void *data;
1017};
1018
1019/**
1020 * debugfs node structure. This structure represents a debugfs file.
1021 */
1022struct drm_info_node {
1023 struct list_head list;
1024 struct drm_minor *minor;
David Howellsce089b52013-04-12 15:23:25 +01001025 const struct drm_info_list *info_ent;
Ben Gamari955b12d2009-02-17 20:08:49 -05001026 struct dentry *dent;
1027};
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029/**
Dave Airlie2c14f282008-04-21 16:47:32 +10001030 * DRM minor structure. This structure represents a drm minor number.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 */
Dave Airlie2c14f282008-04-21 16:47:32 +10001032struct drm_minor {
1033 int index; /**< Minor device number */
1034 int type; /**< Control or render */
1035 dev_t device; /**< Device number for mknod */
1036 struct device kdev; /**< Linux device */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 struct drm_device *dev;
Ben Gamari955b12d2009-02-17 20:08:49 -05001038
1039 struct proc_dir_entry *proc_root; /**< proc directory entry */
1040 struct drm_info_node proc_nodes;
1041 struct dentry *debugfs_root;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01001042
1043 struct list_head debugfs_list;
1044 struct mutex debugfs_lock; /* Protects debugfs_list. */
Ben Gamari955b12d2009-02-17 20:08:49 -05001045
Dave Airlie7c1c2872008-11-28 14:22:24 +10001046 struct drm_master *master; /* currently active master for this node */
1047 struct list_head master_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001048 struct drm_mode_group mode_group;
Dave Airlie84b1fd12007-07-11 15:53:27 +10001049};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Chris Wilson1794d252011-04-17 07:43:32 +01001051/* mode specified on the command line */
1052struct drm_cmdline_mode {
1053 bool specified;
1054 bool refresh_specified;
1055 bool bpp_specified;
1056 int xres, yres;
1057 int bpp;
1058 int refresh;
1059 bool rb;
1060 bool interlace;
1061 bool cvt;
1062 bool margins;
1063 enum drm_connector_force force;
1064};
1065
1066
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +10001067struct drm_pending_vblank_event {
1068 struct drm_pending_event base;
1069 int pipe;
1070 struct drm_event_vblank event;
1071};
1072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073/**
1074 * DRM device structure. This structure represent a complete card that
1075 * may contain multiple heads.
1076 */
Dave Airlie84b1fd12007-07-11 15:53:27 +10001077struct drm_device {
Dave Airliee7f7ab42008-11-28 13:43:47 +10001078 struct list_head driver_item; /**< list of devices per driver */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001079 char *devname; /**< For /proc/interrupts */
1080 int if_version; /**< Highest interface version set */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 /** \name Locks */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001083 /*@{ */
1084 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
Dave Airlie30e2fb12006-02-02 19:37:46 +11001085 struct mutex struct_mutex; /**< For others */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001086 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088 /** \name Usage Counters */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001089 /*@{ */
1090 int open_count; /**< Outstanding files open */
1091 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
1092 atomic_t vma_count; /**< Outstanding vma areas open */
1093 int buf_use; /**< Buffers in use -- cannot alloc */
1094 atomic_t buf_alloc; /**< Buffer allocation in progress */
1095 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /** \name Performance counters */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001098 /*@{ */
1099 unsigned long counters;
Dave Airliec60ce622007-07-11 15:27:12 +10001100 enum drm_stat_type types[15];
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001101 atomic_t counts[15];
1102 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Dave Airliebd1b3312007-05-26 05:01:51 +10001104 struct list_head filelist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 /** \name Memory management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001107 /*@{ */
Dave Airliebd1b3312007-05-26 05:01:51 +10001108 struct list_head maplist; /**< Linked list of regions */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001109 int map_count; /**< Number of mappable regions */
Dave Airliee0be4282007-07-12 10:26:44 +10001110 struct drm_open_hash map_hash; /**< User token hash table for maps */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 /** \name Context handle management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001113 /*@{ */
Dave Airliebd1b3312007-05-26 05:01:51 +10001114 struct list_head ctxlist; /**< Linked list of context handles */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001115 int ctx_count; /**< Number of context handles */
Dave Airlie30e2fb12006-02-02 19:37:46 +11001116 struct mutex ctxlist_mutex; /**< For ctxlist */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Dave Airlie62968142007-07-17 10:46:52 +10001118 struct idr ctx_idr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Dave Airliebd1b3312007-05-26 05:01:51 +10001120 struct list_head vmalist; /**< List of vmas (for debugging) */
Dave Airlief453ba02008-11-07 14:05:41 -08001121
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001122 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Daniel Vettera344a7e2011-10-26 00:54:41 +02001124 /** \name DMA support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001125 /*@{ */
Dave Airliecdd55a22007-07-11 16:32:08 +10001126 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001127 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 /** \name Context support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001130 /*@{ */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001131 int irq_enabled; /**< True if irq handler is enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 __volatile__ long context_flag; /**< Context swapping flag */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001133 int last_context; /**< Last current context */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001134 /*@} */
1135
1136 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 /** \name VBLANK IRQ support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001138 /*@{ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001140 /*
1141 * At load time, disabling the vblank interrupt won't be allowed since
1142 * old clients may not call the modeset ioctl and therefore misbehave.
1143 * Once the modeset ioctl *has* been called though, we can safely
1144 * disable them when unused.
1145 */
1146 int vblank_disable_allowed;
1147
1148 wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */
1149 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
Mario Kleiner27641c32010-10-23 04:20:23 +02001150 struct timeval *_vblank_time; /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
1151 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001152 spinlock_t vbl_lock;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001153 atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */
1154 u32 *last_vblank; /* protected by dev->vbl_lock, used */
1155 /* for wraparound handling */
1156 int *vblank_enabled; /* so we don't call enable more than
1157 once per disable */
1158 int *vblank_inmodeset; /* Display driver is setting mode */
Eric Anholtfede5c92008-12-19 17:23:38 -08001159 u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001160 struct timer_list vblank_disable_timer;
1161
1162 u32 max_vblank_count; /**< size of vblank counter register */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +10001164 /**
1165 * List of events
1166 */
1167 struct list_head vblank_event_list;
1168 spinlock_t event_lock;
1169
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001170 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Dave Airlie55910512007-07-11 16:53:40 +10001174 struct drm_agp_head *agp; /**< AGP data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Jordan Crousedcdb1672010-05-27 13:40:25 -06001176 struct device *dev; /**< Device structure */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001177 struct pci_dev *pdev; /**< PCI device structure */
Eric Anholt2f02cc32006-09-22 04:19:34 +10001178 int pci_vendor; /**< PCI vendor id */
1179 int pci_device; /**< PCI device id */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#ifdef __alpha__
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 struct pci_controller *hose;
1182#endif
Jordan Crousedcdb1672010-05-27 13:40:25 -06001183
1184 struct platform_device *platformdev; /**< Platform device struture */
Dave Airliea250b9f2010-12-15 07:13:55 +10001185 struct usb_device *usbdev;
Jordan Crousedcdb1672010-05-27 13:40:25 -06001186
Dave Airlie55910512007-07-11 16:53:40 +10001187 struct drm_sg_mem *sg; /**< Scatter gather memory */
Dave Airlie19227562011-02-24 08:35:06 +10001188 unsigned int num_crtcs; /**< Number of CRTCs on this device */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001189 void *dev_private; /**< device private data */
Jesse Barnesa2c0a972008-11-05 10:31:53 -08001190 void *mm_private;
1191 struct address_space *dev_mapping;
Dave Airlie55910512007-07-11 16:53:40 +10001192 struct drm_sigdata sigdata; /**< For block_all_signals */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001193 sigset_t sigmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001195 struct drm_driver *driver;
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +11001196 struct drm_local_map *agp_buffer_map;
Dave Airlied1f2b552005-08-05 22:11:22 +10001197 unsigned int agp_buffer_token;
Dave Airlief453ba02008-11-07 14:05:41 -08001198 struct drm_minor *control; /**< Control node for card */
Dave Airlie2c14f282008-04-21 16:47:32 +10001199 struct drm_minor *primary; /**< render type primary screen head */
=?utf-8?q?Michel_D=C3=A4nzer?=bea56792006-10-24 23:04:19 +10001200
Dave Airlief453ba02008-11-07 14:05:41 -08001201 struct drm_mode_config mode_config; /**< Current mode config */
1202
Eric Anholt673a3942008-07-30 12:06:12 -07001203 /** \name GEM information */
1204 /*@{ */
1205 spinlock_t object_name_lock;
1206 struct idr object_name_idr;
Eric Anholt673a3942008-07-30 12:06:12 -07001207 /*@} */
Dave Airlie5bcf7192010-12-07 09:20:40 +10001208 int switch_power_state;
Dave Airlie2c07a212012-02-20 14:18:07 +00001209
1210 atomic_t unplugged; /* device has been unplugged or gone away */
Dave Airlie84b1fd12007-07-11 15:53:27 +10001211};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Dave Airlie5bcf7192010-12-07 09:20:40 +10001213#define DRM_SWITCH_POWER_ON 0
1214#define DRM_SWITCH_POWER_OFF 1
1215#define DRM_SWITCH_POWER_CHANGING 2
1216
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001217static __inline__ int drm_core_check_feature(struct drm_device *dev,
1218 int feature)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
1220 return ((dev->driver->driver_features & feature) ? 1 : 0);
1221}
1222
Jordan Crousedcdb1672010-05-27 13:40:25 -06001223static inline int drm_dev_to_irq(struct drm_device *dev)
1224{
Dave Airlie8410ea32010-12-15 03:16:38 +10001225 return dev->driver->bus->get_irq(dev);
Jordan Crousedcdb1672010-05-27 13:40:25 -06001226}
1227
Dave Airlie332296012006-08-07 20:23:42 +10001228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229#if __OS_HAS_AGP
1230static inline int drm_core_has_AGP(struct drm_device *dev)
1231{
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001232 return drm_core_check_feature(dev, DRIVER_USE_AGP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234#else
1235#define drm_core_has_AGP(dev) (0)
1236#endif
1237
1238#if __OS_HAS_MTRR
1239static inline int drm_core_has_MTRR(struct drm_device *dev)
1240{
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001241 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243#else
1244#define drm_core_has_MTRR(dev) (0)
1245#endif
1246
Dave Airlie2c07a212012-02-20 14:18:07 +00001247static inline void drm_device_set_unplugged(struct drm_device *dev)
1248{
1249 smp_wmb();
1250 atomic_set(&dev->unplugged, 1);
1251}
1252
1253static inline int drm_device_is_unplugged(struct drm_device *dev)
1254{
1255 int ret = atomic_read(&dev->unplugged);
1256 smp_rmb();
1257 return ret;
1258}
1259
Daniel Vetter8faf6b12012-12-01 23:43:11 +01001260static inline bool drm_modeset_is_locked(struct drm_device *dev)
1261{
1262 return mutex_is_locked(&dev->mode_config.mutex);
1263}
1264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265/******************************************************************/
1266/** \name Internal function definitions */
1267/*@{*/
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 /* Driver support (drm_drv.h) */
Arnd Bergmanned8b6702009-12-16 22:17:09 +00001270extern long drm_ioctl(struct file *filp,
1271 unsigned int cmd, unsigned long arg);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001272extern long drm_compat_ioctl(struct file *filp,
1273 unsigned int cmd, unsigned long arg);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001274extern int drm_lastclose(struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 /* Device support (drm_fops.h) */
Arnd Bergmann58374712010-07-10 23:51:39 +02001277extern struct mutex drm_global_mutex;
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001278extern int drm_open(struct inode *inode, struct file *filp);
1279extern int drm_stub_open(struct inode *inode, struct file *filp);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001280extern int drm_fasync(int fd, struct file *filp, int on);
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +10001281extern ssize_t drm_read(struct file *filp, char __user *buffer,
1282 size_t count, loff_t *offset);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001283extern int drm_release(struct inode *inode, struct file *filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 /* Mapping support (drm_vm.h) */
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001286extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
Jesse Barnesa2c0a972008-11-05 10:31:53 -08001287extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
Rob Clarkb06d66b2012-05-01 11:04:51 -05001288extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1289extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001290extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292 /* Memory management support (drm_memory.h) */
David Howellsa1ce3922012-10-02 18:01:25 +01001293#include <drm/drm_memory.h>
Daniel Vetter690bb512010-08-23 22:53:35 +02001294extern void drm_free_agp(DRM_AGP_MEM * handle, int pages);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001295extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
Eric Anholt673a3942008-07-30 12:06:12 -07001296extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1297 struct page **pages,
1298 unsigned long num_pages,
Keith Packardba1eb1d2008-10-14 19:55:10 -07001299 uint32_t gtt_offset,
1300 uint32_t type);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001301extern int drm_unbind_agp(DRM_AGP_MEM * handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 /* Misc. IOCTL support (drm_ioctl.h) */
Eric Anholtc153f452007-09-03 12:06:45 +10001304extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1305 struct drm_file *file_priv);
1306extern int drm_getunique(struct drm_device *dev, void *data,
1307 struct drm_file *file_priv);
1308extern int drm_setunique(struct drm_device *dev, void *data,
1309 struct drm_file *file_priv);
1310extern int drm_getmap(struct drm_device *dev, void *data,
1311 struct drm_file *file_priv);
1312extern int drm_getclient(struct drm_device *dev, void *data,
1313 struct drm_file *file_priv);
1314extern int drm_getstats(struct drm_device *dev, void *data,
1315 struct drm_file *file_priv);
Ben Skeggs9f354212011-02-21 11:17:35 +10001316extern int drm_getcap(struct drm_device *dev, void *data,
1317 struct drm_file *file_priv);
Eric Anholtc153f452007-09-03 12:06:45 +10001318extern int drm_setversion(struct drm_device *dev, void *data,
1319 struct drm_file *file_priv);
1320extern int drm_noop(struct drm_device *dev, void *data,
1321 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 /* Context IOCTL support (drm_context.h) */
Eric Anholtc153f452007-09-03 12:06:45 +10001324extern int drm_resctx(struct drm_device *dev, void *data,
1325 struct drm_file *file_priv);
1326extern int drm_addctx(struct drm_device *dev, void *data,
1327 struct drm_file *file_priv);
Eric Anholtc153f452007-09-03 12:06:45 +10001328extern int drm_getctx(struct drm_device *dev, void *data,
1329 struct drm_file *file_priv);
1330extern int drm_switchctx(struct drm_device *dev, void *data,
1331 struct drm_file *file_priv);
1332extern int drm_newctx(struct drm_device *dev, void *data,
1333 struct drm_file *file_priv);
1334extern int drm_rmctx(struct drm_device *dev, void *data,
1335 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Dave Airlie84b1fd12007-07-11 15:53:27 +10001337extern int drm_ctxbitmap_init(struct drm_device *dev);
1338extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1339extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Eric Anholtc153f452007-09-03 12:06:45 +10001341extern int drm_setsareactx(struct drm_device *dev, void *data,
1342 struct drm_file *file_priv);
1343extern int drm_getsareactx(struct drm_device *dev, void *data,
1344 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 /* Authentication IOCTL support (drm_auth.h) */
Eric Anholtc153f452007-09-03 12:06:45 +10001347extern int drm_getmagic(struct drm_device *dev, void *data,
1348 struct drm_file *file_priv);
1349extern int drm_authmagic(struct drm_device *dev, void *data,
1350 struct drm_file *file_priv);
Thomas Hellstrom598781d2012-01-24 18:54:21 +01001351extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Eric Anholt673a3942008-07-30 12:06:12 -07001353/* Cache management (drm_cache.c) */
1354void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
Chris Wilson9da3da62012-06-01 15:20:22 +01001355void drm_clflush_sg(struct sg_table *st);
Daniel Vetter6d5cd9c2012-03-25 19:47:30 +02001356void drm_clflush_virt_range(char *addr, unsigned long length);
Eric Anholt673a3942008-07-30 12:06:12 -07001357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 /* Locking IOCTL support (drm_lock.h) */
Eric Anholtc153f452007-09-03 12:06:45 +10001359extern int drm_lock(struct drm_device *dev, void *data,
1360 struct drm_file *file_priv);
1361extern int drm_unlock(struct drm_device *dev, void *data,
1362 struct drm_file *file_priv);
Dave Airlie55910512007-07-11 16:53:40 +10001363extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1364extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1365extern void drm_idlelock_release(struct drm_lock_data *lock_data);
Thomas Hellstrom040ac322007-03-23 13:28:33 +11001366
1367/*
1368 * These are exported to drivers so that they can implement fencing using
1369 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1370 */
1371
Eric Anholtc153f452007-09-03 12:06:45 +10001372extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 /* Buffer management support (drm_bufs.h) */
Dave Airlie84b1fd12007-07-11 15:53:27 +10001375extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1376extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
Benjamin Herrenschmidt41c2e752009-02-02 16:55:47 +11001377extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
Dave Airliec60ce622007-07-11 15:27:12 +10001378 unsigned int size, enum drm_map_type type,
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +11001379 enum drm_map_flags flags, struct drm_local_map **map_ptr);
Eric Anholtc153f452007-09-03 12:06:45 +10001380extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1381 struct drm_file *file_priv);
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +11001382extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
1383extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
Eric Anholtc153f452007-09-03 12:06:45 +10001384extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1385 struct drm_file *file_priv);
1386extern int drm_addbufs(struct drm_device *dev, void *data,
1387 struct drm_file *file_priv);
1388extern int drm_infobufs(struct drm_device *dev, void *data,
1389 struct drm_file *file_priv);
1390extern int drm_markbufs(struct drm_device *dev, void *data,
1391 struct drm_file *file_priv);
1392extern int drm_freebufs(struct drm_device *dev, void *data,
1393 struct drm_file *file_priv);
1394extern int drm_mapbufs(struct drm_device *dev, void *data,
1395 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 /* DMA support (drm_dma.h) */
Dave Airlie84b1fd12007-07-11 15:53:27 +10001398extern int drm_dma_setup(struct drm_device *dev);
1399extern void drm_dma_takedown(struct drm_device *dev);
Dave Airlie056219e2007-07-11 16:17:42 +10001400extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
Eric Anholt6c340ea2007-08-25 20:23:09 +10001401extern void drm_core_reclaim_buffers(struct drm_device *dev,
1402 struct drm_file *filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 /* IRQ support (drm_irq.h) */
Eric Anholtc153f452007-09-03 12:06:45 +10001405extern int drm_control(struct drm_device *dev, void *data,
1406 struct drm_file *file_priv);
Kristian Høgsbergdbb19d32008-08-20 11:04:27 -04001407extern int drm_irq_install(struct drm_device *dev);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001408extern int drm_irq_uninstall(struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001410extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
Dave Airlieaf6061a2008-05-07 12:15:39 +10001411extern int drm_wait_vblank(struct drm_device *dev, void *data,
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001412 struct drm_file *filp);
Dave Airlieaf6061a2008-05-07 12:15:39 +10001413extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001414extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
Mario Kleiner27641c32010-10-23 04:20:23 +02001415extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1416 struct timeval *vblanktime);
Rob Clarkc6eefa12012-10-16 22:48:40 +00001417extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1418 struct drm_pending_vblank_event *e);
Chris Wilson78c6e172011-01-31 10:48:04 +00001419extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001420extern int drm_vblank_get(struct drm_device *dev, int crtc);
1421extern void drm_vblank_put(struct drm_device *dev, int crtc);
Li Peng778c9022009-11-09 12:51:22 +08001422extern void drm_vblank_off(struct drm_device *dev, int crtc);
Keith Packard52440212008-11-18 09:30:25 -08001423extern void drm_vblank_cleanup(struct drm_device *dev);
Mario Kleiner27641c32010-10-23 04:20:23 +02001424extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1425 struct timeval *tvblank, unsigned flags);
1426extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1427 int crtc, int *max_error,
1428 struct timeval *vblank_time,
1429 unsigned flags,
1430 struct drm_crtc *refcrtc);
1431extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1432
Chris Wilson1794d252011-04-17 07:43:32 +01001433extern bool
1434drm_mode_parse_command_line_for_connector(const char *mode_option,
1435 struct drm_connector *connector,
1436 struct drm_cmdline_mode *mode);
1437
1438extern struct drm_display_mode *
1439drm_mode_create_from_cmdline_mode(struct drm_device *dev,
1440 struct drm_cmdline_mode *cmd);
1441
Steffen Trumtrarebc64e42012-11-14 11:22:52 +01001442extern int drm_display_mode_from_videomode(const struct videomode *vm,
1443 struct drm_display_mode *dmode);
Steffen Trumtraredb37a92012-10-28 18:28:06 +01001444extern int of_get_drm_display_mode(struct device_node *np,
1445 struct drm_display_mode *dmode,
1446 int index);
Steffen Trumtrarebc64e42012-11-14 11:22:52 +01001447
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001448/* Modesetting support */
Dave Airlief453ba02008-11-07 14:05:41 -08001449extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1450extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001451extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1452 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 /* AGP/GART support (drm_agpsupport.h) */
Dave Airlie55910512007-07-11 16:53:40 +10001455extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001456extern int drm_agp_acquire(struct drm_device *dev);
Eric Anholtc153f452007-09-03 12:06:45 +10001457extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1458 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001459extern int drm_agp_release(struct drm_device *dev);
Eric Anholtc153f452007-09-03 12:06:45 +10001460extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1461 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001462extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
Eric Anholtc153f452007-09-03 12:06:45 +10001463extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1464 struct drm_file *file_priv);
1465extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1466extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1467 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001468extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
Eric Anholtc153f452007-09-03 12:06:45 +10001469extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1470 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001471extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
Eric Anholtc153f452007-09-03 12:06:45 +10001472extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1473 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001474extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
Eric Anholtc153f452007-09-03 12:06:45 +10001475extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1476 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001477extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
Eric Anholtc153f452007-09-03 12:06:45 +10001478extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1479 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 /* Stub support (drm_stub.h) */
Dave Airlie7c1c2872008-11-28 14:22:24 +10001482extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1483 struct drm_file *file_priv);
1484extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1485 struct drm_file *file_priv);
1486struct drm_master *drm_master_create(struct drm_minor *minor);
1487extern struct drm_master *drm_master_get(struct drm_master *master);
1488extern void drm_master_put(struct drm_master **master);
Dave Airlie8410ea32010-12-15 03:16:38 +10001489
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001490extern void drm_put_dev(struct drm_device *dev);
Dave Airlie2c14f282008-04-21 16:47:32 +10001491extern int drm_put_minor(struct drm_minor **minor);
Dave Airlie2c07a212012-02-20 14:18:07 +00001492extern void drm_unplug_dev(struct drm_device *dev);
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001493extern unsigned int drm_debug;
Dave Airlie2c14f282008-04-21 16:47:32 +10001494
Mario Kleiner27641c32010-10-23 04:20:23 +02001495extern unsigned int drm_vblank_offdelay;
1496extern unsigned int drm_timestamp_precision;
Imre Deakc61eef72012-10-23 18:53:26 +00001497extern unsigned int drm_timestamp_monotonic;
Mario Kleiner27641c32010-10-23 04:20:23 +02001498
Greg Kroah-Hartman0650fd52006-01-20 14:08:59 -08001499extern struct class *drm_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500extern struct proc_dir_entry *drm_proc_root;
Ben Gamari955b12d2009-02-17 20:08:49 -05001501extern struct dentry *drm_debugfs_root;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Dave Airlie2c14f282008-04-21 16:47:32 +10001503extern struct idr drm_minors_idr;
1504
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +11001505extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
Dave Airlieda509d72007-05-26 05:04:51 +10001506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 /* Proc support (drm_proc.h) */
David Howellsb63e6aa2013-04-12 15:34:31 +01001508extern int drm_proc_init(struct drm_minor *minor, struct proc_dir_entry *root);
Dave Airlie2c14f282008-04-21 16:47:32 +10001509extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Ben Gamari955b12d2009-02-17 20:08:49 -05001511 /* Debugfs support */
1512#if defined(CONFIG_DEBUG_FS)
1513extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1514 struct dentry *root);
1515extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
1516 struct dentry *root, struct drm_minor *minor);
1517extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
1518 struct drm_minor *minor);
1519extern int drm_debugfs_cleanup(struct drm_minor *minor);
1520#endif
1521
1522 /* Info file support */
1523extern int drm_name_info(struct seq_file *m, void *data);
1524extern int drm_vm_info(struct seq_file *m, void *data);
Ben Gamari955b12d2009-02-17 20:08:49 -05001525extern int drm_bufs_info(struct seq_file *m, void *data);
1526extern int drm_vblank_info(struct seq_file *m, void *data);
1527extern int drm_clients_info(struct seq_file *m, void* data);
1528extern int drm_gem_name_info(struct seq_file *m, void *data);
Ben Gamari955b12d2009-02-17 20:08:49 -05001529
Dave Airlie32488772011-11-25 15:21:02 +00001530
Aaron Plattner89177642013-01-15 20:47:42 +00001531extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
1532 struct drm_gem_object *obj, int flags);
Dave Airlie32488772011-11-25 15:21:02 +00001533extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1534 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1535 int *prime_fd);
Aaron Plattner89177642013-01-15 20:47:42 +00001536extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1537 struct dma_buf *dma_buf);
Dave Airlie32488772011-11-25 15:21:02 +00001538extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1539 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1540
1541extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1542 struct drm_file *file_priv);
1543extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1544 struct drm_file *file_priv);
1545
Dave Airlie51ab7ba2012-05-18 15:40:33 +01001546extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1547 dma_addr_t *addrs, int max_pages);
Dave Airlie32488772011-11-25 15:21:02 +00001548extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1549extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1550
Daniel Vetter43387b32013-07-16 09:12:04 +02001551int drm_gem_dumb_destroy(struct drm_file *file,
1552 struct drm_device *dev,
1553 uint32_t handle);
Dave Airlie32488772011-11-25 15:21:02 +00001554
1555void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1556void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
Dave Airlie219b4732013-04-22 09:54:36 +10001557int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1558void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
Dave Airlie32488772011-11-25 15:21:02 +00001559
1560int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1561int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1562 struct drm_gem_object **obj);
1563
Ben Gamari955b12d2009-02-17 20:08:49 -05001564#if DRM_DEBUG_CODE
1565extern int drm_vma_info(struct seq_file *m, void *data);
1566#endif
1567
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 /* Scatter Gather Support (drm_scatter.h) */
Dave Airlie55910512007-07-11 16:53:40 +10001569extern void drm_sg_cleanup(struct drm_sg_mem * entry);
Daniel Vetter1d8d29c2013-07-10 14:11:50 +02001570extern int drm_sg_alloc(struct drm_device *dev, void *data,
Eric Anholtc153f452007-09-03 12:06:45 +10001571 struct drm_file *file_priv);
Eric Anholtc153f452007-09-03 12:06:45 +10001572extern int drm_sg_free(struct drm_device *dev, void *data,
1573 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001575 /* ATI PCIGART support (ati_pcigart.h) */
Dave Airlie84b1fd12007-07-11 15:53:27 +10001576extern int drm_ati_pcigart_init(struct drm_device *dev,
Dave Airlie55910512007-07-11 16:53:40 +10001577 struct drm_ati_pcigart_info * gart_info);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001578extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
Dave Airlie55910512007-07-11 16:53:40 +10001579 struct drm_ati_pcigart_info * gart_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Dave Airlie84b1fd12007-07-11 15:53:27 +10001581extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
Zhenyu Wange6be8d92010-01-05 11:25:05 +08001582 size_t align);
Dave Airlie84b1fd12007-07-11 15:53:27 +10001583extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1584extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
1586 /* sysfs support (drm_sysfs.c) */
Jesse Barnese8b962b2007-11-22 14:02:38 +10001587struct drm_sysfs_class;
Greg Kroah-Hartman0650fd52006-01-20 14:08:59 -08001588extern struct class *drm_sysfs_create(struct module *owner, char *name);
Jesse Barnese8b962b2007-11-22 14:02:38 +10001589extern void drm_sysfs_destroy(void);
Dave Airlie2c14f282008-04-21 16:47:32 +10001590extern int drm_sysfs_device_add(struct drm_minor *minor);
Dave Airlief453ba02008-11-07 14:05:41 -08001591extern void drm_sysfs_hotplug_event(struct drm_device *dev);
Dave Airlie2c14f282008-04-21 16:47:32 +10001592extern void drm_sysfs_device_remove(struct drm_minor *minor);
Dave Airlief453ba02008-11-07 14:05:41 -08001593extern int drm_sysfs_connector_add(struct drm_connector *connector);
1594extern void drm_sysfs_connector_remove(struct drm_connector *connector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Eric Anholt673a3942008-07-30 12:06:12 -07001596/* Graphics Execution Manager library functions (drm_gem.c) */
1597int drm_gem_init(struct drm_device *dev);
Jesse Barnesa2c0a972008-11-05 10:31:53 -08001598void drm_gem_destroy(struct drm_device *dev);
Daniel Vetterfd632aa2010-04-09 19:05:05 +00001599void drm_gem_object_release(struct drm_gem_object *obj);
Eric Anholt673a3942008-07-30 12:06:12 -07001600void drm_gem_object_free(struct kref *kref);
1601struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1602 size_t size);
Daniel Vetter1d397042010-04-09 19:05:04 +00001603int drm_gem_object_init(struct drm_device *dev,
1604 struct drm_gem_object *obj, size_t size);
David Herrmann89c82332013-07-11 11:56:32 +02001605void drm_gem_private_object_init(struct drm_device *dev,
1606 struct drm_gem_object *obj, size_t size);
Dave Airlie29d08b32010-09-27 16:17:17 +10001607void drm_gem_object_handle_free(struct drm_gem_object *obj);
Jesse Barnesab00b3e2009-02-11 14:01:46 -08001608void drm_gem_vm_open(struct vm_area_struct *vma);
1609void drm_gem_vm_close(struct vm_area_struct *vma);
Laurent Pinchart1c5aafa2013-04-16 14:14:52 +02001610int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1611 struct vm_area_struct *vma);
Jesse Barnesa2c0a972008-11-05 10:31:53 -08001612int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
Eric Anholt673a3942008-07-30 12:06:12 -07001613
David Howellsa1ce3922012-10-02 18:01:25 +01001614#include <drm/drm_global.h>
Dave Airlieba4420c2010-03-09 10:56:52 +10001615
Eric Anholt673a3942008-07-30 12:06:12 -07001616static inline void
1617drm_gem_object_reference(struct drm_gem_object *obj)
1618{
1619 kref_get(&obj->refcount);
1620}
1621
1622static inline void
1623drm_gem_object_unreference(struct drm_gem_object *obj)
1624{
Luca Barbieric3ae90c2010-02-09 05:49:11 +00001625 if (obj != NULL)
1626 kref_put(&obj->refcount, drm_gem_object_free);
1627}
Eric Anholt673a3942008-07-30 12:06:12 -07001628
Luca Barbieric3ae90c2010-02-09 05:49:11 +00001629static inline void
1630drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1631{
Chris Wilson7fc65eb2013-08-06 09:59:46 +01001632 if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
Chris Wilson39b4d072010-09-30 09:10:26 +01001633 struct drm_device *dev = obj->dev;
Chris Wilson7fc65eb2013-08-06 09:59:46 +01001634
Chris Wilson39b4d072010-09-30 09:10:26 +01001635 mutex_lock(&dev->struct_mutex);
Chris Wilson7fc65eb2013-08-06 09:59:46 +01001636 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
1637 drm_gem_object_free(&obj->refcount);
Chris Wilson39b4d072010-09-30 09:10:26 +01001638 mutex_unlock(&dev->struct_mutex);
1639 }
Eric Anholt673a3942008-07-30 12:06:12 -07001640}
1641
1642int drm_gem_handle_create(struct drm_file *file_priv,
1643 struct drm_gem_object *obj,
Pekka Paalanena1a2d1d2009-08-23 12:40:55 +03001644 u32 *handlep);
Dave Airlieff72145b2011-02-07 12:16:14 +10001645int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
Eric Anholt673a3942008-07-30 12:06:12 -07001646
1647static inline void
1648drm_gem_object_handle_reference(struct drm_gem_object *obj)
1649{
1650 drm_gem_object_reference(obj);
Dave Airlie29d08b32010-09-27 16:17:17 +10001651 atomic_inc(&obj->handle_count);
Eric Anholt673a3942008-07-30 12:06:12 -07001652}
1653
1654static inline void
Luca Barbieric3ae90c2010-02-09 05:49:11 +00001655drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
1656{
1657 if (obj == NULL)
1658 return;
1659
Dave Airlie29d08b32010-09-27 16:17:17 +10001660 if (atomic_read(&obj->handle_count) == 0)
1661 return;
1662
Luca Barbieric3ae90c2010-02-09 05:49:11 +00001663 /*
1664 * Must bump handle count first as this may be the last
1665 * ref, in which case the object would disappear before we
1666 * checked for a name
1667 */
Dave Airlie29d08b32010-09-27 16:17:17 +10001668
1669 if (atomic_dec_and_test(&obj->handle_count))
1670 drm_gem_object_handle_free(obj);
Luca Barbieric3ae90c2010-02-09 05:49:11 +00001671 drm_gem_object_unreference_unlocked(obj);
1672}
1673
Rob Clark75ef8b32011-08-10 08:09:07 -05001674void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1675int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1676
Eric Anholt673a3942008-07-30 12:06:12 -07001677struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1678 struct drm_file *filp,
Pekka Paalanena1a2d1d2009-08-23 12:40:55 +03001679 u32 handle);
Eric Anholt673a3942008-07-30 12:06:12 -07001680int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1681 struct drm_file *file_priv);
1682int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1683 struct drm_file *file_priv);
1684int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1685 struct drm_file *file_priv);
1686void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1687void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1688
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +11001689extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1690extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1691extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +11001693static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1694 unsigned int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
Dave Airlie55910512007-07-11 16:53:40 +10001696 struct drm_map_list *_entry;
Dave Airliebd1b3312007-05-26 05:01:51 +10001697 list_for_each_entry(_entry, &dev->maplist, head)
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001698 if (_entry->user_token == token)
1699 return _entry->map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 return NULL;
1701}
1702
Dave Airlie8410ea32010-12-15 03:16:38 +10001703static __inline__ void drm_core_dropmap(struct drm_local_map *map)
Dave Airliecda17382005-07-10 17:31:26 +10001704{
Dave Airlie8410ea32010-12-15 03:16:38 +10001705}
Jordan Crousedcdb1672010-05-27 13:40:25 -06001706
David Howellsa1ce3922012-10-02 18:01:25 +01001707#include <drm/drm_mem_util.h>
Dave Airlie8410ea32010-12-15 03:16:38 +10001708
1709extern int drm_fill_in_dev(struct drm_device *dev,
1710 const struct pci_device_id *ent,
1711 struct drm_driver *driver);
1712int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
1713/*@}*/
1714
1715/* PCI section */
1716static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1717{
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001718 if (dev->driver->device_is_agp != NULL) {
1719 int err = (*dev->driver->device_is_agp) (dev);
1720
Dave Airliecda17382005-07-10 17:31:26 +10001721 if (err != 2) {
1722 return err;
1723 }
1724 }
1725
1726 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1727}
1728
Dave Airlie8410ea32010-12-15 03:16:38 +10001729extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1730extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
1731extern int drm_get_pci_dev(struct pci_dev *pdev,
Jordan Crousedcdb1672010-05-27 13:40:25 -06001732 const struct pci_device_id *ent,
1733 struct drm_driver *driver);
Dave Airlie8410ea32010-12-15 03:16:38 +10001734
Dave Airlief4297782012-06-27 08:35:53 +01001735#define DRM_PCIE_SPEED_25 1
1736#define DRM_PCIE_SPEED_50 2
1737#define DRM_PCIE_SPEED_80 4
1738
1739extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
Dave Airlie8410ea32010-12-15 03:16:38 +10001740
1741/* platform section */
1742extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1743extern void drm_platform_exit(struct drm_driver *driver, struct platform_device *platform_device);
1744
1745extern int drm_get_platform_dev(struct platform_device *pdev,
1746 struct drm_driver *driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Dave Airliecc1f7192012-01-05 09:55:22 +00001748/* returns true if currently okay to sleep */
1749static __inline__ bool drm_can_sleep(void)
1750{
1751 if (in_atomic() || in_dbg_master() || irqs_disabled())
1752 return false;
1753 return true;
1754}
1755
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001756#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757#endif