blob: f588f967bb1498df62cf7e2d338fcecbc0401ce5 [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 const struct drm_driver *driver;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010080
Daniel Vetter3214a162019-01-11 17:40:48 +010081 /**
82 * @dev_private:
83 *
Daniel Vetter74aae1c2020-04-03 15:57:47 +020084 * DRM driver private data. This is deprecated and should be left set to
85 * NULL.
86 *
87 * Instead of using this pointer it is recommended that drivers use
Daniel Vetter4c8e84b82020-09-02 09:26:27 +020088 * devm_drm_dev_alloc() and embed struct &drm_device in their larger
Daniel Vetter74aae1c2020-04-03 15:57:47 +020089 * per-device structure.
Daniel Vetter3214a162019-01-11 17:40:48 +010090 */
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010091 void *dev_private;
92
93 /** @primary: Primary node */
94 struct drm_minor *primary;
95
96 /** @render: Render node */
97 struct drm_minor *render;
98
Daniel Vetter3214a162019-01-11 17:40:48 +010099 /**
100 * @registered:
101 *
102 * Internally used by drm_dev_register() and drm_connector_register().
103 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200104 bool registered;
105
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100106 /**
107 * @master:
108 *
109 * Currently active master for this device.
110 * Protected by &master_mutex
111 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200112 struct drm_master *master;
113
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300114 /**
Ville Syrjälä18ace112018-09-13 16:16:21 +0300115 * @driver_features: per-device driver features
116 *
117 * Drivers can clear specific flags here to disallow
118 * certain features on a per-device basis while still
119 * sharing a single &struct drm_driver instance across
120 * all devices.
121 */
122 u32 driver_features;
123
124 /**
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300125 * @unplugged:
126 *
127 * Flag to tell if the device has been unplugged.
128 * See drm_dev_enter() and drm_dev_is_unplugged().
129 */
130 bool unplugged;
131
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100132 /** @anon_inode: inode for private address-space */
133 struct inode *anon_inode;
Daniel Vettere4672e52017-08-02 13:56:01 +0200134
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100135 /** @unique: Unique name of the device */
136 char *unique;
Daniel Vettere4672e52017-08-02 13:56:01 +0200137
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100138 /**
139 * @struct_mutex:
140 *
141 * Lock for others (not &drm_minor.master and &drm_file.is_master)
Emil Velikove33f4232020-05-15 10:50:45 +0100142 *
143 * WARNING:
144 * Only drivers annotated with DRIVER_LEGACY should be using this.
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100145 */
146 struct mutex struct_mutex;
147
148 /**
149 * @master_mutex:
150 *
151 * Lock for &drm_minor.master and &drm_file.is_master
152 */
153 struct mutex master_mutex;
154
155 /**
156 * @open_count:
157 *
158 * Usage counter for outstanding files open,
159 * protected by drm_global_mutex
160 */
Chris Wilson7e13ad82020-01-24 13:01:07 +0000161 atomic_t open_count;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100162
Daniel Vetter3214a162019-01-11 17:40:48 +0100163 /** @filelist_mutex: Protects @filelist. */
Daniel Vettere4672e52017-08-02 13:56:01 +0200164 struct mutex filelist_mutex;
Daniel Vetter3214a162019-01-11 17:40:48 +0100165 /**
166 * @filelist:
167 *
168 * List of userspace clients, linked through &drm_file.lhead.
169 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200170 struct list_head filelist;
171
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200172 /**
173 * @filelist_internal:
174 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100175 * List of open DRM files for in-kernel clients.
176 * Protected by &filelist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200177 */
178 struct list_head filelist_internal;
179
180 /**
181 * @clientlist_mutex:
182 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100183 * Protects &clientlist access.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200184 */
185 struct mutex clientlist_mutex;
186
187 /**
188 * @clientlist:
189 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100190 * List of in-kernel clients. Protected by &clientlist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200191 */
192 struct list_head clientlist;
193
Daniel Vettere4672e52017-08-02 13:56:01 +0200194 /**
195 * @irq_enabled:
196 *
197 * Indicates that interrupt handling is enabled, specifically vblank
198 * handling. Drivers which don't use drm_irq_install() need to set this
199 * to true manually.
200 */
201 bool irq_enabled;
Daniel Vetter3214a162019-01-11 17:40:48 +0100202
203 /**
204 * @irq: Used by the drm_irq_install() and drm_irq_unistall() helpers.
205 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200206 int irq;
207
208 /**
209 * @vblank_disable_immediate:
210 *
211 * If true, vblank interrupt will be disabled immediately when the
212 * refcount drops to zero, as opposed to via the vblank disable
213 * timer.
214 *
215 * This can be set to true it the hardware has a working vblank counter
216 * with high-precision timestamping (otherwise there are races) and the
217 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
218 * appropriately. See also @max_vblank_count and
219 * &drm_crtc_funcs.get_vblank_counter.
220 */
221 bool vblank_disable_immediate;
222
223 /**
224 * @vblank:
225 *
226 * Array of vblank tracking structures, one per &struct drm_crtc. For
227 * historical reasons (vblank support predates kernel modesetting) this
228 * is free-standing and not part of &struct drm_crtc itself. It must be
229 * initialized explicitly by calling drm_vblank_init().
230 */
231 struct drm_vblank_crtc *vblank;
232
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100233 /**
234 * @vblank_time_lock:
235 *
236 * Protects vblank count and time updates during vblank enable/disable
237 */
238 spinlock_t vblank_time_lock;
Daniel Vetter3214a162019-01-11 17:40:48 +0100239 /**
240 * @vbl_lock: Top-level vblank references lock, wraps the low-level
241 * @vblank_time_lock.
242 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200243 spinlock_t vbl_lock;
244
245 /**
246 * @max_vblank_count:
247 *
248 * Maximum value of the vblank registers. This value +1 will result in a
249 * wrap-around of the vblank register. It is used by the vblank core to
250 * handle wrap-arounds.
251 *
252 * If set to zero the vblank core will try to guess the elapsed vblanks
253 * between times when the vblank interrupt is disabled through
254 * high-precision timestamps. That approach is suffering from small
255 * races and imprecision over longer time periods, hence exposing a
256 * hardware vblank counter is always recommended.
257 *
Ville Syrjäläed201512018-11-27 20:20:04 +0200258 * This is the statically configured device wide maximum. The driver
259 * can instead choose to use a runtime configurable per-crtc value
260 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
261 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
262 * to use the per-crtc value.
263 *
Daniel Vetter3214a162019-01-11 17:40:48 +0100264 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
Daniel Vettere4672e52017-08-02 13:56:01 +0200265 */
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100266 u32 max_vblank_count;
267
268 /** @vblank_event_list: List of vblank events */
Daniel Vettere4672e52017-08-02 13:56:01 +0200269 struct list_head vblank_event_list;
Daniel Vetter3214a162019-01-11 17:40:48 +0100270
271 /**
272 * @event_lock:
273 *
274 * Protects @vblank_event_list and event delivery in
275 * general. See drm_send_event() and drm_send_event_locked().
276 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200277 spinlock_t event_lock;
278
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100279 /** @num_crtcs: Number of CRTCs on this device */
280 unsigned int num_crtcs;
Daniel Vettere4672e52017-08-02 13:56:01 +0200281
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100282 /** @mode_config: Current mode config */
283 struct drm_mode_config mode_config;
Daniel Vettere4672e52017-08-02 13:56:01 +0200284
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100285 /** @object_name_lock: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200286 struct mutex object_name_lock;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100287
288 /** @object_name_idr: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200289 struct idr object_name_idr;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100290
291 /** @vma_offset_manager: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200292 struct drm_vma_offset_manager *vma_offset_manager;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100293
Thomas Zimmermann59f59892019-05-08 10:26:18 +0200294 /** @vram_mm: VRAM MM memory manager */
295 struct drm_vram_mm *vram_mm;
296
Sam Ravnborg7af78f42019-01-08 20:29:29 +0100297 /**
298 * @switch_power_state:
299 *
300 * Power state of the client.
301 * Used by drivers supporting the switcheroo driver.
302 * The state is maintained in the
303 * &vga_switcheroo_client_ops.set_gpu_state callback
304 */
305 enum switch_power_state switch_power_state;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +0100306
307 /**
308 * @fb_helper:
309 *
310 * Pointer to the fbdev emulation structure.
311 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
312 */
313 struct drm_fb_helper *fb_helper;
Daniel Vetter3214a162019-01-11 17:40:48 +0100314
315 /* Everything below here is for legacy driver, never use! */
316 /* private: */
Dave Airlie83c163f2019-04-23 09:56:01 +1000317#if IS_ENABLED(CONFIG_DRM_LEGACY)
Laurent Pinchart8dbe1b42020-02-20 17:16:28 +0200318 /* List of devices per driver for stealth attach cleanup */
319 struct list_head legacy_dev_list;
320
Thomas Zimmermann14054f22021-01-12 09:10:35 +0100321#ifdef __alpha__
322 /** @hose: PCI hose, only used on ALPHA platforms. */
323 struct pci_controller *hose;
324#endif
325
Thomas Zimmermann04dfe192021-05-07 20:57:09 +0200326 /* AGP data */
327 struct drm_agp_head *agp;
328
Daniel Vetter3214a162019-01-11 17:40:48 +0100329 /* Context handle management - linked list of context handles */
330 struct list_head ctxlist;
331
332 /* Context handle management - mutex for &ctxlist */
333 struct mutex ctxlist_mutex;
334
335 /* Context handle management */
336 struct idr ctx_idr;
337
338 /* Memory management - linked list of regions */
339 struct list_head maplist;
340
341 /* Memory management - user token hash table for maps */
342 struct drm_open_hash map_hash;
343
344 /* Context handle management - list of vmas (for debugging) */
345 struct list_head vmalist;
346
347 /* Optional pointer for DMA support */
348 struct drm_device_dma *dma;
349
350 /* Context swapping flag */
351 __volatile__ long context_flag;
352
353 /* Last current context */
354 int last_context;
355
356 /* Lock for &buf_use and a few other things. */
357 spinlock_t buf_lock;
358
359 /* Usage counter for buffers in use -- cannot alloc */
360 int buf_use;
361
362 /* Buffer allocation in progress */
363 atomic_t buf_alloc;
364
365 struct {
366 int context;
367 struct drm_hw_lock *lock;
368 } sigdata;
369
370 struct drm_local_map *agp_buffer_map;
371 unsigned int agp_buffer_token;
372
373 /* Scatter gather memory */
374 struct drm_sg_mem *sg;
Dave Airlie83c163f2019-04-23 09:56:01 +1000375#endif
Daniel Vettere4672e52017-08-02 13:56:01 +0200376};
377
378#endif