Subversion Repositories Kolibri OS

Rev

Rev 3255 | Rev 3297 | 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 2          /**< 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. #endif
  431.  
  432. /** File private data */
  433. struct drm_file {
  434.         struct list_head lhead;
  435.         unsigned long lock_count;
  436.  
  437.         /** Mapping of mm object handles to object pointers. */
  438.         struct idr object_idr;
  439.         /** Lock for synchronization of access to object_idr. */
  440.         spinlock_t table_lock;
  441.  
  442.         void *driver_priv;
  443.  
  444.         struct list_head fbs;
  445.  
  446.         wait_queue_head_t event_wait;
  447.         struct list_head event_list;
  448.         int event_space;
  449. };
  450.  
  451. #if 0
  452. /** Wait queue */
  453. struct drm_queue {
  454.         atomic_t use_count;             /**< Outstanding uses (+1) */
  455.         atomic_t finalization;          /**< Finalization in progress */
  456.         atomic_t block_count;           /**< Count of processes waiting */
  457.         atomic_t block_read;            /**< Queue blocked for reads */
  458.         wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
  459.         atomic_t block_write;           /**< Queue blocked for writes */
  460.         wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
  461.         atomic_t total_queued;          /**< Total queued statistic */
  462.         atomic_t total_flushed;         /**< Total flushes statistic */
  463.         atomic_t total_locks;           /**< Total locks statistics */
  464.         enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
  465.         struct drm_waitlist waitlist;   /**< Pending buffers */
  466.         wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
  467. };
  468.  
  469. /**
  470.  * Lock data.
  471.  */
  472. struct drm_lock_data {
  473.         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
  474.         /** Private of lock holder's file (NULL=kernel) */
  475.         struct drm_file *file_priv;
  476.         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
  477.         unsigned long lock_time;        /**< Time of last lock in jiffies */
  478.         spinlock_t spinlock;
  479.         uint32_t kernel_waiters;
  480.         uint32_t user_waiters;
  481.         int idle_has_lock;
  482. };
  483.  
  484. /**
  485.  * DMA data.
  486.  */
  487. struct drm_device_dma {
  488.  
  489.         struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
  490.         int buf_count;                  /**< total number of buffers */
  491.         struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
  492.         int seg_count;
  493.         int page_count;                 /**< number of pages */
  494.         unsigned long *pagelist;        /**< page list */
  495.         unsigned long byte_count;
  496.         enum {
  497.                 _DRM_DMA_USE_AGP = 0x01,
  498.                 _DRM_DMA_USE_SG = 0x02,
  499.                 _DRM_DMA_USE_FB = 0x04,
  500.                 _DRM_DMA_USE_PCI_RO = 0x08
  501.         } flags;
  502.  
  503. };
  504.  
  505. /**
  506.  * AGP memory entry.  Stored as a doubly linked list.
  507.  */
  508. struct drm_agp_mem {
  509.         unsigned long handle;           /**< handle */
  510.         DRM_AGP_MEM *memory;
  511.         unsigned long bound;            /**< address */
  512.         int pages;
  513.         struct list_head head;
  514. };
  515.  
  516. /**
  517.  * AGP data.
  518.  *
  519.  * \sa drm_agp_init() and drm_device::agp.
  520.  */
  521. struct drm_agp_head {
  522.         DRM_AGP_KERN agp_info;          /**< AGP device information */
  523.         struct list_head memory;
  524.         unsigned long mode;             /**< AGP mode */
  525.         struct agp_bridge_data *bridge;
  526.         int enabled;                    /**< whether the AGP bus as been enabled */
  527.         int acquired;                   /**< whether the AGP device has been acquired */
  528.         unsigned long base;
  529.         int agp_mtrr;
  530.         int cant_use_aperture;
  531.         unsigned long page_mask;
  532. };
  533.  
  534. /**
  535.  * Scatter-gather memory.
  536.  */
  537. struct drm_sg_mem {
  538.         unsigned long handle;
  539.         void *virtual;
  540.         int pages;
  541.         struct page **pagelist;
  542.         dma_addr_t *busaddr;
  543. };
  544.  
  545. struct drm_sigdata {
  546.         int context;
  547.         struct drm_hw_lock *lock;
  548. };
  549.  
  550. #endif
  551.  
  552.  
  553. /**
  554.  * Kernel side of a mapping
  555.  */
  556. struct drm_local_map {
  557.         resource_size_t offset;  /**< Requested physical address (0 for SAREA)*/
  558.         unsigned long size;      /**< Requested physical size (bytes) */
  559.         enum drm_map_type type;  /**< Type of memory to map */
  560.         enum drm_map_flags flags;        /**< Flags */
  561.         void *handle;            /**< User-space: "Handle" to pass to mmap() */
  562.                                  /**< Kernel-space: kernel-virtual address */
  563.         int mtrr;                /**< MTRR slot used */
  564. };
  565.  
  566. typedef struct drm_local_map drm_local_map_t;
  567.  
  568. #if 0
  569. /**
  570.  * Mappings list
  571.  */
  572. struct drm_map_list {
  573.         struct list_head head;          /**< list head */
  574.         struct drm_hash_item hash;
  575.         struct drm_local_map *map;      /**< mapping */
  576.         uint64_t user_token;
  577.         struct drm_master *master;
  578.         struct drm_mm_node *file_offset_node;   /**< fake offset */
  579. };
  580.  
  581. /**
  582.  * Context handle list
  583.  */
  584. struct drm_ctx_list {
  585.         struct list_head head;          /**< list head */
  586.         drm_context_t handle;           /**< context handle */
  587.         struct drm_file *tag;           /**< associated fd private data */
  588. };
  589.  
  590. /* location of GART table */
  591. #define DRM_ATI_GART_MAIN 1
  592. #define DRM_ATI_GART_FB   2
  593.  
  594. #define DRM_ATI_GART_PCI 1
  595. #define DRM_ATI_GART_PCIE 2
  596. #define DRM_ATI_GART_IGP 3
  597.  
  598. struct drm_ati_pcigart_info {
  599.         int gart_table_location;
  600.         int gart_reg_if;
  601.         void *addr;
  602.         dma_addr_t bus_addr;
  603.         dma_addr_t table_mask;
  604.         struct drm_dma_handle *table_handle;
  605.         struct drm_local_map mapping;
  606.         int table_size;
  607. };
  608.  
  609. /**
  610.  * GEM specific mm private for tracking GEM objects
  611.  */
  612. struct drm_gem_mm {
  613.         struct drm_mm offset_manager;   /**< Offset mgmt for buffer objects */
  614.         struct drm_open_hash offset_hash; /**< User token hash table for maps */
  615. };
  616.  
  617. #endif
  618.  
  619. /**
  620.  * This structure defines the drm_mm memory object, which will be used by the
  621.  * DRM for its buffer objects.
  622.  */
  623. struct drm_gem_object {
  624.         /** Reference count of this object */
  625.         struct kref refcount;
  626.  
  627.         /** Handle count of this object. Each handle also holds a reference */
  628.         atomic_t handle_count; /* number of handles on this object */
  629.  
  630.         /** Related drm device */
  631.         struct drm_device *dev;
  632.  
  633.         /** File representing the shmem storage */
  634.         struct file *filp;
  635.  
  636.         /* Mapping info for this object */
  637.  
  638.         /**
  639.          * Size of the object, in bytes.  Immutable over the object's
  640.          * lifetime.
  641.          */
  642.         size_t size;
  643.  
  644.         /**
  645.          * Global name for this object, starts at 1. 0 means unnamed.
  646.          * Access is covered by the object_name_lock in the related drm_device
  647.          */
  648.         int name;
  649.  
  650.         /**
  651.          * Memory domains. These monitor which caches contain read/write data
  652.          * related to the object. When transitioning from one set of domains
  653.          * to another, the driver is called to ensure that caches are suitably
  654.          * flushed and invalidated
  655.          */
  656.         uint32_t read_domains;
  657.         uint32_t write_domain;
  658.  
  659.         /**
  660.          * While validating an exec operation, the
  661.          * new read/write domain values are computed here.
  662.          * They will be transferred to the above values
  663.          * at the point that any cache flushing occurs
  664.          */
  665.         uint32_t pending_read_domains;
  666.         uint32_t pending_write_domain;
  667.  
  668.         void *driver_private;
  669. };
  670.  
  671. #include <drm/drm_crtc.h>
  672.  
  673. /* per-master structure */
  674. struct drm_master {
  675.  
  676.         struct kref refcount; /* refcount for this master */
  677.  
  678.         struct list_head head; /**< each minor contains a list of masters */
  679.         struct drm_minor *minor; /**< link back to minor we are a master for */
  680.  
  681.         char *unique;                   /**< Unique identifier: e.g., busid */
  682.         int unique_len;                 /**< Length of unique field */
  683.         int unique_size;                /**< amount allocated */
  684.  
  685.         int blocked;                    /**< Blocked due to VC switch? */
  686.  
  687.         /** \name Authentication */
  688.         /*@{ */
  689. //   struct drm_open_hash magiclist;
  690. //   struct list_head magicfree;
  691.         /*@} */
  692.  
  693. //   struct drm_lock_data lock;  /**< Information on hardware lock */
  694.  
  695.         void *driver_priv; /**< Private structure for driver to use */
  696. };
  697.  
  698. #if 0
  699.  
  700. /* Size of ringbuffer for vblank timestamps. Just double-buffer
  701.  * in initial implementation.
  702.  */
  703. #define DRM_VBLANKTIME_RBSIZE 2
  704.  
  705. /* Flags and return codes for get_vblank_timestamp() driver function. */
  706. #define DRM_CALLED_FROM_VBLIRQ 1
  707. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  708. #define DRM_VBLANKTIME_INVBL             (1 << 1)
  709.  
  710. /* get_scanout_position() return flags */
  711. #define DRM_SCANOUTPOS_VALID        (1 << 0)
  712. #define DRM_SCANOUTPOS_INVBL        (1 << 1)
  713. #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
  714.  
  715. struct drm_bus {
  716.         int bus_type;
  717.         int (*get_irq)(struct drm_device *dev);
  718.         const char *(*get_name)(struct drm_device *dev);
  719.         int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  720.         int (*set_unique)(struct drm_device *dev, struct drm_master *master,
  721.                           struct drm_unique *unique);
  722.         int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
  723.         /* hooks that are for PCI */
  724.         int (*agp_init)(struct drm_device *dev);
  725.  
  726. };
  727.  
  728. /**
  729.  * DRM driver structure. This structure represent the common code for
  730.  * a family of cards. There will one drm_device for each card present
  731.  * in this family
  732.  */
  733. struct drm_driver {
  734.         int (*load) (struct drm_device *, unsigned long flags);
  735.         int (*firstopen) (struct drm_device *);
  736.         int (*open) (struct drm_device *, struct drm_file *);
  737.         void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  738.         void (*postclose) (struct drm_device *, struct drm_file *);
  739.         void (*lastclose) (struct drm_device *);
  740.         int (*unload) (struct drm_device *);
  741.         int (*suspend) (struct drm_device *, pm_message_t state);
  742.         int (*resume) (struct drm_device *);
  743.         int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  744.         int (*dma_quiescent) (struct drm_device *);
  745.         int (*context_dtor) (struct drm_device *dev, int context);
  746.  
  747.         /**
  748.          * get_vblank_counter - get raw hardware vblank counter
  749.          * @dev: DRM device
  750.          * @crtc: counter to fetch
  751.          *
  752.          * Driver callback for fetching a raw hardware vblank counter for @crtc.
  753.          * If a device doesn't have a hardware counter, the driver can simply
  754.          * return the value of drm_vblank_count. The DRM core will account for
  755.          * missed vblank events while interrupts where disabled based on system
  756.          * timestamps.
  757.          *
  758.          * Wraparound handling and loss of events due to modesetting is dealt
  759.          * with in the DRM core code.
  760.          *
  761.          * RETURNS
  762.          * Raw vblank counter value.
  763.          */
  764.         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  765.  
  766.         /**
  767.          * enable_vblank - enable vblank interrupt events
  768.          * @dev: DRM device
  769.          * @crtc: which irq to enable
  770.          *
  771.          * Enable vblank interrupts for @crtc.  If the device doesn't have
  772.          * a hardware vblank counter, this routine should be a no-op, since
  773.          * interrupts will have to stay on to keep the count accurate.
  774.          *
  775.          * RETURNS
  776.          * Zero on success, appropriate errno if the given @crtc's vblank
  777.          * interrupt cannot be enabled.
  778.          */
  779.         int (*enable_vblank) (struct drm_device *dev, int crtc);
  780.  
  781.         /**
  782.          * disable_vblank - disable vblank interrupt events
  783.          * @dev: DRM device
  784.          * @crtc: which irq to enable
  785.          *
  786.          * Disable vblank interrupts for @crtc.  If the device doesn't have
  787.          * a hardware vblank counter, this routine should be a no-op, since
  788.          * interrupts will have to stay on to keep the count accurate.
  789.          */
  790.         void (*disable_vblank) (struct drm_device *dev, int crtc);
  791.  
  792.         /**
  793.          * Called by \c drm_device_is_agp.  Typically used to determine if a
  794.          * card is really attached to AGP or not.
  795.          *
  796.          * \param dev  DRM device handle
  797.          *
  798.          * \returns
  799.          * One of three values is returned depending on whether or not the
  800.          * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  801.          * (return of 1), or may or may not be AGP (return of 2).
  802.          */
  803.         int (*device_is_agp) (struct drm_device *dev);
  804.  
  805.         /**
  806.          * Called by vblank timestamping code.
  807.          *
  808.          * Return the current display scanout position from a crtc.
  809.          *
  810.          * \param dev  DRM device.
  811.          * \param crtc Id of the crtc to query.
  812.          * \param *vpos Target location for current vertical scanout position.
  813.          * \param *hpos Target location for current horizontal scanout position.
  814.          *
  815.          * Returns vpos as a positive number while in active scanout area.
  816.          * Returns vpos as a negative number inside vblank, counting the number
  817.          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  818.          * until start of active scanout / end of vblank."
  819.          *
  820.          * \return Flags, or'ed together as follows:
  821.          *
  822.          * DRM_SCANOUTPOS_VALID = Query successful.
  823.          * DRM_SCANOUTPOS_INVBL = Inside vblank.
  824.          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  825.          * this flag means that returned position may be offset by a constant
  826.          * but unknown small number of scanlines wrt. real scanout position.
  827.          *
  828.          */
  829.         int (*get_scanout_position) (struct drm_device *dev, int crtc,
  830.                                      int *vpos, int *hpos);
  831.  
  832.         /**
  833.          * Called by \c drm_get_last_vbltimestamp. Should return a precise
  834.          * timestamp when the most recent VBLANK interval ended or will end.
  835.          *
  836.          * Specifically, the timestamp in @vblank_time should correspond as
  837.          * closely as possible to the time when the first video scanline of
  838.          * the video frame after the end of VBLANK will start scanning out,
  839.          * the time immediately after end of the VBLANK interval. If the
  840.          * @crtc is currently inside VBLANK, this will be a time in the future.
  841.          * If the @crtc is currently scanning out a frame, this will be the
  842.          * past start time of the current scanout. This is meant to adhere
  843.          * to the OpenML OML_sync_control extension specification.
  844.          *
  845.          * \param dev dev DRM device handle.
  846.          * \param crtc crtc for which timestamp should be returned.
  847.          * \param *max_error Maximum allowable timestamp error in nanoseconds.
  848.          *                   Implementation should strive to provide timestamp
  849.          *                   with an error of at most *max_error nanoseconds.
  850.          *                   Returns true upper bound on error for timestamp.
  851.          * \param *vblank_time Target location for returned vblank timestamp.
  852.          * \param flags 0 = Defaults, no special treatment needed.
  853.          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  854.          *              irq handler. Some drivers need to apply some workarounds
  855.          *              for gpu-specific vblank irq quirks if flag is set.
  856.          *
  857.          * \returns
  858.          * Zero if timestamping isn't supported in current display mode or a
  859.          * negative number on failure. A positive status code on success,
  860.          * which describes how the vblank_time timestamp was computed.
  861.          */
  862.         int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
  863.                                      int *max_error,
  864.                                      struct timeval *vblank_time,
  865.                                      unsigned flags);
  866.  
  867.         /* these have to be filled in */
  868.  
  869.         irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  870.         void (*irq_preinstall) (struct drm_device *dev);
  871.         int (*irq_postinstall) (struct drm_device *dev);
  872.         void (*irq_uninstall) (struct drm_device *dev);
  873.         void (*set_version) (struct drm_device *dev,
  874.                              struct drm_set_version *sv);
  875.  
  876.         /* Master routines */
  877.         int (*master_create)(struct drm_device *dev, struct drm_master *master);
  878.         void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  879.         /**
  880.          * master_set is called whenever the minor master is set.
  881.          * master_drop is called whenever the minor master is dropped.
  882.          */
  883.  
  884.         int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  885.                           bool from_open);
  886.         void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
  887.                             bool from_release);
  888.  
  889.         int (*debugfs_init)(struct drm_minor *minor);
  890.         void (*debugfs_cleanup)(struct drm_minor *minor);
  891.  
  892.         /**
  893.          * Driver-specific constructor for drm_gem_objects, to set up
  894.          * obj->driver_private.
  895.          *
  896.          * Returns 0 on success.
  897.          */
  898.         int (*gem_init_object) (struct drm_gem_object *obj);
  899.         void (*gem_free_object) (struct drm_gem_object *obj);
  900.         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  901.         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  902.  
  903.         /* prime: */
  904.         /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  905.         int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  906.                                 uint32_t handle, uint32_t flags, int *prime_fd);
  907.         /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  908.         int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  909.                                 int prime_fd, uint32_t *handle);
  910.         /* export GEM -> dmabuf */
  911.         struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  912.                                 struct drm_gem_object *obj, int flags);
  913.         /* import dmabuf -> GEM */
  914.         struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  915.                                 struct dma_buf *dma_buf);
  916.  
  917.         /* vga arb irq handler */
  918.         void (*vgaarb_irq)(struct drm_device *dev, bool state);
  919.  
  920.         /* dumb alloc support */
  921.         int (*dumb_create)(struct drm_file *file_priv,
  922.                            struct drm_device *dev,
  923.                            struct drm_mode_create_dumb *args);
  924.         int (*dumb_map_offset)(struct drm_file *file_priv,
  925.                                struct drm_device *dev, uint32_t handle,
  926.                                uint64_t *offset);
  927.         int (*dumb_destroy)(struct drm_file *file_priv,
  928.                             struct drm_device *dev,
  929.                             uint32_t handle);
  930.  
  931.         /* Driver private ops for this object */
  932.         const struct vm_operations_struct *gem_vm_ops;
  933.  
  934.         int major;
  935.         int minor;
  936.         int patchlevel;
  937.         char *name;
  938.         char *desc;
  939.         char *date;
  940.  
  941.         u32 driver_features;
  942.         int dev_priv_size;
  943.         struct drm_ioctl_desc *ioctls;
  944.         int num_ioctls;
  945.         const struct file_operations *fops;
  946.         union {
  947.                 struct pci_driver *pci;
  948.                 struct platform_device *platform_device;
  949.                 struct usb_driver *usb;
  950.         } kdriver;
  951.         struct drm_bus *bus;
  952.  
  953.         /* List of devices hanging off this driver */
  954.         struct list_head device_list;
  955. };
  956.  
  957. #endif
  958.  
  959. #define DRM_IRQ_ARGS            int irq, void *arg
  960.  
  961. struct drm_driver {
  962.         int (*open) (struct drm_device *, struct drm_file *);
  963.  
  964.     irqreturn_t (*irq_handler) (DRM_IRQ_ARGS);
  965.     void (*irq_preinstall) (struct drm_device *dev);
  966.     int (*irq_postinstall) (struct drm_device *dev);
  967.  
  968.         int (*gem_init_object) (struct drm_gem_object *obj);
  969.         void (*gem_free_object) (struct drm_gem_object *obj);
  970.         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  971.         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  972. };
  973.  
  974.  
  975. #define DRM_MINOR_UNASSIGNED 0
  976. #define DRM_MINOR_LEGACY 1
  977. #define DRM_MINOR_CONTROL 2
  978. #define DRM_MINOR_RENDER 3
  979.  
  980.  
  981. /**
  982.  * debugfs node list. This structure represents a debugfs file to
  983.  * be created by the drm core
  984.  */
  985. struct drm_debugfs_list {
  986.         const char *name; /** file name */
  987. //   int (*show)(struct seq_file*, void*); /** show callback */
  988.         u32 driver_features; /**< Required driver features for this entry */
  989. };
  990.  
  991. /**
  992.  * debugfs node structure. This structure represents a debugfs file.
  993.  */
  994. struct drm_debugfs_node {
  995.         struct list_head list;
  996.         struct drm_minor *minor;
  997.         struct drm_debugfs_list *debugfs_ent;
  998.         struct dentry *dent;
  999. };
  1000.  
  1001. /**
  1002.  * Info file list entry. This structure represents a debugfs or proc file to
  1003.  * be created by the drm core
  1004.  */
  1005. struct drm_info_list {
  1006.         const char *name; /** file name */
  1007. //   int (*show)(struct seq_file*, void*); /** show callback */
  1008.         u32 driver_features; /**< Required driver features for this entry */
  1009.         void *data;
  1010. };
  1011.  
  1012. /**
  1013.  * debugfs node structure. This structure represents a debugfs file.
  1014.  */
  1015. struct drm_info_node {
  1016.         struct list_head list;
  1017.         struct drm_minor *minor;
  1018.         struct drm_info_list *info_ent;
  1019.         struct dentry *dent;
  1020. };
  1021.  
  1022. /**
  1023.  * DRM minor structure. This structure represents a drm minor number.
  1024.  */
  1025. struct drm_minor {
  1026.         int index;                      /**< Minor device number */
  1027.         int type;                       /**< Control or render */
  1028. //   dev_t device;           /**< Device number for mknod */
  1029. //   struct device kdev;     /**< Linux device */
  1030.         struct drm_device *dev;
  1031.  
  1032. //   struct proc_dir_entry *proc_root;  /**< proc directory entry */
  1033. //   struct drm_info_node proc_nodes;
  1034. //   struct dentry *debugfs_root;
  1035. //   struct drm_info_node debugfs_nodes;
  1036.  
  1037.     struct drm_master *master; /* currently active master for this node */
  1038. //   struct list_head master_list;
  1039. //   struct drm_mode_group mode_group;
  1040. };
  1041.  
  1042. /* mode specified on the command line */
  1043. struct drm_cmdline_mode {
  1044.         bool specified;
  1045.         bool refresh_specified;
  1046.         bool bpp_specified;
  1047.         int xres, yres;
  1048.         int bpp;
  1049.         int refresh;
  1050.         bool rb;
  1051.         bool interlace;
  1052.         bool cvt;
  1053.         bool margins;
  1054.         enum drm_connector_force force;
  1055. };
  1056.  
  1057.  
  1058.  
  1059. /**
  1060.  * DRM device structure. This structure represent a complete card that
  1061.  * may contain multiple heads.
  1062.  */
  1063. struct drm_device {
  1064.         struct list_head driver_item;   /**< list of devices per driver */
  1065.         char *devname;                  /**< For /proc/interrupts */
  1066.         int if_version;                 /**< Highest interface version set */
  1067.  
  1068.         /** \name Locks */
  1069.         /*@{ */
  1070.     spinlock_t count_lock;      /**< For inuse, drm_device::open_count, drm_device::buf_use */
  1071.         struct mutex struct_mutex;      /**< For others */
  1072.         /*@} */
  1073.  
  1074.         /** \name Usage Counters */
  1075.         /*@{ */
  1076.         int open_count;                 /**< Outstanding files open */
  1077.    atomic_t ioctl_count;       /**< Outstanding IOCTLs pending */
  1078.    atomic_t vma_count;     /**< Outstanding vma areas open */
  1079.         int buf_use;                    /**< Buffers in use -- cannot alloc */
  1080.    atomic_t buf_alloc;     /**< Buffer allocation in progress */
  1081.         /*@} */
  1082.  
  1083.         /** \name Performance counters */
  1084.         /*@{ */
  1085.         unsigned long counters;
  1086. //   enum drm_stat_type types[15];
  1087.    atomic_t counts[15];
  1088.         /*@} */
  1089.  
  1090.         struct list_head filelist;
  1091.  
  1092.         /** \name Memory management */
  1093.         /*@{ */
  1094.         struct list_head maplist;       /**< Linked list of regions */
  1095.         int map_count;                  /**< Number of mappable regions */
  1096. //   struct drm_open_hash map_hash;  /**< User token hash table for maps */
  1097.  
  1098.         /** \name Context handle management */
  1099.         /*@{ */
  1100.         struct list_head ctxlist;       /**< Linked list of context handles */
  1101.         int ctx_count;                  /**< Number of context handles */
  1102.         struct mutex ctxlist_mutex;     /**< For ctxlist */
  1103.  
  1104.         struct idr ctx_idr;
  1105.  
  1106.         struct list_head vmalist;       /**< List of vmas (for debugging) */
  1107.  
  1108.         /*@} */
  1109.  
  1110.         /** \name DMA support */
  1111.         /*@{ */
  1112. //   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
  1113.         /*@} */
  1114.  
  1115.         /** \name Context support */
  1116.         /*@{ */
  1117.         int irq_enabled;                /**< True if irq handler is enabled */
  1118.         __volatile__ long context_flag; /**< Context swapping flag */
  1119.         __volatile__ long interrupt_flag; /**< Interruption handler flag */
  1120.         __volatile__ long dma_flag;     /**< DMA dispatch flag */
  1121. //   wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
  1122.         int last_checked;               /**< Last context checked for DMA */
  1123.         int last_context;               /**< Last current context */
  1124.         unsigned long last_switch;      /**< jiffies at last context switch */
  1125.         /*@} */
  1126.  
  1127. //   struct work_struct work;
  1128.         /** \name VBLANK IRQ support */
  1129.         /*@{ */
  1130.  
  1131.         /*
  1132.          * At load time, disabling the vblank interrupt won't be allowed since
  1133.          * old clients may not call the modeset ioctl and therefore misbehave.
  1134.          * Once the modeset ioctl *has* been called though, we can safely
  1135.          * disable them when unused.
  1136.          */
  1137.         int vblank_disable_allowed;
  1138.  
  1139. //   wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
  1140.    atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
  1141.         struct timeval *_vblank_time;   /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
  1142.         spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
  1143.    spinlock_t vbl_lock;
  1144.    atomic_t *vblank_refcount;      /* number of users of vblank interruptsper crtc */
  1145.         u32 *last_vblank;               /* protected by dev->vbl_lock, used */
  1146.                                         /* for wraparound handling */
  1147.         int *vblank_enabled;            /* so we don't call enable more than
  1148.                                            once per disable */
  1149.         int *vblank_inmodeset;          /* Display driver is setting mode */
  1150.         u32 *last_vblank_wait;          /* Last vblank seqno waited per CRTC */
  1151. //   struct timer_list vblank_disable_timer;
  1152.  
  1153.         u32 max_vblank_count;           /**< size of vblank counter register */
  1154.  
  1155.         /**
  1156.          * List of events
  1157.          */
  1158.         struct list_head vblank_event_list;
  1159.         spinlock_t event_lock;
  1160.  
  1161.         /*@} */
  1162. //   cycles_t ctx_start;
  1163. //   cycles_t lck_start;
  1164.  
  1165. //   struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
  1166. //   wait_queue_head_t buf_readers;  /**< Processes waiting to read */
  1167. //   wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
  1168.  
  1169. //   struct drm_agp_head *agp;   /**< AGP data */
  1170.  
  1171.         struct device *dev;             /**< Device structure */
  1172.         struct pci_dev *pdev;           /**< PCI device structure */
  1173.         int pci_vendor;                 /**< PCI vendor id */
  1174.         int pci_device;                 /**< PCI device id */
  1175.         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
  1176.         void *dev_private;              /**< device private data */
  1177.         void *mm_private;
  1178.     struct address_space *dev_mapping;
  1179. //   struct drm_sigdata sigdata;    /**< For block_all_signals */
  1180. //   sigset_t sigmask;
  1181.  
  1182.         struct drm_driver *driver;
  1183. //   struct drm_local_map *agp_buffer_map;
  1184. //   unsigned int agp_buffer_token;
  1185. //   struct drm_minor *control;      /**< Control node for card */
  1186.    struct drm_minor *primary;      /**< render type primary screen head */
  1187.  
  1188.         struct drm_mode_config mode_config;     /**< Current mode config */
  1189.  
  1190.         /** \name GEM information */
  1191.         /*@{ */
  1192.    spinlock_t object_name_lock;
  1193.         struct idr object_name_idr;
  1194.         /*@} */
  1195.         int switch_power_state;
  1196.  
  1197.         atomic_t unplugged; /* device has been unplugged or gone away */
  1198. };
  1199.  
  1200. #define DRM_SWITCH_POWER_ON 0
  1201. #define DRM_SWITCH_POWER_OFF 1
  1202. #define DRM_SWITCH_POWER_CHANGING 2
  1203.  
  1204.  
  1205. static inline int drm_dev_to_irq(struct drm_device *dev)
  1206. {
  1207.         return dev->pdev->irq;
  1208. }
  1209.  
  1210. #if 0
  1211.  
  1212. #ifdef __alpha__
  1213. #define drm_get_pci_domain(dev) dev->hose->index
  1214. #else
  1215. #define drm_get_pci_domain(dev) 0
  1216. #endif
  1217.  
  1218. #if __OS_HAS_AGP
  1219. static inline int drm_core_has_AGP(struct drm_device *dev)
  1220. {
  1221.         return drm_core_check_feature(dev, DRIVER_USE_AGP);
  1222. }
  1223. #else
  1224. #define drm_core_has_AGP(dev) (0)
  1225. #endif
  1226.  
  1227. #if __OS_HAS_MTRR
  1228. static inline int drm_core_has_MTRR(struct drm_device *dev)
  1229. {
  1230.         return drm_core_check_feature(dev, DRIVER_USE_MTRR);
  1231. }
  1232.  
  1233. #define DRM_MTRR_WC             MTRR_TYPE_WRCOMB
  1234.  
  1235. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  1236.                                unsigned int flags)
  1237. {
  1238.         return mtrr_add(offset, size, flags, 1);
  1239. }
  1240.  
  1241. static inline int drm_mtrr_del(int handle, unsigned long offset,
  1242.                                unsigned long size, unsigned int flags)
  1243. {
  1244.         return mtrr_del(handle, offset, size);
  1245. }
  1246.  
  1247. #else
  1248. #define drm_core_has_MTRR(dev) (0)
  1249.  
  1250. #define DRM_MTRR_WC             0
  1251.  
  1252. static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
  1253.                                unsigned int flags)
  1254. {
  1255.         return 0;
  1256. }
  1257.  
  1258. static inline int drm_mtrr_del(int handle, unsigned long offset,
  1259.                                unsigned long size, unsigned int flags)
  1260. {
  1261.         return 0;
  1262. }
  1263. #endif
  1264.  
  1265. /******************************************************************/
  1266. /** \name Internal function definitions */
  1267. /*@{*/
  1268.  
  1269.                                 /* Driver support (drm_drv.h) */
  1270. extern long drm_ioctl(struct file *filp,
  1271.                      unsigned int cmd, unsigned long arg);
  1272. extern long drm_compat_ioctl(struct file *filp,
  1273.                              unsigned int cmd, unsigned long arg);
  1274. extern int drm_lastclose(struct drm_device *dev);
  1275.  
  1276.                                 /* Device support (drm_fops.h) */
  1277. extern struct mutex drm_global_mutex;
  1278. extern int drm_open(struct inode *inode, struct file *filp);
  1279. extern int drm_stub_open(struct inode *inode, struct file *filp);
  1280. extern int drm_fasync(int fd, struct file *filp, int on);
  1281. extern ssize_t drm_read(struct file *filp, char __user *buffer,
  1282.                         size_t count, loff_t *offset);
  1283. extern int drm_release(struct inode *inode, struct file *filp);
  1284.  
  1285.                                 /* Mapping support (drm_vm.h) */
  1286. extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
  1287. extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
  1288. extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1289. extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
  1290. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  1291.  
  1292.                                 /* Memory management support (drm_memory.h) */
  1293. #include <drm/drm_memory.h>
  1294. extern void drm_free_agp(DRM_AGP_MEM * handle, int pages);
  1295. extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
  1296. extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
  1297.                                        struct page **pages,
  1298.                                        unsigned long num_pages,
  1299.                                        uint32_t gtt_offset,
  1300.                                        uint32_t type);
  1301. extern int drm_unbind_agp(DRM_AGP_MEM * handle);
  1302.  
  1303.                                 /* Misc. IOCTL support (drm_ioctl.h) */
  1304. extern int drm_irq_by_busid(struct drm_device *dev, void *data,
  1305.                             struct drm_file *file_priv);
  1306. extern int drm_getunique(struct drm_device *dev, void *data,
  1307.                          struct drm_file *file_priv);
  1308. extern int drm_setunique(struct drm_device *dev, void *data,
  1309.                          struct drm_file *file_priv);
  1310. extern int drm_getmap(struct drm_device *dev, void *data,
  1311.                       struct drm_file *file_priv);
  1312. extern int drm_getclient(struct drm_device *dev, void *data,
  1313.                          struct drm_file *file_priv);
  1314. extern int drm_getstats(struct drm_device *dev, void *data,
  1315.                         struct drm_file *file_priv);
  1316. extern int drm_getcap(struct drm_device *dev, void *data,
  1317.                       struct drm_file *file_priv);
  1318. extern int drm_setversion(struct drm_device *dev, void *data,
  1319.                           struct drm_file *file_priv);
  1320. extern int drm_noop(struct drm_device *dev, void *data,
  1321.                     struct drm_file *file_priv);
  1322.  
  1323.                                 /* Context IOCTL support (drm_context.h) */
  1324. extern int drm_resctx(struct drm_device *dev, void *data,
  1325.                       struct drm_file *file_priv);
  1326. extern int drm_addctx(struct drm_device *dev, void *data,
  1327.                       struct drm_file *file_priv);
  1328. extern int drm_modctx(struct drm_device *dev, void *data,
  1329.                       struct drm_file *file_priv);
  1330. extern int drm_getctx(struct drm_device *dev, void *data,
  1331.                       struct drm_file *file_priv);
  1332. extern int drm_switchctx(struct drm_device *dev, void *data,
  1333.                          struct drm_file *file_priv);
  1334. extern int drm_newctx(struct drm_device *dev, void *data,
  1335.                       struct drm_file *file_priv);
  1336. extern int drm_rmctx(struct drm_device *dev, void *data,
  1337.                      struct drm_file *file_priv);
  1338.  
  1339. extern int drm_ctxbitmap_init(struct drm_device *dev);
  1340. extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
  1341. extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
  1342.  
  1343. extern int drm_setsareactx(struct drm_device *dev, void *data,
  1344.                            struct drm_file *file_priv);
  1345. extern int drm_getsareactx(struct drm_device *dev, void *data,
  1346.                            struct drm_file *file_priv);
  1347.  
  1348.                                 /* Authentication IOCTL support (drm_auth.h) */
  1349. extern int drm_getmagic(struct drm_device *dev, void *data,
  1350.                         struct drm_file *file_priv);
  1351. extern int drm_authmagic(struct drm_device *dev, void *data,
  1352.                          struct drm_file *file_priv);
  1353. extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
  1354.  
  1355. /* Cache management (drm_cache.c) */
  1356. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  1357. void drm_clflush_sg(struct sg_table *st);
  1358. void drm_clflush_virt_range(char *addr, unsigned long length);
  1359.  
  1360.                                 /* Locking IOCTL support (drm_lock.h) */
  1361. extern int drm_lock(struct drm_device *dev, void *data,
  1362.                     struct drm_file *file_priv);
  1363. extern int drm_unlock(struct drm_device *dev, void *data,
  1364.                       struct drm_file *file_priv);
  1365. extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
  1366. extern void drm_idlelock_take(struct drm_lock_data *lock_data);
  1367. extern void drm_idlelock_release(struct drm_lock_data *lock_data);
  1368.  
  1369. /*
  1370.  * These are exported to drivers so that they can implement fencing using
  1371.  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  1372.  */
  1373.  
  1374. extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
  1375.  
  1376.                                 /* Buffer management support (drm_bufs.h) */
  1377. extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
  1378. extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
  1379. extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
  1380.                       unsigned int size, enum drm_map_type type,
  1381.                       enum drm_map_flags flags, struct drm_local_map **map_ptr);
  1382. extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
  1383.                             struct drm_file *file_priv);
  1384. extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
  1385. extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
  1386. extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
  1387.                            struct drm_file *file_priv);
  1388. extern int drm_addbufs(struct drm_device *dev, void *data,
  1389.                        struct drm_file *file_priv);
  1390. extern int drm_infobufs(struct drm_device *dev, void *data,
  1391.                         struct drm_file *file_priv);
  1392. extern int drm_markbufs(struct drm_device *dev, void *data,
  1393.                         struct drm_file *file_priv);
  1394. extern int drm_freebufs(struct drm_device *dev, void *data,
  1395.                         struct drm_file *file_priv);
  1396. extern int drm_mapbufs(struct drm_device *dev, void *data,
  1397.                        struct drm_file *file_priv);
  1398. extern int drm_order(unsigned long size);
  1399.  
  1400.                                 /* DMA support (drm_dma.h) */
  1401. extern int drm_dma_setup(struct drm_device *dev);
  1402. extern void drm_dma_takedown(struct drm_device *dev);
  1403. extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
  1404. extern void drm_core_reclaim_buffers(struct drm_device *dev,
  1405.                                      struct drm_file *filp);
  1406.  
  1407.                                 /* IRQ support (drm_irq.h) */
  1408. extern int drm_control(struct drm_device *dev, void *data,
  1409.                        struct drm_file *file_priv);
  1410. extern int drm_irq_install(struct drm_device *dev);
  1411. extern int drm_irq_uninstall(struct drm_device *dev);
  1412.  
  1413. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  1414. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  1415.                            struct drm_file *filp);
  1416. extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
  1417. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  1418. extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
  1419.                                      struct timeval *vblanktime);
  1420. extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
  1421. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1422. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1423. extern void drm_vblank_off(struct drm_device *dev, int crtc);
  1424. extern void drm_vblank_cleanup(struct drm_device *dev);
  1425. extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
  1426.                                      struct timeval *tvblank, unsigned flags);
  1427. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  1428.                                                  int crtc, int *max_error,
  1429.                                                  struct timeval *vblank_time,
  1430.                                                  unsigned flags,
  1431.                                                  struct drm_crtc *refcrtc);
  1432. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
  1433.  
  1434. extern bool
  1435. drm_mode_parse_command_line_for_connector(const char *mode_option,
  1436.                                           struct drm_connector *connector,
  1437.                                           struct drm_cmdline_mode *mode);
  1438.  
  1439. extern struct drm_display_mode *
  1440. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  1441.                                   struct drm_cmdline_mode *cmd);
  1442.  
  1443. /* Modesetting support */
  1444. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1445. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1446. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1447.                            struct drm_file *file_priv);
  1448.  
  1449.                                 /* AGP/GART support (drm_agpsupport.h) */
  1450. extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
  1451. extern int drm_agp_acquire(struct drm_device *dev);
  1452. extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
  1453.                                  struct drm_file *file_priv);
  1454. extern int drm_agp_release(struct drm_device *dev);
  1455. extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
  1456.                                  struct drm_file *file_priv);
  1457. extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
  1458. extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
  1459.                                 struct drm_file *file_priv);
  1460. extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
  1461. extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
  1462.                         struct drm_file *file_priv);
  1463. extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
  1464. extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
  1465.                          struct drm_file *file_priv);
  1466. extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
  1467. extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
  1468.                         struct drm_file *file_priv);
  1469. extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
  1470. extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
  1471.                           struct drm_file *file_priv);
  1472. extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
  1473. extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
  1474.                         struct drm_file *file_priv);
  1475.  
  1476.                                 /* Stub support (drm_stub.h) */
  1477. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1478.                                struct drm_file *file_priv);
  1479. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1480.                                 struct drm_file *file_priv);
  1481. struct drm_master *drm_master_create(struct drm_minor *minor);
  1482. extern struct drm_master *drm_master_get(struct drm_master *master);
  1483. extern void drm_master_put(struct drm_master **master);
  1484.  
  1485. extern void drm_put_dev(struct drm_device *dev);
  1486. extern int drm_put_minor(struct drm_minor **minor);
  1487. extern void drm_unplug_dev(struct drm_device *dev);
  1488. #endif
  1489.  
  1490. extern unsigned int drm_debug;
  1491.  
  1492. #if 0
  1493. extern unsigned int drm_vblank_offdelay;
  1494. extern unsigned int drm_timestamp_precision;
  1495. extern unsigned int drm_timestamp_monotonic;
  1496.  
  1497. extern struct class *drm_class;
  1498. extern struct proc_dir_entry *drm_proc_root;
  1499. extern struct dentry *drm_debugfs_root;
  1500.  
  1501. extern struct idr drm_minors_idr;
  1502.  
  1503. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1504.  
  1505.                                 /* Proc support (drm_proc.h) */
  1506. extern int drm_proc_init(struct drm_minor *minor, int minor_id,
  1507.                          struct proc_dir_entry *root);
  1508. extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
  1509.  
  1510.                                 /* Debugfs support */
  1511. #if defined(CONFIG_DEBUG_FS)
  1512. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1513.                             struct dentry *root);
  1514. extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
  1515.                                     struct dentry *root, struct drm_minor *minor);
  1516. extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
  1517.                                     struct drm_minor *minor);
  1518. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1519. #endif
  1520.  
  1521.                                 /* Info file support */
  1522. extern int drm_name_info(struct seq_file *m, void *data);
  1523. extern int drm_vm_info(struct seq_file *m, void *data);
  1524. extern int drm_bufs_info(struct seq_file *m, void *data);
  1525. extern int drm_vblank_info(struct seq_file *m, void *data);
  1526. extern int drm_clients_info(struct seq_file *m, void* data);
  1527. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1528.  
  1529. #if DRM_DEBUG_CODE
  1530. extern int drm_vma_info(struct seq_file *m, void *data);
  1531. #endif
  1532.  
  1533.                                 /* Scatter Gather Support (drm_scatter.h) */
  1534. extern void drm_sg_cleanup(struct drm_sg_mem * entry);
  1535. extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
  1536.                         struct drm_file *file_priv);
  1537. extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
  1538. extern int drm_sg_free(struct drm_device *dev, void *data,
  1539.                        struct drm_file *file_priv);
  1540.  
  1541.                                /* ATI PCIGART support (ati_pcigart.h) */
  1542. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1543.                                 struct drm_ati_pcigart_info * gart_info);
  1544. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1545.                                    struct drm_ati_pcigart_info * gart_info);
  1546. #endif
  1547.  
  1548. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1549.                                        size_t align);
  1550. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1551. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1552.  
  1553. #if 0
  1554.                                /* sysfs support (drm_sysfs.c) */
  1555. struct drm_sysfs_class;
  1556. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1557. extern void drm_sysfs_destroy(void);
  1558. extern int drm_sysfs_device_add(struct drm_minor *minor);
  1559. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1560. extern void drm_sysfs_device_remove(struct drm_minor *minor);
  1561. extern char *drm_get_connector_status_name(enum drm_connector_status status);
  1562.  
  1563. static inline int drm_sysfs_connector_add(struct drm_connector *connector)
  1564. { return 0; };
  1565.  
  1566. static inline void drm_sysfs_connector_remove(struct drm_connector *connector)
  1567. { };
  1568.  
  1569. #endif
  1570.  
  1571. /* Graphics Execution Manager library functions (drm_gem.c) */
  1572. int drm_gem_init(struct drm_device *dev);
  1573. void drm_gem_destroy(struct drm_device *dev);
  1574. void drm_gem_object_release(struct drm_gem_object *obj);
  1575. void drm_gem_object_free(struct kref *kref);
  1576. struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
  1577.                                             size_t size);
  1578. int drm_gem_object_init(struct drm_device *dev,
  1579.                         struct drm_gem_object *obj, size_t size);
  1580. int drm_gem_private_object_init(struct drm_device *dev,
  1581.                         struct drm_gem_object *obj, size_t size);
  1582. void drm_gem_object_handle_free(struct drm_gem_object *obj);
  1583. void drm_gem_vm_open(struct vm_area_struct *vma);
  1584. void drm_gem_vm_close(struct vm_area_struct *vma);
  1585. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1586.  
  1587.  
  1588. static inline void
  1589. drm_gem_object_reference(struct drm_gem_object *obj)
  1590. {
  1591.         kref_get(&obj->refcount);
  1592. }
  1593.  
  1594. static inline void
  1595. drm_gem_object_unreference(struct drm_gem_object *obj)
  1596. {
  1597.         if (obj != NULL)
  1598.                 kref_put(&obj->refcount, drm_gem_object_free);
  1599. }
  1600.  
  1601. static inline void
  1602. drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
  1603. {
  1604.         if (obj != NULL) {
  1605.                 struct drm_device *dev = obj->dev;
  1606.                 mutex_lock(&dev->struct_mutex);
  1607.         kref_put(&obj->refcount, drm_gem_object_free);
  1608.                 mutex_unlock(&dev->struct_mutex);
  1609.         }
  1610. }
  1611.  
  1612. int drm_gem_handle_create(struct drm_file *file_priv,
  1613.                           struct drm_gem_object *obj,
  1614.                           u32 *handlep);
  1615. int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
  1616.  
  1617. static inline void
  1618. drm_gem_object_handle_reference(struct drm_gem_object *obj)
  1619. {
  1620.         drm_gem_object_reference(obj);
  1621.         atomic_inc(&obj->handle_count);
  1622. }
  1623.  
  1624. static inline void
  1625. drm_gem_object_handle_unreference(struct drm_gem_object *obj)
  1626. {
  1627.         if (obj == NULL)
  1628.                 return;
  1629.  
  1630.         if (atomic_read(&obj->handle_count) == 0)
  1631.                 return;
  1632.         /*
  1633.          * Must bump handle count first as this may be the last
  1634.          * ref, in which case the object would disappear before we
  1635.          * checked for a name
  1636.          */
  1637.         if (atomic_dec_and_test(&obj->handle_count))
  1638.                 drm_gem_object_handle_free(obj);
  1639.         drm_gem_object_unreference(obj);
  1640. }
  1641.  
  1642. static inline void
  1643. drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
  1644. {
  1645.         if (obj == NULL)
  1646.                 return;
  1647.  
  1648.         if (atomic_read(&obj->handle_count) == 0)
  1649.                 return;
  1650.  
  1651.         /*
  1652.         * Must bump handle count first as this may be the last
  1653.         * ref, in which case the object would disappear before we
  1654.         * checked for a name
  1655.         */
  1656.  
  1657.         if (atomic_dec_and_test(&obj->handle_count))
  1658.                 drm_gem_object_handle_free(obj);
  1659.         drm_gem_object_unreference_unlocked(obj);
  1660. }
  1661.  
  1662. void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
  1663. int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
  1664.  
  1665. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1666.                                              struct drm_file *filp,
  1667.                                              u32 handle);
  1668. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1669.                         struct drm_file *file_priv);
  1670. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1671.                         struct drm_file *file_priv);
  1672. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1673.                        struct drm_file *file_priv);
  1674. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1675. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1676.  
  1677. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1678. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1679. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1680.  
  1681. #if 0
  1682.  
  1683. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1684.                                                          unsigned int token)
  1685. {
  1686.         struct drm_map_list *_entry;
  1687.         list_for_each_entry(_entry, &dev->maplist, head)
  1688.             if (_entry->user_token == token)
  1689.                 return _entry->map;
  1690.         return NULL;
  1691. }
  1692.  
  1693. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1694. {
  1695. }
  1696.  
  1697.  
  1698.  
  1699. static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
  1700. {
  1701.         if (size * nmemb <= PAGE_SIZE)
  1702.             return kcalloc(nmemb, size, GFP_KERNEL);
  1703.  
  1704.         if (size != 0 && nmemb > ULONG_MAX / size)
  1705.                 return NULL;
  1706.  
  1707.         return __vmalloc(size * nmemb,
  1708.                          GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
  1709. }
  1710.  
  1711. static __inline void drm_free_large(void *ptr)
  1712. {
  1713.         if (!is_vmalloc_addr(ptr))
  1714.                 return kfree(ptr);
  1715.  
  1716.         vfree(ptr);
  1717. }
  1718.  
  1719. #endif
  1720.  
  1721. #define DRM_PCIE_SPEED_25 1
  1722. #define DRM_PCIE_SPEED_50 2
  1723. #define DRM_PCIE_SPEED_80 4
  1724.  
  1725. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  1726.  
  1727. static __inline__ int drm_device_is_agp(struct drm_device *dev)
  1728. {
  1729.     return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1730. }
  1731.  
  1732. static __inline__ int drm_device_is_pcie(struct drm_device *dev)
  1733. {
  1734.     return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  1735. }
  1736. #endif                          /* __KERNEL__ */
  1737.  
  1738. #define drm_sysfs_connector_add(connector)
  1739. #define drm_sysfs_connector_remove(connector)
  1740.  
  1741. #endif
  1742.