Subversion Repositories Kolibri OS

Rev

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