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