Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Internal Header for the Direct Rendering Manager
  3.  *
  4.  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5.  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6.  * Copyright (c) 2009-2010, Code Aurora Forum.
  7.  * All rights reserved.
  8.  *
  9.  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
  10.  * Author: Gareth Hughes <gareth@valinux.com>
  11.  *
  12.  * Permission is hereby granted, free of charge, to any person obtaining a
  13.  * copy of this software and associated documentation files (the "Software"),
  14.  * to deal in the Software without restriction, including without limitation
  15.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  16.  * and/or sell copies of the Software, and to permit persons to whom the
  17.  * Software is furnished to do so, subject to the following conditions:
  18.  *
  19.  * The above copyright notice and this permission notice (including the next
  20.  * paragraph) shall be included in all copies or substantial portions of the
  21.  * Software.
  22.  *
  23.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  26.  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29.  * OTHER DEALINGS IN THE SOFTWARE.
  30.  */
  31.  
  32. #ifndef _DRM_P_H_
  33. #define _DRM_P_H_
  34.  
  35. #include <syscall.h>
  36. #include <linux/agp_backend.h>
  37.  
  38. #include <linux/dma-mapping.h>
  39. #include <linux/file.h>
  40. #include <linux/fs.h>
  41. #include <linux/idr.h>
  42. #include <linux/jiffies.h>
  43. #include <linux/kernel.h>
  44. #include <linux/kref.h>
  45. #include <linux/mm.h>
  46.  
  47. #include <linux/spinlock.h>
  48. #include <linux/wait.h>
  49. #include <linux/bug.h>
  50. #include <linux/mutex.h>
  51. #include <linux/pci.h>
  52. #include <linux/sched.h>
  53.  
  54. #include <linux/firmware.h>
  55. #include <linux/err.h>
  56.  
  57.  
  58. #include <linux/irqreturn.h>
  59. #include <linux/slab.h>
  60. #include <linux/types.h>
  61. #include <linux/vmalloc.h>
  62. #include <linux/workqueue.h>
  63.  
  64. #include <uapi/drm/drm.h>
  65. #include <uapi/drm/drm_mode.h>
  66.  
  67. #include <drm/drm_agpsupport.h>
  68. #include <drm/drm_crtc.h>
  69. #include <drm/drm_global.h>
  70. #include <drm/drm_hashtab.h>
  71. #include <drm/drm_mem_util.h>
  72. #include <drm/drm_mm.h>
  73. #include <drm/drm_os_linux.h>
  74. #include <drm/drm_sarea.h>
  75. #include <drm/drm_vma_manager.h>
  76.  
  77. struct module;
  78.  
  79. struct drm_file;
  80. struct drm_device;
  81. struct drm_agp_head;
  82. struct drm_local_map;
  83. struct drm_device_dma;
  84. struct drm_dma_handle;
  85. struct drm_gem_object;
  86.  
  87. struct device_node;
  88. struct videomode;
  89. struct reservation_object;
  90. struct dma_buf_attachment;
  91.  
  92. struct inode;
  93. struct poll_table_struct;
  94. struct sg_table;
  95.  
  96. #define KHZ2PICOS(a) (1000000000UL/(a))
  97.  
  98. /*
  99.  * 4 debug categories are defined:
  100.  *
  101.  * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
  102.  *       This is the category used by the DRM_DEBUG() macro.
  103.  *
  104.  * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
  105.  *         This is the category used by the DRM_DEBUG_DRIVER() macro.
  106.  *
  107.  * KMS: used in the modesetting code.
  108.  *      This is the category used by the DRM_DEBUG_KMS() macro.
  109.  *
  110.  * PRIME: used in the prime code.
  111.  *        This is the category used by the DRM_DEBUG_PRIME() macro.
  112.  *
  113.  * Enabling verbose debug messages is done through the drm.debug parameter,
  114.  * each category being enabled by a bit.
  115.  *
  116.  * drm.debug=0x1 will enable CORE messages
  117.  * drm.debug=0x2 will enable DRIVER messages
  118.  * drm.debug=0x3 will enable CORE and DRIVER messages
  119.  * ...
  120.  * drm.debug=0xf will enable all messages
  121.  *
  122.  * An interesting feature is that it's possible to enable verbose logging at
  123.  * run-time by echoing the debug value in its sysfs node:
  124.  *   # echo 0xf > /sys/module/drm/parameters/debug
  125.  */
  126. #define DRM_UT_CORE             0x01
  127. #define DRM_UT_DRIVER           0x02
  128. #define DRM_UT_KMS          0x04
  129. #define DRM_UT_PRIME            0x08
  130.  
  131. extern __printf(2, 3)
  132. void drm_ut_debug_printk(const char *function_name,
  133.                                 const char *format, ...);
  134. extern __printf(1, 2)
  135. void drm_err(const char *format, ...);
  136.  
  137. /***********************************************************************/
  138. /** \name DRM template customization defaults */
  139. /*@{*/
  140.  
  141. /* driver capabilities and requirements mask */
  142. #define DRIVER_USE_AGP     0x1
  143. #define DRIVER_PCI_DMA     0x8
  144. #define DRIVER_SG          0x10
  145. #define DRIVER_HAVE_DMA    0x20
  146. #define DRIVER_HAVE_IRQ    0x40
  147. #define DRIVER_IRQ_SHARED  0x80
  148. #define DRIVER_GEM         0x1000
  149. #define DRIVER_MODESET     0x2000
  150. #define DRIVER_PRIME       0x4000
  151. #define DRIVER_RENDER      0x8000
  152.  
  153. /***********************************************************************/
  154. /** \name Macros to make printk easier */
  155. /*@{*/
  156.  
  157. /**
  158.  * Error output.
  159.  *
  160.  * \param fmt printf() like format string.
  161.  * \param arg arguments
  162.  */
  163. #define DRM_ERROR(fmt, ...)                             \
  164.         drm_err(fmt, ##__VA_ARGS__)
  165.  
  166. /**
  167.  * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
  168.  *
  169.  * \param fmt printf() like format string.
  170.  * \param arg arguments
  171.  */
  172. #define DRM_ERROR_RATELIMITED(fmt, ...)                         \
  173. ({                                                                      \
  174.         static DEFINE_RATELIMIT_STATE(_rs,                              \
  175.                                       DEFAULT_RATELIMIT_INTERVAL,       \
  176.                                       DEFAULT_RATELIMIT_BURST);         \
  177.                                                                         \
  178.         if (__ratelimit(&_rs))                                          \
  179.                 drm_err(fmt, ##__VA_ARGS__);                            \
  180. })
  181.  
  182. #define DRM_INFO(fmt, ...)                              \
  183.         printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  184.  
  185. #define DRM_INFO_ONCE(fmt, ...)                         \
  186.         printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
  187.  
  188. /**
  189.  * Debug output.
  190.  *
  191.  * \param fmt printf() like format string.
  192.  * \param arg arguments
  193.  */
  194. #if DRM_DEBUG_CODE
  195. #define DRM_DEBUG(fmt, args...)                                         \
  196.     do {                                                    \
  197.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
  198.         } while (0)
  199.  
  200. #define DRM_DEBUG_DRIVER(fmt, args...)                                  \
  201.     do {                                                    \
  202.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
  203.         } while (0)
  204. #define DRM_DEBUG_KMS(fmt, args...)                                     \
  205.         do {                                                            \
  206.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
  207.         } while (0)
  208. #define DRM_DEBUG_PRIME(fmt, args...)                                   \
  209.         do {                                                            \
  210.     printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args);  \
  211.         } while (0)
  212. #else
  213. #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
  214. #define DRM_DEBUG_KMS(fmt, args...)     do { } while (0)
  215. #define DRM_DEBUG_PRIME(fmt, args...)   do { } while (0)
  216. #define DRM_DEBUG(fmt, arg...)           do { } while (0)
  217. #endif
  218.  
  219. /*@}*/
  220.  
  221. /***********************************************************************/
  222. /** \name Internal types and structures */
  223. /*@{*/
  224.  
  225. #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
  226.  
  227. /**
  228.  * Ioctl function type.
  229.  *
  230.  * \param inode device inode.
  231.  * \param file_priv DRM file private pointer.
  232.  * \param cmd command.
  233.  * \param arg argument.
  234.  */
  235. typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  236.                         struct drm_file *file_priv);
  237.  
  238. typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
  239.                                unsigned long arg);
  240.  
  241. #define DRM_IOCTL_NR(n)                _IOC_NR(n)
  242. #define DRM_MAJOR       226
  243.  
  244. #define DRM_AUTH        0x1
  245. #define DRM_MASTER      0x2
  246. #define DRM_ROOT_ONLY   0x4
  247. #define DRM_CONTROL_ALLOW 0x8
  248. #define DRM_UNLOCKED    0x10
  249. #define DRM_RENDER_ALLOW 0x20
  250.  
  251. struct drm_ioctl_desc {
  252.         unsigned int cmd;
  253.         int flags;
  254.         drm_ioctl_t *func;
  255.         unsigned int cmd_drv;
  256.         const char *name;
  257. };
  258.  
  259. /**
  260.  * Creates a driver or general drm_ioctl_desc array entry for the given
  261.  * ioctl, for use by drm_ioctl().
  262.  */
  263.  
  264. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                 \
  265.         [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
  266.  
  267. /* Event queued up for userspace to read */
  268. struct drm_pending_event {
  269.         struct drm_event *event;
  270.         struct list_head link;
  271.         struct drm_file *file_priv;
  272.         pid_t pid; /* pid of requester, no guarantee it's valid by the time
  273.                       we deliver the event, for tracing only */
  274.         void (*destroy)(struct drm_pending_event *event);
  275. };
  276.  
  277. /* initial implementaton using a linked list - todo hashtab */
  278. struct drm_prime_file_private {
  279.         struct list_head head;
  280.         struct mutex lock;
  281. };
  282.  
  283. /** File private data */
  284. struct drm_file {
  285.         unsigned authenticated :1;
  286.         /* Whether we're master for a minor. Protected by master_mutex */
  287.         unsigned is_master :1;
  288.         /* true when the client has asked us to expose stereo 3D mode flags */
  289.         unsigned stereo_allowed :1;
  290.         /*
  291.          * true if client understands CRTC primary planes and cursor planes
  292.          * in the plane list
  293.          */
  294.         unsigned universal_planes:1;
  295.         struct list_head lhead;
  296.         unsigned long lock_count;
  297.  
  298.         /** Mapping of mm object handles to object pointers. */
  299.         struct idr object_idr;
  300.         /** Lock for synchronization of access to object_idr. */
  301.         spinlock_t table_lock;
  302.  
  303.         void *driver_priv;
  304.  
  305.         struct drm_master *master; /* master this node is currently associated with
  306.                                       N.B. not always minor->master */
  307.         /**
  308.          * fbs - List of framebuffers associated with this file.
  309.          *
  310.          * Protected by fbs_lock. Note that the fbs list holds a reference on
  311.          * the fb object to prevent it from untimely disappearing.
  312.          */
  313.         struct list_head fbs;
  314.         struct mutex fbs_lock;
  315.  
  316.         wait_queue_head_t event_wait;
  317.         struct list_head event_list;
  318.         int event_space;
  319. };
  320.  
  321. /**
  322.  * Lock data.
  323.  */
  324. struct drm_lock_data {
  325.         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
  326.         /** Private of lock holder's file (NULL=kernel) */
  327.         struct drm_file *file_priv;
  328.         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
  329.         unsigned long lock_time;        /**< Time of last lock in jiffies */
  330.         spinlock_t spinlock;
  331.         uint32_t kernel_waiters;
  332.         uint32_t user_waiters;
  333.         int idle_has_lock;
  334. };
  335.  
  336. /**
  337.  * struct drm_master - drm master structure
  338.  *
  339.  * @refcount: Refcount for this master object.
  340.  * @minor: Link back to minor char device we are master for. Immutable.
  341.  * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
  342.  * @unique_len: Length of unique field. Protected by drm_global_mutex.
  343.  * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
  344.  * @magicfree: List of used authentication tokens. Protected by struct_mutex.
  345.  * @lock: DRI lock information.
  346.  * @driver_priv: Pointer to driver-private information.
  347.  */
  348. struct drm_master {
  349.         struct kref refcount;
  350.         struct drm_minor *minor;
  351.         char *unique;
  352.         int unique_len;
  353.         struct drm_open_hash magiclist;
  354.         struct list_head magicfree;
  355.         struct drm_lock_data lock;
  356.         void *driver_priv;
  357. };
  358.  
  359. /* Size of ringbuffer for vblank timestamps. Just double-buffer
  360.  * in initial implementation.
  361.  */
  362. #define DRM_VBLANKTIME_RBSIZE 2
  363.  
  364. /* Flags and return codes for get_vblank_timestamp() driver function. */
  365. #define DRM_CALLED_FROM_VBLIRQ 1
  366. #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
  367. #define DRM_VBLANKTIME_IN_VBLANK         (1 << 1)
  368.  
  369. /* get_scanout_position() return flags */
  370. #define DRM_SCANOUTPOS_VALID        (1 << 0)
  371. #define DRM_SCANOUTPOS_IN_VBLANK    (1 << 1)
  372. #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
  373.  
  374. /**
  375.  * DRM driver structure. This structure represent the common code for
  376.  * a family of cards. There will one drm_device for each card present
  377.  * in this family
  378.  */
  379. struct drm_driver {
  380.         int (*load) (struct drm_device *, unsigned long flags);
  381.         int (*open) (struct drm_device *, struct drm_file *);
  382.  
  383.         /**
  384.          * get_vblank_counter - get raw hardware vblank counter
  385.          * @dev: DRM device
  386.          * @crtc: counter to fetch
  387.          *
  388.          * Driver callback for fetching a raw hardware vblank counter for @crtc.
  389.          * If a device doesn't have a hardware counter, the driver can simply
  390.          * return the value of drm_vblank_count. The DRM core will account for
  391.          * missed vblank events while interrupts where disabled based on system
  392.          * timestamps.
  393.          *
  394.          * Wraparound handling and loss of events due to modesetting is dealt
  395.          * with in the DRM core code.
  396.          *
  397.          * RETURNS
  398.          * Raw vblank counter value.
  399.          */
  400.         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
  401.  
  402.         /**
  403.          * enable_vblank - enable vblank interrupt events
  404.          * @dev: DRM device
  405.          * @crtc: which irq to enable
  406.          *
  407.          * Enable vblank interrupts for @crtc.  If the device doesn't have
  408.          * a hardware vblank counter, this routine should be a no-op, since
  409.          * interrupts will have to stay on to keep the count accurate.
  410.          *
  411.          * RETURNS
  412.          * Zero on success, appropriate errno if the given @crtc's vblank
  413.          * interrupt cannot be enabled.
  414.          */
  415.         int (*enable_vblank) (struct drm_device *dev, int crtc);
  416.  
  417.         /**
  418.          * disable_vblank - disable vblank interrupt events
  419.          * @dev: DRM device
  420.          * @crtc: which irq to enable
  421.          *
  422.          * Disable vblank interrupts for @crtc.  If the device doesn't have
  423.          * a hardware vblank counter, this routine should be a no-op, since
  424.          * interrupts will have to stay on to keep the count accurate.
  425.          */
  426.         void (*disable_vblank) (struct drm_device *dev, int crtc);
  427.         /**
  428.          * Called by vblank timestamping code.
  429.          *
  430.          * Return the current display scanout position from a crtc, and an
  431.          * optional accurate ktime_get timestamp of when position was measured.
  432.          *
  433.          * \param dev  DRM device.
  434.          * \param crtc Id of the crtc to query.
  435.          * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
  436.          * \param *vpos Target location for current vertical scanout position.
  437.          * \param *hpos Target location for current horizontal scanout position.
  438.          * \param *stime Target location for timestamp taken immediately before
  439.          *               scanout position query. Can be NULL to skip timestamp.
  440.          * \param *etime Target location for timestamp taken immediately after
  441.          *               scanout position query. Can be NULL to skip timestamp.
  442.          *
  443.          * Returns vpos as a positive number while in active scanout area.
  444.          * Returns vpos as a negative number inside vblank, counting the number
  445.          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  446.          * until start of active scanout / end of vblank."
  447.          *
  448.          * \return Flags, or'ed together as follows:
  449.          *
  450.          * DRM_SCANOUTPOS_VALID = Query successful.
  451.          * DRM_SCANOUTPOS_INVBL = Inside vblank.
  452.          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  453.          * this flag means that returned position may be offset by a constant
  454.          * but unknown small number of scanlines wrt. real scanout position.
  455.          *
  456.          */
  457.         int (*get_scanout_position) (struct drm_device *dev, int crtc,
  458.                                      unsigned int flags,
  459.                      int *vpos, int *hpos, void *stime,
  460.                      void *etime);
  461.  
  462.         /**
  463.          * Called by \c drm_get_last_vbltimestamp. Should return a precise
  464.          * timestamp when the most recent VBLANK interval ended or will end.
  465.          *
  466.          * Specifically, the timestamp in @vblank_time should correspond as
  467.          * closely as possible to the time when the first video scanline of
  468.          * the video frame after the end of VBLANK will start scanning out,
  469.          * the time immediately after end of the VBLANK interval. If the
  470.          * @crtc is currently inside VBLANK, this will be a time in the future.
  471.          * If the @crtc is currently scanning out a frame, this will be the
  472.          * past start time of the current scanout. This is meant to adhere
  473.          * to the OpenML OML_sync_control extension specification.
  474.          *
  475.          * \param dev dev DRM device handle.
  476.          * \param crtc crtc for which timestamp should be returned.
  477.          * \param *max_error Maximum allowable timestamp error in nanoseconds.
  478.          *                   Implementation should strive to provide timestamp
  479.          *                   with an error of at most *max_error nanoseconds.
  480.          *                   Returns true upper bound on error for timestamp.
  481.          * \param *vblank_time Target location for returned vblank timestamp.
  482.          * \param flags 0 = Defaults, no special treatment needed.
  483.          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
  484.          *              irq handler. Some drivers need to apply some workarounds
  485.          *              for gpu-specific vblank irq quirks if flag is set.
  486.          *
  487.          * \returns
  488.          * Zero if timestamping isn't supported in current display mode or a
  489.          * negative number on failure. A positive status code on success,
  490.          * which describes how the vblank_time timestamp was computed.
  491.          */
  492.         int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
  493.                                      int *max_error,
  494.                                      struct timeval *vblank_time,
  495.                                      unsigned flags);
  496.  
  497.         /* these have to be filled in */
  498.  
  499.         irqreturn_t(*irq_handler) (int irq, void *arg);
  500.         void (*irq_preinstall) (struct drm_device *dev);
  501.         int (*irq_postinstall) (struct drm_device *dev);
  502.         void (*irq_uninstall) (struct drm_device *dev);
  503.  
  504.         /**
  505.          * Driver-specific constructor for drm_gem_objects, to set up
  506.          * obj->driver_private.
  507.          *
  508.          * Returns 0 on success.
  509.          */
  510.         void (*gem_free_object) (struct drm_gem_object *obj);
  511.         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  512.         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  513.         u32 driver_features;
  514.         int dev_priv_size;
  515. };
  516.  
  517. enum drm_minor_type {
  518.         DRM_MINOR_LEGACY,
  519.         DRM_MINOR_CONTROL,
  520.         DRM_MINOR_RENDER,
  521.         DRM_MINOR_CNT,
  522. };
  523.  
  524. /**
  525.  * Info file list entry. This structure represents a debugfs or proc file to
  526.  * be created by the drm core
  527.  */
  528. struct drm_info_list {
  529.         const char *name; /** file name */
  530. //   int (*show)(struct seq_file*, void*); /** show callback */
  531.         u32 driver_features; /**< Required driver features for this entry */
  532.         void *data;
  533. };
  534.  
  535. /**
  536.  * debugfs node structure. This structure represents a debugfs file.
  537.  */
  538. struct drm_info_node {
  539.         struct list_head list;
  540.         struct drm_minor *minor;
  541.         const struct drm_info_list *info_ent;
  542.         struct dentry *dent;
  543. };
  544.  
  545. /**
  546.  * DRM minor structure. This structure represents a drm minor number.
  547.  */
  548. struct drm_minor {
  549.         int index;                      /**< Minor device number */
  550.         int type;                       /**< Control or render */
  551. //   struct device kdev;     /**< Linux device */
  552.         struct drm_device *dev;
  553.  
  554.         struct dentry *debugfs_root;
  555.  
  556.         struct list_head debugfs_list;
  557.         struct mutex debugfs_lock; /* Protects debugfs_list. */
  558.  
  559.         /* currently active master for this node. Protected by master_mutex */
  560.         struct drm_master *master;
  561.         struct drm_mode_group mode_group;
  562. };
  563.  
  564.  
  565. struct drm_pending_vblank_event {
  566.         struct drm_pending_event base;
  567.         int pipe;
  568.         struct drm_event_vblank event;
  569. };
  570.  
  571. struct drm_vblank_crtc {
  572.         struct drm_device *dev;         /* pointer to the drm_device */
  573.         wait_queue_head_t queue;        /**< VBLANK wait queue */
  574.         struct timeval time[DRM_VBLANKTIME_RBSIZE];     /**< timestamp of current count */
  575.         struct timer_list disable_timer;                /* delayed disable timer */
  576.         atomic_t count;                 /**< number of VBLANK interrupts */
  577.         atomic_t refcount;              /* number of users of vblank interruptsper crtc */
  578.         u32 last;                       /* protected by dev->vbl_lock, used */
  579.                                         /* for wraparound handling */
  580.         u32 last_wait;                  /* Last vblank seqno waited per CRTC */
  581.         unsigned int inmodeset;         /* Display driver is setting mode */
  582.         int crtc;                       /* crtc index */
  583.         bool enabled;                   /* so we don't call enable more than
  584.                                            once per disable */
  585. };
  586.  
  587. /**
  588.  * DRM device structure. This structure represent a complete card that
  589.  * may contain multiple heads.
  590.  */
  591. struct drm_device {
  592.         struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
  593.         int if_version;                 /**< Highest interface version set */
  594.  
  595.         /** \name Lifetime Management */
  596.         /*@{ */
  597.         struct kref ref;                /**< Object ref-count */
  598.         struct device *dev;             /**< Device structure of bus-device */
  599.         struct drm_driver *driver;      /**< DRM driver managing the device */
  600.         void *dev_private;              /**< DRM driver private data */
  601.         struct drm_minor *primary;              /**< Primary node */
  602.         atomic_t unplugged;                     /**< Flag whether dev is dead */
  603.         /** \name Locks */
  604.         /*@{ */
  605.         struct mutex struct_mutex;      /**< For others */
  606.         struct mutex master_mutex;      /**< For drm_minor::master and drm_file::is_master */
  607.         /*@} */
  608.  
  609.         /** \name Usage Counters */
  610.         /*@{ */
  611.         int open_count;                 /**< Outstanding files open, protected by drm_global_mutex. */
  612.         spinlock_t buf_lock;            /**< For drm_device::buf_use and a few other things. */
  613.         int buf_use;                    /**< Buffers in use -- cannot alloc */
  614.    atomic_t buf_alloc;     /**< Buffer allocation in progress */
  615.         /*@} */
  616.  
  617.         struct list_head filelist;
  618.  
  619.         /** \name Memory management */
  620.         /*@{ */
  621.         struct list_head maplist;       /**< Linked list of regions */
  622.  
  623.         /** \name Context handle management */
  624.         /*@{ */
  625.         struct list_head ctxlist;       /**< Linked list of context handles */
  626.         struct mutex ctxlist_mutex;     /**< For ctxlist */
  627.  
  628.         struct idr ctx_idr;
  629.  
  630.         struct list_head vmalist;       /**< List of vmas (for debugging) */
  631.  
  632.         /*@} */
  633.  
  634.         /** \name DMA support */
  635.         /*@{ */
  636. //   struct drm_device_dma *dma;     /**< Optional pointer for DMA support */
  637.         /*@} */
  638.  
  639.         /** \name Context support */
  640.         /*@{ */
  641.         bool irq_enabled;               /**< True if irq handler is enabled */
  642.         int irq;
  643.  
  644.         __volatile__ long context_flag; /**< Context swapping flag */
  645.         int last_context;               /**< Last current context */
  646.         /*@} */
  647.  
  648.         /** \name VBLANK IRQ support */
  649.         /*@{ */
  650.  
  651.         /*
  652.          * At load time, disabling the vblank interrupt won't be allowed since
  653.          * old clients may not call the modeset ioctl and therefore misbehave.
  654.          * Once the modeset ioctl *has* been called though, we can safely
  655.          * disable them when unused.
  656.          */
  657.         bool vblank_disable_allowed;
  658.  
  659.         /*
  660.          * If true, vblank interrupt will be disabled immediately when the
  661.          * refcount drops to zero, as opposed to via the vblank disable
  662.          * timer.
  663.          * This can be set to true it the hardware has a working vblank
  664.          * counter and the driver uses drm_vblank_on() and drm_vblank_off()
  665.          * appropriately.
  666.          */
  667.         bool vblank_disable_immediate;
  668.  
  669.         /* array of size num_crtcs */
  670.         struct drm_vblank_crtc *vblank;
  671.  
  672.         spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
  673.         spinlock_t vbl_lock;
  674.  
  675.         u32 max_vblank_count;           /**< size of vblank counter register */
  676.  
  677.         /**
  678.          * List of events
  679.          */
  680.         struct list_head vblank_event_list;
  681.         spinlock_t event_lock;
  682.  
  683.         /*@} */
  684.  
  685. //   struct drm_agp_head *agp;   /**< AGP data */
  686.  
  687.         struct pci_dev *pdev;           /**< PCI device structure */
  688.  
  689.         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
  690.  
  691.         struct {
  692.                 int context;
  693.                 struct drm_hw_lock *lock;
  694.         } sigdata;
  695.  
  696.         struct drm_mode_config mode_config;     /**< Current mode config */
  697.  
  698.         /** \name GEM information */
  699.         /*@{ */
  700.         struct mutex object_name_lock;
  701.         struct idr object_name_idr;
  702.         struct drm_vma_offset_manager *vma_offset_manager;
  703.         /*@} */
  704.         int switch_power_state;
  705. };
  706.  
  707. #define DRM_SWITCH_POWER_ON 0
  708. #define DRM_SWITCH_POWER_OFF 1
  709. #define DRM_SWITCH_POWER_CHANGING 2
  710. #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
  711.  
  712. static __inline__ int drm_core_check_feature(struct drm_device *dev,
  713.                                              int feature)
  714. {
  715.         return ((dev->driver->driver_features & feature) ? 1 : 0);
  716. }
  717.  
  718. static inline void drm_device_set_unplugged(struct drm_device *dev)
  719. {
  720.         smp_wmb();
  721.         atomic_set(&dev->unplugged, 1);
  722. }
  723.  
  724. static inline int drm_device_is_unplugged(struct drm_device *dev)
  725. {
  726.         int ret = atomic_read(&dev->unplugged);
  727.         smp_rmb();
  728.         return ret;
  729. }
  730.  
  731.  
  732. /******************************************************************/
  733. /** \name Internal function definitions */
  734. /*@{*/
  735.  
  736.                                 /* Driver support (drm_drv.h) */
  737. extern long drm_ioctl(struct file *filp,
  738.                      unsigned int cmd, unsigned long arg);
  739. extern long drm_compat_ioctl(struct file *filp,
  740.                              unsigned int cmd, unsigned long arg);
  741. extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  742.  
  743.                                 /* Device support (drm_fops.h) */
  744. extern int drm_open(struct inode *inode, struct file *filp);
  745. extern ssize_t drm_read(struct file *filp, char __user *buffer,
  746.                         size_t count, loff_t *offset);
  747. extern int drm_release(struct inode *inode, struct file *filp);
  748.  
  749.                                 /* Mapping support (drm_vm.h) */
  750. extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
  751.  
  752. /* Misc. IOCTL support (drm_ioctl.c) */
  753. int drm_noop(struct drm_device *dev, void *data,
  754.                          struct drm_file *file_priv);
  755.  
  756. /* Cache management (drm_cache.c) */
  757. void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
  758. void drm_clflush_sg(struct sg_table *st);
  759. void drm_clflush_virt_range(void *addr, unsigned long length);
  760.  
  761. /*
  762.  * These are exported to drivers so that they can implement fencing using
  763.  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  764.  */
  765.  
  766.                                 /* IRQ support (drm_irq.h) */
  767. extern int drm_irq_install(struct drm_device *dev, int irq);
  768. extern int drm_irq_uninstall(struct drm_device *dev);
  769.  
  770. extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
  771. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  772.                            struct drm_file *filp);
  773. extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
  774. extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
  775.                                      struct timeval *vblanktime);
  776. extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
  777.                                      struct drm_pending_vblank_event *e);
  778. extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
  779. extern int drm_vblank_get(struct drm_device *dev, int crtc);
  780. extern void drm_vblank_put(struct drm_device *dev, int crtc);
  781. extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
  782. extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
  783. extern void drm_wait_one_vblank(struct drm_device *dev, int crtc);
  784. extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
  785. extern void drm_vblank_off(struct drm_device *dev, int crtc);
  786. extern void drm_vblank_on(struct drm_device *dev, int crtc);
  787. extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
  788. extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
  789. extern void drm_vblank_cleanup(struct drm_device *dev);
  790.  
  791. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  792.                                                  int crtc, int *max_error,
  793.                                                  struct timeval *vblank_time,
  794.                                                  unsigned flags,
  795.                                                  const struct drm_crtc *refcrtc,
  796.                                                  const struct drm_display_mode *mode);
  797. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
  798.                                             const struct drm_display_mode *mode);
  799.  
  800. /**
  801.  * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
  802.  * @crtc: which CRTC's vblank waitqueue to retrieve
  803.  *
  804.  * This function returns a pointer to the vblank waitqueue for the CRTC.
  805.  * Drivers can use this to implement vblank waits using wait_event() & co.
  806.  */
  807. static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
  808. {
  809.         return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
  810. }
  811.  
  812. /* Modesetting support */
  813. extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
  814. extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
  815.  
  816.                                 /* Stub support (drm_stub.h) */
  817. extern struct drm_master *drm_master_get(struct drm_master *master);
  818. extern void drm_master_put(struct drm_master **master);
  819.  
  820. extern void drm_put_dev(struct drm_device *dev);
  821. extern void drm_unplug_dev(struct drm_device *dev);
  822. extern unsigned int drm_debug;
  823.  
  824.                                 /* Debugfs support */
  825. #if defined(CONFIG_DEBUG_FS)
  826. extern int drm_debugfs_create_files(const struct drm_info_list *files,
  827.                                     int count, struct dentry *root,
  828.                                     struct drm_minor *minor);
  829. extern int drm_debugfs_remove_files(const struct drm_info_list *files,
  830.                                     int count, struct drm_minor *minor);
  831. #else
  832. static inline int drm_debugfs_create_files(const struct drm_info_list *files,
  833.                                            int count, struct dentry *root,
  834.                                            struct drm_minor *minor)
  835. {
  836.         return 0;
  837. }
  838.  
  839. static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
  840.                                            int count, struct drm_minor *minor)
  841. {
  842.         return 0;
  843. }
  844. #endif
  845.  
  846. extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
  847.                 struct drm_gem_object *obj, int flags);
  848. extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
  849.                 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
  850.                 int *prime_fd);
  851. extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  852.                 struct dma_buf *dma_buf);
  853. extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
  854.                 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
  855. extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
  856.  
  857. extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
  858.                                             dma_addr_t *addrs, int max_pages);
  859. extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
  860. extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
  861.  
  862.  
  863. extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
  864.                                        size_t align);
  865. extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
  866.  
  867.                                /* sysfs support (drm_sysfs.c) */
  868. extern void drm_sysfs_hotplug_event(struct drm_device *dev);
  869.  
  870.  
  871. struct drm_device *drm_dev_alloc(struct drm_driver *driver,
  872.                                  struct device *parent);
  873. void drm_dev_ref(struct drm_device *dev);
  874. void drm_dev_unref(struct drm_device *dev);
  875. int drm_dev_register(struct drm_device *dev, unsigned long flags);
  876. void drm_dev_unregister(struct drm_device *dev);
  877. int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
  878.  
  879. struct drm_minor *drm_minor_acquire(unsigned int minor_id);
  880. void drm_minor_release(struct drm_minor *minor);
  881.  
  882. /*@}*/
  883.  
  884. /* PCI section */
  885. static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
  886. {
  887.  
  888.         return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
  889. }
  890. void drm_pci_agp_destroy(struct drm_device *dev);
  891.  
  892. #if 0
  893. extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  894. extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  895. extern int drm_get_pci_dev(struct pci_dev *pdev,
  896.                            const struct pci_device_id *ent,
  897.                            struct drm_driver *driver);
  898. #endif
  899.  
  900. #define DRM_PCIE_SPEED_25 1
  901. #define DRM_PCIE_SPEED_50 2
  902. #define DRM_PCIE_SPEED_80 4
  903.  
  904. extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
  905.  
  906.  
  907. static __inline__ int drm_device_is_pcie(struct drm_device *dev)
  908. {
  909.     return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
  910. }
  911.  
  912. #define LFB_SIZE 0x1000000
  913. extern struct drm_device *main_device;
  914. extern struct drm_file *drm_file_handlers[256];
  915.  
  916. #endif
  917.