~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/drm/drmP.h

Version: ~ [ linux-5.4-rc1 ] ~ [ linux-5.3.2 ] ~ [ linux-5.2.18 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.76 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.146 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.194 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.194 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.74 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp