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