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