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