Subversion Repositories Kolibri OS

Rev

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