1a8f8b1d9SDaniel Vetter /*
2a8f8b1d9SDaniel Vetter * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3a8f8b1d9SDaniel Vetter * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4a8f8b1d9SDaniel Vetter * Copyright (c) 2009-2010, Code Aurora Forum.
5a8f8b1d9SDaniel Vetter * All rights reserved.
6a8f8b1d9SDaniel Vetter *
7a8f8b1d9SDaniel Vetter * Author: Rickard E. (Rik) Faith <faith@valinux.com>
8a8f8b1d9SDaniel Vetter * Author: Gareth Hughes <gareth@valinux.com>
9a8f8b1d9SDaniel Vetter *
10a8f8b1d9SDaniel Vetter * Permission is hereby granted, free of charge, to any person obtaining a
11a8f8b1d9SDaniel Vetter * copy of this software and associated documentation files (the "Software"),
12a8f8b1d9SDaniel Vetter * to deal in the Software without restriction, including without limitation
13a8f8b1d9SDaniel Vetter * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14a8f8b1d9SDaniel Vetter * and/or sell copies of the Software, and to permit persons to whom the
15a8f8b1d9SDaniel Vetter * Software is furnished to do so, subject to the following conditions:
16a8f8b1d9SDaniel Vetter *
17a8f8b1d9SDaniel Vetter * The above copyright notice and this permission notice (including the next
18a8f8b1d9SDaniel Vetter * paragraph) shall be included in all copies or substantial portions of the
19a8f8b1d9SDaniel Vetter * Software.
20a8f8b1d9SDaniel Vetter *
21a8f8b1d9SDaniel Vetter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22a8f8b1d9SDaniel Vetter * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23a8f8b1d9SDaniel Vetter * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24a8f8b1d9SDaniel Vetter * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25a8f8b1d9SDaniel Vetter * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26a8f8b1d9SDaniel Vetter * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27a8f8b1d9SDaniel Vetter * OTHER DEALINGS IN THE SOFTWARE.
28a8f8b1d9SDaniel Vetter */
29a8f8b1d9SDaniel Vetter
30a8f8b1d9SDaniel Vetter #ifndef _DRM_FILE_H_
31a8f8b1d9SDaniel Vetter #define _DRM_FILE_H_
32a8f8b1d9SDaniel Vetter
33a8f8b1d9SDaniel Vetter #include <linux/types.h>
34a8f8b1d9SDaniel Vetter #include <linux/completion.h>
3539e23674SJani Nikula #include <linux/idr.h>
36a8f8b1d9SDaniel Vetter
37a8f8b1d9SDaniel Vetter #include <uapi/drm/drm.h>
38a8f8b1d9SDaniel Vetter
39a8f8b1d9SDaniel Vetter #include <drm/drm_prime.h>
40a8f8b1d9SDaniel Vetter
41a8f8b1d9SDaniel Vetter struct dma_fence;
42a8f8b1d9SDaniel Vetter struct drm_file;
43a8f8b1d9SDaniel Vetter struct drm_device;
44686b21b5SRob Clark struct drm_printer;
453ed4351aSDaniel Vetter struct device;
464748aa16SChris Wilson struct file;
47a8f8b1d9SDaniel Vetter
48*f6b589e3SMichał Winiarski extern struct xarray drm_minors_xa;
49*f6b589e3SMichał Winiarski
50a8f8b1d9SDaniel Vetter /*
51a8f8b1d9SDaniel Vetter * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
52a8f8b1d9SDaniel Vetter * header include loops we need it here for now.
53a8f8b1d9SDaniel Vetter */
54b93658f8SDaniel Vetter
5503fad56aSSimon Ser /* Note that the values of this enum are ABI (it determines
56c9ac371dSEric Anholt * /dev/dri/renderD* numbers).
572c204f3dSOded Gabbay *
582c204f3dSOded Gabbay * Setting DRM_MINOR_ACCEL to 32 gives enough space for more drm minors to
592c204f3dSOded Gabbay * be implemented before we hit any future
60c9ac371dSEric Anholt */
61a8f8b1d9SDaniel Vetter enum drm_minor_type {
6203fad56aSSimon Ser DRM_MINOR_PRIMARY = 0,
6303fad56aSSimon Ser DRM_MINOR_CONTROL = 1,
6403fad56aSSimon Ser DRM_MINOR_RENDER = 2,
652c204f3dSOded Gabbay DRM_MINOR_ACCEL = 32,
66a8f8b1d9SDaniel Vetter };
67a8f8b1d9SDaniel Vetter
68a8f8b1d9SDaniel Vetter /**
69b93658f8SDaniel Vetter * struct drm_minor - DRM device minor structure
70b93658f8SDaniel Vetter *
71b93658f8SDaniel Vetter * This structure represents a DRM minor number for device nodes in /dev.
72b93658f8SDaniel Vetter * Entirely opaque to drivers and should never be inspected directly by drivers.
73b93658f8SDaniel Vetter * Drivers instead should only interact with &struct drm_file and of course
74b93658f8SDaniel Vetter * &struct drm_device, which is also where driver-private data and resources can
75b93658f8SDaniel Vetter * be attached to.
76a8f8b1d9SDaniel Vetter */
77a8f8b1d9SDaniel Vetter struct drm_minor {
78b93658f8SDaniel Vetter /* private: */
79b93658f8SDaniel Vetter int index; /* Minor device number */
802c204f3dSOded Gabbay int type; /* Control or render or accel */
81b93658f8SDaniel Vetter struct device *kdev; /* Linux device */
82a8f8b1d9SDaniel Vetter struct drm_device *dev;
83a8f8b1d9SDaniel Vetter
84a8f8b1d9SDaniel Vetter struct dentry *debugfs_root;
85a8f8b1d9SDaniel Vetter
86a8f8b1d9SDaniel Vetter struct list_head debugfs_list;
87a8f8b1d9SDaniel Vetter struct mutex debugfs_lock; /* Protects debugfs_list. */
88a8f8b1d9SDaniel Vetter };
89a8f8b1d9SDaniel Vetter
90b93658f8SDaniel Vetter /**
91b93658f8SDaniel Vetter * struct drm_pending_event - Event queued up for userspace to read
92b93658f8SDaniel Vetter *
93b93658f8SDaniel Vetter * This represents a DRM event. Drivers can use this as a generic completion
94b93658f8SDaniel Vetter * mechanism, which supports kernel-internal &struct completion, &struct dma_fence
95b93658f8SDaniel Vetter * and also the DRM-specific &struct drm_event delivery mechanism.
96b93658f8SDaniel Vetter */
97a8f8b1d9SDaniel Vetter struct drm_pending_event {
98b93658f8SDaniel Vetter /**
99b93658f8SDaniel Vetter * @completion:
100b93658f8SDaniel Vetter *
101b93658f8SDaniel Vetter * Optional pointer to a kernel internal completion signalled when
102b93658f8SDaniel Vetter * drm_send_event() is called, useful to internally synchronize with
103b93658f8SDaniel Vetter * nonblocking operations.
104b93658f8SDaniel Vetter */
105a8f8b1d9SDaniel Vetter struct completion *completion;
106b93658f8SDaniel Vetter
107b93658f8SDaniel Vetter /**
108b93658f8SDaniel Vetter * @completion_release:
109b93658f8SDaniel Vetter *
110b93658f8SDaniel Vetter * Optional callback currently only used by the atomic modeset helpers
111b93658f8SDaniel Vetter * to clean up the reference count for the structure @completion is
112b93658f8SDaniel Vetter * stored in.
113b93658f8SDaniel Vetter */
114a8f8b1d9SDaniel Vetter void (*completion_release)(struct completion *completion);
115b93658f8SDaniel Vetter
116b93658f8SDaniel Vetter /**
117b93658f8SDaniel Vetter * @event:
118b93658f8SDaniel Vetter *
119b93658f8SDaniel Vetter * Pointer to the actual event that should be sent to userspace to be
120b93658f8SDaniel Vetter * read using drm_read(). Can be optional, since nowadays events are
121b93658f8SDaniel Vetter * also used to signal kernel internal threads with @completion or DMA
122b93658f8SDaniel Vetter * transactions using @fence.
123b93658f8SDaniel Vetter */
124a8f8b1d9SDaniel Vetter struct drm_event *event;
125b93658f8SDaniel Vetter
126b93658f8SDaniel Vetter /**
127b93658f8SDaniel Vetter * @fence:
128b93658f8SDaniel Vetter *
129b93658f8SDaniel Vetter * Optional DMA fence to unblock other hardware transactions which
130b93658f8SDaniel Vetter * depend upon the nonblocking DRM operation this event represents.
131b93658f8SDaniel Vetter */
132a8f8b1d9SDaniel Vetter struct dma_fence *fence;
133b93658f8SDaniel Vetter
134b93658f8SDaniel Vetter /**
135b93658f8SDaniel Vetter * @file_priv:
136b93658f8SDaniel Vetter *
137b93658f8SDaniel Vetter * &struct drm_file where @event should be delivered to. Only set when
138b93658f8SDaniel Vetter * @event is set.
139b93658f8SDaniel Vetter */
140a8f8b1d9SDaniel Vetter struct drm_file *file_priv;
141b93658f8SDaniel Vetter
142b93658f8SDaniel Vetter /**
143b93658f8SDaniel Vetter * @link:
144b93658f8SDaniel Vetter *
145b93658f8SDaniel Vetter * Double-linked list to keep track of this event. Can be used by the
146b93658f8SDaniel Vetter * driver up to the point when it calls drm_send_event(), after that
147b93658f8SDaniel Vetter * this list entry is owned by the core for its own book-keeping.
148b93658f8SDaniel Vetter */
149b93658f8SDaniel Vetter struct list_head link;
150b93658f8SDaniel Vetter
151b93658f8SDaniel Vetter /**
152b93658f8SDaniel Vetter * @pending_link:
153b93658f8SDaniel Vetter *
154b93658f8SDaniel Vetter * Entry on &drm_file.pending_event_list, to keep track of all pending
155b93658f8SDaniel Vetter * events for @file_priv, to allow correct unwinding of them when
156b93658f8SDaniel Vetter * userspace closes the file before the event is delivered.
157b93658f8SDaniel Vetter */
158b93658f8SDaniel Vetter struct list_head pending_link;
159a8f8b1d9SDaniel Vetter };
160a8f8b1d9SDaniel Vetter
161b93658f8SDaniel Vetter /**
162b93658f8SDaniel Vetter * struct drm_file - DRM file private data
163b93658f8SDaniel Vetter *
164b93658f8SDaniel Vetter * This structure tracks DRM state per open file descriptor.
165b93658f8SDaniel Vetter */
166a8f8b1d9SDaniel Vetter struct drm_file {
167b93658f8SDaniel Vetter /**
168b93658f8SDaniel Vetter * @authenticated:
169b93658f8SDaniel Vetter *
170b93658f8SDaniel Vetter * Whether the client is allowed to submit rendering, which for legacy
171b93658f8SDaniel Vetter * nodes means it must be authenticated.
172b93658f8SDaniel Vetter *
173b93658f8SDaniel Vetter * See also the :ref:`section on primary nodes and authentication
174b93658f8SDaniel Vetter * <drm_primary_node>`.
175b93658f8SDaniel Vetter */
176078b7de4SDaniel Vetter bool authenticated;
177b93658f8SDaniel Vetter
178b93658f8SDaniel Vetter /**
179b93658f8SDaniel Vetter * @stereo_allowed:
180b93658f8SDaniel Vetter *
181b93658f8SDaniel Vetter * True when the client has asked us to expose stereo 3D mode flags.
182b93658f8SDaniel Vetter */
183078b7de4SDaniel Vetter bool stereo_allowed;
184b93658f8SDaniel Vetter
185b93658f8SDaniel Vetter /**
186b93658f8SDaniel Vetter * @universal_planes:
187b93658f8SDaniel Vetter *
188b93658f8SDaniel Vetter * True if client understands CRTC primary planes and cursor planes
189b93658f8SDaniel Vetter * in the plane list. Automatically set when @atomic is set.
190a8f8b1d9SDaniel Vetter */
191078b7de4SDaniel Vetter bool universal_planes;
192b93658f8SDaniel Vetter
193b93658f8SDaniel Vetter /** @atomic: True if client understands atomic properties. */
194078b7de4SDaniel Vetter bool atomic;
195b93658f8SDaniel Vetter
196b93658f8SDaniel Vetter /**
1977595bda2SAnkit Nautiyal * @aspect_ratio_allowed:
1987595bda2SAnkit Nautiyal *
1997595bda2SAnkit Nautiyal * True, if client can handle picture aspect ratios, and has requested
2007595bda2SAnkit Nautiyal * to pass this information along with the mode.
2017595bda2SAnkit Nautiyal */
202078b7de4SDaniel Vetter bool aspect_ratio_allowed;
2037595bda2SAnkit Nautiyal
2047595bda2SAnkit Nautiyal /**
205d67b6a20SLiviu Dudau * @writeback_connectors:
206d67b6a20SLiviu Dudau *
207d67b6a20SLiviu Dudau * True if client understands writeback connectors
208d67b6a20SLiviu Dudau */
209078b7de4SDaniel Vetter bool writeback_connectors;
210d67b6a20SLiviu Dudau
211d67b6a20SLiviu Dudau /**
21245bc3d26SEmil Velikov * @was_master:
21345bc3d26SEmil Velikov *
21445bc3d26SEmil Velikov * This client has or had, master capability. Protected by struct
21545bc3d26SEmil Velikov * &drm_device.master_mutex.
21645bc3d26SEmil Velikov *
21745bc3d26SEmil Velikov * This is used to ensure that CAP_SYS_ADMIN is not enforced, if the
21845bc3d26SEmil Velikov * client is or was master in the past.
21945bc3d26SEmil Velikov */
22045bc3d26SEmil Velikov bool was_master;
22145bc3d26SEmil Velikov
22245bc3d26SEmil Velikov /**
223b93658f8SDaniel Vetter * @is_master:
224b93658f8SDaniel Vetter *
225b93658f8SDaniel Vetter * This client is the creator of @master. Protected by struct
226b93658f8SDaniel Vetter * &drm_device.master_mutex.
227b93658f8SDaniel Vetter *
228b93658f8SDaniel Vetter * See also the :ref:`section on primary nodes and authentication
229b93658f8SDaniel Vetter * <drm_primary_node>`.
230a8f8b1d9SDaniel Vetter */
231078b7de4SDaniel Vetter bool is_master;
232a8f8b1d9SDaniel Vetter
233b93658f8SDaniel Vetter /**
23487b3b45cSZack Rusin * @supports_virtualized_cursor_plane:
23587b3b45cSZack Rusin *
23687b3b45cSZack Rusin * This client is capable of handling the cursor plane with the
23787b3b45cSZack Rusin * restrictions imposed on it by the virtualized drivers.
23887b3b45cSZack Rusin *
23987b3b45cSZack Rusin * This implies that the cursor plane has to behave like a cursor
24087b3b45cSZack Rusin * i.e. track cursor movement. It also requires setting of the
24187b3b45cSZack Rusin * hotspot properties by the client on the cursor plane.
24287b3b45cSZack Rusin */
24387b3b45cSZack Rusin bool supports_virtualized_cursor_plane;
24487b3b45cSZack Rusin
24587b3b45cSZack Rusin /**
246b93658f8SDaniel Vetter * @master:
247b93658f8SDaniel Vetter *
2480b0860a3SDesmond Cheong Zhi Xi * Master this node is currently associated with. Protected by struct
2490b0860a3SDesmond Cheong Zhi Xi * &drm_device.master_mutex, and serialized by @master_lookup_lock.
2500b0860a3SDesmond Cheong Zhi Xi *
2510b0860a3SDesmond Cheong Zhi Xi * Only relevant if drm_is_primary_client() returns true. Note that
2520b0860a3SDesmond Cheong Zhi Xi * this only matches &drm_device.master if the master is the currently
2530b0860a3SDesmond Cheong Zhi Xi * active one.
254b93658f8SDaniel Vetter *
255649839d7SDesmond Cheong Zhi Xi * To update @master, both &drm_device.master_mutex and
256649839d7SDesmond Cheong Zhi Xi * @master_lookup_lock need to be held, therefore holding either of
257649839d7SDesmond Cheong Zhi Xi * them is safe and enough for the read side.
258649839d7SDesmond Cheong Zhi Xi *
25956f0729aSDesmond Cheong Zhi Xi * When dereferencing this pointer, either hold struct
26056f0729aSDesmond Cheong Zhi Xi * &drm_device.master_mutex for the duration of the pointer's use, or
26156f0729aSDesmond Cheong Zhi Xi * use drm_file_get_master() if struct &drm_device.master_mutex is not
26256f0729aSDesmond Cheong Zhi Xi * currently held and there is no other need to hold it. This prevents
26356f0729aSDesmond Cheong Zhi Xi * @master from being freed during use.
26456f0729aSDesmond Cheong Zhi Xi *
265b93658f8SDaniel Vetter * See also @authentication and @is_master and the :ref:`section on
266b93658f8SDaniel Vetter * primary nodes and authentication <drm_primary_node>`.
267b93658f8SDaniel Vetter */
268b93658f8SDaniel Vetter struct drm_master *master;
269a8f8b1d9SDaniel Vetter
27035352081SRandy Dunlap /** @master_lookup_lock: Serializes @master. */
2710b0860a3SDesmond Cheong Zhi Xi spinlock_t master_lookup_lock;
2720b0860a3SDesmond Cheong Zhi Xi
273031ddd28STvrtko Ursulin /**
274031ddd28STvrtko Ursulin * @pid: Process that is using this file.
275031ddd28STvrtko Ursulin *
276031ddd28STvrtko Ursulin * Must only be dereferenced under a rcu_read_lock or equivalent.
277031ddd28STvrtko Ursulin *
278031ddd28STvrtko Ursulin * Updates are guarded with dev->filelist_mutex and reference must be
279031ddd28STvrtko Ursulin * dropped after a RCU grace period to accommodate lockless readers.
280031ddd28STvrtko Ursulin */
281031ddd28STvrtko Ursulin struct pid __rcu *pid;
282b93658f8SDaniel Vetter
2833f09a0cdSRob Clark /** @client_id: A unique id for fdinfo */
2843f09a0cdSRob Clark u64 client_id;
2853f09a0cdSRob Clark
286b93658f8SDaniel Vetter /** @magic: Authentication magic, see @authenticated. */
287b93658f8SDaniel Vetter drm_magic_t magic;
288b93658f8SDaniel Vetter
289b93658f8SDaniel Vetter /**
290b93658f8SDaniel Vetter * @lhead:
291b93658f8SDaniel Vetter *
292b93658f8SDaniel Vetter * List of all open files of a DRM device, linked into
293b93658f8SDaniel Vetter * &drm_device.filelist. Protected by &drm_device.filelist_mutex.
294b93658f8SDaniel Vetter */
295b93658f8SDaniel Vetter struct list_head lhead;
296b93658f8SDaniel Vetter
297b93658f8SDaniel Vetter /** @minor: &struct drm_minor for this file. */
298b93658f8SDaniel Vetter struct drm_minor *minor;
299b93658f8SDaniel Vetter
300b93658f8SDaniel Vetter /**
301b93658f8SDaniel Vetter * @object_idr:
302b93658f8SDaniel Vetter *
303b93658f8SDaniel Vetter * Mapping of mm object handles to object pointers. Used by the GEM
304b93658f8SDaniel Vetter * subsystem. Protected by @table_lock.
305b93658f8SDaniel Vetter */
306a8f8b1d9SDaniel Vetter struct idr object_idr;
307b93658f8SDaniel Vetter
308b93658f8SDaniel Vetter /** @table_lock: Protects @object_idr. */
309a8f8b1d9SDaniel Vetter spinlock_t table_lock;
310a8f8b1d9SDaniel Vetter
311e9083420SDave Airlie /** @syncobj_idr: Mapping of sync object handles to object pointers. */
312e9083420SDave Airlie struct idr syncobj_idr;
313e9083420SDave Airlie /** @syncobj_table_lock: Protects @syncobj_idr. */
314e9083420SDave Airlie spinlock_t syncobj_table_lock;
315e9083420SDave Airlie
316b93658f8SDaniel Vetter /** @filp: Pointer to the core file structure. */
317a8f8b1d9SDaniel Vetter struct file *filp;
318b93658f8SDaniel Vetter
319b93658f8SDaniel Vetter /**
320b93658f8SDaniel Vetter * @driver_priv:
321b93658f8SDaniel Vetter *
322b93658f8SDaniel Vetter * Optional pointer for driver private data. Can be allocated in
323b93658f8SDaniel Vetter * &drm_driver.open and should be freed in &drm_driver.postclose.
324b93658f8SDaniel Vetter */
325a8f8b1d9SDaniel Vetter void *driver_priv;
326a8f8b1d9SDaniel Vetter
327a8f8b1d9SDaniel Vetter /**
328b93658f8SDaniel Vetter * @fbs:
329a8f8b1d9SDaniel Vetter *
330b93658f8SDaniel Vetter * List of &struct drm_framebuffer associated with this file, using the
331b93658f8SDaniel Vetter * &drm_framebuffer.filp_head entry.
332b93658f8SDaniel Vetter *
333b93658f8SDaniel Vetter * Protected by @fbs_lock. Note that the @fbs list holds a reference on
334b93658f8SDaniel Vetter * the framebuffer object to prevent it from untimely disappearing.
335a8f8b1d9SDaniel Vetter */
336a8f8b1d9SDaniel Vetter struct list_head fbs;
337b93658f8SDaniel Vetter
338b93658f8SDaniel Vetter /** @fbs_lock: Protects @fbs. */
339a8f8b1d9SDaniel Vetter struct mutex fbs_lock;
340a8f8b1d9SDaniel Vetter
341b93658f8SDaniel Vetter /**
342b93658f8SDaniel Vetter * @blobs:
343b93658f8SDaniel Vetter *
344b93658f8SDaniel Vetter * User-created blob properties; this retains a reference on the
345b93658f8SDaniel Vetter * property.
346b93658f8SDaniel Vetter *
347b93658f8SDaniel Vetter * Protected by @drm_mode_config.blob_lock;
348b93658f8SDaniel Vetter */
349a8f8b1d9SDaniel Vetter struct list_head blobs;
350a8f8b1d9SDaniel Vetter
351b93658f8SDaniel Vetter /** @event_wait: Waitqueue for new events added to @event_list. */
352a8f8b1d9SDaniel Vetter wait_queue_head_t event_wait;
353b93658f8SDaniel Vetter
354b93658f8SDaniel Vetter /**
355b93658f8SDaniel Vetter * @pending_event_list:
356b93658f8SDaniel Vetter *
357b93658f8SDaniel Vetter * List of pending &struct drm_pending_event, used to clean up pending
358b93658f8SDaniel Vetter * events in case this file gets closed before the event is signalled.
359b93658f8SDaniel Vetter * Uses the &drm_pending_event.pending_link entry.
360b93658f8SDaniel Vetter *
361b93658f8SDaniel Vetter * Protect by &drm_device.event_lock.
362b93658f8SDaniel Vetter */
363a8f8b1d9SDaniel Vetter struct list_head pending_event_list;
364b93658f8SDaniel Vetter
365b93658f8SDaniel Vetter /**
366b93658f8SDaniel Vetter * @event_list:
367b93658f8SDaniel Vetter *
368b93658f8SDaniel Vetter * List of &struct drm_pending_event, ready for delivery to userspace
369b93658f8SDaniel Vetter * through drm_read(). Uses the &drm_pending_event.link entry.
370b93658f8SDaniel Vetter *
371b93658f8SDaniel Vetter * Protect by &drm_device.event_lock.
372b93658f8SDaniel Vetter */
373a8f8b1d9SDaniel Vetter struct list_head event_list;
374b93658f8SDaniel Vetter
375b93658f8SDaniel Vetter /**
376b93658f8SDaniel Vetter * @event_space:
377b93658f8SDaniel Vetter *
378b93658f8SDaniel Vetter * Available event space to prevent userspace from
379b93658f8SDaniel Vetter * exhausting kernel memory. Currently limited to the fairly arbitrary
380b93658f8SDaniel Vetter * value of 4KB.
381b93658f8SDaniel Vetter */
382a8f8b1d9SDaniel Vetter int event_space;
383a8f8b1d9SDaniel Vetter
384b93658f8SDaniel Vetter /** @event_read_lock: Serializes drm_read(). */
385a8f8b1d9SDaniel Vetter struct mutex event_read_lock;
386a8f8b1d9SDaniel Vetter
387b93658f8SDaniel Vetter /**
388b93658f8SDaniel Vetter * @prime:
389b93658f8SDaniel Vetter *
390b93658f8SDaniel Vetter * Per-file buffer caches used by the PRIME buffer sharing code.
391b93658f8SDaniel Vetter */
392a8f8b1d9SDaniel Vetter struct drm_prime_file_private prime;
393b93658f8SDaniel Vetter
394b93658f8SDaniel Vetter /* private: */
395ee22f763SDave Airlie #if IS_ENABLED(CONFIG_DRM_LEGACY)
396b93658f8SDaniel Vetter unsigned long lock_count; /* DRI1 legacy lock count */
397ee22f763SDave Airlie #endif
398a8f8b1d9SDaniel Vetter };
399a8f8b1d9SDaniel Vetter
400b93658f8SDaniel Vetter /**
401b93658f8SDaniel Vetter * drm_is_primary_client - is this an open file of the primary node
402b93658f8SDaniel Vetter * @file_priv: DRM file
403b93658f8SDaniel Vetter *
404b93658f8SDaniel Vetter * Returns true if this is an open file of the primary node, i.e.
405b93658f8SDaniel Vetter * &drm_file.minor of @file_priv is a primary minor.
406b93658f8SDaniel Vetter *
407b93658f8SDaniel Vetter * See also the :ref:`section on primary nodes and authentication
408b93658f8SDaniel Vetter * <drm_primary_node>`.
409b93658f8SDaniel Vetter */
drm_is_primary_client(const struct drm_file * file_priv)410b93658f8SDaniel Vetter static inline bool drm_is_primary_client(const struct drm_file *file_priv)
411b93658f8SDaniel Vetter {
412b93658f8SDaniel Vetter return file_priv->minor->type == DRM_MINOR_PRIMARY;
413b93658f8SDaniel Vetter }
414b93658f8SDaniel Vetter
415b93658f8SDaniel Vetter /**
416b93658f8SDaniel Vetter * drm_is_render_client - is this an open file of the render node
417b93658f8SDaniel Vetter * @file_priv: DRM file
418b93658f8SDaniel Vetter *
419b93658f8SDaniel Vetter * Returns true if this is an open file of the render node, i.e.
420b93658f8SDaniel Vetter * &drm_file.minor of @file_priv is a render minor.
421b93658f8SDaniel Vetter *
422b93658f8SDaniel Vetter * See also the :ref:`section on render nodes <drm_render_node>`.
423b93658f8SDaniel Vetter */
drm_is_render_client(const struct drm_file * file_priv)424a8f8b1d9SDaniel Vetter static inline bool drm_is_render_client(const struct drm_file *file_priv)
425a8f8b1d9SDaniel Vetter {
426a8f8b1d9SDaniel Vetter return file_priv->minor->type == DRM_MINOR_RENDER;
427a8f8b1d9SDaniel Vetter }
428a8f8b1d9SDaniel Vetter
4292c204f3dSOded Gabbay /**
4302c204f3dSOded Gabbay * drm_is_accel_client - is this an open file of the compute acceleration node
4312c204f3dSOded Gabbay * @file_priv: DRM file
4322c204f3dSOded Gabbay *
4332c204f3dSOded Gabbay * Returns true if this is an open file of the compute acceleration node, i.e.
4342c204f3dSOded Gabbay * &drm_file.minor of @file_priv is a accel minor.
4352c204f3dSOded Gabbay *
4366d179f84SBagas Sanjaya * See also :doc:`Introduction to compute accelerators subsystem
4376d179f84SBagas Sanjaya * </accel/introduction>`.
4382c204f3dSOded Gabbay */
drm_is_accel_client(const struct drm_file * file_priv)4392c204f3dSOded Gabbay static inline bool drm_is_accel_client(const struct drm_file *file_priv)
4402c204f3dSOded Gabbay {
4412c204f3dSOded Gabbay return file_priv->minor->type == DRM_MINOR_ACCEL;
4422c204f3dSOded Gabbay }
4432c204f3dSOded Gabbay
444031ddd28STvrtko Ursulin void drm_file_update_pid(struct drm_file *);
445031ddd28STvrtko Ursulin
446*f6b589e3SMichał Winiarski struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
447*f6b589e3SMichał Winiarski void drm_minor_release(struct drm_minor *minor);
448*f6b589e3SMichał Winiarski
449a8f8b1d9SDaniel Vetter int drm_open(struct inode *inode, struct file *filp);
4502c204f3dSOded Gabbay int drm_open_helper(struct file *filp, struct drm_minor *minor);
451a8f8b1d9SDaniel Vetter ssize_t drm_read(struct file *filp, char __user *buffer,
452a8f8b1d9SDaniel Vetter size_t count, loff_t *offset);
453a8f8b1d9SDaniel Vetter int drm_release(struct inode *inode, struct file *filp);
4547a2c65ddSChris Wilson int drm_release_noglobal(struct inode *inode, struct file *filp);
455afc9a42bSAl Viro __poll_t drm_poll(struct file *filp, struct poll_table_struct *wait);
456a8f8b1d9SDaniel Vetter int drm_event_reserve_init_locked(struct drm_device *dev,
457a8f8b1d9SDaniel Vetter struct drm_file *file_priv,
458a8f8b1d9SDaniel Vetter struct drm_pending_event *p,
459a8f8b1d9SDaniel Vetter struct drm_event *e);
460a8f8b1d9SDaniel Vetter int drm_event_reserve_init(struct drm_device *dev,
461a8f8b1d9SDaniel Vetter struct drm_file *file_priv,
462a8f8b1d9SDaniel Vetter struct drm_pending_event *p,
463a8f8b1d9SDaniel Vetter struct drm_event *e);
464a8f8b1d9SDaniel Vetter void drm_event_cancel_free(struct drm_device *dev,
465a8f8b1d9SDaniel Vetter struct drm_pending_event *p);
466a8f8b1d9SDaniel Vetter void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
467a8f8b1d9SDaniel Vetter void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
468a78e7a51SVeera Sundaram Sankaran void drm_send_event_timestamp_locked(struct drm_device *dev,
469a78e7a51SVeera Sundaram Sankaran struct drm_pending_event *e,
470a78e7a51SVeera Sundaram Sankaran ktime_t timestamp);
471686b21b5SRob Clark
472686b21b5SRob Clark /**
473686b21b5SRob Clark * struct drm_memory_stats - GEM object stats associated
474686b21b5SRob Clark * @shared: Total size of GEM objects shared between processes
475686b21b5SRob Clark * @private: Total size of GEM objects
476686b21b5SRob Clark * @resident: Total size of GEM objects backing pages
477686b21b5SRob Clark * @purgeable: Total size of GEM objects that can be purged (resident and not active)
478686b21b5SRob Clark * @active: Total size of GEM objects active on one or more engines
479686b21b5SRob Clark *
480686b21b5SRob Clark * Used by drm_print_memory_stats()
481686b21b5SRob Clark */
482686b21b5SRob Clark struct drm_memory_stats {
483686b21b5SRob Clark u64 shared;
484686b21b5SRob Clark u64 private;
485686b21b5SRob Clark u64 resident;
486686b21b5SRob Clark u64 purgeable;
487686b21b5SRob Clark u64 active;
488686b21b5SRob Clark };
489686b21b5SRob Clark
490686b21b5SRob Clark enum drm_gem_object_status;
491686b21b5SRob Clark
492686b21b5SRob Clark void drm_print_memory_stats(struct drm_printer *p,
493686b21b5SRob Clark const struct drm_memory_stats *stats,
494686b21b5SRob Clark enum drm_gem_object_status supported_status,
495686b21b5SRob Clark const char *region);
496686b21b5SRob Clark
497686b21b5SRob Clark void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
4983f09a0cdSRob Clark void drm_show_fdinfo(struct seq_file *m, struct file *f);
499a8f8b1d9SDaniel Vetter
5004748aa16SChris Wilson struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
5014748aa16SChris Wilson
502a8f8b1d9SDaniel Vetter #endif /* _DRM_FILE_H_ */
503