blob: bd5abe7cd48f67719c885e8b6d038bfb4cebaccc [file] [log] [blame]
Daniel Vettere4672e52017-08-02 13:56:01 +02001#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;
Thomas Zimmermann59f59892019-05-08 10:26:18 +020020struct drm_vram_mm;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +010021struct drm_fb_helper;
Daniel Vettere4672e52017-08-02 13:56:01 +020022
23struct inode;
24
25struct pci_dev;
26struct pci_controller;
27
Sam Ravnborg7af78f42019-01-08 20:29:29 +010028
29/**
Mauro Carvalho Chehabe9d28712020-11-16 11:18:01 +010030 * enum switch_power_state - power state of drm device
Sam Ravnborg7af78f42019-01-08 20:29:29 +010031 */
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
Daniel Vettere4672e52017-08-02 13:56:01 +020047/**
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010048 * struct drm_device - DRM device structure
49 *
50 * This structure represent a complete card that
Daniel Vettere4672e52017-08-02 13:56:01 +020051 * may contain multiple heads.
52 */
53struct drm_device {
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010054 /** @if_version: Highest interface version set */
55 int if_version;
56
57 /** @ref: Object ref-count */
58 struct kref ref;
59
60 /** @dev: Device structure of bus-device */
61 struct device *dev;
62
Daniel Vetterc6603c72020-03-24 13:45:40 +010063 /**
64 * @managed:
65 *
66 * Managed resources linked to the lifetime of this &drm_device as
67 * tracked by @ref.
68 */
69 struct {
70 /** @managed.resources: managed resources list */
71 struct list_head resources;
72 /** @managed.final_kfree: pointer for final kfree() call */
73 void *final_kfree;
74 /** @managed.lock: protects @managed.resources */
75 spinlock_t lock;
76 } managed;
77
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010078 /** @driver: DRM driver managing the device */
Daniel Vetter8f5c7aa2020-11-04 11:04:23 +010079#ifdef CONFIG_DRM_LEGACY
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010080 struct drm_driver *driver;
Daniel Vetter8f5c7aa2020-11-04 11:04:23 +010081#else
82 const struct drm_driver *driver;
83#endif
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010084
Daniel Vetter3214a162019-01-11 17:40:48 +010085 /**
86 * @dev_private:
87 *
Daniel Vetter74aae1c2020-04-03 15:57:47 +020088 * DRM driver private data. This is deprecated and should be left set to
89 * NULL.
90 *
91 * Instead of using this pointer it is recommended that drivers use
Daniel Vetter4c8e84b82020-09-02 09:26:27 +020092 * devm_drm_dev_alloc() and embed struct &drm_device in their larger
Daniel Vetter74aae1c2020-04-03 15:57:47 +020093 * per-device structure.
Daniel Vetter3214a162019-01-11 17:40:48 +010094 */
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010095 void *dev_private;
96
97 /** @primary: Primary node */
98 struct drm_minor *primary;
99
100 /** @render: Render node */
101 struct drm_minor *render;
102
Daniel Vetter3214a162019-01-11 17:40:48 +0100103 /**
104 * @registered:
105 *
106 * Internally used by drm_dev_register() and drm_connector_register().
107 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200108 bool registered;
109
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100110 /**
111 * @master:
112 *
113 * Currently active master for this device.
114 * Protected by &master_mutex
115 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200116 struct drm_master *master;
117
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300118 /**
Ville Syrjälä18ace112018-09-13 16:16:21 +0300119 * @driver_features: per-device driver features
120 *
121 * Drivers can clear specific flags here to disallow
122 * certain features on a per-device basis while still
123 * sharing a single &struct drm_driver instance across
124 * all devices.
125 */
126 u32 driver_features;
127
128 /**
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300129 * @unplugged:
130 *
131 * Flag to tell if the device has been unplugged.
132 * See drm_dev_enter() and drm_dev_is_unplugged().
133 */
134 bool unplugged;
135
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100136 /** @anon_inode: inode for private address-space */
137 struct inode *anon_inode;
Daniel Vettere4672e52017-08-02 13:56:01 +0200138
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100139 /** @unique: Unique name of the device */
140 char *unique;
Daniel Vettere4672e52017-08-02 13:56:01 +0200141
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100142 /**
143 * @struct_mutex:
144 *
145 * Lock for others (not &drm_minor.master and &drm_file.is_master)
Emil Velikove33f4232020-05-15 10:50:45 +0100146 *
147 * WARNING:
148 * Only drivers annotated with DRIVER_LEGACY should be using this.
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100149 */
150 struct mutex struct_mutex;
151
152 /**
153 * @master_mutex:
154 *
155 * Lock for &drm_minor.master and &drm_file.is_master
156 */
157 struct mutex master_mutex;
158
159 /**
160 * @open_count:
161 *
162 * Usage counter for outstanding files open,
163 * protected by drm_global_mutex
164 */
Chris Wilson7e13ad82020-01-24 13:01:07 +0000165 atomic_t open_count;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100166
Daniel Vetter3214a162019-01-11 17:40:48 +0100167 /** @filelist_mutex: Protects @filelist. */
Daniel Vettere4672e52017-08-02 13:56:01 +0200168 struct mutex filelist_mutex;
Daniel Vetter3214a162019-01-11 17:40:48 +0100169 /**
170 * @filelist:
171 *
172 * List of userspace clients, linked through &drm_file.lhead.
173 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200174 struct list_head filelist;
175
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200176 /**
177 * @filelist_internal:
178 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100179 * List of open DRM files for in-kernel clients.
180 * Protected by &filelist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200181 */
182 struct list_head filelist_internal;
183
184 /**
185 * @clientlist_mutex:
186 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100187 * Protects &clientlist access.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200188 */
189 struct mutex clientlist_mutex;
190
191 /**
192 * @clientlist:
193 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100194 * List of in-kernel clients. Protected by &clientlist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200195 */
196 struct list_head clientlist;
197
Daniel Vettere4672e52017-08-02 13:56:01 +0200198 /**
199 * @irq_enabled:
200 *
201 * Indicates that interrupt handling is enabled, specifically vblank
202 * handling. Drivers which don't use drm_irq_install() need to set this
203 * to true manually.
204 */
205 bool irq_enabled;
Daniel Vetter3214a162019-01-11 17:40:48 +0100206
207 /**
208 * @irq: Used by the drm_irq_install() and drm_irq_unistall() helpers.
209 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200210 int irq;
211
212 /**
213 * @vblank_disable_immediate:
214 *
215 * If true, vblank interrupt will be disabled immediately when the
216 * refcount drops to zero, as opposed to via the vblank disable
217 * timer.
218 *
219 * This can be set to true it the hardware has a working vblank counter
220 * with high-precision timestamping (otherwise there are races) and the
221 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
222 * appropriately. See also @max_vblank_count and
223 * &drm_crtc_funcs.get_vblank_counter.
224 */
225 bool vblank_disable_immediate;
226
227 /**
228 * @vblank:
229 *
230 * Array of vblank tracking structures, one per &struct drm_crtc. For
231 * historical reasons (vblank support predates kernel modesetting) this
232 * is free-standing and not part of &struct drm_crtc itself. It must be
233 * initialized explicitly by calling drm_vblank_init().
234 */
235 struct drm_vblank_crtc *vblank;
236
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100237 /**
238 * @vblank_time_lock:
239 *
240 * Protects vblank count and time updates during vblank enable/disable
241 */
242 spinlock_t vblank_time_lock;
Daniel Vetter3214a162019-01-11 17:40:48 +0100243 /**
244 * @vbl_lock: Top-level vblank references lock, wraps the low-level
245 * @vblank_time_lock.
246 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200247 spinlock_t vbl_lock;
248
249 /**
250 * @max_vblank_count:
251 *
252 * Maximum value of the vblank registers. This value +1 will result in a
253 * wrap-around of the vblank register. It is used by the vblank core to
254 * handle wrap-arounds.
255 *
256 * If set to zero the vblank core will try to guess the elapsed vblanks
257 * between times when the vblank interrupt is disabled through
258 * high-precision timestamps. That approach is suffering from small
259 * races and imprecision over longer time periods, hence exposing a
260 * hardware vblank counter is always recommended.
261 *
Ville Syrjäläed201512018-11-27 20:20:04 +0200262 * This is the statically configured device wide maximum. The driver
263 * can instead choose to use a runtime configurable per-crtc value
264 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
265 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
266 * to use the per-crtc value.
267 *
Daniel Vetter3214a162019-01-11 17:40:48 +0100268 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
Daniel Vettere4672e52017-08-02 13:56:01 +0200269 */
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100270 u32 max_vblank_count;
271
272 /** @vblank_event_list: List of vblank events */
Daniel Vettere4672e52017-08-02 13:56:01 +0200273 struct list_head vblank_event_list;
Daniel Vetter3214a162019-01-11 17:40:48 +0100274
275 /**
276 * @event_lock:
277 *
278 * Protects @vblank_event_list and event delivery in
279 * general. See drm_send_event() and drm_send_event_locked().
280 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200281 spinlock_t event_lock;
282
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100283 /** @agp: AGP data */
284 struct drm_agp_head *agp;
Daniel Vettere4672e52017-08-02 13:56:01 +0200285
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100286 /** @pdev: PCI device structure */
287 struct pci_dev *pdev;
Daniel Vettere4672e52017-08-02 13:56:01 +0200288
Daniel Vettere4672e52017-08-02 13:56:01 +0200289#ifdef __alpha__
Daniel Vetter3214a162019-01-11 17:40:48 +0100290 /** @hose: PCI hose, only used on ALPHA platforms. */
Daniel Vettere4672e52017-08-02 13:56:01 +0200291 struct pci_controller *hose;
292#endif
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100293 /** @num_crtcs: Number of CRTCs on this device */
294 unsigned int num_crtcs;
Daniel Vettere4672e52017-08-02 13:56:01 +0200295
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100296 /** @mode_config: Current mode config */
297 struct drm_mode_config mode_config;
Daniel Vettere4672e52017-08-02 13:56:01 +0200298
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100299 /** @object_name_lock: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200300 struct mutex object_name_lock;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100301
302 /** @object_name_idr: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200303 struct idr object_name_idr;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100304
305 /** @vma_offset_manager: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200306 struct drm_vma_offset_manager *vma_offset_manager;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100307
Thomas Zimmermann59f59892019-05-08 10:26:18 +0200308 /** @vram_mm: VRAM MM memory manager */
309 struct drm_vram_mm *vram_mm;
310
Sam Ravnborg7af78f42019-01-08 20:29:29 +0100311 /**
312 * @switch_power_state:
313 *
314 * Power state of the client.
315 * Used by drivers supporting the switcheroo driver.
316 * The state is maintained in the
317 * &vga_switcheroo_client_ops.set_gpu_state callback
318 */
319 enum switch_power_state switch_power_state;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +0100320
321 /**
322 * @fb_helper:
323 *
324 * Pointer to the fbdev emulation structure.
325 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
326 */
327 struct drm_fb_helper *fb_helper;
Daniel Vetter3214a162019-01-11 17:40:48 +0100328
329 /* Everything below here is for legacy driver, never use! */
330 /* private: */
Dave Airlie83c163f2019-04-23 09:56:01 +1000331#if IS_ENABLED(CONFIG_DRM_LEGACY)
Laurent Pinchart8dbe1b42020-02-20 17:16:28 +0200332 /* List of devices per driver for stealth attach cleanup */
333 struct list_head legacy_dev_list;
334
Daniel Vetter3214a162019-01-11 17:40:48 +0100335 /* 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;
Dave Airlie83c163f2019-04-23 09:56:01 +1000381#endif
Daniel Vettere4672e52017-08-02 13:56:01 +0200382};
383
384#endif