]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/drm/drm_device.h
x86/boot/compressed/64: Add stage1 #VC handler
[mirror_ubuntu-jammy-kernel.git] / include / drm / drm_device.h
CommitLineData
e4672e55
DV
1#ifndef _DRM_DEVICE_H_
2#define _DRM_DEVICE_H_
3
4#include <linux/list.h>
5#include <linux/kref.h>
6#include <linux/mutex.h>
7#include <linux/idr.h>
8
9#include <drm/drm_hashtab.h>
10#include <drm/drm_mode_config.h>
11
12struct drm_driver;
13struct drm_minor;
14struct drm_master;
15struct drm_device_dma;
16struct drm_vblank_crtc;
17struct drm_sg_mem;
18struct drm_local_map;
19struct drm_vma_offset_manager;
59f5989a 20struct drm_vram_mm;
29ad20b2 21struct drm_fb_helper;
e4672e55
DV
22
23struct inode;
24
25struct pci_dev;
26struct pci_controller;
27
7af78f40
SR
28
29/**
30 * enum drm_switch_power - power state of drm device
31 */
32
33enum switch_power_state {
34 /** @DRM_SWITCH_POWER_ON: Power state is ON */
35 DRM_SWITCH_POWER_ON = 0,
36
37 /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
38 DRM_SWITCH_POWER_OFF = 1,
39
40 /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
41 DRM_SWITCH_POWER_CHANGING = 2,
42
43 /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
44 DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
45};
46
e4672e55 47/**
ac4f24c2
SR
48 * struct drm_device - DRM device structure
49 *
50 * This structure represent a complete card that
e4672e55
DV
51 * may contain multiple heads.
52 */
53struct drm_device {
ac4f24c2
SR
54 /**
55 * @legacy_dev_list:
56 *
57 * List of devices per driver for stealth attach cleanup
58 */
59 struct list_head legacy_dev_list;
60
61 /** @if_version: Highest interface version set */
62 int if_version;
63
64 /** @ref: Object ref-count */
65 struct kref ref;
66
67 /** @dev: Device structure of bus-device */
68 struct device *dev;
69
c6603c74
DV
70 /**
71 * @managed:
72 *
73 * Managed resources linked to the lifetime of this &drm_device as
74 * tracked by @ref.
75 */
76 struct {
77 /** @managed.resources: managed resources list */
78 struct list_head resources;
79 /** @managed.final_kfree: pointer for final kfree() call */
80 void *final_kfree;
81 /** @managed.lock: protects @managed.resources */
82 spinlock_t lock;
83 } managed;
84
ac4f24c2
SR
85 /** @driver: DRM driver managing the device */
86 struct drm_driver *driver;
87
3214a166
DV
88 /**
89 * @dev_private:
90 *
74aae1c4
DV
91 * DRM driver private data. This is deprecated and should be left set to
92 * NULL.
93 *
94 * Instead of using this pointer it is recommended that drivers use
95 * drm_dev_init() and embed struct &drm_device in their larger
96 * per-device structure.
3214a166 97 */
ac4f24c2
SR
98 void *dev_private;
99
100 /** @primary: Primary node */
101 struct drm_minor *primary;
102
103 /** @render: Render node */
104 struct drm_minor *render;
105
3214a166
DV
106 /**
107 * @registered:
108 *
109 * Internally used by drm_dev_register() and drm_connector_register().
110 */
e4672e55
DV
111 bool registered;
112
ac4f24c2
SR
113 /**
114 * @master:
115 *
116 * Currently active master for this device.
117 * Protected by &master_mutex
118 */
e4672e55
DV
119 struct drm_master *master;
120
18ace11f
VS
121 /**
122 * @driver_features: per-device driver features
123 *
124 * Drivers can clear specific flags here to disallow
125 * certain features on a per-device basis while still
126 * sharing a single &struct drm_driver instance across
127 * all devices.
128 */
129 u32 driver_features;
130
bee330f3
NT
131 /**
132 * @unplugged:
133 *
134 * Flag to tell if the device has been unplugged.
135 * See drm_dev_enter() and drm_dev_is_unplugged().
136 */
137 bool unplugged;
138
ac4f24c2
SR
139 /** @anon_inode: inode for private address-space */
140 struct inode *anon_inode;
141
142 /** @unique: Unique name of the device */
143 char *unique;
144
145 /**
146 * @struct_mutex:
147 *
148 * Lock for others (not &drm_minor.master and &drm_file.is_master)
e33f4234
EV
149 *
150 * WARNING:
151 * Only drivers annotated with DRIVER_LEGACY should be using this.
ac4f24c2
SR
152 */
153 struct mutex struct_mutex;
154
155 /**
156 * @master_mutex:
157 *
158 * Lock for &drm_minor.master and &drm_file.is_master
159 */
160 struct mutex master_mutex;
161
162 /**
163 * @open_count:
164 *
165 * Usage counter for outstanding files open,
166 * protected by drm_global_mutex
167 */
7e13ad89 168 atomic_t open_count;
ac4f24c2 169
3214a166 170 /** @filelist_mutex: Protects @filelist. */
e4672e55 171 struct mutex filelist_mutex;
3214a166
DV
172 /**
173 * @filelist:
174 *
175 * List of userspace clients, linked through &drm_file.lhead.
176 */
e4672e55
DV
177 struct list_head filelist;
178
c76f0f7c
NT
179 /**
180 * @filelist_internal:
181 *
ac4f24c2
SR
182 * List of open DRM files for in-kernel clients.
183 * Protected by &filelist_mutex.
c76f0f7c
NT
184 */
185 struct list_head filelist_internal;
186
187 /**
188 * @clientlist_mutex:
189 *
ac4f24c2 190 * Protects &clientlist access.
c76f0f7c
NT
191 */
192 struct mutex clientlist_mutex;
193
194 /**
195 * @clientlist:
196 *
ac4f24c2 197 * List of in-kernel clients. Protected by &clientlist_mutex.
c76f0f7c
NT
198 */
199 struct list_head clientlist;
200
e4672e55
DV
201 /**
202 * @irq_enabled:
203 *
204 * Indicates that interrupt handling is enabled, specifically vblank
205 * handling. Drivers which don't use drm_irq_install() need to set this
206 * to true manually.
207 */
208 bool irq_enabled;
3214a166
DV
209
210 /**
211 * @irq: Used by the drm_irq_install() and drm_irq_unistall() helpers.
212 */
e4672e55
DV
213 int irq;
214
215 /**
216 * @vblank_disable_immediate:
217 *
218 * If true, vblank interrupt will be disabled immediately when the
219 * refcount drops to zero, as opposed to via the vblank disable
220 * timer.
221 *
222 * This can be set to true it the hardware has a working vblank counter
223 * with high-precision timestamping (otherwise there are races) and the
224 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
225 * appropriately. See also @max_vblank_count and
226 * &drm_crtc_funcs.get_vblank_counter.
227 */
228 bool vblank_disable_immediate;
229
230 /**
231 * @vblank:
232 *
233 * Array of vblank tracking structures, one per &struct drm_crtc. For
234 * historical reasons (vblank support predates kernel modesetting) this
235 * is free-standing and not part of &struct drm_crtc itself. It must be
236 * initialized explicitly by calling drm_vblank_init().
237 */
238 struct drm_vblank_crtc *vblank;
239
ac4f24c2
SR
240 /**
241 * @vblank_time_lock:
242 *
243 * Protects vblank count and time updates during vblank enable/disable
244 */
245 spinlock_t vblank_time_lock;
3214a166
DV
246 /**
247 * @vbl_lock: Top-level vblank references lock, wraps the low-level
248 * @vblank_time_lock.
249 */
e4672e55
DV
250 spinlock_t vbl_lock;
251
252 /**
253 * @max_vblank_count:
254 *
255 * Maximum value of the vblank registers. This value +1 will result in a
256 * wrap-around of the vblank register. It is used by the vblank core to
257 * handle wrap-arounds.
258 *
259 * If set to zero the vblank core will try to guess the elapsed vblanks
260 * between times when the vblank interrupt is disabled through
261 * high-precision timestamps. That approach is suffering from small
262 * races and imprecision over longer time periods, hence exposing a
263 * hardware vblank counter is always recommended.
264 *
ed20151a
VS
265 * This is the statically configured device wide maximum. The driver
266 * can instead choose to use a runtime configurable per-crtc value
267 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
268 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
269 * to use the per-crtc value.
270 *
3214a166 271 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
e4672e55 272 */
ac4f24c2
SR
273 u32 max_vblank_count;
274
275 /** @vblank_event_list: List of vblank events */
e4672e55 276 struct list_head vblank_event_list;
3214a166
DV
277
278 /**
279 * @event_lock:
280 *
281 * Protects @vblank_event_list and event delivery in
282 * general. See drm_send_event() and drm_send_event_locked().
283 */
e4672e55
DV
284 spinlock_t event_lock;
285
ac4f24c2
SR
286 /** @agp: AGP data */
287 struct drm_agp_head *agp;
e4672e55 288
ac4f24c2
SR
289 /** @pdev: PCI device structure */
290 struct pci_dev *pdev;
e4672e55 291
e4672e55 292#ifdef __alpha__
3214a166 293 /** @hose: PCI hose, only used on ALPHA platforms. */
e4672e55
DV
294 struct pci_controller *hose;
295#endif
ac4f24c2
SR
296 /** @num_crtcs: Number of CRTCs on this device */
297 unsigned int num_crtcs;
e4672e55 298
ac4f24c2
SR
299 /** @mode_config: Current mode config */
300 struct drm_mode_config mode_config;
e4672e55 301
ac4f24c2 302 /** @object_name_lock: GEM information */
e4672e55 303 struct mutex object_name_lock;
ac4f24c2
SR
304
305 /** @object_name_idr: GEM information */
e4672e55 306 struct idr object_name_idr;
ac4f24c2
SR
307
308 /** @vma_offset_manager: GEM information */
e4672e55 309 struct drm_vma_offset_manager *vma_offset_manager;
ac4f24c2 310
59f5989a
TZ
311 /** @vram_mm: VRAM MM memory manager */
312 struct drm_vram_mm *vram_mm;
313
7af78f40
SR
314 /**
315 * @switch_power_state:
316 *
317 * Power state of the client.
318 * Used by drivers supporting the switcheroo driver.
319 * The state is maintained in the
320 * &vga_switcheroo_client_ops.set_gpu_state callback
321 */
322 enum switch_power_state switch_power_state;
29ad20b2
NT
323
324 /**
325 * @fb_helper:
326 *
327 * Pointer to the fbdev emulation structure.
328 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
329 */
330 struct drm_fb_helper *fb_helper;
3214a166
DV
331
332 /* Everything below here is for legacy driver, never use! */
333 /* private: */
83c163f7 334#if IS_ENABLED(CONFIG_DRM_LEGACY)
3214a166
DV
335 /* Context handle management - linked list of context handles */
336 struct list_head ctxlist;
337
338 /* Context handle management - mutex for &ctxlist */
339 struct mutex ctxlist_mutex;
340
341 /* Context handle management */
342 struct idr ctx_idr;
343
344 /* Memory management - linked list of regions */
345 struct list_head maplist;
346
347 /* Memory management - user token hash table for maps */
348 struct drm_open_hash map_hash;
349
350 /* Context handle management - list of vmas (for debugging) */
351 struct list_head vmalist;
352
353 /* Optional pointer for DMA support */
354 struct drm_device_dma *dma;
355
356 /* Context swapping flag */
357 __volatile__ long context_flag;
358
359 /* Last current context */
360 int last_context;
361
362 /* Lock for &buf_use and a few other things. */
363 spinlock_t buf_lock;
364
365 /* Usage counter for buffers in use -- cannot alloc */
366 int buf_use;
367
368 /* Buffer allocation in progress */
369 atomic_t buf_alloc;
370
371 struct {
372 int context;
373 struct drm_hw_lock *lock;
374 } sigdata;
375
376 struct drm_local_map *agp_buffer_map;
377 unsigned int agp_buffer_token;
378
379 /* Scatter gather memory */
380 struct drm_sg_mem *sg;
83c163f7 381#endif
e4672e55
DV
382};
383
384#endif