Subversion Repositories Kolibri OS

Rev

Rev 4279 | Rev 4393 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file drmP.h
  3.  * Private header for Direct Rendering Manager
  4.  *
  5.  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6.  * \author Gareth Hughes <gareth@valinux.com>
  7.  */
  8.  
  9. /*
  10.  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  11.  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  12.  * Copyright (c) 2009-2010, Code Aurora Forum.
  13.  * 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.  
  38. #define iowrite32(v, addr)      writel((v), (addr))
  39.  
  40. #ifdef __KERNEL__
  41. #ifdef __alpha__
  42. /* add include of current.h so that "current" is defined
  43.  * before static inline funcs in wait.h. Doing this so we
  44.  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
  45. #include <asm/current.h>
  46. #endif                          /* __alpha__ */
  47.  
  48. #include <syscall.h>
  49.  
  50. #include <linux/kernel.h>
  51. #include <linux/export.h>
  52. #include <linux/errno.h>
  53. #include <linux/kref.h>
  54. #include <linux/spinlock.h>
  55. #include <linux/wait.h>
  56. #include <linux/bug.h>
  57. #include <linux/sched.h>
  58.  
  59. #include <linux/firmware.h>
  60. #include <linux/err.h>
  61.  
  62. //#include <linux/fs.h>
  63. //#include <linux/proc_fs.h>
  64. //#include <linux/init.h>
  65. //#include <linux/file.h>
  66. #include <linux/pci.h>
  67. #include <linux/jiffies.h>
  68. #include <linux/irqreturn.h>
  69. //#include <linux/smp_lock.h>    /* For (un)lock_kernel */
  70. //#include <linux/dma-mapping.h>
  71. //#include <linux/mm.h>
  72. //#include <linux/cdev.h>
  73. #include <linux/mutex.h>
  74. //#include <asm/io.h>
  75. //#include <asm/mman.h>
  76. //#include <asm/uaccess.h>
  77. //#include <linux/workqueue.h>
  78. //#include <linux/poll.h>
  79. //#include <asm/pgalloc.h>
  80.  
  81. #include <linux/workqueue.h>
  82.  
  83.  
  84. #include <drm/drm.h>
  85. #include <drm/drm_vma_manager.h>
  86.  
  87. #include <linux/idr.h>
  88.  
  89. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  90.  
  91. struct module;
  92.  
  93. struct drm_file;
  94. struct drm_device;
  95.  
  96. struct device_node;
  97. struct videomode;
  98.  
  99. struct inode;
  100. struct poll_table_struct;
  101. struct drm_lock_data;
  102.  
  103. struct sg_table;
  104. struct dma_buf;
  105.  
  106. //#include <drm/drm_os_linux.h>
  107. #include <drm/drm_hashtab.h>
  108. #include <drm/drm_mm.h>
  109.  
  110. #define KHZ2PICOS(a) (1000000000UL/(a))
  111.  
  112. /* get_scanout_position() return flags */
  113. #define DRM_SCANOUTPOS_VALID        (1 << 0)
  114. #define DRM_SCANOUTPOS_INVBL        (1 << 1)
  115. #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
  116.  
  117.  
  118.  
  119. #define DRM_UT_CORE             0x01
  120. #define DRM_UT_DRIVER           0x02
  121. #define DRM_UT_KMS          0x04
  122. #define DRM_UT_PRIME            0x08
  123. /*
  124.  * Three debug levels are defined.
  125.  * drm_core, drm_driver, drm_kms
  126.  * drm_core level can be used in the generic drm code. For example:
  127.  *      drm_ioctl, drm_mm, drm_memory
  128.  * The macro definition of DRM_DEBUG is used.
  129.  *      DRM_DEBUG(fmt, args...)
  130.  *      The debug info by using the DRM_DEBUG can be obtained by adding
  131.  *      the boot option of "drm.debug=1".
  132.  *
  133.  * drm_driver level can be used in the specific drm driver. It is used
  134.  * to add the debug info related with the drm driver. For example:
  135.  * i915_drv, i915_dma, i915_gem, radeon_drv,
  136.  *      The macro definition of DRM_DEBUG_DRIVER can be used.
  137.  *      DRM_DEBUG_DRIVER(fmt, args...)
  138.  *      The debug info by using the DRM_DEBUG_DRIVER can be obtained by
  139.  *      adding the boot option of "drm.debug=0x02"
  140.  *
  141.  * drm_kms level can be used in the KMS code related with specific drm driver.
  142.  * It is used to add the debug info related with KMS mode. For example:
  143.  * the connector/crtc ,
  144.  *      The macro definition of DRM_DEBUG_KMS can be used.
  145.  *      DRM_DEBUG_KMS(fmt, args...)
  146.  *      The debug info by using the DRM_DEBUG_KMS can be obtained by
  147.  *      adding the boot option of "drm.debug=0x04"
  148.  *
  149.  * If we add the boot option of "drm.debug=0x06", we can get the debug info by
  150.  * using the DRM_DEBUG_KMS and DRM_DEBUG_DRIVER.
  151.  * If we add the boot option of "drm.debug=0x05", we can get the debug info by
  152.  * using the DRM_DEBUG_KMS and DRM_DEBUG.
  153.  */
  154.  
  155. extern __printf(4, 5)
  156. void drm_ut_debug_printk(unsigned int request_level,
  157.                                 const char *prefix,
  158.                                 const char *function_name,
  159.                                 const char *format, ...);
  160. extern __printf(2, 3)
  161. int drm_err(const char *func, const char *format, ...);
  162.  
  163. /***********************************************************************/
  164. /** \name DRM template customization defaults */
  165. /*@{*/
  166.  
  167. /* driver capabilities and requirements mask */
  168. #define DRIVER_USE_AGP     0x1
  169. #define DRIVER_REQUIRE_AGP 0x2
  170. #define DRIVER_PCI_DMA     0x8
  171. #define DRIVER_SG          0x10
  172. #define DRIVER_HAVE_DMA    0x20
  173. #define DRIVER_HAVE_IRQ    0x40
  174. #define DRIVER_IRQ_SHARED  0x80
  175. #define DRIVER_GEM         0x1000
  176. #define DRIVER_MODESET     0x2000
  177. #define DRIVER_PRIME       0x4000
  178. #define DRIVER_RENDER      0x8000
  179.  
  180. #define DRIVER_BUS_PCI 0x1
  181. #define DRIVER_BUS_PLATFORM 0x2
  182. #define DRIVER_BUS_USB 0x3
  183.  
  184. /***********************************************************************/
  185. /** \name Begin the DRM... */
  186. /*@{*/
  187.  
  188. #define DRM_DEBUG_CODE 2     /**< Include debugging code if > 1, then
  189.                                      also include looping detection. */
  190.  
  191. #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
  192. #define DRM_KERNEL_CONTEXT    0  /**< Change drm_resctx if changed */
  193. #define DRM_RESERVED_CONTEXTS 1  /**< Change drm_resctx if changed */
  194. #define DRM_LOOPING_LIMIT     5000000
  195. #define DRM_TIME_SLICE        (HZ/20)  /**< Time slice for GLXContexts */
  196. #define DRM_LOCK_SLICE        1 /**< Time slice for lock, in jiffies */
  197.  
  198. #define DRM_FLAG_DEBUG    0x01
  199.  
  200. #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
  201. #define DRM_MAP_HASH_OFFSET 0x10000000
  202.  
  203. /*@}*/
  204.  
  205. /***********************************************************************/
  206. /** \name Macros to make printk easier */
  207. /*@{*/
  208.  
  209. /**
  210.  * Error output.
  211.  *
  212.  * \param fmt printf() like format string.
  213.  * \param arg arguments
  214.  */
  215. #define DRM_ERROR(fmt, ...)                             \
  216.         drm_err(__func__, fmt, ##__VA_ARGS__)
  217.  
  218. #define DRM_INFO(fmt, ...)                              \
  219.         printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  220.  
  221. /**
  222.  * Debug output.
  223.  *
  224.  * \param fmt printf() like format string.
  225.  * \param arg arguments
  226.  */
  227. #if DRM_DEBUG_CODE
  228. #define DRM_DEBUG(fmt, ...)                                 \
  229.     do {                                                    \
  230.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  231.         } while (0)
  232.  
  233. #define DRM_DEBUG_DRIVER(fmt, ...)                          \
  234.     do {                                                    \
  235.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  236.         } while (0)
  237. #define DRM_DEBUG_KMS(fmt, ...)              \
  238.         do {                                                            \
  239.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  240.         } while (0)
  241. #define DRM_DEBUG_PRIME(fmt, ...)                    \
  242.         do {                                                            \
  243.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  244.         } while (0)
  245. #define DRM_LOG(fmt, ...)                        \
  246.         do {                                                            \
  247.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  248.         } while (0)
  249. #define DRM_LOG_KMS(fmt, ...)                    \
  250.         do {                                                            \
  251.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  252.         } while (0)
  253. #define DRM_LOG_MODE(fmt, ...)                   \
  254.         do {                                                            \
  255.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  256.         } while (0)
  257. #define DRM_LOG_DRIVER(fmt, ...)                 \
  258.         do {                                                            \
  259.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  260.         } while (0)
  261. #else
  262. #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
  263. #define DRM_DEBUG_KMS(fmt, args...)     do { } while (0)
  264. #define DRM_DEBUG_PRIME(fmt, args...)   do { } while (0)
  265. #define DRM_DEBUG(fmt, arg...)           do { } while (0)
  266. #define DRM_LOG(fmt, arg...)            do { } while (0)
  267. #define DRM_LOG_KMS(fmt, args...) do { } while (0)
  268. #define DRM_LOG_MODE(fmt, arg...) do { } while (0)
  269. #define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
  270.  
  271. #endif
  272.  
  273. /*@}*/
  274.  
  275. /***********************************************************************/
  276. /** \name Internal types and structures */
  277. /*@{*/
  278.  
  279. #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
  280.  
  281. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  282.  
  283. /**
  284.  * Test that the hardware lock is held by the caller, returning otherwise.
  285.  *
  286.  * \param dev DRM device.
  287.  * \param filp file pointer of the caller.
  288.  */
  289. #define LOCK_TEST_WITH_RETURN( dev, _file_priv )                                \
  290. do {                                                                            \
  291.         if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||       \
  292.             _file_priv->master->lock.file_priv != _file_priv)   {               \
  293.                 DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
  294.                            __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  295.                            _file_priv->master->lock.file_priv, _file_priv);     \
  296.                 return -EINVAL;                                                 \
  297.         }                                                                       \
  298. } while (0)
  299.  
  300. #if 0
  301. /**
  302.  * Ioctl function type.
  303.  *
  304.  * \param inode device inode.
  305.  * \param file_priv DRM file private pointer.
  306.  * \param cmd command.
  307.  * \param arg argument.
  308.  */
  309. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  310.                         struct drm_file *file_priv);
  311.  
  312. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  313.                                unsigned long arg);
  314.  
  315. #define DRM_IOCTL_NR(n)                _IOC_NR(n)
  316. #define DRM_MAJOR       226
  317.  
  318. #define DRM_AUTH        0x1
  319. #define DRM_MASTER      0x2
  320. #define DRM_ROOT_ONLY   0x4
  321. #define DRM_CONTROL_ALLOW 0x8
  322. #define DRM_UNLOCKED    0x10
  323. #define DRM_RENDER_ALLOW 0x20
  324.  
  325. struct drm_ioctl_desc {
  326.         unsigned int cmd;
  327.         int flags;
  328.         drm_ioctl_t *func;
  329.         unsigned int cmd_drv;
  330.         const char *name;
  331. };
  332.  
  333. /**
  334.  * Creates a driver or general drm_ioctl_desc array entry for the given
  335.  * ioctl, for use by drm_ioctl().
  336.  */
  337.  
  338. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                 \
  339.         [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
  340.  
  341. struct drm_magic_entry {
  342.         struct list_head head;
  343.         struct drm_hash_item hash_item;
  344.         struct drm_file *priv;
  345. };
  346.  
  347. struct drm_vma_entry {
  348.         struct list_head head;
  349.         struct vm_area_struct *vma;
  350.         pid_t pid;
  351. };
  352.  
  353. /**
  354.  * DMA buffer.
  355.  */
  356. struct drm_buf {
  357.         int idx;                       /**< Index into master buflist */
  358.         int total;                     /**< Buffer size */
  359.         int order;                     /**< log-base-2(total) */
  360.         int used;                      /**< Amount of buffer in use (for DMA) */
  361.         unsigned long offset;          /**< Byte offset (used internally) */
  362.         void *address;                 /**< Address of buffer */
  363.         unsigned long bus_address;     /**< Bus address of buffer */
  364.         struct drm_buf *next;          /**< Kernel-only: used for free list */
  365.         __volatile__ int waiting;      /**< On kernel DMA queue */
  366.         __volatile__ int pending;      /**< On hardware DMA queue */
  367.         struct drm_file *file_priv;    /**< Private of holding file descr */
  368.         int context;                   /**< Kernel queue for this buffer */
  369.         int while_locked;              /**< Dispatch this buffer while locked */
  370.         enum {
  371.                 DRM_LIST_NONE = 0,
  372.                 DRM_LIST_FREE = 1,
  373.                 DRM_LIST_WAIT = 2,
  374.                 DRM_LIST_PEND = 3,
  375.                 DRM_LIST_PRIO = 4,
  376.                 DRM_LIST_RECLAIM = 5
  377.         } list;                        /**< Which list we're on */
  378.  
  379.         int dev_priv_size;               /**< Size of buffer private storage */
  380.         void *dev_private;               /**< Per-buffer private storage */
  381. };
  382.  
  383. /** bufs is one longer than it has to be */
  384. struct drm_waitlist {
  385.         int count;                      /**< Number of possible buffers */
  386.         struct drm_buf **bufs;          /**< List of pointers to buffers */
  387.         struct drm_buf **rp;                    /**< Read pointer */
  388.         struct drm_buf **wp;                    /**< Write pointer */
  389.         struct drm_buf **end;           /**< End pointer */
  390.         spinlock_t read_lock;
  391.         spinlock_t write_lock;
  392. };
  393. #endif
  394.  
  395. struct drm_freelist {
  396.         int initialized;               /**< Freelist in use */
  397.         atomic_t count;                /**< Number of free buffers */
  398.         struct drm_buf *next;          /**< End pointer */
  399.  
  400.         wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
  401.         int low_mark;                  /**< Low water mark */
  402.         int high_mark;                 /**< High water mark */
  403.         atomic_t wfh;                  /**< If waiting for high mark */
  404.         spinlock_t lock;
  405. };
  406.  
  407. typedef struct drm_dma_handle {
  408.         dma_addr_t busaddr;
  409.         void *vaddr;
  410.         size_t size;
  411. } drm_dma_handle_t;
  412.  
  413. /**
  414.  * Buffer entry.  There is one of this for each buffer size order.
  415.  */
  416. struct drm_buf_entry {
  417.         int buf_size;                   /**< size */
  418.         int buf_count;                  /**< number of buffers */
  419.         struct drm_buf *buflist;                /**< buffer list */
  420.         int seg_count;
  421.         int page_order;
  422.         struct drm_dma_handle **seglist;
  423.  
  424.         struct drm_freelist freelist;
  425. };
  426.  
  427. /* Event queued up for userspace to read */
  428. struct drm_pending_event {
  429.         struct drm_event *event;
  430.         struct list_head link;
  431.         struct drm_file *file_priv;
  432.         pid_t pid; /* pid of requester, no guarantee it's valid by the time
  433.                       we deliver the event, for tracing only */
  434.         void (*destroy)(struct drm_pending_event *event);
  435. };
  436.  
  437. /* initial implementaton using a linked list - todo hashtab */
  438. struct drm_prime_file_private {
  439.         struct list_head head;
  440.         struct mutex lock;
  441. };
  442.  
  443. /** File private data */
  444. struct drm_file {
  445.         struct list_head lhead;
  446.         unsigned long lock_count;
  447.  
  448.         /** Mapping of mm object handles to object pointers. */
  449.         struct idr object_idr;
  450.         /** Lock for synchronization of access to object_idr. */
  451.         spinlock_t table_lock;
  452.  
  453.         void *driver_priv;
  454.  
  455.         struct list_head fbs;
  456.  
  457.         wait_queue_head_t event_wait;
  458.         struct list_head event_list;
  459.         int event_space;
  460. };
  461.  
  462. #if 0
  463. /** Wait queue */
  464. struct drm_queue {
  465.         atomic_t use_count;             /**< Outstanding uses (+1) */
  466.         atomic_t finalization;          /**< Finalization in progress */
  467.         atomic_t block_count;           /**< Count of processes waiting */
  468.         atomic_t block_read;            /**< Queue blocked for reads */
  469.         wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
  470.         atomic_t block_write;           /**< Queue blocked for writes */
  471.         wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
  472.         atomic_t total_queued;          /**< Total queued statistic */
  473.         atomic_t total_flushed;         /**< Total flushes statistic */
  474.         atomic_t total_locks;           /**< Total locks statistics */
  475.         enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
  476.         struct drm_waitlist waitlist;   /**< Pending buffers */
  477.         wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
  478. };
  479.  
  480. /**
  481.  * Lock data.
  482.  */
  483. struct drm_lock_data {
  484.         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
  485.         /** Private of lock holder's file (NULL=kernel) */
  486.         struct drm_file *file_priv;
  487.         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
  488.         unsigned long lock_time;        /**< Time of last lock in jiffies */
  489.         spinlock_t spinlock;
  490.         uint32_t kernel_waiters;
  491.         uint32_t user_waiters;
  492.         int idle_has_lock;
  493. };
  494.  
  495. /**
  496.  * DMA data.
  497.  */
  498. struct drm_device_dma {
  499.  
  500.         struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
  501.         int buf_count;                  /**< total number of buffers */
  502.         struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
  503.         int seg_count;
  504.         int page_count;                 /**< number of pages */
  505.         unsigned long *pagelist;        /**< page list */
  506.         unsigned long byte_count;
  507.         enum {
  508.                 _DRM_DMA_USE_AGP = 0x01,
  509.                 _DRM_DMA_USE_SG = 0x02,
  510.                 _DRM_DMA_USE_FB = 0x04,
  511.                 _DRM_DMA_USE_PCI_RO = 0x08
  512.         } flags;
  513.  
  514. };
  515.  
  516. /**
  517.  * AGP memory entry.  Stored as a doubly linked list.
  518.  */
  519. struct drm_agp_mem {
  520.         unsigned long handle;           /**< handle */
  521.         DRM_AGP_MEM *memory;
  522.         unsigned long bound;            /**< address */
  523.         int pages;
  524.         struct list_head head;
  525. };
  526.  
  527. /**
  528.  * AGP data.
  529.  *
  530.  * \sa drm_agp_init() and drm_device::agp.
  531.  */
  532. struct drm_agp_head {
  533.         DRM_AGP_KERN agp_info;          /**< AGP device information */
  534.         struct list_head memory;
  535.         unsigned long mode;             /**< AGP mode */
  536.         struct agp_bridge_data *bridge;
  537.         int enabled;                    /**< whether the AGP bus as been enabled */
  538.         int acquired;                   /**< whether the AGP device has been acquired */
  539.         unsigned long base;
  540.         int agp_mtrr;
  541.         int cant_use_aperture;
  542.         unsigned long page_mask;
  543. };
  544.  
  545. /**
  546.  * Scatter-gather memory.
  547.  */
  548. struct drm_sg_mem {
  549.         unsigned long handle;
  550.         void *virtual;
  551.         int pages;
  552.         struct page **pagelist;
  553.         dma_addr_t *busaddr;
  554. };
  555.  
  556. struct drm_sigdata {
  557.         int context;
  558.         struct drm_hw_lock *lock;
  559. };
  560.  
  561. #endif
  562.  
  563.  
  564. /**
  565.  * Kernel side of a mapping
  566.  */
  567. struct drm_local_map {
  568.         resource_size_t offset;  /**< Requested physical address (0 for SAREA)*/
  569.         unsigned long size;      /**< Requested physical size (bytes) */
  570.         enum drm_map_type type;  /**< Type of memory to map */
  571.         enum drm_map_flags flags;        /**< Flags */
  572.         void *handle;            /**< User-space: "Handle" to pass to mmap() */
  573.                                  /**< Kernel-space: kernel-virtual address */
  574.         int mtrr;                /**< MTRR slot used */
  575. };
  576.  
  577. typedef struct drm_local_map drm_local_map_t;
  578.  
  579. /**
  580.  * Mappings list
  581.  */
  582. struct drm_map_list {
  583.         struct list_head head;          /**< list head */
  584.         struct drm_hash_item hash;
  585.         struct drm_local_map *map;      /**< mapping */
  586.         uint64_t user_token;
  587.         struct drm_master *master;
  588. };
  589.  
  590. /**
  591.  * Context handle list
  592.  */
  593. struct drm_ctx_list {
  594.         struct list_head head;          /**< list head */
  595.         drm_context_t handle;           /**< context handle */
  596.         struct drm_file *tag;           /**< associated fd private data */
  597. };
  598.  
  599. /* location of GART table */
  600. #define DRM_ATI_GART_MAIN 1
  601. #define DRM_ATI_GART_FB   2
  602.  
  603. #define DRM_ATI_GART_PCI 1
  604. #define DRM_ATI_GART_PCIE 2
  605. #define DRM_ATI_GART_IGP 3
  606.  
  607. struct drm_ati_pcigart_info {
  608.         int gart_table_location;
  609.         int gart_reg_if;
  610.         void *addr;
  611.         dma_addr_t bus_addr;
  612.         dma_addr_t table_mask;
  613.         struct drm_dma_handle *table_handle;
  614.         struct drm_local_map mapping;
  615.         int table_size;
  616. };
  617.  
  618. /**
  619.  * GEM specific mm private for tracking GEM objects
  620.  */
  621. struct drm_gem_mm {
  622.         struct drm_vma_offset_manager vma_manager;
  623. };
  624.  
  625. /**
  626.  * This structure defines the drm_mm memory object, which will be used by the
  627.  * DRM for its buffer objects.
  628.  */
  629. struct drm_gem_object {
  630.         /** Reference count of this object */
  631.         struct kref refcount;
  632.  
  633.         /**
  634.          * handle_count - gem file_priv handle count of this object
  635.          *
  636.          * Each handle also holds a reference. Note that when the handle_count
  637.          * drops to 0 any global names (e.g. the id in the flink namespace) will
  638.          * be cleared.
  639.          *
  640.          * Protected by dev->object_name_lock.
  641.          * */
  642.         unsigned handle_count;
  643.  
  644.         /** Related drm device */
  645.         struct drm_device *dev;
  646.  
  647.         /** File representing the shmem storage */
  648.         struct file *filp;
  649.  
  650.         /* Mapping info for this object */
  651.         struct drm_vma_offset_node vma_node;
  652.  
  653.         /**
  654.          * Size of the object, in bytes.  Immutable over the object's
  655.          * lifetime.
  656.          */
  657.         size_t size;
  658.  
  659.         /**
  660.          * Global name for this object, starts at 1. 0 means unnamed.
  661.          * Access is covered by the object_name_lock in the related drm_device
  662.          */
  663.         int name;
  664.  
  665.         /**
  666.          * Memory domains. These monitor which caches contain read/write data
  667.          * related to the object. When transitioning from one set of domains
  668.          * to another, the driver is called to ensure that caches are suitably
  669.          * flushed and invalidated
  670.          */
  671.         uint32_t read_domains;
  672.         uint32_t write_domain;
  673.  
  674.         /**
  675.          * While validating an exec operation, the
  676.          * new read/write domain values are computed here.
  677.          * They will be transferred to the above values
  678.          * at the point that any cache flushing occurs
  679.          */
  680.         uint32_t pending_read_domains;
  681.         uint32_t pending_write_domain;
  682.  
  683.         void *driver_private;
  684. };
  685.  
  686. #include <drm/drm_crtc.h>
  687.  
  688. /* per-master structure */
  689. struct drm_master {
  690.  
  691.         struct kref refcount; /* refcount for this master */
  692.  
  693.         struct list_head head; /**< each minor contains a list of masters */
  694.         struct drm_minor *minor; /**< link back to minor we are a master for */
  695.  
  696.         char *unique;                   /**< Unique identifier: e.g., busid */
  697.         int unique_len;                 /**< Length of unique field */
  698.         int unique_size;                /**< amount allocated */
  699.  
  700.         int blocked;                    /**< Blocked due to VC switch? */
  701.  
  702.         /** \name Authentication */
  703.         /*@{ */
  704. //   struct drm_open_hash magiclist;
  705. //   struct list_head magicfree;
  706.         /*@} */
  707.  
  708. //   struct drm_lock_data lock;  /**< Information on hardware lock */
  709.  
  710.         void *driver_priv; /**< Private structure for driver to use */
  711. };
  712.  
  713. #if 0
  714.  
  715. /* Size of ringbuffer for vblank timestamps. Just double-buffer
  716.  * in initial implementation.
  717.  */
  718. #define DRM_VBLANKTIME_RBSIZE 2
  719.  
  720. /* Flags and return codes for get_vblank_timestamp() driver function. */
  721. #define DRM_CALLED_FROM_VBLIRQ 1
  722. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  723. #define DRM_VBLANKTIME_INVBL             (1 << 1)
  724.  
  725. /* get_scanout_position() return flags */
  726. #define DRM_SCANOUTPOS_VALID        (1 << 0)
  727. #define DRM_SCANOUTPOS_INVBL        (1 << 1)
  728. #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
  729.  
  730. struct drm_bus {
  731.         int bus_type;
  732.         int (*get_irq)(struct drm_device *dev);
  733.         const char *(*get_name)(struct drm_device *dev);
  734.         int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  735.         int (*set_unique)(struct drm_device *dev, struct drm_master *master,
  736.                           struct drm_unique *unique);
  737.         int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
  738.         /* hooks that are for PCI */
  739.         int (*agp_init)(struct drm_device *dev);
  740.         void (*agp_destroy)(struct drm_device *dev);
  741.  
  742. };
  743. #endif
  744.  
  745. #define DRM_IRQ_ARGS            int irq, void *arg
  746.  
  747. /**
  748.  * DRM driver structure. This structure represent the common code for
  749.  * a family of cards. There will one drm_device for each card present
  750.  * in this family
  751.  */
  752. struct drm_driver {
  753.         int (*load) (struct drm_device *, unsigned long flags);
  754.         int (*open) (struct drm_device *, struct drm_file *);
  755.  
  756.         /**
  757.          * get_vblank_counter - get raw hardware vblank counter
  758.          * @dev: DRM device
  759.          * @crtc: counter to fetch
  760.          *
  761.          * Driver callback for fetching a raw hardware vblank counter for @crtc.
  762.          * If a device doesn't have a hardware counter, the driver can simply
  763.          * return the value of drm_vblank_count. The DRM core will account for
  764.          * missed vblank events while interrupts where disabled based on system
  765.          * timestamps.
  766.          *
  767.          * Wraparound handling and loss of events due to modesetting is dealt
  768.          * with in the DRM core code.
  769.          *
  770.          * RETURNS
  771.          * Raw vblank counter value.
  772.          */
  773.         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  774.  
  775.         /**
  776.          * enable_vblank - enable vblank interrupt events
  777.          * @dev: DRM device
  778.          * @crtc: which irq to enable
  779.          *
  780.          * Enable vblank interrupts for @crtc.  If the device doesn't have
  781.          * a hardware vblank counter, this routine should be a no-op, since
  782.          * interrupts will have to stay on to keep the count accurate.
  783.          *
  784.          * RETURNS
  785.          * Zero on success, appropriate errno if the given @crtc's vblank
  786.          * interrupt cannot be enabled.
  787.          */
  788.         int (*enable_vblank) (struct drm_device *dev, int crtc);
  789.  
  790.         /**
  791.          * disable_vblank - disable vblank interrupt events
  792.          * @dev: DRM device
  793.          * @crtc: which irq to enable
  794.          *
  795.          * Disable vblank interrupts for @crtc.  If the device doesn't have
  796.          * a hardware vblank counter, this routine should be a no-op, since
  797.          * interrupts will have to stay on to keep the count accurate.
  798.          */
  799.         void (*disable_vblank) (struct drm_device *dev, int crtc);
  800.         /**
  801.          * Called by vblank timestamping code.
  802.          *
  803.          * Return the current display scanout position from a crtc.
  804.          *
  805.          * \param dev  DRM device.
  806.          * \param crtc Id of the crtc to query.
  807.          * \param *vpos Target location for current vertical scanout position.
  808.          * \param *hpos Target location for current horizontal scanout position.
  809.          *
  810.          * Returns vpos as a positive number while in active scanout area.
  811.          * Returns vpos as a negative number inside vblank, counting the number
  812.          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  813.          * until start of active scanout / end of vblank."
  814.          *
  815.          * \return Flags, or'ed together as follows:
  816.          *
  817.          * DRM_SCANOUTPOS_VALID = Query successful.
  818.          * DRM_SCANOUTPOS_INVBL = Inside vblank.
  819.          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  820.          * this flag means that returned position may be offset by a constant
  821.          * but unknown small number of scanlines wrt. real scanout position.
  822.          *
  823.          */
  824.         int (*get_scanout_position) (struct drm_device *dev, int crtc,
  825.                                      int *vpos, int *hpos);
  826.  
  827.         /**
  828.          * Called by \c drm_get_last_vbltimestamp. Should return a precise
  829.          * timestamp when the most recent VBLANK interval ended or will end.
  830.          *
  831.          * Specifically, the timestamp in @vblank_time should correspond as
  832.          * closely as possible to the time when the first video scanline of
  833.          * the video frame after the end of VBLANK will start scanning out,
  834.          * the time immediately after end of the VBLANK interval. If the
  835.          * @crtc is currently inside VBLANK, this will be a time in the future.
  836.          * If the @crtc is currently scanning out a frame, this will be the
  837.          * past start time of the current scanout. This is meant to adhere
  838.          * to the OpenML OML_sync_control extension specification.
  839.          *
  840.          * \param dev dev DRM device handle.
  841.          * \param crtc crtc for which timestamp should be returned.
  842.          * \param *max_error Maximum allowable timestamp error in nanoseconds.
  843.          *                   Implementation should strive to provide timestamp
  844.          *                   with an error of at most *max_error nanoseconds.
  845.          *                   Returns true upper bound on error for timestamp.
  846.          * \param *vblank_time Target location for returned vblank timestamp.
  847.          * \param flags 0 = Defaults, no special treatment needed.
  848.          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  849.          *              irq handler. Some drivers need to apply some workarounds
  850.          *              for gpu-specific vblank irq quirks if flag is set.
  851.          *
  852.          * \returns
  853.          * Zero if timestamping isn't supported in current display mode or a
  854.          * negative number on failure. A positive status code on success,
  855.          * which describes how the vblank_time timestamp was computed.
  856.          */
  857.         int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
  858.                                      int *max_error,
  859.                                      struct timeval *vblank_time,
  860.                                      unsigned flags);
  861.  
  862.         /* these have to be filled in */
  863.  
  864.         irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  865.         void (*irq_preinstall) (struct drm_device *dev);
  866.         int (*irq_postinstall) (struct drm_device *dev);
  867.         void (*irq_uninstall) (struct drm_device *dev);
  868.  
  869.         /**
  870.          * Driver-specific constructor for drm_gem_objects, to set up
  871.          * obj->driver_private.
  872.          *
  873.          * Returns 0 on success.
  874.          */
  875.         int (*gem_init_object) (struct drm_gem_object *obj);
  876.         void (*gem_free_object) (struct drm_gem_object *obj);
  877.         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  878.         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  879.         u32 driver_features;
  880. };
  881.  
  882. #define DRM_MINOR_UNASSIGNED 0
  883. #define DRM_MINOR_LEGACY 1
  884. #define DRM_MINOR_CONTROL 2
  885. #define DRM_MINOR_RENDER 3
  886.  
  887.  
  888. /**
  889.  * debugfs node list. This structure represents a debugfs file to
  890.  * be created by the drm core
  891.  */
  892. struct drm_debugfs_list {
  893.         const char *name; /** file name */
  894. //   int (*show)(struct seq_file*, void*); /** show callback */
  895.         u32 driver_features; /**< Required driver features for this entry */
  896. };
  897.  
  898. /**
  899.  * debugfs node structure. This structure represents a debugfs file.
  900.  */
  901. struct drm_debugfs_node {
  902.         struct list_head list;
  903.         struct drm_minor *minor;
  904.         struct drm_debugfs_list *debugfs_ent;
  905.         struct dentry *dent;
  906. };
  907.  
  908. /**
  909.  * Info file list entry. This structure represents a debugfs or proc file to
  910.  * be created by the drm core
  911.  */
  912. struct drm_info_list {
  913.         const char *name; /** file name */
  914. //   int (*show)(struct seq_file*, void*); /** show callback */
  915.         u32 driver_features; /**< Required driver features for this entry */
  916.         void *data;
  917. };
  918.  
  919. /**
  920.  * debugfs node structure. This structure represents a debugfs file.
  921.  */
  922. struct drm_info_node {
  923.         struct list_head list;
  924.         struct drm_minor *minor;
  925.         const struct drm_info_list *info_ent;
  926.         struct dentry *dent;
  927. };
  928.  
  929. /**
  930.  * DRM minor structure. This structure represents a drm minor number.
  931.  */
  932. struct drm_minor {
  933.         int index;                      /**< Minor device number */
  934.         int type;                       /**< Control or render */
  935. //   dev_t device;           /**< Device number for mknod */
  936. //   struct device kdev;     /**< Linux device */
  937.         struct drm_device *dev;
  938.  
  939. //   struct proc_dir_entry *proc_root;  /**< proc directory entry */
  940. //   struct drm_info_node proc_nodes;
  941. //   struct dentry *debugfs_root;
  942. //   struct drm_info_node debugfs_nodes;
  943.  
  944.     struct drm_master *master; /* currently active master for this node */
  945. //   struct list_head master_list;
  946. //   struct drm_mode_group mode_group;
  947. };
  948.  
  949. /* mode specified on the command line */
  950. struct drm_cmdline_mode {
  951.         bool specified;
  952.         bool refresh_specified;
  953.         bool bpp_specified;
  954.         int xres, yres;
  955.         int bpp;
  956.         int refresh;
  957.         bool rb;
  958.         bool interlace;
  959.         bool cvt;
  960.         bool margins;
  961.         enum drm_connector_force force;
  962. };
  963.  
  964.  
  965.  
  966. /**
  967.  * DRM device structure. This structure represent a complete card that
  968.  * may contain multiple heads.
  969.  */
  970. struct drm_device {
  971.         struct list_head driver_item;   /**< list of devices per driver */
  972.         char *devname;                  /**< For /proc/interrupts */
  973.         int if_version;                 /**< Highest interface version set */
  974.  
  975.         /** \name Locks */
  976.         /*@{ */
  977.     spinlock_t count_lock;      /**< For inuse, drm_device::open_count, drm_device::buf_use */
  978.         struct mutex struct_mutex;      /**< For others */
  979.         /*@} */
  980.  
  981.         /** \name Usage Counters */
  982.         /*@{ */
  983.         int open_count;                 /**< Outstanding files open */
  984.    atomic_t ioctl_count;       /**< Outstanding IOCTLs pending */
  985.    atomic_t vma_count;     /**< Outstanding vma areas open */
  986.         int buf_use;                    /**< Buffers in use -- cannot alloc */
  987.    atomic_t buf_alloc;     /**< Buffer allocation in progress */
  988.         /*@} */
  989.  
  990.         /** \name Performance counters */
  991.         /*@{ */
  992.         unsigned long counters;
  993. //   enum drm_stat_type types[15];
  994.    atomic_t counts[15];
  995.         /*@} */
  996.  
  997.         struct list_head filelist;
  998.  
  999.         /** \name Memory management */
  1000.         /*@{ */
  1001.         struct list_head maplist;       /**< Linked list of regions */
  1002.         int map_count;                  /**< Number of mappable regions */
  1003. //   struct drm_open_hash map_hash;  /**< User token hash table for maps */
  1004.  
  1005.         /** \name Context handle management */
  1006.         /*@{ */
  1007.         struct list_head ctxlist;       /**< Linked list of context handles */
  1008.         int ctx_count;                  /**< Number of context handles */
  1009.         struct mutex ctxlist_mutex;     /**< For ctxlist */
  1010.  
  1011.         struct idr ctx_idr;
  1012.  
  1013.         struct list_head vmalist;       /**< List of vmas (for debugging) */
  1014.  
  1015.         /*@} */
  1016.  
  1017.         /** \name DMA support */
  1018.         /*@{ */
  1019. //   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
  1020.         /*@} */
  1021.  
  1022.         /** \name Context support */
  1023.         /*@{ */
  1024.         int irq_enabled;                /**< True if irq handler is enabled */
  1025.         __volatile__ long context_flag; /**< Context swapping flag */
  1026.         int last_context;               /**< Last current context */
  1027.         /*@} */
  1028.  
  1029. //   struct work_struct work;
  1030.         /** \name VBLANK IRQ support */
  1031.         /*@{ */
  1032.  
  1033.         /*
  1034.          * At load time, disabling the vblank interrupt won't be allowed since
  1035.          * old clients may not call the modeset ioctl and therefore misbehave.
  1036.          * Once the modeset ioctl *has* been called though, we can safely
  1037.          * disable them when unused.
  1038.          */
  1039.         int vblank_disable_allowed;
  1040.  
  1041. //   wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
  1042.    atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
  1043.         struct timeval *_vblank_time;   /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
  1044.         spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
  1045.    spinlock_t vbl_lock;
  1046.    atomic_t *vblank_refcount;      /* number of users of vblank interruptsper crtc */
  1047.         u32 *last_vblank;               /* protected by dev->vbl_lock, used */
  1048.                                         /* for wraparound handling */
  1049.         int *vblank_enabled;            /* so we don't call enable more than
  1050.                                            once per disable */
  1051.         int *vblank_inmodeset;          /* Display driver is setting mode */
  1052.         u32 *last_vblank_wait;          /* Last vblank seqno waited per CRTC */
  1053. //   struct timer_list vblank_disable_timer;
  1054.  
  1055.         u32 max_vblank_count;           /**< size of vblank counter register */
  1056.  
  1057.         /**
  1058.          * List of events
  1059.          */
  1060.         struct list_head vblank_event_list;
  1061.         spinlock_t event_lock;
  1062.  
  1063.         /*@} */
  1064.  
  1065. //   struct drm_agp_head *agp;   /**< AGP data */
  1066.  
  1067.         struct device *dev;             /**< Device structure */
  1068.         struct pci_dev *pdev;           /**< PCI device structure */
  1069.         int pci_vendor;                 /**< PCI vendor id */
  1070.         int pci_device;                 /**< PCI device id */
  1071.         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
  1072.         void *dev_private;              /**< device private data */
  1073.         void *mm_private;
  1074.     struct address_space *dev_mapping;
  1075. //   struct drm_sigdata sigdata;    /**< For block_all_signals */
  1076. //   sigset_t sigmask;
  1077.  
  1078.         struct drm_driver *driver;
  1079. //   struct drm_local_map *agp_buffer_map;
  1080. //   unsigned int agp_buffer_token;
  1081. //   struct drm_minor *control;      /**< Control node for card */
  1082.    struct drm_minor *primary;      /**< render type primary screen head */
  1083.  
  1084.         struct drm_mode_config mode_config;     /**< Current mode config */
  1085.  
  1086.         /** \name GEM information */
  1087.         /*@{ */
  1088.         struct mutex object_name_lock;
  1089.         struct idr object_name_idr;
  1090.         /*@} */
  1091.         int switch_power_state;
  1092.  
  1093.         atomic_t unplugged; /* device has been unplugged or gone away */
  1094. };
  1095.  
  1096. #define DRM_SWITCH_POWER_ON 0
  1097. #define DRM_SWITCH_POWER_OFF 1
  1098. #define DRM_SWITCH_POWER_CHANGING 2
  1099. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  1100.  
  1101. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  1102.                                              int feature)
  1103. {
  1104.         return ((dev->driver->driver_features & feature) ? 1 : 0);
  1105. }
  1106.  
  1107. static inline int drm_dev_to_irq(struct drm_device *dev)
  1108. {
  1109.         return dev->pdev->irq;
  1110. }
  1111.  
  1112. static inline void drm_device_set_unplugged(struct drm_device *dev)
  1113. {
  1114.         smp_wmb();
  1115.         atomic_set(&dev->unplugged, 1);
  1116. }
  1117.  
  1118. static inline int drm_device_is_unplugged(struct drm_device *dev)
  1119. {
  1120.         int ret = atomic_read(&dev->unplugged);
  1121.         smp_rmb();
  1122.         return ret;
  1123. }
  1124.  
  1125. static inline bool drm_modeset_is_locked(struct drm_device *dev)
  1126. {
  1127.         return mutex_is_locked(&dev->mode_config.mutex);
  1128. }
  1129.  
  1130. /******************************************************************/
  1131. /** \name Internal function definitions */
  1132. /*@{*/
  1133.  
  1134.                                 /* Driver support (drm_drv.h) */
  1135. extern long drm_ioctl(struct file *filp,
  1136.                      unsigned int cmd, unsigned long arg);
  1137. extern long drm_compat_ioctl(struct file *filp,
  1138.                              unsigned int cmd, unsigned long arg);
  1139. extern int drm_lastclose(struct drm_device *dev);
  1140.  
  1141.                                 /* Device support (drm_fops.h) */
  1142. extern struct mutex drm_global_mutex;
  1143. extern int drm_open(struct inode *inode, struct file *filp);
  1144. extern int drm_stub_open(struct inode *inode, struct file *filp);
  1145. extern ssize_t drm_read(struct file *filp, char __user *buffer,
  1146.                         size_t count, loff_t *offset);
  1147. extern int drm_release(struct inode *inode, struct file *filp);
  1148.  
  1149.                                 /* Mapping support (drm_vm.h) */
  1150. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  1151. extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
  1152. extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1153. extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1154. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  1155.  
  1156.                                 /* Memory management support (drm_memory.h) */
  1157. #include <drm/drm_memory.h>
  1158.  
  1159.                                 /* Misc. IOCTL support (drm_ioctl.h) */
  1160. extern int drm_irq_by_busid(struct drm_device *dev, void *data,
  1161.                             struct drm_file *file_priv);
  1162. extern int drm_getunique(struct drm_device *dev, void *data,
  1163.                          struct drm_file *file_priv);
  1164. extern int drm_setunique(struct drm_device *dev, void *data,
  1165.                          struct drm_file *file_priv);
  1166. extern int drm_getmap(struct drm_device *dev, void *data,
  1167.                       struct drm_file *file_priv);
  1168. extern int drm_getclient(struct drm_device *dev, void *data,
  1169.                          struct drm_file *file_priv);
  1170. extern int drm_getstats(struct drm_device *dev, void *data,
  1171.                         struct drm_file *file_priv);
  1172. extern int drm_getcap(struct drm_device *dev, void *data,
  1173.                       struct drm_file *file_priv);
  1174. extern int drm_setversion(struct drm_device *dev, void *data,
  1175.                           struct drm_file *file_priv);
  1176. extern int drm_noop(struct drm_device *dev, void *data,
  1177.                     struct drm_file *file_priv);
  1178.  
  1179.                                 /* Context IOCTL support (drm_context.h) */
  1180. extern int drm_resctx(struct drm_device *dev, void *data,
  1181.                       struct drm_file *file_priv);
  1182. extern int drm_addctx(struct drm_device *dev, void *data,
  1183.                       struct drm_file *file_priv);
  1184. extern int drm_getctx(struct drm_device *dev, void *data,
  1185.                       struct drm_file *file_priv);
  1186. extern int drm_switchctx(struct drm_device *dev, void *data,
  1187.                          struct drm_file *file_priv);
  1188. extern int drm_newctx(struct drm_device *dev, void *data,
  1189.                       struct drm_file *file_priv);
  1190. extern int drm_rmctx(struct drm_device *dev, void *data,
  1191.                      struct drm_file *file_priv);
  1192.  
  1193. extern int drm_ctxbitmap_init(struct drm_device *dev);
  1194. extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
  1195. extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
  1196.  
  1197. extern int drm_setsareactx(struct drm_device *dev, void *data,
  1198.                            struct drm_file *file_priv);
  1199. extern int drm_getsareactx(struct drm_device *dev, void *data,
  1200.                            struct drm_file *file_priv);
  1201.  
  1202.                                 /* Authentication IOCTL support (drm_auth.h) */
  1203. extern int drm_getmagic(struct drm_device *dev, void *data,
  1204.                         struct drm_file *file_priv);
  1205. extern int drm_authmagic(struct drm_device *dev, void *data,
  1206.                          struct drm_file *file_priv);
  1207. extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
  1208.  
  1209. /* Cache management (drm_cache.c) */
  1210. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  1211. void drm_clflush_sg(struct sg_table *st);
  1212. void drm_clflush_virt_range(char *addr, unsigned long length);
  1213.  
  1214.                                 /* Locking IOCTL support (drm_lock.h) */
  1215. extern int drm_lock(struct drm_device *dev, void *data,
  1216.                     struct drm_file *file_priv);
  1217. extern int drm_unlock(struct drm_device *dev, void *data,
  1218.                       struct drm_file *file_priv);
  1219. extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
  1220. extern void drm_idlelock_take(struct drm_lock_data *lock_data);
  1221. extern void drm_idlelock_release(struct drm_lock_data *lock_data);
  1222.  
  1223. /*
  1224.  * These are exported to drivers so that they can implement fencing using
  1225.  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  1226.  */
  1227.  
  1228. extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
  1229.  
  1230.                                 /* Buffer management support (drm_bufs.h) */
  1231. extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
  1232. extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
  1233. extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
  1234.                       unsigned int size, enum drm_map_type type,
  1235.                       enum drm_map_flags flags, struct drm_local_map **map_ptr);
  1236. extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
  1237.                             struct drm_file *file_priv);
  1238. extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
  1239. extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
  1240. extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
  1241.                            struct drm_file *file_priv);
  1242. extern int drm_addbufs(struct drm_device *dev, void *data,
  1243.                        struct drm_file *file_priv);
  1244. extern int drm_infobufs(struct drm_device *dev, void *data,
  1245.                         struct drm_file *file_priv);
  1246. extern int drm_markbufs(struct drm_device *dev, void *data,
  1247.                         struct drm_file *file_priv);
  1248. extern int drm_freebufs(struct drm_device *dev, void *data,
  1249.                         struct drm_file *file_priv);
  1250. extern int drm_mapbufs(struct drm_device *dev, void *data,
  1251.                        struct drm_file *file_priv);
  1252. extern int drm_dma_ioctl(struct drm_device *dev, void *data,
  1253.                          struct drm_file *file_priv);
  1254.  
  1255.                                 /* DMA support (drm_dma.h) */
  1256. extern int drm_legacy_dma_setup(struct drm_device *dev);
  1257. extern void drm_legacy_dma_takedown(struct drm_device *dev);
  1258. extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
  1259. extern void drm_core_reclaim_buffers(struct drm_device *dev,
  1260.                                      struct drm_file *filp);
  1261.  
  1262.                                 /* IRQ support (drm_irq.h) */
  1263. extern int drm_control(struct drm_device *dev, void *data,
  1264.                        struct drm_file *file_priv);
  1265. extern int drm_irq_install(struct drm_device *dev);
  1266. extern int drm_irq_uninstall(struct drm_device *dev);
  1267.  
  1268. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  1269. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  1270.                            struct drm_file *filp);
  1271. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  1272. extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
  1273.                                      struct timeval *vblanktime);
  1274. extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
  1275.                                      struct drm_pending_vblank_event *e);
  1276. extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
  1277. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1278. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1279. extern void drm_vblank_off(struct drm_device *dev, int crtc);
  1280. extern void drm_vblank_cleanup(struct drm_device *dev);
  1281. extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
  1282.                                      struct timeval *tvblank, unsigned flags);
  1283. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  1284.                                                  int crtc, int *max_error,
  1285.                                                  struct timeval *vblank_time,
  1286.                                                  unsigned flags,
  1287.                                                  struct drm_crtc *refcrtc);
  1288. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
  1289.  
  1290. extern bool
  1291. drm_mode_parse_command_line_for_connector(const char *mode_option,
  1292.                                           struct drm_connector *connector,
  1293.                                           struct drm_cmdline_mode *mode);
  1294.  
  1295. extern struct drm_display_mode *
  1296. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  1297.                                   struct drm_cmdline_mode *cmd);
  1298.  
  1299. extern int drm_display_mode_from_videomode(const struct videomode *vm,
  1300.                                            struct drm_display_mode *dmode);
  1301. extern int of_get_drm_display_mode(struct device_node *np,
  1302.                                    struct drm_display_mode *dmode,
  1303.                                    int index);
  1304.  
  1305. /* Modesetting support */
  1306. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1307. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1308. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1309.                            struct drm_file *file_priv);
  1310.  
  1311.                                 /* AGP/GART support (drm_agpsupport.h) */
  1312.  
  1313.                                 /* Stub support (drm_stub.h) */
  1314. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1315.                                struct drm_file *file_priv);
  1316. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1317.                                 struct drm_file *file_priv);
  1318. struct drm_master *drm_master_create(struct drm_minor *minor);
  1319. extern struct drm_master *drm_master_get(struct drm_master *master);
  1320. extern void drm_master_put(struct drm_master **master);
  1321.  
  1322. extern void drm_put_dev(struct drm_device *dev);
  1323. extern int drm_put_minor(struct drm_minor **minor);
  1324. extern void drm_unplug_dev(struct drm_device *dev);
  1325. extern unsigned int drm_debug;
  1326. extern unsigned int drm_rnodes;
  1327.  
  1328. #if 0
  1329. extern unsigned int drm_vblank_offdelay;
  1330. extern unsigned int drm_timestamp_precision;
  1331. extern unsigned int drm_timestamp_monotonic;
  1332.  
  1333. extern struct class *drm_class;
  1334. extern struct dentry *drm_debugfs_root;
  1335.  
  1336. extern struct idr drm_minors_idr;
  1337.  
  1338. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1339.  
  1340.                                 /* Debugfs support */
  1341. #if defined(CONFIG_DEBUG_FS)
  1342. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1343.                             struct dentry *root);
  1344. extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
  1345.                                     struct dentry *root, struct drm_minor *minor);
  1346. extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
  1347.                                     struct drm_minor *minor);
  1348. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1349. #endif
  1350.  
  1351.                                 /* Info file support */
  1352. extern int drm_name_info(struct seq_file *m, void *data);
  1353. extern int drm_vm_info(struct seq_file *m, void *data);
  1354. extern int drm_bufs_info(struct seq_file *m, void *data);
  1355. extern int drm_vblank_info(struct seq_file *m, void *data);
  1356. extern int drm_clients_info(struct seq_file *m, void* data);
  1357. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1358.  
  1359. #if DRM_DEBUG_CODE
  1360. extern int drm_vma_info(struct seq_file *m, void *data);
  1361. #endif
  1362.  
  1363.                                 /* Scatter Gather Support (drm_scatter.h) */
  1364. extern void drm_legacy_sg_cleanup(struct drm_device *dev);
  1365. extern int drm_sg_alloc(struct drm_device *dev, void *data,
  1366.                         struct drm_file *file_priv);
  1367. extern int drm_sg_free(struct drm_device *dev, void *data,
  1368.                        struct drm_file *file_priv);
  1369.  
  1370.                                /* ATI PCIGART support (ati_pcigart.h) */
  1371. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1372.                                 struct drm_ati_pcigart_info * gart_info);
  1373. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1374.                                    struct drm_ati_pcigart_info * gart_info);
  1375. #endif
  1376.  
  1377. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1378.                                        size_t align);
  1379. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1380. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1381.  
  1382. #if 0
  1383.                                /* sysfs support (drm_sysfs.c) */
  1384. struct drm_sysfs_class;
  1385. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1386. extern void drm_sysfs_destroy(void);
  1387. extern int drm_sysfs_device_add(struct drm_minor *minor);
  1388. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1389. extern void drm_sysfs_device_remove(struct drm_minor *minor);
  1390. extern int drm_sysfs_connector_add(struct drm_connector *connector);
  1391. extern void drm_sysfs_connector_remove(struct drm_connector *connector);
  1392. #endif
  1393.  
  1394. /* Graphics Execution Manager library functions (drm_gem.c) */
  1395. int drm_gem_init(struct drm_device *dev);
  1396. void drm_gem_destroy(struct drm_device *dev);
  1397. void drm_gem_object_release(struct drm_gem_object *obj);
  1398. void drm_gem_object_free(struct kref *kref);
  1399. struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
  1400.                                             size_t size);
  1401. int drm_gem_object_init(struct drm_device *dev,
  1402.                         struct drm_gem_object *obj, size_t size);
  1403. void drm_gem_private_object_init(struct drm_device *dev,
  1404.                         struct drm_gem_object *obj, size_t size);
  1405. void drm_gem_vm_open(struct vm_area_struct *vma);
  1406. void drm_gem_vm_close(struct vm_area_struct *vma);
  1407. int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
  1408.                      struct vm_area_struct *vma);
  1409. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1410.  
  1411. #include <drm/drm_global.h>
  1412.  
  1413. static inline void
  1414. drm_gem_object_reference(struct drm_gem_object *obj)
  1415. {
  1416.         kref_get(&obj->refcount);
  1417. }
  1418.  
  1419. static inline void
  1420. drm_gem_object_unreference(struct drm_gem_object *obj)
  1421. {
  1422.         if (obj != NULL)
  1423.                 kref_put(&obj->refcount, drm_gem_object_free);
  1424. }
  1425.  
  1426. static inline void
  1427. drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
  1428. {
  1429.         if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
  1430.                 struct drm_device *dev = obj->dev;
  1431.  
  1432.                 mutex_lock(&dev->struct_mutex);
  1433.                 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
  1434.                         drm_gem_object_free(&obj->refcount);
  1435.                 mutex_unlock(&dev->struct_mutex);
  1436.         }
  1437. }
  1438.  
  1439. int drm_gem_handle_create_tail(struct drm_file *file_priv,
  1440.                                struct drm_gem_object *obj,
  1441.                                u32 *handlep);
  1442. int drm_gem_handle_create(struct drm_file *file_priv,
  1443.                           struct drm_gem_object *obj,
  1444.                           u32 *handlep);
  1445. int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
  1446.  
  1447.  
  1448. void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
  1449. int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
  1450. int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
  1451.  
  1452. struct page **drm_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  1453. void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
  1454.                 bool dirty, bool accessed);
  1455.  
  1456. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1457.                                              struct drm_file *filp,
  1458.                                              u32 handle);
  1459. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1460.                         struct drm_file *file_priv);
  1461. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1462.                         struct drm_file *file_priv);
  1463. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1464.                        struct drm_file *file_priv);
  1465. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1466. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1467.  
  1468. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1469. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1470. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1471.  
  1472. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1473.                                                          unsigned int token)
  1474. {
  1475.         struct drm_map_list *_entry;
  1476.         list_for_each_entry(_entry, &dev->maplist, head)
  1477.             if (_entry->user_token == token)
  1478.                 return _entry->map;
  1479.         return NULL;
  1480. }
  1481.  
  1482. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1483. {
  1484. }
  1485.  
  1486. //#include <drm/drm_mem_util.h>
  1487.  
  1488. extern int drm_fill_in_dev(struct drm_device *dev,
  1489.                            const struct pci_device_id *ent,
  1490.                            struct drm_driver *driver);
  1491. int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
  1492. /*@}*/
  1493.  
  1494.  
  1495.  
  1496. extern int drm_get_pci_dev(struct pci_dev *pdev,
  1497.                            const struct pci_device_id *ent,
  1498.                            struct drm_driver *driver);
  1499.  
  1500. #define DRM_PCIE_SPEED_25 1
  1501. #define DRM_PCIE_SPEED_50 2
  1502. #define DRM_PCIE_SPEED_80 4
  1503.  
  1504. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  1505.  
  1506. static __inline__ int drm_device_is_agp(struct drm_device *dev)
  1507. {
  1508.     return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1509. }
  1510.  
  1511. static __inline__ int drm_device_is_pcie(struct drm_device *dev)
  1512. {
  1513.     return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  1514. }
  1515. #endif                          /* __KERNEL__ */
  1516.  
  1517. #define drm_sysfs_connector_add(connector)
  1518. #define drm_sysfs_connector_remove(connector)
  1519.  
  1520. #define LFB_SIZE 0xC00000
  1521. extern struct drm_device *main_device;
  1522. extern struct drm_file *drm_file_handlers[256];
  1523.  
  1524. #endif
  1525.