Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
0003  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
0004  * Copyright (c) 2009-2010, Code Aurora Forum.
0005  * All rights reserved.
0006  *
0007  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
0008  * Author: Gareth Hughes <gareth@valinux.com>
0009  *
0010  * Permission is hereby granted, free of charge, to any person obtaining a
0011  * copy of this software and associated documentation files (the "Software"),
0012  * to deal in the Software without restriction, including without limitation
0013  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0014  * and/or sell copies of the Software, and to permit persons to whom the
0015  * Software is furnished to do so, subject to the following conditions:
0016  *
0017  * The above copyright notice and this permission notice (including the next
0018  * paragraph) shall be included in all copies or substantial portions of the
0019  * Software.
0020  *
0021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0022  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0024  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0025  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0026  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0027  * OTHER DEALINGS IN THE SOFTWARE.
0028  */
0029 
0030 #ifndef _DRM_FILE_H_
0031 #define _DRM_FILE_H_
0032 
0033 #include <linux/types.h>
0034 #include <linux/completion.h>
0035 #include <linux/idr.h>
0036 
0037 #include <uapi/drm/drm.h>
0038 
0039 #include <drm/drm_prime.h>
0040 
0041 struct dma_fence;
0042 struct drm_file;
0043 struct drm_device;
0044 struct device;
0045 struct file;
0046 
0047 /*
0048  * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
0049  * header include loops we need it here for now.
0050  */
0051 
0052 /* Note that the order of this enum is ABI (it determines
0053  * /dev/dri/renderD* numbers).
0054  */
0055 enum drm_minor_type {
0056     DRM_MINOR_PRIMARY,
0057     DRM_MINOR_CONTROL,
0058     DRM_MINOR_RENDER,
0059 };
0060 
0061 /**
0062  * struct drm_minor - DRM device minor structure
0063  *
0064  * This structure represents a DRM minor number for device nodes in /dev.
0065  * Entirely opaque to drivers and should never be inspected directly by drivers.
0066  * Drivers instead should only interact with &struct drm_file and of course
0067  * &struct drm_device, which is also where driver-private data and resources can
0068  * be attached to.
0069  */
0070 struct drm_minor {
0071     /* private: */
0072     int index;          /* Minor device number */
0073     int type;                       /* Control or render */
0074     struct device *kdev;        /* Linux device */
0075     struct drm_device *dev;
0076 
0077     struct dentry *debugfs_root;
0078 
0079     struct list_head debugfs_list;
0080     struct mutex debugfs_lock; /* Protects debugfs_list. */
0081 };
0082 
0083 /**
0084  * struct drm_pending_event - Event queued up for userspace to read
0085  *
0086  * This represents a DRM event. Drivers can use this as a generic completion
0087  * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
0088  * and also the DRM-specific &struct drm_event delivery mechanism.
0089  */
0090 struct drm_pending_event {
0091     /**
0092      * @completion:
0093      *
0094      * Optional pointer to a kernel internal completion signalled when
0095      * drm_send_event() is called, useful to internally synchronize with
0096      * nonblocking operations.
0097      */
0098     struct completion *completion;
0099 
0100     /**
0101      * @completion_release:
0102      *
0103      * Optional callback currently only used by the atomic modeset helpers
0104      * to clean up the reference count for the structure @completion is
0105      * stored in.
0106      */
0107     void (*completion_release)(struct completion *completion);
0108 
0109     /**
0110      * @event:
0111      *
0112      * Pointer to the actual event that should be sent to userspace to be
0113      * read using drm_read(). Can be optional, since nowadays events are
0114      * also used to signal kernel internal threads with @completion or DMA
0115      * transactions using @fence.
0116      */
0117     struct drm_event *event;
0118 
0119     /**
0120      * @fence:
0121      *
0122      * Optional DMA fence to unblock other hardware transactions which
0123      * depend upon the nonblocking DRM operation this event represents.
0124      */
0125     struct dma_fence *fence;
0126 
0127     /**
0128      * @file_priv:
0129      *
0130      * &struct drm_file where @event should be delivered to. Only set when
0131      * @event is set.
0132      */
0133     struct drm_file *file_priv;
0134 
0135     /**
0136      * @link:
0137      *
0138      * Double-linked list to keep track of this event. Can be used by the
0139      * driver up to the point when it calls drm_send_event(), after that
0140      * this list entry is owned by the core for its own book-keeping.
0141      */
0142     struct list_head link;
0143 
0144     /**
0145      * @pending_link:
0146      *
0147      * Entry on &drm_file.pending_event_list, to keep track of all pending
0148      * events for @file_priv, to allow correct unwinding of them when
0149      * userspace closes the file before the event is delivered.
0150      */
0151     struct list_head pending_link;
0152 };
0153 
0154 /**
0155  * struct drm_file - DRM file private data
0156  *
0157  * This structure tracks DRM state per open file descriptor.
0158  */
0159 struct drm_file {
0160     /**
0161      * @authenticated:
0162      *
0163      * Whether the client is allowed to submit rendering, which for legacy
0164      * nodes means it must be authenticated.
0165      *
0166      * See also the :ref:`section on primary nodes and authentication
0167      * <drm_primary_node>`.
0168      */
0169     bool authenticated;
0170 
0171     /**
0172      * @stereo_allowed:
0173      *
0174      * True when the client has asked us to expose stereo 3D mode flags.
0175      */
0176     bool stereo_allowed;
0177 
0178     /**
0179      * @universal_planes:
0180      *
0181      * True if client understands CRTC primary planes and cursor planes
0182      * in the plane list. Automatically set when @atomic is set.
0183      */
0184     bool universal_planes;
0185 
0186     /** @atomic: True if client understands atomic properties. */
0187     bool atomic;
0188 
0189     /**
0190      * @aspect_ratio_allowed:
0191      *
0192      * True, if client can handle picture aspect ratios, and has requested
0193      * to pass this information along with the mode.
0194      */
0195     bool aspect_ratio_allowed;
0196 
0197     /**
0198      * @writeback_connectors:
0199      *
0200      * True if client understands writeback connectors
0201      */
0202     bool writeback_connectors;
0203 
0204     /**
0205      * @was_master:
0206      *
0207      * This client has or had, master capability. Protected by struct
0208      * &drm_device.master_mutex.
0209      *
0210      * This is used to ensure that CAP_SYS_ADMIN is not enforced, if the
0211      * client is or was master in the past.
0212      */
0213     bool was_master;
0214 
0215     /**
0216      * @is_master:
0217      *
0218      * This client is the creator of @master. Protected by struct
0219      * &drm_device.master_mutex.
0220      *
0221      * See also the :ref:`section on primary nodes and authentication
0222      * <drm_primary_node>`.
0223      */
0224     bool is_master;
0225 
0226     /**
0227      * @master:
0228      *
0229      * Master this node is currently associated with. Protected by struct
0230      * &drm_device.master_mutex, and serialized by @master_lookup_lock.
0231      *
0232      * Only relevant if drm_is_primary_client() returns true. Note that
0233      * this only matches &drm_device.master if the master is the currently
0234      * active one.
0235      *
0236      * To update @master, both &drm_device.master_mutex and
0237      * @master_lookup_lock need to be held, therefore holding either of
0238      * them is safe and enough for the read side.
0239      *
0240      * When dereferencing this pointer, either hold struct
0241      * &drm_device.master_mutex for the duration of the pointer's use, or
0242      * use drm_file_get_master() if struct &drm_device.master_mutex is not
0243      * currently held and there is no other need to hold it. This prevents
0244      * @master from being freed during use.
0245      *
0246      * See also @authentication and @is_master and the :ref:`section on
0247      * primary nodes and authentication <drm_primary_node>`.
0248      */
0249     struct drm_master *master;
0250 
0251     /** @master_lookup_lock: Serializes @master. */
0252     spinlock_t master_lookup_lock;
0253 
0254     /** @pid: Process that opened this file. */
0255     struct pid *pid;
0256 
0257     /** @magic: Authentication magic, see @authenticated. */
0258     drm_magic_t magic;
0259 
0260     /**
0261      * @lhead:
0262      *
0263      * List of all open files of a DRM device, linked into
0264      * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
0265      */
0266     struct list_head lhead;
0267 
0268     /** @minor: &struct drm_minor for this file. */
0269     struct drm_minor *minor;
0270 
0271     /**
0272      * @object_idr:
0273      *
0274      * Mapping of mm object handles to object pointers. Used by the GEM
0275      * subsystem. Protected by @table_lock.
0276      */
0277     struct idr object_idr;
0278 
0279     /** @table_lock: Protects @object_idr. */
0280     spinlock_t table_lock;
0281 
0282     /** @syncobj_idr: Mapping of sync object handles to object pointers. */
0283     struct idr syncobj_idr;
0284     /** @syncobj_table_lock: Protects @syncobj_idr. */
0285     spinlock_t syncobj_table_lock;
0286 
0287     /** @filp: Pointer to the core file structure. */
0288     struct file *filp;
0289 
0290     /**
0291      * @driver_priv:
0292      *
0293      * Optional pointer for driver private data. Can be allocated in
0294      * &drm_driver.open and should be freed in &drm_driver.postclose.
0295      */
0296     void *driver_priv;
0297 
0298     /**
0299      * @fbs:
0300      *
0301      * List of &struct drm_framebuffer associated with this file, using the
0302      * &drm_framebuffer.filp_head entry.
0303      *
0304      * Protected by @fbs_lock. Note that the @fbs list holds a reference on
0305      * the framebuffer object to prevent it from untimely disappearing.
0306      */
0307     struct list_head fbs;
0308 
0309     /** @fbs_lock: Protects @fbs. */
0310     struct mutex fbs_lock;
0311 
0312     /**
0313      * @blobs:
0314      *
0315      * User-created blob properties; this retains a reference on the
0316      * property.
0317      *
0318      * Protected by @drm_mode_config.blob_lock;
0319      */
0320     struct list_head blobs;
0321 
0322     /** @event_wait: Waitqueue for new events added to @event_list. */
0323     wait_queue_head_t event_wait;
0324 
0325     /**
0326      * @pending_event_list:
0327      *
0328      * List of pending &struct drm_pending_event, used to clean up pending
0329      * events in case this file gets closed before the event is signalled.
0330      * Uses the &drm_pending_event.pending_link entry.
0331      *
0332      * Protect by &drm_device.event_lock.
0333      */
0334     struct list_head pending_event_list;
0335 
0336     /**
0337      * @event_list:
0338      *
0339      * List of &struct drm_pending_event, ready for delivery to userspace
0340      * through drm_read(). Uses the &drm_pending_event.link entry.
0341      *
0342      * Protect by &drm_device.event_lock.
0343      */
0344     struct list_head event_list;
0345 
0346     /**
0347      * @event_space:
0348      *
0349      * Available event space to prevent userspace from
0350      * exhausting kernel memory. Currently limited to the fairly arbitrary
0351      * value of 4KB.
0352      */
0353     int event_space;
0354 
0355     /** @event_read_lock: Serializes drm_read(). */
0356     struct mutex event_read_lock;
0357 
0358     /**
0359      * @prime:
0360      *
0361      * Per-file buffer caches used by the PRIME buffer sharing code.
0362      */
0363     struct drm_prime_file_private prime;
0364 
0365     /* private: */
0366 #if IS_ENABLED(CONFIG_DRM_LEGACY)
0367     unsigned long lock_count; /* DRI1 legacy lock count */
0368 #endif
0369 };
0370 
0371 /**
0372  * drm_is_primary_client - is this an open file of the primary node
0373  * @file_priv: DRM file
0374  *
0375  * Returns true if this is an open file of the primary node, i.e.
0376  * &drm_file.minor of @file_priv is a primary minor.
0377  *
0378  * See also the :ref:`section on primary nodes and authentication
0379  * <drm_primary_node>`.
0380  */
0381 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
0382 {
0383     return file_priv->minor->type == DRM_MINOR_PRIMARY;
0384 }
0385 
0386 /**
0387  * drm_is_render_client - is this an open file of the render node
0388  * @file_priv: DRM file
0389  *
0390  * Returns true if this is an open file of the render node, i.e.
0391  * &drm_file.minor of @file_priv is a render minor.
0392  *
0393  * See also the :ref:`section on render nodes <drm_render_node>`.
0394  */
0395 static inline bool drm_is_render_client(const struct drm_file *file_priv)
0396 {
0397     return file_priv->minor->type == DRM_MINOR_RENDER;
0398 }
0399 
0400 int drm_open(struct inode *inode, struct file *filp);
0401 ssize_t drm_read(struct file *filp, char __user *buffer,
0402          size_t count, loff_t *offset);
0403 int drm_release(struct inode *inode, struct file *filp);
0404 int drm_release_noglobal(struct inode *inode, struct file *filp);
0405 __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
0406 int drm_event_reserve_init_locked(struct drm_device *dev,
0407                   struct drm_file *file_priv,
0408                   struct drm_pending_event *p,
0409                   struct drm_event *e);
0410 int drm_event_reserve_init(struct drm_device *dev,
0411                struct drm_file *file_priv,
0412                struct drm_pending_event *p,
0413                struct drm_event *e);
0414 void drm_event_cancel_free(struct drm_device *dev,
0415                struct drm_pending_event *p);
0416 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
0417 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
0418 void drm_send_event_timestamp_locked(struct drm_device *dev,
0419                      struct drm_pending_event *e,
0420                      ktime_t timestamp);
0421 
0422 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
0423 
0424 #ifdef CONFIG_MMU
0425 struct drm_vma_offset_manager;
0426 unsigned long drm_get_unmapped_area(struct file *file,
0427                     unsigned long uaddr, unsigned long len,
0428                     unsigned long pgoff, unsigned long flags,
0429                     struct drm_vma_offset_manager *mgr);
0430 #endif /* CONFIG_MMU */
0431 
0432 
0433 #endif /* _DRM_FILE_H_ */