Subversion Repositories Kolibri OS

Rev

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