Subversion Repositories Kolibri OS

Rev

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

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