Subversion Repositories Kolibri OS

Rev

Rev 3297 | Rev 3482 | 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. #include <linux/sched.h>
  56.  
  57. //#include <linux/miscdevice.h>
  58. //#include <linux/fs.h>
  59. //#include <linux/proc_fs.h>
  60. //#include <linux/init.h>
  61. //#include <linux/file.h>
  62. #include <linux/pci.h>
  63. #include <linux/jiffies.h>
  64. #include <linux/irqreturn.h>
  65. //#include <linux/smp_lock.h>    /* For (un)lock_kernel */
  66. //#include <linux/dma-mapping.h>
  67. //#include <linux/mm.h>
  68. //#include <linux/cdev.h>
  69. #include <linux/mutex.h>
  70. //#include <asm/io.h>
  71. //#include <asm/mman.h>
  72. //#include <asm/uaccess.h>
  73. //#include <linux/workqueue.h>
  74. //#include <linux/poll.h>
  75. //#include <asm/pgalloc.h>
  76.  
  77. #include "drm.h"
  78.  
  79. #include <linux/idr.h>
  80.  
  81. #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
  82. #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
  83.  
  84. struct module;
  85.  
  86. struct drm_file;
  87. struct drm_device;
  88.  
  89. struct device_node;
  90. struct videomode;
  91. //#include <drm/drm_os_linux.h>
  92. #include <drm/drm_hashtab.h>
  93. #include <drm/drm_mm.h>
  94.  
  95. #define KHZ2PICOS(a) (1000000000UL/(a))
  96.  
  97. /* get_scanout_position() return flags */
  98. #define DRM_SCANOUTPOS_VALID        (1 << 0)
  99. #define DRM_SCANOUTPOS_INVBL        (1 << 1)
  100. #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
  101.  
  102.  
  103.  
  104. #define DRM_UT_CORE             0x01
  105. #define DRM_UT_DRIVER           0x02
  106. #define DRM_UT_KMS          0x04
  107. #define DRM_UT_PRIME            0x08
  108. /*
  109.  * Three debug levels are defined.
  110.  * drm_core, drm_driver, drm_kms
  111.  * drm_core level can be used in the generic drm code. For example:
  112.  *      drm_ioctl, drm_mm, drm_memory
  113.  * The macro definition of DRM_DEBUG is used.
  114.  *      DRM_DEBUG(fmt, args...)
  115.  *      The debug info by using the DRM_DEBUG can be obtained by adding
  116.  *      the boot option of "drm.debug=1".
  117.  *
  118.  * drm_driver level can be used in the specific drm driver. It is used
  119.  * to add the debug info related with the drm driver. For example:
  120.  * i915_drv, i915_dma, i915_gem, radeon_drv,
  121.  *      The macro definition of DRM_DEBUG_DRIVER can be used.
  122.  *      DRM_DEBUG_DRIVER(fmt, args...)
  123.  *      The debug info by using the DRM_DEBUG_DRIVER can be obtained by
  124.  *      adding the boot option of "drm.debug=0x02"
  125.  *
  126.  * drm_kms level can be used in the KMS code related with specific drm driver.
  127.  * It is used to add the debug info related with KMS mode. For example:
  128.  * the connector/crtc ,
  129.  *      The macro definition of DRM_DEBUG_KMS can be used.
  130.  *      DRM_DEBUG_KMS(fmt, args...)
  131.  *      The debug info by using the DRM_DEBUG_KMS can be obtained by
  132.  *      adding the boot option of "drm.debug=0x04"
  133.  *
  134.  * If we add the boot option of "drm.debug=0x06", we can get the debug info by
  135.  * using the DRM_DEBUG_KMS and DRM_DEBUG_DRIVER.
  136.  * If we add the boot option of "drm.debug=0x05", we can get the debug info by
  137.  * using the DRM_DEBUG_KMS and DRM_DEBUG.
  138.  */
  139.  
  140. extern __printf(4, 5)
  141. void drm_ut_debug_printk(unsigned int request_level,
  142.                                 const char *prefix,
  143.                                 const char *function_name,
  144.                                 const char *format, ...);
  145. extern __printf(2, 3)
  146. int drm_err(const char *func, const char *format, ...);
  147.  
  148. /***********************************************************************/
  149. /** \name DRM template customization defaults */
  150. /*@{*/
  151.  
  152. /* driver capabilities and requirements mask */
  153. #define DRIVER_USE_AGP     0x1
  154. #define DRIVER_REQUIRE_AGP 0x2
  155. #define DRIVER_USE_MTRR    0x4
  156. #define DRIVER_PCI_DMA     0x8
  157. #define DRIVER_SG          0x10
  158. #define DRIVER_HAVE_DMA    0x20
  159. #define DRIVER_HAVE_IRQ    0x40
  160. #define DRIVER_IRQ_SHARED  0x80
  161. #define DRIVER_IRQ_VBL     0x100
  162. #define DRIVER_DMA_QUEUE   0x200
  163. #define DRIVER_FB_DMA      0x400
  164. #define DRIVER_IRQ_VBL2    0x800
  165. #define DRIVER_GEM         0x1000
  166. #define DRIVER_MODESET     0x2000
  167. #define DRIVER_PRIME       0x4000
  168.  
  169. #define DRIVER_BUS_PCI 0x1
  170. #define DRIVER_BUS_PLATFORM 0x2
  171. #define DRIVER_BUS_USB 0x3
  172.  
  173. /***********************************************************************/
  174. /** \name Begin the DRM... */
  175. /*@{*/
  176.  
  177. #define DRM_DEBUG_CODE 2          /**< Include debugging code if > 1, then
  178.                                      also include looping detection. */
  179.  
  180. #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
  181. #define DRM_KERNEL_CONTEXT    0  /**< Change drm_resctx if changed */
  182. #define DRM_RESERVED_CONTEXTS 1  /**< Change drm_resctx if changed */
  183. #define DRM_LOOPING_LIMIT     5000000
  184. #define DRM_TIME_SLICE        (HZ/20)  /**< Time slice for GLXContexts */
  185. #define DRM_LOCK_SLICE        1 /**< Time slice for lock, in jiffies */
  186.  
  187. #define DRM_FLAG_DEBUG    0x01
  188.  
  189. #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
  190. #define DRM_MAP_HASH_OFFSET 0x10000000
  191.  
  192. /*@}*/
  193.  
  194. /***********************************************************************/
  195. /** \name Macros to make printk easier */
  196. /*@{*/
  197.  
  198. /**
  199.  * Error output.
  200.  *
  201.  * \param fmt printf() like format string.
  202.  * \param arg arguments
  203.  */
  204. #define DRM_ERROR(fmt, ...)                             \
  205.         drm_err(__func__, fmt, ##__VA_ARGS__)
  206.  
  207. #define DRM_INFO(fmt, ...)                              \
  208.         printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  209.  
  210. /**
  211.  * Debug output.
  212.  *
  213.  * \param fmt printf() like format string.
  214.  * \param arg arguments
  215.  */
  216. #if DRM_DEBUG_CODE
  217. #define DRM_DEBUG(fmt, ...)                                 \
  218.     do {                                                    \
  219.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  220.         } while (0)
  221.  
  222. #define DRM_DEBUG_DRIVER(fmt, ...)                          \
  223.     do {                                                    \
  224.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  225.         } while (0)
  226. #define DRM_DEBUG_KMS(fmt, ...)              \
  227.         do {                                                            \
  228.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  229.         } while (0)
  230. #define DRM_DEBUG_PRIME(fmt, ...)                    \
  231.         do {                                                            \
  232.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  233.         } while (0)
  234. #define DRM_LOG(fmt, ...)                        \
  235.         do {                                                            \
  236.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  237.         } while (0)
  238. #define DRM_LOG_KMS(fmt, ...)                    \
  239.         do {                                                            \
  240.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  241.         } while (0)
  242. #define DRM_LOG_MODE(fmt, ...)                   \
  243.         do {                                                            \
  244.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  245.         } while (0)
  246. #define DRM_LOG_DRIVER(fmt, ...)                 \
  247.         do {                                                            \
  248.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__);  \
  249.         } while (0)
  250. #else
  251. #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
  252. #define DRM_DEBUG_KMS(fmt, args...)     do { } while (0)
  253. #define DRM_DEBUG_PRIME(fmt, args...)   do { } while (0)
  254. #define DRM_DEBUG(fmt, arg...)           do { } while (0)
  255. #define DRM_LOG(fmt, arg...)            do { } while (0)
  256. #define DRM_LOG_KMS(fmt, args...) do { } while (0)
  257. #define DRM_LOG_MODE(fmt, arg...) do { } while (0)
  258. #define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
  259.  
  260. #endif
  261.  
  262. /*@}*/
  263.  
  264. /***********************************************************************/
  265. /** \name Internal types and structures */
  266. /*@{*/
  267.  
  268. #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
  269.  
  270. #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
  271. #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
  272.  
  273. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  274.  
  275. /**
  276.  * Test that the hardware lock is held by the caller, returning otherwise.
  277.  *
  278.  * \param dev DRM device.
  279.  * \param filp file pointer of the caller.
  280.  */
  281. #define LOCK_TEST_WITH_RETURN( dev, _file_priv )                                \
  282. do {                                                                            \
  283.         if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||       \
  284.             _file_priv->master->lock.file_priv != _file_priv)   {               \
  285.                 DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
  286.                            __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  287.                            _file_priv->master->lock.file_priv, _file_priv);     \
  288.                 return -EINVAL;                                                 \
  289.         }                                                                       \
  290. } while (0)
  291.  
  292. #if 0
  293. /**
  294.  * Ioctl function type.
  295.  *
  296.  * \param inode device inode.
  297.  * \param file_priv DRM file private pointer.
  298.  * \param cmd command.
  299.  * \param arg argument.
  300.  */
  301. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  302.                         struct drm_file *file_priv);
  303.  
  304. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  305.                                unsigned long arg);
  306.  
  307. #define DRM_IOCTL_NR(n)                _IOC_NR(n)
  308. #define DRM_MAJOR       226
  309.  
  310. #define DRM_AUTH        0x1
  311. #define DRM_MASTER      0x2
  312. #define DRM_ROOT_ONLY   0x4
  313. #define DRM_CONTROL_ALLOW 0x8
  314. #define DRM_UNLOCKED    0x10
  315.  
  316. struct drm_ioctl_desc {
  317.         unsigned int cmd;
  318.         int flags;
  319.         drm_ioctl_t *func;
  320.         unsigned int cmd_drv;
  321. };
  322.  
  323. /**
  324.  * Creates a driver or general drm_ioctl_desc array entry for the given
  325.  * ioctl, for use by drm_ioctl().
  326.  */
  327.  
  328. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                 \
  329.         [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
  330.  
  331. struct drm_magic_entry {
  332.         struct list_head head;
  333.         struct drm_hash_item hash_item;
  334.         struct drm_file *priv;
  335. };
  336.  
  337. struct drm_vma_entry {
  338.         struct list_head head;
  339.         struct vm_area_struct *vma;
  340.         pid_t pid;
  341. };
  342.  
  343. /**
  344.  * DMA buffer.
  345.  */
  346. struct drm_buf {
  347.         int idx;                       /**< Index into master buflist */
  348.         int total;                     /**< Buffer size */
  349.         int order;                     /**< log-base-2(total) */
  350.         int used;                      /**< Amount of buffer in use (for DMA) */
  351.         unsigned long offset;          /**< Byte offset (used internally) */
  352.         void *address;                 /**< Address of buffer */
  353.         unsigned long bus_address;     /**< Bus address of buffer */
  354.         struct drm_buf *next;          /**< Kernel-only: used for free list */
  355.         __volatile__ int waiting;      /**< On kernel DMA queue */
  356.         __volatile__ int pending;      /**< On hardware DMA queue */
  357.         struct drm_file *file_priv;    /**< Private of holding file descr */
  358.         int context;                   /**< Kernel queue for this buffer */
  359.         int while_locked;              /**< Dispatch this buffer while locked */
  360.         enum {
  361.                 DRM_LIST_NONE = 0,
  362.                 DRM_LIST_FREE = 1,
  363.                 DRM_LIST_WAIT = 2,
  364.                 DRM_LIST_PEND = 3,
  365.                 DRM_LIST_PRIO = 4,
  366.                 DRM_LIST_RECLAIM = 5
  367.         } list;                        /**< Which list we're on */
  368.  
  369.         int dev_priv_size;               /**< Size of buffer private storage */
  370.         void *dev_private;               /**< Per-buffer private storage */
  371. };
  372.  
  373. /** bufs is one longer than it has to be */
  374. struct drm_waitlist {
  375.         int count;                      /**< Number of possible buffers */
  376.         struct drm_buf **bufs;          /**< List of pointers to buffers */
  377.         struct drm_buf **rp;                    /**< Read pointer */
  378.         struct drm_buf **wp;                    /**< Write pointer */
  379.         struct drm_buf **end;           /**< End pointer */
  380.         spinlock_t read_lock;
  381.         spinlock_t write_lock;
  382. };
  383.  
  384. struct drm_freelist {
  385.         int initialized;               /**< Freelist in use */
  386.         atomic_t count;                /**< Number of free buffers */
  387.         struct drm_buf *next;          /**< End pointer */
  388.  
  389.         wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
  390.         int low_mark;                  /**< Low water mark */
  391.         int high_mark;                 /**< High water mark */
  392.         atomic_t wfh;                  /**< If waiting for high mark */
  393.         spinlock_t lock;
  394. };
  395. #endif
  396.  
  397. typedef struct drm_dma_handle {
  398.         dma_addr_t busaddr;
  399.         void *vaddr;
  400.         size_t size;
  401. } drm_dma_handle_t;
  402.  
  403. #if 0
  404. /**
  405.  * Buffer entry.  There is one of this for each buffer size order.
  406.  */
  407. struct drm_buf_entry {
  408.         int buf_size;                   /**< size */
  409.         int buf_count;                  /**< number of buffers */
  410.         struct drm_buf *buflist;                /**< buffer list */
  411.         int seg_count;
  412.         int page_order;
  413.         struct drm_dma_handle **seglist;
  414.  
  415.         struct drm_freelist freelist;
  416. };
  417.  
  418. /* Event queued up for userspace to read */
  419. struct drm_pending_event {
  420.         struct drm_event *event;
  421.         struct list_head link;
  422.         struct drm_file *file_priv;
  423.         pid_t pid; /* pid of requester, no guarantee it's valid by the time
  424.                       we deliver the event, for tracing only */
  425.         void (*destroy)(struct drm_pending_event *event);
  426. };
  427.  
  428. /* initial implementaton using a linked list - todo hashtab */
  429. struct drm_prime_file_private {
  430.         struct list_head head;
  431.         struct mutex lock;
  432. };
  433. #endif
  434.  
  435. /** File private data */
  436. struct drm_file {
  437.         struct list_head lhead;
  438.         unsigned long lock_count;
  439.  
  440.         /** Mapping of mm object handles to object pointers. */
  441.         struct idr object_idr;
  442.         /** Lock for synchronization of access to object_idr. */
  443.         spinlock_t table_lock;
  444.  
  445.         void *driver_priv;
  446.  
  447.         struct list_head fbs;
  448.  
  449.         wait_queue_head_t event_wait;
  450.         struct list_head event_list;
  451.         int event_space;
  452. };
  453.  
  454. #if 0
  455. /** Wait queue */
  456. struct drm_queue {
  457.         atomic_t use_count;             /**< Outstanding uses (+1) */
  458.         atomic_t finalization;          /**< Finalization in progress */
  459.         atomic_t block_count;           /**< Count of processes waiting */
  460.         atomic_t block_read;            /**< Queue blocked for reads */
  461.         wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
  462.         atomic_t block_write;           /**< Queue blocked for writes */
  463.         wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
  464.         atomic_t total_queued;          /**< Total queued statistic */
  465.         atomic_t total_flushed;         /**< Total flushes statistic */
  466.         atomic_t total_locks;           /**< Total locks statistics */
  467.         enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
  468.         struct drm_waitlist waitlist;   /**< Pending buffers */
  469.         wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
  470. };
  471.  
  472. /**
  473.  * Lock data.
  474.  */
  475. struct drm_lock_data {
  476.         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
  477.         /** Private of lock holder's file (NULL=kernel) */
  478.         struct drm_file *file_priv;
  479.         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
  480.         unsigned long lock_time;        /**< Time of last lock in jiffies */
  481.         spinlock_t spinlock;
  482.         uint32_t kernel_waiters;
  483.         uint32_t user_waiters;
  484.         int idle_has_lock;
  485. };
  486.  
  487. /**
  488.  * DMA data.
  489.  */
  490. struct drm_device_dma {
  491.  
  492.         struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
  493.         int buf_count;                  /**< total number of buffers */
  494.         struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
  495.         int seg_count;
  496.         int page_count;                 /**< number of pages */
  497.         unsigned long *pagelist;        /**< page list */
  498.         unsigned long byte_count;
  499.         enum {
  500.                 _DRM_DMA_USE_AGP = 0x01,
  501.                 _DRM_DMA_USE_SG = 0x02,
  502.                 _DRM_DMA_USE_FB = 0x04,
  503.                 _DRM_DMA_USE_PCI_RO = 0x08
  504.         } flags;
  505.  
  506. };
  507.  
  508. /**
  509.  * AGP memory entry.  Stored as a doubly linked list.
  510.  */
  511. struct drm_agp_mem {
  512.         unsigned long handle;           /**< handle */
  513.         DRM_AGP_MEM *memory;
  514.         unsigned long bound;            /**< address */
  515.         int pages;
  516.         struct list_head head;
  517. };
  518.  
  519. /**
  520.  * AGP data.
  521.  *
  522.  * \sa drm_agp_init() and drm_device::agp.
  523.  */
  524. struct drm_agp_head {
  525.         DRM_AGP_KERN agp_info;          /**< AGP device information */
  526.         struct list_head memory;
  527.         unsigned long mode;             /**< AGP mode */
  528.         struct agp_bridge_data *bridge;
  529.         int enabled;                    /**< whether the AGP bus as been enabled */
  530.         int acquired;                   /**< whether the AGP device has been acquired */
  531.         unsigned long base;
  532.         int agp_mtrr;
  533.         int cant_use_aperture;
  534.         unsigned long page_mask;
  535. };
  536.  
  537. /**
  538.  * Scatter-gather memory.
  539.  */
  540. struct drm_sg_mem {
  541.         unsigned long handle;
  542.         void *virtual;
  543.         int pages;
  544.         struct page **pagelist;
  545.         dma_addr_t *busaddr;
  546. };
  547.  
  548. struct drm_sigdata {
  549.         int context;
  550.         struct drm_hw_lock *lock;
  551. };
  552.  
  553. #endif
  554.  
  555.  
  556. /**
  557.  * Kernel side of a mapping
  558.  */
  559. struct drm_local_map {
  560.         resource_size_t offset;  /**< Requested physical address (0 for SAREA)*/
  561.         unsigned long size;      /**< Requested physical size (bytes) */
  562.         enum drm_map_type type;  /**< Type of memory to map */
  563.         enum drm_map_flags flags;        /**< Flags */
  564.         void *handle;            /**< User-space: "Handle" to pass to mmap() */
  565.                                  /**< Kernel-space: kernel-virtual address */
  566.         int mtrr;                /**< MTRR slot used */
  567. };
  568.  
  569. typedef struct drm_local_map drm_local_map_t;
  570.  
  571. #if 0
  572. /**
  573.  * Mappings list
  574.  */
  575. struct drm_map_list {
  576.         struct list_head head;          /**< list head */
  577.         struct drm_hash_item hash;
  578.         struct drm_local_map *map;      /**< mapping */
  579.         uint64_t user_token;
  580.         struct drm_master *master;
  581.         struct drm_mm_node *file_offset_node;   /**< fake offset */
  582. };
  583.  
  584. /**
  585.  * Context handle list
  586.  */
  587. struct drm_ctx_list {
  588.         struct list_head head;          /**< list head */
  589.         drm_context_t handle;           /**< context handle */
  590.         struct drm_file *tag;           /**< associated fd private data */
  591. };
  592.  
  593. /* location of GART table */
  594. #define DRM_ATI_GART_MAIN 1
  595. #define DRM_ATI_GART_FB   2
  596.  
  597. #define DRM_ATI_GART_PCI 1
  598. #define DRM_ATI_GART_PCIE 2
  599. #define DRM_ATI_GART_IGP 3
  600.  
  601. struct drm_ati_pcigart_info {
  602.         int gart_table_location;
  603.         int gart_reg_if;
  604.         void *addr;
  605.         dma_addr_t bus_addr;
  606.         dma_addr_t table_mask;
  607.         struct drm_dma_handle *table_handle;
  608.         struct drm_local_map mapping;
  609.         int table_size;
  610. };
  611.  
  612. /**
  613.  * GEM specific mm private for tracking GEM objects
  614.  */
  615. struct drm_gem_mm {
  616.         struct drm_mm offset_manager;   /**< Offset mgmt for buffer objects */
  617.         struct drm_open_hash offset_hash; /**< User token hash table for maps */
  618. };
  619.  
  620. #endif
  621.  
  622. /**
  623.  * This structure defines the drm_mm memory object, which will be used by the
  624.  * DRM for its buffer objects.
  625.  */
  626. struct drm_gem_object {
  627.         /** Reference count of this object */
  628.         struct kref refcount;
  629.  
  630.         /** Handle count of this object. Each handle also holds a reference */
  631.         atomic_t handle_count; /* number of handles on this object */
  632.  
  633.         /** Related drm device */
  634.         struct drm_device *dev;
  635.  
  636.         /** File representing the shmem storage */
  637.         struct file *filp;
  638.  
  639.         /* Mapping info for this object */
  640.  
  641.         /**
  642.          * Size of the object, in bytes.  Immutable over the object's
  643.          * lifetime.
  644.          */
  645.         size_t size;
  646.  
  647.         /**
  648.          * Global name for this object, starts at 1. 0 means unnamed.
  649.          * Access is covered by the object_name_lock in the related drm_device
  650.          */
  651.         int name;
  652.  
  653.         /**
  654.          * Memory domains. These monitor which caches contain read/write data
  655.          * related to the object. When transitioning from one set of domains
  656.          * to another, the driver is called to ensure that caches are suitably
  657.          * flushed and invalidated
  658.          */
  659.         uint32_t read_domains;
  660.         uint32_t write_domain;
  661.  
  662.         /**
  663.          * While validating an exec operation, the
  664.          * new read/write domain values are computed here.
  665.          * They will be transferred to the above values
  666.          * at the point that any cache flushing occurs
  667.          */
  668.         uint32_t pending_read_domains;
  669.         uint32_t pending_write_domain;
  670.  
  671.         void *driver_private;
  672. };
  673.  
  674. #include <drm/drm_crtc.h>
  675.  
  676. /* per-master structure */
  677. struct drm_master {
  678.  
  679.         struct kref refcount; /* refcount for this master */
  680.  
  681.         struct list_head head; /**< each minor contains a list of masters */
  682.         struct drm_minor *minor; /**< link back to minor we are a master for */
  683.  
  684.         char *unique;                   /**< Unique identifier: e.g., busid */
  685.         int unique_len;                 /**< Length of unique field */
  686.         int unique_size;                /**< amount allocated */
  687.  
  688.         int blocked;                    /**< Blocked due to VC switch? */
  689.  
  690.         /** \name Authentication */
  691.         /*@{ */
  692. //   struct drm_open_hash magiclist;
  693. //   struct list_head magicfree;
  694.         /*@} */
  695.  
  696. //   struct drm_lock_data lock;  /**< Information on hardware lock */
  697.  
  698.         void *driver_priv; /**< Private structure for driver to use */
  699. };
  700.  
  701. #if 0
  702.  
  703. /* Size of ringbuffer for vblank timestamps. Just double-buffer
  704.  * in initial implementation.
  705.  */
  706. #define DRM_VBLANKTIME_RBSIZE 2
  707.  
  708. /* Flags and return codes for get_vblank_timestamp() driver function. */
  709. #define DRM_CALLED_FROM_VBLIRQ 1
  710. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  711. #define DRM_VBLANKTIME_INVBL             (1 << 1)
  712.  
  713. /* get_scanout_position() return flags */
  714. #define DRM_SCANOUTPOS_VALID        (1 << 0)
  715. #define DRM_SCANOUTPOS_INVBL        (1 << 1)
  716. #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
  717.  
  718. struct drm_bus {
  719.         int bus_type;
  720.         int (*get_irq)(struct drm_device *dev);
  721.         const char *(*get_name)(struct drm_device *dev);
  722.         int (*set_busid)(struct drm_device *dev, struct drm_master *master);
  723.         int (*set_unique)(struct drm_device *dev, struct drm_master *master,
  724.                           struct drm_unique *unique);
  725.         int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
  726.         /* hooks that are for PCI */
  727.         int (*agp_init)(struct drm_device *dev);
  728.  
  729. };
  730.  
  731. /**
  732.  * DRM driver structure. This structure represent the common code for
  733.  * a family of cards. There will one drm_device for each card present
  734.  * in this family
  735.  */
  736. struct drm_driver {
  737.         int (*load) (struct drm_device *, unsigned long flags);
  738.         int (*firstopen) (struct drm_device *);
  739.         int (*open) (struct drm_device *, struct drm_file *);
  740.         void (*preclose) (struct drm_device *, struct drm_file *file_priv);
  741.         void (*postclose) (struct drm_device *, struct drm_file *);
  742.         void (*lastclose) (struct drm_device *);
  743.         int (*unload) (struct drm_device *);
  744.         int (*suspend) (struct drm_device *, pm_message_t state);
  745.         int (*resume) (struct drm_device *);
  746.         int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
  747.         int (*dma_quiescent) (struct drm_device *);
  748.         int (*context_dtor) (struct drm_device *dev, int context);
  749.  
  750.         /**
  751.          * get_vblank_counter - get raw hardware vblank counter
  752.          * @dev: DRM device
  753.          * @crtc: counter to fetch
  754.          *
  755.          * Driver callback for fetching a raw hardware vblank counter for @crtc.
  756.          * If a device doesn't have a hardware counter, the driver can simply
  757.          * return the value of drm_vblank_count. The DRM core will account for
  758.          * missed vblank events while interrupts where disabled based on system
  759.          * timestamps.
  760.          *
  761.          * Wraparound handling and loss of events due to modesetting is dealt
  762.          * with in the DRM core code.
  763.          *
  764.          * RETURNS
  765.          * Raw vblank counter value.
  766.          */
  767.         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  768.  
  769.         /**
  770.          * enable_vblank - enable vblank interrupt events
  771.          * @dev: DRM device
  772.          * @crtc: which irq to enable
  773.          *
  774.          * Enable vblank interrupts for @crtc.  If the device doesn't have
  775.          * a hardware vblank counter, this routine should be a no-op, since
  776.          * interrupts will have to stay on to keep the count accurate.
  777.          *
  778.          * RETURNS
  779.          * Zero on success, appropriate errno if the given @crtc's vblank
  780.          * interrupt cannot be enabled.
  781.          */
  782.         int (*enable_vblank) (struct drm_device *dev, int crtc);
  783.  
  784.         /**
  785.          * disable_vblank - disable vblank interrupt events
  786.          * @dev: DRM device
  787.          * @crtc: which irq to enable
  788.          *
  789.          * Disable vblank interrupts for @crtc.  If the device doesn't have
  790.          * a hardware vblank counter, this routine should be a no-op, since
  791.          * interrupts will have to stay on to keep the count accurate.
  792.          */
  793.         void (*disable_vblank) (struct drm_device *dev, int crtc);
  794.  
  795.         /**
  796.          * Called by \c drm_device_is_agp.  Typically used to determine if a
  797.          * card is really attached to AGP or not.
  798.          *
  799.          * \param dev  DRM device handle
  800.          *
  801.          * \returns
  802.          * One of three values is returned depending on whether or not the
  803.          * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
  804.          * (return of 1), or may or may not be AGP (return of 2).
  805.          */
  806.         int (*device_is_agp) (struct drm_device *dev);
  807.  
  808.         /**
  809.          * Called by vblank timestamping code.
  810.          *
  811.          * Return the current display scanout position from a crtc.
  812.          *
  813.          * \param dev  DRM device.
  814.          * \param crtc Id of the crtc to query.
  815.          * \param *vpos Target location for current vertical scanout position.
  816.          * \param *hpos Target location for current horizontal scanout position.
  817.          *
  818.          * Returns vpos as a positive number while in active scanout area.
  819.          * Returns vpos as a negative number inside vblank, counting the number
  820.          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  821.          * until start of active scanout / end of vblank."
  822.          *
  823.          * \return Flags, or'ed together as follows:
  824.          *
  825.          * DRM_SCANOUTPOS_VALID = Query successful.
  826.          * DRM_SCANOUTPOS_INVBL = Inside vblank.
  827.          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  828.          * this flag means that returned position may be offset by a constant
  829.          * but unknown small number of scanlines wrt. real scanout position.
  830.          *
  831.          */
  832.         int (*get_scanout_position) (struct drm_device *dev, int crtc,
  833.                                      int *vpos, int *hpos);
  834.  
  835.         /**
  836.          * Called by \c drm_get_last_vbltimestamp. Should return a precise
  837.          * timestamp when the most recent VBLANK interval ended or will end.
  838.          *
  839.          * Specifically, the timestamp in @vblank_time should correspond as
  840.          * closely as possible to the time when the first video scanline of
  841.          * the video frame after the end of VBLANK will start scanning out,
  842.          * the time immediately after end of the VBLANK interval. If the
  843.          * @crtc is currently inside VBLANK, this will be a time in the future.
  844.          * If the @crtc is currently scanning out a frame, this will be the
  845.          * past start time of the current scanout. This is meant to adhere
  846.          * to the OpenML OML_sync_control extension specification.
  847.          *
  848.          * \param dev dev DRM device handle.
  849.          * \param crtc crtc for which timestamp should be returned.
  850.          * \param *max_error Maximum allowable timestamp error in nanoseconds.
  851.          *                   Implementation should strive to provide timestamp
  852.          *                   with an error of at most *max_error nanoseconds.
  853.          *                   Returns true upper bound on error for timestamp.
  854.          * \param *vblank_time Target location for returned vblank timestamp.
  855.          * \param flags 0 = Defaults, no special treatment needed.
  856.          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  857.          *              irq handler. Some drivers need to apply some workarounds
  858.          *              for gpu-specific vblank irq quirks if flag is set.
  859.          *
  860.          * \returns
  861.          * Zero if timestamping isn't supported in current display mode or a
  862.          * negative number on failure. A positive status code on success,
  863.          * which describes how the vblank_time timestamp was computed.
  864.          */
  865.         int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
  866.                                      int *max_error,
  867.                                      struct timeval *vblank_time,
  868.                                      unsigned flags);
  869.  
  870.         /* these have to be filled in */
  871.  
  872.         irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  873.         void (*irq_preinstall) (struct drm_device *dev);
  874.         int (*irq_postinstall) (struct drm_device *dev);
  875.         void (*irq_uninstall) (struct drm_device *dev);
  876.         void (*set_version) (struct drm_device *dev,
  877.                              struct drm_set_version *sv);
  878.  
  879.         /* Master routines */
  880.         int (*master_create)(struct drm_device *dev, struct drm_master *master);
  881.         void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
  882.         /**
  883.          * master_set is called whenever the minor master is set.
  884.          * master_drop is called whenever the minor master is dropped.
  885.          */
  886.  
  887.         int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
  888.                           bool from_open);
  889.         void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
  890.                             bool from_release);
  891.  
  892.         int (*debugfs_init)(struct drm_minor *minor);
  893.         void (*debugfs_cleanup)(struct drm_minor *minor);
  894.  
  895.         /**
  896.          * Driver-specific constructor for drm_gem_objects, to set up
  897.          * obj->driver_private.
  898.          *
  899.          * Returns 0 on success.
  900.          */
  901.         int (*gem_init_object) (struct drm_gem_object *obj);
  902.         void (*gem_free_object) (struct drm_gem_object *obj);
  903.         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  904.         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  905.  
  906.         /* prime: */
  907.         /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  908.         int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  909.                                 uint32_t handle, uint32_t flags, int *prime_fd);
  910.         /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
  911.         int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
  912.                                 int prime_fd, uint32_t *handle);
  913.         /* export GEM -> dmabuf */
  914.         struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  915.                                 struct drm_gem_object *obj, int flags);
  916.         /* import dmabuf -> GEM */
  917.         struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  918.                                 struct dma_buf *dma_buf);
  919.  
  920.         /* vga arb irq handler */
  921.         void (*vgaarb_irq)(struct drm_device *dev, bool state);
  922.  
  923.         /* dumb alloc support */
  924.         int (*dumb_create)(struct drm_file *file_priv,
  925.                            struct drm_device *dev,
  926.                            struct drm_mode_create_dumb *args);
  927.         int (*dumb_map_offset)(struct drm_file *file_priv,
  928.                                struct drm_device *dev, uint32_t handle,
  929.                                uint64_t *offset);
  930.         int (*dumb_destroy)(struct drm_file *file_priv,
  931.                             struct drm_device *dev,
  932.                             uint32_t handle);
  933.  
  934.         /* Driver private ops for this object */
  935.         const struct vm_operations_struct *gem_vm_ops;
  936.  
  937.         int major;
  938.         int minor;
  939.         int patchlevel;
  940.         char *name;
  941.         char *desc;
  942.         char *date;
  943.  
  944.         u32 driver_features;
  945.         int dev_priv_size;
  946.         struct drm_ioctl_desc *ioctls;
  947.         int num_ioctls;
  948.         const struct file_operations *fops;
  949.         union {
  950.                 struct pci_driver *pci;
  951.                 struct platform_device *platform_device;
  952.                 struct usb_driver *usb;
  953.         } kdriver;
  954.         struct drm_bus *bus;
  955.  
  956.         /* List of devices hanging off this driver */
  957.         struct list_head device_list;
  958. };
  959.  
  960. #endif
  961.  
  962. #define DRM_IRQ_ARGS            int irq, void *arg
  963.  
  964. struct drm_driver {
  965.         int (*open) (struct drm_device *, struct drm_file *);
  966.  
  967.     irqreturn_t (*irq_handler) (DRM_IRQ_ARGS);
  968.     void (*irq_preinstall) (struct drm_device *dev);
  969.     int (*irq_postinstall) (struct drm_device *dev);
  970.  
  971.         int (*gem_init_object) (struct drm_gem_object *obj);
  972.         void (*gem_free_object) (struct drm_gem_object *obj);
  973.         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  974.         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  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 void drm_send_vblank_event(struct drm_device *dev, int crtc,
  1424.                                      struct drm_pending_vblank_event *e);
  1425. extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
  1426. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  1427. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  1428. extern void drm_vblank_off(struct drm_device *dev, int crtc);
  1429. extern void drm_vblank_cleanup(struct drm_device *dev);
  1430. extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
  1431.                                      struct timeval *tvblank, unsigned flags);
  1432. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  1433.                                                  int crtc, int *max_error,
  1434.                                                  struct timeval *vblank_time,
  1435.                                                  unsigned flags,
  1436.                                                  struct drm_crtc *refcrtc);
  1437. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
  1438.  
  1439. extern bool
  1440. drm_mode_parse_command_line_for_connector(const char *mode_option,
  1441.                                           struct drm_connector *connector,
  1442.                                           struct drm_cmdline_mode *mode);
  1443.  
  1444. extern struct drm_display_mode *
  1445. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  1446.                                   struct drm_cmdline_mode *cmd);
  1447.  
  1448. extern int drm_display_mode_from_videomode(const struct videomode *vm,
  1449.                                            struct drm_display_mode *dmode);
  1450. extern int of_get_drm_display_mode(struct device_node *np,
  1451.                                    struct drm_display_mode *dmode,
  1452.                                    int index);
  1453.  
  1454. /* Modesetting support */
  1455. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  1456. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  1457. extern int drm_modeset_ctl(struct drm_device *dev, void *data,
  1458.                            struct drm_file *file_priv);
  1459.  
  1460.                                 /* AGP/GART support (drm_agpsupport.h) */
  1461. extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
  1462. extern int drm_agp_acquire(struct drm_device *dev);
  1463. extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
  1464.                                  struct drm_file *file_priv);
  1465. extern int drm_agp_release(struct drm_device *dev);
  1466. extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
  1467.                                  struct drm_file *file_priv);
  1468. extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
  1469. extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
  1470.                                 struct drm_file *file_priv);
  1471. extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
  1472. extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
  1473.                         struct drm_file *file_priv);
  1474. extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
  1475. extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
  1476.                          struct drm_file *file_priv);
  1477. extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
  1478. extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
  1479.                         struct drm_file *file_priv);
  1480. extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
  1481. extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
  1482.                           struct drm_file *file_priv);
  1483. extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
  1484. extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
  1485.                         struct drm_file *file_priv);
  1486.  
  1487.                                 /* Stub support (drm_stub.h) */
  1488. extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
  1489.                                struct drm_file *file_priv);
  1490. extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
  1491.                                 struct drm_file *file_priv);
  1492. struct drm_master *drm_master_create(struct drm_minor *minor);
  1493. extern struct drm_master *drm_master_get(struct drm_master *master);
  1494. extern void drm_master_put(struct drm_master **master);
  1495.  
  1496. extern void drm_put_dev(struct drm_device *dev);
  1497. extern int drm_put_minor(struct drm_minor **minor);
  1498. extern void drm_unplug_dev(struct drm_device *dev);
  1499. #endif
  1500.  
  1501. extern unsigned int drm_debug;
  1502.  
  1503. #if 0
  1504. extern unsigned int drm_vblank_offdelay;
  1505. extern unsigned int drm_timestamp_precision;
  1506. extern unsigned int drm_timestamp_monotonic;
  1507.  
  1508. extern struct class *drm_class;
  1509. extern struct proc_dir_entry *drm_proc_root;
  1510. extern struct dentry *drm_debugfs_root;
  1511.  
  1512. extern struct idr drm_minors_idr;
  1513.  
  1514. extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
  1515.  
  1516.                                 /* Proc support (drm_proc.h) */
  1517. extern int drm_proc_init(struct drm_minor *minor, int minor_id,
  1518.                          struct proc_dir_entry *root);
  1519. extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
  1520.  
  1521.                                 /* Debugfs support */
  1522. #if defined(CONFIG_DEBUG_FS)
  1523. extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
  1524.                             struct dentry *root);
  1525. extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
  1526.                                     struct dentry *root, struct drm_minor *minor);
  1527. extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
  1528.                                     struct drm_minor *minor);
  1529. extern int drm_debugfs_cleanup(struct drm_minor *minor);
  1530. #endif
  1531.  
  1532.                                 /* Info file support */
  1533. extern int drm_name_info(struct seq_file *m, void *data);
  1534. extern int drm_vm_info(struct seq_file *m, void *data);
  1535. extern int drm_bufs_info(struct seq_file *m, void *data);
  1536. extern int drm_vblank_info(struct seq_file *m, void *data);
  1537. extern int drm_clients_info(struct seq_file *m, void* data);
  1538. extern int drm_gem_name_info(struct seq_file *m, void *data);
  1539.  
  1540. #if DRM_DEBUG_CODE
  1541. extern int drm_vma_info(struct seq_file *m, void *data);
  1542. #endif
  1543.  
  1544.                                 /* Scatter Gather Support (drm_scatter.h) */
  1545. extern void drm_sg_cleanup(struct drm_sg_mem * entry);
  1546. extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
  1547.                         struct drm_file *file_priv);
  1548. extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
  1549. extern int drm_sg_free(struct drm_device *dev, void *data,
  1550.                        struct drm_file *file_priv);
  1551.  
  1552.                                /* ATI PCIGART support (ati_pcigart.h) */
  1553. extern int drm_ati_pcigart_init(struct drm_device *dev,
  1554.                                 struct drm_ati_pcigart_info * gart_info);
  1555. extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
  1556.                                    struct drm_ati_pcigart_info * gart_info);
  1557. #endif
  1558.  
  1559. extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
  1560.                                        size_t align);
  1561. extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1562. extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  1563.  
  1564. #if 0
  1565.                                /* sysfs support (drm_sysfs.c) */
  1566. struct drm_sysfs_class;
  1567. extern struct class *drm_sysfs_create(struct module *owner, char *name);
  1568. extern void drm_sysfs_destroy(void);
  1569. extern int drm_sysfs_device_add(struct drm_minor *minor);
  1570. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  1571. extern void drm_sysfs_device_remove(struct drm_minor *minor);
  1572. extern char *drm_get_connector_status_name(enum drm_connector_status status);
  1573.  
  1574. static inline int drm_sysfs_connector_add(struct drm_connector *connector)
  1575. { return 0; };
  1576.  
  1577. static inline void drm_sysfs_connector_remove(struct drm_connector *connector)
  1578. { };
  1579.  
  1580. #endif
  1581.  
  1582. /* Graphics Execution Manager library functions (drm_gem.c) */
  1583. int drm_gem_init(struct drm_device *dev);
  1584. void drm_gem_destroy(struct drm_device *dev);
  1585. void drm_gem_object_release(struct drm_gem_object *obj);
  1586. void drm_gem_object_free(struct kref *kref);
  1587. struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
  1588.                                             size_t size);
  1589. int drm_gem_object_init(struct drm_device *dev,
  1590.                         struct drm_gem_object *obj, size_t size);
  1591. int drm_gem_private_object_init(struct drm_device *dev,
  1592.                         struct drm_gem_object *obj, size_t size);
  1593. void drm_gem_object_handle_free(struct drm_gem_object *obj);
  1594. void drm_gem_vm_open(struct vm_area_struct *vma);
  1595. void drm_gem_vm_close(struct vm_area_struct *vma);
  1596. int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  1597.  
  1598.  
  1599. static inline void
  1600. drm_gem_object_reference(struct drm_gem_object *obj)
  1601. {
  1602.         kref_get(&obj->refcount);
  1603. }
  1604.  
  1605. static inline void
  1606. drm_gem_object_unreference(struct drm_gem_object *obj)
  1607. {
  1608.         if (obj != NULL)
  1609.                 kref_put(&obj->refcount, drm_gem_object_free);
  1610. }
  1611.  
  1612. static inline void
  1613. drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
  1614. {
  1615.         if (obj != NULL) {
  1616.                 struct drm_device *dev = obj->dev;
  1617.                 mutex_lock(&dev->struct_mutex);
  1618.         kref_put(&obj->refcount, drm_gem_object_free);
  1619.                 mutex_unlock(&dev->struct_mutex);
  1620.         }
  1621. }
  1622.  
  1623. int drm_gem_handle_create(struct drm_file *file_priv,
  1624.                           struct drm_gem_object *obj,
  1625.                           u32 *handlep);
  1626. int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
  1627.  
  1628. static inline void
  1629. drm_gem_object_handle_reference(struct drm_gem_object *obj)
  1630. {
  1631.         drm_gem_object_reference(obj);
  1632.         atomic_inc(&obj->handle_count);
  1633. }
  1634.  
  1635. static inline void
  1636. drm_gem_object_handle_unreference(struct drm_gem_object *obj)
  1637. {
  1638.         if (obj == NULL)
  1639.                 return;
  1640.  
  1641.         if (atomic_read(&obj->handle_count) == 0)
  1642.                 return;
  1643.         /*
  1644.          * Must bump handle count first as this may be the last
  1645.          * ref, in which case the object would disappear before we
  1646.          * checked for a name
  1647.          */
  1648.         if (atomic_dec_and_test(&obj->handle_count))
  1649.                 drm_gem_object_handle_free(obj);
  1650.         drm_gem_object_unreference(obj);
  1651. }
  1652.  
  1653. static inline void
  1654. drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
  1655. {
  1656.         if (obj == NULL)
  1657.                 return;
  1658.  
  1659.         if (atomic_read(&obj->handle_count) == 0)
  1660.                 return;
  1661.  
  1662.         /*
  1663.         * Must bump handle count first as this may be the last
  1664.         * ref, in which case the object would disappear before we
  1665.         * checked for a name
  1666.         */
  1667.  
  1668.         if (atomic_dec_and_test(&obj->handle_count))
  1669.                 drm_gem_object_handle_free(obj);
  1670.         drm_gem_object_unreference_unlocked(obj);
  1671. }
  1672.  
  1673. void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
  1674. int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
  1675.  
  1676. struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
  1677.                                              struct drm_file *filp,
  1678.                                              u32 handle);
  1679. int drm_gem_close_ioctl(struct drm_device *dev, void *data,
  1680.                         struct drm_file *file_priv);
  1681. int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  1682.                         struct drm_file *file_priv);
  1683. int drm_gem_open_ioctl(struct drm_device *dev, void *data,
  1684.                        struct drm_file *file_priv);
  1685. void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
  1686. void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
  1687.  
  1688. extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
  1689. extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  1690. extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  1691.  
  1692. #if 0
  1693.  
  1694. static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
  1695.                                                          unsigned int token)
  1696. {
  1697.         struct drm_map_list *_entry;
  1698.         list_for_each_entry(_entry, &dev->maplist, head)
  1699.             if (_entry->user_token == token)
  1700.                 return _entry->map;
  1701.         return NULL;
  1702. }
  1703.  
  1704. static __inline__ void drm_core_dropmap(struct drm_local_map *map)
  1705. {
  1706. }
  1707.  
  1708.  
  1709.  
  1710. static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
  1711. {
  1712.         if (size * nmemb <= PAGE_SIZE)
  1713.             return kcalloc(nmemb, size, GFP_KERNEL);
  1714.  
  1715.         if (size != 0 && nmemb > ULONG_MAX / size)
  1716.                 return NULL;
  1717.  
  1718.         return __vmalloc(size * nmemb,
  1719.                          GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
  1720. }
  1721.  
  1722. static __inline void drm_free_large(void *ptr)
  1723. {
  1724.         if (!is_vmalloc_addr(ptr))
  1725.                 return kfree(ptr);
  1726.  
  1727.         vfree(ptr);
  1728. }
  1729.  
  1730. #endif
  1731.  
  1732. #define DRM_PCIE_SPEED_25 1
  1733. #define DRM_PCIE_SPEED_50 2
  1734. #define DRM_PCIE_SPEED_80 4
  1735.  
  1736. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  1737.  
  1738. static __inline__ int drm_device_is_agp(struct drm_device *dev)
  1739. {
  1740.     return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  1741. }
  1742.  
  1743. static __inline__ int drm_device_is_pcie(struct drm_device *dev)
  1744. {
  1745.     return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  1746. }
  1747. #endif                          /* __KERNEL__ */
  1748.  
  1749. #define drm_sysfs_connector_add(connector)
  1750. #define drm_sysfs_connector_remove(connector)
  1751.  
  1752. #define LFB_SIZE 0xC00000
  1753.  
  1754. #endif
  1755.