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 #include <linux/sched.h>
9
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 * Recovery methods for wedged device in order of less to more side-effects.
27 * To be used with drm_dev_wedged_event() as recovery @method. Callers can
28 * use any one, multiple (or'd) or none depending on their needs.
29 */
30 #define DRM_WEDGE_RECOVERY_NONE BIT(0) /* optional telemetry collection */
31 #define DRM_WEDGE_RECOVERY_REBIND BIT(1) /* unbind + bind driver */
32 #define DRM_WEDGE_RECOVERY_BUS_RESET BIT(2) /* unbind + reset bus device + bind */
33
34 /**
35 * struct drm_wedge_task_info - information about the guilty task of a wedge dev
36 */
37 struct drm_wedge_task_info {
38 /** @pid: pid of the task */
39 pid_t pid;
40 /** @comm: command name of the task */
41 char comm[TASK_COMM_LEN];
42 };
43
44 /**
45 * enum switch_power_state - power state of drm device
46 */
47
48 enum switch_power_state {
49 /** @DRM_SWITCH_POWER_ON: Power state is ON */
50 DRM_SWITCH_POWER_ON = 0,
51
52 /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
53 DRM_SWITCH_POWER_OFF = 1,
54
55 /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
56 DRM_SWITCH_POWER_CHANGING = 2,
57
58 /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
59 DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
60 };
61
62 /**
63 * struct drm_device - DRM device structure
64 *
65 * This structure represent a complete card that
66 * may contain multiple heads.
67 */
68 struct drm_device {
69 /** @if_version: Highest interface version set */
70 int if_version;
71
72 /** @ref: Object ref-count */
73 struct kref ref;
74
75 /** @dev: Device structure of bus-device */
76 struct device *dev;
77
78 /**
79 * @dma_dev:
80 *
81 * Device for DMA operations. Only required if the device @dev
82 * cannot perform DMA by itself. Should be NULL otherwise. Call
83 * drm_dev_dma_dev() to get the DMA device instead of using this
84 * field directly. Call drm_dev_set_dma_dev() to set this field.
85 *
86 * DRM devices are sometimes bound to virtual devices that cannot
87 * perform DMA by themselves. Drivers should set this field to the
88 * respective DMA controller.
89 *
90 * Devices on USB and other peripheral busses also cannot perform
91 * DMA by themselves. The @dma_dev field should point the bus
92 * controller that does DMA on behalve of such a device. Required
93 * for importing buffers via dma-buf.
94 *
95 * If set, the DRM core automatically releases the reference on the
96 * device.
97 */
98 struct device *dma_dev;
99
100 /**
101 * @managed:
102 *
103 * Managed resources linked to the lifetime of this &drm_device as
104 * tracked by @ref.
105 */
106 struct {
107 /** @managed.resources: managed resources list */
108 struct list_head resources;
109 /** @managed.final_kfree: pointer for final kfree() call */
110 void *final_kfree;
111 /** @managed.lock: protects @managed.resources */
112 spinlock_t lock;
113 } managed;
114
115 /** @driver: DRM driver managing the device */
116 const struct drm_driver *driver;
117
118 /**
119 * @dev_private:
120 *
121 * DRM driver private data. This is deprecated and should be left set to
122 * NULL.
123 *
124 * Instead of using this pointer it is recommended that drivers use
125 * devm_drm_dev_alloc() and embed struct &drm_device in their larger
126 * per-device structure.
127 */
128 void *dev_private;
129
130 /**
131 * @primary:
132 *
133 * Primary node. Drivers should not interact with this
134 * directly. debugfs interfaces can be registered with
135 * drm_debugfs_add_file(), and sysfs should be directly added on the
136 * hardware (and not character device node) struct device @dev.
137 */
138 struct drm_minor *primary;
139
140 /**
141 * @render:
142 *
143 * Render node. Drivers should not interact with this directly ever.
144 * Drivers should not expose any additional interfaces in debugfs or
145 * sysfs on this node.
146 */
147 struct drm_minor *render;
148
149 /** @accel: Compute Acceleration node */
150 struct drm_minor *accel;
151
152 /**
153 * @registered:
154 *
155 * Internally used by drm_dev_register() and drm_connector_register().
156 */
157 bool registered;
158
159 /**
160 * @master:
161 *
162 * Currently active master for this device.
163 * Protected by &master_mutex
164 */
165 struct drm_master *master;
166
167 /**
168 * @driver_features: per-device driver features
169 *
170 * Drivers can clear specific flags here to disallow
171 * certain features on a per-device basis while still
172 * sharing a single &struct drm_driver instance across
173 * all devices.
174 */
175 u32 driver_features;
176
177 /**
178 * @unplugged:
179 *
180 * Flag to tell if the device has been unplugged.
181 * See drm_dev_enter() and drm_dev_is_unplugged().
182 */
183 bool unplugged;
184
185 /** @anon_inode: inode for private address-space */
186 struct inode *anon_inode;
187
188 /** @unique: Unique name of the device */
189 char *unique;
190
191 /**
192 * @struct_mutex:
193 *
194 * Lock for others (not &drm_minor.master and &drm_file.is_master)
195 *
196 * TODO: This lock used to be the BKL of the DRM subsystem. Move the
197 * lock into i915, which is the only remaining user.
198 */
199 struct mutex struct_mutex;
200
201 /**
202 * @master_mutex:
203 *
204 * Lock for &drm_minor.master and &drm_file.is_master
205 */
206 struct mutex master_mutex;
207
208 /**
209 * @open_count:
210 *
211 * Usage counter for outstanding files open,
212 * protected by drm_global_mutex
213 */
214 atomic_t open_count;
215
216 /** @filelist_mutex: Protects @filelist. */
217 struct mutex filelist_mutex;
218 /**
219 * @filelist:
220 *
221 * List of userspace clients, linked through &drm_file.lhead.
222 */
223 struct list_head filelist;
224
225 /**
226 * @filelist_internal:
227 *
228 * List of open DRM files for in-kernel clients.
229 * Protected by &filelist_mutex.
230 */
231 struct list_head filelist_internal;
232
233 /**
234 * @clientlist_mutex:
235 *
236 * Protects &clientlist access.
237 */
238 struct mutex clientlist_mutex;
239
240 /**
241 * @clientlist:
242 *
243 * List of in-kernel clients. Protected by &clientlist_mutex.
244 */
245 struct list_head clientlist;
246
247 /**
248 * @vblank_disable_immediate:
249 *
250 * If true, vblank interrupt will be disabled immediately when the
251 * refcount drops to zero, as opposed to via the vblank disable
252 * timer.
253 *
254 * This can be set to true it the hardware has a working vblank counter
255 * with high-precision timestamping (otherwise there are races) and the
256 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
257 * appropriately. Also, see @max_vblank_count,
258 * &drm_crtc_funcs.get_vblank_counter and
259 * &drm_vblank_crtc_config.disable_immediate.
260 */
261 bool vblank_disable_immediate;
262
263 /**
264 * @vblank:
265 *
266 * Array of vblank tracking structures, one per &struct drm_crtc. For
267 * historical reasons (vblank support predates kernel modesetting) this
268 * is free-standing and not part of &struct drm_crtc itself. It must be
269 * initialized explicitly by calling drm_vblank_init().
270 */
271 struct drm_vblank_crtc *vblank;
272
273 /**
274 * @vblank_time_lock:
275 *
276 * Protects vblank count and time updates during vblank enable/disable
277 */
278 spinlock_t vblank_time_lock;
279 /**
280 * @vbl_lock: Top-level vblank references lock, wraps the low-level
281 * @vblank_time_lock.
282 */
283 spinlock_t vbl_lock;
284
285 /**
286 * @max_vblank_count:
287 *
288 * Maximum value of the vblank registers. This value +1 will result in a
289 * wrap-around of the vblank register. It is used by the vblank core to
290 * handle wrap-arounds.
291 *
292 * If set to zero the vblank core will try to guess the elapsed vblanks
293 * between times when the vblank interrupt is disabled through
294 * high-precision timestamps. That approach is suffering from small
295 * races and imprecision over longer time periods, hence exposing a
296 * hardware vblank counter is always recommended.
297 *
298 * This is the statically configured device wide maximum. The driver
299 * can instead choose to use a runtime configurable per-crtc value
300 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
301 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
302 * to use the per-crtc value.
303 *
304 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
305 */
306 u32 max_vblank_count;
307
308 /** @vblank_event_list: List of vblank events */
309 struct list_head vblank_event_list;
310
311 /**
312 * @event_lock:
313 *
314 * Protects @vblank_event_list and event delivery in
315 * general. See drm_send_event() and drm_send_event_locked().
316 */
317 spinlock_t event_lock;
318
319 /** @num_crtcs: Number of CRTCs on this device */
320 unsigned int num_crtcs;
321
322 /** @mode_config: Current mode config */
323 struct drm_mode_config mode_config;
324
325 /** @object_name_lock: GEM information */
326 struct mutex object_name_lock;
327
328 /** @object_name_idr: GEM information */
329 struct idr object_name_idr;
330
331 /** @vma_offset_manager: GEM information */
332 struct drm_vma_offset_manager *vma_offset_manager;
333
334 /** @vram_mm: VRAM MM memory manager */
335 struct drm_vram_mm *vram_mm;
336
337 /**
338 * @switch_power_state:
339 *
340 * Power state of the client.
341 * Used by drivers supporting the switcheroo driver.
342 * The state is maintained in the
343 * &vga_switcheroo_client_ops.set_gpu_state callback
344 */
345 enum switch_power_state switch_power_state;
346
347 /**
348 * @fb_helper:
349 *
350 * Pointer to the fbdev emulation structure.
351 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
352 */
353 struct drm_fb_helper *fb_helper;
354
355 /**
356 * @debugfs_root:
357 *
358 * Root directory for debugfs files.
359 */
360 struct dentry *debugfs_root;
361 };
362
363 void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev);
364
365 /**
366 * drm_dev_dma_dev - returns the DMA device for a DRM device
367 * @dev: DRM device
368 *
369 * Returns the DMA device of the given DRM device. By default, this
370 * the DRM device's parent. See drm_dev_set_dma_dev().
371 *
372 * Returns:
373 * A DMA-capable device for the DRM device.
374 */
drm_dev_dma_dev(struct drm_device * dev)375 static inline struct device *drm_dev_dma_dev(struct drm_device *dev)
376 {
377 if (dev->dma_dev)
378 return dev->dma_dev;
379 return dev->dev;
380 }
381
382 #endif
383