blob: d7cedbac66a326ffa575f1a9f87b94d049c346a1 [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;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +010020struct drm_fb_helper;
Daniel Vettere4672e52017-08-02 13:56:01 +020021
22struct inode;
23
24struct pci_dev;
25struct pci_controller;
26
Sam Ravnborg7af78f42019-01-08 20:29:29 +010027
28/**
29 * enum drm_switch_power - power state of drm device
30 */
31
32enum switch_power_state {
33 /** @DRM_SWITCH_POWER_ON: Power state is ON */
34 DRM_SWITCH_POWER_ON = 0,
35
36 /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
37 DRM_SWITCH_POWER_OFF = 1,
38
39 /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
40 DRM_SWITCH_POWER_CHANGING = 2,
41
42 /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
43 DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
44};
45
Daniel Vettere4672e52017-08-02 13:56:01 +020046/**
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010047 * struct drm_device - DRM device structure
48 *
49 * This structure represent a complete card that
Daniel Vettere4672e52017-08-02 13:56:01 +020050 * may contain multiple heads.
51 */
52struct drm_device {
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010053 /**
54 * @legacy_dev_list:
55 *
56 * List of devices per driver for stealth attach cleanup
57 */
58 struct list_head legacy_dev_list;
Daniel Vettere4672e52017-08-02 13:56:01 +020059
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010060 /** @if_version: Highest interface version set */
61 int if_version;
62
63 /** @ref: Object ref-count */
64 struct kref ref;
65
66 /** @dev: Device structure of bus-device */
67 struct device *dev;
68
69 /** @driver: DRM driver managing the device */
70 struct drm_driver *driver;
71
72 /** @dev_private: DRM driver private data */
73 void *dev_private;
74
75 /** @primary: Primary node */
76 struct drm_minor *primary;
77
78 /** @render: Render node */
79 struct drm_minor *render;
80
Daniel Vettere4672e52017-08-02 13:56:01 +020081 bool registered;
82
Sam Ravnborgac4f24c2019-01-08 20:29:28 +010083 /**
84 * @master:
85 *
86 * Currently active master for this device.
87 * Protected by &master_mutex
88 */
Daniel Vettere4672e52017-08-02 13:56:01 +020089 struct drm_master *master;
90
Noralf Trønnesbee330f2018-03-28 10:38:35 +030091 /**
Ville Syrjälä18ace112018-09-13 16:16:21 +030092 * @driver_features: per-device driver features
93 *
94 * Drivers can clear specific flags here to disallow
95 * certain features on a per-device basis while still
96 * sharing a single &struct drm_driver instance across
97 * all devices.
98 */
99 u32 driver_features;
100
101 /**
Noralf Trønnesbee330f2018-03-28 10:38:35 +0300102 * @unplugged:
103 *
104 * Flag to tell if the device has been unplugged.
105 * See drm_dev_enter() and drm_dev_is_unplugged().
106 */
107 bool unplugged;
108
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100109 /** @anon_inode: inode for private address-space */
110 struct inode *anon_inode;
Daniel Vettere4672e52017-08-02 13:56:01 +0200111
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100112 /** @unique: Unique name of the device */
113 char *unique;
Daniel Vettere4672e52017-08-02 13:56:01 +0200114
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100115 /**
116 * @struct_mutex:
117 *
118 * Lock for others (not &drm_minor.master and &drm_file.is_master)
119 */
120 struct mutex struct_mutex;
121
122 /**
123 * @master_mutex:
124 *
125 * Lock for &drm_minor.master and &drm_file.is_master
126 */
127 struct mutex master_mutex;
128
129 /**
130 * @open_count:
131 *
132 * Usage counter for outstanding files open,
133 * protected by drm_global_mutex
134 */
135 int open_count;
136
137 /** @buf_lock: Lock for &buf_use and a few other things. */
138 spinlock_t buf_lock;
139
140 /** @buf_use: Usage counter for buffers in use -- cannot alloc */
141 int buf_use;
142
143 /** @buf_alloc: Buffer allocation in progress */
144 atomic_t buf_alloc;
Daniel Vettere4672e52017-08-02 13:56:01 +0200145
146 struct mutex filelist_mutex;
147 struct list_head filelist;
148
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200149 /**
150 * @filelist_internal:
151 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100152 * List of open DRM files for in-kernel clients.
153 * Protected by &filelist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200154 */
155 struct list_head filelist_internal;
156
157 /**
158 * @clientlist_mutex:
159 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100160 * Protects &clientlist access.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200161 */
162 struct mutex clientlist_mutex;
163
164 /**
165 * @clientlist:
166 *
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100167 * List of in-kernel clients. Protected by &clientlist_mutex.
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200168 */
169 struct list_head clientlist;
170
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100171 /** @maplist: Memory management - linked list of regions */
172 struct list_head maplist;
Daniel Vettere4672e52017-08-02 13:56:01 +0200173
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100174 /** @map_hash: Memory management - user token hash table for maps */
175 struct drm_open_hash map_hash;
Daniel Vettere4672e52017-08-02 13:56:01 +0200176
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100177 /**
178 * @ctxlist:
179 * Context handle management - linked list of context handles
180 */
181 struct list_head ctxlist;
182
183 /**
184 * @ctxlist_mutex:
185 *
186 * Context handle management - mutex for &ctxlist
187 */
188 struct mutex ctxlist_mutex;
189
190 /**
191 * @ctx_idr:
192 * Context handle management
193 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200194 struct idr ctx_idr;
195
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100196 /**
197 * @vmalist:
198 * Context handle management - list of vmas (for debugging)
199 */
200 struct list_head vmalist;
Daniel Vettere4672e52017-08-02 13:56:01 +0200201
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100202 /** @dma: Optional pointer for DMA support */
203 struct drm_device_dma *dma;
Daniel Vettere4672e52017-08-02 13:56:01 +0200204
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100205 /** @context_flag: Context swapping flag */
206 __volatile__ long context_flag;
Daniel Vettere4672e52017-08-02 13:56:01 +0200207
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100208 /** @last_context: Last current context */
209 int last_context;
Daniel Vettere4672e52017-08-02 13:56:01 +0200210
211 /**
212 * @irq_enabled:
213 *
214 * Indicates that interrupt handling is enabled, specifically vblank
215 * handling. Drivers which don't use drm_irq_install() need to set this
216 * to true manually.
217 */
218 bool irq_enabled;
219 int irq;
220
221 /**
222 * @vblank_disable_immediate:
223 *
224 * If true, vblank interrupt will be disabled immediately when the
225 * refcount drops to zero, as opposed to via the vblank disable
226 * timer.
227 *
228 * This can be set to true it the hardware has a working vblank counter
229 * with high-precision timestamping (otherwise there are races) and the
230 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
231 * appropriately. See also @max_vblank_count and
232 * &drm_crtc_funcs.get_vblank_counter.
233 */
234 bool vblank_disable_immediate;
235
236 /**
237 * @vblank:
238 *
239 * Array of vblank tracking structures, one per &struct drm_crtc. For
240 * historical reasons (vblank support predates kernel modesetting) this
241 * is free-standing and not part of &struct drm_crtc itself. It must be
242 * initialized explicitly by calling drm_vblank_init().
243 */
244 struct drm_vblank_crtc *vblank;
245
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100246 /**
247 * @vblank_time_lock:
248 *
249 * Protects vblank count and time updates during vblank enable/disable
250 */
251 spinlock_t vblank_time_lock;
Daniel Vettere4672e52017-08-02 13:56:01 +0200252 spinlock_t vbl_lock;
253
254 /**
255 * @max_vblank_count:
256 *
257 * Maximum value of the vblank registers. This value +1 will result in a
258 * wrap-around of the vblank register. It is used by the vblank core to
259 * handle wrap-arounds.
260 *
261 * If set to zero the vblank core will try to guess the elapsed vblanks
262 * between times when the vblank interrupt is disabled through
263 * high-precision timestamps. That approach is suffering from small
264 * races and imprecision over longer time periods, hence exposing a
265 * hardware vblank counter is always recommended.
266 *
267 * If non-zeor, &drm_crtc_funcs.get_vblank_counter must be set.
268 */
Daniel Vettere4672e52017-08-02 13:56:01 +0200269
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100270 /** @max_vblank_count: Size of vblank counter register */
271 u32 max_vblank_count;
272
273 /** @vblank_event_list: List of vblank events */
Daniel Vettere4672e52017-08-02 13:56:01 +0200274 struct list_head vblank_event_list;
275 spinlock_t event_lock;
276
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100277 /** @agp: AGP data */
278 struct drm_agp_head *agp;
Daniel Vettere4672e52017-08-02 13:56:01 +0200279
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100280 /** @pdev: PCI device structure */
281 struct pci_dev *pdev;
Daniel Vettere4672e52017-08-02 13:56:01 +0200282
Daniel Vettere4672e52017-08-02 13:56:01 +0200283#ifdef __alpha__
284 struct pci_controller *hose;
285#endif
286
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100287 /** @sg: Scatter gather memory */
288 struct drm_sg_mem *sg;
289
290 /** @num_crtcs: Number of CRTCs on this device */
291 unsigned int num_crtcs;
Daniel Vettere4672e52017-08-02 13:56:01 +0200292
293 struct {
294 int context;
295 struct drm_hw_lock *lock;
296 } sigdata;
297
298 struct drm_local_map *agp_buffer_map;
299 unsigned int agp_buffer_token;
300
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100301 /** @mode_config: Current mode config */
302 struct drm_mode_config mode_config;
Daniel Vettere4672e52017-08-02 13:56:01 +0200303
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100304 /** @object_name_lock: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200305 struct mutex object_name_lock;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100306
307 /** @object_name_idr: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200308 struct idr object_name_idr;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100309
310 /** @vma_offset_manager: GEM information */
Daniel Vettere4672e52017-08-02 13:56:01 +0200311 struct drm_vma_offset_manager *vma_offset_manager;
Sam Ravnborgac4f24c2019-01-08 20:29:28 +0100312
Sam Ravnborg7af78f42019-01-08 20:29:29 +0100313 /**
314 * @switch_power_state:
315 *
316 * Power state of the client.
317 * Used by drivers supporting the switcheroo driver.
318 * The state is maintained in the
319 * &vga_switcheroo_client_ops.set_gpu_state callback
320 */
321 enum switch_power_state switch_power_state;
Noralf Trønnes29ad20b222017-10-30 16:39:38 +0100322
323 /**
324 * @fb_helper:
325 *
326 * Pointer to the fbdev emulation structure.
327 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
328 */
329 struct drm_fb_helper *fb_helper;
Daniel Vettere4672e52017-08-02 13:56:01 +0200330};
331
332#endif