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