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