blob: 9923c7a6885e89dc6621d16c17d7df52520df2d2 [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
Thomas Zimmermanna21800b2021-11-29 10:48:41 +01009#include <drm/drm_legacy.h>
Daniel Vettere4672e52017-08-02 13:56:01 +020010#include <drm/drm_mode_config.h>
11
12struct drm_driver;
13struct drm_minor;
14struct drm_master;
Daniel Vettere4672e52017-08-02 13:56:01 +020015struct drm_vblank_crtc;
Daniel Vettere4672e52017-08-02 13:56:01 +020016struct drm_vma_offset_manager;
Thomas Zimmermann59f59892019-05-08 10:26:18 +020017struct drm_vram_mm;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +010018struct drm_fb_helper;
Daniel Vettere4672e52017-08-02 13:56:01 +020019
20struct inode;
21
22struct pci_dev;
23struct pci_controller;
24
Sam Ravnborg7af78f42019-01-08 20:29:29 +010025
26/**
Mauro Carvalho Chehabe9d28712020-11-16 11:18:01 +010027 * enum switch_power_state - power state of drm device
Sam Ravnborg7af78f42019-01-08 20:29:29 +010028 */
29
30enum switch_power_state {
31 /** @DRM_SWITCH_POWER_ON: Power state is ON */
32 DRM_SWITCH_POWER_ON = 0,
33
34 /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
35 DRM_SWITCH_POWER_OFF = 1,
36
37 /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
38 DRM_SWITCH_POWER_CHANGING = 2,
39
40 /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
41 DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
42};
43
Daniel Vettere4672e52017-08-02 13:56:01 +020044/**
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010045 * struct drm_device - DRM device structure
46 *
47 * This structure represent a complete card that
Daniel Vettere4672e52017-08-02 13:56:01 +020048 * may contain multiple heads.
49 */
50struct drm_device {
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010051 /** @if_version: Highest interface version set */
52 int if_version;
53
54 /** @ref: Object ref-count */
55 struct kref ref;
56
57 /** @dev: Device structure of bus-device */
58 struct device *dev;
59
Daniel Vetterc6603c72020-03-24 13:45:40 +010060 /**
61 * @managed:
62 *
63 * Managed resources linked to the lifetime of this &drm_device as
64 * tracked by @ref.
65 */
66 struct {
67 /** @managed.resources: managed resources list */
68 struct list_head resources;
69 /** @managed.final_kfree: pointer for final kfree() call */
70 void *final_kfree;
71 /** @managed.lock: protects @managed.resources */
72 spinlock_t lock;
73 } managed;
74
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010075 /** @driver: DRM driver managing the device */
Daniel Vetter8f5c7aa2020-11-04 11:04:23 +010076 const struct drm_driver *driver;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010077
Daniel Vetter3214a162019-01-11 17:40:48 +010078 /**
79 * @dev_private:
80 *
Daniel Vetter74aae1c2020-04-03 15:57:47 +020081 * DRM driver private data. This is deprecated and should be left set to
82 * NULL.
83 *
84 * Instead of using this pointer it is recommended that drivers use
Daniel Vetter4c8e84b82020-09-02 09:26:27 +020085 * devm_drm_dev_alloc() and embed struct &drm_device in their larger
Daniel Vetter74aae1c2020-04-03 15:57:47 +020086 * per-device structure.
Daniel Vetter3214a162019-01-11 17:40:48 +010087 */
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010088 void *dev_private;
89
90 /** @primary: Primary node */
91 struct drm_minor *primary;
92
93 /** @render: Render node */
94 struct drm_minor *render;
95
Daniel Vetter3214a162019-01-11 17:40:48 +010096 /**
97 * @registered:
98 *
99 * Internally used by drm_dev_register() and drm_connector_register().
100 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200101 bool registered;
102
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100103 /**
104 * @master:
105 *
106 * Currently active master for this device.
107 * Protected by &master_mutex
108 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200109 struct drm_master *master;
110
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300111 /**
Ville Syrjälä18ace112018-09-13 16:16:21 +0300112 * @driver_features: per-device driver features
113 *
114 * Drivers can clear specific flags here to disallow
115 * certain features on a per-device basis while still
116 * sharing a single &struct drm_driver instance across
117 * all devices.
118 */
119 u32 driver_features;
120
121 /**
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300122 * @unplugged:
123 *
124 * Flag to tell if the device has been unplugged.
125 * See drm_dev_enter() and drm_dev_is_unplugged().
126 */
127 bool unplugged;
128
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100129 /** @anon_inode: inode for private address-space */
130 struct inode *anon_inode;
Daniel Vettere4672e52017-08-02 13:56:01 +0200131
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100132 /** @unique: Unique name of the device */
133 char *unique;
Daniel Vettere4672e52017-08-02 13:56:01 +0200134
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100135 /**
136 * @struct_mutex:
137 *
138 * Lock for others (not &drm_minor.master and &drm_file.is_master)
Emil Velikove33f4232020-05-15 10:50:45 +0100139 *
140 * WARNING:
141 * Only drivers annotated with DRIVER_LEGACY should be using this.
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100142 */
143 struct mutex struct_mutex;
144
145 /**
146 * @master_mutex:
147 *
148 * Lock for &drm_minor.master and &drm_file.is_master
149 */
150 struct mutex master_mutex;
151
152 /**
153 * @open_count:
154 *
155 * Usage counter for outstanding files open,
156 * protected by drm_global_mutex
157 */
Chris Wilson7e13ad82020-01-24 13:01:07 +0000158 atomic_t open_count;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100159
Daniel Vetter3214a162019-01-11 17:40:48 +0100160 /** @filelist_mutex: Protects @filelist. */
Daniel Vettere4672e52017-08-02 13:56:01 +0200161 struct mutex filelist_mutex;
Daniel Vetter3214a162019-01-11 17:40:48 +0100162 /**
163 * @filelist:
164 *
165 * List of userspace clients, linked through &drm_file.lhead.
166 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200167 struct list_head filelist;
168
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200169 /**
170 * @filelist_internal:
171 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100172 * List of open DRM files for in-kernel clients.
173 * Protected by &filelist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200174 */
175 struct list_head filelist_internal;
176
177 /**
178 * @clientlist_mutex:
179 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100180 * Protects &clientlist access.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200181 */
182 struct mutex clientlist_mutex;
183
184 /**
185 * @clientlist:
186 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100187 * List of in-kernel clients. Protected by &clientlist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200188 */
189 struct list_head clientlist;
190
Daniel Vettere4672e52017-08-02 13:56:01 +0200191 /**
Daniel Vettere4672e52017-08-02 13:56:01 +0200192 * @vblank_disable_immediate:
193 *
194 * If true, vblank interrupt will be disabled immediately when the
195 * refcount drops to zero, as opposed to via the vblank disable
196 * timer.
197 *
198 * This can be set to true it the hardware has a working vblank counter
199 * with high-precision timestamping (otherwise there are races) and the
200 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
201 * appropriately. See also @max_vblank_count and
202 * &drm_crtc_funcs.get_vblank_counter.
203 */
204 bool vblank_disable_immediate;
205
206 /**
207 * @vblank:
208 *
209 * Array of vblank tracking structures, one per &struct drm_crtc. For
210 * historical reasons (vblank support predates kernel modesetting) this
211 * is free-standing and not part of &struct drm_crtc itself. It must be
212 * initialized explicitly by calling drm_vblank_init().
213 */
214 struct drm_vblank_crtc *vblank;
215
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100216 /**
217 * @vblank_time_lock:
218 *
219 * Protects vblank count and time updates during vblank enable/disable
220 */
221 spinlock_t vblank_time_lock;
Daniel Vetter3214a162019-01-11 17:40:48 +0100222 /**
223 * @vbl_lock: Top-level vblank references lock, wraps the low-level
224 * @vblank_time_lock.
225 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200226 spinlock_t vbl_lock;
227
228 /**
229 * @max_vblank_count:
230 *
231 * Maximum value of the vblank registers. This value +1 will result in a
232 * wrap-around of the vblank register. It is used by the vblank core to
233 * handle wrap-arounds.
234 *
235 * If set to zero the vblank core will try to guess the elapsed vblanks
236 * between times when the vblank interrupt is disabled through
237 * high-precision timestamps. That approach is suffering from small
238 * races and imprecision over longer time periods, hence exposing a
239 * hardware vblank counter is always recommended.
240 *
Ville Syrjäläed201512018-11-27 20:20:04 +0200241 * This is the statically configured device wide maximum. The driver
242 * can instead choose to use a runtime configurable per-crtc value
243 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
244 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
245 * to use the per-crtc value.
246 *
Daniel Vetter3214a162019-01-11 17:40:48 +0100247 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
Daniel Vettere4672e52017-08-02 13:56:01 +0200248 */
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100249 u32 max_vblank_count;
250
251 /** @vblank_event_list: List of vblank events */
Daniel Vettere4672e52017-08-02 13:56:01 +0200252 struct list_head vblank_event_list;
Daniel Vetter3214a162019-01-11 17:40:48 +0100253
254 /**
255 * @event_lock:
256 *
257 * Protects @vblank_event_list and event delivery in
258 * general. See drm_send_event() and drm_send_event_locked().
259 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200260 spinlock_t event_lock;
261
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100262 /** @num_crtcs: Number of CRTCs on this device */
263 unsigned int num_crtcs;
Daniel Vettere4672e52017-08-02 13:56:01 +0200264
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100265 /** @mode_config: Current mode config */
266 struct drm_mode_config mode_config;
Daniel Vettere4672e52017-08-02 13:56:01 +0200267
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100268 /** @object_name_lock: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200269 struct mutex object_name_lock;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100270
271 /** @object_name_idr: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200272 struct idr object_name_idr;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100273
274 /** @vma_offset_manager: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200275 struct drm_vma_offset_manager *vma_offset_manager;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100276
Thomas Zimmermann59f59892019-05-08 10:26:18 +0200277 /** @vram_mm: VRAM MM memory manager */
278 struct drm_vram_mm *vram_mm;
279
Sam Ravnborg7af78f42019-01-08 20:29:29 +0100280 /**
281 * @switch_power_state:
282 *
283 * Power state of the client.
284 * Used by drivers supporting the switcheroo driver.
285 * The state is maintained in the
286 * &vga_switcheroo_client_ops.set_gpu_state callback
287 */
288 enum switch_power_state switch_power_state;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +0100289
290 /**
291 * @fb_helper:
292 *
293 * Pointer to the fbdev emulation structure.
294 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
295 */
296 struct drm_fb_helper *fb_helper;
Daniel Vetter3214a162019-01-11 17:40:48 +0100297
298 /* Everything below here is for legacy driver, never use! */
299 /* private: */
Dave Airlie83c163f2019-04-23 09:56:01 +1000300#if IS_ENABLED(CONFIG_DRM_LEGACY)
Laurent Pinchart8dbe1b42020-02-20 17:16:28 +0200301 /* List of devices per driver for stealth attach cleanup */
302 struct list_head legacy_dev_list;
303
Thomas Zimmermann14054f22021-01-12 09:10:35 +0100304#ifdef __alpha__
305 /** @hose: PCI hose, only used on ALPHA platforms. */
306 struct pci_controller *hose;
307#endif
308
Thomas Zimmermann04dfe192021-05-07 20:57:09 +0200309 /* AGP data */
310 struct drm_agp_head *agp;
311
Daniel Vetter3214a162019-01-11 17:40:48 +0100312 /* Context handle management - linked list of context handles */
313 struct list_head ctxlist;
314
315 /* Context handle management - mutex for &ctxlist */
316 struct mutex ctxlist_mutex;
317
318 /* Context handle management */
319 struct idr ctx_idr;
320
321 /* Memory management - linked list of regions */
322 struct list_head maplist;
323
324 /* Memory management - user token hash table for maps */
325 struct drm_open_hash map_hash;
326
327 /* Context handle management - list of vmas (for debugging) */
328 struct list_head vmalist;
329
330 /* Optional pointer for DMA support */
331 struct drm_device_dma *dma;
332
333 /* Context swapping flag */
334 __volatile__ long context_flag;
335
336 /* Last current context */
337 int last_context;
338
339 /* Lock for &buf_use and a few other things. */
340 spinlock_t buf_lock;
341
342 /* Usage counter for buffers in use -- cannot alloc */
343 int buf_use;
344
345 /* Buffer allocation in progress */
346 atomic_t buf_alloc;
347
348 struct {
349 int context;
350 struct drm_hw_lock *lock;
351 } sigdata;
352
353 struct drm_local_map *agp_buffer_map;
354 unsigned int agp_buffer_token;
355
356 /* Scatter gather memory */
357 struct drm_sg_mem *sg;
Thomas Zimmermannc1736b92021-06-25 15:50:33 +0200358
359 /* IRQs */
360 bool irq_enabled;
361 int irq;
Dave Airlie83c163f2019-04-23 09:56:01 +1000362#endif
Daniel Vettere4672e52017-08-02 13:56:01 +0200363};
364
365#endif