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 #include <linux/idr.h> 36 37 #include <uapi/drm/drm.h> 38 39 #include <drm/drm_prime.h> 40 41 struct dma_fence; 42 struct drm_file; 43 struct drm_device; 44 struct device; 45 46 /* 47 * FIXME: Not sure we want to have drm_minor here in the end, but to avoid 48 * header include loops we need it here for now. 49 */ 50 51 enum drm_minor_type { 52 DRM_MINOR_PRIMARY, 53 DRM_MINOR_CONTROL, 54 DRM_MINOR_RENDER, 55 }; 56 57 /** 58 * struct drm_minor - DRM device minor structure 59 * 60 * This structure represents a DRM minor number for device nodes in /dev. 61 * Entirely opaque to drivers and should never be inspected directly by drivers. 62 * Drivers instead should only interact with &struct drm_file and of course 63 * &struct drm_device, which is also where driver-private data and resources can 64 * be attached to. 65 */ 66 struct drm_minor { 67 /* private: */ 68 int index; /* Minor device number */ 69 int type; /* Control or render */ 70 struct device *kdev; /* Linux device */ 71 struct drm_device *dev; 72 73 struct dentry *debugfs_root; 74 75 struct list_head debugfs_list; 76 struct lock debugfs_lock; /* Protects debugfs_list. */ 77 }; 78 79 /** 80 * struct drm_pending_event - Event queued up for userspace to read 81 * 82 * This represents a DRM event. Drivers can use this as a generic completion 83 * mechanism, which supports kernel-internal &struct completion, &struct dma_fence 84 * and also the DRM-specific &struct drm_event delivery mechanism. 85 */ 86 struct drm_pending_event { 87 /** 88 * @completion: 89 * 90 * Optional pointer to a kernel internal completion signalled when 91 * drm_send_event() is called, useful to internally synchronize with 92 * nonblocking operations. 93 */ 94 struct completion *completion; 95 96 /** 97 * @completion_release: 98 * 99 * Optional callback currently only used by the atomic modeset helpers 100 * to clean up the reference count for the structure @completion is 101 * stored in. 102 */ 103 void (*completion_release)(struct completion *completion); 104 105 /** 106 * @event: 107 * 108 * Pointer to the actual event that should be sent to userspace to be 109 * read using drm_read(). Can be optional, since nowadays events are 110 * also used to signal kernel internal threads with @completion or DMA 111 * transactions using @fence. 112 */ 113 struct drm_event *event; 114 115 /** 116 * @fence: 117 * 118 * Optional DMA fence to unblock other hardware transactions which 119 * depend upon the nonblocking DRM operation this event represents. 120 */ 121 struct dma_fence *fence; 122 123 /** 124 * @file_priv: 125 * 126 * &struct drm_file where @event should be delivered to. Only set when 127 * @event is set. 128 */ 129 struct drm_file *file_priv; 130 131 /** 132 * @link: 133 * 134 * Double-linked list to keep track of this event. Can be used by the 135 * driver up to the point when it calls drm_send_event(), after that 136 * this list entry is owned by the core for its own book-keeping. 137 */ 138 struct list_head link; 139 140 /** 141 * @pending_link: 142 * 143 * Entry on &drm_file.pending_event_list, to keep track of all pending 144 * events for @file_priv, to allow correct unwinding of them when 145 * userspace closes the file before the event is delivered. 146 */ 147 struct list_head pending_link; 148 }; 149 150 /** 151 * struct drm_file - DRM file private data 152 * 153 * This structure tracks DRM state per open file descriptor. 154 */ 155 struct drm_file { 156 /** 157 * @authenticated: 158 * 159 * Whether the client is allowed to submit rendering, which for legacy 160 * nodes means it must be authenticated. 161 * 162 * See also the :ref:`section on primary nodes and authentication 163 * <drm_primary_node>`. 164 */ 165 unsigned authenticated :1; 166 167 /** 168 * @stereo_allowed: 169 * 170 * True when the client has asked us to expose stereo 3D mode flags. 171 */ 172 unsigned stereo_allowed :1; 173 174 /** 175 * @universal_planes: 176 * 177 * True if client understands CRTC primary planes and cursor planes 178 * in the plane list. Automatically set when @atomic is set. 179 */ 180 unsigned universal_planes:1; 181 182 /** @atomic: True if client understands atomic properties. */ 183 unsigned atomic:1; 184 185 /** 186 * @is_master: 187 * 188 * This client is the creator of @master. Protected by struct 189 * &drm_device.master_mutex. 190 * 191 * See also the :ref:`section on primary nodes and authentication 192 * <drm_primary_node>`. 193 */ 194 unsigned is_master:1; 195 196 /** 197 * @master: 198 * 199 * Master this node is currently associated with. Only relevant if 200 * drm_is_primary_client() returns true. Note that this only 201 * matches &drm_device.master if the master is the currently active one. 202 * 203 * See also @authentication and @is_master and the :ref:`section on 204 * primary nodes and authentication <drm_primary_node>`. 205 */ 206 struct drm_master *master; 207 208 /** @pid: Process that opened this file. */ 209 pid_t pid; 210 211 /** @magic: Authentication magic, see @authenticated. */ 212 drm_magic_t magic; 213 214 /** 215 * @lhead: 216 * 217 * List of all open files of a DRM device, linked into 218 * &drm_device.filelist. Protected by &drm_device.filelist_mutex. 219 */ 220 struct list_head lhead; 221 222 /** @minor: &struct drm_minor for this file. */ 223 struct drm_minor *minor; 224 225 /** 226 * @object_idr: 227 * 228 * Mapping of mm object handles to object pointers. Used by the GEM 229 * subsystem. Protected by @table_lock. 230 */ 231 struct idr object_idr; 232 233 /** @table_lock: Protects @object_idr. */ 234 spinlock_t table_lock; 235 236 /** @syncobj_idr: Mapping of sync object handles to object pointers. */ 237 struct idr syncobj_idr; 238 /** @syncobj_table_lock: Protects @syncobj_idr. */ 239 spinlock_t syncobj_table_lock; 240 241 /** @filp: Pointer to the core file structure. */ 242 struct file *filp; 243 244 /** 245 * @driver_priv: 246 * 247 * Optional pointer for driver private data. Can be allocated in 248 * &drm_driver.open and should be freed in &drm_driver.postclose. 249 */ 250 void *driver_priv; 251 252 /** 253 * @fbs: 254 * 255 * List of &struct drm_framebuffer associated with this file, using the 256 * &drm_framebuffer.filp_head entry. 257 * 258 * Protected by @fbs_lock. Note that the @fbs list holds a reference on 259 * the framebuffer object to prevent it from untimely disappearing. 260 */ 261 struct list_head fbs; 262 263 /** @fbs_lock: Protects @fbs. */ 264 struct lock fbs_lock; 265 266 /** 267 * @blobs: 268 * 269 * User-created blob properties; this retains a reference on the 270 * property. 271 * 272 * Protected by @drm_mode_config.blob_lock; 273 */ 274 struct list_head blobs; 275 276 /** @event_wait: Waitqueue for new events added to @event_list. */ 277 wait_queue_head_t event_wait; 278 279 /** 280 * @pending_event_list: 281 * 282 * List of pending &struct drm_pending_event, used to clean up pending 283 * events in case this file gets closed before the event is signalled. 284 * Uses the &drm_pending_event.pending_link entry. 285 * 286 * Protect by &drm_device.event_lock. 287 */ 288 struct list_head pending_event_list; 289 290 /** 291 * @event_list: 292 * 293 * List of &struct drm_pending_event, ready for delivery to userspace 294 * through drm_read(). Uses the &drm_pending_event.link entry. 295 * 296 * Protect by &drm_device.event_lock. 297 */ 298 struct list_head event_list; 299 300 /** 301 * @event_space: 302 * 303 * Available event space to prevent userspace from 304 * exhausting kernel memory. Currently limited to the fairly arbitrary 305 * value of 4KB. 306 */ 307 int event_space; 308 309 /** @event_read_lock: Serializes drm_read(). */ 310 struct lock event_read_lock; 311 312 /** 313 * @prime: 314 * 315 * Per-file buffer caches used by the PRIME buffer sharing code. 316 */ 317 struct drm_prime_file_private prime; 318 319 /* private: */ 320 unsigned long lock_count; /* DRI1 legacy lock count */ 321 322 #ifdef __DragonFly__ 323 struct drm_device *dev; 324 struct kqinfo dkq; 325 #endif 326 }; 327 328 /** 329 * drm_is_primary_client - is this an open file of the primary node 330 * @file_priv: DRM file 331 * 332 * Returns true if this is an open file of the primary node, i.e. 333 * &drm_file.minor of @file_priv is a primary minor. 334 * 335 * See also the :ref:`section on primary nodes and authentication 336 * <drm_primary_node>`. 337 */ 338 static inline bool drm_is_primary_client(const struct drm_file *file_priv) 339 { 340 return file_priv->minor->type == DRM_MINOR_PRIMARY; 341 } 342 343 /** 344 * drm_is_render_client - is this an open file of the render node 345 * @file_priv: DRM file 346 * 347 * Returns true if this is an open file of the render node, i.e. 348 * &drm_file.minor of @file_priv is a render minor. 349 * 350 * See also the :ref:`section on render nodes <drm_render_node>`. 351 */ 352 static inline bool drm_is_render_client(const struct drm_file *file_priv) 353 { 354 return file_priv->minor->type == DRM_MINOR_RENDER; 355 } 356 357 /** 358 * drm_is_control_client - is this an open file of the control node 359 * @file_priv: DRM file 360 * 361 * Control nodes are deprecated and in the process of getting removed from the 362 * DRM userspace API. Do not ever use! 363 */ 364 static inline bool drm_is_control_client(const struct drm_file *file_priv) 365 { 366 return file_priv->minor->type == DRM_MINOR_CONTROL; 367 } 368 369 #ifdef __DragonFly__ 370 d_open_t drm_open; 371 d_close_t drm_close; 372 d_read_t drm_read; 373 #else 374 int drm_open(struct inode *inode, struct file *filp); 375 ssize_t drm_read(struct file *filp, char __user *buffer, 376 size_t count, loff_t *offset); 377 #endif 378 int drm_release(struct inode *inode, struct file *filp); 379 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); 380 int drm_event_reserve_init_locked(struct drm_device *dev, 381 struct drm_file *file_priv, 382 struct drm_pending_event *p, 383 struct drm_event *e); 384 int drm_event_reserve_init(struct drm_device *dev, 385 struct drm_file *file_priv, 386 struct drm_pending_event *p, 387 struct drm_event *e); 388 void drm_event_cancel_free(struct drm_device *dev, 389 struct drm_pending_event *p); 390 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e); 391 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); 392 393 #endif /* _DRM_FILE_H_ */ 394