Subversion Repositories Kolibri OS

Rev

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