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