Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. |
| 3 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 4 | * Copyright (c) 2009-2010, Code Aurora Forum. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Author: Rickard E. (Rik) Faith <faith@valinux.com> |
| 8 | * Author: Gareth Hughes <gareth@valinux.com> |
| 9 | * |
| 10 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 11 | * copy of this software and associated documentation files (the "Software"), |
| 12 | * to deal in the Software without restriction, including without limitation |
| 13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 | * and/or sell copies of the Software, and to permit persons to whom the |
| 15 | * Software is furnished to do so, subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice (including the next |
| 18 | * paragraph) shall be included in all copies or substantial portions of the |
| 19 | * Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 24 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 25 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 26 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 27 | * OTHER DEALINGS IN THE SOFTWARE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef _DRM_FILE_H_ |
| 31 | #define _DRM_FILE_H_ |
| 32 | |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/completion.h> |
| 35 | |
| 36 | #include <uapi/drm/drm.h> |
| 37 | |
| 38 | #include <drm/drm_prime.h> |
| 39 | |
| 40 | struct dma_fence; |
| 41 | struct drm_file; |
| 42 | struct drm_device; |
| 43 | |
| 44 | /* |
| 45 | * FIXME: Not sure we want to have drm_minor here in the end, but to avoid |
| 46 | * header include loops we need it here for now. |
| 47 | */ |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 48 | |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 49 | enum drm_minor_type { |
| 50 | DRM_MINOR_PRIMARY, |
| 51 | DRM_MINOR_CONTROL, |
| 52 | DRM_MINOR_RENDER, |
| 53 | }; |
| 54 | |
| 55 | /** |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 56 | * struct drm_minor - DRM device minor structure |
| 57 | * |
| 58 | * This structure represents a DRM minor number for device nodes in /dev. |
| 59 | * Entirely opaque to drivers and should never be inspected directly by drivers. |
| 60 | * Drivers instead should only interact with &struct drm_file and of course |
| 61 | * &struct drm_device, which is also where driver-private data and resources can |
| 62 | * be attached to. |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 63 | */ |
| 64 | struct drm_minor { |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 65 | /* private: */ |
| 66 | int index; /* Minor device number */ |
| 67 | int type; /* Control or render */ |
| 68 | struct device *kdev; /* Linux device */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 69 | struct drm_device *dev; |
| 70 | |
| 71 | struct dentry *debugfs_root; |
| 72 | |
| 73 | struct list_head debugfs_list; |
| 74 | struct mutex debugfs_lock; /* Protects debugfs_list. */ |
| 75 | }; |
| 76 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 77 | /** |
| 78 | * struct drm_pending_event - Event queued up for userspace to read |
| 79 | * |
| 80 | * This represents a DRM event. Drivers can use this as a generic completion |
| 81 | * mechanism, which supports kernel-internal &struct completion, &struct dma_fence |
| 82 | * and also the DRM-specific &struct drm_event delivery mechanism. |
| 83 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 84 | struct drm_pending_event { |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 85 | /** |
| 86 | * @completion: |
| 87 | * |
| 88 | * Optional pointer to a kernel internal completion signalled when |
| 89 | * drm_send_event() is called, useful to internally synchronize with |
| 90 | * nonblocking operations. |
| 91 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 92 | struct completion *completion; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * @completion_release: |
| 96 | * |
| 97 | * Optional callback currently only used by the atomic modeset helpers |
| 98 | * to clean up the reference count for the structure @completion is |
| 99 | * stored in. |
| 100 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 101 | void (*completion_release)(struct completion *completion); |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * @event: |
| 105 | * |
| 106 | * Pointer to the actual event that should be sent to userspace to be |
| 107 | * read using drm_read(). Can be optional, since nowadays events are |
| 108 | * also used to signal kernel internal threads with @completion or DMA |
| 109 | * transactions using @fence. |
| 110 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 111 | struct drm_event *event; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * @fence: |
| 115 | * |
| 116 | * Optional DMA fence to unblock other hardware transactions which |
| 117 | * depend upon the nonblocking DRM operation this event represents. |
| 118 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 119 | struct dma_fence *fence; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * @file_priv: |
| 123 | * |
| 124 | * &struct drm_file where @event should be delivered to. Only set when |
| 125 | * @event is set. |
| 126 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 127 | struct drm_file *file_priv; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * @link: |
| 131 | * |
| 132 | * Double-linked list to keep track of this event. Can be used by the |
| 133 | * driver up to the point when it calls drm_send_event(), after that |
| 134 | * this list entry is owned by the core for its own book-keeping. |
| 135 | */ |
| 136 | struct list_head link; |
| 137 | |
| 138 | /** |
| 139 | * @pending_link: |
| 140 | * |
| 141 | * Entry on &drm_file.pending_event_list, to keep track of all pending |
| 142 | * events for @file_priv, to allow correct unwinding of them when |
| 143 | * userspace closes the file before the event is delivered. |
| 144 | */ |
| 145 | struct list_head pending_link; |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 148 | /** |
| 149 | * struct drm_file - DRM file private data |
| 150 | * |
| 151 | * This structure tracks DRM state per open file descriptor. |
| 152 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 153 | struct drm_file { |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 154 | /** |
| 155 | * @authenticated: |
| 156 | * |
| 157 | * Whether the client is allowed to submit rendering, which for legacy |
| 158 | * nodes means it must be authenticated. |
| 159 | * |
| 160 | * See also the :ref:`section on primary nodes and authentication |
| 161 | * <drm_primary_node>`. |
| 162 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 163 | unsigned authenticated :1; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * @stereo_allowed: |
| 167 | * |
| 168 | * True when the client has asked us to expose stereo 3D mode flags. |
| 169 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 170 | unsigned stereo_allowed :1; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * @universal_planes: |
| 174 | * |
| 175 | * True if client understands CRTC primary planes and cursor planes |
| 176 | * in the plane list. Automatically set when @atomic is set. |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 177 | */ |
| 178 | unsigned universal_planes:1; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 179 | |
| 180 | /** @atomic: True if client understands atomic properties. */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 181 | unsigned atomic:1; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 182 | |
| 183 | /** |
| 184 | * @is_master: |
| 185 | * |
| 186 | * This client is the creator of @master. Protected by struct |
| 187 | * &drm_device.master_mutex. |
| 188 | * |
| 189 | * See also the :ref:`section on primary nodes and authentication |
| 190 | * <drm_primary_node>`. |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 191 | */ |
| 192 | unsigned is_master:1; |
| 193 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 194 | /** |
| 195 | * @master: |
| 196 | * |
| 197 | * Master this node is currently associated with. Only relevant if |
| 198 | * drm_is_primary_client() returns true. Note that this only |
| 199 | * matches &drm_device.master if the master is the currently active one. |
| 200 | * |
| 201 | * See also @authentication and @is_master and the :ref:`section on |
| 202 | * primary nodes and authentication <drm_primary_node>`. |
| 203 | */ |
| 204 | struct drm_master *master; |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 205 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 206 | /** @pid: Process that opened this file. */ |
| 207 | struct pid *pid; |
| 208 | |
| 209 | /** @magic: Authentication magic, see @authenticated. */ |
| 210 | drm_magic_t magic; |
| 211 | |
| 212 | /** |
| 213 | * @lhead: |
| 214 | * |
| 215 | * List of all open files of a DRM device, linked into |
| 216 | * &drm_device.filelist. Protected by &drm_device.filelist_mutex. |
| 217 | */ |
| 218 | struct list_head lhead; |
| 219 | |
| 220 | /** @minor: &struct drm_minor for this file. */ |
| 221 | struct drm_minor *minor; |
| 222 | |
| 223 | /** |
| 224 | * @object_idr: |
| 225 | * |
| 226 | * Mapping of mm object handles to object pointers. Used by the GEM |
| 227 | * subsystem. Protected by @table_lock. |
| 228 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 229 | struct idr object_idr; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 230 | |
| 231 | /** @table_lock: Protects @object_idr. */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 232 | spinlock_t table_lock; |
| 233 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 234 | /** @filp: Pointer to the core file structure. */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 235 | struct file *filp; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * @driver_priv: |
| 239 | * |
| 240 | * Optional pointer for driver private data. Can be allocated in |
| 241 | * &drm_driver.open and should be freed in &drm_driver.postclose. |
| 242 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 243 | void *driver_priv; |
| 244 | |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 245 | /** |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 246 | * @fbs: |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 247 | * |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 248 | * List of &struct drm_framebuffer associated with this file, using the |
| 249 | * &drm_framebuffer.filp_head entry. |
| 250 | * |
| 251 | * Protected by @fbs_lock. Note that the @fbs list holds a reference on |
| 252 | * the framebuffer object to prevent it from untimely disappearing. |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 253 | */ |
| 254 | struct list_head fbs; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 255 | |
| 256 | /** @fbs_lock: Protects @fbs. */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 257 | struct mutex fbs_lock; |
| 258 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 259 | /** |
| 260 | * @blobs: |
| 261 | * |
| 262 | * User-created blob properties; this retains a reference on the |
| 263 | * property. |
| 264 | * |
| 265 | * Protected by @drm_mode_config.blob_lock; |
| 266 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 267 | struct list_head blobs; |
| 268 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 269 | /** @event_wait: Waitqueue for new events added to @event_list. */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 270 | wait_queue_head_t event_wait; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * @pending_event_list: |
| 274 | * |
| 275 | * List of pending &struct drm_pending_event, used to clean up pending |
| 276 | * events in case this file gets closed before the event is signalled. |
| 277 | * Uses the &drm_pending_event.pending_link entry. |
| 278 | * |
| 279 | * Protect by &drm_device.event_lock. |
| 280 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 281 | struct list_head pending_event_list; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * @event_list: |
| 285 | * |
| 286 | * List of &struct drm_pending_event, ready for delivery to userspace |
| 287 | * through drm_read(). Uses the &drm_pending_event.link entry. |
| 288 | * |
| 289 | * Protect by &drm_device.event_lock. |
| 290 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 291 | struct list_head event_list; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 292 | |
| 293 | /** |
| 294 | * @event_space: |
| 295 | * |
| 296 | * Available event space to prevent userspace from |
| 297 | * exhausting kernel memory. Currently limited to the fairly arbitrary |
| 298 | * value of 4KB. |
| 299 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 300 | int event_space; |
| 301 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 302 | /** @event_read_lock: Serializes drm_read(). */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 303 | struct mutex event_read_lock; |
| 304 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 305 | /** |
| 306 | * @prime: |
| 307 | * |
| 308 | * Per-file buffer caches used by the PRIME buffer sharing code. |
| 309 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 310 | struct drm_prime_file_private prime; |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 311 | |
| 312 | /* private: */ |
| 313 | unsigned long lock_count; /* DRI1 legacy lock count */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 314 | }; |
| 315 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 316 | /** |
| 317 | * drm_is_primary_client - is this an open file of the primary node |
| 318 | * @file_priv: DRM file |
| 319 | * |
| 320 | * Returns true if this is an open file of the primary node, i.e. |
| 321 | * &drm_file.minor of @file_priv is a primary minor. |
| 322 | * |
| 323 | * See also the :ref:`section on primary nodes and authentication |
| 324 | * <drm_primary_node>`. |
| 325 | */ |
| 326 | static inline bool drm_is_primary_client(const struct drm_file *file_priv) |
| 327 | { |
| 328 | return file_priv->minor->type == DRM_MINOR_PRIMARY; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * drm_is_render_client - is this an open file of the render node |
| 333 | * @file_priv: DRM file |
| 334 | * |
| 335 | * Returns true if this is an open file of the render node, i.e. |
| 336 | * &drm_file.minor of @file_priv is a render minor. |
| 337 | * |
| 338 | * See also the :ref:`section on render nodes <drm_render_node>`. |
| 339 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 340 | static inline bool drm_is_render_client(const struct drm_file *file_priv) |
| 341 | { |
| 342 | return file_priv->minor->type == DRM_MINOR_RENDER; |
| 343 | } |
| 344 | |
Daniel Vetter | b93658f | 2017-03-08 15:12:44 +0100 | [diff] [blame] | 345 | /** |
| 346 | * drm_is_control_client - is this an open file of the control node |
| 347 | * @file_priv: DRM file |
| 348 | * |
| 349 | * Control nodes are deprecated and in the process of getting removed from the |
| 350 | * DRM userspace API. Do not ever use! |
| 351 | */ |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 352 | static inline bool drm_is_control_client(const struct drm_file *file_priv) |
| 353 | { |
| 354 | return file_priv->minor->type == DRM_MINOR_CONTROL; |
| 355 | } |
| 356 | |
Daniel Vetter | a8f8b1d | 2017-03-08 15:12:42 +0100 | [diff] [blame] | 357 | int drm_open(struct inode *inode, struct file *filp); |
| 358 | ssize_t drm_read(struct file *filp, char __user *buffer, |
| 359 | size_t count, loff_t *offset); |
| 360 | int drm_release(struct inode *inode, struct file *filp); |
| 361 | unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); |
| 362 | int drm_event_reserve_init_locked(struct drm_device *dev, |
| 363 | struct drm_file *file_priv, |
| 364 | struct drm_pending_event *p, |
| 365 | struct drm_event *e); |
| 366 | int drm_event_reserve_init(struct drm_device *dev, |
| 367 | struct drm_file *file_priv, |
| 368 | struct drm_pending_event *p, |
| 369 | struct drm_event *e); |
| 370 | void drm_event_cancel_free(struct drm_device *dev, |
| 371 | struct drm_pending_event *p); |
| 372 | void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e); |
| 373 | void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); |
| 374 | |
| 375 | #endif /* _DRM_FILE_H_ */ |