drm_auth.h revision 1.4 1 /* $NetBSD: drm_auth.h,v 1.4 2021/12/19 01:54:28 riastradh Exp $ */
2
3 #ifndef _DRM_AUTH_H_
4 #define _DRM_AUTH_H_
5
6 /*
7 * Internal Header for the Direct Rendering Manager
8 *
9 * Copyright 2016 Intel Corporation
10 *
11 * Author: Daniel Vetter <daniel.vetter (at) ffwll.ch>
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice (including the next
21 * paragraph) shall be included in all copies or substantial portions of the
22 * Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
31 */
32
33 #include <linux/idr.h>
34 #include <linux/kref.h>
35 #include <linux/wait.h>
36
37 struct drm_file;
38 struct drm_hw_lock;
39
40 #include <linux/idr.h>
41 #include <linux/kref.h>
42 #include <linux/list.h>
43 #include <linux/spinlock.h>
44 #include <linux/types.h>
45
46 #ifdef __NetBSD__
47 #include <drm/drm_wait_netbsd.h>
48 #endif
49
50 struct drm_device;
51 struct drm_file;
52 struct drm_hw_lock;
53 struct drm_master;
54
55 /*
56 * Legacy DRI1 locking data structure. Only here instead of in drm_legacy.h for
57 * include ordering reasons.
58 *
59 * DO NOT USE.
60 */
61 struct drm_lock_data {
62 struct drm_hw_lock *hw_lock;
63 struct drm_file *file_priv;
64 #ifdef __NetBSD__
65 drm_waitqueue_t lock_queue; /**< Queue of blocked processes */
66 #else
67 wait_queue_head_t lock_queue;
68 #endif
69 unsigned long lock_time;
70 spinlock_t spinlock;
71 uint32_t kernel_waiters;
72 uint32_t user_waiters;
73 int idle_has_lock;
74 };
75
76 /**
77 * struct drm_master - drm master structure
78 *
79 * @refcount: Refcount for this master object.
80 * @dev: Link back to the DRM device
81 * @driver_priv: Pointer to driver-private information.
82 * @lessor: Lease holder
83 * @lessee_id: id for lessees. Owners always have id 0
84 * @lessee_list: other lessees of the same master
85 * @lessees: drm_masters leasing from this one
86 * @leases: Objects leased to this drm_master.
87 * @lessee_idr: All lessees under this owner (only used where lessor == NULL)
88 *
89 * Note that master structures are only relevant for the legacy/primary device
90 * nodes, hence there can only be one per device, not one per drm_minor.
91 */
92 struct drm_master {
93 struct kref refcount;
94 struct drm_device *dev;
95 /**
96 * @unique: Unique identifier: e.g. busid. Protected by
97 * &drm_device.master_mutex.
98 */
99 char *unique;
100 /**
101 * @unique_len: Length of unique field. Protected by
102 * &drm_device.master_mutex.
103 */
104 int unique_len;
105 /**
106 * @magic_map: Map of used authentication tokens. Protected by
107 * &drm_device.master_mutex.
108 */
109 struct idr magic_map;
110 void *driver_priv;
111
112 /* Tree of display resource leases, each of which is a drm_master struct
113 * All of these get activated simultaneously, so drm_device master points
114 * at the top of the tree (for which lessor is NULL). Protected by
115 * &drm_device.mode_config.idr_mutex.
116 */
117
118 struct drm_master *lessor;
119 int lessee_id;
120 struct list_head lessee_list;
121 struct list_head lessees;
122 struct idr leases;
123 struct idr lessee_idr;
124 /* private: */
125 #if IS_ENABLED(CONFIG_DRM_LEGACY)
126 struct drm_lock_data lock;
127 #endif
128 };
129
130 struct drm_master *drm_master_get(struct drm_master *master);
131 void drm_master_put(struct drm_master **master);
132 bool drm_is_current_master(struct drm_file *fpriv);
133
134 struct drm_master *drm_master_create(struct drm_device *dev);
135
136 #endif
137