Subversion Repositories Kolibri OS

Rev

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